LifeV
run_MeshExtractor.cpp
Go to the documentation of this file.
1 /*
2  * run_MeshExtractor.cpp
3  *
4  * Author: uvilla
5  *
6  * Extract a 2d dimensional mesh from the boundary of a 3d mesh.
7  */
8 
9 #include <lifev/core/filter/GetPot.hpp>
10 #include <lifev/core/util/LifeChrono.hpp>
11 
12 
13 #include <lifev/core/mesh/MeshData.hpp>
14 #include <lifev/core/mesh/RegionMesh.hpp>
15 #include <lifev/core/mesh/MeshPartitioner.hpp>
16 
17 #include <lifev/core/filter/ExporterEnsight.hpp>
18 #include <lifev/core/filter/ExporterHDF5.hpp>
19 #include <lifev/core/filter/ExporterEmpty.hpp>
20 
21 #include "MeshExtractor.hpp"
22 
23 int run (GetPot& dataFile, bool /*verbose*/, std::shared_ptr<Epetra_Comm>& comm)
24 {
25  using namespace LifeV;
26  typedef RegionMesh<LinearTetra> mesh_Type;
27  typedef RegionMesh<LinearTriangle> mesh2d_Type;
28 
29  // LifeChrono chrono;
30 
31  std::string mesh_section ("mesh");
32  //FIXME At the moment we can extract only one marker at a time.
33  //Only the first marker in boundaryMarkerListToExtract will be extracted
34  std::list<UInt> boundaryMarkerListToExtract, otherBoundaryMarkerList;
35  parseList ( dataFile ( (mesh_section + "/interfaceList").c_str(), ""), boundaryMarkerListToExtract );
36  parseList ( dataFile ( (mesh_section + "/boundaryList").c_str(), ""), otherBoundaryMarkerList );
37 
38 
39  //=======================================================================//
40  // Mesh Stuff //
41  //=======================================================================//
42  // Read the 3d mesh
43  std::shared_ptr<mesh_Type> mesh;
44  std::shared_ptr< MeshPartitioner<mesh_Type> > meshPart;
45  MeshData meshData (dataFile, mesh_section);
46  mesh.reset ( new mesh_Type ( comm ) );
47  readMesh (*mesh, meshData);
48 
49  //Extract the 2d mesh from the boundary with a given marker
50  std::shared_ptr<mesh2d_Type> mesh2d;
51  std::shared_ptr< MeshPartitioner<mesh2d_Type> > mesh2dPart;
52  mesh2d.reset (extractBoundaryMesh (*mesh, *boundaryMarkerListToExtract.begin(), otherBoundaryMarkerList) );
53  mesh2d->showMe (false, std::cout);
54 
55  meshPart.reset (new MeshPartitioner<mesh_Type> (mesh, comm) );
56  mesh2dPart.reset (new MeshPartitioner<mesh2d_Type> (mesh2d, comm) ); //Fails in debug mode!!!
57 
58  //========================================================================//
59  // Create a dummy feSpace on the boundary mesh //
60  //========================================================================//
61  std::shared_ptr< FESpace<mesh2d_Type, MapEpetra> > feSpace;
62  feSpace.reset (new FESpace<mesh2d_Type, MapEpetra> (mesh2dPart->meshPartition(), "P1", 1, comm) );
63 
64  //========================================================================//
65  // post processing setup //
66  //========================================================================//
67  std::shared_ptr<Exporter<mesh2d_Type> > exporter;
68  std::string const exporterType = dataFile ( "exporter/type", "hdf5");
69 
70 #ifdef HAVE_HDF5
71  if (exporterType.compare ("hdf5") == 0)
72  {
73  exporter.reset ( new ExporterHDF5<mesh2d_Type > ( dataFile, "2dmesh" ) );
74  }
75  else
76 #endif
77  {
78  if (exporterType.compare ("none") == 0)
79  {
80  exporter.reset ( new ExporterEmpty<mesh2d_Type > ( dataFile, mesh2d, "2dmesh", comm->MyPID() ) );
81  }
82  else
83  {
84  exporter.reset ( new ExporterEnsight<mesh2d_Type > ( dataFile, mesh2d, "2dmesh", comm->MyPID() ) );
85  }
86  }
87 
88  exporter->setPostDir ( "./" );
89  exporter->setMeshProcId ( mesh2d, comm->MyPID() );
90 
91 
92  //====================================================================//
93  // Show the extracted mesh, color element according to the PID //
94  //====================================================================//
95  std::shared_ptr<VectorEpetra> u (new VectorEpetra (feSpace->map(), exporter->mapType() ) );
96  exporter->addVariable (ExporterData<mesh2d_Type >::ScalarField, "u", feSpace, u, UInt (0) );
97  *u = comm->MyPID();
98  exporter->postProcess (0);
99 
100 
101 
102  return 0;
103 }
MeshData - class for handling spatial discretization.
Definition: MeshData.hpp:72
int run(GetPot &dataFile, bool, std::shared_ptr< Epetra_Comm > &comm)