16 #if !defined(KRATOS_MAPPER_FACTORY_H_INCLUDED )
17 #define KRATOS_MAPPER_FACTORY_H_INCLUDED
20 #include <unordered_map>
43 template<
class TSparseSpace,
class TDenseSpace>
69 ModelPart& r_interface_model_part_origin = GetInterfaceModelPart(rModelPartOrigin, MapperSettings,
"origin");
70 ModelPart& r_interface_model_part_destination = GetInterfaceModelPart(rModelPartDestination, MapperSettings,
"destination");
72 KRATOS_ERROR_IF(!TSparseSpace::IsDistributed() && (r_interface_model_part_origin.
IsDistributed() || r_interface_model_part_destination.
IsDistributed())) <<
"Trying to construct a non-MPI Mapper with a distributed ModelPart. Please use \"CreateMPIMapper\" instead!" << std::endl;
74 KRATOS_ERROR_IF(TSparseSpace::IsDistributed() && !r_interface_model_part_origin.
IsDistributed() && !r_interface_model_part_destination.
IsDistributed()) <<
"Trying to construct a MPI Mapper without a distributed ModelPart. Please use \"CreateMapper\" instead!" << std::endl;
76 const std::string mapper_name = MapperSettings[
"mapper_type"].
GetString();
78 const auto& mapper_list = GetRegisteredMappersList();
80 if (mapper_list.find(mapper_name) != mapper_list.end()) {
83 MapperSettings.
RemoveValue(
"interface_submodel_part_origin");
84 MapperSettings.
RemoveValue(
"interface_submodel_part_destination");
87 return mapper_list.at(mapper_name)->Clone(r_interface_model_part_origin,
88 r_interface_model_part_destination,
93 err_msg <<
"The requested Mapper \"" << mapper_name <<
"\" is not not available!\n"
94 <<
"The following Mappers are available:" << std::endl;
96 for (
auto const& registered_mapper : mapper_list)
97 err_msg <<
"\t" << registered_mapper.first <<
"\n";
103 static void Register(
const std::string& rMapperName,
106 GetRegisteredMappersList().insert(
107 std::make_pair(rMapperName, pMapperPrototype));
112 const auto& mapper_list = GetRegisteredMappersList();
113 return mapper_list.find(rMapperName) != mapper_list.end();
118 const auto& mapper_list = GetRegisteredMappersList();
120 std::vector<std::string> mapper_names;
122 mapper_names.reserve(mapper_list.size());
123 for (
auto const& r_registered_mapper : mapper_list) {
124 mapper_names.push_back(r_registered_mapper.first);
135 virtual std::string
Info()
const
137 std::stringstream buffer;
138 buffer <<
"MapperFactory" ;
145 rOStream <<
"MapperFactory";
160 static ModelPart& GetInterfaceModelPart(ModelPart& rModelPart,
161 const Parameters InterfaceParameters,
162 const std::string& InterfaceSide)
164 const int echo_level = InterfaceParameters.Has(
"echo_level") ? InterfaceParameters[
"echo_level"].GetInt() : 0;
166 const std::string key_sub_model_part =
"interface_submodel_part_" + InterfaceSide;
168 if (InterfaceParameters.Has(key_sub_model_part)) {
169 const std::string name_interface_submodel_part = rModelPart.FullName() +
"." + InterfaceParameters[key_sub_model_part].GetString();
170 KRATOS_INFO_IF(
"MapperFactory",
echo_level >= 3) <<
"Mapper: SubModelPart used for " << InterfaceSide <<
"-ModelPart" << std::endl;
172 return rModelPart.GetModel().GetModelPart(name_interface_submodel_part);
174 KRATOS_INFO_IF(
"MapperFactory",
echo_level >= 3) <<
"Mapper: Main ModelPart used for " << InterfaceSide <<
"-ModelPart" << std::endl;
180 static std::unordered_map<std::string,
typename Mapper<TSparseSpace,
181 TDenseSpace>::Pointer>& GetRegisteredMappersList();
Python Interface of the MappingApplication.
Definition: mapper_factory.h:45
virtual ~MapperFactory()=default
Destructor.
KRATOS_CLASS_POINTER_DEFINITION(MapperFactory)
Pointer definition of MapperFactory.
static Mapper< TSparseSpace, TDenseSpace >::Pointer CreateMapper(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination, Parameters MapperSettings)
Definition: mapper_factory.h:64
virtual std::string Info() const
Turn back information as a string.
Definition: mapper_factory.h:135
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: mapper_factory.h:149
static bool HasMapper(const std::string &rMapperName)
Definition: mapper_factory.h:110
static std::vector< std::string > GetRegisteredMapperNames()
Definition: mapper_factory.h:116
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: mapper_factory.h:143
static void Register(const std::string &rMapperName, typename Mapper< TSparseSpace, TDenseSpace >::Pointer pMapperPrototype)
Definition: mapper_factory.h:103
Base Class for all Mappers.
Definition: mapper.h:43
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
bool IsDistributed() const
Definition: model_part.h:1898
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
bool RemoveValue(const std::string &rEntry)
This method removes an entry of the Parameters given a certain key.
Definition: kratos_parameters.cpp:482
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Mapper
Definition: MappingApplication.py:39
MapperFactory
Definition: MappingApplication.py:40
string err_msg
Definition: fluid_chimera_analysis.py:21
echo_level
Definition: script.py:68