Commit 0ad18a06 authored by GILLES Sebastien's avatar GILLES Sebastien
Browse files

#859 Add the possibility to save on disk a Petsc vector and reload it.

parent 1775fafd
...@@ -55,6 +55,30 @@ namespace HappyHeart ...@@ -55,6 +55,30 @@ namespace HappyHeart
} }
Vector::Vector(const Mpi& mpi,
const std::string& binary_file,
const char* invoking_file, int invoking_line)
: petsc_vector_(PETSC_NULL),
do_petsc_destroy_(true)
{
const auto communicator = mpi.GetCommunicator();
Viewer viewer(mpi,
binary_file,
FILE_MODE_READ,
invoking_file, invoking_line);
int error_code = VecCreate(communicator, &petsc_vector_);
if (error_code)
throw ExceptionNS::Exception(error_code, "VecCreate", invoking_file, invoking_line);
error_code = VecLoad(petsc_vector_, viewer.GetUnderlyingPetscObject());
if (error_code)
throw ExceptionNS::Exception(error_code, "VecLoad", invoking_file, invoking_line);
}
Vector::~Vector() Vector::~Vector()
{ {
...@@ -477,6 +501,20 @@ namespace HappyHeart ...@@ -477,6 +501,20 @@ namespace HappyHeart
} }
void Vector::ViewBinary(const Mpi& mpi,
const std::string& output_file,
const char* invoking_file, int invoking_line) const
{
Viewer viewer(mpi, output_file, FILE_MODE_WRITE, invoking_file, invoking_line);
int error_code = VecView(Internal(), viewer.GetUnderlyingPetscObject());
if (error_code)
throw ExceptionNS::Exception(error_code, "VecView", invoking_file, invoking_line);
}
void GatherVector(const Mpi& mpi, void GatherVector(const Mpi& mpi,
const Wrappers::Petsc::Vector& local_parallel_vector, const Wrappers::Petsc::Vector& local_parallel_vector,
Wrappers::Petsc::Vector& sequential_vector, Wrappers::Petsc::Vector& sequential_vector,
......
...@@ -125,6 +125,17 @@ namespace HappyHeart ...@@ -125,6 +125,17 @@ namespace HappyHeart
* *
*/ */
explicit Vector(const Vec& petsc_vector, bool do_destroy_petsc); 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.
* \copydoc doxygen_hide_invoking_file_and_line
*/
explicit Vector(const Mpi& mpi,
const std::string& binary_file,
const char* invoking_file, int invoking_line);
//! Destructor. //! Destructor.
~Vector(); ~Vector();
...@@ -445,6 +456,20 @@ namespace HappyHeart ...@@ -445,6 +456,20 @@ namespace HappyHeart
PetscViewerFormat format = PETSC_VIEWER_DEFAULT) const; PetscViewerFormat format = PETSC_VIEWER_DEFAULT) const;
/*!
* \brief Wrapper over MatView in the case the viewer is a binary file.
*
* \param[in] output_file File into which the vector content will be written.
* \param[in] invoking_file File that invoked the function or class; usually __FILE__.
* \param[in] invoking_line File that invoked the function or class; usually __LINE__.
*/
void ViewBinary(const Mpi& mpi,
const std::string& output_file,
const char* invoking_file, int invoking_line) const;
/*! /*!
* \brief Print the content of a vector in a file. * \brief Print the content of a vector in a file.
* *
......
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