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.
entities_utilities.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: Vicente Mataix Ferrandiz
11 // Philipp Bucher (https://github.com/philbucher)
12 //
13 
14 #pragma once
15 
16 // System includes
17 
18 // External includes
19 
20 // Project includes
21 #include "includes/model_part.h"
24 
25 namespace Kratos
26 {
34 namespace EntitiesUtilities
35 {
41  template<class TEntity>
42  class KRATOS_API(KRATOS_CORE) EntitityIdentifier
43  {
44  public:
47 
50 
52  constexpr static std::size_t LengthArray = static_cast<std::size_t>(GeometryData::KratosGeometryType::NumberOfGeometryTypes);
53 
56 
60 
64  EntitityIdentifier() = default;
65 
70  EntitityIdentifier(const std::string& rName);
71 
76  : mTypes(rOther.mTypes),
77  mIsInitialized(rOther.mIsInitialized)
78  {
79  }
80 
84 
89  {
90  mTypes = rOther.mTypes;
91  mIsInitialized = rOther.mIsInitialized;
92 
93  return *this;
94  }
95 
99 
104  bool IsInitialized() const;
105 
112  bool HasPrototypeEntity(const GeometryType& rGeometry) const;
113 
119  const TEntity& GetPrototypeEntity(typename GeometryType::Pointer pGeometry) const;
120 
126  const TEntity& GetPrototypeEntity(const GeometryType& rGeometry) const;
127 
131 
133  std::string Info() const
134  {
135  return "EntitityIdentifier";
136  }
137 
139  void PrintInfo(std::ostream& rOStream) const
140  {
141  rOStream << "EntitityIdentifier";
142  }
143 
145  void PrintData(std::ostream& rOStream) const;
146 
148  private:
151 
152  std::array<const TEntity*, LengthArray> mTypes;
153  bool mIsInitialized = false;
154 
158 
164  std::string GetEntityTypeName() const;
165 
171  void GenerateSingleType(const std::string& rName);
172 
178  void GenerateMultipleTypes(const std::string& rName);
179 
185  void GenerateTemplatedTypes(const std::string& rName);
186 
188  };
189 
193 
195  template<class TEntity>
196  inline std::istream& operator >> (std::istream& rIStream,
198 
200  template<class TEntity>
201  inline std::ostream& operator << (std::ostream& rOStream,
202  const EntitityIdentifier<TEntity>& rThis)
203  {
204  rThis.PrintInfo(rOStream);
205  rOStream << std::endl;
206  rThis.PrintData(rOStream);
207 
208  return rOStream;
209  }
211 
216  void KRATOS_API(KRATOS_CORE) InitializeAllEntities(ModelPart& rModelPart);
217 
222  void KRATOS_API(KRATOS_CORE) InitializeSolutionStepAllEntities(ModelPart& rModelPart);
223 
228  void KRATOS_API(KRATOS_CORE) FinalizeSolutionStepAllEntities(ModelPart& rModelPart);
229 
234  void KRATOS_API(KRATOS_CORE) InitializeNonLinearIterationAllEntities(ModelPart& rModelPart);
235 
240  void KRATOS_API(KRATOS_CORE) FinalizeNonLinearIterationAllEntities(ModelPart& rModelPart);
241 
246  template<class TEntityType>
248 
253  template<class TEntityType>
254  void InitializeEntities(ModelPart& rModelPart)
255  {
256  KRATOS_TRY
257 
258  // Array of entities
259  auto& r_entities_array = GetEntities<TEntityType>(rModelPart);
260 
261  // The current process info
262  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
263 
264  // Initialize
266  r_entities_array,
267  [&r_current_process_info](TEntityType& rEntity) {
268  // If the entity is active
269  if (rEntity.IsActive()) {
270  rEntity.Initialize(r_current_process_info);
271  }
272  }
273  );
274 
275  KRATOS_CATCH("")
276  }
277 
282  template<class TEntityType>
284  {
285  KRATOS_TRY
286 
287  // The current process info
288  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
289 
290  // Initialize
292  GetEntities<TEntityType>(rModelPart),
293  [&r_current_process_info](TEntityType& rEntity){
294  rEntity.InitializeSolutionStep(r_current_process_info);
295  }
296  );
297 
298  KRATOS_CATCH("")
299  }
300 
305  template<class TEntityType>
307  {
308  KRATOS_TRY
309 
310  // The current process info
311  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
312 
313  // Initialize
315  GetEntities<TEntityType>(rModelPart),
316  [&r_current_process_info](TEntityType& rEntity){
317  rEntity.FinalizeSolutionStep(r_current_process_info);
318  }
319  );
320 
321  KRATOS_CATCH("")
322  }
323 
328  template<class TEntityType>
330  {
331  KRATOS_TRY
332 
333  // The current process info
334  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
335 
336  // Initialize
338  GetEntities<TEntityType>(rModelPart),
339  [&r_current_process_info](TEntityType& rEntity){
340  rEntity.InitializeNonLinearIteration(r_current_process_info);
341  }
342  );
343 
344  KRATOS_CATCH("")
345  }
346 
351  template<class TEntityType>
353  {
354  KRATOS_TRY
355 
356  // The current process info
357  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
358 
359  // Initialize
361  GetEntities<TEntityType>(rModelPart),
362  [&r_current_process_info](TEntityType& rEntity){
363  rEntity.FinalizeNonLinearIteration(r_current_process_info);
364  }
365  );
366 
367  KRATOS_CATCH("")
368  }
369 
371 
372 }; // namespace EntitiesUtilities
373 } // namespace Kratos
Template struct for entity identifier.
Definition: entities_utilities.h:43
KRATOS_CLASS_POINTER_DEFINITION(EntitityIdentifier)
Pointer definition of ReplaceElementsAndConditionsProcess.
EntitityIdentifier(const EntitityIdentifier &rOther)
Copy constructor.
Definition: entities_utilities.h:75
EntitityIdentifier()=default
Default constructor.
std::string Info() const
Turn back information as a string.
Definition: entities_utilities.h:133
typename TEntity::GeometryType GeometryType
Geometry type definition.
Definition: entities_utilities.h:49
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: entities_utilities.cpp:95
EntitityIdentifier & operator=(const EntitityIdentifier &rOther)
Assignment operator.
Definition: entities_utilities.h:88
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: entities_utilities.h:139
Geometry base class.
Definition: geometry.h:71
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
This namespace includes several utilities necessaries for the computation of entities functions in a ...
void InitializeSolutionStepEntities(ModelPart &rModelPart)
This method calls InitializeSolutionStep for all the entities.
Definition: entities_utilities.h:283
void InitializeAllEntities(ModelPart &rModelPart)
This method initializes all the active entities (conditions, elements, constraints)
Definition: entities_utilities.cpp:199
void InitializeEntities(ModelPart &rModelPart)
This method initializes all the active entities.
Definition: entities_utilities.h:254
void InitializeNonLinearIterationEntities(ModelPart &rModelPart)
This method calls InitializeNonLinearIteration for all the entities.
Definition: entities_utilities.h:329
void FinalizeNonLinearIterationAllEntities(ModelPart &rModelPart)
This method calls FinalizeNonLinearIteration for all the entities (conditions, elements,...
Definition: entities_utilities.cpp:243
void FinalizeNonLinearIterationEntities(ModelPart &rModelPart)
This method calls FinalizeNonLinearIteration for all the entities.
Definition: entities_utilities.h:352
void FinalizeSolutionStepEntities(ModelPart &rModelPart)
This method calls FinalizeSolutionStep for all the entities.
Definition: entities_utilities.h:306
std::ostream & operator<<(std::ostream &rOStream, const EntitityIdentifier< TEntity > &rThis)
output stream function
Definition: entities_utilities.h:201
void InitializeSolutionStepAllEntities(ModelPart &rModelPart)
This method calls InitializeSolution for all the entities (conditions, elements, constraints)
Definition: entities_utilities.cpp:210
void FinalizeSolutionStepAllEntities(ModelPart &rModelPart)
This method calls FinalizeSolutionStep for all the entities (conditions, elements,...
Definition: entities_utilities.cpp:221
std::istream & operator>>(std::istream &rIStream, EntitityIdentifier< TEntity > &rThis)
input stream function
void InitializeNonLinearIterationAllEntities(ModelPart &rModelPart)
This method calls InitializeNonLinearIteration for all the entities (conditions, elements,...
Definition: entities_utilities.cpp:232
PointerVectorSet< TEntityType, IndexedObject > & GetEntities(ModelPart &rModelPart)
This method returns the appropriate TEntitytype container (elements, conditions, and nodes) from mode...
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
Geometry< Node > GeometryType
The definition of the geometry.
Definition: mortar_classes.h:37