LifeV
lifev/structure/examples/example_principalTensionsInflationExtensions/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  \date 2012-05-01
30  */
31 #undef HAVE_HDF5
32 #ifdef TWODIM
33 #error test_structure cannot be compiled in 2D
34 #endif
35 
36 // Tell the compiler to ignore specific kind of warnings:
37 #pragma GCC diagnostic ignored "-Wunused-variable"
38 #pragma GCC diagnostic ignored "-Wunused-parameter"
39 
40 #include <Epetra_ConfigDefs.h>
41 #ifdef EPETRA_MPI
42 #include <mpi.h>
43 #include <Epetra_MpiComm.h>
44 #else
45 #include <Epetra_SerialComm.h>
46 #endif
47 
48 //Tell the compiler to restore the warning previously silented
49 #pragma GCC diagnostic warning "-Wunused-variable"
50 #pragma GCC diagnostic warning "-Wunused-parameter"
51 
52 #include <lifev/core/LifeV.hpp>
53 
54 #include <lifev/core/array/MapEpetra.hpp>
55 
56 #include <lifev/core/mesh/MeshData.hpp>
57 #include <lifev/core/mesh/MeshPartitioner.hpp>
58 
59 #include <lifev/structure/solver/StructuralConstitutiveLawData.hpp>
60 
61 #include <lifev/structure/solver/StructuralConstitutiveLaw.hpp>
62 #include <lifev/structure/solver/VenantKirchhoffMaterialLinear.hpp>
63 #include <lifev/structure/solver/VenantKirchhoffMaterialNonLinear.hpp>
64 #include <lifev/structure/solver/NeoHookeanMaterialNonLinear.hpp>
65 #include <lifev/structure/solver/ExponentialMaterialNonLinear.hpp>
66 
67 #include <lifev/structure/solver/WallTensionEstimatorCylindricalCoordinates.hpp>
68 #include <lifev/structure/solver/WallTensionEstimatorData.hpp>
69 
70 #include <lifev/core/filter/ExporterEnsight.hpp>
71 #ifdef HAVE_HDF5
72 #include <lifev/core/filter/ExporterHDF5.hpp>
73 #endif
74 #include <lifev/core/filter/ExporterEmpty.hpp>
75 
76 #include <iostream>
77 
78 
79 using namespace LifeV;
80 
81 int returnValue = EXIT_FAILURE;
82 
84 {
85  std::string stringList = list;
86  std::set<UInt> setList;
87  if ( list == "" )
88  {
89  return setList;
90  }
91  size_t commaPos = 0;
92  while ( commaPos != std::string::npos )
93  {
94  commaPos = stringList.find ( "," );
95  setList.insert ( atoi ( stringList.substr ( 0, commaPos ).c_str() ) );
96  stringList = stringList.substr ( commaPos + 1 );
97  }
98  setList.insert ( atoi ( stringList.c_str() ) );
99  return setList;
100 }
101 
102 
103 class Structure
104 {
105 public:
106 
108 
109  // Filters
110  typedef LifeV::Exporter<mesh_Type > filter_Type;
112 
117 
118 #ifdef HAVE_HDF5
121 #endif
122 
123 
124 
125  /** @name Constructors, destructor
126  */
127  //@{
128  Structure ( int argc,
129  char** argv,
130  std::shared_ptr<Epetra_Comm> structComm );
131 
133  {}
134  //@}
135 
136  //@{
137  void run()
138  {
139  run3d();
140  }
141  //@}
142 
143 protected:
144 
145 private:
146 
147  /**
148  * run the 2D driven cylinder simulation
149  */
150  void run2d();
151 
152  /**
153  * run the 3D driven cylinder simulation
154  */
155  void run3d();
156 
157 private:
158  struct Private;
159  std::shared_ptr<Private> parameters;
160  filterPtr_Type M_importer;
161  filterPtr_Type M_exporter;
162 };
163 
164 
165 
166 struct Structure::Private
167 {
169  rho (1),
170  poisson (1),
171  young (1),
172  bulk (1),
173  alpha (1),
174  gamma (1)
175  {}
176  typedef std::function<Real ( Real const&, Real const&, Real const&, Real const&, ID const& ) > fct_type;
177  double rho, poisson, young, bulk, alpha, gamma;
178 
179  std::string data_file_name;
180 
181  std::shared_ptr<Epetra_Comm> comm;
182 
183 };
184 
185 
186 
187 Structure::Structure ( int argc,
188  char** argv,
189  std::shared_ptr<Epetra_Comm> structComm) :
190  parameters ( new Private() )
191 {
192  GetPot command_line (argc, argv);
193  std::string data_file_name = command_line.follow ("data", 2, "-f", "--file");
194  GetPot dataFile ( data_file_name );
195  parameters->data_file_name = data_file_name;
196 
197  parameters->rho = dataFile ( "solid/physics/density", 1. );
198  parameters->young = dataFile ( "solid/physics/young", 1. );
199  parameters->poisson = dataFile ( "solid/physics/poisson", 1. );
200  parameters->bulk = dataFile ( "solid/physics/bulk", 1. );
201  parameters->alpha = dataFile ( "solid/physics/alpha", 1. );
202  parameters->gamma = dataFile ( "solid/physics/gamma", 1. );
203 
204  std::cout << "density = " << parameters->rho << std::endl
205  << "young = " << parameters->young << std::endl
206  << "poisson = " << parameters->poisson << std::endl
207  << "bulk = " << parameters->bulk << std::endl
208  << "alpha = " << parameters->alpha << std::endl
209  << "gamma = " << parameters->gamma << std::endl;
210 
211  parameters->comm = structComm;
212  int ntasks = parameters->comm->NumProc();
213 
214  if (!parameters->comm->MyPID() )
215  {
216  std::cout << "My PID = " << parameters->comm->MyPID() << " out of " << ntasks << " running." << std::endl;
217  }
218 }
219 
220 
221 
222 void
223 Structure::run2d()
224 {
225  std::cout << "2D cylinder test case is not available yet\n";
226 }
227 
228 
229 
230 void
231 Structure::run3d()
232 {
233  // General typedefs
234  typedef WallTensionEstimatorCylindricalCoordinates< mesh_Type >::solutionVect_Type vector_Type;
235  typedef std::shared_ptr<vector_Type> vectorPtr_Type;
236  typedef FESpace< mesh_Type, MapEpetra > solidFESpace_Type;
237  typedef std::shared_ptr<solidFESpace_Type> solidFESpacePtr_Type;
238 
239  typedef ETFESpace< RegionMesh<LinearTetra>, MapEpetra, 3, 3 > solidETFESpace_Type;
240  typedef std::shared_ptr<solidETFESpace_Type> solidETFESpacePtr_Type;
241 
242  bool verbose = (parameters->comm->MyPID() == 0);
243 
244  //! dataElasticStructure for parameters
245  GetPot dataFile ( parameters->data_file_name.c_str() );
246 
247  std::shared_ptr<StructuralConstitutiveLawData> dataStructure (new StructuralConstitutiveLawData( ) );
248  dataStructure->setup (dataFile);
249 
250  //! Parameters for the analysis
251  std::shared_ptr<WallTensionEstimatorData> tensionData (new WallTensionEstimatorData( ) );
252  tensionData->setup (dataFile);
253 
254  tensionData->showMe();
255  //! Read and partition mesh
256  MeshData meshData;
257  meshData.setup (dataFile, "solid/space_discretization");
258 
259  std::shared_ptr<mesh_Type > fullMeshPtr ( new RegionMesh<LinearTetra> ( ( parameters->comm ) ) );
260  readMesh (*fullMeshPtr, meshData);
261 
262  MeshPartitioner< mesh_Type > meshPart ( fullMeshPtr, parameters->comm );
263 
264  //! Functional spaces - needed for the computations of the gradients
265  std::string dOrder = dataFile ( "solid/space_discretization/order", "P1");
266  solidFESpacePtr_Type dFESpace ( new solidFESpace_Type (meshPart, dOrder, 3, parameters->comm) );
267  solidETFESpacePtr_Type dETFESpace ( new solidETFESpace_Type (meshPart, & (dFESpace->refFE() ), & (dFESpace->fe().geoMap() ), parameters->comm) );
268 
269  if (verbose)
270  {
271  std::cout << std::endl;
272  }
273 
274 
275  //! Setting the marker for the volumes
276  UInt marker = dataFile ( "solid/physics/material_flag", 1);
277 
278  //! 1. Constructor of the class to compute the tensions
279  std::shared_ptr<WallTensionEstimatorCylindricalCoordinates< mesh_Type > >
280  solid ( new WallTensionEstimatorCylindricalCoordinates< mesh_Type >() );
281 
282  //! 2. Its setup
283  solid->setup (dataStructure,
284  tensionData,
285  dFESpace,
286  dETFESpace,
287  parameters->comm,
288  marker);
289 
290  //! 3. Creation of the importers to read the displacement field
291  std::string const filename = tensionData->nameFile();
292  std::string const importerType = tensionData->typeFile();
293 
294  std::string iterationString; //useful to iterate over the strings
295 
296  if (verbose)
297  {
298  std::cout << "The filename is : " << filename << std::endl;
299  std::cout << "The importerType is: " << importerType << std::endl;
300  }
301 
302 #ifdef HAVE_HDF5
303  if (importerType.compare ("hdf5") == 0)
304  {
305  M_importer.reset ( new hdf5Filter_Type (dataFile, filename) );
306  }
307  else
308 #endif
309  {
310  if (importerType.compare ("none") == 0)
311  {
312  M_importer.reset ( new emptyFilter_Type ( dataFile, solid->dFESpace().mesh(), "solid", solid->dFESpace().map().comm().MyPID() ) );
313  }
314  else
315  {
316  M_importer.reset ( new ensightFilter_Type ( dataFile, filename ) );
317  }
318  }
319  M_importer->setMeshProcId (solid->dFESpace().mesh(), solid->dFESpace().map().comm().MyPID() );
320 
321  // The vector where the solution will be stored
322  vectorPtr_Type solidDisp (new vector_Type (solid->dFESpace().map(), M_importer->mapType() ) );
323 
324 
325  //! 6. Post-processing setting
326  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporter;
327 
328  std::string const exporterType = dataFile ( "exporter/type", "hdf5");
329  std::string const nameExporter = dataFile ( "exporter/name", "tensions");
330 
331 #ifdef HAVE_HDF5
332  if (exporterType.compare ("hdf5") == 0)
333  {
334  M_exporter.reset ( new hdf5Filter_Type ( dataFile, nameExporter ) );
335  }
336  else
337 #endif
338  {
339  if (exporterType.compare ("none") == 0)
340  {
341  M_exporter.reset ( new emptyFilter_Type ( dataFile, meshPart.meshPartition(), nameExporter, parameters->comm->MyPID() ) ) ;
342  }
343 
344  else
345  {
346  M_exporter.reset ( new ensightFilter_Type ( dataFile, meshPart.meshPartition(), nameExporter, parameters->comm->MyPID() ) ) ;
347  }
348  }
349 
350  M_exporter->setMeshProcId (solid->dFESpace().mesh(), solid->dFESpace().map().comm().MyPID() );
351 
352  vectorPtr_Type solidTensions ( new vector_Type (solid->principalStresses(), M_exporter->mapType() ) );
353 
354  M_exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "vonMises", dFESpace, solidTensions, UInt (0) );
355  M_exporter->postProcess ( 0.0 );
356 
357 
358  // //Post processing for the displacement gradient
359  // std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporterX;
360  // std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporterY;
361  // std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporterZ;
362 
363  // //Setting pointers
364  // exporterX.reset( new ExporterHDF5<RegionMesh<LinearTetra> > ( dataFile, "gradX" ) );
365  // exporterY.reset( new ExporterHDF5<RegionMesh<LinearTetra> > ( dataFile, "gradY" ) );
366  // exporterZ.reset( new ExporterHDF5<RegionMesh<LinearTetra> > ( dataFile, "gradZ" ) );
367 
368  // exporterX->setMeshProcId(solid->dFESpace().mesh(), solid->dFESpace().map().comm().MyPID());
369  // exporterY->setMeshProcId(solid->dFESpace().mesh(), solid->dFESpace().map().comm().MyPID());
370  // exporterZ->setMeshProcId(solid->dFESpace().mesh(), solid->dFESpace().map().comm().MyPID());
371 
372  // //Defining the vectors
373  // vectorPtr_Type gradX ( new vector_Type(solid->gradientX(), M_exporter->mapType() ) );
374  // vectorPtr_Type gradY ( new vector_Type(solid->gradientY(), M_exporter->mapType() ) );
375  // vectorPtr_Type gradZ ( new vector_Type(solid->gradientZ(), M_exporter->mapType() ) );
376 
377  // //Adding variable
378  // exporterX->addVariable( ExporterData<mesh_Type >::VectorField, "gradX", solid->dFESpacePtr(),
379  // gradX, UInt(0) );
380  // exporterY->addVariable( ExporterData<mesh_Type >::VectorField, "gradY", solid->dFESpacePtr(),
381  // gradY, UInt(0) );
382  // exporterZ->addVariable( ExporterData<mesh_Type >::VectorField, "gradZ", solid->dFESpacePtr(),
383  // gradZ, UInt(0) );
384 
385  // exporterX->postProcess( 0.0 );
386  // exporterY->postProcess( 0.0 );
387  // exporterZ->postProcess( 0.0 );
388 
389 
390  //! =================================================================================
391  //! Analysis - Istant or Interval
392  //! =================================================================================
393 
394  MPI_Barrier (MPI_COMM_WORLD);
395 
396  //! 5. For each interval, the analysis is performed
397  //LifeV::Real dt = dataFile ( "solid/time_discretization/timestep", 0.0);
398  std::string const nameField = dataFile ( "solid/analysis/nameField", "NO_DEFAULT_VALUE");
399 
400  if ( !tensionData->analysisType().compare ("istant") )
401  {
402  //Get the iteration number
403  iterationString = tensionData->iterStart (0);
404  LifeV::Real startTime = tensionData->initialTime (0);
405 
406  /*!Definition of the ExporterData, used to load the solution inside the previously defined vectors*/
407  LifeV::ExporterData<mesh_Type> solutionDispl (LifeV::ExporterData<mesh_Type>::VectorField, nameField + "." + iterationString, solid->dFESpacePtr(), solidDisp, UInt (0), LifeV::ExporterData<mesh_Type>::UnsteadyRegime );
408 
409  //Read the variable
410  M_importer->readVariable (solutionDispl);
411  M_importer->closeFile();
412 
413 
414  //Create and exporter to check importing
415  // std::string expVerFile = "verificationDisplExporter";
416  // LifeV::ExporterHDF5<RegionMesh<LinearTetra> > exporter( dataFile, meshPart.meshPartition(), expVerFile, parameters->comm->MyPID());
417  // vectorPtr_Type vectVer ( new vector_Type(solid->displacement(), exporter.mapType() ) );
418 
419  // exporter.addVariable( ExporterData<mesh_Type >::VectorField, "displVer", solid->dFESpacePtr(),
420  // vectVer, UInt(0) );
421 
422  // exporter.postProcess(0.0);
423  // *vectVer = *solidDisp;
424  // exporter.postProcess(startTime);
425 
426 
427  //Set the current solution as the displacement vector to use
428  solid->setDisplacement (*solidDisp);
429 
430  std::cout << "The norm of the set displacement, at time " << startTime << ", is: " << solid->displacement().norm2() << std::endl;
431 
432  //Perform the analysis
433  solid->analyzeTensions();
434 
435  //Extracting the gradient
436  // *gradX = solid->gradientX();
437  // *gradY = solid->gradientY();
438  // *gradZ = solid->gradientZ();
439 
440  // exporterX->postProcess( startTime );
441  // exporterY->postProcess( startTime );
442  // exporterZ->postProcess( startTime );
443 
444  //Extracting the tensions
445  std::cout << std::endl;
446  std::cout << "Norm of the tension vector: " << solid->principalStresses().norm2() << std::endl;
447 
448  *solidTensions = solid->principalStresses();
449  M_exporter->postProcess ( startTime );
450 
451  if (verbose )
452  {
453  std::cout << "Analysis Completed!" << std::endl;
454  }
455 
456  //Closing files
457  M_exporter->closeFile();
458  // exporterX->closeFile();
459  // exporterY->closeFile();
460  // exporterZ->closeFile();
461  // exporter.closeFile();
462 
463 
464  }
465  else
466  {
467  std::cout << "we are still working idiot! " << std::endl;
468  }
469 
470  if (verbose )
471  {
472  std::cout << "finished" << std::endl;
473  }
474 
475  MPI_Barrier (MPI_COMM_WORLD);
476  //!---------------------------------------------.-----------------------------------------------------
477 }
478 
479 int
480 main ( int argc, char** argv )
481 {
482 
483 #ifdef HAVE_MPI
484  MPI_Init (&argc, &argv);
485  std::shared_ptr<Epetra_MpiComm> Comm (new Epetra_MpiComm ( MPI_COMM_WORLD ) );
486  if ( Comm->MyPID() == 0 )
487  {
488  std::cout << "% using MPI" << std::endl;
489  }
490 #else
491  std::shared_ptr<Epetra_SerialComm> Comm ( new Epetra_SerialComm() );
492  std::cout << "% using serial Version" << std::endl;
493 #endif
494 
495  Structure structure ( argc, argv, Comm );
496  structure.run();
497 
498 #ifdef HAVE_MPI
499  MPI_Finalize();
500 #endif
501  return returnValue ;
502 }
Structure(int argc, char **argv, std::shared_ptr< Epetra_Comm > structComm)
ExporterEnsight data exporter.
std::shared_ptr< emptyFilter_Type > emptyFilterPtr_Type
FESpace - Short description here please!
Definition: FESpace.hpp:78
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > fct_type
LifeV::ExporterEnsight< mesh_Type > ensightFilter_Type
LifeV::Exporter< mesh_Type > filter_Type
std::shared_ptr< hdf5Filter_Type > hdf5FilterPtr_Type
std::set< UInt > parseList(const std::string &list)
LifeV::ExporterEmpty< mesh_Type > emptyFilter_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
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
std::shared_ptr< ensightFilter_Type > ensightFilterPtr_Type
MeshData - class for handling spatial discretization.
Definition: MeshData.hpp:72
int operator()(const char *VarName, int Default) const
Definition: GetPot.hpp:2021
std::shared_ptr< LifeV::Exporter< mesh_Type > > filterPtr_Type
int main(int argc, char **argv)
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191