Reference documentation for deal.II version 9.5.0
|
#include <deal.II/distributed/solution_transfer.h>
Public Member Functions | |
SolutionTransfer (const DoFHandler< dim, spacedim > &dof_handler, const bool average_values=false) | |
~SolutionTransfer ()=default | |
void | prepare_for_coarsening_and_refinement (const std::vector< const VectorType * > &all_in) |
void | prepare_for_coarsening_and_refinement (const VectorType &in) |
void | interpolate (std::vector< VectorType * > &all_out) |
void | interpolate (VectorType &out) |
void | prepare_for_serialization (const VectorType &in) |
void | prepare_for_serialization (const std::vector< const VectorType * > &all_in) |
void | deserialize (VectorType &in) |
void | deserialize (std::vector< VectorType * > &all_in) |
Private Member Functions | |
std::vector< char > | pack_callback (const typename Triangulation< dim, spacedim >::cell_iterator &cell, const typename Triangulation< dim, spacedim >::CellStatus status) |
void | unpack_callback (const typename Triangulation< dim, spacedim >::cell_iterator &cell, const typename Triangulation< dim, spacedim >::CellStatus status, const boost::iterator_range< std::vector< char >::const_iterator > &data_range, std::vector< VectorType * > &all_out, VectorType &valence) |
void | register_data_attach () |
Private Attributes | |
SmartPointer< const DoFHandler< dim, spacedim >, SolutionTransfer< dim, VectorType, spacedim > > | dof_handler |
const bool | average_values |
std::vector< const VectorType * > | input_vectors |
unsigned int | handle |
Transfer a discrete FE function (like a solution vector) by interpolation while refining and/or coarsening a distributed grid and handles the necessary communication.
In a parallel computation PETSc or Trilinos vector may contain ghost elements or not. For reading in information with prepare_for_coarsening_and_refinement() or prepare_for_serialization() you need to supply vectors with ghost elements, so that all locally_active elements can be read. On the other hand, ghosted vectors are generally not writable, so for calls to interpolate() or deserialize() you need to supply distributed vectors without ghost elements. More precisely, during interpolation the current algorithm writes into all locally active degrees of freedom.
Here VectorType is your favorite vector type, e.g. PETScWrappers::MPI::Vector, TrilinosWrappers::MPI::Vector, or corresponding block vectors.
As the grid is distributed, it is important to note that the old solution(s) must be copied to one that also provides access to the locally relevant DoF values (these values required for the interpolation process):
Different from PETSc and Trilinos vectors, LinearAlgebra::distributed::Vector allows writing into ghost elements. For a ghosted vector the interpolation step can be accomplished via
This class can be used to serialize and later deserialize a distributed mesh with solution vectors to a file. If you use more than one DoFHandler and therefore more than one SolutionTransfer object, they need to be serialized and deserialized in the same order.
If vector has the locally relevant DoFs, serialization works as follows:
For deserialization the vector needs to be a distributed vector (without ghost elements):
Since data on DoFHandler objects with hp-capabilities is associated with many different FiniteElement objects, each cell's data has to be processed with its corresponding future_fe_index
. Further, if refinement is involved, data will be packed on the parent cell with its future_fe_index
and unpacked later with the same index on its children. If cells get coarsened into one, data will be packed on the children with the least dominant finite element of their common subspace, and unpacked on the parent with this particular finite element (consult hp::FECollection::find_dominated_fe_extended() for more information).
Transferring a solution across refinement works exactly like in the non-hp-case. However, when considering serialization, we also have to store the active FE indices in an additional step. A code snippet demonstrating serialization with the parallel::distributed::SolutionTransfer class with DoFHandler objects with hp-capabilities is provided in the following. Here VectorType is your favorite vector type, e.g. PETScWrappers::MPI::Vector, TrilinosWrappers::MPI::Vector, or corresponding block vectors.
If vector has the locally relevant DoFs, serialization works as follows:
For deserialization the vector needs to be a distributed vector (without ghost elements):
In essence, this class implements the same steps as does SolutionTransfer (though the implementation is entirely separate). Consequently, the same issue with hanging nodes and coarsening can happen with this class as happens with SolutionTransfer. See there for an extended discussion.
Definition at line 225 of file solution_transfer.h.
SolutionTransfer< dim, VectorType, spacedim >::SolutionTransfer | ( | const DoFHandler< dim, spacedim > & | dof_handler, |
const bool | average_values = false |
||
) |
Constructor.
[in] | dof_handler | The DoFHandler on which all operations will happen. At the time when this constructor is called, the DoFHandler still points to the Triangulation before the refinement in question happens. |
[in] | average_values | Average the contribututions to the same DoF coming from different cells. Note: averaging requires an additional communication step, since the valence of the DoF has to be determined. |
Definition at line 116 of file solution_transfer.cc.
|
default |
Destructor.
void SolutionTransfer< dim, VectorType, spacedim >::prepare_for_coarsening_and_refinement | ( | const std::vector< const VectorType * > & | all_in | ) |
Prepare the current object for coarsening and refinement. It stores the dof indices of each cell and stores the dof values of the vectors in all_in
in each cell that'll be coarsened. all_in
includes all vectors that are to be interpolated onto the new (refined and/or coarsened) grid.
Definition at line 135 of file solution_transfer.cc.
void SolutionTransfer< dim, VectorType, spacedim >::prepare_for_coarsening_and_refinement | ( | const VectorType & | in | ) |
Same as the previous function but for only one discrete function to be interpolated.
Definition at line 177 of file solution_transfer.cc.
void SolutionTransfer< dim, VectorType, spacedim >::interpolate | ( | std::vector< VectorType * > & | all_out | ) |
Interpolate the data previously stored in this object before the mesh was refined or coarsened onto the current set of cells. Do so for each of the vectors provided to prepare_for_coarsening_and_refinement() and write the result into the given set of vectors.
Definition at line 233 of file solution_transfer.cc.
void SolutionTransfer< dim, VectorType, spacedim >::interpolate | ( | VectorType & | out | ) |
Same as the previous function. It interpolates only one function. It assumes the vectors having the right sizes (i.e. in.size()==n_dofs_old
, out.size()==n_dofs_refined
)
Multiple calling of this function is NOT allowed. Interpolating several functions can be performed in one step by using interpolate (all_in, all_out)
Definition at line 301 of file solution_transfer.cc.
void SolutionTransfer< dim, VectorType, spacedim >::prepare_for_serialization | ( | const VectorType & | in | ) |
Prepare the serialization of the given vector. The serialization is done by Triangulation::save(). The given vector needs all information on the locally active DoFs (it must be ghosted). See documentation of this class for more information.
Definition at line 188 of file solution_transfer.cc.
void SolutionTransfer< dim, VectorType, spacedim >::prepare_for_serialization | ( | const std::vector< const VectorType * > & | all_in | ) |
Same as the function above, only for a list of vectors.
Definition at line 199 of file solution_transfer.cc.
void SolutionTransfer< dim, VectorType, spacedim >::deserialize | ( | VectorType & | in | ) |
Execute the deserialization of the given vector. This needs to be done after calling Triangulation::load(). The given vector must be a fully distributed vector without ghost elements. See documentation of this class for more information.
Definition at line 209 of file solution_transfer.cc.
void SolutionTransfer< dim, VectorType, spacedim >::deserialize | ( | std::vector< VectorType * > & | all_in | ) |
Same as the function above, only for a list of vectors.
Definition at line 219 of file solution_transfer.cc.
|
private |
A callback function used to pack the data on the current mesh into objects that can later be retrieved after refinement, coarsening and repartitioning.
Definition at line 311 of file solution_transfer.cc.
|
private |
A callback function used to unpack the data on the current mesh that has been packed up previously on the mesh before refinement, coarsening and repartitioning.
Definition at line 382 of file solution_transfer.cc.
|
private |
Registers the pack_callback() function to the parallel::distributed::Triangulation that has been assigned to the DoFHandler class member and stores the returning handle.
Definition at line 151 of file solution_transfer.cc.
|
private |
Pointer to the degree of freedom handler to work with.
Definition at line 325 of file solution_transfer.h.
|
private |
Flag indicating if averaging should be performed.
Definition at line 330 of file solution_transfer.h.
|
private |
A vector that stores pointers to all the vectors we are supposed to copy over from the old to the new mesh.
Definition at line 336 of file solution_transfer.h.
|
private |
The handle that the Triangulation has assigned to this object with which we can access our memory offset and our pack function.
Definition at line 342 of file solution_transfer.h.