LifeV
lifev/structure/examples/example_checkingFibersDirection/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 
29  This exampleis meant to help people checking if their analytical definition
30  of the collagen fibers families in the computational domain is correct.
31 
32  Successfully used for cube, cylinder, torus, idealized aneurysm
33 
34  \author Paolo Tricerri <paolo.tricerri@epfl.ch>
35  \date 1861-03-17
36  */
37 
38 #ifdef TWODIM
39 #error test_structure cannot be compiled in 2D
40 #endif
41 
42 // Tell the compiler to ignore specific kind of warnings:
43 #pragma GCC diagnostic ignored "-Wunused-variable"
44 #pragma GCC diagnostic ignored "-Wunused-parameter"
45 
46 #include <Epetra_ConfigDefs.h>
47 #ifdef EPETRA_MPI
48 #include <mpi.h>
49 #include <Epetra_MpiComm.h>
50 #else
51 #include <Epetra_SerialComm.h>
52 #endif
53 
54 //Tell the compiler to restore the warning previously silented
55 #pragma GCC diagnostic warning "-Wunused-variable"
56 #pragma GCC diagnostic warning "-Wunused-parameter"
57 
58 #include <lifev/core/LifeV.hpp>
59 
60 #include <lifev/core/array/MapEpetra.hpp>
61 #include <lifev/core/array/VectorEpetra.hpp>
62 
63 #include <lifev/core/mesh/MeshData.hpp>
64 #include <lifev/core/mesh/MeshPartitioner.hpp>
65 #include <lifev/core/filter/PartitionIO.hpp>
66 
67 #include <lifev/structure/solver/StructuralConstitutiveLawData.hpp>
68 #include <lifev/structure/solver/StructuralConstitutiveLaw.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 #include <fstream>
78 
79 #include "ud_functions.hpp"
80 
81 
82 using namespace LifeV;
83 
85 {
86  std::string stringList = list;
87  std::set<UInt> setList;
88  if ( list == "" )
89  {
90  return setList;
91  }
92  size_t commaPos = 0;
93  while ( commaPos != std::string::npos )
94  {
95  commaPos = stringList.find ( "," );
96  setList.insert ( atoi ( stringList.substr ( 0, commaPos ).c_str() ) );
97  stringList = stringList.substr ( commaPos + 1 );
98  }
99  setList.insert ( atoi ( stringList.c_str() ) );
100  return setList;
101 }
102 
103 
104 class Structure
105 {
106 public:
107 
108  // Public typedefs
114 
115  // typedefs for fibers
116  // std function for fiber direction
117  typedef std::function<Real ( Real const&, Real const&, Real const&, Real const&, ID const& ) > fiberFunction_Type;
119 
122 
124 
127 
130 
131 #ifdef HAVE_HDF5
134 #endif
135 
136  /** @name Constructors, destructor
137  */
138  //@{
139  Structure ( int argc,
140  char** argv,
141  std::shared_ptr<Epetra_Comm> structComm );
142 
144  {}
145  //@}
146 
147  //@{
148  void run()
149  {
150  run3d();
151  }
152  //@}
153 
154 protected:
155 
156 private:
157 
158  /**
159  * run the 2D driven cylinder simulation
160  */
161  void run2d();
162 
163  /**
164  * run the 3D driven cylinder simulation
165  */
166  void run3d();
167 
168 private:
169  struct Private;
170  std::shared_ptr<Private> parameters;
171 };
172 
173 
174 
175 struct Structure::Private
176 {
178  rho (1), poisson (1), young (1), bulk (1), alpha (1), gamma (1)
179  {}
180  double rho, poisson, young, bulk, alpha, gamma;
181 
182  std::string data_file_name;
183 
184  std::shared_ptr<Epetra_Comm> comm;
185 };
186 
187 
188 
189 Structure::Structure ( int argc,
190  char** argv,
191  std::shared_ptr<Epetra_Comm> structComm) :
192  parameters ( new Private() )
193 {
194  GetPot command_line (argc, argv);
195  std::string data_file_name = command_line.follow ("data", 2, "-f", "--file");
196  GetPot dataFile ( data_file_name );
197  parameters->data_file_name = data_file_name;
198 
199  parameters->comm = structComm;
200  int ntasks = parameters->comm->NumProc();
201 
202  if (!parameters->comm->MyPID() )
203  {
204  std::cout << "My PID = " << parameters->comm->MyPID() << " out of " << ntasks << " running." << std::endl;
205  }
206 }
207 
208 
209 
210 void
211 Structure::run2d()
212 {
213  std::cout << "2D cylinder test case is not available yet\n";
214 }
215 
216 
217 
218 void
219 Structure::run3d()
220 {
221  bool verbose = (parameters->comm->MyPID() == 0);
222 
223  //! dataElasticStructure
224  GetPot dataFile ( parameters->data_file_name.c_str() );
225 
226  //Loading a partitoned mesh or reading a new one
227  const std::string partitioningMesh = dataFile ( "partitioningOffline/loadMesh", "no");
228 
229  //Creation of pointers
230  std::shared_ptr<MeshPartitioner<mesh_Type> > meshPart;
231  std::shared_ptr<mesh_Type> pointerToMesh;
232 
233  if ( ! (partitioningMesh.compare ("no") ) )
234  {
235  std::shared_ptr<mesh_Type > fullMeshPtr (new mesh_Type ( ( parameters->comm ) ) );
236  //Creating a new mesh from scratch
237  MeshData meshData;
238  meshData.setup (dataFile, "solid/space_discretization");
239  readMesh (*fullMeshPtr, meshData);
240 
241  meshPart.reset ( new MeshPartitioner<mesh_Type> (fullMeshPtr, parameters->comm ) );
242 
243  pointerToMesh = meshPart->meshPartition();
244  }
245  else
246  {
247  //Creating a mesh object from a partitioned mesh
248  const std::string partsFileName (dataFile ("partitioningOffline/hdf5_file_name", "NO_DEFAULT_VALUE.h5") );
249 
250  std::shared_ptr<Epetra_MpiComm> mpiComm =
251  std::dynamic_pointer_cast<Epetra_MpiComm>(parameters->comm);
252  PartitionIO<mesh_Type> partitionIO (partsFileName, mpiComm);
253 
254 
255  partitionIO.read (pointerToMesh);
256 
257  }
258 
259  std::string dOrder = dataFile ( "solid/space_discretization/order", "P1");
260 
261  //Mainly used for BCs assembling (Neumann type)
262  solidFESpacePtr_Type dFESpace ( new solidFESpace_Type (pointerToMesh, dOrder, 3, parameters->comm) );
263  solidFESpacePtr_Type dScalarFESpace ( new solidFESpace_Type (pointerToMesh, dOrder, 1, parameters->comm) );
264 
265  UInt numberOfFibersFamilies = dataFile ( "solid/model/fibers/numberFamilies" , 0 );
266  ASSERT( numberOfFibersFamilies, "This test should be used to check at least one fiber family!! Check the data file, please.")
267 
268  // Setting the fibers
269  vectorFiberFunctionPtr_Type pointerToVectorOfFamilies( new vectorFiberFunction_Type( ) );
270  (*pointerToVectorOfFamilies).resize( numberOfFibersFamilies );
271 
272  listOfFiberDirections_Type fiberDirections;
273  fiberDirections.resize( numberOfFibersFamilies );
274 
275  if( verbose )
276  std::cout << "Size of the number of families: " << (*pointerToVectorOfFamilies).size() << std::endl;
277 
278  fibersDirectionList setOfFiberFunctions;
279  setOfFiberFunctions.setupFiberDefinitions( numberOfFibersFamilies );
280 
281  // Setting the vector of fibers functions
282  for( UInt k(1); k <= pointerToVectorOfFamilies->size( ); k++ )
283  {
284  // Setting up the name of the function to define the family
285  std::string family="Family";
286  // adding the number of the family
287  std::string familyNumber;
288  std::ostringstream number;
289  number << ( k );
290  familyNumber = number.str();
291 
292  // Name of the function to create
293  std::string creationString = family + familyNumber;
294  (*pointerToVectorOfFamilies)[ k-1 ].reset( new fiberFunction_Type() );
295  (*pointerToVectorOfFamilies)[ k-1 ] = setOfFiberFunctions.fiberDefinition( creationString );
296 
297  fiberDirections[ k-1 ].reset( new vector_Type( dFESpace->map() ) );
298  }
299 
300  vectorPtr_Type thetaSection;
301  thetaSection.reset( new vector_Type( dScalarFESpace->map() ) );
302  vectorPtr_Type thetaRotation;
303  thetaRotation.reset( new vector_Type( dScalarFESpace->map() ) );
304  vectorPtr_Type sphereIndicator;
305  sphereIndicator.reset( new vector_Type( dScalarFESpace->map() ) );
306  vectorPtr_Type positionCenterVector;
307  positionCenterVector.reset( new vector_Type( dFESpace->map() ) );
308  vectorPtr_Type localPositionVector;
309  localPositionVector.reset( new vector_Type( dFESpace->map() ) );
310 
311  MPI_Barrier (MPI_COMM_WORLD);
312 
313  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporter;
314 
315  std::string const exporterType = dataFile ( "exporter/type", "ensight");
316  std::string const exportFileName = dataFile ( "exporter/nameFile", "structure");
317 #ifdef HAVE_HDF5
318  if (exporterType.compare ("hdf5") == 0)
319  {
320  exporter.reset ( new ExporterHDF5<RegionMesh<LinearTetra> > ( dataFile, exportFileName ) );
321  }
322  else
323 #endif
324  {
325  if (exporterType.compare ("none") == 0)
326  {
327  exporter.reset ( new ExporterEmpty<RegionMesh<LinearTetra> > ( dataFile, pointerToMesh, exportFileName, parameters->comm->MyPID() ) );
328  }
329 
330  else
331  {
332  exporter.reset ( new ExporterEnsight<RegionMesh<LinearTetra> > ( dataFile, pointerToMesh, exportFileName, parameters->comm->MyPID() ) );
333  }
334  }
335 
336  exporter->setPostDir ( "./" );
337  exporter->setMeshProcId ( pointerToMesh, parameters->comm->MyPID() );
338 
339  // Adding the fibers vectors
340  // Setting the vector of fibers functions
341  for( UInt k(1); k <= pointerToVectorOfFamilies->size( ); k++ )
342  {
343  // Setting up the name of the function to define the family
344  std::string family="Family-";
345  // adding the number of the family
346  std::string familyNumber;
347  std::ostringstream number;
348  number << ( k );
349  familyNumber = number.str();
350 
351  // Name of the function to create
352  std::string creationString = family + familyNumber;
353  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, creationString, dFESpace, fiberDirections[ k-1 ], UInt (0) );
354  }
355 
356  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::ScalarField, "sphereIndicator", dScalarFESpace, sphereIndicator, UInt (0) );
357  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::ScalarField, "thetaSection", dScalarFESpace, thetaSection, UInt (0) );
358  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::ScalarField, "thetaRotation", dScalarFESpace, thetaRotation, UInt (0) );
359  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "positionCenter", dFESpace, positionCenterVector, UInt (0) );
360  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "localPosition", dFESpace, localPositionVector, UInt (0) );
361 
362  dScalarFESpace->interpolate ( static_cast<solidFESpace_Type::function_Type>( thetaFunction ),
363  *thetaSection,
364  0.0 );
365 
366  dScalarFESpace->interpolate ( static_cast<solidFESpace_Type::function_Type>( thetaRotationFunction ),
367  *thetaRotation,
368  0.0 );
369 
370  dScalarFESpace->interpolate ( static_cast<solidFESpace_Type::function_Type>( sphereIndicatorFunction ),
371  *sphereIndicator,
372  0.0 );
373 
374  dFESpace->interpolate ( static_cast<solidFESpace_Type::function_Type>( positionCenterSpherical ),
375  *positionCenterVector,
376  0.0 );
377 
378  dFESpace->interpolate ( static_cast<solidFESpace_Type::function_Type>( localPositionSpherical ),
379  *localPositionVector,
380  0.0 );
381 
382  // For loop on the families of fibers
383  for( UInt k(1); k <= pointerToVectorOfFamilies->size( ); k++ )
384  {
385  // Interpolating the i-th fiber family
386  dFESpace->interpolate ( static_cast<solidFESpace_Type::function_Type>( *(*pointerToVectorOfFamilies)[k - 1] ),
387  *fiberDirections[ k-1 ],
388  0.0 );
389  }
390 
391  exporter->postProcess ( 0.0 );
392  std::cout.precision(16);
393 
394  MPI_Barrier (MPI_COMM_WORLD);
395 }
396 
397 
398 int
399 main ( int argc, char** argv )
400 {
401 
402 #ifdef HAVE_MPI
403  MPI_Init (&argc, &argv);
404  std::shared_ptr<Epetra_MpiComm> Comm (new Epetra_MpiComm ( MPI_COMM_WORLD ) );
405  if ( Comm->MyPID() == 0 )
406  {
407  std::cout << "% using MPI" << std::endl;
408  }
409 #else
410  std::shared_ptr<Epetra_SerialComm> Comm ( new Epetra_SerialComm() );
411  std::cout << "% using serial Version" << std::endl;
412 #endif
413 
414  Structure structure ( argc, argv, Comm );
415  structure.run();
416 
417 #ifdef HAVE_MPI
418  MPI_Finalize();
419 #endif
420  return EXIT_SUCCESS ;
421 }
VectorEpetra - The Epetra Vector format Wrapper.
Structure(int argc, char **argv, std::shared_ptr< Epetra_Comm > structComm)
ExporterEnsight data exporter.
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
LifeV::ExporterEnsight< mesh_Type > ensightFilter_Type
std::shared_ptr< fiberFunction_Type > fiberFunctionPtr_Type
std::shared_ptr< hdf5Filter_Type > hdf5FilterPtr_Type
FESpace< RegionMesh< LinearTetra >, MapEpetra > solidFESpace_Type
std::set< UInt > parseList(const std::string &list)
void run3d()
run the 3D driven cylinder simulation
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
LifeV::RegionMesh< LinearTetra > mesh_Type
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
LifeV::ExporterEmpty< mesh_Type > emptyExporter_Type
void setupFiberDefinitions(const UInt nbFamilies)
std::shared_ptr< emptyExporter_Type > emptyExporterPtr_Type
int operator()(const char *VarName, int Default) const
Definition: GetPot.hpp:2021
int main(int argc, char **argv)
std::shared_ptr< solidFESpace_Type > solidFESpacePtr_Type
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
std::shared_ptr< vectorFiberFunction_Type > vectorFiberFunctionPtr_Type
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > fiberFunction_Type
std::vector< fiberFunctionPtr_Type > vectorFiberFunction_Type