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.
pmmg_utilities.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: Marc Nunez
11 // Carlos Roig
12 // Vicente Mataix Ferrandiz
13 //
14 
15 #if !defined(KRATOS_PMMG_UTILITIES)
16 #define KRATOS_PMMG_UTILITIES
17 
18 // System includes
19 
20 // External includes
21 
22 // Project includes
24 
25 // NOTE: The following contains the license of the PMMG library
26 /* =============================================================================
27 ** Copyright (c) Bx INP/Inria/UBordeaux, 2017- .
28 **
29 ** parmmg is free software: you can redistribute it and/or modify it
30 ** under the terms of the GNU Lesser General Public License as published
31 ** by the Free Software Foundation, either version 3 of the License, or
32 ** (at your option) any later version.
33 **
34 ** parmmg is distributed in the hope that it will be useful, but WITHOUT
35 ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
36 ** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
37 ** License for more details.
38 **
39 ** You should have received a copy of the GNU Lesser General Public
40 ** License and of the GNU General Public License along with mmg (in
41 ** files COPYING.LESSER and COPYING). If not, see
42 ** <http://www.gnu.org/licenses/>. Please read their terms carefully and
43 ** use this copy of the mmg distribution only if you accept them.
44 ** =============================================================================
45 */
46 
47 namespace Kratos
48 {
51 
55 
57  typedef std::size_t IndexType;
58 
60  typedef std::size_t SizeType;
61 
63  typedef std::vector<IndexType> IndexVectorType;
64 
68 
72 
76 
83 template<PMMGLibrary TPMMGLibrary>
84 struct PMMGMeshInfo : public MMGMeshInfo<MMGLibrary::MMG3D>
85 {
86 };
87 
96 template<PMMGLibrary TPMMGLibrary>
97 class KRATOS_API(MESHING_APPLICATION) ParMmgUtilities
98  : public MmgUtilities<MMGLibrary::MMG3D>
99 {
100 public:
101 
104 
107 
109 
111  typedef Node NodeType;
112  // Geometry definition
114 
116  static constexpr SizeType Dimension = 3;
117 
119  typedef typename std::conditional<Dimension == 2, array_1d<double, 3>, array_1d<double, 6>>::type TensorArrayType;
120 
122  typedef std::vector<double> DoubleVectorType;
123 
125  typedef std::unordered_map<DoubleVectorType, IndexType, KeyHasherRange<DoubleVectorType>, KeyComparorRange<DoubleVectorType> > DoubleVectorMapType;
126 
128  typedef std::unordered_map<IndexVectorType, IndexType, KeyHasherRange<IndexVectorType>, KeyComparorRange<IndexVectorType> > IndexVectorMapType;
129 
131  typedef std::unordered_map<IndexType,IndexType> ColorsMapType;
132 
134  typedef std::pair<IndexType,IndexType> IndexPairType;
135 
137  typedef std::pair<IndexType, std::vector<std::string>> IndexStringVectorPairType;
138 
140  static constexpr double ZeroTolerance = std::numeric_limits<double>::epsilon();
141 
145 
149 
153 
157 
161 
165 
169 
173 
178  void PrintAndGetParMmgMeshInfo(PMMGMeshInfo<TPMMGLibrary>& rPMMGMeshInfo);
179 
184  IndexVectorType FindDuplicateNodeIds(const ModelPart& rModelPart) override;
185 
191 
197 
202  void BlockNode(const IndexType iNode) override;
203 
208  void BlockCondition(const IndexType iCondition) override;
209 
214  void BlockElement(const IndexType iElement) override;
215 
225  NodeType::Pointer CreateNode(
226  ModelPart& rModelPart,
227  IndexType iNode,
228  int& Ref,
229  int& IsRequired
230  ) override;
231 
243  Condition::Pointer CreateFirstTypeCondition(
244  ModelPart& rModelPart,
245  std::unordered_map<IndexType,Condition::Pointer>& rMapPointersRefCondition,
246  const IndexType CondId,
247  int& Ref,
248  int& IsRequired,
249  bool SkipCreation
250  ) override;
251 
261  Element::Pointer CreateFirstTypeElement(
262  ModelPart& rModelPart,
263  std::unordered_map<IndexType,Element::Pointer>& rMapPointersRefElement,
264  const IndexType ElemId,
265  int& Ref,
266  int& IsRequired,
267  bool SkipCreation
268  ) override;
269 
281  void InitMesh(const DataCommunicator& rDataCommunicator);
282 
286  void InitVerbosity() override;
287 
292  void InitAPIModeParameter(const IndexType VerbosityPMMG);
293 
298  void InitNodeGloNumParameter(const IndexType nodeGloNum);
299 
304  void InitVerbosityParameter(const IndexType VerbosityPMMG) override;
305 
311 
316  void SetSolSizeScalar(const SizeType NumNodes) override;
317 
322  void SetSolSizeVector(const SizeType NumNodes) override;
323 
328  void SetSolSizeTensor(const SizeType NumNodes) override;
329 
334  void SetDispSizeVector(const SizeType NumNodes) override;
335 
339  void CheckMeshData() override;
340 
345  void InputMesh(const std::string& rInputName) override;
346 
351  void InputSol(const std::string& rInputName) override;
352 
357  void OutputMesh(const std::string& rOutputName) override;
358 
363  void OutputSol(const std::string& rOutputName) override;
364 
369  void OutputDisplacement(const std::string& rOutputName) override;
370 
377  void OutputReferenceEntitities(
378  const std::string& rOutputName,
379  const std::unordered_map<IndexType,Condition::Pointer>& rRefCondition,
380  const std::unordered_map<IndexType,Element::Pointer>& rRefElement
381  ) override;
382 
386  void FreeAll() override;
387 
391  void PMMGLibCallMetric(Parameters ConfigurationParameters);
392 
396  void PMMGLibCallIsoSurface(Parameters ConfigurationParameters);
397 
406  void SetNodes(
407  const double X,
408  const double Y,
409  const double Z,
410  const IndexType Color,
411  const IndexType Index
412  ) override;
413 
421  GeometryType& rGeometry,
422  const IndexType Color,
423  const IndexType Index
424  ) override;
425 
433  GeometryType& rGeometry,
434  const IndexType Color,
435  const IndexType Index
436  ) override;
437 
444  const double Metric,
445  const IndexType NodeId
446  ) override;
447 
454  const array_1d<double, Dimension>& rMetric,
455  const IndexType NodeId
456  ) override;
457 
464  const TensorArrayType& rMetric,
465  const IndexType NodeId
466  ) override;
467 
474  const array_1d<double, 3>& rDisplacement,
475  const IndexType NodeId
476  ) override;
477 
482  void GetMetricScalar(double& rMetric) override;
483 
489 
494  void GetMetricTensor(TensorArrayType& rMetric) override;
495 
500  void GetDisplacementVector(array_1d<double, 3>& rDisplacement) override;
501 
511  void GenerateMeshDataFromModelPart(
512  ModelPart& rModelPart,
513  std::unordered_map<IndexType,std::vector<std::string>>& rColors,
514  ColorsMapType& rColorMapCondition,
515  ColorsMapType& rColorMapElement,
517  const bool CollapsePrismElements = false
518  ) override;
519 
525  ModelPart& rModelPart
526  );
527 
533  ModelPart& rModelPart
534  );
535 
544  void GenerateReferenceMaps(
545  ModelPart& rModelPart,
546  const ColorsMapType& rColorMapCondition,
547  const ColorsMapType& rColorMapElement,
548  std::unordered_map<IndexType,Condition::Pointer>& rRefCondition,
549  std::unordered_map<IndexType,Element::Pointer>& rRefElement
550  ) override;
551 
556  void GenerateSolDataFromModelPart(ModelPart& rModelPart) override;
557 
562  void GenerateDisplacementDataFromModelPart(ModelPart& rModelPart) override;
563 
573  void WriteMeshDataToModelPart(
574  ModelPart& rModelPart,
575  const std::unordered_map<IndexType,std::vector<std::string>>& rColors,
576  const NodeType::DofsContainerType& rDofs,
577  const PMMGMeshInfo<TPMMGLibrary>& rPMMGMeshInfo,
578  std::unordered_map<IndexType,Condition::Pointer>& rMapPointersRefCondition,
579  std::unordered_map<IndexType,Element::Pointer>& rMapPointersRefElement
580  );
581 
589  void WriteReferenceEntitities(
590  ModelPart& rModelPart,
591  const std::string& rFilename,
592  std::unordered_map<IndexType,Condition::Pointer>& rRefCondition,
593  std::unordered_map<IndexType,Element::Pointer>& rRefElement
594  ) override;
595 
600  void CreateAuxiliarSubModelPartForFlags(ModelPart& rModelPart) override;
601 
606  void AssignAndClearAuxiliarSubModelPartForFlags(ModelPart& rModelPart) override;
607 
608  std::unordered_map<int, int> GetNodalLocalToGlobalMap();
609 
613 
614 
618 
619 
623 
625  std::string Info() const // override
626  {
627  return "ParMmgUtilities";
628  }
629 
631  void PrintInfo(std::ostream& rOStream) const // override
632  {
633  rOStream << "ParMmgUtilities";
634  }
635 
637  void PrintData(std::ostream& rOStream) const // override
638  {
639  }
640 
641 protected:
642 
645 
649 
653 
657 
661 
665 
669 
671 
672 private:
675 
679 
680  std::unordered_map<int, int> mGlobalToLocalNodePreMap;
681  std::unordered_map<int, int> mGlobalToLocalElemPreMap;
682  std::unordered_map<int, int> mGlobalToLocalCondPreMap;
683  std::unordered_map<int, int> mLocalToGlobalNodePostMap;
684 
688 
692 
696 
697 
701 
702 
706 
707 // /// Assignment operator.
708 // ParMmgUtilities& operator=(ParMmgUtilities const& rOther);
709 
710 // /// Copy constructor.
711 // ParMmgUtilities(ParMmgUtilities const& rOther);
712 
714 
715 };// class ParMmgUtilities
717 
720 
721 
725 
727 template<PMMGLibrary TPMMGLibrary>
728 inline std::istream& operator >> (std::istream& rIStream,
730 
732 template<PMMGLibrary TPMMGLibrary>
733 inline std::ostream& operator << (std::ostream& rOStream,
734  const ParMmgUtilities<TPMMGLibrary>& rThis)
735 {
736  rThis.PrintInfo(rOStream);
737  rOStream << std::endl;
738  rThis.PrintData(rOStream);
739 
740  return rOStream;
741 }
742 
743 }// namespace Kratos.
744 #endif /* KRATOS_PMMG_UTILITIES defined */
Serial (do-nothing) version of a wrapper class for MPI communication.
Definition: data_communicator.h:318
Geometry base class.
Definition: geometry.h:71
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
Provides the Kratos interface to the PMMG library API.
Definition: pmmg_utilities.h:99
void SetMetricScalar(const double Metric, const IndexType NodeId) override
This function is used to set the metric scalar.
void PrintParallelInterfaces(ModelPart &rModelPart)
This method prints the interface data for the parallel communicator.
void PMMGLibCallMetric(Parameters ConfigurationParameters)
This loads the solution.
MmgUtilities< MMGLibrary::MMG3D > BaseType
Definition: pmmg_utilities.h:108
void SetMetricVector(const array_1d< double, Dimension > &rMetric, const IndexType NodeId) override
This function is used to set the metric vector (x, y, z)
void OutputSol(const std::string &rOutputName) override
This sets the output sol.
void BlockNode(const IndexType iNode) override
It blocks certain nodes before remesh the model.
void SetConditions(GeometryType &rGeometry, const IndexType Color, const IndexType Index) override
This sets the conditions of the mesh.
NodeType::Pointer CreateNode(ModelPart &rModelPart, IndexType iNode, int &Ref, int &IsRequired) override
It creates the new node.
void BlockCondition(const IndexType iCondition) override
It blocks certain conditions before remesh the model.
void FreeAll() override
This frees the PMMG structures.
void SetSolSizeVector(const SizeType NumNodes) override
This sets the size of the solution for the vector case.
std::pair< IndexType, IndexType > IndexPairType
Index pair.
Definition: pmmg_utilities.h:134
void InputSol(const std::string &rInputName) override
This sets the output sol.
void SetElements(GeometryType &rGeometry, const IndexType Color, const IndexType Index) override
This sets elements of the mesh.
void SetDisplacementVector(const array_1d< double, 3 > &rDisplacement, const IndexType NodeId) override
This function is used to set the displacement vector (x, y, z)
Geometry< NodeType > GeometryType
Definition: pmmg_utilities.h:113
std::unordered_map< IndexType, IndexType > ColorsMapType
Colors map.
Definition: pmmg_utilities.h:131
std::unordered_map< DoubleVectorType, IndexType, KeyHasherRange< DoubleVectorType >, KeyComparorRange< DoubleVectorType > > DoubleVectorMapType
Double vector map.
Definition: pmmg_utilities.h:125
void PMMGLibCallIsoSurface(Parameters ConfigurationParameters)
This loads the solution.
void InitAPIModeParameter(const IndexType VerbosityPMMG)
Here the API mode is set using the API.
void InitNodeGloNumParameter(const IndexType nodeGloNum)
Ask for output node global numbering.
void BlockElement(const IndexType iElement) override
It blocks certain elements before remesh the model.
std::string Info() const
Turn back information as a string.
Definition: pmmg_utilities.h:625
void GenerateParallelInterfaces(ModelPart &rModelPart)
This method generates the interface data for the parallel communicator.
KRATOS_CLASS_POINTER_DEFINITION(ParMmgUtilities)
Pointer definition of ParMmgUtilities.
std::vector< double > DoubleVectorType
Double vector.
Definition: pmmg_utilities.h:122
void SetDispSizeVector(const SizeType NumNodes) override
This sets the size of the displacement for lagrangian movement.
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: pmmg_utilities.h:637
Element::Pointer CreateFirstTypeElement(ModelPart &rModelPart, std::unordered_map< IndexType, Element::Pointer > &rMapPointersRefElement, const IndexType ElemId, int &Ref, int &IsRequired, bool SkipCreation) override
It creates the new element (first type, depends if the library work in 2D/3D/Surfaces)
std::unordered_map< IndexVectorType, IndexType, KeyHasherRange< IndexVectorType >, KeyComparorRange< IndexVectorType > > IndexVectorMapType
Index vector map.
Definition: pmmg_utilities.h:128
IndexVectorType CheckFirstTypeElements() override
Returns a vector of ids of repeated elements.
Condition::Pointer CreateFirstTypeCondition(ModelPart &rModelPart, std::unordered_map< IndexType, Condition::Pointer > &rMapPointersRefCondition, const IndexType CondId, int &Ref, int &IsRequired, bool SkipCreation) override
It creates the new condition (first type, depends if the library work in 2D/3D/Surfaces)
void GetMetricScalar(double &rMetric) override
This function is used to retrieve the metric scalar.
std::conditional< Dimension==2, array_1d< double, 3 >, array_1d< double, 6 > >::type TensorArrayType
The type of array considered for the tensor.
Definition: pmmg_utilities.h:119
void OutputMesh(const std::string &rOutputName) override
This sets the output mesh.
void SetMetricTensor(const TensorArrayType &rMetric, const IndexType NodeId) override
This function is used to set the Hessian metric tensor, note that when using the Hessian,...
void InputMesh(const std::string &rInputName) override
This sets the output mesh.
std::pair< IndexType, std::vector< std::string > > IndexStringVectorPairType
Index and string vector pair.
Definition: pmmg_utilities.h:137
void SetMeshSize(PMMGMeshInfo< TPMMGLibrary > &rPMMGMeshInfo)
This sets the size of the mesh.
void GetMetricVector(array_1d< double, Dimension > &rMetric) override
This function is used to retrieve the metric vector (x, y, z)
void SetSolSizeTensor(const SizeType NumNodes) override
This sets the size of the solution for the tensor case.
void GetMetricTensor(TensorArrayType &rMetric) override
This function is used to retrieve the Hessian metric tensor, note that when using the Hessian,...
void OutputDisplacement(const std::string &rOutputName) override
This sets the output displacement.
IndexVectorType CheckFirstTypeConditions() override
Returns a vector of ids of repeated conditions.
void CheckMeshData() override
This checks the mesh data and prints if it is OK.
void SetNodes(const double X, const double Y, const double Z, const IndexType Color, const IndexType Index) override
This sets the nodes of the mesh.
Node NodeType
Node definition.
Definition: pmmg_utilities.h:111
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: pmmg_utilities.h:631
void InitVerbosityParameter(const IndexType VerbosityPMMG) override
Here the verbosity is set using the API.
void SetSolSizeScalar(const SizeType NumNodes) override
This sets the size of the solution for the scalar case.
void GetDisplacementVector(array_1d< double, 3 > &rDisplacement) override
This function is used to retrieve the displacement vector (x, y, z)
void InitMesh(const DataCommunicator &rDataCommunicator)
Initialisation of mesh and sol structures.
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
FrameworkEulerLagrange
This enums allows to differentiate the working framework.
Definition: meshing_application.h:66
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
def Index()
Definition: hdf5_io_tools.py:38
tuple const
Definition: ode_solve.py:403
This is a key comparer of general pourpose between two classes.
Definition: key_hash.h:100
Stores the Mmg mesh information.
Definition: mmg_utilities.h:115
Stores the ParMmg mesh information.
Definition: pmmg_utilities.h:85