LifeV
mesh/basic_test.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief Test the consistency of the mesh data structure
30 
31  @author
32  @contributor
33  @maintainer
34 
35  @date 00-00-0000
36 
37  Read a 3d mesh and perform internal consistency checks.
38 
39  */
40 
41 // ===================================================
42 //! Includes
43 // ===================================================
44 
45 #include <Epetra_ConfigDefs.h>
46 #ifdef HAVE_MPI
47 #include <mpi.h>
48 #include <Epetra_MpiComm.h>
49 #else
50 #include <Epetra_SerialComm.h>
51 #endif
52 
53 
54 #include <lifev/core/filter/GetPot.hpp>
55 
56 #include <lifev/core/mesh/MarkerDefinitions.hpp>
57 #include <lifev/core/filter/ImporterMesh3D.hpp>
58 #include <lifev/core/mesh/RegionMesh.hpp>
59 #include <lifev/core/mesh/MeshElementBare.hpp>
60 #include <lifev/core/array/EnumMapEpetra.hpp>
61 
62 // A dummy class to imitate a VectorEpetra
63 class dummyVect:
64  public std::vector<double>
65 {
66 public:
67  dummyVect() : std::vector<double>() {}
68  dummyVect (unsigned const int& n) : std::vector<double> (n) {}
69  dummyVect ( dummyVect v, LifeV::MapEpetraType ) : std::vector<double> (v) {}
70  bool isGlobalIDPresent (int ) const
71  {
72  return true;
73  }
75  {
76  return LifeV::Repeated;
77  }
78 };
79 
80 template<typename meshEntity>
81 class ResetFlag
82 {
83 public:
84  void operator() (meshEntity& m)
85  {
86  m.replaceFlag (LifeV::EntityFlags::DEFAULT);
87  m.setMarkerID (0);
88  }
89 };
90 
91 int main (int argc, char** argv)
92 {
93 #ifdef HAVE_MPI
94  MPI_Init (&argc, &argv);
95  std::cout << "MPI Initialization" << std::endl;
96  std::shared_ptr<Epetra_Comm> comm ( new Epetra_MpiComm ( MPI_COMM_WORLD ) );
97 #else
98  std::shared_ptr<Epetra_Comm> comm ( new Epetra_SerialComm );
99 #endif
100 
101 
102  using namespace LifeV;
103  using namespace LifeV::MeshUtility;
104 
105  GetPot datafile ( "data" );
106  std::string dirname = datafile ( "mesh_dir", "." ); //"../data/mesh/mesh++/";
107  if (*dirname.rbegin() != '/');
108  dirname += "/";
109  std::string fname = dirname + datafile ( "mesh_file", "cube_47785.m++" ); //dirname+"cube_47785.m++";
110  std::string outfile = "testBuilders.dat";
111  std::ofstream ofile (outfile.c_str() );
112  if (ofile.fail() )
113  {
114  std::cerr << " Error: Cannot creat output file" << std::endl;
115  abort();
116  }
117 
118  RegionMesh<LinearTetra> aMesh ( comm );
119  typedef RegionMesh<LinearTetra> mesh_Type;
120  // aMesh.test3DBuilder();
121  // aMesh.readMppFile(mystream, id, m);
122  ID m = 1;
123  readMppFile (aMesh, fname, m);
124 
125  std::cout << " **********************************************************" << std::endl;
126 
127  std::cout << " ****************** CHECKING MESH WITH INTERNAL CHECKER" << std::endl;
128 
129  aMesh.check (0, true, true);
130  Switch sw;
131 
132 
133  std::cout << " **********************************************************" << std::endl;
134 
135  std::cout << " ****************** CLEANING edges and faces " << std::endl;
136 
137  aMesh.edgeList.clear();
138  aMesh.faceList.clear();
139 
140  checkMesh3D (aMesh, sw,
141  true, true,
142  std::cerr, std::cout, ofile);
143 
144 
145  aMesh.showMe();
146 
147 
148  std::cout << " Now building local Edges/faces Stuff" << std::endl << std::endl;
149  aMesh.updateElementEdges();
150  aMesh.updateElementFaces();
151  aMesh.showMe();
152  std::cout << " Now cleaning local Edges/faces Stuff" << std::endl << std::endl;
153  aMesh.cleanElementRidges();
154  aMesh.cleanElementFacets();
155  aMesh.showMe();
156  std::cout << " **********************************************************" << std::endl;
157 
158  std::cout << " ****************** BUILDING ALL EDGES" << std::endl;
159  UInt bedges_found, iedges_found;
160  buildEdges (aMesh, ofile, std::cerr, bedges_found,
161  iedges_found, true, true, true);
162  std::cout << " **********************************************************" << std::endl;
163 
164  std::cout << " ****************** BUILDING ALL FACES" << std::endl;
165  UInt bfaces_found, ifaces_found;
166  buildFaces (aMesh, ofile, std::cerr, bfaces_found,
167  ifaces_found, true, true, true);
168 
169  aMesh.showMe();
170 
171  std::cout << " Now building again local Edges/faces Stuff" << std::endl << std::endl;
172  aMesh.updateElementEdges();
173  aMesh.updateElementFaces();
174  aMesh.showMe();
175  checkMesh3D (aMesh, sw,
176  true, true,
177  std::cerr, std::cout, ofile);
178  ofile.close();
179 
180  ///THIS PART IS ONLY TO VERIFY IF THESE ROUTINES COMPILE PROPERLY
181  std::cerr << "Fixing bpoints" << std::endl;
182 
183  fixBoundaryPoints (aMesh, ofile, std::cerr, true);
184  std::cerr << "Fixing edge markers" << std::endl;
185  setBoundaryEdgesMarker (aMesh, ofile, std::cerr, true);
186  std::cerr << "Fixing faces marker" << std::endl;
187  setBoundaryFacesMarker (aMesh, ofile, std::cerr, true);
188  std::cerr << "Fixing points marker" << std::endl;
189  setBoundaryPointsMarker (aMesh, ofile, std::cerr, true);
190  std::cerr << std::endl;
191  dummyVect disp (3 * aMesh.numPoints() );
192  MeshUtility::MeshTransformer<mesh_Type> transformer (aMesh);
193  transformer.moveMesh (disp, 3);
194  MeshUtility::MeshStatistics::meshSize sizes = MeshUtility::MeshStatistics::computeSize (aMesh);
195  std::cerr << "Hmin =" << sizes.minH << " Hmax=" << sizes.maxH << std::endl;
196  mesh_Type::points_Type newPointList = aMesh.pointList;
197  mesh_Type::faces_Type newFaceList = aMesh.faceList;
198  Utilities::fixAfterShallowCopy (newFaceList, newPointList);
199  for (mesh_Type::faces_Type::iterator i = newFaceList.begin(); i < newFaceList.end(); ++i)
200  {
201  ID theId = i->point (0).id();
202  if (& (i->point (0) ) != & (newPointList[theId]) )
203  {
204  std::cerr << "ERROR: Error after renumbering Faces" << std::endl;
205  break;
206  }
207  }
208  aMesh.faceList[2].replaceFlag (EntityFlags::CUTTED);
209  aMesh.faceList.reorderAccordingToFlag (EntityFlags::CUTTED, &Flag::testOneSet);
210  if (aMesh.faceList[0].flag() != EntityFlags::CUTTED)
211  {
212  std::cerr << "ERROR: Reordering is not working" << std::endl;
213  }
214  std::cout << "Number of cutted faces (should be 1) " <<
215  aMesh.faceList.countElementsWithFlag (EntityFlags::CUTTED, &Flag::testOneSet) << std::endl;
216  // Reset all flags to default
217  aMesh.edgeList.changeAccordingToFunctor (ResetFlag<mesh_Type::edge_Type>() );
218  aMesh.edge (0).setMarkerID (10);
219  aMesh.edge (5).setMarkerID (10);
220  aMesh.edge (10).setMarkerID (15);
221  std::vector<ID> watermarks (2);
222  watermarks[0] = 10;
223  watermarks[1] = 15;
224  // change flags according to marker iD
225  SetFlagAccordingToWatermarks changeFlags (EntityFlags::CUTTED, watermarks);
226  aMesh.edgeList.changeAccordingToFunctor (changeFlags);
227  std::cout << "Number of cutted edges (should be 3) "
228  << aMesh.edgeList.countElementsWithFlag (EntityFlags::CUTTED, &Flag::testOneSet) << std::endl;
229  aMesh.edgeList.changeAccordingToFunctor ( ResetFlag<mesh_Type::edge_Type>() );
230  aMesh.edge (0).setMarkerID (10);
231  aMesh.edge (5).setMarkerID (12);
232  aMesh.edge (10).setMarkerID (15);
233  SetFlagAccordingToMarkerRanges changer ( &Flag::turnOn ); //I may use the default constructor
234  changer.insert (std::make_pair (10, 12), EntityFlags::INTERNAL_INTERFACE);
235  changer.insert (std::make_pair (15, 18), EntityFlags::CUTTED);
236  aMesh.edgeList.changeAccordingToFunctor (changer);
237  std::cout << "Number of cutted edges (should be 1) " <<
238  aMesh.edgeList.countElementsWithFlag (EntityFlags::CUTTED, &Flag::testOneSet) << std::endl;
239  std::cout << "Number of internal interface edges (should be 2) " <<
240  aMesh.edgeList.countElementsWithFlag (EntityFlags::INTERNAL_INTERFACE, &Flag::testOneSet) << std::endl;
241 
242  SetFlagAccordingToWatermark<std::equal_to<markerID_Type> > changer2 (EntityFlags::INTERNAL_INTERFACE, 12000, Flag::turnOn);
243  aMesh.faceList.changeAccordingToFunctor (changer2);
244 
245 #ifdef HAVE_MPI
246  MPI_Finalize();
247 #endif
248 
249  return ( EXIT_SUCCESS );
250 }
bool isGlobalIDPresent(int) const
void operator()(meshEntity &m)
LifeV::MapEpetraType mapType() const
dummyVect(dummyVect v, LifeV::MapEpetraType)
Includes.
dummyVect(unsigned const int &n)
int main(int argc, char **argv)