preCICE v3.2.0
Loading...
Searching...
No Matches
precice::impl::DataContext Class Referenceabstract

Stores one Data object with related mesh. More...

#include <DataContext.hpp>

Inheritance diagram for precice::impl::DataContext:
[legend]
Collaboration diagram for precice::impl::DataContext:
[legend]

Public Member Functions

std::string getDataName () const
 Get the Name of _providedData.
void resetInitialGuesses ()
 Resets initial guesses of transient mappings to zero.
int getDataDimensions () const
 Get the dimensions of _providedData.
int getSpatialDimensions () const
 Get the spatial dimensions of _providedData.
std::string getMeshName () const
 Get the name of _mesh.
MeshID getMeshID () const
 Get the ID of _mesh.
bool hasGradient () const
 Returns whether _providedData has gradient.
int mapData (std::optional< double > after=std::nullopt, bool skipZero=false)
 Perform the mapping for mapping contexts and the corresponding data context (from and to data)
virtual void appendMappingConfiguration (MappingContext &mappingContext, const MeshContext &meshContext)=0
 Adds a MappingContext and the MeshContext required by the mapping to the corresponding DataContext data structures.
bool hasMapping () const
 Informs the user whether this DataContext has any _mappingContext.
template<typename Container>
std::optional< std::size_tlocateInvalidVertexID (const Container &c)
void addJustInTimeMapping (MappingContext &mappingContext, MeshContext &meshContext)
 Attach a just-in-time mapping to this data context and setup a corresponding MappingDataCache.
void initializeMappingDataCache ()
 Initializes the MappingDataCache.
void invalidateMappingCache ()
 Resets the time stamp of the MappingDataCache.
void invalidateMappingCacheAndResetData ()
 Resets the time stamp of the MappingDataCache and resets the data it holds.

Protected Member Functions

 DataContext (mesh::PtrData data, mesh::PtrMesh mesh)
 Construct a new DataContext without a mapping. Protected, because only ReadDataContext and WriteDataContext should use this constructor.
void appendMapping (MappingContext mappingContext)
 Helper to append a mappingContext, fromData and toData to the corresponding data containers.
bool hasReadMapping () const
 Informs the user whether this DataContext has any read mapping.
bool hasWriteMapping () const
 Informs the user whether this DataContext has any write mapping.
int getMeshVertexCount () const
 Get the number of vertices of mesh.
bool isValidVertexID (const VertexID id) const
 Returns true if the given vertexID is valid.

Protected Attributes

std::vector< MappingContext_mappingContexts
 Defines all mappings associated to this DataContext. A DataContext may also exist without a mapping.
mesh::PtrData _providedData
std::unique_ptr< mapping::impl::MappingDataCachemappingCache
 Cache for just-in-time mapping.
mapping::PtrMapping justInTimeMapping
 The just-in-time mapping for this data context.
mesh::PtrMesh _mesh

Private Types

using FromToDataIDs = std::pair<int, int>

Private Attributes

std::map< FromToDataIDs, Eigen::VectorXd > _initialGuesses

Static Private Attributes

static logging::Logger _log {"impl::DataContext"}
 Unique mesh associated with _providedData.

Friends

class testing::DataContextFixture

Detailed Description

Stores one Data object with related mesh.

  • For each mapping that is added to the data context fromData and toData will be set correspondingly. Either fromData or toData must be equal to providedData. fromData and toData must be different.
  • If a DataContext is not associated with a mapping, fromData and toData will be unset.
  • A DataContext can be associated with multiple mappings, fromData and toData

Definition at line 30 of file DataContext.hpp.

Member Typedef Documentation

◆ FromToDataIDs

Definition at line 255 of file DataContext.hpp.

Constructor & Destructor Documentation

◆ DataContext()

precice::impl::DataContext::DataContext ( mesh::PtrData data,
mesh::PtrMesh mesh )
protected

Construct a new DataContext without a mapping. Protected, because only ReadDataContext and WriteDataContext should use this constructor.

Parameters
dataData associated with this DataContext.
meshMesh associated with this DataContext.

Definition at line 12 of file DataContext.cpp.

Member Function Documentation

◆ addJustInTimeMapping()

void precice::impl::DataContext::addJustInTimeMapping ( MappingContext & mappingContext,
MeshContext & meshContext )

Attach a just-in-time mapping to this data context and setup a corresponding MappingDataCache.

A just-in-time mapping ( justInTimeMapping ) might be shared across multiple data contexts (it's a PtrMapping). The MappingDataCache ( mappingCache ), however, is unique for each data context.

There is no need to put this function into a derived class: The Mapping class knows the direction of the mapping and the DataContext is directly called via the API function. Since all mappings within the DataContexts (stored in a std::vector as _mappingContexts ) only call and steer the mapData() execution (and not the computeMapping() execution), we don't register the just-in-time mapping in the _mappingContexts data structures. For just-in-time mappings, only the computeMapping() part is relevant, whereas the mapData() part is essentially handled through the API function calls.

Parameters
[in]mappingContextThe MappingContext which holds the mapping configuration
[in]meshContextThe MeshContext holding the relevant data to map

Definition at line 85 of file DataContext.cpp.

Here is the call graph for this function:

◆ appendMapping()

void precice::impl::DataContext::appendMapping ( MappingContext mappingContext)
protected

Helper to append a mappingContext, fromData and toData to the corresponding data containers.

Parameters
mappingContextMappingContext this DataContext will be associated to.
Note
Only unique mappings may be appended. In case the same mapping is appended twice, an error is raised.

Definition at line 69 of file DataContext.cpp.

Here is the call graph for this function:

◆ appendMappingConfiguration()

virtual void precice::impl::DataContext::appendMappingConfiguration ( MappingContext & mappingContext,
const MeshContext & meshContext )
pure virtual

Adds a MappingContext and the MeshContext required by the mapping to the corresponding DataContext data structures.

A mapping maps the given data from or to _providedData (depending on whether it is a read or write mapping).

Parameters
[in]mappingContextContext of the mapping
[in]meshContextContext of mesh this mapping is mapping from or to

Implemented in precice::impl::ReadDataContext, and precice::impl::WriteDataContext.

◆ getDataDimensions()

int precice::impl::DataContext::getDataDimensions ( ) const

Get the dimensions of _providedData.

Returns
int Dimensions of _providedData.

Definition at line 33 of file DataContext.cpp.

◆ getDataName()

std::string precice::impl::DataContext::getDataName ( ) const

Get the Name of _providedData.

Returns
std::string Name of _providedData.

Definition at line 20 of file DataContext.cpp.

◆ getMeshID()

MeshID precice::impl::DataContext::getMeshID ( ) const

Get the ID of _mesh.

Returns
int ID of _mesh.

Definition at line 57 of file DataContext.cpp.

◆ getMeshName()

std::string precice::impl::DataContext::getMeshName ( ) const

Get the name of _mesh.

Returns
std::string Name of _mesh.

Definition at line 45 of file DataContext.cpp.

◆ getMeshVertexCount()

int precice::impl::DataContext::getMeshVertexCount ( ) const
protected

Get the number of vertices of mesh.

Returns
int number of vertices

Definition at line 51 of file DataContext.cpp.

◆ getSpatialDimensions()

int precice::impl::DataContext::getSpatialDimensions ( ) const

Get the spatial dimensions of _providedData.

Returns
int Spatial dimensions of _providedData.

Definition at line 39 of file DataContext.cpp.

◆ hasGradient()

bool precice::impl::DataContext::hasGradient ( ) const

Returns whether _providedData has gradient.

Returns
true, if it has gradient
false, if it has gradient

Definition at line 63 of file DataContext.cpp.

◆ hasMapping()

bool precice::impl::DataContext::hasMapping ( ) const

Informs the user whether this DataContext has any _mappingContext.

Returns
True, if this DataContext is associated with a mapping. False, if not.

Definition at line 105 of file DataContext.cpp.

Here is the call graph for this function:

◆ hasReadMapping()

bool precice::impl::DataContext::hasReadMapping ( ) const
protected

Informs the user whether this DataContext has any read mapping.

Returns
True, if DataContext has any read mapping.

Definition at line 176 of file DataContext.cpp.

Here is the call graph for this function:

◆ hasWriteMapping()

bool precice::impl::DataContext::hasWriteMapping ( ) const
protected

Informs the user whether this DataContext has any write mapping.

Returns
True, if DataContext has any write mapping.

Definition at line 181 of file DataContext.cpp.

Here is the call graph for this function:

◆ initializeMappingDataCache()

void precice::impl::DataContext::initializeMappingDataCache ( )
inline

Initializes the MappingDataCache.

Essentially a forward to Mapping::initializeMappingDataCache, where we provide the cache from this class itself.

See Mapping::initializeMappingDataCache and the MappingDataCache documentation for more information.

Definition at line 142 of file DataContext.hpp.

◆ invalidateMappingCache()

void precice::impl::DataContext::invalidateMappingCache ( )
inline

Resets the time stamp of the MappingDataCache.

See also the impl::MappingDataCache for more details.

Definition at line 155 of file DataContext.hpp.

◆ invalidateMappingCacheAndResetData()

void precice::impl::DataContext::invalidateMappingCacheAndResetData ( )
inline

Resets the time stamp of the MappingDataCache and resets the data it holds.

See also the impl::MappingDataCache for more details.

Definition at line 167 of file DataContext.hpp.

Here is the call graph for this function:

◆ isValidVertexID()

bool precice::impl::DataContext::isValidVertexID ( const VertexID id) const
protected

Returns true if the given vertexID is valid.

Definition at line 186 of file DataContext.cpp.

◆ locateInvalidVertexID()

template<typename Container>
std::optional< std::size_t > precice::impl::DataContext::locateInvalidVertexID ( const Container & c)
inline

Definition at line 109 of file DataContext.hpp.

Here is the call graph for this function:

◆ mapData()

int precice::impl::DataContext::mapData ( std::optional< double > after = std::nullopt,
bool skipZero = false )

Perform the mapping for mapping contexts and the corresponding data context (from and to data)

Parameters
[in]afteronly map samples after this optional time
[in]skipZeroset output sample to zero if the input sample is zero too
Returns
the number of performed mappings

Definition at line 110 of file DataContext.cpp.

Here is the call graph for this function:

◆ resetInitialGuesses()

void precice::impl::DataContext::resetInitialGuesses ( )

Resets initial guesses of transient mappings to zero.

Definition at line 26 of file DataContext.cpp.

◆ testing::DataContextFixture

friend class testing::DataContextFixture
friend

Definition at line 31 of file DataContext.hpp.

Member Data Documentation

◆ _initialGuesses

std::map<FromToDataIDs, Eigen::VectorXd> precice::impl::DataContext::_initialGuesses
private

Definition at line 256 of file DataContext.hpp.

◆ _log

logging::Logger precice::impl::DataContext::_log {"impl::DataContext"}
staticprivate

Unique mesh associated with _providedData.

Definition at line 253 of file DataContext.hpp.

◆ _mappingContexts

std::vector<MappingContext> precice::impl::DataContext::_mappingContexts
protected

Defines all mappings associated to this DataContext. A DataContext may also exist without a mapping.

Definition at line 185 of file DataContext.hpp.

◆ _mesh

mesh::PtrMesh precice::impl::DataContext::_mesh
protected

Definition at line 248 of file DataContext.hpp.

◆ _providedData

mesh::PtrData precice::impl::DataContext::_providedData
protected

Unique data this context is associated with For direct and just-in-time mapping, this is data from the received mesh

Definition at line 189 of file DataContext.hpp.

◆ justInTimeMapping

mapping::PtrMapping precice::impl::DataContext::justInTimeMapping
protected

The just-in-time mapping for this data context.

Definition at line 213 of file DataContext.hpp.

◆ mappingCache

std::unique_ptr<mapping::impl::MappingDataCache> precice::impl::DataContext::mappingCache
protected

Cache for just-in-time mapping.

Purpose: For just-in-time mapping, we want to pre-compute as much data as possible to not have expensive operations repeated in every read/write call of the mapping class.

The cache itself is updated in the associated Mapping class where it is used. However, storing it in the mapping class is not useful, as we might map multiple data from the same mesh. In preCICE, this leads to one (shared) MappingContext in different DataContexts. Hence, we store the data in this unique Mesh-Data pair.

The _mappingContexts in this class are a std::vector for multiple mappings associated to the same DataContext. However, for one DataContext (read or write) there can only be one just-in-time mapping. For conventional mappings, multiple MappingContexts can only occur in write direction (write to one local mesh, map it to different remote meshes). Since the just-in-time mapping operates on the remote meshes, this multiplicity cannot occur. Thus, one cache per DataContext is enough. See the documentation of impl::MappingDataCache for more information.

Definition at line 210 of file DataContext.hpp.


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