deal.II version GIT relicensing-2055-gd703fda1ad 2024-10-30 20:00:00+00:00
|
#include <deal.II/numerics/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 std::vector< VectorType > &all_in) |
void | prepare_for_coarsening_and_refinement (const VectorType &in) |
void | interpolate (std::vector< VectorType * > &all_out) |
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) |
void | clear () |
Private Member Functions | |
std::vector< char > | pack_callback (const typename Triangulation< dim, spacedim >::cell_iterator &cell, const CellStatus status) |
void | unpack_callback (const typename Triangulation< dim, spacedim >::cell_iterator &cell, const 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 | |
ObserverPointer< const DoFHandler< dim, spacedim >, SolutionTransfer< dim, VectorType, spacedim > > | dof_handler |
const bool | average_values |
std::vector< const VectorType * > | input_vectors |
unsigned int | handle |
This class implements the transfer of a discrete FE function (e.g. a solution vector) from one mesh to another that is obtained from the first by a single refinement and/or coarsening step. During interpolation the vector is filled with the interpolated values. This class is used in the step-15, step-26, step-31, and step-33 tutorial programs. This class works both for serial and distributed meshes.
Here VectorType is your favorite vector type, e.g. Vector, LinearAlgebra::distributed::Vector, PETScWrappers::MPI::Vector, TrilinosWrappers::MPI::Vector, or corresponding block vectors.
If 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):
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.
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 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 SolutionTransfer class with DoFHandler objects with hp-capabilities is provided in the following. Here VectorType is your favorite vector type, e.g. Vector, LinearAlgebra::distributed::Vector, 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):
This class does its best to represent on the new mesh the finite element function that existed on the old mesh, but this may lead to situations where the function on the new mesh is no longer conforming at hanging nodes. To this end, consider a situation of a twice refined mesh that started with a single square cell (i.e., we now have 16 cells). Consider also that we coarsen 4 of the cells back to the first refinement level. In this case, we end up with a mesh that will look as follows if we were to use a \(Q_1\) element:
The process of interpolating from the old to the new mesh would imply that the values of the finite element function will not change on all of the cells that remained as they are (i.e., the fine cells) but that on the coarse cell at the top right, the four values at the vertices are obtained by interpolating down from its former children. If the original function was not linear, this implies that the marked hanging nodes will retain their old values which, in general, will not lead to a continuous function along the corresponding edges. In other words, the solution vector obtained after SolutionTransfer::interpolate() does not satisfy hanging node constraints: it corresponds to the pointwise interpolation, but not to the interpolation onto the new finite element space that contains constraints from hanging nodes.
Whether this is a problem you need to worry about or not depends on your application. The situation is easily corrected, of course, by applying AffineConstraints::distribute() to your solution vector after transfer, using a constraints object computed on the new DoFHandler object (you probably need to create this object anyway if you have hanging nodes). This is also what is done, for example, in step-15.
In the case of DoFHandlers with hp-capabilities, nothing defines which of the finite elements that are part of the hp::FECollection associated with the DoFHandler, should be considered on cells that are not active (i.e., that have children). This is because degrees of freedom are only allocated for active cells and, in fact, it is not allowed to set an active FE index on non-active cells using DoFAccessor::set_active_fe_index().
It is, thus, not entirely natural what should happen if, for example, a few cells are coarsened away. This class then implements the following algorithm:
Definition at line 302 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 pointers to the vectors in all_in
to be interpolated onto the new (refined and/or coarsened) grid, and registers this object for data transfer on the grid.
Definition at line 128 of file solution_transfer.cc.
void SolutionTransfer< dim, VectorType, spacedim >::prepare_for_coarsening_and_refinement | ( | const std::vector< VectorType > & | all_in | ) |
Same as above but without pointers.
Definition at line 148 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 186 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 242 of file solution_transfer.cc.
void SolutionTransfer< dim, VectorType, spacedim >::interpolate | ( | std::vector< VectorType > & | all_out | ) |
Same as above but without pointers.
Definition at line 316 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 vector has the right size (i.e. 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_out)
Definition at line 331 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 197 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 208 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 218 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 228 of file solution_transfer.cc.
void SolutionTransfer< dim, VectorType, spacedim >::clear | ( | ) |
Reinit this class to the state that it has directly after calling the constructor.
Definition at line 505 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 341 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 408 of file solution_transfer.cc.
|
private |
Registers the pack_callback() function to the Triangulation that has been assigned to the DoFHandler class member and stores the returning handle.
Definition at line 163 of file solution_transfer.cc.
|
private |
Pointer to the degree of freedom handler to work with.
Definition at line 420 of file solution_transfer.h.
|
private |
Flag indicating if averaging should be performed.
Definition at line 425 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 431 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 437 of file solution_transfer.h.