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.
mmg_process.h
Go to the documentation of this file.
1 // KRATOS __ __ _____ ____ _ _ ___ _ _ ____
2 // | \/ | ____/ ___|| | | |_ _| \ | |/ ___|
3 // | |\/| | _| \___ \| |_| || || \| | | _
4 // | | | | |___ ___) | _ || || |\ | |_| |
5 // |_| |_|_____|____/|_| |_|___|_| \_|\____| APPLICATION
6 //
7 // License: BSD License
8 // license: MeshingApplication/license.txt
9 //
10 // Main authors: Vicente Mataix Ferrandiz
11 //
12 
13 #pragma once
14 
15 // System includes
16 #include <unordered_set>
17 #include <unordered_map>
18 
19 // External includes
20 // The includes related with the MMG library
21 // #include "mmg/libmmg.h"
22 
23 // Project includes
24 #include "processes/process.h"
25 #include "includes/key_hash.h"
26 #include "includes/model_part.h"
30 #include "meshing_application.h"
31 
32 // NOTE: The following contains the license of the MMG library
33 /* =============================================================================
34 ** Copyright (c) Bx INP/Inria/UBordeaux/UPMC, 2004- .
35 **
36 ** mmg is free software: you can redistribute it and/or modify it
37 ** under the terms of the GNU Lesser General Public License as published
38 ** by the Free Software Foundation, either version 3 of the License, or
39 ** (at your option) any later version.
40 **
41 ** mmg is distributed in the hope that it will be useful, but WITHOUT
42 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43 ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44 ** License for more details.
45 **
46 ** You should have received a copy of the GNU Lesser General Public
47 ** License and of the GNU General Public License along with mmg (in
48 ** files COPYING.LESSER and COPYING). If not, see
49 ** <http://www.gnu.org/licenses/>. Please read their terms carefully and
50 ** use this copy of the mmg distribution only if you accept them.
51 ** =============================================================================
52 */
53 
54 namespace Kratos
55 {
58 
62 
64  typedef std::size_t IndexType;
65 
67  typedef std::size_t SizeType;
68 
70  typedef std::vector<IndexType> IndexVectorType;
71 
75 
79 
83 
92 template<MMGLibrary TMMGLibrary>
93 class KRATOS_API(MESHING_APPLICATION) MmgProcess
94  : public Process
95 {
96 public:
97 
100 
103 
105  typedef Node NodeType;
106  // Geometry definition
108 
110  static constexpr SizeType Dimension = (TMMGLibrary == MMGLibrary::MMG2D) ? 2 : 3;
111 
113  typedef typename std::conditional<Dimension == 2, array_1d<double, 3>, array_1d<double, 6>>::type TensorArrayType;
114 
116  typedef std::unordered_map<IndexType,IndexType> ColorsMapType;
117 
119  typedef std::pair<IndexType,IndexType> IndexPairType;
120 
121 
125 
129 
130  // Constructor
131 
137  MmgProcess(
138  ModelPart& rThisModelPart,
139  Parameters ThisParameters = Parameters(R"({})")
140  );
141 
143  ~MmgProcess() override = default;
144 
148 
152 
156 
160 
164 
165  void operator()();
166 
170 
174  void Execute() override;
175 
179  void ExecuteInitialize() override;
180 
184  void ExecuteBeforeSolutionLoop() override;
185 
189  void ExecuteInitializeSolutionStep() override;
190 
194  void ExecuteFinalizeSolutionStep() override;
195 
199  void ExecuteBeforeOutputStep() override;
200 
204  void ExecuteAfterOutputStep() override;
205 
209  void ExecuteFinalize() override;
210 
214  virtual void OutputMdpa();
215 
219  void CleanSuperfluousNodes();
220 
224  void CleanSuperfluousConditions();
225 
230  std::string GetMmgVersion();
231 
235  const Parameters GetDefaultParameters() const override;
236 
240 
244 
245 
249 
251  std::string Info() const override
252  {
253  return "MmgProcess";
254  }
255 
257  void PrintInfo(std::ostream& rOStream) const override
258  {
259  rOStream << "MmgProcess";
260  }
261 
263  void PrintData(std::ostream& rOStream) const override
264  {
265  }
266 
267 protected:
268 
271 
275 
279 
280  std::string mFilename;
282 
284 
287 
288  std::unordered_map<IndexType,std::vector<std::string>> mColors;
289 
290  std::unordered_map<IndexType,Element::Pointer> mpRefElement;
291  std::unordered_map<IndexType,Condition::Pointer> mpRefCondition;
292 
296 
300 
305  MmgProcess(
306  ModelPart* pThisModelPart
307  );
308 
314  static inline FrameworkEulerLagrange ConvertFramework(const std::string& rString)
315  {
316  if(rString == "Lagrangian" || rString == "LAGRANGIAN")
318  else if(rString == "Eulerian" || rString == "EULERIAN")
320  else if(rString == "ALE")
322  else
324  }
325 
331  static inline DiscretizationOption ConvertDiscretization(const std::string& rString)
332  {
333  if(rString == "Lagrangian" || rString == "LAGRANGIAN")
335  else if(rString == "Standard" || rString == "STANDARD")
337  else if(rString == "Isosurface" || rString == "ISOSURFACE" || rString == "IsoSurface")
339  else
341  }
342 
346  virtual void InitializeMeshData();
347 
351  virtual void InitializeSolDataMetric();
352 
356  virtual void InitializeSolDataDistance();
357 
361  virtual void InitializeDisplacementData();
362 
366  virtual void ExecuteRemeshing();
367 
371  virtual void InitializeElementsAndConditions();
372 
377  virtual void SaveSolutionToFile(const bool PostOutput);
378 
382  virtual void FreeMemory();
383 
391  template<class TContainerType>
393  TContainerType& rNewContainer,
394  const TContainerType& rOldContainer
395  )
396  {
397  // Firts we generate the variable list
398  std::unordered_set<std::string> list_variables;
399  const auto it_begin_old = rOldContainer.begin();
400  auto& data = it_begin_old->GetData();
401  for(auto i = data.begin() ; i != data.end() ; ++i) {
402  list_variables.insert((i->first)->Name());
403  }
404 
405  for (auto& var_name : list_variables) {
406  if (KratosComponents<Variable<bool>>::Has(var_name)) {
407  const Variable<bool>& r_var = KratosComponents<Variable<bool>>::Get(var_name);
408  VariableUtils().SetNonHistoricalVariable(r_var, false, rNewContainer);
409  } else if (KratosComponents<Variable<double>>::Has(var_name)) {
410  const Variable<double>& r_var = KratosComponents<Variable<double>>::Get(var_name);
411  VariableUtils().SetNonHistoricalVariable(r_var, 0.0, rNewContainer);
412  } else if (KratosComponents<Variable<array_1d<double, 3>>>::Has(var_name)) {
414  const array_1d<double, 3> aux_value = ZeroVector(3);
415  VariableUtils().SetNonHistoricalVariable(r_var, aux_value, rNewContainer);
416  } else if (KratosComponents<Variable<array_1d<double, 4>>>::Has(var_name)) {
418  const array_1d<double, 4> aux_value = ZeroVector(4);
419  VariableUtils().SetNonHistoricalVariable(r_var, aux_value, rNewContainer);
420  } else if (KratosComponents<Variable<array_1d<double, 6>>>::Has(var_name)) {
422  const array_1d<double, 6> aux_value = ZeroVector(6);
423  VariableUtils().SetNonHistoricalVariable(r_var, aux_value, rNewContainer);
424  } else if (KratosComponents<Variable<array_1d<double, 9>>>::Has(var_name)) {
426  const array_1d<double, 9> aux_value = ZeroVector(9);
427  VariableUtils().SetNonHistoricalVariable(r_var, aux_value, rNewContainer);
428  } else if (KratosComponents<Variable<Vector>>::Has(var_name)) {
429  const Variable<Vector>& r_var = KratosComponents<Variable<Vector>>::Get(var_name);
430  Vector aux_value = ZeroVector(it_begin_old->GetValue(r_var).size());
431  VariableUtils().SetNonHistoricalVariable(r_var, aux_value, rNewContainer);
432  } else if (KratosComponents<Variable<Matrix>>::Has(var_name)) {
433  const Variable<Matrix>& r_var = KratosComponents<Variable<Matrix>>::Get(var_name);
434  const Matrix& ref_matrix = it_begin_old->GetValue(r_var);
435  Matrix aux_value = ZeroMatrix(ref_matrix.size1(), ref_matrix.size2());
436  VariableUtils().SetNonHistoricalVariable(r_var, aux_value, rNewContainer);
437  }
438  }
439  }
440 
444  virtual void ClearConditionsDuplicatedGeometries();
445 
450  virtual void CreateDebugPrePostRemeshOutput(ModelPart& rOldModelPart);
451 
456  void ApplyLocalParameters();
457 
461 
465 
469 
471 
472 private:
475 
476 
480 
481  MmgUtilities<TMMGLibrary> mMmgUtilities;
482 
486 
490 
494  void CollapsePrismsToTriangles();
495 
500  void ExtrudeTrianglestoPrisms(ModelPart& rOldModelPart);
501 
506  void MarkConditionsSubmodelParts(ModelPart& rModelPart);
507 
511 
512 
516 
517 
521 
523  MmgProcess& operator=(MmgProcess const& rOther);
524 
526  MmgProcess(MmgProcess const& rOther);
527 
529 
530 };// class MmgProcess
532 
535 
536 
540 
542 template<MMGLibrary TMMGLibrary>
543 inline std::istream& operator >> (std::istream& rIStream,
544  MmgProcess<TMMGLibrary>& rThis);
545 
547 template<MMGLibrary TMMGLibrary>
548 inline std::ostream& operator << (std::ostream& rOStream,
549  const MmgProcess<TMMGLibrary>& rThis)
550 {
551  rThis.PrintInfo(rOStream);
552  rOStream << std::endl;
553  rThis.PrintData(rOStream);
554 
555  return rOStream;
556 }
557 
558 }// namespace Kratos.
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
void ExecuteFinalizeSolutionStep() override
this function will be executed at every time step AFTER performing the solve phase
Definition: periodic_interface_process.hpp:55
void ExecuteInitialize() override
Definition: periodic_interface_process.hpp:37
std::size_t IndexType
Definition: flags.h:74
Geometry base class.
Definition: geometry.h:71
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
This class is a remesher which uses the MMG library.
Definition: mmg_process.h:95
KRATOS_CLASS_POINTER_DEFINITION(MmgProcess)
Pointer definition of MmgProcess.
IndexType mEchoLevel
I/O file name.
Definition: mmg_process.h:281
static FrameworkEulerLagrange ConvertFramework(const std::string &rString)
This converts the framework string to an enum.
Definition: mmg_process.h:314
std::string Info() const override
Turn back information as a string.
Definition: mmg_process.h:251
Parameters mThisParameters
The model part to compute.
Definition: mmg_process.h:277
std::unordered_map< IndexType, std::vector< std::string > > mColors
Cuttig-out specified regions during surface remeshing.
Definition: mmg_process.h:288
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: mmg_process.h:257
std::unordered_map< IndexType, Condition::Pointer > mpRefCondition
Reference element.
Definition: mmg_process.h:291
ModelPart & mrThisModelPart
Definition: mmg_process.h:276
std::unordered_map< IndexType, Element::Pointer > mpRefElement
Where the sub model parts IDs are stored.
Definition: mmg_process.h:290
std::pair< IndexType, IndexType > IndexPairType
Index pair.
Definition: mmg_process.h:119
NodeType::DofsContainerType mDofs
The parameters (can be used for general pourposes)
Definition: mmg_process.h:278
bool mRemoveRegions
The discretization option.
Definition: mmg_process.h:286
void SetToZeroEntityData(TContainerType &rNewContainer, const TContainerType &rOldContainer)
It sets to zero the entity data, using the variables from the orginal model part.
Definition: mmg_process.h:392
std::unordered_map< IndexType, IndexType > ColorsMapType
Colors map.
Definition: mmg_process.h:116
Geometry< NodeType > GeometryType
Definition: mmg_process.h:107
std::string mFilename
Storage for the dof of the node.
Definition: mmg_process.h:280
FrameworkEulerLagrange mFramework
The echo level.
Definition: mmg_process.h:283
DiscretizationOption mDiscretization
The framework.
Definition: mmg_process.h:285
std::conditional< Dimension==2, array_1d< double, 3 >, array_1d< double, 6 > >::type TensorArrayType
The type of array considered for the tensor.
Definition: mmg_process.h:113
Node NodeType
Node definition.
Definition: mmg_process.h:105
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: mmg_process.h:263
static DiscretizationOption ConvertDiscretization(const std::string &rString)
This converts the discretization string to an enum.
Definition: mmg_process.h:331
~MmgProcess() override=default
Destructor.
Provides the Kratos interface to the MMG library API.
Definition: mmg_utilities.h:153
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This class defines the node.
Definition: node.h:65
std::vector< std::unique_ptr< Dof< double > >> DofsContainerType
The DoF container type definition.
Definition: node.h:92
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
The base class for all processes in Kratos.
Definition: process.h:49
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
void SetNonHistoricalVariable(const TVarType &rVariable, const TType &Value, TContainerType &rContainer)
Sets the container value of any type of non historical variable.
Definition: variable_utils.h:790
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
FrameworkEulerLagrange
This enums allows to differentiate the working framework.
Definition: meshing_application.h:66
DiscretizationOption
This enums allows to differentiate the discretization options.
Definition: meshing_application.h:71
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::vector< IndexType > IndexVectorType
Index vector.
Definition: mmg_io.h:63
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
type
Definition: generate_gid_list_file.py:35
data
Definition: mesh_to_mdpa_converter.py:59
integer i
Definition: TensorModule.f:17