2#include <boost/config.hpp>
14 bool requiresGradientData,
16 : _requiresGradientData(requiresGradientData),
17 _constraint(constraint),
22 _dimensions(dimensions),
23 _initialGuessRequirement(mappingType)
118void Mapping::map(
int inputDataID,
int outputDataID, Eigen::VectorXd &initialGuess)
122 map(inputDataID, outputDataID);
144 input()->data(inputDataID)->values(),
145 input()->data(inputDataID)->gradients()};
146 map(sample,
output()->data(outputDataID)->values());
189 int spaceDimension = this->
input()->getDimensions();
190 bool requiresEdges = (spaceDimension == 2 and !volumeMode);
191 bool requiresTriangles = (spaceDimension == 2 and volumeMode) or (spaceDimension == 3 and !volumeMode);
192 bool requiresTetra = (spaceDimension == 3 and volumeMode);
195 if (not mesh->empty()) {
197 PRECICE_CHECK(!(requiresEdges && mesh->edges().empty()),
"Edges connectivity information is missing for the mesh \"{}\". "
198 "Scaled consistent mapping requires connectivity information.",
201 PRECICE_CHECK(!(requiresTriangles && mesh->triangles().empty()),
"Triangles connectivity information is missing for the mesh \"{}\". "
202 "Scaled consistent mapping requires connectivity information.",
205 PRECICE_CHECK(!(requiresTetra && mesh->tetrahedra().empty()),
"Tetrahedra connectivity information is missing for the mesh \"{}\". "
206 "Scaled consistent mapping requires connectivity information.",
211 const int valueDimensions =
input.size() / this->
input()->nVertices();
213 Eigen::VectorXd integralInput;
214 Eigen::VectorXd integralOutput;
226 Eigen::Map<Eigen::MatrixXd> outputValuesMatrix(
output.data(), valueDimensions,
output.size() / valueDimensions);
232 const Eigen::VectorXd scalingFactor = integralInput.binaryExpr(integralOutput, [](
double lhs,
double rhs) {
return (rhs == 0.0) ? 1.0 : (lhs / rhs); });
233 PRECICE_DEBUG(
"Scaling factor in scaled-consistent mapping: {}", scalingFactor);
235 PRECICE_DEBUG(
"Scaling factor in scaled-consistent mapping: {}", scalingFactor);
236 outputValuesMatrix.array().colwise() *= scalingFactor.array();
239 for (Eigen::Index i = 0; i < scalingFactor.size(); ++i) {
240 double consistency = scalingFactor[i] * integralOutput[i] - integralInput[i];
243 "Failed to fulfill consistency constraint of component {} for scaled-consistent mapping from mesh \"{}\" to mesh \"{}\". Consistency difference between input and scaled output is \"{}\".", i, this->
input()->
getName(), this->
output()->
getName(), consistency);
272 BOOST_UNREACHABLE_RETURN(
false);
#define PRECICE_WARN_IF(condition,...)
#define PRECICE_DEBUG(...)
#define PRECICE_CHECK(check,...)
#define PRECICE_ASSERT(...)
#define PRECICE_UNREACHABLE(...)
This class provides a lightweight logger.
bool requiresInitialGuess() const
Return true if the mapping requires an initial guess.
mesh::PtrMesh output() const
Returns pointer to output mesh.
Eigen::VectorXd & initialGuess()
Constraint _constraint
Determines whether mapping is consistent or conservative.
mesh::PtrMesh _input
Pointer to input mesh.
virtual void mapConsistent(const time::Sample &input, Eigen::VectorXd &output)=0
Maps data using a consistent constraint.
MeshRequirement
Specifies requirements for the input and output meshes of a mapping.
Constraint
Specifies additional constraints for a mapping.
@ SCALED_CONSISTENT_VOLUME
@ SCALED_CONSISTENT_SURFACE
Eigen::VectorXd * _initialGuess
Pointer to the initialGuess set and unset by map.
int getDimensions() const
InitialGuessRequirement _initialGuessRequirement
The InitialGuessRequirement of the Mapping.
void setMeshes(const mesh::PtrMesh &input, const mesh::PtrMesh &output)
Sets input and output meshes carrying data to be mapped.
Mapping(Constraint constraint, int dimensions, bool requiresGradientData, InitialGuessRequirement initialGuessRequirement)
Constructor, takes mapping constraint.
mesh::PtrMesh input() const
Returns pointer to input mesh.
bool _hasComputedMapping
Flag to indicate whether computeMapping() has been called.
Constraint getConstraint() const
Returns the constraint (consistent/conservative) of the mapping.
bool isScaledConsistent() const
Returns true if mapping is a form of scaled consistent mapping.
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...
void setInputRequirement(MeshRequirement requirement)
Sets the mesh requirement for the input mesh.
bool hasInitialGuess() const
True if initialGuess().size() == 0.
mesh::PtrMesh _output
Pointer to output mesh.
bool requiresGradientData() const
Returns whether the mapping requires gradient data.
MeshRequirement _inputRequirement
Requirement on input mesh.
virtual std::string getName() const =0
Returns the name of the mapping method for logging purpose.
virtual void mapConservative(const time::Sample &input, Eigen::VectorXd &output)=0
Maps data using a conservative constraint.
MeshRequirement _outputRequirement
Requirement on output mesh.
const mesh::PtrMesh & getOutputMesh() const
void setOutputRequirement(MeshRequirement requirement)
Sets the mesh requirement for the output mesh.
const Eigen::VectorXd & initialGuess() const
Return the provided initial guess of a mapping using an initialGuess.
bool hasComputedMapping() const
Returns true, if the mapping has been computed.
void map(int inputDataID, int outputDataID)
MeshRequirement getInputRequirement() const
Returns the requirement on the input mesh.
const mesh::PtrMesh & getInputMesh() const
MeshRequirement getOutputRequirement() const
Returns the requirement on the output mesh.
virtual bool hasConstraint(const Constraint &constraint) const
Checks whether the mapping has the given constraint or not.
InitialGuessRequirement
Specifies whether the mapping requires an initial guess.
bool _requiresGradientData
Flag if gradient data is required for the mapping.
static bool isPrimary()
True if this process is running the primary rank.
static bool isSecondary()
True if this process is running a secondary rank.
contains data mapping from points to meshes.
bool operator<(Mapping::MeshRequirement lhs, Mapping::MeshRequirement rhs)
std::ostream & operator<<(std::ostream &out, Mapping::MeshRequirement val)
std::enable_if< std::is_arithmetic< Scalar >::value, bool >::type greater(Scalar A, Scalar B, Scalar tolerance=NUMERICAL_ZERO_DIFFERENCE)
Eigen::VectorXd integrateSurface(const PtrMesh &mesh, const Eigen::VectorXd &input)
Given the data and the mesh, this function returns the surface integral. Assumes no overlap exists fo...
Eigen::VectorXd integrateVolume(const PtrMesh &mesh, const Eigen::VectorXd &input)
Given the data and the mesh, this function returns the volume integral. Assumes no overlap exists for...
static precice::logging::Logger _log("precicec")