42 for (
auto &p : parents) {
43 p.addSubtags(subtags);
50template <
typename TagStorage>
53 for (
auto &s : storage) {
54 for (
auto &a : attributes)
55 std::
visit([&s](auto &&arg) { s.addAttribute(arg); }, a);
60enum struct RBFBackend {
69template <RBFBackend Backend,
typename RBF>
70struct BackendSelector {
75template <
typename RBF>
76struct BackendSelector<RBFBackend::Eigen, RBF> {
77 typedef mapping::RadialBasisFctMapping<RadialBasisFctSolver<RBF>> type;
81#ifndef PRECICE_NO_PETSC
82template <
typename RBF>
83struct BackendSelector<RBFBackend::PETSc, RBF> {
84 typedef mapping::PetRadialBasisFctMapping<RBF> type;
89#ifndef PRECICE_NO_GINKGO
90template <
typename RBF>
91struct BackendSelector<RBFBackend::Ginkgo, RBF> {
92 typedef mapping::RadialBasisFctMapping<GinkgoRadialBasisFctSolver<RBF>, MappingConfiguration::GinkgoParameter> type;
96template <
typename RBF>
97struct BackendSelector<RBFBackend::PUM, RBF> {
98 typedef mapping::PartitionOfUnityMapping<RBF> type;
102using rbf_variant_t =
std::variant<CompactPolynomialC0, CompactPolynomialC2, CompactPolynomialC4, CompactPolynomialC6, CompactPolynomialC8, CompactThinPlateSplinesC2, ThinPlateSplines, VolumeSplines, Multiquadrics, InverseMultiquadrics, Gaussian>;
105template <RBFBackend T,
typename RADIAL_BASIS_FUNCTION_T,
typename... Args>
109 return PtrMapping(
new typename BackendSelector<T, RADIAL_BASIS_FUNCTION_T>::type(constraint, dimension, function, std::forward<Args>(args)...));
113rbf_variant_t constructRBF(
BasisFunction functionType,
double supportRadius,
double shapeParameter)
115 switch (functionType) {
117 return mapping::CompactPolynomialC0(supportRadius);
120 return mapping::CompactPolynomialC2(supportRadius);
123 return mapping::CompactPolynomialC4(supportRadius);
126 return mapping::CompactPolynomialC6(supportRadius);
129 return mapping::CompactPolynomialC8(supportRadius);
157template <RBFBackend T,
typename... Args>
162 auto functionVariant = constructRBF(functionType, supportRadius, shapeParameter);
164 return std::visit([&](
auto &&func) {
return instantiateRBFMapping<T>(constraint, dimension, func, std::forward<Args>(args)...); }, functionVariant);
171 : _meshConfig(
std::move(meshConfiguration))
177 XMLTag::Occurrence occ = XMLTag::OCCUR_ARBITRARY;
179 XMLTag{*
this,
TYPE_NEAREST_NEIGHBOR, occ,
TAG}.setDocumentation(
"Nearest-neighbour mapping which uses a rstar-spacial index tree to index meshes and run nearest-neighbour queries."),
180 XMLTag{*
this,
TYPE_NEAREST_PROJECTION, occ,
TAG}.setDocumentation(
"Nearest-projection mapping which uses a rstar-spacial index tree to index meshes and locate the nearest projections."),
181 XMLTag{*
this,
TYPE_NEAREST_NEIGHBOR_GRADIENT, occ,
TAG}.setDocumentation(
"Nearest-neighbor-gradient mapping which uses nearest-neighbor mapping with an additional linear approximation using gradient data."),
182 XMLTag{*
this,
TYPE_LINEAR_CELL_INTERPOLATION, occ,
TAG}.setDocumentation(
"Linear cell interpolation mapping which uses a rstar-spacial index tree to index meshes and locate the nearest cell. Only supports 2D meshes.")};
184 XMLTag{*
this,
TYPE_RBF_GLOBAL_DIRECT, occ,
TAG}.setDocumentation(
"Radial-basis-function mapping using a direct solver with a gather-scatter parallelism.")};
186 XMLTag{*
this,
TYPE_RBF_GLOBAL_ITERATIVE, occ,
TAG}.setDocumentation(
"Radial-basis-function mapping using an iterative solver with a distributed parallelism.")};
188 XMLTag{*
this,
TYPE_RBF_PUM_DIRECT, occ,
TAG}.setDocumentation(
"Radial-basis-function mapping using a partition of unity method, which supports a distributed parallelism.")};
190 XMLTag{*
this,
TYPE_RBF_ALIAS, occ,
TAG}.setDocumentation(
"Alias tag, which auto-selects a radial-basis-function mapping depending on the simulation parameter,")};
193 XMLTag{*
this,
TYPE_RADIAL_GEOMETRIC_MULTISCALE, occ,
TAG}.setDocumentation(
"Radial geometric multiscale mapping between multiple 1D and multiple 3D vertices, distributed along a principle axis.")};
198 .setDocumentation(
"Write mappings map written data prior to communication, thus in the same participant who writes the data. "
199 "Read mappings map received data after communication, thus in the same participant who reads the data.");
201 auto attrFromMesh = XMLAttribute<std::string>(
ATTR_FROM)
202 .setDocumentation(
"The mesh to map the data from.");
204 auto attrToMesh = XMLAttribute<std::string>(
ATTR_TO)
205 .setDocumentation(
"The mesh to map the data to.");
208 .setDocumentation(
"Use conservative to conserve the nodal sum of the data over the interface (needed e.g. for force mapping). Use consistent for normalized quantities such as temperature or pressure. Use scaled-consistent-surface or scaled-consistent-volume for normalized quantities where conservation of integral values (surface or volume) is needed (e.g. velocities when the mass flow rate needs to be conserved). Mesh connectivity is required to use scaled-consistent.")
210 auto attrXDead = makeXMLAttribute(
ATTR_X_DEAD,
false)
211 .
setDocumentation(
"If set to true, the x axis will be ignored for the mapping");
212 auto attrYDead = makeXMLAttribute(
ATTR_Y_DEAD,
false)
213 .
setDocumentation(
"If set to true, the y axis will be ignored for the mapping");
214 auto attrZDead = makeXMLAttribute(
ATTR_Z_DEAD,
false)
215 .
setDocumentation(
"If set to true, the z axis will be ignored for the mapping");
230 .
setDocumentation(
"Average number of vertices per cluster (partition) applied in the rbf partition of unity method.");
232 .
setDocumentation(
"Value between 0 and 1 indicating the relative overlap between clusters. A value of 0.15 is usually a good trade-off between accuracy and efficiency.");
234 .
setDocumentation(
"If enabled, places the cluster centers at the closest vertex of the input mesh. Should be enabled in case of non-uniform point distributions such as for shell structures.");
237 .
setDocumentation(
"Type of geometric multiscale mapping. Either 'spread' or 'collect'.")
240 .
setDocumentation(
"Principle axis along which geometric multiscale mapping is performed.")
243 .
setDocumentation(
"Radius of the circular interface between the 1D and 3D participant.");
246 addAttributes(projectionTags, {attrFromMesh, attrToMesh, attrDirection, attrConstraint});
247 addAttributes(rbfDirectTags, {attrFromMesh, attrToMesh, attrDirection, attrConstraint, attrPolynomial, attrXDead, attrYDead, attrZDead});
248 addAttributes(rbfIterativeTags, {attrFromMesh, attrToMesh, attrDirection, attrConstraint, attrPolynomial, attrXDead, attrYDead, attrZDead, attrSolverRtol});
249 addAttributes(pumDirectTags, {attrFromMesh, attrToMesh, attrDirection, attrConstraint, attrPumPolynomial, verticesPerCluster, relativeOverlap, projectToInput});
250 addAttributes(rbfAliasTag, {attrFromMesh, attrToMesh, attrDirection, attrConstraint, attrXDead, attrYDead, attrZDead});
251 addAttributes(geoMultiscaleTags, {attrFromMesh, attrToMesh, attrDirection, attrConstraint, attrGeoMultiscaleType, attrGeoMultiscaleAxis, attrGeoMultiscaleRadius});
254 XMLTag::Occurrence once = XMLTag::OCCUR_NOT_OR_ONCE;
256 auto attrDeviceId = makeXMLAttribute(
ATTR_DEVICE_ID,
static_cast<int>(0))
257 .
setDocumentation(
"Specifies the ID of the GPU that should be used for the Ginkgo GPU backend.");
258 auto attrNThreads = makeXMLAttribute(
ATTR_N_THREADS,
static_cast<int>(0))
259 .
setDocumentation(
"Specifies the number of threads for the OpenMP executor that should be used for the Ginkgo OpenMP backend. If a value of \"0\" is set, preCICE doesn't set the number of threads and the default behavior of OpenMP applies.");
264 XMLTag{*
this,
EXECUTOR_CPU, once,
SUBTAG_EXECUTOR}.setDocumentation(
"The default executor, which uses a single-core CPU with a gather-scatter parallelism.")};
266 XMLTag{*
this,
EXECUTOR_CUDA, once,
SUBTAG_EXECUTOR}.setDocumentation(
"Cuda (Nvidia) executor, which uses cuSolver/Ginkgo and a direct QR decomposition with a gather-scatter parallelism."),
267 XMLTag{*
this,
EXECUTOR_HIP, once,
SUBTAG_EXECUTOR}.setDocumentation(
"Hip (AMD/Nvidia) executor, which uses hipSolver/Ginkgo and a direct QR decomposition with a gather-scatter parallelism.")};
269 addAttributes(deviceExecutors, {attrDeviceId});
270 addSubtagsToParents(cpuExecutor, rbfDirectTags);
271 addSubtagsToParents(deviceExecutors, rbfDirectTags);
276 XMLTag{*
this,
EXECUTOR_CPU, once,
SUBTAG_EXECUTOR}.setDocumentation(
"The default executor relying on PETSc, which uses CPUs and distributed memory parallelism via MPI.")};
278 XMLTag{*
this,
EXECUTOR_CUDA, once,
SUBTAG_EXECUTOR}.setDocumentation(
"Cuda (Nvidia) executor, which uses Ginkgo with a gather-scatter parallelism."),
279 XMLTag{*
this,
EXECUTOR_HIP, once,
SUBTAG_EXECUTOR}.setDocumentation(
"Hip (AMD/Nvidia) executor, which uses hipSolver with a gather-scatter parallelism.")};
281 XMLTag{*
this,
EXECUTOR_OMP, once,
SUBTAG_EXECUTOR}.setDocumentation(
"OpenMP executor, which uses Ginkgo with a gather-scatter parallelism.")};
283 addAttributes(deviceExecutors, {attrDeviceId});
284 addAttributes(ompExecutor, {attrNThreads});
285 addSubtagsToParents(cpuExecutor, rbfIterativeTags);
286 addSubtagsToParents(deviceExecutors, rbfIterativeTags);
287 addSubtagsToParents(ompExecutor, rbfIterativeTags);
291 XMLTag{*
this,
EXECUTOR_CPU, once,
SUBTAG_EXECUTOR}.setDocumentation(
"The default (and currently only) executor using a CPU and a distributed memory parallelism via MPI.")};
292 addSubtagsToParents(cpuExecutor, pumDirectTags);
307 .setDocumentation(
"Support radius of each RBF basis function (global choice).");
309 addAttributes(supportRadiusRBF, {attrSupportRadius});
310 addSubtagsToParents(supportRadiusRBF, rbfIterativeTags);
311 addSubtagsToParents(supportRadiusRBF, rbfDirectTags);
312 addSubtagsToParents(supportRadiusRBF, pumDirectTags);
313 addSubtagsToParents(supportRadiusRBF, rbfAliasTag);
321 .setDocumentation(
"Specific shape parameter for RBF basis function.");
323 addAttributes(shapeParameterRBF, {attrShapeParam});
324 addSubtagsToParents(shapeParameterRBF, rbfIterativeTags);
325 addSubtagsToParents(shapeParameterRBF, rbfDirectTags);
326 addSubtagsToParents(shapeParameterRBF, pumDirectTags);
327 addSubtagsToParents(shapeParameterRBF, rbfAliasTag);
334 addAttributes(GaussRBF, {attrShapeParam, attrSupportRadius});
335 addSubtagsToParents(GaussRBF, rbfIterativeTags);
336 addSubtagsToParents(GaussRBF, rbfDirectTags);
337 addSubtagsToParents(GaussRBF, pumDirectTags);
338 addSubtagsToParents(GaussRBF, rbfAliasTag);
345 addSubtagsToParents(attributelessRBFs, rbfIterativeTags);
346 addSubtagsToParents(attributelessRBFs, rbfDirectTags);
347 addSubtagsToParents(attributelessRBFs, pumDirectTags);
348 addSubtagsToParents(attributelessRBFs, rbfAliasTag);
393 PRECICE_CHECK(
_experimental,
"Axial geometric multiscale is experimental and the configuration can change between minor releases. Set experimental=\"on\" in the precice-configuration tag.");
397 throw std::runtime_error{
"Axial geometric multiscale mapping is not available for parallel participants."};
401 throw std::runtime_error{
"Radial geometric multiscale mapping is not available for parallel participants."};
431 PRECICE_CHECK(
_mappings.back().requiresBasisFunction ==
true,
"A basis-function was defined for the mapping "
432 "from mesh \"{}\" to mesh \"{}\", but no basis-function is required for this mapping type. "
433 "Please remove the basis-function tag or configure an rbf mapping, which requires a basis-function.",
437 "from mesh \"{}\" to mesh \"{}\".",
450 PRECICE_CHECK(exactlyOneSet,
"The specified parameters for the Gaussian RBF mapping are invalid. Please specify either a \"shape-parameter\" or a \"support-radius\".");
479 bool xDead,
bool yDead,
bool zDead,
481 double verticesPerCluster,
482 double relativeOverlap,
483 bool projectToInput)
const
528 const double & multiscaleRadius)
const
536 "Mesh \"{0}\" was not found while creating a mapping. "
537 "Please correct the from=\"{0}\" attribute.",
540 "Mesh \"{0}\" was not found while creating a mapping. "
541 "Please correct the to=\"{0}\" attribute.",
545 PRECICE_CHECK(fromMesh->getDimensions() == toMesh->getDimensions(),
546 "Mapping between meshes of different dimensions is not allowed yet. "
547 "Please set the same dimensions attribute to meshes \"{}\" and \"{}\", "
548 "or choose different meshes.",
549 fromMeshName, toMeshName);
551 configuredMapping.
fromMesh = fromMesh;
552 configuredMapping.
toMesh = toMesh;
573 "Nearest-neighbor-gradient mapping is not implemented using a \"conservative\" constraint. "
574 "Please select constraint=\" consistent\" or a different mapping method.");
582 "Axial geometric multiscale mapping is not implemented for the \"conservative\" constraint. "
583 "Please select constraint=\" consistent\" or a different mapping method.");
587 if (geoMultiscaleAxis ==
"x") {
589 }
else if (geoMultiscaleAxis ==
"y") {
591 }
else if (geoMultiscaleAxis ==
"z") {
598 if (geoMultiscaleType ==
"spread") {
600 }
else if (geoMultiscaleType ==
"collect") {
612 "Radial geometric multiscale mapping is not implemented for the \"conservative\" constraint. "
613 "Please select constraint=\" consistent\" or a different mapping method.");
617 if (geoMultiscaleAxis ==
"x") {
619 }
else if (geoMultiscaleAxis ==
"y") {
621 }
else if (geoMultiscaleAxis ==
"z") {
628 if (geoMultiscaleType ==
"spread") {
630 }
else if (geoMultiscaleType ==
"collect") {
641 configuredMapping.
mapping =
nullptr;
647 return configuredMapping;
653 bool sameToMesh = mapping.
toMesh->getName() == configuredMapping.toMesh->getName();
654 bool sameFromMesh = mapping.
fromMesh->getName() == configuredMapping.fromMesh->getName();
655 bool sameMapping = sameToMesh && sameFromMesh;
657 "There cannot be two mappings from mesh \"{}\" to mesh \"{}\". "
658 "Please remove one of the duplicated meshes. ",
689#ifndef PRECICE_NO_PETSC
695 PRECICE_CHECK(
false,
"The global-iterative RBF solver on a CPU requires a preCICE build with PETSc enabled.");
704#ifndef PRECICE_NO_GINKGO
710#ifndef PRECICE_WITH_CUDA
711 PRECICE_CHECK(
false,
"The cuda-executor (configured for the mapping from mesh {} to mesh {}) requires a Ginkgo and preCICE build with Cuda enabled.", mapping.
fromMesh->getName(), mapping.
toMesh->getName());
715#ifndef PRECICE_WITH_HIP
716 PRECICE_CHECK(
false,
"The hip-executor (configured for the mapping from mesh {} to mesh {}) requires a Ginkgo and preCICE build with HIP enabled.", mapping.
fromMesh->getName(), mapping.
toMesh->getName());
721#ifndef PRECICE_WITH_OMP
722 PRECICE_CHECK(
false,
"The omp-executor (configured for the mapping from mesh {} to mesh {}) requires a Ginkgo and preCICE build with OpenMP enabled.", mapping.
fromMesh->getName(), mapping.
toMesh->getName());
735 PRECICE_CHECK(
false,
"The selected executor for the mapping from mesh {} to mesh {} requires a preCICE build with Ginkgo enabled.", mapping.
fromMesh->getName(), mapping.
toMesh->getName());
777 return basisFunction;
#define PRECICE_TRACE(...)
#define PRECICE_CHECK(check,...)
#define PRECICE_ASSERT(...)
#define PRECICE_UNREACHABLE(...)
Geometric multiscale mapping in axial direction.
MultiscaleType
Geometric multiscale nature of the mapping (spread or collect).
static constexpr double cutoffThreshold
Below that value the function is supposed to be zero. Defines the support radius if not explicitly gi...
Mapping using orthogonal projection to nearest triangle/edge/vertex and linear interpolation from pro...
const std::string ATTR_TO
virtual void xmlEndTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag)
Callback function required for use of automatic configuration.
RBFConfiguration configureRBFMapping(const std::string &type, const std::string &polynomial, bool xDead, bool yDead, bool zDead, double solverRtol, double verticesPerCluster, double relativeOverlap, bool projectToInput) const
const std::string GEOMETRIC_MULTISCALE_AXIS_X
const std::string SUBTAG_BASIS_FUNCTION
const std::string ATTR_VERTICES_PER_CLUSTER
const std::string TYPE_RBF_PUM_DIRECT
const std::string RBF_CPOLYNOMIAL_C2
const std::string ATTR_X_DEAD
const std::string SUBTAG_EXECUTOR
virtual void xmlTagCallback(const xml::ConfigurationContext &context, xml::XMLTag &callingTag)
Callback function required for use of automatic configuration.
const std::vector< ConfiguredMapping > & mappings()
Returns all configured mappings.
GinkgoParameter _ginkgoParameter
const std::string ATTR_DIRECTION
const std::string RBF_VOLUME_SPLINES
Mapping::Constraint constraintValue
const std::string DIRECTION_WRITE
const std::string ATTR_SOLVER_RTOL
mesh::PtrMeshConfiguration _meshConfig
const std::string EXECUTOR_HIP
const std::string DIRECTION_READ
const std::string POLYNOMIAL_OFF
std::unique_ptr< ExecutorConfiguration > _executorConfig
const std::string ATTR_Y_DEAD
const std::string RBF_MULTIQUADRICS
const std::string RBF_CPOLYNOMIAL_C4
const std::string ATTR_SHAPE_PARAM
const std::string CONSTRAINT_SCALED_CONSISTENT_VOLUME
const std::string EXECUTOR_CPU
const std::string TYPE_RBF_ALIAS
const std::string TYPE_RBF_GLOBAL_DIRECT
const std::string ATTR_PROJECT_TO_INPUT
const std::string GEOMETRIC_MULTISCALE_AXIS_Z
bool requiresBasisFunction(const std::string &mappingType) const
const std::string RBF_CPOLYNOMIAL_C6
const std::string TYPE_AXIAL_GEOMETRIC_MULTISCALE
BasisFunction parseBasisFunctions(const std::string &basisFctName) const
Given a basis function name (as a string), transforms the string into an enum of the BasisFunction.
const std::string RBF_TPS
const std::string ATTR_DEVICE_ID
void finishRBFConfiguration()
const std::string RBF_CPOLYNOMIAL_C0
const std::string CONSTRAINT_CONSISTENT
RBFConfiguration _rbfConfig
const std::string TYPE_RBF_GLOBAL_ITERATIVE
const std::string ATTR_RELATIVE_OVERLAP
const std::string ATTR_GEOMETRIC_MULTISCALE_AXIS
const std::string TYPE_LINEAR_CELL_INTERPOLATION
const std::string GEOMETRIC_MULTISCALE_AXIS_Y
const std::string RBF_GAUSSIAN
std::vector< ConfiguredMapping > _mappings
const std::string ATTR_CONSTRAINT
const std::string TYPE_NEAREST_NEIGHBOR
const std::string ATTR_Z_DEAD
const std::string EXECUTOR_CUDA
const std::string ATTR_GEOMETRIC_MULTISCALE_TYPE
const std::string ATTR_SUPPORT_RADIUS
ConfiguredMapping createMapping(const std::string &direction, const std::string &type, const std::string &fromMeshName, const std::string &toMeshName, const std::string &geoMultiscaleType, const std::string &geoMultiscaleAxis, const double &multiscaleRadius) const
void checkDuplicates(const ConfiguredMapping &mapping)
Check whether a mapping to and from the same mesh already exists.
const std::string TYPE_NEAREST_PROJECTION
const std::string RBF_CPOLYNOMIAL_C8
const std::string POLYNOMIAL_ON
const std::string ATTR_N_THREADS
const std::string ATTR_POLYNOMIAL
const std::string POLYNOMIAL_SEPARATE
const std::string TYPE_NEAREST_NEIGHBOR_GRADIENT
const std::string RBF_INV_MULTIQUADRICS
const RBFConfiguration & rbfConfig() const
const std::string TYPE_RADIAL_GEOMETRIC_MULTISCALE
const std::string RBF_CTPS_C2
MappingConfiguration(xml::XMLTag &parent, mesh::PtrMeshConfiguration meshConfiguration)
const std::string GEOMETRIC_MULTISCALE_TYPE_SPREAD
const std::string CONSTRAINT_CONSERVATIVE
const std::string ATTR_FROM
const std::string EXECUTOR_OMP
void setExperimental(bool experimental)
const std::string ATTR_GEOMETRIC_MULTISCALE_RADIUS
const std::string CONSTRAINT_SCALED_CONSISTENT_SURFACE
const std::string GEOMETRIC_MULTISCALE_TYPE_COLLECT
Constraint
Specifies additional constraints for a mapping.
@ SCALED_CONSISTENT_VOLUME
@ SCALED_CONSISTENT_SURFACE
Mapping using nearest neighboring vertices and their local gradient values.
Mapping using nearest neighboring vertices.
Mapping using orthogonal projection to nearest triangle/edge/vertex and linear interpolation from pro...
Geometric multiscale mapping in radial direction.
MultiscaleType
Geometric multiscale type of the mapping (spread or collect).
static CommStatePtr current()
Returns an owning pointer to the current CommState.
static void initialize(utils::Parallel::Communicator comm)
Initializes the Petsc environment.
XMLAttribute & setOptions(std::vector< ATTRIBUTE_T > options)
const std::string & getName() const
XMLAttribute & setDocumentation(std::string documentation)
Sets a documentation string for the attribute.
Represents an XML tag to be configured automatically.
const std::string & getNamespace() const
Returns xml namespace.
void addSubtags(const Container &subtags)
std::string getStringAttributeValue(const std::string &name, std::optional< std::string > default_value=std::nullopt) const
bool getBooleanAttributeValue(const std::string &name, std::optional< bool > default_value=std::nullopt) const
const std::string & getName() const
Returns name (without namespace).
int getIntAttributeValue(const std::string &name, std::optional< int > default_value=std::nullopt) const
double getDoubleAttributeValue(const std::string &name, std::optional< double > default_value=std::nullopt) const
contains data mapping from points to meshes.
@ CompactThinPlateSplinesC2
std::shared_ptr< Mapping > PtrMapping
bool basisFunctionDefined
std::array< bool, 3 > deadAxis
BasisFunction basisFunction
Tightly coupled to the parameters of Participant()