LifeV
test_baremesh.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 baremesh data structure
30 
31  @author Antonio Cervone <ant.cervone@gmail.com>
32  @contributor
33  @maintainer Antonio Cervone <ant.cervone@gmail.com>
34 
35  @date 13-09-2011
36 
37  Read a 3d mesh via the baremesh structure 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 
58 #include <lifev/core/mesh/RegionMesh.hpp>
59 #include <lifev/core/mesh/BareMesh.hpp>
60 
61 #include <lifev/core/filter/ParserINRIAMesh.hpp>
62 #include <lifev/core/mesh/ConvertBareMesh.hpp>
63 #include <lifev/core/array/MapEpetra.hpp>
64 
65 // A dummy class to imitate a VectorEpetra
66 class dummyVect:
67  public std::vector<double>
68 {
69 public:
70  dummyVect() : std::vector<double>() {}
71  dummyVect (unsigned const int& n) : std::vector<double> (n) {}
72  dummyVect ( dummyVect v, LifeV::MapEpetraType ) : std::vector<double> (v) {}
73  bool isGlobalIDPresent (int ) const
74  {
75  return true;
76  }
78  {
79  return LifeV::Repeated;
80  }
81 };
82 
83 template<typename meshEntity>
84 class ResetFlag
85 {
86 public:
87  void operator() (meshEntity& m)
88  {
89  m.replaceFlag (LifeV::EntityFlags::DEFAULT);
90  m.setMarkerID (0);
91  }
92 };
93 
94 using namespace LifeV;
95 
96 int main (int argc, char** argv)
97 {
98 #ifdef HAVE_MPI
99  MPI_Init (&argc, &argv);
100  std::cout << "MPI Initialization" << std::endl;
101  std::shared_ptr<Epetra_Comm> comm ( new Epetra_MpiComm ( MPI_COMM_WORLD ) );
102 #else
103  std::shared_ptr<Epetra_Comm> comm ( new Epetra_SerialComm );
104 #endif
105 
106  GetPot datafile ( "data_baremesh" );
107  std::string dirname = datafile ( "mesh_dir", "." ); // "../data/mesh/inria/"
108  std::string fname = dirname + datafile ( "mesh_file",
109  "cartesian_cube8.mesh" ); // dirname + "cartesian_cube8.mesh";
110  std::string outfile = "testBuilders_baremesh.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  typedef BareMesh<LinearTetra> bareMesh_Type;
119  typedef RegionMesh<LinearTetra> mesh_Type;
120 
121  ID m = 1;
122 
123  bareMesh_Type bareMesh;
124  MeshIO::ReadINRIAMeshFile ( bareMesh, fname, m );
125 
126  mesh_Type aMesh ( comm );
127  convertBareMesh ( bareMesh, aMesh );
128 
129  std::cout << " **********************************************************" << std::endl;
130 
131  std::cout << " ****************** CHECKING MESH WITH INTERNAL CHECKER" << std::endl;
132 
133  aMesh.check ( 0, true, true );
134  Switch sw;
135 
136  std::cout << " **********************************************************" << std::endl;
137 
138  std::cout << " ****************** CLEANING edges and faces " << std::endl;
139 
140  aMesh.edgeList.clear();
141  aMesh.faceList.clear();
142 
143  checkMesh3D (aMesh, sw,
144  true, true,
145  std::cerr, std::cout, ofile);
146 
147 
148  aMesh.showMe();
149 
150 
151  std::cout << " Now building local Edges/faces Stuff" << std::endl << std::endl;
152  aMesh.updateElementEdges();
153  aMesh.updateElementFaces();
154  aMesh.showMe();
155  std::cout << " Now cleaning local Edges/faces Stuff" << std::endl << std::endl;
156  aMesh.cleanElementRidges();
157  aMesh.cleanElementFaces();
158  aMesh.showMe();
159  std::cout << " **********************************************************" << std::endl;
160 
161  std::cout << " ****************** BUILDING ALL EDGES" << std::endl;
162  UInt bedges_found, iedges_found;
163  MeshUtility::buildEdges ( aMesh, ofile, std::cerr, bedges_found,
164  iedges_found, true, true, true );
165  std::cout << " **********************************************************" << std::endl;
166 
167  std::cout << " ****************** BUILDING ALL FACES" << std::endl;
168  UInt bfaces_found, ifaces_found;
169  MeshUtility::buildFaces ( aMesh, ofile, std::cerr, bfaces_found,
170  ifaces_found, true, true, true );
171 
172  aMesh.showMe();
173 
174  std::cout << " Now building again local Edges/faces Stuff" << std::endl << std::endl;
175  aMesh.updateElementEdges();
176  aMesh.updateElementFaces();
177  aMesh.showMe();
178  checkMesh3D (aMesh, sw,
179  true, true,
180  std::cerr, std::cout, ofile);
181  ofile.close();
182 
183  ///THIS PART IS ONLY TO VERIFY IF THESE ROUTINES COMPILE PROPERLY
184  std::cerr << "Fixing bpoints" << std::endl;
185 
186  MeshUtility::fixBoundaryPoints ( aMesh, ofile, std::cerr, true );
187  std::cerr << "Fixing edge markers" << std::endl;
188  MeshUtility::setBoundaryEdgesMarker ( aMesh, ofile, std::cerr, true );
189  std::cerr << "Fixing faces marker" << std::endl;
190  MeshUtility::setBoundaryFacesMarker ( aMesh, ofile, std::cerr, true );
191  std::cerr << "Fixing points marker" << std::endl;
192  MeshUtility::setBoundaryPointsMarker ( aMesh, ofile, std::cerr, true );
193  std::cerr << std::endl;
194  dummyVect disp ( 3 * aMesh.numPoints() );
195  MeshUtility::MeshTransformer<mesh_Type > transformer ( aMesh );
196  transformer.moveMesh ( disp, 3 );
197  MeshUtility::MeshStatistics::meshSize sizes = MeshUtility::MeshStatistics::computeSize ( aMesh );
198  std::cerr << "Hmin =" << sizes.minH << " Hmax=" << sizes.maxH << std::endl;
199  mesh_Type::points_Type newPointList = aMesh.pointList;
200  mesh_Type::faces_Type newFaceList = aMesh.faceList;
201  Utilities::fixAfterShallowCopy ( newFaceList, newPointList );
202  for ( mesh_Type::faces_Type::iterator i = newFaceList.begin(); i < newFaceList.end(); ++i )
203  {
204  ID theId = i->point (0).id();
205  if ( & (i->point (0) ) != & ( newPointList[ theId ] ) )
206  {
207  std::cerr << "ERROR: Error after renumbering Faces" << std::endl;
208  break;
209  }
210  }
211  aMesh.faceList[2].replaceFlag ( EntityFlags::CUTTED );
212  aMesh.faceList.reorderAccordingToFlag ( EntityFlags::CUTTED, Flag::testOneSet );
213  if ( aMesh.faceList[0].flag() != EntityFlags::CUTTED )
214  {
215  std::cerr << "ERROR: Reordering is not working" << std::endl;
216  }
217  std::cout << "Number of cutted faces (should be 1) " <<
218  aMesh.faceList.countElementsWithFlag ( EntityFlags::CUTTED, Flag::testOneSet ) << std::endl;
219  // Reset all flags to default
220  aMesh.edgeList.changeAccordingToFunctor ( ResetFlag<mesh_Type::edge_Type>() );
221  aMesh.edge ( 0 ).setMarkerID ( 10 );
222  aMesh.edge ( 5 ).setMarkerID ( 10 );
223  aMesh.edge ( 10 ).setMarkerID ( 15 );
224  std::vector<ID> watermarks ( 2 );
225  watermarks[ 0 ] = 10;
226  watermarks[ 1 ] = 15;
227  // change flags according to marker iD
228  SetFlagAccordingToWatermarks changeFlags ( EntityFlags::CUTTED, watermarks );
229  aMesh.edgeList.changeAccordingToFunctor ( changeFlags );
230  std::cout << "Number of cutted edges (should be 3) " <<
231  aMesh.edgeList.countElementsWithFlag (EntityFlags::CUTTED, Flag::testOneSet) << std::endl;
232  aMesh.edgeList.changeAccordingToFunctor ( ResetFlag<mesh_Type::edge_Type>() );
233  aMesh.edge ( 0 ).setMarkerID ( 10 );
234  aMesh.edge ( 5 ).setMarkerID ( 12 );
235  aMesh.edge ( 10 ).setMarkerID ( 15 );
236  SetFlagAccordingToMarkerRanges changer ( Flag::turnOn ); //I may use the default constructor
237  changer.insert ( std::make_pair ( 10, 12 ), EntityFlags::INTERNAL_INTERFACE );
238  changer.insert ( std::make_pair ( 15, 18 ), EntityFlags::CUTTED );
239  aMesh.edgeList.changeAccordingToFunctor ( changer );
240  std::cout << "Number of cutted edges (should be 1) " <<
241  aMesh.edgeList.countElementsWithFlag ( EntityFlags::CUTTED, Flag::testOneSet ) << std::endl;
242  std::cout << "Number of internal interface edges (should be 2) " <<
243  aMesh.edgeList.countElementsWithFlag ( EntityFlags::INTERNAL_INTERFACE, Flag::testOneSet ) << std::endl;
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)