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.
print_mesh_output_mesher_process.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosDelaunayMeshingApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: April 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_PRINT_MESH_OUTPUT_MESHER_PROCESS_H_INCLUDED )
11 #define KRATOS_PRINT_MESH_OUTPUT_MESHER_PROCESS_H_INCLUDED
12 
13 
14 // External includes
15 #include <fstream>
16 
17 // System includes
18 
19 // Project includes
22 
23 #include "includes/model_part.h"
27 
28 namespace Kratos
29 {
30 
33 
34 
36  : public MesherProcess
37  {
38  public:
41 
44 
45 
49 
52  MesherUtilities::MeshingParameters& rRemeshingParameters,
53  std::string FileName,
54  int EchoLevel)
55  : mrModelPart(rModelPart),
56  mrRemesh(rRemeshingParameters)
57  {
58  mFileName = FileName;
59  mEchoLevel = EchoLevel;
60  }
61 
62 
65 
66 
70 
72  void operator()()
73  {
74  Execute();
75  }
76 
77 
81 
82 
84  void Execute() override
85  {
87 
88  if( mEchoLevel > 0 ){
89  std::cout<<" [ PRINT IN/OUT MESHER: ("<<mFileName<<") "<<std::endl;
90  //std::cout<<" Nodes before erasing : "<<mrModelPart.Nodes().size()<<std::endl;
91  }
92 
93  PrintPointsXYZ();
94 
95  PrintMesh();
96 
97  std::cout<<" PRINT IN/OUT MESHER ]; "<<std::endl;
98 
99 
100  KRATOS_CATCH(" ")
101  }
102 
103 
107 
108 
112 
113 
117 
119  std::string Info() const override
120  {
121  return "PrintMeshOutputMesherProcess";
122  }
123 
125  void PrintInfo(std::ostream& rOStream) const override
126  {
127  rOStream << "PrintMeshOutputMesherProcess";
128  }
129 
131  void PrintData(std::ostream& rOStream) const override
132  {
133  }
134 
135 
139 
141 
142 
143  private:
146 
150  ModelPart& mrModelPart;
151 
153 
154  std::string mFileName;
155 
156  int mEchoLevel;
157 
161 
162 
163  void PrintPointsXYZ()
164  {
165  KRATOS_TRY
166 
167  const int& step = mrModelPart.GetProcessInfo()[STEP];
168 
169  const unsigned int& dimension = mrModelPart.GetProcessInfo()[SPACE_DIMENSION];
170 
171  std::string FileName;
172  FileName += mrModelPart.Name();
173  FileName += "_points_";
174  FileName += mFileName;
175  FileName += "_";
176  FileName += std::to_string(step);
177  FileName += ".txt";
178 
179  std::ofstream File;
180 
181  File.open(FileName);
182 
183  double* PointList;
184  unsigned int NumberOfPoints;
185  if( mFileName == "input" ){
186  PointList = mrRemesh.InMesh.GetPointList();
187  NumberOfPoints = mrRemesh.InMesh.GetNumberOfPoints();
188  }
189  else{
190  PointList = mrRemesh.OutMesh.GetPointList();
191  NumberOfPoints = mrRemesh.OutMesh.GetNumberOfPoints();
192  }
193 
194  unsigned int base = 0;
195  for(unsigned int pn=0; pn<NumberOfPoints; pn++)
196  {
197  std::string Point;
198  for(unsigned int i=0; i<dimension; i++)
199  {
200  Point += " ";
201  Point += std::to_string(PointList[base]);
202  base++;
203  }
204 
205  Point += " \n";
206 
207  File << Point;
208  }
209 
210  File.close();
211 
212  KRATOS_CATCH(" ")
213  }
214 
215 
216  void PrintMesh()
217  {
218  KRATOS_TRY
219 
220  const int& step = mrModelPart.GetProcessInfo()[STEP];
221 
222  std::string FileName;
223  FileName += mrModelPart.Name();
224  FileName += "_mesh_";
225  FileName += mFileName;
226  FileName += "_";
227  FileName += std::to_string(step);
228  FileName += ".msh";
229 
230  std::ofstream File;
231 
232  File.open(FileName);
233 
234  const int& dimension = mrModelPart.GetProcessInfo()[SPACE_DIMENSION];
235 
236  if( dimension == 3 ) //number of nodes of a tetrahedron
237  File << "mesh dimension 3 elemtype tetrahedra nnode 4 \n";
238  else if( dimension == 2 ) //number of nodes of a triangle
239  File << "mesh dimension 2 elemtype triangle nnode 3 \n";
240 
241 
242  // write node coordinates
243  PrintNodes(File);
244 
245  // write element connectivities
246  PrintElements(File);
247 
248  File.close();
249 
250  KRATOS_CATCH(" ")
251  }
252 
253 
254  void PrintNodes(std::ofstream& File)
255  {
256  KRATOS_TRY
257 
258  File << "\n";
259  File << "coordinates \n";
260  File << "\n";
261 
262  double* PointList;
263  unsigned int NumberOfPoints;
264  if( mFileName == "input" ){
265  PointList = mrRemesh.InMesh.GetPointList();
266  NumberOfPoints = mrRemesh.InMesh.GetNumberOfPoints();
267  }
268  else{
269  PointList = mrRemesh.OutMesh.GetPointList();
270  NumberOfPoints = mrRemesh.OutMesh.GetNumberOfPoints();
271  }
272 
273  const unsigned int& dimension = mrModelPart.GetProcessInfo()[SPACE_DIMENSION];
274 
275  unsigned int base = 0;
276  for(unsigned int pn=0; pn<NumberOfPoints; pn++)
277  {
278  std::string Point(std::to_string( pn+1 ));
279 
280  for(unsigned int i=0; i<dimension; i++)
281  {
282  Point += " ";
283  Point += std::to_string(PointList[base]);
284  base++;
285  }
286 
287  Point += " \n";
288 
289  File << Point;
290  }
291 
292 
293  File << "\n";
294  File << "end coordinates \n";
295  File << "\n";
296 
297  KRATOS_CATCH(" ")
298  }
299 
300 
301  void PrintElements(std::ofstream& File)
302  {
303  KRATOS_TRY
304 
305  File << "\n";
306  File << "elements \n";
307  File << "\n";
308 
309  int* ElementList;
310  unsigned int NumberOfElements;
311  if( mFileName == "input" ){
312  ElementList = mrRemesh.InMesh.GetElementList();
313  NumberOfElements = mrRemesh.InMesh.GetNumberOfElements();
314  }
315  else{
316  ElementList = mrRemesh.OutMesh.GetElementList();
317  NumberOfElements = mrRemesh.OutMesh.GetNumberOfElements();
318  }
319 
320 
321  const unsigned int& dimension = mrModelPart.GetProcessInfo()[SPACE_DIMENSION];
322 
323  unsigned int nds = 3; //number of nodes of a triangle
324  if( dimension == 3 ) //number of nodes of a tetrahedron
325  nds = 4;
326 
327 
328  for(unsigned int el=0; el<NumberOfElements; el++)
329  {
330  std::string Element(std::to_string( el+1 ));
331 
332  for(unsigned int pn=0; pn<nds; pn++)
333  {
334  Element += " ";
335  Element += std::to_string(ElementList[el*nds+pn]);
336  }
337 
338  Element += " \n";
339 
340  File << Element;
341  }
342 
343 
344  File << "\n";
345  File << "end elements \n";
346  File << "\n";
347 
348  KRATOS_CATCH(" ")
349  }
350 
353 
354 
356 
357 
359  //Process(Process const& rOther);
360 
361 
363 
364  }; // Class Process
365 
367 
370 
371 
375 
376 
378  inline std::istream& operator >> (std::istream& rIStream,
380 
382  inline std::ostream& operator << (std::ostream& rOStream,
383  const PrintMeshOutputMesherProcess& rThis)
384  {
385  rThis.PrintInfo(rOStream);
386  rOStream << std::endl;
387  rThis.PrintData(rOStream);
388 
389  return rOStream;
390  }
392 
393 
394 } // namespace Kratos.
395 
396 #endif // KRATOS_PRINT_OUTPUT_MESH_PROCESS_H_INCLUDED defined
397 
398 
The base class for processes passed to the solution scheme.
Definition: mesher_process.hpp:37
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Definition: print_mesh_output_mesher_process.hpp:37
std::string Info() const override
Turn back information as a string.
Definition: print_mesh_output_mesher_process.hpp:119
void operator()()
This operator is provided to call the process as a function and simply calls the Execute method.
Definition: print_mesh_output_mesher_process.hpp:72
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: print_mesh_output_mesher_process.hpp:131
PrintMeshOutputMesherProcess(ModelPart &rModelPart, MesherUtilities::MeshingParameters &rRemeshingParameters, std::string FileName, int EchoLevel)
Default constructor.
Definition: print_mesh_output_mesher_process.hpp:51
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: print_mesh_output_mesher_process.hpp:125
KRATOS_CLASS_POINTER_DEFINITION(PrintMeshOutputMesherProcess)
Pointer definition of Process.
void Execute() override
Execute method is used to execute the Process algorithms.
Definition: print_mesh_output_mesher_process.hpp:84
virtual ~PrintMeshOutputMesherProcess()
Destructor.
Definition: print_mesh_output_mesher_process.hpp:64
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
static int EchoLevel
Definition: co_sim_EMPIRE_API.h:42
string FileName
Export to vtk.
Definition: GenerateWind.py:175
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int step
Definition: face_heat.py:88
pn
Definition: generate_droplet_dynamics.py:65
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
el
Definition: read_stl.py:25
integer i
Definition: TensorModule.f:17
int * GetElementList()
Definition: mesher_utilities.hpp:178
int & GetNumberOfPoints()
Definition: mesher_utilities.hpp:182
double * GetPointList()
Definition: mesher_utilities.hpp:177
int & GetNumberOfElements()
Definition: mesher_utilities.hpp:183
Definition: mesher_utilities.hpp:631
MeshContainer InMesh
Definition: mesher_utilities.hpp:674
MeshContainer OutMesh
Definition: mesher_utilities.hpp:675