LifeV
lifev/structure/examples/example_creatingDamagedZone/main.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  \file main.cpp
28  \author Paolo Tricerri <paolo.tricerri@epfl.ch>
29 
30  This example shows how to select portion of the computational domain
31  and change their flag using the MeshUtility features.
32  Now the elements for which the flag is changed to 2 are the ones
33  belonging to the intersection of the computational domain and the sphere
34  defined by its center and
35 
36  I have always executed the example in serial since the regionmesh object that
37  I pass to the elementlist function is the unpartitioned object.
38 
39  \date 2005-04-16
40  */
41 #undef HAVE_HDF5
42 #ifdef TWODIM
43 #error test_structure cannot be compiled in 2D
44 #endif
45 
46 // Tell the compiler to ignore specific kind of warnings:
47 #pragma GCC diagnostic ignored "-Wunused-variable"
48 #pragma GCC diagnostic ignored "-Wunused-parameter"
49 
50 #include <Epetra_ConfigDefs.h>
51 #ifdef EPETRA_MPI
52 #include <mpi.h>
53 #include <Epetra_MpiComm.h>
54 #else
55 #include <Epetra_SerialComm.h>
56 #endif
57 
58 //Tell the compiler to restore the warning previously silented
59 #pragma GCC diagnostic warning "-Wunused-variable"
60 #pragma GCC diagnostic warning "-Wunused-parameter"
61 
62 #include <lifev/core/LifeV.hpp>
63 #include <lifev/core/algorithm/PreconditionerIfpack.hpp>
64 #include <lifev/core/algorithm/PreconditionerML.hpp>
65 
66 
67 //Include fils which were in the structure.cpp file
68 #include <lifev/core/array/MapEpetra.hpp>
69 
70 #include <lifev/core/mesh/MeshData.hpp>
71 #include <lifev/core/mesh/MeshPartitioner.hpp>
72 #include <lifev/core/filter/MeshWriter.hpp>
73 
74 #include <lifev/structure/solver/StructuralConstitutiveLawData.hpp>
75 #include <lifev/structure/solver/StructuralConstitutiveLaw.hpp>
76 #include <lifev/structure/solver/StructuralOperator.hpp>
77 
78 #include <lifev/structure/solver/isotropic/ExponentialMaterialNonLinear.hpp>
79 
80 
81 #include <lifev/core/filter/ExporterEnsight.hpp>
82 #ifdef HAVE_HDF5
83 #include <lifev/core/filter/ExporterHDF5.hpp>
84 #endif
85 #include <lifev/core/filter/ExporterEmpty.hpp>
86 
87 #include <iostream>
88 
89 
90 
91 using namespace LifeV;
92 
93 int returnValue = EXIT_FAILURE;
94 
95 
96 //Class to investigate the mesh
97 template < typename MeshEntityType,
98  typename ComparisonPolicyType = std::function < bool (
99  Real const&,
100  Real const&) > >
102 {
103 public:
104  typedef MeshEntityType meshEntity_Type;
105  typedef ComparisonPolicyType comparisonPolicy_Type;
106 
107  SphereInterrogator ( Vector3D const& center,
108  Real radius,
109  comparisonPolicy_Type const& policy = std::less<Real>() )
110  : M_center ( center ),
111  M_radius ( radius ),
112  M_policy ( policy ) {}
113 
114  void operator() ( meshEntity_Type& entity ) const
115  {
116  // compute the barycenter of the entity
117  // (this should be a method of the object)
118  Vector3D barycenter;
119  for ( UInt k = 0; k < meshEntity_Type::S_numPoints; k++ )
120  {
121  barycenter += entity.point ( k ).coordinates();
122  }
123  barycenter /= meshEntity_Type::S_numPoints;
124 
125  UInt newMarker (2);
126  // check if the distance between the barycenter and the center of the circle
127  // satisfies the policy (default: distance less than the radius)
128  if ( M_policy ( ( barycenter - M_center ).norm(), M_radius ) )
129  {
130  entity.setMarkerID ( newMarker );
131  }
132  }
133 
134 private:
136  const Real M_radius;
138 
139 }; // SphereInterrogator
140 
141 //This class is to count how many volumes are in the sphere. This is for debug purposes
142 //It cannot be used the same functor as SphereInspector since they perform different operation
143 template < typename MeshEntityType,
144  typename ComparisonPolicyType = std::function < bool (
145  Real const&,
146  Real const&) > >
148 {
149 public:
150  typedef MeshEntityType meshEntity_Type;
151  typedef ComparisonPolicyType comparisonPolicy_Type;
152 
153  SphereCounter ( Vector3D const& center,
154  Real radius,
155  comparisonPolicy_Type const& policy = std::less<Real>() )
156  : M_center ( center ),
157  M_radius ( radius ),
158  M_policy ( policy ) {}
159 
160  bool operator() ( const meshEntity_Type& entity ) const
161  {
162  // compute the barycenter of the entity
163  // (this should be a method of the object)
164  Vector3D barycenter;
165  for ( UInt k = 0; k < meshEntity_Type::S_numPoints; k++ )
166  {
167  barycenter += entity.point ( k ).coordinates();
168  }
169  barycenter /= meshEntity_Type::S_numPoints;
170 
171  // check if the distance between the barycenter and the center of the circle
172  // satisfies the policy (default: distance less than the radius)
173  return M_policy ( ( barycenter - M_center ).norm(), M_radius );
174  }
175 
176 private:
178  const Real M_radius;
180 
181 }; // SphereCounter
182 
183 
185 {
186  std::string stringList = list;
187  std::set<UInt> setList;
188  if ( list == "" )
189  {
190  return setList;
191  }
192  size_t commaPos = 0;
193  while ( commaPos != std::string::npos )
194  {
195  commaPos = stringList.find ( "," );
196  setList.insert ( atoi ( stringList.substr ( 0, commaPos ).c_str() ) );
197  stringList = stringList.substr ( commaPos + 1 );
198  }
199  setList.insert ( atoi ( stringList.c_str() ) );
200  return setList;
201 }
202 
203 
204 class Structure
205 {
206 public:
207 
209 
210  /** @name Constructors, destructor
211  */
212  //@{
213  Structure ( int argc,
214  char** argv,
215  std::shared_ptr<Epetra_Comm> structComm );
216 
218  {}
219  //@}
220 
221  //@{
222  void run()
223  {
224  run3d();
225  }
226  //@}
227 
228 protected:
229 
230 private:
231 
232  /**
233  * run the 2D driven cylinder simulation
234  */
235  void run2d();
236 
237  /**
238  * run the 3D driven cylinder simulation
239  */
240  void run3d();
241 
242 private:
243  struct Private;
245 
246 };
247 
248 
249 
250 struct Structure::Private
251 {
253  rho (1), poisson (1), young (1), bulk (1), alpha (1), gamma (1)
254  {}
255  double rho, poisson, young, bulk, alpha, gamma;
256 
258 
260 
261 };
262 
263 
264 
265 Structure::Structure ( int argc,
266  char** argv,
267  std::shared_ptr<Epetra_Comm> structComm) :
268  parameters ( new Private() )
269 {
270  GetPot command_line (argc, argv);
271  std::string data_file_name = command_line.follow ("data", 2, "-f", "--file");
272  GetPot dataFile ( data_file_name );
273  parameters->data_file_name = data_file_name;
274 
275  parameters->comm = structComm;
276  int ntasks = parameters->comm->NumProc();
277 
278  if (!parameters->comm->MyPID() )
279  {
280  std::cout << "My PID = " << parameters->comm->MyPID() << " out of " << ntasks << " running." << std::endl;
281  }
282 }
283 
284 
285 
286 void
287 Structure::run2d()
288 {
289  std::cout << "2D cylinder test case is not available yet\n";
290 }
291 
292 
293 
294 void
295 Structure::run3d()
296 {
297  typedef StructuralOperator<mesh_Type >::vector_Type vector_Type;
298  typedef std::shared_ptr<vector_Type> vectorPtr_Type;
299  typedef FESpace< mesh_Type, MapEpetra > solidFESpace_Type;
300  typedef std::shared_ptr<solidFESpace_Type> solidFESpacePtr_Type;
301  typedef ETFESpace< RegionMesh<LinearTetra>, MapEpetra, 3, 3 > solidETFESpace_Type;
302  typedef std::shared_ptr<solidETFESpace_Type> solidETFESpacePtr_Type;
303 
304  typedef LifeV::RegionMesh<LinearTetra> mesh_Type;
305 
306  // Filters
307  typedef LifeV::Exporter<mesh_Type > filter_Type;
308  typedef std::shared_ptr< LifeV::Exporter<mesh_Type > > filterPtr_Type;
309 
310  typedef LifeV::ExporterEmpty<mesh_Type > emptyFilter_Type;
311  typedef std::shared_ptr<emptyFilter_Type> emptyFilterPtr_Type;
312  typedef LifeV::ExporterEnsight<mesh_Type > ensightFilter_Type;
313  typedef std::shared_ptr<ensightFilter_Type> ensightFilterPtr_Type;
314 
315 #ifdef HAVE_HDF5
316  typedef LifeV::ExporterHDF5<mesh_Type > hdf5Filter_Type;
317  typedef std::shared_ptr<hdf5Filter_Type> hdf5FilterPtr_Type;
318 #endif
319 
320  bool verbose = (parameters->comm->MyPID() == 0);
321 
322  //! dataElasticStructure
323  GetPot dataFile ( parameters->data_file_name.c_str() );
324  std::shared_ptr<StructuralConstitutiveLawData> dataStructure (new StructuralConstitutiveLawData( ) );
325  dataStructure->setup (dataFile);
326 
327  MeshData meshData;
328  meshData.setup (dataFile, "solid/space_discretization");
329 
330 
331  std::shared_ptr<RegionMesh<LinearTetra> > fullMeshPtr (new RegionMesh<LinearTetra> ( ( parameters->comm ) ) );
332  std::shared_ptr<RegionMesh<LinearTetra> > localMeshPtr (new RegionMesh<LinearTetra> ( ( parameters->comm ) ) );
333 
334  readMesh (*fullMeshPtr, meshData);
335 
336  //fullMeshPtr->showMe( );
337 
338  if (verbose)
339  {
340  std::cout << std::endl;
341  }
342 
343  //Geometrical Infos on the sphere
344  Vector3D center (0.138, 0.0, 0.138);
345  Real radius (0.1);
346 
347  //Count how many volumes are in the sphere
348  //Create the Predicate
349  SphereCounter<mesh_Type::element_Type> countVolumesFunctor ( center, radius );
350  //Count phase
351  UInt numExtractedVolumes = fullMeshPtr->elementList().countAccordingToPredicate ( countVolumesFunctor );
352 
353  std::cout << " The Number of volumes inside the sphere is: " << numExtractedVolumes << std::endl;
354 
355  //Extract the list of elements inside the sphere.
356  //Creation of the class to investigate the mesh
357  SphereInterrogator<mesh_Type::element_Type> setSphereInterrogator ( center, radius );
358 
359  //This method changes the markerID for the volumes which are inside the defined sphere
360  fullMeshPtr->elementList().changeAccordingToFunctor ( setSphereInterrogator );
361 
362  //Exporting the modified mesh
363  std::string const nameExportMesh = dataFile ( "exporter/modifiedMesh", "damagedMesh");
364  MeshWriter::writeMeshMedit<RegionMesh<LinearTetra> > ( nameExportMesh , *fullMeshPtr );
365 
366 
367  // Exporting the mesh to check region with changed flag
368  MeshPartitioner< mesh_Type > meshPart ( fullMeshPtr, parameters->comm );
369  localMeshPtr = meshPart.meshPartition();
370 
371  std::string dOrder = dataFile ( "solid/space_discretization/order", "P1");
372  solidFESpacePtr_Type dFESpace ( new solidFESpace_Type (localMeshPtr, dOrder, 3, parameters->comm) );
373  solidETFESpacePtr_Type dETFESpace ( new solidETFESpace_Type (meshPart, & (dFESpace->refFE() ), & (dFESpace->fe().geoMap() ), parameters->comm) );
374 
375  //! 1. Constructor of the class to compute the tensions
376  StructuralOperator<RegionMesh<LinearTetra> > solid;
377 
378  //! face BChandler object
379  std::shared_ptr<BCHandler> BCh ( new BCHandler() );
380 
381  //! 2. Its setup
382  solid.setup (dataStructure,
383  dFESpace,
384  dETFESpace,
385  BCh,
386  parameters->comm);
387 
388  //! 6. Post-processing setting
389  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporter;
390 
391  std::string const exporterType = dataFile ( "exporter/type", "hdf5");
392  std::string const nameExporter = dataFile ( "exporter/name", "");
393 
394 #ifdef HAVE_HDF5
395  if (exporterType.compare ("hdf5") == 0)
396  {
397  exporter.reset ( new hdf5Filter_Type ( dataFile, nameExporter ) );
398  }
399  else
400 #endif
401  {
402  if (exporterType.compare ("none") == 0)
403  {
404  exporter.reset ( new emptyFilter_Type ( dataFile, meshPart.meshPartition(), nameExporter, parameters->comm->MyPID() ) ) ;
405  }
406 
407  else
408  {
409  exporter.reset ( new ensightFilter_Type ( dataFile, meshPart.meshPartition(), nameExporter, parameters->comm->MyPID() ) ) ;
410  }
411  }
412 
413  exporter->setMeshProcId (dFESpace->mesh(), dFESpace->map().comm().MyPID() );
414 
415  vectorPtr_Type meshColors ( new vector_Type (solid.displacement(), LifeV::Unique ) );
416  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "colors", dFESpace, meshColors, UInt (0) );
417 
418  exporter->postProcess ( 0.0 );
419  MPI_Barrier (MPI_COMM_WORLD);
420 
421  //color the mesh according to the marker of the volume
422  solid.colorMesh ( *meshColors );
423 
424  exporter->postProcess ( 1000.0 );
425 
426  //Closing files
427  exporter->closeFile();
428 
429  if (verbose )
430  {
431  std::cout << "finished" << std::endl;
432  }
433 
434  MPI_Barrier (MPI_COMM_WORLD);
435 
436 }
437 
438 
439 
440 
441 
442 
443 int
444 main ( int argc, char** argv )
445 {
446 
447 #ifdef HAVE_MPI
448  MPI_Init (&argc, &argv);
449  std::shared_ptr<Epetra_MpiComm> Comm (new Epetra_MpiComm ( MPI_COMM_WORLD ) );
450  if ( Comm->MyPID() == 0 )
451  {
452  std::cout << "% using MPI" << std::endl;
453  }
454 #else
455  std::shared_ptr<Epetra_SerialComm> Comm ( new Epetra_SerialComm() );
456  std::cout << "% using serial Version" << std::endl;
457 #endif
458 
459  Structure structure ( argc, argv, Comm );
460  structure.run();
461 
462 #ifdef HAVE_MPI
463  MPI_Finalize();
464 #endif
465  return EXIT_SUCCESS; //Check has to be perfomed later.
466 }
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
Structure(int argc, char **argv, std::shared_ptr< Epetra_Comm > structComm)
bool operator()(const meshEntity_Type &entity) const
FESpace - Short description here please!
Definition: FESpace.hpp:78
int main(int argc, char **argv)
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
SphereCounter(Vector3D const &center, Real radius, comparisonPolicy_Type const &policy=std::less< Real >())
SphereInterrogator(Vector3D const &center, Real radius, comparisonPolicy_Type const &policy=std::less< Real >())
std::shared_ptr< hdf5Filter_Type > hdf5FilterPtr_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
VectorSmall(VectorSmall< 3 > const &vector)
Copy constructor.
void run3d()
run the 3D driven cylinder simulation
LifeV::RegionMesh< LinearTetra > mesh_Type
std::shared_ptr< std::vector< Int > > M_isOnProc
void run2d()
run the 2D driven cylinder simulation
MeshData - class for handling spatial discretization.
Definition: MeshData.hpp:72
double Real
Generic real data.
Definition: LifeV.hpp:175
std::set< UInt > parseList(const std::string &list)
VectorSmall< 3 > Vector3D
VectorSmall(Real const &x, Real const &y, Real const &z)
Full constructor with all components explicitly initialized.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191