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.
nearest_neighbor_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, Jordi Cotela
11 //
12 // See Master-Thesis P.Bucher
13 // "Development and Implementation of a Parallel
14 // Framework for Non-Matching Grid Mapping"
15 
16 #pragma once
17 
18 // System includes
19 
20 // External includes
21 
22 // Project includes
24 
25 namespace Kratos
26 {
29 
30 class KRATOS_API(MAPPING_APPLICATION) NearestNeighborInterfaceInfo : public MapperInterfaceInfo
31 {
32 public:
33 
36 
37  explicit NearestNeighborInterfaceInfo(const CoordinatesArrayType& rCoordinates,
38  const IndexType SourceLocalSystemIndex,
39  const IndexType SourceRank)
40  : MapperInterfaceInfo(rCoordinates, SourceLocalSystemIndex, SourceRank) {}
41 
42  MapperInterfaceInfo::Pointer Create() const override
43  {
44  return Kratos::make_shared<NearestNeighborInterfaceInfo>();
45  }
46 
47  MapperInterfaceInfo::Pointer Create(const CoordinatesArrayType& rCoordinates,
48  const IndexType SourceLocalSystemIndex,
49  const IndexType SourceRank) const override
50  {
51  return Kratos::make_shared<NearestNeighborInterfaceInfo>(
52  rCoordinates,
53  SourceLocalSystemIndex,
54  SourceRank);
55  }
56 
58  {
60  }
61 
62  void ProcessSearchResult(const InterfaceObject& rInterfaceObject) override;
63 
64  void GetValue(std::vector<int>& rValue,
65  const InfoType ValueType) const override
66  {
67  rValue = mNearestNeighborId;
68  }
69 
70  void GetValue(double& rValue,
71  const InfoType ValueType) const override
72  {
73  rValue = mNearestNeighborDistance;
74  }
75 
76 private:
77 
78  std::vector<int> mNearestNeighborId = {};
79  double mNearestNeighborDistance = std::numeric_limits<double>::max();
80 
81  friend class Serializer;
82 
83  void save(Serializer& rSerializer) const override
84  {
86  rSerializer.save("NearestNeighborId", mNearestNeighborId);
87  rSerializer.save("NearestNeighborDistance", mNearestNeighborDistance);
88  }
89 
90  void load(Serializer& rSerializer) override
91  {
93  rSerializer.load("NearestNeighborId", mNearestNeighborId);
94  rSerializer.load("NearestNeighborDistance", mNearestNeighborDistance);
95  }
96 };
97 
98 class KRATOS_API(MAPPING_APPLICATION) NearestNeighborLocalSystem : public MapperLocalSystem
99 {
100 public:
101 
102  explicit NearestNeighborLocalSystem(NodePointerType pNode) : mpNode(pNode) {}
103 
104  void CalculateAll(MatrixType& rLocalMappingMatrix,
105  EquationIdVectorType& rOriginIds,
106  EquationIdVectorType& rDestinationIds,
107  MapperLocalSystem::PairingStatus& rPairingStatus) const override;
108 
110  {
111  KRATOS_DEBUG_ERROR_IF_NOT(mpNode) << "Members are not intitialized!" << std::endl;
112  return mpNode->Coordinates();
113  }
114 
116  {
117  return Kratos::make_unique<NearestNeighborLocalSystem>(pNode);
118  }
119 
120  void PairingInfo(std::ostream& rOStream, const int EchoLevel) const override;
121 
122  void SetPairingStatusForPrinting() override;
123 
124 private:
125  NodePointerType mpNode;
126 
127 };
128 
130 
136 template<class TSparseSpace, class TDenseSpace, class TMapperBackend>
137 class KRATOS_API(MAPPING_APPLICATION) NearestNeighborMapper
138  : public InterpolativeMapperBase<TSparseSpace, TDenseSpace, TMapperBackend>
139 {
140 public:
141 
144 
149 
153 
157 
158  // Default constructor, needed for registration
159  NearestNeighborMapper(ModelPart& rModelPartOrigin,
160  ModelPart& rModelPartDestination)
161  : BaseType(rModelPartOrigin, rModelPartDestination) {}
162 
163  NearestNeighborMapper(ModelPart& rModelPartOrigin,
164  ModelPart& rModelPartDestination,
165  Parameters JsonParameters)
166  : BaseType(rModelPartOrigin,
167  rModelPartDestination,
168  JsonParameters)
169  {
170  KRATOS_TRY;
171 
172  auto check_has_nodes = [](const ModelPart& rModelPart){
173  if (rModelPart.GetCommunicator().GetDataCommunicator().IsDefinedOnThisRank()) {
174  KRATOS_ERROR_IF(rModelPart.GetCommunicator().GlobalNumberOfNodes() == 0) << "No nodes exist in ModelPart \"" << rModelPart.FullName() << "\"" << std::endl;
175  }
176  };
177  check_has_nodes(rModelPartOrigin);
178  check_has_nodes(rModelPartDestination);
179 
180  this->ValidateInput();
181  this->Initialize();
182 
183  KRATOS_CATCH("");
184  }
185 
187  ~NearestNeighborMapper() override = default;
188 
192 
194  ModelPart& rModelPartDestination,
195  Parameters JsonParameters) const override
196  {
197  KRATOS_TRY;
198 
199  return Kratos::make_unique<NearestNeighborMapper<TSparseSpace, TDenseSpace, TMapperBackend>>(
200  rModelPartOrigin,
201  rModelPartDestination,
202  JsonParameters);
203 
204  KRATOS_CATCH("");
205  }
206 
210 
211  int AreMeshesConforming() const override
212  {
213  KRATOS_WARNING_ONCE("Mapper") << "Developer-warning: \"AreMeshesConforming\" is deprecated and will be removed in the future" << std::endl;
214  return BaseType::mMeshesAreConforming;
215  }
216 
220 
222  std::string Info() const override
223  {
224  return "NearestNeighborMapper";
225  }
226 
228  void PrintInfo(std::ostream& rOStream) const override
229  {
230  rOStream << "NearestNeighborMapper";
231  }
232 
234  void PrintData(std::ostream& rOStream) const override
235  {
236  BaseType::PrintData(rOStream);
237  }
238 
239 private:
240 
243 
244  void CreateMapperLocalSystems(
245  const Communicator& rModelPartCommunicator,
246  std::vector<Kratos::unique_ptr<MapperLocalSystem>>& rLocalSystems) override
247  {
250  rModelPartCommunicator,
251  rLocalSystems);
252  }
253 
254  MapperInterfaceInfoUniquePointerType GetMapperInterfaceInfo() const override
255  {
256  return Kratos::make_unique<NearestNeighborInterfaceInfo>();
257  }
258 
259  Parameters GetMapperDefaultSettings() const override
260  {
261  return Parameters( R"({
262  "search_settings" : {},
263  "use_initial_configuration" : false,
264  "echo_level" : 0,
265  "print_pairing_status_to_file" : false,
266  "pairing_status_file_path" : ""
267  })");
268  }
269 
271 
272 }; // Class NearestNeighborMapper
273 
275 } // namespace Kratos.
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
Base Class for all Mappers.
Definition: mapper.h:43
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
InfoType
Definition: mapper_interface_info.h:62
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
Definition: nearest_neighbor_mapper.h:31
InterfaceObject::ConstructionType GetInterfaceObjectType() const override
returning the type of construction for the InterfaceObject The returned type is used to create the ob...
Definition: nearest_neighbor_mapper.h:57
MapperInterfaceInfo::Pointer Create() const override
Definition: nearest_neighbor_mapper.h:42
NearestNeighborInterfaceInfo(const CoordinatesArrayType &rCoordinates, const IndexType SourceLocalSystemIndex, const IndexType SourceRank)
Definition: nearest_neighbor_mapper.h:37
void GetValue(std::vector< int > &rValue, const InfoType ValueType) const override
Definition: nearest_neighbor_mapper.h:64
MapperInterfaceInfo::Pointer Create(const CoordinatesArrayType &rCoordinates, const IndexType SourceLocalSystemIndex, const IndexType SourceRank) const override
Definition: nearest_neighbor_mapper.h:47
void GetValue(double &rValue, const InfoType ValueType) const override
Definition: nearest_neighbor_mapper.h:70
NearestNeighborInterfaceInfo()
Default constructor.
Definition: nearest_neighbor_mapper.h:35
Definition: nearest_neighbor_mapper.h:99
NearestNeighborLocalSystem(NodePointerType pNode)
Definition: nearest_neighbor_mapper.h:102
CoordinatesArrayType & Coordinates() const override
Definition: nearest_neighbor_mapper.h:109
MapperLocalSystemUniquePointer Create(NodePointerType pNode) const override
Definition: nearest_neighbor_mapper.h:115
Nearest Neighbor Mapper.
Definition: nearest_neighbor_mapper.h:139
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: nearest_neighbor_mapper.h:193
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: nearest_neighbor_mapper.h:228
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: nearest_neighbor_mapper.h:234
InterpolativeMapperBase< TSparseSpace, TDenseSpace, TMapperBackend > BaseType
Definition: nearest_neighbor_mapper.h:150
BaseType::MapperInterfaceInfoUniquePointerType MapperInterfaceInfoUniquePointerType
Definition: nearest_neighbor_mapper.h:152
std::string Info() const override
Turn back information as a string.
Definition: nearest_neighbor_mapper.h:222
int AreMeshesConforming() const override
Quering for mesh conformity This function is deprecated and will eventually be removed,...
Definition: nearest_neighbor_mapper.h:211
BaseType::MapperUniquePointerType MapperUniquePointerType
Definition: nearest_neighbor_mapper.h:151
NearestNeighborMapper(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination)
Definition: nearest_neighbor_mapper.h:159
NearestNeighborMapper(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination, Parameters JsonParameters)
Definition: nearest_neighbor_mapper.h:163
~NearestNeighborMapper() override=default
Destructor.
KRATOS_CLASS_POINTER_DEFINITION(NearestNeighborMapper)
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
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
#define KRATOS_SERIALIZE_SAVE_BASE_CLASS(Serializer, BaseType)
Definition: define.h:812
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_SERIALIZE_LOAD_BASE_CLASS(Serializer, BaseType)
Definition: define.h:815
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_DEBUG_ERROR_IF_NOT(conditional)
Definition: exception.h:172
#define KRATOS_WARNING_ONCE(label)
Definition: logger.h:271
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
static double max(double a, double b)
Definition: GeometryFunctions.h:79
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
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
def load(f)
Definition: ode_solve.py:307