preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
precice::mapping::Mapping Class Referenceabstract

Abstract base class for mapping of data from one mesh to another. More...

#include <Mapping.hpp>

Inheritance diagram for precice::mapping::Mapping:
[legend]
Collaboration diagram for precice::mapping::Mapping:
[legend]

Public Types

enum  Constraint { CONSISTENT , CONSERVATIVE , SCALED_CONSISTENT_SURFACE , SCALED_CONSISTENT_VOLUME }
 Specifies additional constraints for a mapping. More...
 
enum class  MeshRequirement { UNDEFINED = 0 , VERTEX = 1 , FULL = 2 }
 Specifies requirements for the input and output meshes of a mapping. More...
 
enum class  InitialGuessRequirement : bool { Required = true , None = false }
 Specifies whether the mapping requires an initial guess. More...
 

Public Member Functions

 Mapping (Constraint constraint, int dimensions, bool requiresGradientData, InitialGuessRequirement initialGuessRequirement)
 Constructor, takes mapping constraint.
 
Mappingoperator= (Mapping &&)=delete
 
virtual ~Mapping ()=default
 Destructor, empty.
 
void setMeshes (const mesh::PtrMesh &input, const mesh::PtrMesh &output)
 Sets input and output meshes carrying data to be mapped.
 
const mesh::PtrMeshgetInputMesh () const
 
const mesh::PtrMeshgetOutputMesh () const
 
Constraint getConstraint () const
 Returns the constraint (consistent/conservative) of the mapping.
 
MeshRequirement getInputRequirement () const
 Returns the requirement on the input mesh.
 
MeshRequirement getOutputRequirement () const
 Returns the requirement on the output mesh.
 
virtual void computeMapping ()=0
 Computes the mapping coefficients from the in- and output mesh.
 
bool hasComputedMapping () const
 Returns true, if the mapping has been computed.
 
virtual bool hasConstraint (const Constraint &constraint) const
 Checks whether the mapping has the given constraint or not.
 
bool isScaledConsistent () const
 Returns true if mapping is a form of scaled consistent mapping.
 
bool requiresInitialGuess () const
 Return true if the mapping requires an initial guess.
 
bool isJustInTimeMapping () const
 
const Eigen::VectorXd & initialGuess () const
 Return the provided initial guess of a mapping using an initialGuess.
 
Eigen::VectorXd & initialGuess ()
 
bool hasInitialGuess () const
 True if initialGuess().size() == 0.
 
virtual void clear ()=0
 Removes a computed mapping.
 
void map (int inputDataID, int outputDataID)
 
void map (int inputDataID, int outputDataID, Eigen::VectorXd &initialGuess)
 
void map (const time::Sample &input, Eigen::VectorXd &output)
 Maps an input Sample to output data from input mesh to output mesh.
 
void map (const time::Sample &input, Eigen::VectorXd &output, Eigen::VectorXd &initialGuess)
 Maps an input Sample to output data from input mesh to output mesh, given an initialGuess.
 
virtual void tagMeshFirstRound ()=0
 Method used by partition. Tags vertices that could be owned by this rank.
 
virtual void tagMeshSecondRound ()=0
 Method used by partition. Tags vertices that can be filtered out.
 
virtual void scaleConsistentMapping (const Eigen::VectorXd &input, Eigen::VectorXd &output, Constraint type) const
 Scales the consistently mapped output data such that the surface integral of the values on input mesh and output mesh are equal.
 
bool requiresGradientData () const
 Returns whether the mapping requires gradient data.
 
virtual std::string getName () const =0
 Returns the name of the mapping method for logging purpose.
 
virtual void mapConservativeAt (const Eigen::Ref< const Eigen::MatrixXd > &coordinates, const Eigen::Ref< const Eigen::MatrixXd > &source, impl::MappingDataCache &cache, Eigen::Ref< Eigen::MatrixXd > target)
 Just-in-time mapping variant of mapConservative.
 
virtual void mapConsistentAt (const Eigen::Ref< const Eigen::MatrixXd > &coordinates, const impl::MappingDataCache &cache, Eigen::Ref< Eigen::MatrixXd > values)
 Just-in-time mapping variant of mapConsistent.
 
virtual void updateMappingDataCache (impl::MappingDataCache &cache, const Eigen::Ref< const Eigen::VectorXd > &in)
 Allows updating a so-called MappingDataCache for more efficient just-in-time mappings.
 
virtual void initializeMappingDataCache (impl::MappingDataCache &cache)
 Allocates memory and sets up the data structures inside the MappingDataCache.
 
virtual void completeJustInTimeMapping (impl::MappingDataCache &cache, Eigen::Ref< Eigen::MatrixXd > result)
 Completes a just-in-time mapping for conservative constraints.
 

Protected Member Functions

mesh::PtrMesh input () const
 Returns pointer to input mesh.
 
mesh::PtrMesh output () const
 Returns pointer to output mesh.
 
void setInputRequirement (MeshRequirement requirement)
 Sets the mesh requirement for the input mesh.
 
void setOutputRequirement (MeshRequirement requirement)
 Sets the mesh requirement for the output mesh.
 
int getDimensions () const
 
virtual void mapConservative (const time::Sample &input, Eigen::VectorXd &output)=0
 Maps data using a conservative constraint.
 
virtual void mapConsistent (const time::Sample &input, Eigen::VectorXd &output)=0
 Maps data using a consistent constraint.
 

Protected Attributes

bool _hasComputedMapping = false
 Flag to indicate whether computeMapping() has been called.
 
bool _requiresGradientData
 Flag if gradient data is required for the mapping.
 

Private Attributes

Constraint _constraint
 Determines whether mapping is consistent or conservative.
 
MeshRequirement _inputRequirement
 Requirement on input mesh.
 
MeshRequirement _outputRequirement
 Requirement on output mesh.
 
mesh::PtrMesh _input
 Pointer to input mesh.
 
mesh::PtrMesh _output
 Pointer to output mesh.
 
int _dimensions
 
InitialGuessRequirement _initialGuessRequirement
 The InitialGuessRequirement of the Mapping.
 
Eigen::VectorXd * _initialGuess = nullptr
 Pointer to the initialGuess set and unset by map.
 

Detailed Description

Abstract base class for mapping of data from one mesh to another.

Definition at line 16 of file Mapping.hpp.

Member Enumeration Documentation

◆ Constraint

Specifies additional constraints for a mapping.

A consistent mapping retains mean values. When mapping displacements, e.g. rigid body motions are retained. A conservative mapping retains the sum of the values. The scaled-consistent-surface/volume mappings first map the values consistently, then scales the mapped such that the integrals on both meshes are equal. Integrals are either done on surfaces or volumes depending on the mode.

  • Continuous fields such as displacements or temperatures should use consistent maps.
  • Quantities whose sum is preserved such as forces should use conservative maps.
  • Continuous fields whose integral matters, such as pressure or heat fluxes should be consistent or scaled-consistent.
Enumerator
CONSISTENT 
CONSERVATIVE 
SCALED_CONSISTENT_SURFACE 
SCALED_CONSISTENT_VOLUME 

Definition at line 30 of file Mapping.hpp.

◆ InitialGuessRequirement

Specifies whether the mapping requires an initial guess.

Iterative mappings use an additional initial guess to perform the mapping. When calling the version of map with the initialGuess, derived classes of Mapping can access and update this initial guess using initialGuess(). Note that the size of the initial guess is controlled by the Mapping.

The first initial guess is expected to be an empty VectorXd.

Enumerator
Required 
None 

Definition at line 64 of file Mapping.hpp.

◆ MeshRequirement

Specifies requirements for the input and output meshes of a mapping.

Different mapping types have different requirements on the meshes involved in the mapping, while the input and output mesh holding the data to map can have different requirements. FULL requires a mesh consisting of vertices connected by edges and faces. VERTEX requires a mesh consisting of vertices only.

Enumerator
UNDEFINED 
VERTEX 

Vertices only.

FULL 

Full mesh.

Definition at line 46 of file Mapping.hpp.

Constructor & Destructor Documentation

◆ Mapping()

precice::mapping::Mapping::Mapping ( Constraint constraint,
int dimensions,
bool requiresGradientData,
InitialGuessRequirement initialGuessRequirement )

Constructor, takes mapping constraint.

Definition at line 12 of file Mapping.cpp.

◆ ~Mapping()

virtual precice::mapping::Mapping::~Mapping ( )
virtualdefault

Destructor, empty.

Member Function Documentation

◆ clear()

virtual void precice::mapping::Mapping::clear ( )
pure virtual

◆ completeJustInTimeMapping()

void precice::mapping::Mapping::completeJustInTimeMapping ( impl::MappingDataCache & cache,
Eigen::Ref< Eigen::MatrixXd > result )
virtual

Completes a just-in-time mapping for conservative constraints.

For conservative constraints (only implemented in write direction at the moment), we potentially buffer (partially mapped) data written by the user into the MappingDataCache. Once the user has written all data, we complete the mapping to generate the full output data. In many cases, the initial 'partial processing' or partial mapping is a computationally cheaper operation, whereas the finalization in this function call performs the computationally more demanding operations. To prevent the expensive operations from entering the API functions, we use the MappingDataCache and the additional completeJustInTimeMapping function. The function needs to be called in the ParticipantImpl before calling storeBufferedData (which adds the (mapped and written) output data to the time step storage). The function is called through the (Write)DataContext owning the just-in-time mapping.

This is not relevant for consistent constraints (only implemented in read direction at the moment), as we map before we give the data to the user, i.e., there is no completion to defer.

See also the documentation in impl::MappingDataCache for more information.

Parameters
[in]cacheThe MappingDataCache holding the buffered data we want to evaluate
[out]resultThe data vector we store the output data in.

Reimplemented in precice::mapping::PartitionOfUnityMapping< RADIAL_BASIS_FUNCTION_T >.

Definition at line 301 of file Mapping.cpp.

◆ computeMapping()

virtual void precice::mapping::Mapping::computeMapping ( )
pure virtual

◆ getConstraint()

Mapping::Constraint precice::mapping::Mapping::getConstraint ( ) const

Returns the constraint (consistent/conservative) of the mapping.

Definition at line 46 of file Mapping.cpp.

◆ getDimensions()

int precice::mapping::Mapping::getDimensions ( ) const
protected

Definition at line 109 of file Mapping.cpp.

◆ getInputMesh()

const mesh::PtrMesh & precice::mapping::Mapping::getInputMesh ( ) const

Definition at line 36 of file Mapping.cpp.

◆ getInputRequirement()

Mapping::MeshRequirement precice::mapping::Mapping::getInputRequirement ( ) const

Returns the requirement on the input mesh.

Definition at line 77 of file Mapping.cpp.

◆ getName()

virtual std::string precice::mapping::Mapping::getName ( ) const
pure virtual

◆ getOutputMesh()

const mesh::PtrMesh & precice::mapping::Mapping::getOutputMesh ( ) const

Definition at line 41 of file Mapping.cpp.

◆ getOutputRequirement()

Mapping::MeshRequirement precice::mapping::Mapping::getOutputRequirement ( ) const

Returns the requirement on the output mesh.

Definition at line 82 of file Mapping.cpp.

◆ hasComputedMapping()

bool precice::mapping::Mapping::hasComputedMapping ( ) const

Returns true, if the mapping has been computed.

After a call to clear(), a computed mapping is removed and false returned.

Definition at line 253 of file Mapping.cpp.

◆ hasConstraint()

bool precice::mapping::Mapping::hasConstraint ( const Constraint & constraint) const
virtual

Checks whether the mapping has the given constraint or not.

Definition at line 248 of file Mapping.cpp.

Here is the call graph for this function:

◆ hasInitialGuess()

bool precice::mapping::Mapping::hasInitialGuess ( ) const

True if initialGuess().size() == 0.

Definition at line 56 of file Mapping.cpp.

Here is the call graph for this function:

◆ initialGuess() [1/2]

Eigen::VectorXd & precice::mapping::Mapping::initialGuess ( )

Definition at line 70 of file Mapping.cpp.

Here is the call graph for this function:

◆ initialGuess() [2/2]

const Eigen::VectorXd & precice::mapping::Mapping::initialGuess ( ) const

Return the provided initial guess of a mapping using an initialGuess.

Definition at line 63 of file Mapping.cpp.

Here is the call graph for this function:

◆ initializeMappingDataCache()

void precice::mapping::Mapping::initializeMappingDataCache ( impl::MappingDataCache & cache)
virtual

Allocates memory and sets up the data structures inside the MappingDataCache.

This is only relevant for just-in-time mappings. The MappingDataCache is specific to a Data-Mapping pair and stores intermediate computatons for efficiency reasons. The initialization happens immediately after ParticipantImpl::computeMappings through the DataContext::initializeMappingDataCache, which owns the just-in-time mapping, since only then the size of relevant data structures is known.

See the documentation in impl::MappingDataCache for more information.

Parameters
cachethe cache in use, specific to the mapping-data pair

Reimplemented in precice::mapping::PartitionOfUnityMapping< RADIAL_BASIS_FUNCTION_T >.

Definition at line 281 of file Mapping.cpp.

◆ input()

mesh::PtrMesh precice::mapping::Mapping::input ( ) const
protected

Returns pointer to input mesh.

Definition at line 87 of file Mapping.cpp.

◆ isJustInTimeMapping()

bool precice::mapping::Mapping::isJustInTimeMapping ( ) const

Returns true if either the input or output is a just-in-time (dummy) mesh which is used for just-in-time mappings. The just-in-time mesh is essentially a placeholder for the non-existent or just-in-time mesh provided by the user through the API functions

Definition at line 263 of file Mapping.cpp.

◆ isScaledConsistent()

bool precice::mapping::Mapping::isScaledConsistent ( ) const

Returns true if mapping is a form of scaled consistent mapping.

Definition at line 258 of file Mapping.cpp.

Here is the call graph for this function:

◆ map() [1/4]

void precice::mapping::Mapping::map ( const time::Sample & input,
Eigen::VectorXd & output )

Maps an input Sample to output data from input mesh to output mesh.

Derived classed must implement the mapping functionality using mapConsistent() and mapConservative()

Parameters
[in]inputsample to map
[out]outputresult data
Precondition
hasComputedMapping() == true
requiresInitialGuess() == false
Postcondition
output contains the mapped data

Definition at line 158 of file Mapping.cpp.

Here is the call graph for this function:

◆ map() [2/4]

void precice::mapping::Mapping::map ( const time::Sample & input,
Eigen::VectorXd & output,
Eigen::VectorXd & initialGuess )

Maps an input Sample to output data from input mesh to output mesh, given an initialGuess.

The initialGuess must be either an empty VectorXd, or the result of a previous invocation of map.

Derived classed must implement the mapping functionality using mapConsistent() and mapConservative()

Warning
this is the map version which requires an initial guess
Parameters
[in]inputsample to map
[out]outputresult data
[in,out]initialGuessguess to use during map, may be an empty VectorXd
Precondition
initialGuess is either an empty VectorXd or the result of a previous invocation of map
hasComputedMapping() == true
requiresInitialGuess() == true
Postcondition
output contains the mapped data
initialGuess() contains the initial guess for the next call to map

Definition at line 150 of file Mapping.cpp.

Here is the call graph for this function:

◆ map() [3/4]

void precice::mapping::Mapping::map ( int inputDataID,
int outputDataID )
Deprecated

Definition at line 127 of file Mapping.cpp.

Here is the call graph for this function:

◆ map() [4/4]

void precice::mapping::Mapping::map ( int inputDataID,
int outputDataID,
Eigen::VectorXd & initialGuess )
Deprecated

Definition at line 119 of file Mapping.cpp.

Here is the call graph for this function:

◆ mapConservative()

virtual void precice::mapping::Mapping::mapConservative ( const time::Sample & input,
Eigen::VectorXd & output )
protectedpure virtual

Maps data using a conservative constraint.

Parameters
[in]inputSample to map data from
[in]outputValues to map to

If requiresInitialGuess(), then the initial guess is available via initialGuess(). Provide a new initial guess by overwriting it. The mapping has full control over its size.

See also
For mappings requiring an initialGuess: initialGuess() hasInitialGuess()

Implemented in precice::mapping::NearestNeighborGradientMapping, precice::mapping::NearestNeighborMapping, precice::mapping::PetRadialBasisFctMapping< RADIAL_BASIS_FUNCTION_T >, precice::mapping::RadialBasisFctMapping< SOLVER_T, Args >, precice::mapping::AxialGeoMultiscaleMapping, precice::mapping::BarycentricBaseMapping, precice::mapping::PartitionOfUnityMapping< RADIAL_BASIS_FUNCTION_T >, and precice::mapping::RadialGeoMultiscaleMapping.

◆ mapConservativeAt()

void precice::mapping::Mapping::mapConservativeAt ( const Eigen::Ref< const Eigen::MatrixXd > & coordinates,
const Eigen::Ref< const Eigen::MatrixXd > & source,
impl::MappingDataCache & cache,
Eigen::Ref< Eigen::MatrixXd > target )
virtual

Just-in-time mapping variant of mapConservative.

Depending on the underlying mapping implementation, the result is either stored in an intermediate cache or directly in the target values, i.e., one of both arguments is typically unused in the mapping method. In case the data is stored in the cache, final results may be computed using completeJustInTimeMapping

Parameters
coordinates[in]where to compute the mapping
source[in]the data values passed from the user
cache[out]the mapping data cache previously initialized with initializeMappingDataCache
target[out]preCICE-interal buffer where we store the result
Note
the default implementation in this class simply aborts the code and actual implementations are in derived classes

Reimplemented in precice::mapping::NearestNeighborMapping, and precice::mapping::PartitionOfUnityMapping< RADIAL_BASIS_FUNCTION_T >.

Definition at line 292 of file Mapping.cpp.

◆ mapConsistent()

virtual void precice::mapping::Mapping::mapConsistent ( const time::Sample & input,
Eigen::VectorXd & output )
protectedpure virtual

◆ mapConsistentAt()

void precice::mapping::Mapping::mapConsistentAt ( const Eigen::Ref< const Eigen::MatrixXd > & coordinates,
const impl::MappingDataCache & cache,
Eigen::Ref< Eigen::MatrixXd > values )
virtual

Just-in-time mapping variant of mapConsistent.

Parameters
coordinates[in]where to compute the mapping
cache[in]the mapping data cache previously computed with updateMappingDataCache
values[out]data buffer passed from the user (needs to have the correct shape)
Note
the default implementation in this class simply aborts the code and actual implementations are in derived classes

Reimplemented in precice::mapping::NearestNeighborMapping, and precice::mapping::PartitionOfUnityMapping< RADIAL_BASIS_FUNCTION_T >.

Definition at line 312 of file Mapping.cpp.

◆ operator=()

Mapping & precice::mapping::Mapping::operator= ( Mapping && )
delete

◆ output()

mesh::PtrMesh precice::mapping::Mapping::output ( ) const
protected

Returns pointer to output mesh.

Definition at line 92 of file Mapping.cpp.

◆ requiresGradientData()

bool precice::mapping::Mapping::requiresGradientData ( ) const

Returns whether the mapping requires gradient data.

Definition at line 114 of file Mapping.cpp.

◆ requiresInitialGuess()

bool precice::mapping::Mapping::requiresInitialGuess ( ) const

Return true if the mapping requires an initial guess.

Definition at line 51 of file Mapping.cpp.

◆ scaleConsistentMapping()

void precice::mapping::Mapping::scaleConsistentMapping ( const Eigen::VectorXd & input,
Eigen::VectorXd & output,
Mapping::Constraint constraint ) const
virtual

Scales the consistently mapped output data such that the surface integral of the values on input mesh and output mesh are equal.

Precondition
Input and output mesh should have full connectivity information.

Definition at line 175 of file Mapping.cpp.

Here is the call graph for this function:

◆ setInputRequirement()

void precice::mapping::Mapping::setInputRequirement ( MeshRequirement requirement)
protected

Sets the mesh requirement for the input mesh.

Definition at line 97 of file Mapping.cpp.

◆ setMeshes()

void precice::mapping::Mapping::setMeshes ( const mesh::PtrMesh & input,
const mesh::PtrMesh & output )

Sets input and output meshes carrying data to be mapped.

Parameters
[in]inputMesh with known data values to be mapped.
[in]outputMesh with unknown data values to be computed from input.

Definition at line 28 of file Mapping.cpp.

Here is the call graph for this function:

◆ setOutputRequirement()

void precice::mapping::Mapping::setOutputRequirement ( MeshRequirement requirement)
protected

Sets the mesh requirement for the output mesh.

Definition at line 103 of file Mapping.cpp.

◆ tagMeshFirstRound()

virtual void precice::mapping::Mapping::tagMeshFirstRound ( )
pure virtual

◆ tagMeshSecondRound()

virtual void precice::mapping::Mapping::tagMeshSecondRound ( )
pure virtual

◆ updateMappingDataCache()

void precice::mapping::Mapping::updateMappingDataCache ( impl::MappingDataCache & cache,
const Eigen::Ref< const Eigen::VectorXd > & in )
virtual

Allows updating a so-called MappingDataCache for more efficient just-in-time mappings.

To compute a mapping just-in-time (either with mapConservativeAt or mapConsistentAt ), we first sample in time and then (using this time sample) compute an interpolant in space. Since we typically need to evaluate at a specific point in time for many different locations (potentially corresponding to many different calls of mapConservativeAt or mapConsistentAt ) we would compute the same time interpolant many times. Depending on the mapping method selected, we need to compute further derived data structures and values from the time interpolant (e.g. RBF coefficients) which is computationally demanding. The cache enables to store the latest queried time snapshot and (potentially, depending on the mapping) further derived data structures which remain constant for a specific point in time.

In the default implementation, the cache stores the latest waveform sample in time.

This function updates the cache in use to the provided time-interpolated data ( in ). It is called in the ReadDataContext::mapAndReadValues and called whenever the timestamp of the MappingDataCache is different from the actual 'readTime'. See also the documentation of the impl::MappingDataCache for more information.

Parameters
cachethe cache in use, specific to a particular mapping-data pair
inthe time-interpolated data values

Reimplemented in precice::mapping::PartitionOfUnityMapping< RADIAL_BASIS_FUNCTION_T >.

Definition at line 270 of file Mapping.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ _constraint

Constraint precice::mapping::Mapping::_constraint
private

Determines whether mapping is consistent or conservative.

Definition at line 341 of file Mapping.hpp.

◆ _dimensions

int precice::mapping::Mapping::_dimensions
private

Definition at line 355 of file Mapping.hpp.

◆ _hasComputedMapping

bool precice::mapping::Mapping::_hasComputedMapping = false
protected

Flag to indicate whether computeMapping() has been called.

Definition at line 307 of file Mapping.hpp.

◆ _initialGuess

Eigen::VectorXd* precice::mapping::Mapping::_initialGuess = nullptr
private

Pointer to the initialGuess set and unset by map.

Definition at line 361 of file Mapping.hpp.

◆ _initialGuessRequirement

InitialGuessRequirement precice::mapping::Mapping::_initialGuessRequirement
private

The InitialGuessRequirement of the Mapping.

Definition at line 358 of file Mapping.hpp.

◆ _input

mesh::PtrMesh precice::mapping::Mapping::_input
private

Pointer to input mesh.

Definition at line 350 of file Mapping.hpp.

◆ _inputRequirement

MeshRequirement precice::mapping::Mapping::_inputRequirement
private

Requirement on input mesh.

Definition at line 344 of file Mapping.hpp.

◆ _output

mesh::PtrMesh precice::mapping::Mapping::_output
private

Pointer to output mesh.

Definition at line 353 of file Mapping.hpp.

◆ _outputRequirement

MeshRequirement precice::mapping::Mapping::_outputRequirement
private

Requirement on output mesh.

Definition at line 347 of file Mapping.hpp.

◆ _requiresGradientData

bool precice::mapping::Mapping::_requiresGradientData
protected

Flag if gradient data is required for the mapping.

Definition at line 310 of file Mapping.hpp.


The documentation for this class was generated from the following files: