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_io.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 #if !defined(KRATOS_MMG_IO)
14 #define KRATOS_MMG_IO
15 
16 // System includes
17 
18 // External includes
19 
20 // Project includes
21 #include "includes/io.h"
22 #include "includes/model_part.h"
24 
25 // NOTE: The following contains the license of the MMG library
26 /* =============================================================================
27 ** Copyright (c) Bx INP/Inria/UBordeaux/UPMC, 2004- .
28 **
29 ** mmg 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 ** mmg 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 
84 template<MMGLibrary TMMGLibrary>
85 class KRATOS_API(MESHING_APPLICATION) MmgIO
86  : public IO
87 {
88 public:
89 
92 
95 
102 
104  typedef Node NodeType;
105  // Geometry definition
107 
118 
120  static constexpr SizeType Dimension = (TMMGLibrary == MMGLibrary::MMG2D) ? 2 : 3;
121 
123  static constexpr SizeType ConditionsArraySize = (Dimension == 2) ? 1 : 2;
124 
126  static constexpr SizeType ElementsArraySize = (Dimension == 2) ? 1 : 2;
127 
129  typedef typename std::conditional<Dimension == 2, array_1d<double, 3>, array_1d<double, 6>>::type TensorArrayType;
130 
132  typedef std::vector<double> DoubleVectorType;
133 
135  typedef std::unordered_map<DoubleVectorType, IndexType, KeyHasherRange<DoubleVectorType>, KeyComparorRange<DoubleVectorType> > DoubleVectorMapType;
136 
138  typedef std::unordered_map<IndexVectorType, IndexType, KeyHasherRange<IndexVectorType>, KeyComparorRange<IndexVectorType> > IndexVectorMapType;
139 
141  typedef std::unordered_map<IndexType,IndexType> ColorsMapType;
142 
144  typedef std::pair<IndexType,IndexType> IndexPairType;
145 
149 
153 
154  // Constructor
155 
157  MmgIO(
158  std::string const& rFilename,
159  Parameters ThisParameters = Parameters(R"({})"),
160  const Flags Options = IO::READ | IO::IGNORE_VARIABLES_ERROR.AsFalse() | IO::SKIP_TIMER);
161 
163  ~MmgIO() override = default;
164 
168 
172 
176 
180 
184 
188 
192  void ReadModelPart(ModelPart& rModelPart) override;
193 
197  void WriteModelPart(ModelPart& rModelPart) override;
198 
203  std::string GetMmgVersion();
204 
208 
209 
213 
214 
218 
220  std::string Info() const override
221  {
222  return "MmgIO";
223  }
224 
226  void PrintInfo(std::ostream& rOStream) const override
227  {
228  rOStream << "MmgIO";
229  }
230 
232  void PrintData(std::ostream& rOStream) const override
233  {
234  }
235 
236 protected:
237 
240 
244 
248 
252 
256 
260 
264 
266 
267 private:
270 
274 
275  std::string mFilename;
276  Parameters mThisParameters;
277  Flags mOptions;
278 
279  MmgUtilities<TMMGLibrary> mMmgUtilities;
280 
284 
288 
292  Parameters GetDefaultParameters()
293  {
294  Parameters default_parameters = Parameters(R"(
295  {
296  "echo_level" : 0
297  })" );
298 
299  return default_parameters;
300  }
301 
305 
306 
310 
311 
315 
316 // /// Assignment operator.
317 // MmgIO& operator=(MmgIO const& rOther);
318 
319 // /// Copy constructor.
320 // MmgIO(MmgIO const& rOther);
321 
323 
324 };// class MmgIO
326 
329 
330 
334 
336 template<MMGLibrary TMMGLibrary>
337 inline std::istream& operator >> (std::istream& rIStream,
338  MmgIO<TMMGLibrary>& rThis);
339 
341 template<MMGLibrary TMMGLibrary>
342 inline std::ostream& operator << (std::ostream& rOStream,
343  const MmgIO<TMMGLibrary>& rThis)
344 {
345  rThis.PrintInfo(rOStream);
346  rOStream << std::endl;
347  rThis.PrintData(rOStream);
348 
349  return rOStream;
350 }
351 
352 }// namespace Kratos.
353 #endif /* KRATOS_MMG_IO defined */
Definition: flags.h:58
Geometry base class.
Definition: geometry.h:71
IO provides different implementation of input output procedures which can be used to read and write w...
Definition: io.h:58
std::size_t SizeType
Definition: io.h:97
Mesh is the second level of abstraction in the data structure which hold Nodes, Elements and Conditio...
Definition: mesh.h:69
typename NodesContainerType::const_iterator NodeConstantIterator
Const iterator for nodes in the container. Provides direct references to nodes.
Definition: mesh.h:117
typename ConditionsContainerType::const_iterator ConditionConstantIterator
Const iterator for conditions in the container. Provides direct references to conditions.
Definition: mesh.h:156
typename ElementsContainerType::const_iterator ElementConstantIterator
Const iterator for elements in the container. Provides direct references to elements.
Definition: mesh.h:141
This class is a IO which uses the MMG library.
Definition: mmg_io.h:87
std::unordered_map< IndexType, IndexType > ColorsMapType
Colors map.
Definition: mmg_io.h:141
MeshType::NodeConstantIterator NodeConstantIterator
Nodes container definition.
Definition: mmg_io.h:113
ModelPart::ConditionsContainerType ConditionsArrayType
Conditions containers definition.
Definition: mmg_io.h:101
ModelPart::NodesContainerType NodesArrayType
Node containers definition.
Definition: mmg_io.h:97
ModelPart::ElementsContainerType ElementsArrayType
Elements containers definition.
Definition: mmg_io.h:99
MeshType::ElementConstantIterator ElementConstantIterator
Elements container definition.
Definition: mmg_io.h:117
Geometry< NodeType > GeometryType
Definition: mmg_io.h:106
Mesh< NodeType, Properties, Element, Condition > MeshType
Mesh definition.
Definition: mmg_io.h:109
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: mmg_io.h:226
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: mmg_io.h:232
std::vector< double > DoubleVectorType
Double vector.
Definition: mmg_io.h:132
KRATOS_CLASS_POINTER_DEFINITION(MmgIO)
Pointer definition of MmgIO.
std::unordered_map< DoubleVectorType, IndexType, KeyHasherRange< DoubleVectorType >, KeyComparorRange< DoubleVectorType > > DoubleVectorMapType
Double vector map.
Definition: mmg_io.h:135
std::unordered_map< IndexVectorType, IndexType, KeyHasherRange< IndexVectorType >, KeyComparorRange< IndexVectorType > > IndexVectorMapType
Index vector map.
Definition: mmg_io.h:138
~MmgIO() override=default
Destructor.
Node NodeType
Node definition.
Definition: mmg_io.h:104
MeshType::ConditionConstantIterator ConditionConstantIterator
Conditions container definition.
Definition: mmg_io.h:115
std::conditional< Dimension==2, array_1d< double, 3 >, array_1d< double, 6 > >::type TensorArrayType
The type of array considered for the tensor.
Definition: mmg_io.h:129
std::pair< IndexType, IndexType > IndexPairType
Index pair.
Definition: mmg_io.h:144
MeshType::PropertiesContainerType PropertiesContainerType
Properties container definition.
Definition: mmg_io.h:111
std::string Info() const override
Turn back information as a string.
Definition: mmg_io.h:220
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
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
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
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
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
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 ReadModelPart(model_part, inputfile)
Definition: read_modelpart_from_json.py:3
This is a key comparer of general pourpose between two classes.
Definition: key_hash.h:100