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.
gid_io.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: Riccardo Rossi
11 // Janosch Stascheit
12 // Pooyan Dadvand
13 //
14 
15 #if !defined(KRATOS_GID_OUTPUT_H_INCLUDED)
16 #define KRATOS_GID_OUTPUT_H_INCLUDED
17 
18 // System includes
19 #include <iostream>
20 #include <fstream>
21 #include <sstream>
22 #include <string>
23 #include <cstddef>
24 #include <iomanip>
25 
26 // External includes
27 #define USE_CONST
28 #include "gidpost/source/gidpost.h"
29 
30 // Project includes
31 #include "includes/define.h"
32 #include "includes/io.h"
35 #include "utilities/timer.h"
36 #include "containers/flags.h"
37 
38 namespace Kratos
39 {
42 
46 
50 
55 
59 
63 
72 class KRATOS_API(KRATOS_CORE) GidIOBase
73  : public IO
74 {
75 protected:
80  int data;
81 
82  // Private constructor so that no objects can be created.
84  data = 0;
85  }
86 
87 public:
88  static GidIOBase& GetInstance();
89 
90  int GetData();
91  void SetData(int data);
92 
93 private:
94  static void Create();
95 
96  static GidIOBase* mpInstance;
97 };
98 
109 template<class TGaussPointContainer = GidGaussPointsContainer, class TMeshContainer = GidMeshContainer>
110 class KRATOS_API(KRATOS_CORE) GidIO
111  : public GidIOBase
112 {
113 public:
116 
119 
121  typedef IO BaseType;
122 
127 
130 
133 
137 
141 
146  const std::string& rDatafilename,
147  const GiD_PostMode Mode,
148  const MultiFileFlag UseMultipleFilesFlag,
149  const WriteDeformedMeshFlag WriteDeformedFlag,
151  const bool InitializeGaussPointContainers=true
152  ) : mResultFileName(rDatafilename),
153  mMeshFileName(rDatafilename),
154  mWriteDeformed(WriteDeformedFlag),
155  mWriteConditions(WriteConditions),
156  mUseMultiFile(UseMultipleFilesFlag),
157  mMode(Mode)
158  {
159  mResultFileOpen = false;
160  mMeshFileOpen = false;
161 
162  InitializeResultFile(mResultFileName);
163  SetUpMeshContainers();
164  if (InitializeGaussPointContainers) {
165  SetUpGaussPointContainers();
166  }
167 
168  GidIOBase& r_gid_io_base = GidIOBase::GetInstance();
169 
170  if (r_gid_io_base.GetData() == 0){
171  GiD_PostInit();
172  }
173  r_gid_io_base.SetData(r_gid_io_base.GetData() + 1);
174  }
175 
177  ~GidIO() override
178  {
179  if ( mResultFileOpen ) {
180  GiD_fClosePostResultFile( mResultFile );
181  mResultFileOpen = false;
182  }
183 
184  GidIOBase& r_gid_io_base = GidIOBase::GetInstance();
185 
186  r_gid_io_base.SetData(r_gid_io_base.GetData() - 1);
187 
188  if (r_gid_io_base.GetData() == 0) {
189  GiD_PostDone();
190  }
191  }
192 
196 
200 
204 
208 
212 
216 
222  {
223  mGidMeshContainers.push_back( TMeshContainer(
225  GiD_Hexahedra, "Kratos_Hexahedra3D20_Mesh" ) );
226  mGidMeshContainers.push_back( TMeshContainer(
228  GiD_Hexahedra, "Kratos_Hexahedra3D27_Mesh" ) );
229  mGidMeshContainers.push_back( TMeshContainer(
231  GiD_Hexahedra, "Kratos_Hexahedra3D8_Mesh" ) );
232  mGidMeshContainers.push_back( TMeshContainer(
234  GiD_Prism, "Kratos_Prism3D15_Mesh" ) );
235  mGidMeshContainers.push_back( TMeshContainer(
237  GiD_Prism, "Kratos_Prism3D6_Mesh" ) );
238  mGidMeshContainers.push_back( TMeshContainer(
240  GiD_Quadrilateral, "Kratos_Quadrilateral2D4_Mesh" ) );
241  mGidMeshContainers.push_back( TMeshContainer(
243  GiD_Quadrilateral, "Kratos_Quadrilateral2D8_Mesh" ) );
244  mGidMeshContainers.push_back( TMeshContainer(
246  GiD_Quadrilateral, "Kratos_Quadrilateral2D9_Mesh" ) );
247  mGidMeshContainers.push_back( TMeshContainer(
249  GiD_Quadrilateral, "Kratos_Quadrilateral3D4_Mesh" ) );
250  mGidMeshContainers.push_back( TMeshContainer(
252  GiD_Quadrilateral, "Kratos_Quadrilateral3D8_Mesh" ) );
253  mGidMeshContainers.push_back( TMeshContainer(
255  GiD_Quadrilateral, "Kratos_Quadrilateral3D9_Mesh" ) );
256  mGidMeshContainers.push_back( TMeshContainer(
258  GiD_Tetrahedra, "Kratos_Tetrahedra3D10_Mesh" ) );
259  mGidMeshContainers.push_back( TMeshContainer(
261  GiD_Tetrahedra, "Kratos_Tetrahedra3D4_Mesh" ) );
262  mGidMeshContainers.push_back( TMeshContainer(
264  GiD_Triangle, "Kratos_Triangle2D3_Mesh" ) );
265  mGidMeshContainers.push_back( TMeshContainer(
267  GiD_Triangle, "Kratos_Triangle2D6_Mesh" ) );
268  mGidMeshContainers.push_back( TMeshContainer(
270  GiD_Triangle, "Kratos_Triangle3D3_Mesh" ) );
271  mGidMeshContainers.push_back( TMeshContainer(
273  GiD_Triangle, "Kratos_Triangle3D6_Mesh" ) );
274  mGidMeshContainers.push_back( TMeshContainer(
276  GiD_Linear, "Kratos_Line2D2_Mesh" ) );
277  mGidMeshContainers.push_back( TMeshContainer(
279  GiD_Linear, "Kratos_Line3D2_Mesh" ) );
280  mGidMeshContainers.push_back( TMeshContainer(
282  GiD_Linear, "Kratos_Line2D3_Mesh" ) );
283  mGidMeshContainers.push_back( TMeshContainer(
285  GiD_Linear, "Kratos_Line3D3_Mesh" ) );
286  mGidMeshContainers.push_back( TMeshContainer(
288  GiD_Point, "Kratos_Point2D_Mesh" ) );
289  mGidMeshContainers.push_back( TMeshContainer(
291  GiD_Point, "Kratos_Point3D_Mesh" ) );
292 
293 
294  }//SetUpMeshContainers
295 
301  {
302  //elements with 1 gauss point
303  std::vector<int> gp_indices(1, 0);
304 
305  //case Triangle with 1 gauss point
306  mGidGaussPointContainers.push_back( TGaussPointContainer( "tri1_element_gp",
307  GeometryData::KratosGeometryFamily::Kratos_Triangle, GiD_Triangle, 1, gp_indices ) );
308  //case Quadrilateral with 1 gauss point
309  mGidGaussPointContainers.push_back( TGaussPointContainer( "quad1_element_gp",
310  GeometryData::KratosGeometryFamily::Kratos_Quadrilateral, GiD_Quadrilateral, 1, gp_indices ) );
311  //case Tetrahedra with 1 gauss point
312  mGidGaussPointContainers.push_back( TGaussPointContainer( "tet1_element_gp",
313  GeometryData::KratosGeometryFamily::Kratos_Tetrahedra, GiD_Tetrahedra, 1, gp_indices ) );
314  //case Hexahedra with 1 gauss point
315  mGidGaussPointContainers.push_back( TGaussPointContainer( "hex1_element_gp",
316  GeometryData::KratosGeometryFamily::Kratos_Hexahedra, GiD_Hexahedra, 1, gp_indices ) );
317  //case Prism with 1 gauss point
318  mGidGaussPointContainers.push_back( TGaussPointContainer( "prism1_element_gp",
319  GeometryData::KratosGeometryFamily::Kratos_Prism, GiD_Prism, 1, gp_indices ) );
320  //case Linear with 1 gauss point
321  mGidGaussPointContainers.push_back( TGaussPointContainer( "lin1_element_gp",
322  GeometryData::KratosGeometryFamily::Kratos_Linear, GiD_Linear, 1, gp_indices ) );
323 
324  //elements with 2 gauss points
325  gp_indices.resize(2);
326  gp_indices[1] = 1;
327  mGidGaussPointContainers.push_back( TGaussPointContainer( "lin2_element_gp",
328  GeometryData::KratosGeometryFamily::Kratos_Linear, GiD_Linear, 2, gp_indices ) );
329 
330 
331  //elements with 3 gauss points
332  gp_indices.resize(3);
333  //case Triangle with 3 gauss points
334  gp_indices[2] = 2;
335  mGidGaussPointContainers.push_back( TGaussPointContainer( "tri3_element_gp",
336  GeometryData::KratosGeometryFamily::Kratos_Triangle, GiD_Triangle, 3, gp_indices ) );
337  //case Linear with 3 gauss points
338  mGidGaussPointContainers.push_back( TGaussPointContainer( "lin3_element_gp",
339  GeometryData::KratosGeometryFamily::Kratos_Linear, GiD_Linear, 3, gp_indices ) );
340 
341  //elements with 4 gauss points
342  gp_indices.resize(4);
343  gp_indices[3] = 3;
344 
345  //case Linear with 4 gauss points
346  mGidGaussPointContainers.push_back( TGaussPointContainer( "lin3_element_gp",
347  GeometryData::KratosGeometryFamily::Kratos_Linear, GiD_Linear, 4, gp_indices ) );
348  //case Quadrilateral with 4 gauss points
349  mGidGaussPointContainers.push_back( TGaussPointContainer( "quad4_element_gp",
350  GeometryData::KratosGeometryFamily::Kratos_Quadrilateral, GiD_Quadrilateral, 4, gp_indices ) );
351  //case Tetrahedra with 4 gauss points
352  mGidGaussPointContainers.push_back( TGaussPointContainer( "tet4_element_gp",
353  GeometryData::KratosGeometryFamily::Kratos_Tetrahedra, GiD_Tetrahedra, 4, gp_indices ) );
354  //case Triangle with 4 gauss points
355  mGidGaussPointContainers.push_back( TGaussPointContainer( "tri4_element_gp",
356  GeometryData::KratosGeometryFamily::Kratos_Triangle, GiD_Triangle, 4, gp_indices ) );
357  gp_indices[0] = 1;
358  gp_indices[1] = 2;
359  gp_indices[2] = 3;
360  gp_indices[3] = 4;
361  //case Tetrahedra with 5 gauss points (4 gauss points will be created for GiD)
362  mGidGaussPointContainers.push_back( TGaussPointContainer( "tet5_element_gp",
363  GeometryData::KratosGeometryFamily::Kratos_Tetrahedra, GiD_Tetrahedra, 5, gp_indices ) );
364  //case Tetrahedra with 11 gauss points (4 gauss points will be created for GiD)
365  mGidGaussPointContainers.push_back( TGaussPointContainer( "tet11_element_gp",
366  GeometryData::KratosGeometryFamily::Kratos_Tetrahedra, GiD_Tetrahedra, 11, gp_indices ) );
367 
368 
369  //elements with 5 gauss points
370  gp_indices.resize(5);
371  gp_indices[0] = 0;
372  gp_indices[1] = 1;
373  gp_indices[2] = 2;
374  gp_indices[3] = 3;
375  gp_indices[4] = 4;
376  //case Linear with 5 gauss points
377  mGidGaussPointContainers.push_back( TGaussPointContainer( "lin5_element_gp",
378  GeometryData::KratosGeometryFamily::Kratos_Linear, GiD_Linear, 5, gp_indices ) );
379 
380  //case Tetrahedra with 10 gauss points (4 gauss points will be created for GiD)
381  gp_indices.resize(10);
382  gp_indices[5] = 5;
383  gp_indices[6] = 6;
384  gp_indices[7] = 7;
385  gp_indices[8] = 8;
386  gp_indices[9] = 9;
387  mGidGaussPointContainers.push_back( TGaussPointContainer( "tet10_element_gp",
388  GeometryData::KratosGeometryFamily::Kratos_Tetrahedra, GiD_Tetrahedra, 10, gp_indices ) );
389 
390  //elements with 6 gauss points
391  gp_indices.resize(6);
392  gp_indices[0] = 0;
393  gp_indices[1] = 1;
394  gp_indices[2] = 2;
395  gp_indices[3] = 3;
396  gp_indices[4] = 4;
397  gp_indices[5] = 5;
398  //case Triangle with 6 gauss points
399  mGidGaussPointContainers.push_back( TGaussPointContainer( "tri6_element_gp",
400  GeometryData::KratosGeometryFamily::Kratos_Triangle, GiD_Triangle, 6, gp_indices ) );
401  //case Prism with 6 Gauss Points
402  mGidGaussPointContainers.push_back( TGaussPointContainer( "prism6_element_gp",
403  GeometryData::KratosGeometryFamily::Kratos_Prism, GiD_Prism, 6, gp_indices ) );
404 
405  /* START: Adding manually the custom prism */
406  //case Prism with 2 Gauss Points (6 gauss points will be created for GiD)
407  mGidGaussPointContainers.push_back( TGaussPointContainer( "prism2_element_gp",
408  GeometryData::KratosGeometryFamily::Kratos_Prism, GiD_Prism, 2, gp_indices ) );
409  //case Prism with 3 Gauss Points (6 gauss points will be created for GiD)
410  mGidGaussPointContainers.push_back( TGaussPointContainer( "prism3_element_gp",
411  GeometryData::KratosGeometryFamily::Kratos_Prism, GiD_Prism, 3, gp_indices ) );
412  //case Prism with 5 Gauss Points (6 gauss points will be created for GiD)
413  mGidGaussPointContainers.push_back( TGaussPointContainer( "prism5_element_gp",
414  GeometryData::KratosGeometryFamily::Kratos_Prism, GiD_Prism, 5, gp_indices ) );
415  //case Prism with 7 Gauss Points (6 gauss points will be created for GiD)
416  mGidGaussPointContainers.push_back( TGaussPointContainer( "prism7_element_gp",
417  GeometryData::KratosGeometryFamily::Kratos_Prism, GiD_Prism, 7, gp_indices ) );
418  //case Prism with 11 Gauss Points (6 gauss points will be created for GiD)
419  mGidGaussPointContainers.push_back( TGaussPointContainer( "prism11_element_gp",
420  GeometryData::KratosGeometryFamily::Kratos_Prism, GiD_Prism, 11, gp_indices ) );
421  /* END: Adding manually the custom prism */
422 
423  //elements with 7 gauss points
424  gp_indices.resize(7);
425  gp_indices[6] = 6;
426  //case Linear with 7 gauss points
427  mGidGaussPointContainers.push_back( TGaussPointContainer( "lin7_element_gp",
428  GeometryData::KratosGeometryFamily::Kratos_Linear, GiD_Linear, 7, gp_indices ) );
429  //elements with 8 gauss points
430  gp_indices.resize(8);
431  gp_indices[7] = 7;
432  //case Hexahedra with 8 gauss points
433  mGidGaussPointContainers.push_back( TGaussPointContainer( "hex8_element_gp",
434  GeometryData::KratosGeometryFamily::Kratos_Hexahedra, GiD_Hexahedra, 8, gp_indices ) );
435 
436  //elements with 9 gauss points
437  gp_indices.resize(9);
438  gp_indices[8] = 8;
439  //case Linear with 9 gauss points
440  mGidGaussPointContainers.push_back( TGaussPointContainer( "lin9_element_gp",
441  GeometryData::KratosGeometryFamily::Kratos_Linear, GiD_Linear, 9, gp_indices ) );
442  //case Prism with 9 Gauss Points
443  mGidGaussPointContainers.push_back( TGaussPointContainer( "prism9_element_gp",
444  GeometryData::KratosGeometryFamily::Kratos_Prism, GiD_Prism, 9, gp_indices ) );
445  // case quadrilateral with 9 Gauss Points
446  mGidGaussPointContainers.push_back( TGaussPointContainer( "quad9_element_gp",
447  GeometryData::KratosGeometryFamily::Kratos_Quadrilateral, GiD_Quadrilateral, 9, gp_indices ) );
448 
449  //elements with 11 gauss points
450  gp_indices.resize(11);
451  gp_indices[10] = 10;
452  //case Linear with 11 gauss points
453  mGidGaussPointContainers.push_back( TGaussPointContainer( "lin11_element_gp",
454  GeometryData::KratosGeometryFamily::Kratos_Linear, GiD_Linear, 11, gp_indices ) );
455 
456  //elements with 27 gauss points
457  gp_indices.resize(27);
458  gp_indices[0] = 0;
459  gp_indices[8] = 1;
460  gp_indices[1] = 2;
461  gp_indices[11] = 3;
462  gp_indices[20] = 4;
463  gp_indices[9] = 5;
464  gp_indices[3] = 6;
465  gp_indices[10] = 7;
466  gp_indices[2] = 8;
467  gp_indices[12] = 9;
468  gp_indices[21] = 10;
469  gp_indices[13] = 11;
470  gp_indices[24] = 12;
471  gp_indices[26] = 13;
472  gp_indices[22] = 14;
473  gp_indices[15] = 15;
474  gp_indices[23] = 16;
475  gp_indices[14] = 17;
476  gp_indices[4] = 18;
477  gp_indices[16] = 19;
478  gp_indices[5] = 20;
479  gp_indices[19] = 21;
480  gp_indices[25] = 22;
481  gp_indices[17] = 23;
482  gp_indices[7] = 24;
483  gp_indices[18] = 25;
484  gp_indices[6] = 26;
485  //case Hexahedra with 27 Gauss Points
486  mGidGaussPointContainers.push_back( TGaussPointContainer( "hex27_element_gp",
487  GeometryData::KratosGeometryFamily::Kratos_Hexahedra, GiD_Hexahedra, 27, gp_indices ) );
488 
489  }//SetUpGaussPointContainers
490 
491 
493 
498  void ChangeOutputName(const std::string& rDatafilename )
499  {
500  KRATOS_TRY
501  mMeshFileName = rDatafilename;
502  mResultFileName = rDatafilename;
503  KRATOS_CATCH("")
504  }
505 
510  void InitializeResultFile( std::string const& rResultFileName )
511  {
512  mResultFileName = rResultFileName;
513  }
514 
519  {
520  if ( mResultFileOpen )
521  {
522  GiD_fClosePostResultFile( mResultFile );
523  mResultFileOpen = false;
524  }
525  }
526 
530  void Flush()
531  {
532  GiD_fFlushPostFile( mResultFile );
533  }
534 
535 
539  std::string Info() const override
540  {
541  return "gid io";
542  }
543 
547  void PrintInfo(std::ostream& rOStream) const override
548  {
549  rOStream << Info();
550  }
551 
555  void PrintData(std::ostream& rOStream) const override
556  {
557  }
558 
560 
566  virtual void InitializeResults(
567  const double name,
568  const MeshType& rThisMesh
569  )
570  {
571  if ( mMode == GiD_PostAscii && ! mResultFileOpen )
572  {
573  std::stringstream file_name;
574  if ( mUseMultiFile == SingleFile ) {
575  file_name << mResultFileName << ".post.res";
576  } else {
577  file_name << mResultFileName << std::setprecision(12) << "_" << name << ".post.res";
578  }
579  mResultFile = GiD_fOpenPostResultFile((char*)(file_name.str()).c_str(), mMode);
580  mResultFileOpen = true;
581  }
582  //initializing gauss points containers
583  if ( mWriteConditions != WriteConditionsOnly )
584  {
585  for ( auto element_iterator = rThisMesh.ElementsBegin(); element_iterator != rThisMesh.ElementsEnd(); ++element_iterator )
586  {
587  for ( auto it = mGidGaussPointContainers.begin(); it != mGidGaussPointContainers.end(); it++ )
588  {
589  if ( it->AddElement( element_iterator ) )
590  break;
591  }
592 
593  }
594  }
595 
596  if ( mWriteConditions == WriteConditionsFlag::WriteConditions || mWriteConditions == WriteConditionsOnly )
597  for ( auto conditions_iterator = rThisMesh.ConditionsBegin(); conditions_iterator != rThisMesh.ConditionsEnd(); conditions_iterator++ )
598  {
599  for ( auto it = mGidGaussPointContainers.begin(); it != mGidGaussPointContainers.end(); it++ )
600  {
601 
602  if ( it->AddCondition( conditions_iterator ) )
603  break;
604  }
605  }
606 
607  // Writing gauss points definitions
608  for ( auto it = mGidGaussPointContainers.begin();
609  it != mGidGaussPointContainers.end(); it++ )
610  {
611  it->WriteGaussPoints(mResultFile);
612  }
613  }
619  {
620  if ( mUseMultiFile == MultipleFiles || mMode == GiD_PostAscii )
621  {
622  GiD_fClosePostResultFile( mResultFile );
623  mResultFileOpen = false;
624  }
625  //resetting gauss point containers
626  for ( auto it =
627  mGidGaussPointContainers.begin();
628  it != mGidGaussPointContainers.end(); it++ )
629  {
630  it->Reset();
631  }
632  }
633 
635 
639 
643  Variable<bool> const& rVariable,
644  const NodesContainerType& rNodes,
645  const double SolutionTag,
646  const std::size_t SolutionStepNumber
647  )
648  {
649  Timer::Start("Writing Results");
650  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
651  SolutionTag, GiD_Scalar,
652  GiD_OnNodes, NULL, NULL, 0, NULL );
653  for ( auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
654  GiD_fWriteScalar( mResultFile, it_node->Id(), static_cast<double>(it_node->GetSolutionStepValue(rVariable,
655  SolutionStepNumber)) );
656  GiD_fEndResult(mResultFile);
657 
658  Timer::Stop("Writing Results");
659 
660  }
661 
663 
667  Variable<double> const& rVariable,
668  const NodesContainerType& rNodes,
669  const double SolutionTag,
670  const std::size_t SolutionStepNumber
671  )
672  {
673  Timer::Start("Writing Results");
674  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
675  SolutionTag, GiD_Scalar,
676  GiD_OnNodes, NULL, NULL, 0, NULL );
677  for ( auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
678  GiD_fWriteScalar( mResultFile, it_node->Id(), it_node->GetSolutionStepValue(rVariable,
679  SolutionStepNumber) );
680  GiD_fEndResult(mResultFile);
681 
682  Timer::Stop("Writing Results");
683  }
684 
689  Variable<int> const& rVariable,
690  const NodesContainerType& rNodes,
691  const double SolutionTag,
692  const std::size_t SolutionStepNumber
693  )
694  {
695  Timer::Start("Writing Results");
696  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
697  SolutionTag, GiD_Scalar,
698  GiD_OnNodes, NULL, NULL, 0, NULL );
699  for ( auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
700  GiD_fWriteScalar( mResultFile, it_node->Id(), it_node->GetSolutionStepValue(rVariable,
701  SolutionStepNumber) );
702  GiD_fEndResult(mResultFile);
703 
704  Timer::Stop("Writing Results");
705  }
706 
707 
713  Variable<array_1d<double, 3> > const& rVariable,
714  const NodesContainerType& rNodes,
715  const double SolutionTag,
716  const std::size_t SolutionStepNumber
717  )
718  {
719  Timer::Start("Writing Results");
720 
721  GiD_fBeginResult(mResultFile,(char*)(rVariable.Name().c_str()), "Kratos",
722  SolutionTag, GiD_Vector,
723  GiD_OnNodes, NULL, NULL, 0, NULL );
724  for (auto it_node = rNodes.begin();
725  it_node != rNodes.end() ; ++it_node)
726  {
727  const array_1d<double, 3>& temp = it_node->GetSolutionStepValue( rVariable,
728  SolutionStepNumber );
729  GiD_fWriteVector( mResultFile, it_node->Id(), temp[0], temp[1], temp[2] );
730  }
731  GiD_fEndResult(mResultFile);
732 
733  Timer::Stop("Writing Results");
734  }
735 
741  Variable<Vector> const& rVariable,
742  const NodesContainerType& rNodes,
743  const double SolutionTag,
744  const std::size_t SolutionStepNumber
745  )
746  {
747  Timer::Start("Writing Results");
748 
749  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
750  SolutionTag, GiD_Matrix,
751  GiD_OnNodes, NULL, NULL, 0, NULL );
752  for (auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
753  {
754  const Vector& temp_vector = it_node->FastGetSolutionStepValue(rVariable,
755  SolutionStepNumber);
756  if (temp_vector.size() ==3 )
757  GiD_fWrite2DMatrix(mResultFile, it_node->Id(), temp_vector[0], temp_vector[1], temp_vector[2]);
758  else if (temp_vector.size() == 6 )
759  GiD_fWrite3DMatrix( mResultFile, it_node->Id(), temp_vector[0], temp_vector[1], temp_vector[2],
760  temp_vector[3], temp_vector[4], temp_vector[5] );
761  }
762  GiD_fEndResult(mResultFile);
763 
764  Timer::Stop("Writing Results");
765  }
766 
771  Variable<Matrix> const& rVariable,
772  const NodesContainerType& rNodes,
773  const double SolutionTag,
774  const std::size_t SolutionStepNumber
775  )
776  {
777  Timer::Start("Writing Results");
778 
779  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
780  SolutionTag, GiD_Matrix,
781  GiD_OnNodes, NULL, NULL, 0, NULL );
782  for (auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
783  {
784  const Matrix& temp_matrix = it_node->GetSolutionStepValue(rVariable,
785  SolutionStepNumber);
786  if (temp_matrix.size1() ==3 && temp_matrix.size2() ==3)
787  {
788  GiD_fWrite3DMatrix( mResultFile, it_node->Id(), temp_matrix(0,0), temp_matrix(1,1),
789  temp_matrix(2,2), temp_matrix(0,1), temp_matrix(1,2),
790  temp_matrix(0,2) );
791  }
792  else if (temp_matrix.size1() ==2 && temp_matrix.size2() ==2)
793  {
794  GiD_fWrite2DMatrix( mResultFile, it_node->Id(), temp_matrix(0,0), temp_matrix(1,1), temp_matrix(0,1));
795  }
796 
797  else if (temp_matrix.size1() ==1 && temp_matrix.size2() ==3)
798  {
799 
800  GiD_fWrite3DMatrix( mResultFile, it_node->Id(), temp_matrix(0,0), temp_matrix(0,1), 0.00,
801  temp_matrix(0,2), 0.00, 0.00);
802  }
803  else if (temp_matrix.size1() ==1 && temp_matrix.size2() ==6)
804  {
805  GiD_fWrite3DMatrix( mResultFile, it_node->Id(), temp_matrix(0,0), temp_matrix(0,1), temp_matrix(0,2),
806  temp_matrix(0,3), temp_matrix(0,4), temp_matrix(0,5) );
807  }
808  //it_node->GetValue(rVariable) = temp_matrix;
809 
810  }
811  GiD_fEndResult(mResultFile);
812 
813  Timer::Stop("Writing Results");
814  }
815 
817  Variable<array_1d<double, 3> > const& rVariable,
818  const NodesContainerType& rNodes,
819  const double SolutionTag,
820  const std::size_t SolutionStepNumber
821  )
822  {
823  Timer::Start("Writing Results");
824 
825  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
826  SolutionTag, GiD_LocalAxes,
827  GiD_OnNodes, NULL, NULL, 0, NULL );
828 
829  for (auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
830  {
831  const array_1d<double, 3>& temp = it_node->GetSolutionStepValue( rVariable,
832  SolutionStepNumber );
833  GiD_fWriteLocalAxes( mResultFile, it_node->Id(), temp[0], temp[1], temp[2] );
834  }
835  GiD_fEndResult(mResultFile);
836 
837  Timer::Stop("Writing Results");
838  }
839 
843 
848  const Kratos::Flags& rFlag,
849  const std::string& rFlagName,
850  const NodesContainerType& rNodes,
851  const double SolutionTag
852  )
853  {
854  Timer::Start("Writing Results");
855  GiD_fBeginResult( mResultFile, (char*)(rFlagName.c_str()), "Kratos",
856  SolutionTag, GiD_Scalar,
857  GiD_OnNodes, NULL, NULL, 0, NULL );
858  for ( auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
859  {
860  GiD_fWriteScalar( mResultFile, it_node->Id(), static_cast<double>(it_node->Is(rFlag)));
861  }
862  GiD_fEndResult(mResultFile);
863 
864  Timer::Stop("Writing Results");
865  }
866 
871  Variable<bool> const& rVariable,
872  const NodesContainerType& rNodes,
873  const double SolutionTag
874  )
875  {
876  Timer::Start("Writing Results");
877  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
878  SolutionTag, GiD_Scalar,
879  GiD_OnNodes, NULL, NULL, 0, NULL );
880  for ( auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
881  GiD_fWriteScalar( mResultFile, it_node->Id(), static_cast<double>(it_node->GetValue(rVariable)) );
882  GiD_fEndResult(mResultFile);
883 
884  Timer::Stop("Writing Results");
885  }
886 
888 
892  Variable<double> const& rVariable,
893  const NodesContainerType& rNodes,
894  const double SolutionTag
895  )
896  {
897  Timer::Start("Writing Results");
898  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
899  SolutionTag, GiD_Scalar,
900  GiD_OnNodes, NULL, NULL, 0, NULL );
901  for ( auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
902  GiD_fWriteScalar( mResultFile, it_node->Id(), it_node->GetValue(rVariable) );
903  GiD_fEndResult(mResultFile);
904 
905  Timer::Stop("Writing Results");
906  }
907 
912  Variable<int> const& rVariable,
913  const NodesContainerType& rNodes,
914  const double SolutionTag
915  )
916  {
917  Timer::Start("Writing Results");
918  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
919  SolutionTag, GiD_Scalar,
920  GiD_OnNodes, NULL, NULL, 0, NULL );
921  for ( auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
922  GiD_fWriteScalar( mResultFile, it_node->Id(), it_node->GetValue(rVariable) );
923  GiD_fEndResult(mResultFile);
924 
925  Timer::Stop("Writing Results");
926  }
927 
933  Variable<array_1d<double, 3> > const& rVariable,
934  const NodesContainerType& rNodes,
935  const double SolutionTag
936  )
937  {
938  Timer::Start("Writing Results");
939 
940  GiD_fBeginResult(mResultFile,(char*)(rVariable.Name().c_str()), "Kratos",
941  SolutionTag, GiD_Vector,
942  GiD_OnNodes, NULL, NULL, 0, NULL );
943  for (auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
944  {
945  const array_1d<double, 3>& temp = it_node->GetValue( rVariable);
946  GiD_fWriteVector( mResultFile, it_node->Id(), temp[0], temp[1], temp[2] );
947  }
948  GiD_fEndResult(mResultFile);
949 
950  Timer::Stop("Writing Results");
951  }
952 
958  Variable<Vector> const& rVariable,
959  const NodesContainerType& rNodes,
960  const double SolutionTag
961  )
962  {
963  Timer::Start("Writing Results");
964 
965  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
966  SolutionTag, GiD_Matrix,
967  GiD_OnNodes, NULL, NULL, 0, NULL );
968  for (auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
969  {
970  const Vector& temp_vector = it_node->GetValue(rVariable);
971  if (temp_vector.size() ==3 )
972  GiD_fWrite2DMatrix(mResultFile, it_node->Id(), temp_vector[0], temp_vector[1], temp_vector[2]);
973  else if (temp_vector.size() == 6 )
974  GiD_fWrite3DMatrix( mResultFile, it_node->Id(), temp_vector[0], temp_vector[1], temp_vector[2],
975  temp_vector[3], temp_vector[4], temp_vector[5] );
976  }
977  GiD_fEndResult(mResultFile);
978 
979  Timer::Stop("Writing Results");
980  }
981 
986  Variable<Matrix> const& rVariable,
987  const NodesContainerType& rNodes,
988  const double SolutionTag
989  )
990  {
991  Timer::Start("Writing Results");
992 
993  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
994  SolutionTag, GiD_Matrix,
995  GiD_OnNodes, NULL, NULL, 0, NULL );
996  for (auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
997  {
998  const Matrix& temp_matrix = it_node->GetValue(rVariable);
999  if (temp_matrix.size1() ==3 && temp_matrix.size2() ==3)
1000  {
1001  GiD_fWrite3DMatrix( mResultFile, it_node->Id(), temp_matrix(0,0), temp_matrix(1,1),
1002  temp_matrix(2,2), temp_matrix(0,1), temp_matrix(1,2),
1003  temp_matrix(0,2) );
1004  }
1005  else if (temp_matrix.size1() ==2 && temp_matrix.size2() ==2)
1006  {
1007  GiD_fWrite2DMatrix( mResultFile, it_node->Id(), temp_matrix(0,0), temp_matrix(1,1), temp_matrix(0,1));
1008  }
1009 
1010  else if (temp_matrix.size1() ==1 && temp_matrix.size2() ==3)
1011  {
1012 
1013  GiD_fWrite3DMatrix( mResultFile, it_node->Id(), temp_matrix(0,0), temp_matrix(0,1), 0.00,
1014  temp_matrix(0,2), 0.00, 0.00);
1015  }
1016  else if (temp_matrix.size1() ==1 && temp_matrix.size2() ==6)
1017  {
1018  GiD_fWrite3DMatrix( mResultFile, it_node->Id(), temp_matrix(0,0), temp_matrix(0,1), temp_matrix(0,2),
1019  temp_matrix(0,3), temp_matrix(0,4), temp_matrix(0,5) );
1020  }
1021 
1022  }
1023  GiD_fEndResult(mResultFile);
1024 
1025  Timer::Stop("Writing Results");
1026  }
1027 
1029  Variable<array_1d<double, 3> > const& rVariable,
1030  const NodesContainerType& rNodes,
1031  const double SolutionTag
1032  )
1033  {
1034  Timer::Start("Writing Results");
1035 
1036  GiD_fBeginResult( mResultFile, (char*)(rVariable.Name().c_str()), "Kratos",
1037  SolutionTag, GiD_LocalAxes,
1038  GiD_OnNodes, NULL, NULL, 0, NULL );
1039 
1040  for (auto it_node = rNodes.begin(); it_node != rNodes.end() ; ++it_node)
1041  {
1042  const array_1d<double, 3>& temp = it_node->GetSolutionStepValue( rVariable);
1043  GiD_fWriteLocalAxes( mResultFile, it_node->Id(), temp[0], temp[1], temp[2] );
1044  }
1045  GiD_fEndResult(mResultFile);
1046 
1047  Timer::Stop("Writing Results");
1048  }
1049 
1051 
1054  void InitializeMesh( const double name )
1055  {
1056  if ( mUseMultiFile == MultipleFiles )
1057  {
1058  if ( mMode == GiD_PostAscii && ! mMeshFileOpen )
1059  {
1060  std::stringstream file_name;
1061  file_name << std::setprecision(12) << mMeshFileName << "_" << name << ".post.msh";
1062  mMeshFile = GiD_fOpenPostMeshFile( (char *)(file_name.str()).c_str(), mMode);
1063  mMeshFileOpen = true;
1064  }
1065  if ( (mMode == GiD_PostBinary || mMode == GiD_PostHDF5) && ! mResultFileOpen )
1066  {
1067  std::stringstream file_name;
1068  file_name << std::setprecision(12) << mResultFileName << "_" << name << ".post.bin";
1069  if ( ! mResultFileOpen )
1070  {
1071  mResultFile = GiD_fOpenPostResultFile((char*)(file_name.str()).c_str(), mMode);
1072  mResultFileOpen = true;
1073  }
1074  mMeshFile = mResultFile;
1075  }
1076  }
1077  if ( mUseMultiFile == SingleFile )
1078  {
1079  if ( (mMode == GiD_PostBinary || mMode == GiD_PostHDF5) && ! mResultFileOpen )
1080  {
1081  std::stringstream file_name;
1082  file_name << mResultFileName << ".post.bin";
1083  mResultFile = GiD_fOpenPostResultFile((char*)(file_name.str()).c_str(), mMode);
1084  if ( mResultFile == 0) //error handler can not be zero
1085  {
1086  std::stringstream buffer;
1087  buffer << "error opening results file:" << "/" << file_name.str() << "/";
1088  KRATOS_THROW_ERROR(std::runtime_error, buffer.str(), "");
1089  }
1090  mResultFileOpen = true;
1091  mMeshFile = mResultFile;
1092  }
1093  if ( mMode == GiD_PostAscii && ! mMeshFileOpen )
1094  {
1095  std::stringstream file_name;
1096  file_name << mMeshFileName << ".post.msh";
1097  mMeshFile = GiD_fOpenPostMeshFile( (char *)(file_name.str()).c_str(), mMode);
1098  mMeshFileOpen = true;
1099  }
1100  }
1101  }
1102 
1107  {
1108  if ( mUseMultiFile == MultipleFiles && mMode == GiD_PostAscii )
1109  {
1110  GiD_fClosePostMeshFile(mMeshFile);
1111  mMeshFileOpen = false;
1112  }
1113  if ( mUseMultiFile == SingleFile && mMode == GiD_PostAscii )
1114  {
1115  GiD_fClosePostMeshFile(mMeshFile);
1116  mMeshFileOpen = false;
1117  }
1118  }
1119 
1128  void WriteNodeMesh(MeshType& rThisMesh) override
1129  {
1130  KRATOS_TRY
1131 
1132  Timer::Start("Writing Mesh");
1133 
1134  GiD_fBeginMesh(mMeshFile, "Kratos Mesh",GiD_3D,GiD_Point,1);
1135  GiD_fBeginCoordinates(mMeshFile);
1136  for ( auto node_iterator = rThisMesh.NodesBegin();
1137  node_iterator != rThisMesh.NodesEnd();
1138  ++node_iterator)
1139  {
1140  if ( mWriteDeformed == WriteUndeformed )
1141  GiD_fWriteCoordinates(mMeshFile, node_iterator->Id(), node_iterator->X0(),
1142  node_iterator->Y0(), node_iterator->Z0() );
1143  else if ( mWriteDeformed == WriteDeformed )
1144  GiD_fWriteCoordinates(mMeshFile, node_iterator->Id(), node_iterator->X(),
1145  node_iterator->Y(), node_iterator->Z() );
1146  else
1147  KRATOS_ERROR << "Undefined WriteDeformedMeshFlag" << std::endl;
1148  }
1149  GiD_fEndCoordinates(mMeshFile);
1150  int nodes_id[1];
1151  GiD_fBeginElements(mMeshFile);
1152 
1153  for ( auto node_iterator = rThisMesh.NodesBegin(); node_iterator != rThisMesh.NodesEnd(); ++node_iterator)
1154  {
1155  nodes_id[0] = node_iterator->Id();
1156  GiD_fWriteElement(mMeshFile,node_iterator->Id(), nodes_id);
1157  }
1158  GiD_fEndElements(mMeshFile);
1159  GiD_fEndMesh(mMeshFile);
1160 
1161  Timer::Stop("Writing Mesh");
1162 
1163  KRATOS_CATCH("")
1164  }
1165 
1166  void WriteSphereMesh(const MeshType& rThisMesh)
1167  {
1168  KRATOS_TRY
1169 
1170  Timer::Start("Writing Mesh");
1171 
1172  GiD_fBeginMesh(mMeshFile, "Kratos Mesh",GiD_3D,GiD_Sphere,1);
1173  GiD_fBeginCoordinates(mMeshFile);
1174  for ( auto node_iterator = rThisMesh.NodesBegin(); node_iterator != rThisMesh.NodesEnd(); ++node_iterator)
1175  {
1176  if ( mWriteDeformed == WriteUndeformed )
1177  GiD_fWriteCoordinates( mMeshFile, node_iterator->Id(), node_iterator->X0(),
1178  node_iterator->Y0(), node_iterator->Z0() );
1179  else if ( mWriteDeformed == WriteDeformed )
1180  GiD_fWriteCoordinates( mMeshFile, node_iterator->Id(), node_iterator->X(),
1181  node_iterator->Y(), node_iterator->Z() );
1182  else
1183  KRATOS_ERROR << "Undefined WriteDeformedMeshFlag" << std::endl;
1184  }
1185  GiD_fEndCoordinates( mMeshFile );
1186 
1187  GiD_fBeginElements( mMeshFile );
1188 
1189  // DEM variables
1190  const Variable<int>& particle_material = KratosComponents<Variable<int>>::Get("PARTICLE_MATERIAL");
1192 
1193  for ( auto element_iterator = rThisMesh.ElementsBegin(); element_iterator != rThisMesh.ElementsEnd(); ++element_iterator)
1194  {
1195  const unsigned int node_id = element_iterator->GetGeometry()[0].Id();
1196  GiD_fWriteSphereMat(mMeshFile, node_id, node_id, element_iterator->GetGeometry()[0].FastGetSolutionStepValue(radius), element_iterator->GetGeometry()[0].FastGetSolutionStepValue(particle_material));
1197  }
1198  GiD_fEndElements( mMeshFile );
1199  GiD_fEndMesh( mMeshFile);
1200 
1201  Timer::Stop("Writing Mesh");
1202 
1203  KRATOS_CATCH("")
1204  }
1205 
1206  void WriteCircleMesh(const MeshType& rThisMesh)
1207  {
1208  KRATOS_TRY
1209 
1210  Timer::Start("Writing Mesh");
1211  GiD_fBeginMesh(mMeshFile, "Kratos Mesh",GiD_2D,GiD_Circle,1);
1212  GiD_fBeginCoordinates(mMeshFile);
1213  for ( auto node_iterator = rThisMesh.NodesBegin(); node_iterator != rThisMesh.NodesEnd(); ++node_iterator)
1214  {
1215  if ( mWriteDeformed == WriteUndeformed )
1216  GiD_fWriteCoordinates( mMeshFile, node_iterator->Id(), node_iterator->X0(),
1217  node_iterator->Y0(), node_iterator->Z0() );
1218  else if ( mWriteDeformed == WriteDeformed )
1219  GiD_fWriteCoordinates( mMeshFile, node_iterator->Id(), node_iterator->X(),
1220  node_iterator->Y(), node_iterator->Z() );
1221  else
1222  KRATOS_ERROR << "Undefined WriteDeformedMeshFlag" << std::endl;
1223  }
1224  GiD_fEndCoordinates( mMeshFile );
1225  int nodes_id[1];
1226  GiD_fBeginElements( mMeshFile );
1227 
1228  double nx = 0.0;
1229  double ny = 0.0;
1230  double nz = 1.0;
1231 
1232  // DEM variables
1233  const Variable<int>& particle_material = KratosComponents<Variable<int>>::Get("PARTICLE_MATERIAL");
1235 
1236  for ( auto node_iterator = rThisMesh.NodesBegin(); node_iterator != rThisMesh.NodesEnd(); ++node_iterator)
1237  {
1238  nodes_id[0] = node_iterator->Id();
1239  GiD_fWriteCircleMat(mMeshFile, node_iterator->Id(), nodes_id[0], node_iterator->FastGetSolutionStepValue(radius), nx, ny, nz, node_iterator->FastGetSolutionStepValue(particle_material));
1240  }
1241  GiD_fEndElements( mMeshFile );
1242  GiD_fEndMesh( mMeshFile);
1243  Timer::Stop("Writing Mesh");
1244 
1245  KRATOS_CATCH("")
1246  }
1247 
1248  void WriteClusterMesh(const MeshType& rThisMesh)
1249  {
1250  KRATOS_TRY
1251 
1252  Timer::Start("Writing Mesh");
1253 
1254  GiD_fBeginMesh(mMeshFile, "Kratos Mesh",GiD_3D,GiD_Cluster,1);
1255  GiD_fBeginCoordinates(mMeshFile);
1256  for ( auto node_iterator = rThisMesh.NodesBegin(); node_iterator != rThisMesh.NodesEnd(); ++node_iterator)
1257  {
1258  if ( mWriteDeformed == WriteUndeformed )
1259  GiD_fWriteCoordinates( mMeshFile, node_iterator->Id(), node_iterator->X0(),
1260  node_iterator->Y0(), node_iterator->Z0() );
1261  else if ( mWriteDeformed == WriteDeformed )
1262  GiD_fWriteCoordinates( mMeshFile, node_iterator->Id(), node_iterator->X(),
1263  node_iterator->Y(), node_iterator->Z() );
1264  else
1265  KRATOS_ERROR << "Undefined WriteDeformedMeshFlag" << std::endl;
1266  }
1267  GiD_fEndCoordinates( mMeshFile );
1268 
1269  GiD_fBeginElements( mMeshFile );
1270 
1271  // DEM variables
1272  const Variable<int>& particle_material = KratosComponents<Variable<int>>::Get("PARTICLE_MATERIAL");
1273 
1274  for ( auto element_iterator = rThisMesh.ElementsBegin(); element_iterator != rThisMesh.ElementsEnd(); ++element_iterator)
1275  {
1276  const unsigned int node_id = element_iterator->GetGeometry()[0].Id();
1277  GiD_fWriteClusterMat(mMeshFile, node_id, node_id, element_iterator->GetGeometry()[0].FastGetSolutionStepValue(particle_material));
1278  }
1279  GiD_fEndElements( mMeshFile );
1280  GiD_fEndMesh( mMeshFile);
1281 
1282  Timer::Stop("Writing Mesh");
1283 
1284  KRATOS_CATCH("")
1285  }//WriteClusterMesh
1286 
1287 
1295  void WriteMesh(MeshType& rThisMesh) override
1296  {
1297  KRATOS_TRY
1298 
1299  Timer::Start("Writing Mesh");
1300 
1301  if ( mWriteConditions != WriteConditionsOnly )
1302  {
1303  for ( auto element_iterator = rThisMesh.ElementsBegin(); element_iterator != rThisMesh.ElementsEnd(); ++element_iterator)
1304  for ( auto it = mGidMeshContainers.begin(); it != mGidMeshContainers.end(); it++ )
1305  if ( it->AddElement( element_iterator ) )
1306  break;
1307  }
1308  if ( mWriteConditions == WriteConditionsFlag::WriteConditions || mWriteConditions == WriteConditionsOnly )
1309  {
1310  for ( auto conditions_iterator = rThisMesh.ConditionsBegin(); conditions_iterator != rThisMesh.ConditionsEnd(); conditions_iterator++ )
1311  for ( auto it = mGidMeshContainers.begin(); it != mGidMeshContainers.end(); it++ )
1312  if ( it->AddCondition( conditions_iterator ) )
1313  break;
1314  }
1315 
1316  for ( auto it = mGidMeshContainers.begin(); it != mGidMeshContainers.end(); it++ )
1317  {
1318  it->FinalizeMeshCreation();
1319  if ( mWriteDeformed == WriteDeformed )
1320  it->WriteMesh(mMeshFile,true);
1321  else if ( mWriteDeformed == WriteUndeformed )
1322  it->WriteMesh(mMeshFile,false);
1323  else
1324  KRATOS_ERROR << "Undefined WriteDeformedMeshFlag" << std::endl;
1325 
1326  it->Reset();
1327  }
1328 
1329  Timer::Stop("Writing Mesh");
1330 
1331  KRATOS_CATCH("")
1332  }
1333 
1335 
1343  const Kratos::Flags& rFlag,
1344  const std::string& rFlagName,
1345  const ModelPart& rModelPart,
1346  const double SolutionTag
1347  )
1348  {
1349  Timer::Start("Writing Results");
1350 
1351  for ( auto it = mGidGaussPointContainers.begin(); it != mGidGaussPointContainers.end(); it++ ) {
1352  it->PrintFlagsResults( mResultFile, rFlag, rFlagName, rModelPart, SolutionTag );
1353  }
1354 
1355  Timer::Stop("Writing Results");
1356  }
1357 
1363  virtual void PrintOnGaussPoints(
1364  const Variable<bool>& rVariable,
1365  const ModelPart& rModelPart,
1366  const double SolutionTag, const int ValueIndex = 0 )
1367  {
1368  KRATOS_TRY;
1369 
1370  Timer::Start("Writing Results");
1371 
1372  for ( auto it = mGidGaussPointContainers.begin(); it != mGidGaussPointContainers.end(); it++ ) {
1373  it->PrintResults( mResultFile, rVariable, rModelPart, SolutionTag, ValueIndex );
1374  }
1375 
1376  Timer::Stop("Writing Results");
1377 
1378  KRATOS_CATCH("");
1379  }
1380 
1386  virtual void PrintOnGaussPoints(
1387  const Variable<int>& rVariable,
1388  const ModelPart& rModelPart,
1389  const double SolutionTag,
1390  const int ValueIndex = 0
1391  )
1392  {
1393  KRATOS_TRY;
1394 
1395  Timer::Start("Writing Results");
1396 
1397  for ( auto it = mGidGaussPointContainers.begin(); it != mGidGaussPointContainers.end(); it++ ) {
1398  it->PrintResults( mResultFile, rVariable, rModelPart, SolutionTag, ValueIndex );
1399  }
1400 
1401  Timer::Stop("Writing Results");
1402 
1403  KRATOS_CATCH("");
1404  }
1405 
1411  virtual void PrintOnGaussPoints(
1412  const Variable<double>& rVariable,
1413  const ModelPart& rModelPart,
1414  const double SolutionTag,
1415  const int ValueIndex = 0
1416  )
1417  {
1418  KRATOS_TRY;
1419 
1420  Timer::Start("Writing Results");
1421 
1422  for ( auto it = mGidGaussPointContainers.begin(); it != mGidGaussPointContainers.end(); it++ ) {
1423  it->PrintResults( mResultFile, rVariable, rModelPart, SolutionTag, ValueIndex );
1424  }
1425 
1426  Timer::Stop("Writing Results");
1427 
1428  KRATOS_CATCH("");
1429  }
1430 
1436  virtual void PrintOnGaussPoints(
1437  const Variable<array_1d<double,3> >& rVariable,
1438  const ModelPart& rModelPart,
1439  const double SolutionTag,
1440  const int ValueIndex = 0
1441  )
1442  {
1443  KRATOS_TRY;
1444 
1445  Timer::Start("Writing Results");
1446 
1447  for ( auto it = mGidGaussPointContainers.begin(); it != mGidGaussPointContainers.end(); it++ ) {
1448  it->PrintResults( mResultFile, rVariable, rModelPart, SolutionTag, ValueIndex );
1449  }
1450 
1451  Timer::Stop("Writing Results");
1452 
1453  KRATOS_CATCH("");
1454  }
1455 
1461  virtual void PrintOnGaussPoints(
1462  const Variable<Vector>& rVariable,
1463  const ModelPart& rModelPart,
1464  const double SolutionTag,
1465  const int ValueIndex = 0
1466  )
1467  {
1468  KRATOS_TRY;
1469  Timer::Start("Writing Results");
1470 
1471  for ( auto it = mGidGaussPointContainers.begin(); it != mGidGaussPointContainers.end(); it++ ) {
1472  it->PrintResults( mResultFile, rVariable, rModelPart, SolutionTag, ValueIndex );
1473  }
1474 
1475  Timer::Stop("Writing Results");
1476 
1477  KRATOS_CATCH("");
1478  }
1479 
1485  virtual void PrintOnGaussPoints(
1486  const Variable<Matrix>& rVariable,
1487  const ModelPart& rModelPart,
1488  const double SolutionTag,
1489  const int ValueIndex = 0
1490  )
1491  {
1492  KRATOS_TRY;
1493  Timer::Start("Writing Results");
1494 
1495  for ( auto it = mGidGaussPointContainers.begin(); it != mGidGaussPointContainers.end(); it++ ) {
1496  it->PrintResults( mResultFile, rVariable, rModelPart, SolutionTag, ValueIndex );
1497  }
1498 
1499  Timer::Stop("Writing Results");
1500 
1501  KRATOS_CATCH("");
1502  }
1503 
1504 protected:
1508  std::string mResultFileName;
1509  std::string mMeshFileName;
1510 
1511  GiD_FILE mMeshFile;
1512  GiD_FILE mResultFile;
1513 
1520  GiD_PostMode mMode;
1521 
1525  std::vector<TMeshContainer> mGidMeshContainers;
1526  std::vector<TGaussPointContainer> mGidGaussPointContainers;
1529 
1530 private:
1534  GidIO& operator=(GidIO const& rOther);
1535 
1539  GidIO(GidIO const& rOther);
1540 }; // Class GidIO
1541 
1543 
1547 
1548 inline std::ostream& operator << (std::ostream& rOStream, const GidIO<>& rThis)
1549 {
1550  rThis.PrintInfo(rOStream);
1551  rOStream << std::endl;
1552  rThis.PrintData(rOStream);
1553  return rOStream;
1554 }
1555 
1556 }// namespace Kratos.
1557 
1559 
1560 #endif // KRATOS_GID_OUTPUT_H_INCLUDED defined
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Definition: flags.h:58
IntegrationMethod
Definition: geometry_data.h:76
KratosGeometryFamily
Definition: geometry_data.h:91
Base class for GidIO.
Definition: gid_io.h:74
void SetData(int data)
Definition: gid_io.cpp:39
GidIOBase()
Definition: gid_io.h:83
int data
Definition: gid_io.h:80
int GetData()
Definition: gid_io.cpp:35
static GidIOBase & GetInstance()
Definition: gid_io.cpp:22
This class defines an interface to the GiDPost library in order to provide GiD compliant I/O function...
Definition: gid_io.h:112
void WriteNodeMesh(MeshType &rThisMesh) override
Definition: gid_io.h:1128
std::string mResultFileName
Definition: gid_io.h:1508
WriteDeformedMeshFlag mWriteDeformed
Definition: gid_io.h:1517
GeometryData::KratosGeometryFamily KratosGeometryFamily
Geometry family definition.
Definition: gid_io.h:132
void WriteNodalResultsNonHistorical(Variable< Matrix > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag)
Definition: gid_io.h:985
void Flush()
Definition: gid_io.h:530
MultiFileFlag mUseMultiFile
Definition: gid_io.h:1519
void WriteNodalResultsNonHistorical(Variable< bool > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag)
Definition: gid_io.h:870
void InitializeMesh(const double name)
mesh writing functions
Definition: gid_io.h:1054
std::string mMeshFileName
Definition: gid_io.h:1509
virtual void InitializeResults(const double name, const MeshType &rThisMesh)
result functions
Definition: gid_io.h:566
void PrintFlagsOnGaussPoints(const Kratos::Flags &rFlag, const std::string &rFlagName, const ModelPart &rModelPart, const double SolutionTag)
functions for printing results on gauss points
Definition: gid_io.h:1342
void ChangeOutputName(const std::string &rDatafilename)
General GidIO related functions ///.
Definition: gid_io.h:498
void WriteNodalResults(Variable< double > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag, const std::size_t SolutionStepNumber)
functions for writing nodal results
Definition: gid_io.h:666
void FinalizeMesh()
Definition: gid_io.h:1106
IO BaseType
Base class definition.
Definition: gid_io.h:121
void WriteNodalResultsNonHistorical(Variable< double > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag)
functions for writing nodal results
Definition: gid_io.h:891
void WriteNodalResults(Variable< Vector > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag, const std::size_t SolutionStepNumber)
Definition: gid_io.h:740
void WriteClusterMesh(const MeshType &rThisMesh)
Definition: gid_io.h:1248
void WriteNodalResults(Variable< int > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag, const std::size_t SolutionStepNumber)
Definition: gid_io.h:688
ModelPart::ElementsContainerType ElementsArrayType
Containers definition.
Definition: gid_io.h:124
~GidIO() override
Destructor.
Definition: gid_io.h:177
GiD_PostMode mMode
Definition: gid_io.h:1520
virtual void PrintOnGaussPoints(const Variable< bool > &rVariable, const ModelPart &rModelPart, const double SolutionTag, const int ValueIndex=0)
Definition: gid_io.h:1363
bool mResultFileOpen
Definition: gid_io.h:1528
ModelPart::NodesContainerType NodesArrayType
Definition: gid_io.h:125
std::vector< TMeshContainer > mGidMeshContainers
Definition: gid_io.h:1525
void WriteNodalResults(Variable< Matrix > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag, const std::size_t SolutionStepNumber)
Definition: gid_io.h:770
void WriteNodalResults(Variable< array_1d< double, 3 > > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag, const std::size_t SolutionStepNumber)
Definition: gid_io.h:712
KRATOS_CLASS_POINTER_DEFINITION(GidIO)
Pointer definition of GidIO.
void WriteNodalFlags(const Kratos::Flags &rFlag, const std::string &rFlagName, const NodesContainerType &rNodes, const double SolutionTag)
Definition: gid_io.h:847
void InitializeResultFile(std::string const &rResultFileName)
Definition: gid_io.h:510
virtual void PrintOnGaussPoints(const Variable< array_1d< double, 3 > > &rVariable, const ModelPart &rModelPart, const double SolutionTag, const int ValueIndex=0)
Definition: gid_io.h:1436
bool mMeshFileOpen
Definition: gid_io.h:1527
virtual void SetUpGaussPointContainers()
Creates the gauss point containers for all different element types.
Definition: gid_io.h:300
GiD_FILE mMeshFile
Definition: gid_io.h:1511
void WriteMesh(MeshType &rThisMesh) override
Definition: gid_io.h:1295
void SetUpMeshContainers()
Creates the mesh containers for all different element types.
Definition: gid_io.h:221
GiD_FILE mResultFile
Definition: gid_io.h:1512
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: gid_io.h:126
virtual void PrintOnGaussPoints(const Variable< double > &rVariable, const ModelPart &rModelPart, const double SolutionTag, const int ValueIndex=0)
Definition: gid_io.h:1411
void WriteSphereMesh(const MeshType &rThisMesh)
Definition: gid_io.h:1166
void CloseResultFile()
Definition: gid_io.h:518
std::string Info() const override
Definition: gid_io.h:539
WriteConditionsFlag mWriteConditions
Definition: gid_io.h:1518
void WriteNodalResultsNonHistorical(Variable< int > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag)
Definition: gid_io.h:911
GidIO(const std::string &rDatafilename, const GiD_PostMode Mode, const MultiFileFlag UseMultipleFilesFlag, const WriteDeformedMeshFlag WriteDeformedFlag, const WriteConditionsFlag WriteConditions, const bool InitializeGaussPointContainers=true)
Constructor. Single stream IO constructor.
Definition: gid_io.h:145
void PrintInfo(std::ostream &rOStream) const override
Definition: gid_io.h:547
virtual void PrintOnGaussPoints(const Variable< int > &rVariable, const ModelPart &rModelPart, const double SolutionTag, const int ValueIndex=0)
Definition: gid_io.h:1386
void WriteCircleMesh(const MeshType &rThisMesh)
Definition: gid_io.h:1206
void WriteNodalResults(Variable< bool > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag, const std::size_t SolutionStepNumber)
functions for writing nodal results
Definition: gid_io.h:642
void WriteLocalAxesOnNodesNonHistorical(Variable< array_1d< double, 3 > > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag)
Definition: gid_io.h:1028
void PrintData(std::ostream &rOStream) const override
Definition: gid_io.h:555
virtual void PrintOnGaussPoints(const Variable< Vector > &rVariable, const ModelPart &rModelPart, const double SolutionTag, const int ValueIndex=0)
Definition: gid_io.h:1461
virtual void PrintOnGaussPoints(const Variable< Matrix > &rVariable, const ModelPart &rModelPart, const double SolutionTag, const int ValueIndex=0)
Definition: gid_io.h:1485
std::vector< TGaussPointContainer > mGidGaussPointContainers
Definition: gid_io.h:1526
void WriteLocalAxesOnNodes(Variable< array_1d< double, 3 > > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag, const std::size_t SolutionStepNumber)
Definition: gid_io.h:816
void WriteNodalResultsNonHistorical(Variable< array_1d< double, 3 > > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag)
Definition: gid_io.h:932
void FinalizeResults()
Definition: gid_io.h:618
void WriteNodalResultsNonHistorical(Variable< Vector > const &rVariable, const NodesContainerType &rNodes, const double SolutionTag)
Definition: gid_io.h:957
GeometryData::IntegrationMethod IntegrationMethodType
Integration method definition.
Definition: gid_io.h:129
IO provides different implementation of input output procedures which can be used to read and write w...
Definition: io.h:58
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
Mesh is the second level of abstraction in the data structure which hold Nodes, Elements and Conditio...
Definition: mesh.h:69
ElementIterator ElementsEnd()
Definition: mesh.h:558
ElementIterator ElementsBegin()
Definition: mesh.h:548
ConditionIterator ConditionsBegin()
Definition: mesh.h:671
NodeIterator NodesEnd()
Definition: mesh.h:336
NodeIterator NodesBegin()
Definition: mesh.h:326
ConditionIterator ConditionsEnd()
Definition: mesh.h:681
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
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
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
static void Start(std::string const &rIntervalName)
This method starts the timer meassures.
Definition: timer.cpp:109
static void Stop(std::string const &rIntervalName)
This method stops the timer meassures.
Definition: timer.cpp:125
const std::string & Name() const
Definition: variable_data.h:201
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_API_EXTERN
Definition: kratos_export_api.h:57
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
Modeler::Pointer Create(const std::string &ModelerName, Model &rModel, const Parameters ModelParameters)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:30
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
WriteDeformedMeshFlag
Flags for mesh writing.
Definition: gid_io.h:52
@ WriteUndeformed
Definition: gid_io.h:52
@ WriteDeformed
Definition: gid_io.h:52
MultiFileFlag
Definition: gid_io.h:54
@ MultipleFiles
Definition: gid_io.h:54
@ SingleFile
Definition: gid_io.h:54
WriteConditionsFlag
Definition: gid_io.h:53
@ WriteConditions
Definition: gid_io.h:53
@ WriteElementsOnly
Definition: gid_io.h:53
@ WriteConditionsOnly
Definition: gid_io.h:53
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
ny
Definition: cube_mesher.py:738
nz
Definition: cube_mesher.py:739
nx
Definition: cube_mesher.py:737
float radius
Definition: mesh_to_mdpa_converter.py:18
data
Definition: mesh_to_mdpa_converter.py:59
int node_id
Definition: read_stl.py:12
float temp
Definition: rotating_cone.py:85
string file_name
Definition: sp_statistics.py:6