LifeV
lifev/core/examples/utility_mesh_reorder/main.cpp
Go to the documentation of this file.
1 #ifdef TWODIM
2 #error test_reorder cannot be compiled in 2D
3 #endif
4 
5 
6 #include <lifev/core/mesh/InternalEntitySelector.hpp>
7 #include <Epetra_ConfigDefs.h>
8 #ifdef EPETRA_MPI
9 #include <mpi.h>
10 #include <Epetra_MpiComm.h>
11 #else
12 #include <Epetra_SerialComm.h>
13 #endif
14 
15 #include <lifev/core/mesh/MeshData.hpp>
16 
17 #include <lifev/core/filter/GetPot.hpp>
18 #include <lifev/core/filter/MeshWriter.hpp>
19 #include <string>
20 
21 #include <lifev/core/fem/DOFInterface3Dto3D.hpp>
22 #include <lifev/core/fem/FESpace.hpp>
23 
24 /*!
25  * @file
26  * @brief File containing a utility to reorder a mesh
27  *
28  * This utility contains a method to reorder the meshes reducing the fill-in of the matrix,
29  * and a method to create a different marker on a region of a mesh.
30  * In particular this region is identified by a marker of another mesh that shares an interface
31  * (e.g. solid interface and fluid edges in FSI).
32  *
33  * For instance suppose that you have marker=20 on the fluid 'edges'
34  * and on the solid mesh you have just different markers for the internal and external walls,
35  * then using this test you can create a marker '30' on the solid mesh whenever the corresponding marker on the fluid
36  * mesh is '20', and rewrite the mesh.
37  *
38  * usage: test_meshReorder -o mesh_output.mesh
39  *
40  * without the options -o or --output the output mesh can be specified from this data file.
41  * Otherwise the mesh will be written in a file 'mesh'.
42  *
43  * the first mesh is the one reordered. The second mesh is the one where the new marker is added
44  * (not read when create_edge=false).
45  *
46  * @author Paolo Crosetto <paolo.crosetto@epfl.ch>
47  *
48  * @mantainer Paolo Crosetto <paolo.crosetto@epfl.ch>
49  */
50 
51 
52 int main (int argc, char** argv)
53 {
54 #ifdef HAVE_MPI
55  MPI_Init (&argc, &argv);
56  using namespace LifeV;
57  GetPot command_line (argc, argv);
58  std::string data_file_name = command_line.follow ("data", 2, "-f", "--file");
59  GetPot data_file (data_file_name);
60 
61  MeshData mesh_data;
62  mesh_data.setup (data_file, "space_discretization");
63 
64  std::shared_ptr<Epetra_Comm> uselessComm (new Epetra_MpiComm (MPI_COMM_WORLD) );
65  std::shared_ptr<RegionMesh<LinearTetra> > mesh (new RegionMesh<LinearTetra> ( uselessComm) );
66 
67  readMesh (*mesh, mesh_data);
68 
69  //MeshData<RegionMesh<LinearTetra> > solidData(data_file, "solid/space_discretization");
70  //const char* mesh_input = command_line.follow(data_file("fluid/space_discretization/mesh_file", "mesh", 0), 2, "-i","--input");
71 
72  const std::string mesh_output = command_line.follow ( (data_file ("space_discretization/output_mesh_file", "mesh").c_str() ), 2, "-o", "--output");
73  bool ordering = data_file ("space_discretization/ordering", false);
74  bool create_edge = data_file ("interface/create_edge", true);
75  UInt TimeAdvanceNewmarker = data_file ("interface/edgeMarker", 20);
76 
77  if (ordering)
78  {
79  Int numtasks;
80  Int me;
81  MPI_Comm_rank (MPI_COMM_WORLD, &me);
82  MPI_Comm_size (MPI_COMM_WORLD, &numtasks);
83  MPI_Comm MPIcomm;
84  MPI_Group originGroup, newGroup;
85  MPI_Comm_group (MPI_COMM_WORLD, &originGroup);
86  std::vector<Int> members (numtasks);
87  for (Int i = 0; i < numtasks; ++i)
88  {
89  members[i] = 0;
90  }
91  MPI_Group_incl (originGroup, 1, &members[0], &newGroup);
92 
93  MPI_Comm_create (MPI_COMM_WORLD, newGroup, &MPIcomm);
94  if (me == 0)
95  {
96  // LF TAKEN AWAY. IT IS BROKEN
97  // mesh->orderMesh( MPIcomm);
98  //solidData.mesh()->orderMesh( MPIcomm);
99 
100  MeshWriter::writeMeshMedit<RegionMesh<LinearTetra> > ( mesh_output , *mesh);
101  //writeMesh( "solid_ord.mesh", *solidData.mesh());
102  }
103 
104  }
105  else if (create_edge)
106  {
107  UInt FluidInterfaceFlag = data_file ("interface/fluidInterfaceFlag", 2 );
108  UInt SolidInterfaceFlag = data_file ("interface/solidInterfaceFlag", 2 );
109  Int const edgeFlag (data_file ("interface/edgeFlag", 2 ) );
110 
111  MeshData mesh_data2;
112  mesh_data2.setup (data_file, "second_mesh/space_discretization");
113 
114  std::shared_ptr<RegionMesh<LinearTetra> > mesh2;
115  mesh2.reset (new RegionMesh<LinearTetra> (uselessComm) );
116 
117  readMesh (*mesh2, mesh_data2);
118 
119  std::shared_ptr<FESpace<RegionMesh<LinearTetra>, MapEpetra> > firstFESpace;
120  firstFESpace.reset (new FESpace<RegionMesh<LinearTetra>, MapEpetra> (mesh, "P1", 3, uselessComm) );
121 
122  std::shared_ptr<FESpace<RegionMesh<LinearTetra>, MapEpetra> > secondFESpace;
123  secondFESpace.reset (new FESpace<RegionMesh<LinearTetra>, MapEpetra> (mesh2, "P1", 3, uselessComm) );
124 
125 
126  std::shared_ptr<DOFInterface3Dto3D> dofEdgeFluidToEdgeSolid ( new DOFInterface3Dto3D );
127 
128  dofEdgeFluidToEdgeSolid->setup (firstFESpace->refFE(), firstFESpace->dof(),
129  secondFESpace->refFE(), secondFESpace->dof()
130  );
131 
132  dofEdgeFluidToEdgeSolid->update (
133  *mesh, FluidInterfaceFlag,
134  *mesh, SolidInterfaceFlag,
135  0., &edgeFlag);
136 
137  ChangeMarkersAccordingToMap (mesh2->pointList,
138  dofEdgeFluidToEdgeSolid->localDofMap(),
139  TimeAdvanceNewmarker);
140  //mesh2->edgeMarkers(dofEdgeFluidToEdgeSolid->localDofMap(), TimeAdvanceNewmarker);
141  MeshWriter::writeMeshMedit<RegionMesh<LinearTetra> > ( mesh_output , *mesh2);
142 
143  }
144  MPI_Finalize();
145 #endif
146 }
int main(int argc, char **argv)