KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
barycentric_mapper.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Philipp Bucher (https://github.com/philbucher)
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
23 
24 namespace Kratos
25 {
28 
30  LINE,
31  TRIANGLE,
33 };
34 
35 class KRATOS_API(MAPPING_APPLICATION) BarycentricInterfaceInfo : public MapperInterfaceInfo
36 {
37 public:
38  explicit BarycentricInterfaceInfo(const BarycentricInterpolationType InterpolationType);
39 
40  explicit BarycentricInterfaceInfo(const CoordinatesArrayType& rCoordinates,
41  const IndexType SourceLocalSystemIndex,
42  const IndexType SourceRank,
43  const BarycentricInterpolationType InterpolationType);
44 
45  MapperInterfaceInfo::Pointer Create() const override;
46 
47  MapperInterfaceInfo::Pointer Create(const CoordinatesArrayType& rCoordinates,
48  const IndexType SourceLocalSystemIndex,
49  const IndexType SourceRank) const override;
50 
51  InterfaceObject::ConstructionType GetInterfaceObjectType() const override;
52 
53  void ProcessSearchResult(const InterfaceObject& rInterfaceObject) override;
54 
55  BarycentricInterpolationType GetInterpolationType() const { return mInterpolationType; }
56 
57  const ClosestPointsContainer& GetClosestPoints() const { return mClosestPoints; }
58 
59  std::size_t GetNumSearchResults() const { return mNumSearchResults; }
60 
61 private:
62  BarycentricInterpolationType mInterpolationType;
63  ClosestPointsContainer mClosestPoints;
64  std::size_t mNumSearchResults = 0;
65 
66  friend class Serializer;
67 
68  void save(Serializer& rSerializer) const override;
69 
70  void load(Serializer& rSerializer) override;
71 };
72 
73 class KRATOS_API(MAPPING_APPLICATION) BarycentricLocalSystem : public MapperLocalSystem
74 {
75 public:
76 
77  explicit BarycentricLocalSystem(NodePointerType pNode) : mpNode(pNode) {}
78 
79  void CalculateAll(MatrixType& rLocalMappingMatrix,
80  EquationIdVectorType& rOriginIds,
81  EquationIdVectorType& rDestinationIds,
82  MapperLocalSystem::PairingStatus& rPairingStatus) const override;
83 
85  {
86  KRATOS_DEBUG_ERROR_IF_NOT(mpNode) << "Members are not intitialized!" << std::endl;
87  return mpNode->Coordinates();
88  }
89 
91  {
92  return Kratos::make_unique<BarycentricLocalSystem>(pNode);
93  }
94 
95  void PairingInfo(std::ostream& rOStream, const int EchoLevel) const override;
96 
97  void SetPairingStatusForPrinting() override;
98 
99  bool IsDoneSearching() const override;
100 
101 private:
102  NodePointerType mpNode;
104 
105 };
106 
108 template<class TSparseSpace, class TDenseSpace, class TMapperBackend>
109 class KRATOS_API(MAPPING_APPLICATION) BarycentricMapper
110  : public InterpolativeMapperBase<TSparseSpace, TDenseSpace, TMapperBackend>
111 {
112 public:
113 
116 
121 
125 
129 
130  // Default constructor, needed for registration
131  BarycentricMapper(ModelPart& rModelPartOrigin,
132  ModelPart& rModelPartDestination)
133  : BaseType(rModelPartOrigin, rModelPartDestination) {}
134 
135  BarycentricMapper(ModelPart& rModelPartOrigin,
136  ModelPart& rModelPartDestination,
137  Parameters JsonParameters)
138  : BaseType(rModelPartOrigin,
139  rModelPartDestination,
140  JsonParameters)
141  {
142  KRATOS_TRY;
143 
144  auto check_has_nodes = [](const ModelPart& rModelPart){
145  if (rModelPart.GetCommunicator().GetDataCommunicator().IsDefinedOnThisRank()) {
146  KRATOS_ERROR_IF(rModelPart.GetCommunicator().GlobalNumberOfNodes() == 0) << "No nodes exist in ModelPart \"" << rModelPart.FullName() << "\"" << std::endl;
147  }
148  };
149  check_has_nodes(rModelPartOrigin);
150  check_has_nodes(rModelPartDestination);
151 
152  this->ValidateInput();
153 
154  const std::string interpolation_type = JsonParameters["interpolation_type"].GetString();
155  if (interpolation_type == "line") {
156  mInterpolationType = BarycentricInterpolationType::LINE;
157  } else if (interpolation_type == "triangle") {
158  mInterpolationType = BarycentricInterpolationType::TRIANGLE;
159  } else if (interpolation_type == "tetrahedra") {
160  mInterpolationType = BarycentricInterpolationType::TETRAHEDRA;
161  } else {
162  KRATOS_ERROR << "BarycentricMapper: No \"interpolation_type\" was specified, please select \"line\", \"triangle\" or \"tetrahedra\"" << std::endl;
163  }
164 
165  this->Initialize();
166 
167  KRATOS_CATCH("");
168  }
169 
171  ~BarycentricMapper() override = default;
172 
176 
178  ModelPart& rModelPartDestination,
179  Parameters JsonParameters) const override
180  {
181  KRATOS_TRY;
182 
183  return Kratos::make_unique<BarycentricMapper<TSparseSpace, TDenseSpace, TMapperBackend>>(
184  rModelPartOrigin,
185  rModelPartDestination,
186  JsonParameters);
187 
188  KRATOS_CATCH("");
189  }
190 
194 
196  std::string Info() const override
197  {
198  return "BarycentricMapper";
199  }
200 
202  void PrintInfo(std::ostream& rOStream) const override
203  {
204  rOStream << "BarycentricMapper";
205  }
206 
208  void PrintData(std::ostream& rOStream) const override
209  {
210  BaseType::PrintData(rOStream);
211  }
212 
213 private:
216 
217  BarycentricInterpolationType mInterpolationType;
218 
220 
223 
224  void CreateMapperLocalSystems(
225  const Communicator& rModelPartCommunicator,
226  std::vector<Kratos::unique_ptr<MapperLocalSystem>>& rLocalSystems) override
227  {
229  BarycentricLocalSystem(nullptr),
230  rModelPartCommunicator,
231  rLocalSystems);
232  }
233 
234  MapperInterfaceInfoUniquePointerType GetMapperInterfaceInfo() const override
235  {
236  return Kratos::make_unique<BarycentricInterfaceInfo>(mInterpolationType);
237  }
238 
239  Parameters GetMapperDefaultSettings() const override
240  {
241  return Parameters( R"({
242  "search_settings" : {},
243  "interpolation_type" : "unspecified",
244  "local_coord_tolerance" : 0.25,
245  "use_initial_configuration" : false,
246  "echo_level" : 0,
247  "print_pairing_status_to_file" : false,
248  "pairing_status_file_path" : ""
249  })");
250  }
251 
253 
254 }; // Class BarycentricMapper
255 
257 } // namespace Kratos.
Definition: barycentric_mapper.h:36
std::size_t GetNumSearchResults() const
Definition: barycentric_mapper.h:59
const ClosestPointsContainer & GetClosestPoints() const
Definition: barycentric_mapper.h:57
BarycentricInterpolationType GetInterpolationType() const
Definition: barycentric_mapper.h:55
Definition: barycentric_mapper.h:74
BarycentricLocalSystem(NodePointerType pNode)
Definition: barycentric_mapper.h:77
MapperLocalSystemUniquePointer Create(NodePointerType pNode) const override
Definition: barycentric_mapper.h:90
CoordinatesArrayType & Coordinates() const override
Definition: barycentric_mapper.h:84
Barycentric Mapper.
Definition: barycentric_mapper.h:111
KRATOS_CLASS_POINTER_DEFINITION(BarycentricMapper)
std::string Info() const override
Turn back information as a string.
Definition: barycentric_mapper.h:196
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: barycentric_mapper.h:202
InterpolativeMapperBase< TSparseSpace, TDenseSpace, TMapperBackend > BaseType
Definition: barycentric_mapper.h:122
BaseType::MapperInterfaceInfoUniquePointerType MapperInterfaceInfoUniquePointerType
Definition: barycentric_mapper.h:124
BaseType::MapperUniquePointerType MapperUniquePointerType
Definition: barycentric_mapper.h:123
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: barycentric_mapper.h:208
BarycentricMapper(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination)
Definition: barycentric_mapper.h:131
~BarycentricMapper() override=default
Destructor.
MapperUniquePointerType Clone(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination, Parameters JsonParameters) const override
Cloning the Mapper returns a clone of the current Mapper pure virtual, has to be implemented in every...
Definition: barycentric_mapper.h:177
BarycentricMapper(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination, Parameters JsonParameters)
Definition: barycentric_mapper.h:135
Definition: closest_points.h:74
The Commmunicator class manages communication for distributed ModelPart instances.
Definition: communicator.h:67
Object used by the bin-search.
Definition: interface_object.h:40
ConstructionType
Definition: interface_object.h:63
Definition: interpolative_mapper_base.h:81
BaseType::MapperUniquePointerType MapperUniquePointerType
Definition: interpolative_mapper_base.h:103
InterfaceCommunicator::MapperInterfaceInfoUniquePointerType MapperInterfaceInfoUniquePointerType
Definition: interpolative_mapper_base.h:93
Kratos::unique_ptr< Mapper > MapperUniquePointerType
Definition: mapper.h:53
Object for storing data that is needed to construct the local-mapping-system.
Definition: mapper_interface_info.h:42
std::size_t IndexType
Definition: mapper_interface_info.h:50
InterfaceObject::CoordinatesArrayType CoordinatesArrayType
Definition: mapper_interface_info.h:52
This is the "Condition" of the mappers.
Definition: mapper_local_system.h:39
PairingStatus
Definition: mapper_local_system.h:63
MapperInterfaceInfo::CoordinatesArrayType CoordinatesArrayType
Definition: mapper_local_system.h:50
Kratos::unique_ptr< MapperLocalSystem > MapperLocalSystemUniquePointer
Definition: mapper_local_system.h:48
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This class defines the node.
Definition: node.h:65
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_DEBUG_ERROR_IF_NOT(conditional)
Definition: exception.h:172
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
void CreateMapperLocalSystemsFromNodes(const MapperLocalSystem &rMapperLocalSystemPrototype, const Communicator &rModelPartCommunicator, std::vector< Kratos::unique_ptr< MapperLocalSystem >> &rLocalSystems)
Definition: mapper_utilities.cpp:236
Kratos::unique_ptr< MapperInterfaceInfo > MapperInterfaceInfoUniquePointerType
Definition: mapper_utilities.h:40
NodeType::Pointer NodePointerType
Definition: mapping_intersection_utilities.h:36
Modeler::Pointer Create(const std::string &ModelerName, Model &rModel, const Parameters ModelParameters)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:30
PairingIndex
Definition: projection_utilities.h:32
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::unique_ptr< T > unique_ptr
Definition: smart_pointers.h:33
BarycentricInterpolationType
Definition: barycentric_mapper.h:29
def load(f)
Definition: ode_solve.py:307