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.
coupling_geometry_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
11 // Tobias Teschemachen
12 //
13 
14 #pragma once
15 
16 // System includes
17 
18 // External includes
19 
20 // Project includes
21 #include "mappers/mapper.h"
24 
28 
30 
31 namespace Kratos
32 {
35 
37 {
38 public:
39 
41  const bool IsProjection,
42  const bool IsDualMortar,
43  const bool IsDestinationIsSlave
44  )
45  : mpGeom(pGeom),
46  mIsProjection(IsProjection),
47  mIsDualMortar(IsDualMortar),
48  mIsDestinationIsSlave(IsDestinationIsSlave)
49  {}
50 
51  void CalculateAll(MatrixType& rLocalMappingMatrix,
52  EquationIdVectorType& rOriginIds,
53  EquationIdVectorType& rDestinationIds,
54  MapperLocalSystem::PairingStatus& rPairingStatus) const override;
55 
57  {
58  KRATOS_DEBUG_ERROR_IF_NOT(mpGeom) << "Members are not intitialized!" << std::endl;
59  // return mpGeom->Center(); // check why not compiling...
60  KRATOS_ERROR << "not implemented, needs checking" << std::endl;
61  }
62 
64  {
65  return Kratos::make_unique<CouplingGeometryLocalSystem>(pGeometry, mIsProjection, mIsDualMortar, mIsDestinationIsSlave);
66  }
67 
69  void PairingInfo(std::ostream& rOStream, const int EchoLevel) const override {KRATOS_ERROR << "Not implemented!"<<std::endl;}
70 
71 private:
72  GeometryPointerType mpGeom;
73  bool mIsProjection; // Set to true is we are projecting the master onto the slave.
74  // Set to false if we are projecting the slave onto the slave.
75  bool mIsDualMortar = false;
76  bool mIsDestinationIsSlave = true;
77 
78 };
79 
80 // CouplingGeometryMapper
81 //
82 // The mapper always forward maps from the master to the slave.
83 // Normally:
84 // master = interface origin
85 // slave = interface destination
86 //
87 // However, this can be reversed by setting 'destination_is_slave' = false.
88 // This yields:
89 // master = interface destination
90 // slave = interface origin
91 
92 template<class TSparseSpace, class TDenseSpace>
93 class CouplingGeometryMapper : public Mapper<TSparseSpace, TDenseSpace>
94 {
95 public:
96 
99 
104 
106 
108  typedef std::vector<MapperLocalSystemPointer> MapperLocalSystemPointerVector;
109 
112 
113  typedef std::size_t IndexType;
114 
118 
121 
124 
128 
129  // Default constructor, needed for registration
131  ModelPart& rModelPartDestination)
132  : mrModelPartOrigin(rModelPartOrigin),
133  mrModelPartDestination(rModelPartDestination){}
134 
135 
136  CouplingGeometryMapper(ModelPart& rModelPartOrigin,
137  ModelPart& rModelPartDestination,
138  Parameters JsonParameters);
139 
141  ~CouplingGeometryMapper() override = default;
142 
146 
148  Kratos::Flags MappingOptions,
149  double SearchRadius) override
150  {
151  mpModeler->PrepareGeometryModel();
152 
153  AssignInterfaceEquationIds();
154 
155  KRATOS_ERROR << "Not implemented!" << std::endl;
156  }
157 
158  void Map(
159  const Variable<double>& rOriginVariable,
160  const Variable<double>& rDestinationVariable,
161  Kratos::Flags MappingOptions) override
162  {
163  if (MappingOptions.Is(MapperFlags::USE_TRANSPOSE)) {
164  MappingOptions.Reset(MapperFlags::USE_TRANSPOSE);
165  MappingOptions.Set(MapperFlags::INTERNAL_USE_TRANSPOSE, true);
166  GetInverseMapper()->Map(rDestinationVariable, rOriginVariable, MappingOptions);
167  }
168  else if (MappingOptions.Is(MapperFlags::INTERNAL_USE_TRANSPOSE)) {
169  MapInternalTranspose(rOriginVariable, rDestinationVariable, MappingOptions);
170  }
171  else {
172  MapInternal(rOriginVariable, rDestinationVariable, MappingOptions);
173  }
174  }
175 
176  void Map(
177  const Variable< array_1d<double, 3> >& rOriginVariable,
178  const Variable< array_1d<double, 3> >& rDestinationVariable,
179  Kratos::Flags MappingOptions) override
180  {
181  if (MappingOptions.Is(MapperFlags::USE_TRANSPOSE)) {
182  MappingOptions.Reset(MapperFlags::USE_TRANSPOSE);
183  MappingOptions.Set(MapperFlags::INTERNAL_USE_TRANSPOSE, true);
184  GetInverseMapper()->Map(rDestinationVariable, rOriginVariable, MappingOptions);
185  }
186  else if (MappingOptions.Is(MapperFlags::INTERNAL_USE_TRANSPOSE)) {
187  MapInternalTranspose(rOriginVariable, rDestinationVariable, MappingOptions);
188  }
189  else {
190  MapInternal(rOriginVariable, rDestinationVariable, MappingOptions);
191  }
192  }
193 
195  const Variable<double>& rOriginVariable,
196  const Variable<double>& rDestinationVariable,
197  Kratos::Flags MappingOptions) override
198  {
199  if (MappingOptions.Is(MapperFlags::USE_TRANSPOSE)) {
200  MapInternalTranspose(rOriginVariable, rDestinationVariable, MappingOptions);
201  }
202  else {
203  GetInverseMapper()->Map(rDestinationVariable, rOriginVariable, MappingOptions);
204  }
205  }
206 
208  const Variable< array_1d<double, 3> >& rOriginVariable,
209  const Variable< array_1d<double, 3> >& rDestinationVariable,
210  Kratos::Flags MappingOptions) override
211  {
212  if (MappingOptions.Is(MapperFlags::USE_TRANSPOSE)) {
213  MapInternalTranspose(rOriginVariable, rDestinationVariable, MappingOptions);
214  }
215  else {
216  GetInverseMapper()->Map(rDestinationVariable, rOriginVariable, MappingOptions);
217  }
218  }
219 
223 
225  {
226  if (mMapperSettings["precompute_mapping_matrix"].GetBool() || mMapperSettings["dual_mortar"].GetBool()) return *(mpMappingMatrix.get());
227  else KRATOS_ERROR << "'precompute_mapping_matrix' or 'dual_mortar' must be 'true' in your parameters to retrieve the computed mapping matrix!" << std::endl;
228  }
229 
231  ModelPart& rModelPartDestination,
232  Parameters JsonParameters) const override
233  {
234  return Kratos::make_unique<CouplingGeometryMapper<TSparseSpace, TDenseSpace>>(
235  rModelPartOrigin,
236  rModelPartDestination,
237  JsonParameters);
238  }
239 
243 
247 
249  std::string Info() const override
250  {
251  return "CouplingGeometryMapper";
252  }
253 
255  void PrintInfo(std::ostream& rOStream) const override
256  {
257  rOStream << "CouplingGeometryMapper";
258  }
259 
261  void PrintData(std::ostream& rOStream) const override
262  {
263  BaseType::PrintData(rOStream);
264  }
265 
266  // Get values
267  // Always returns the true origin/destination regardless of 'destination_is_slave'
269  {
270 
271  return mpCouplingMP->GetSubModelPart("interface_origin");
272  }
273 
275  {
276  return mpCouplingMP->GetSubModelPart("interface_destination");
277  }
278 
279 private:
280 
283  typename Modeler::Pointer mpModeler = nullptr;
284 
285  ModelPart& mrModelPartOrigin;
286  ModelPart& mrModelPartDestination;
287  ModelPart* mpCouplingMP = nullptr;
288  ModelPart* mpCouplingInterfaceMaster = nullptr;
289  ModelPart* mpCouplingInterfaceSlave = nullptr;
290 
291  Parameters mMapperSettings;
292 
293  MapperUniquePointerType mpInverseMapper = nullptr;
294 
295  MappingMatrixUniquePointerType mpMappingMatrix;
296  MappingMatrixUniquePointerType mpMappingMatrixProjector;
297  MappingMatrixUniquePointerType mpMappingMatrixSlave;
298 
299  TSystemVectorUniquePointerType mpTempVector;
300 
301  MapperLocalSystemPointerVector mMapperLocalSystemsProjector;
302  MapperLocalSystemPointerVector mMapperLocalSystemsSlave;
303 
304  InterfaceVectorContainerPointerType mpInterfaceVectorContainerMaster;
305  InterfaceVectorContainerPointerType mpInterfaceVectorContainerSlave;
306 
307  LinearSolverSharedPointerType mpLinearSolver = nullptr;
308 
309 
310  void InitializeInterface(Kratos::Flags MappingOptions = Kratos::Flags());
311 
312  void AssignInterfaceEquationIds()
313  {
315  MapperUtilities::AssignInterfaceEquationIds(mpCouplingInterfaceMaster->GetCommunicator());
316  }
317 
318  void MapInternal(const Variable<double>& rOriginVariable,
319  const Variable<double>& rDestinationVariable,
320  Kratos::Flags MappingOptions);
321 
322  void MapInternalTranspose(const Variable<double>& rOriginVariable,
323  const Variable<double>& rDestinationVariable,
324  Kratos::Flags MappingOptions);
325 
326  void MapInternal(const Variable<array_1d<double, 3>>& rOriginVariable,
327  const Variable<array_1d<double, 3>>& rDestinationVariable,
328  Kratos::Flags MappingOptions);
329 
330  void MapInternalTranspose(const Variable<array_1d<double, 3>>& rOriginVariable,
331  const Variable<array_1d<double, 3>>& rDestinationVariable,
332  Kratos::Flags MappingOptions);
333 
334  void EnforceConsistencyWithScaling(
335  const MappingMatrixType& rInterfaceMatrixSlave,
336  MappingMatrixType& rInterfaceMatrixProjected,
337  const double scalingLimit = 1.1);
338 
339  void CreateLinearSolver();
340 
341  void CalculateMappingMatrixWithSolver(MappingMatrixType& rConsistentInterfaceMatrix, MappingMatrixType& rProjectedInterfaceMatrix);
342 
343  Parameters GetMapperDefaultSettings() const
344  {
345  return Parameters(R"({
346  "echo_level" : 0,
347  "dual_mortar" : false,
348  "precompute_mapping_matrix" : false,
349  "modeler_name" : "UNSPECIFIED",
350  "modeler_parameters" : {},
351  "consistency_scaling" : true,
352  "row_sum_tolerance" : 1e-12,
353  "destination_is_slave" : true,
354  "linear_solver_settings" : {}
355  })");
356  }
357 
361 
362  MapperUniquePointerType& GetInverseMapper()
363  {
364  if (!mpInverseMapper) {
365  InitializeInverseMapper();
366  }
367  return mpInverseMapper;
368  }
369 
370  void InitializeInverseMapper()
371  {
372  KRATOS_ERROR << "Inverse Mapping is not supported yet!" << std::endl;
373  mpInverseMapper = this->Clone(mrModelPartDestination,
374  mrModelPartOrigin,
375  mMapperSettings);
376  }
377 
379 
380 }; // Class CouplingGeometryMapper
381 
383 } // namespace Kratos.
Definition: coupling_geometry_mapper.h:37
CoordinatesArrayType & Coordinates() const override
Definition: coupling_geometry_mapper.h:56
CouplingGeometryLocalSystem(GeometryPointerType pGeom, const bool IsProjection, const bool IsDualMortar, const bool IsDestinationIsSlave)
Definition: coupling_geometry_mapper.h:40
void PairingInfo(std::ostream &rOStream, const int EchoLevel) const override
Turn back information as a string.
Definition: coupling_geometry_mapper.h:69
MapperLocalSystemUniquePointer Create(GeometryPointerType pGeometry) const override
Definition: coupling_geometry_mapper.h:63
void CalculateAll(MatrixType &rLocalMappingMatrix, EquationIdVectorType &rOriginIds, EquationIdVectorType &rDestinationIds, MapperLocalSystem::PairingStatus &rPairingStatus) const override
Definition: coupling_geometry_mapper.cpp:30
Definition: coupling_geometry_mapper.h:94
void InverseMap(const Variable< double > &rOriginVariable, const Variable< double > &rDestinationVariable, Kratos::Flags MappingOptions) override
Mapping from Destination to Origin, Scalar Variable Data is exchanged on the Interface,...
Definition: coupling_geometry_mapper.h:194
void UpdateInterface(Kratos::Flags MappingOptions, double SearchRadius) override
Updates the mapping-system after the geometry/mesh has changed After changes in the topology (e....
Definition: coupling_geometry_mapper.h:147
Mapper< TSparseSpace, TDenseSpace > BaseType
Definition: coupling_geometry_mapper.h:105
TSparseSpace::VectorType TSystemVectorType
Definition: coupling_geometry_mapper.h:122
~CouplingGeometryMapper() override=default
Destructor.
CouplingGeometryMapper(ModelPart &rModelPartOrigin, ModelPart &rModelPartDestination)
Definition: coupling_geometry_mapper.h:130
ModelPart & GetInterfaceModelPartDestination() override
Definition: coupling_geometry_mapper.h:274
InterfaceVectorContainer< TSparseSpace, TDenseSpace > InterfaceVectorContainerType
Definition: coupling_geometry_mapper.h:110
Kratos::shared_ptr< LinearSolverType > LinearSolverSharedPointerType
Definition: coupling_geometry_mapper.h:120
LinearSolver< TSparseSpace, TDenseSpace > LinearSolverType
Definition: coupling_geometry_mapper.h:119
std::size_t IndexType
Definition: coupling_geometry_mapper.h:113
Kratos::unique_ptr< TSystemVectorType > TSystemVectorUniquePointerType
Definition: coupling_geometry_mapper.h:123
KRATOS_CLASS_POINTER_DEFINITION(CouplingGeometryMapper)
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: coupling_geometry_mapper.h:230
Kratos::unique_ptr< InterfaceVectorContainerType > InterfaceVectorContainerPointerType
Definition: coupling_geometry_mapper.h:111
Kratos::unique_ptr< MapperLocalSystem > MapperLocalSystemPointer
Definition: coupling_geometry_mapper.h:107
void Map(const Variable< array_1d< double, 3 > > &rOriginVariable, const Variable< array_1d< double, 3 > > &rDestinationVariable, Kratos::Flags MappingOptions) override
Mapping from Origin to Destination, Vector Variable Same as Map, but maps an array3-variable.
Definition: coupling_geometry_mapper.h:176
void InverseMap(const Variable< array_1d< double, 3 > > &rOriginVariable, const Variable< array_1d< double, 3 > > &rDestinationVariable, Kratos::Flags MappingOptions) override
Mapping from Destination to Origin, Vector Variable Same as InveseMap, but maps an array3-variable.
Definition: coupling_geometry_mapper.h:207
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: coupling_geometry_mapper.h:255
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: coupling_geometry_mapper.h:261
void Map(const Variable< double > &rOriginVariable, const Variable< double > &rDestinationVariable, Kratos::Flags MappingOptions) override
Mapping from Origin to Destination, Scalar Variable Data is exchanged on the Interface,...
Definition: coupling_geometry_mapper.h:158
std::string Info() const override
Turn back information as a string.
Definition: coupling_geometry_mapper.h:249
std::vector< MapperLocalSystemPointer > MapperLocalSystemPointerVector
Definition: coupling_geometry_mapper.h:108
BaseType::MapperUniquePointerType MapperUniquePointerType
Definition: coupling_geometry_mapper.h:115
ModelPart & GetInterfaceModelPartOrigin() override
Definition: coupling_geometry_mapper.h:268
MappingMatrixType & GetMappingMatrix() override
This method returns the mapping-matrix.
Definition: coupling_geometry_mapper.h:224
Kratos::unique_ptr< MappingMatrixType > MappingMatrixUniquePointerType
Definition: coupling_geometry_mapper.h:117
BaseType::TMappingMatrixType MappingMatrixType
Definition: coupling_geometry_mapper.h:116
Definition: flags.h:58
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
bool Is(Flags const &rOther) const
Definition: flags.h:274
void Reset(const Flags ThisFlag)
Definition: flags.h:193
Geometry base class.
Definition: geometry.h:71
Short class definition.
Definition: interface_vector_container.h:40
Base class for all the linear solvers in Kratos.
Definition: linear_solver.h:65
Base Class for all Mappers.
Definition: mapper.h:43
TSparseSpace::MatrixType TMappingMatrixType
Definition: mapper.h:55
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: mapper.h:205
Kratos::unique_ptr< Mapper > MapperUniquePointerType
Definition: mapper.h:53
This is the "Condition" of the mappers.
Definition: mapper_local_system.h:39
PairingStatus
Definition: mapper_local_system.h:63
std::vector< int > EquationIdVectorType
Definition: mapper_local_system.h:53
MapperInterfaceInfo::CoordinatesArrayType CoordinatesArrayType
Definition: mapper_local_system.h:50
Kratos::unique_ptr< MapperLocalSystem > MapperLocalSystemUniquePointer
Definition: mapper_local_system.h:48
Matrix MatrixType
Definition: mapper_local_system.h:52
InterfaceObject::GeometryPointerType GeometryPointerType
Definition: mapper_local_system.h:56
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Communicator & GetCommunicator()
Definition: model_part.h:1821
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_DEBUG_ERROR_IF_NOT(conditional)
Definition: exception.h:172
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
Vector VectorType
Definition: geometrical_transformation_utilities.h:56
void AssignInterfaceEquationIds(Communicator &rModelPartCommunicator)
Assigning INTERFACE_EQUATION_IDs to the nodes, with and without MPI This function assigns the INTERFA...
Definition: mapper_utilities.cpp:34
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27
std::unique_ptr< T > unique_ptr
Definition: smart_pointers.h:33