Commit 1a11b197 authored by GILLES Sebastien's avatar GILLES Sebastien

#1454 PetscVector: modify the API of some methods to be more in line with the rest of the library.

parent 654b0cb0
......@@ -140,7 +140,7 @@ namespace MoReFEM
const unsigned int Nproc = mpi.template Nprocessor<unsigned int>();
if (Nproc == 1)
vector.InitSequentialVector(Nprocessor_wise_dof, mpi, __FILE__, __LINE__);
vector.InitSequentialVector(mpi, Nprocessor_wise_dof, __FILE__, __LINE__);
else
{
std::vector<PetscInt> ghosted_dof_index_list;
......@@ -163,10 +163,10 @@ namespace MoReFEM
assert(std::is_sorted(ghosted_dof_index_list.cbegin(), ghosted_dof_index_list.cend()));
vector.InitMpiVectorWithGhost(Nprocessor_wise_dof,
vector.InitMpiVectorWithGhost(mpi,
Nprocessor_wise_dof,
Nprogram_wise_dof,
ghosted_dof_index_list,
mpi,
__FILE__, __LINE__);
}
......
......@@ -245,15 +245,15 @@ namespace MoReFEM
if (mpi.Nprocessor<int>() == 1)
{
assert(Nprogram_wise_dof_without_dirichlet == Nprocessor_wise_dof_without_dirichlet);
target_vector_pattern.InitSequentialVector(Nprogram_wise_dof_without_dirichlet,
mpi,
target_vector_pattern.InitSequentialVector(mpi,
Nprogram_wise_dof_without_dirichlet,
__FILE__, __LINE__);
}
else
{
target_vector_pattern.InitMpiVector(Nprocessor_wise_dof_without_dirichlet,
target_vector_pattern.InitMpiVector(mpi,
Nprocessor_wise_dof_without_dirichlet,
Nprogram_wise_dof_without_dirichlet,
mpi,
__FILE__, __LINE__);
}
......
......@@ -79,16 +79,16 @@ namespace MoReFEM
}
Vector::Vector(const Mpi& mpi,
unsigned int processor_wise_size,
unsigned int program_wise_size,
const std::vector<PetscInt>& ghost_padding,
const std::string& binary_file,
const char* invoking_file, int invoking_line)
: petsc_vector_(PETSC_NULL),
do_petsc_destroy_(true)
void Vector::InitFromProgramWiseBinaryFile(const Mpi& mpi,
unsigned int processor_wise_size,
unsigned int program_wise_size,
const std::vector<PetscInt>& ghost_padding,
const std::string& binary_file,
const char* invoking_file, int invoking_line)
{
assert(petsc_vector_ == PETSC_NULL);
assert(processor_wise_size <= program_wise_size && "Detect easily invalid order in arguments...");
do_petsc_destroy_ = true;
Viewer viewer(mpi,
binary_file,
......@@ -97,10 +97,10 @@ namespace MoReFEM
if (mpi.Nprocessor<int>() > 1)
{
InitMpiVectorWithGhost(processor_wise_size,
InitMpiVectorWithGhost(mpi,
processor_wise_size,
program_wise_size,
ghost_padding,
mpi,
invoking_file, invoking_line);
int error_code = VecLoad(petsc_vector_, viewer.GetUnderlyingPetscObject());
......@@ -116,8 +116,8 @@ namespace MoReFEM
assert(processor_wise_size == program_wise_size);
assert(ghost_padding.empty());
InitSequentialVector(processor_wise_size,
mpi,
InitSequentialVector(mpi,
processor_wise_size,
invoking_file, invoking_line);
int error_code = VecLoad(petsc_vector_, viewer.GetUnderlyingPetscObject());
......@@ -148,8 +148,8 @@ namespace MoReFEM
}
void Vector::InitSequentialVector(unsigned int size,
const Mpi& mpi,
void Vector::InitSequentialVector(const Mpi& mpi,
unsigned int size,
const char* invoking_file, int invoking_line)
{
assert(petsc_vector_ == PETSC_NULL && "Should not be initialized when this method is called!");
......@@ -161,8 +161,10 @@ namespace MoReFEM
}
void Vector::InitMpiVector(unsigned int local_size, unsigned int global_size,
const Mpi& mpi, const char* invoking_file, int invoking_line)
void Vector::InitMpiVector(const Mpi& mpi,
unsigned int local_size,
unsigned int global_size,
const char* invoking_file, int invoking_line)
{
assert(petsc_vector_ == PETSC_NULL && "Should not be initialized when this method is called!");
assert(local_size <= global_size && "If not, either sequential mode or the local and global were "
......@@ -180,9 +182,11 @@ namespace MoReFEM
}
void Vector::InitMpiVectorWithGhost(unsigned int local_size, unsigned int global_size,
void Vector::InitMpiVectorWithGhost(const Mpi& mpi,
unsigned int local_size,
unsigned int global_size,
const std::vector<PetscInt>& ghost_padding,
const Mpi& mpi, const char* invoking_file, int invoking_line)
const char* invoking_file, int invoking_line)
{
assert(petsc_vector_ == PETSC_NULL && "Should not be initialized when this method is called!");
assert(local_size <= global_size && "If not, either sequential mode or the local and global were "
......@@ -206,8 +210,8 @@ namespace MoReFEM
}
void Vector::InitSequentialFromFile(const std::string& file,
const Mpi& mpi,
void Vector::InitSequentialFromFile(const Mpi& mpi,
const std::string& file,
const char* invoking_file, int invoking_line)
{
assert(petsc_vector_ == PETSC_NULL && "Should not be initialized when this method is called!");
......@@ -228,7 +232,7 @@ namespace MoReFEM
// Now Init the vector with the appropriate size.
const unsigned int Nvalue = static_cast<unsigned int>(value_list.size());
InitSequentialVector(Nvalue, mpi, invoking_file, invoking_line);
InitSequentialVector(mpi, Nvalue, invoking_file, invoking_line);
// And fill it with the values.
AccessVectorContent<Utilities::Access::read_and_write> content(*this, invoking_file, invoking_line);
......
......@@ -71,6 +71,22 @@ namespace MoReFEM
//! Enum class to specify if in a copy ghosts are updated or not.
enum class update_ghost { yes, no };
/*!
* \class doxygen_hide_parallel_size_arg
*
* \param[in] processor_wise_size Number of elements processor-wise (ghosts excluded).
* \param[in] program_wise_size Number of elements program-wise.
*/
/*!
* \class doxygen_hide_parallel_with_ghosts_arg
*
* \copydetails doxygen_hide_parallel_size_arg
* \param[in] ghost_padding List of program-wise index of values that are ghosted (i.e. required
* processor-wise but owned by another processor).
*/
namespace Wrappers
{
......@@ -134,25 +150,6 @@ namespace MoReFEM
*/
explicit Vector(const Vec& petsc_vector, bool do_destroy_petsc);
/*!
* \brief Constructor from a file: load a vector dumped with View() method.
*
* \param[in] binary_file File from which the vector must be loaded. This file must be in binary format.
* \param[in] processor_wise_size Number of elements processor-wise (ghosts excluded).
* \param[in] program_wise_size Number of elements program-wise.
* \param[in] ghost_padding List of program-wise index of values that are ghosted (i.e. required
* processor-wise but owned by another processor).
* \copydoc doxygen_hide_invoking_file_and_line
* \copydetails doxygen_hide_mpi_param
*/
explicit Vector(const Mpi& mpi,
unsigned int processor_wise_size,
unsigned int program_wise_size,
const std::vector<PetscInt>& ghost_padding,
const std::string& binary_file,
const char* invoking_file, int invoking_line);
//! Destructor.
virtual ~Vector();
......@@ -177,40 +174,43 @@ namespace MoReFEM
/*!
* \brief Set the vector as sequential.
*
* \attention This method is to be called just after creation of the object, whcih should still
* be a blank state.
*
* \param[in] size Number of elements in the vector.
* \copydoc doxygen_hide_invoking_file_and_line
* \copydetails doxygen_hide_mpi_param
*/
void InitSequentialVector(unsigned int size, const Mpi& mpi,
void InitSequentialVector(const Mpi& mpi,
unsigned int size,
const char* invoking_file, int invoking_line);
/*!
* \brief Set the vector as parallel.
* \brief Set the vector as sequential.
*
* \param[in] size_processor_wise Size of the vector on the current processor (the ghost are not counted
* here).
* \param[in] size_program_wise Size of the vector on the program (i.e. the one before partitioning).
* \attention This method is to be called just after creation of the object, whcih should still
* be a blank state.
*
* \copydetails doxygen_hide_parallel_size_arg
* \copydoc doxygen_hide_invoking_file_and_line
* \copydetails doxygen_hide_mpi_param
*/
void InitMpiVector(unsigned int size_processor_wise , unsigned int size_program_wise, const Mpi& mpi,
void InitMpiVector(const Mpi& mpi,
unsigned int processor_wise_size,
unsigned int program_wise_size,
const char* invoking_file, int invoking_line);
/*!
* \brief Create a parallel vector with ghost padding.
*
* \param[in] size_processor_wise Size of the vector on the current processor (the ghost are not counted
* here).
* \param[in] size_program_wise Size of the vector on the program (i.e. the one before partitioning).
* \param[in] ghost_padding List of program-wise index of values that are ghosted (i.e. required
* processor-wise but owned by another processor).
* \copydetails doxygen_hide_parallel_with_ghosts_arg
* \copydoc doxygen_hide_invoking_file_and_line
* \copydetails doxygen_hide_mpi_param
*/
void InitMpiVectorWithGhost(unsigned int size_processor_wise , unsigned int size_program_wise,
const std::vector<PetscInt>& ghost_padding, const Mpi& mpi,
void InitMpiVectorWithGhost(const Mpi& mpi,
unsigned int processor_wise_size ,
unsigned int program_wise_size,
const std::vector<PetscInt>& ghost_padding,
const char* invoking_file, int invoking_line);
......@@ -225,10 +225,24 @@ namespace MoReFEM
* \copydoc doxygen_hide_invoking_file_and_line
* \copydetails doxygen_hide_mpi_param
*/
void InitSequentialFromFile(const std::string& file,
const Mpi& mpi,
void InitSequentialFromFile(const Mpi& mpi,
const std::string& file,
const char* invoking_file, int invoking_line);
/*!
* \brief Init from a program-wise binary file: load a vector dumped with View() method.
*
* \param[in] binary_file File from which the vector must be loaded. This file must be in binary format.
* \copydetails doxygen_hide_parallel_with_ghosts_arg
* \copydoc doxygen_hide_invoking_file_and_line
* \copydetails doxygen_hide_mpi_param
*/
void InitFromProgramWiseBinaryFile(const Mpi& mpi,
unsigned int processor_wise_size,
unsigned int program_wise_size,
const std::vector<PetscInt>& ghost_padding,
const std::string& binary_file,
const char* invoking_file, int invoking_line);
/*!
* \brief Handle over the internal Vec object.
......@@ -509,7 +523,7 @@ namespace MoReFEM
* \param[in] output_file File into which the vector content will be written.
*
* \attention To my knowledge there are no way to reload a PETSc vector from the file; if you need
* to do so rather use binary format.
* to do so rather use binary format.
*
*/
void View(const Mpi& mpi, const std::string& output_file, const char* invoking_file, int invoking_line,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment