LifeV
lifev/structure/examples/example_checkigForceTerm/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 test is the case of traction of a cube. It does not use the symmetry BCs
30  This test uses the FESpace which is the standard in LifeV and the ETFESpace
31  The FESpace is used for the BCs of Neumann type since in the ET branch there
32  is not the integration over the boundary faces.
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 #include <lifev/core/algorithm/PreconditionerIfpack.hpp>
60 #include <lifev/core/algorithm/PreconditionerML.hpp>
61 
62 #include <lifev/core/array/MapEpetra.hpp>
63 #include <lifev/core/array/VectorSmall.hpp>
64 
65 #include <lifev/core/mesh/MeshData.hpp>
66 #include <lifev/core/mesh/MeshPartitioner.hpp>
67 
68 #include <lifev/structure/solver/StructuralConstitutiveLawData.hpp>
69 
70 #include <lifev/structure/solver/StructuralConstitutiveLaw.hpp>
71 #include <lifev/structure/solver/StructuralOperator.hpp>
72 #include <lifev/structure/solver/isotropic/VenantKirchhoffMaterialLinear.hpp>
73 
74 
75 #include <lifev/core/filter/ExporterEnsight.hpp>
76 #ifdef HAVE_HDF5
77 #include <lifev/core/filter/ExporterHDF5.hpp>
78 #endif
79 #include <lifev/core/filter/ExporterEmpty.hpp>
80 
81 //Includes for the Expression Template
82 #include <lifev/eta/fem/ETFESpace.hpp>
83 
84 #include <iostream>
85 
86 
87 
88 using namespace LifeV;
89 
90 namespace
91 {
92 static bool regIF = (PRECFactory::instance().registerProduct ( "Ifpack", &createIfpack ) );
93 static bool regML = (PRECFactory::instance().registerProduct ( "ML", &createML ) );
94 }
95 
96 
98 {
99  std::string stringList = list;
100  std::set<UInt> setList;
101  if ( list == "" )
102  {
103  return setList;
104  }
105  size_t commaPos = 0;
106  while ( commaPos != std::string::npos )
107  {
108  commaPos = stringList.find ( "," );
109  setList.insert ( atoi ( stringList.substr ( 0, commaPos ).c_str() ) );
110  stringList = stringList.substr ( commaPos + 1 );
111  }
112  setList.insert ( atoi ( stringList.c_str() ) );
113  return setList;
114 }
115 
116 
117 class Structure
118 {
119 public:
120 
121  // Public typedefs
128 
131 
132  // typedefs for fibers
133  // std function for fiber direction
134  typedef std::function<Real ( Real const&, Real const&, Real const&, Real const&, ID const& ) > analyticalFunction_Type;
136 
137  typedef std::function<VectorSmall<3> ( Real const&, Real const&, Real const&, Real const& ) > bodyFunction_Type;
139 
140 
143 
145 
146  /** @name Constructors, destructor
147  */
148  //@{
149  Structure ( int argc,
150  char** argv,
151  std::shared_ptr<Epetra_Comm> structComm );
152 
154  {}
155  //@}
156 
157  //@{
158  void run()
159  {
160  run3d();
161  }
162  //@}
163 
164 protected:
165 
166 private:
167 
168  /**
169  * run the 2D driven cylinder simulation
170  */
171  void run2d();
172 
173  /**
174  * run the 3D driven cylinder simulation
175  */
176  void run3d();
177 
178 private:
179  struct Private;
181 };
182 
183 
184 
185 struct Structure::Private
186 {
188  rho (1), poisson (1), young (1), bulk (1), alpha (1), gamma (1)
189  {}
190  double rho, poisson, young, bulk, alpha, gamma;
191 
193 
195 
196  static Real lifeVedF (const Real& t, const Real& x, const Real& y, const Real& z, const ID& i)
197  {
198 
199  switch (i)
200  {
201  case 0:
202  return 1.0;
203  break;
204  case 1:
205  return 1.0;
206  break;
207  case 2:
208  return 1.0;
209  break;
210  default:
211  ERROR_MSG ("This entry is not allowed: ud_functions.hpp");
212  return 0.;
213  break;
214  }
215 
216  }
217 
218  static VectorSmall<3> f (const Real& t, const Real& x, const Real& y, const Real& z)
219  {
220  VectorSmall<3> evaluationOfF;
221 
222  evaluationOfF[ 0 ] = 1.0;
223  evaluationOfF[ 1 ] = 1.0;
224  evaluationOfF[ 2 ] = 1.0;
225 
226  return evaluationOfF;
227  }
228 
229 
230 };
231 
232 
233 
234 Structure::Structure ( int argc,
235  char** argv,
236  std::shared_ptr<Epetra_Comm> structComm) :
237  parameters ( new Private() )
238 {
239  GetPot command_line (argc, argv);
240  std::string data_file_name = command_line.follow ("data", 2, "-f", "--file");
241  GetPot dataFile ( data_file_name );
242  parameters->data_file_name = data_file_name;
243 
244  parameters->comm = structComm;
245  int ntasks = parameters->comm->NumProc();
246 
247  if (!parameters->comm->MyPID() )
248  {
249  std::cout << "My PID = " << parameters->comm->MyPID() << " out of " << ntasks << " running." << std::endl;
250  }
251 }
252 
253 
254 
255 void
256 Structure::run2d()
257 {
258  std::cout << "2D cylinder test case is not available yet\n";
259 }
260 
261 
262 
263 void
264 Structure::run3d()
265 {
266  bool verbose = (parameters->comm->MyPID() == 0);
267 
268  //! dataElasticStructure
269  GetPot dataFile ( parameters->data_file_name.c_str() );
270 
271  //! Number of boundary conditions for the velocity and mesh motion
272  std::shared_ptr<BCHandler> BCh ( new BCHandler() );
273 
274  std::shared_ptr<StructuralConstitutiveLawData> dataStructure (new StructuralConstitutiveLawData( ) );
275  dataStructure->setup (dataFile);
276 
277  dataStructure->showMe();
278 
279  MeshData meshData;
280  meshData.setup (dataFile, "solid/space_discretization");
281 
282  std::shared_ptr<RegionMesh<LinearTetra> > fullMeshPtr (new RegionMesh<LinearTetra> ( parameters->comm ) );
283  readMesh (*fullMeshPtr, meshData);
284 
285  MeshPartitioner< RegionMesh<LinearTetra> > meshPart ( fullMeshPtr, parameters->comm );
286  std::shared_ptr<RegionMesh<LinearTetra> > localMeshPtr (new RegionMesh<LinearTetra> ( parameters->comm ) );
287  localMeshPtr = meshPart.meshPartition();
288 
289  std::string dOrder = dataFile ( "solid/space_discretization/order", "P1");
290 
291  //Mainly used for BCs assembling (Neumann type)
292  solidFESpacePtr_Type dFESpace ( new solidFESpace_Type (localMeshPtr, dOrder, 3, parameters->comm) );
293  solidETFESpacePtr_Type dETFESpace ( new solidETFESpace_Type (meshPart, & (dFESpace->refFE() ), & (dFESpace->fe().geoMap() ), parameters->comm) );
294 
295  //! 1. Constructor of the structuralSolver
296  StructuralOperator< RegionMesh<LinearTetra> > solid;
297 
298  //! 2. Setup of the structuralSolver
299  solid.setup (dataStructure,
300  dFESpace,
301  dETFESpace,
302  BCh,
303  parameters->comm);
304 
305  //! 3. Setting data from getPot for preconditioners
306  solid.setDataFromGetPot (dataFile);
307 
308  //! Setting the vectors
309  vectorPtr_Type rhs (new vector_Type (solid.displacement(), Unique) );
310  vectorPtr_Type disp (new vector_Type (solid.displacement(), Unique) );
311 
312  // Comment this part in order not to have body force in the RHS of the equation
313  bool bodyForce = dataFile ( "solid/physics/bodyForce" , false );
314  if( bodyForce )
315  {
316  solid.setHavingSourceTerm( bodyForce );
317  bodyFunctionPtr_Type bodyTerm( new bodyFunction_Type( Private::f ) );
318 
319  solid.setSourceTerm( bodyTerm );
320  }
321 
322  // Build the mass matrix
323  solid.computeMassMatrix ( 1.0 );
324 
325  // Build the rhs
326  solid.updateRightHandSideWithBodyForce( 1.0, *rhs );
327 
328  MPI_Barrier (MPI_COMM_WORLD);
329 
330  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporter;
331  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporterCheck;
332 
333  std::string const exporterType = dataFile ( "exporter/type", "ensight");
334  std::string const exporterNameFile = dataFile ( "exporter/nameFile", "structure");
335 
336 #ifdef HAVE_HDF5
337  if (exporterType.compare ("hdf5") == 0)
338  {
339  exporter.reset ( new ExporterHDF5<RegionMesh<LinearTetra> > ( dataFile, exporterNameFile ) );
340  }
341  else
342 #endif
343  {
344  if (exporterType.compare ("none") == 0)
345  {
346  exporter.reset ( new ExporterEmpty<RegionMesh<LinearTetra> > ( dataFile, meshPart.meshPartition(), "structure", parameters->comm->MyPID() ) );
347  }
348 
349  else
350  {
351  exporter.reset ( new ExporterEnsight<RegionMesh<LinearTetra> > ( dataFile, meshPart.meshPartition(), "structure", parameters->comm->MyPID() ) );
352  }
353  }
354 
355  exporter->setPostDir ( "./" );
356  exporter->setMeshProcId ( meshPart.meshPartition(), parameters->comm->MyPID() );
357 
358  vectorPtr_Type interpolatedF ( new vector_Type ( solid.map() ) );
359  vectorPtr_Type solutionLinearSystem ( new vector_Type ( solid.map() ) );
360  vectorPtr_Type bodyForcePointer ( new vector_Type ( solid.map() ) );
361  vectorPtr_Type scalarProduct ( new vector_Type ( solid.map() ) );
362 
363  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "scalarProduct", dFESpace, scalarProduct, UInt (0) );
364  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "solution", dFESpace, solutionLinearSystem, UInt (0) );
365  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "assembledBodyForce", dFESpace, bodyForcePointer, UInt (0) );
366 
367  exporter->postProcess ( 0 );
368  std::cout.precision(16);
369 
370  // Interpolating the function and multiplying by the mass matrix
371  dFESpace->interpolate ( static_cast< FESpace<RegionMesh<LinearTetra> , MapEpetra>::function_Type> ( Private::lifeVedF ), *interpolatedF, 0.0);
372  *solutionLinearSystem = *( solid.massMatrix( ) ) * (*interpolatedF);
373 
374  // getting the vector from the expression template assembling
375  *bodyForcePointer = solid.bodyForce();
376 
377  // computing the scalar product f \phi_i
378  dFESpace->l2ScalarProduct( static_cast< FESpace<RegionMesh<LinearTetra> , MapEpetra>::function_Type> ( Private::lifeVedF ), *scalarProduct, 0.0);
379 
380 
381  // Exporting the solution and the interpolation
382  exporter->postProcess ( 1.0 );
383  //!--------------------------------------------------------------------------------------------------
384 
385  MPI_Barrier (MPI_COMM_WORLD);
386 }
387 
388 
389 int
390 main ( int argc, char** argv )
391 {
392 
393 #ifdef HAVE_MPI
394  MPI_Init (&argc, &argv);
395  std::shared_ptr<Epetra_MpiComm> Comm (new Epetra_MpiComm ( MPI_COMM_WORLD ) );
396  if ( Comm->MyPID() == 0 )
397  {
398  std::cout << "% using MPI" << std::endl;
399  }
400 #else
401  std::shared_ptr<Epetra_SerialComm> Comm ( new Epetra_SerialComm() );
402  std::cout << "% using serial Version" << std::endl;
403 #endif
404 
405  Structure structure ( argc, argv, Comm );
406  structure.run();
407 
408 #ifdef HAVE_MPI
409  MPI_Finalize();
410 #endif
411  return EXIT_SUCCESS ;
412 }
StructuralOperator< RegionMesh< LinearTetra > >::matrix_Type matrix_Type
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)
std::function< VectorSmall< 3 > Real const &, Real const &, Real const &, Real const &) > bodyFunction_Type
int main(int argc, char **argv)
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
std::shared_ptr< hdf5Filter_Type > hdf5FilterPtr_Type
FESpace< RegionMesh< LinearTetra >, MapEpetra > solidFESpace_Type
std::shared_ptr< analyticalFunction_Type > analyticalFunctionPtr_Type
#define ERROR_MSG(A)
Definition: LifeAssert.hpp:69
Real & operator[](UInt const &i)
Operator [].
void run3d()
run the 3D driven cylinder simulation
uint32_type ID
IDs.
Definition: LifeV.hpp:194
ETFESpace< RegionMesh< LinearTetra >, MapEpetra, 3, 3 > solidETFESpace_Type
void run2d()
run the 2D driven cylinder simulation
StructuralOperator< RegionMesh< LinearTetra > >::matrixPtr_Type matrixPtr_Type
MeshData - class for handling spatial discretization.
Definition: MeshData.hpp:72
std::shared_ptr< bodyFunction_Type > bodyFunctionPtr_Type
std::shared_ptr< vector_Type > vectorPtr_Type
double Real
Generic real data.
Definition: LifeV.hpp:175
static VectorSmall< 3 > f(const Real &t, const Real &x, const Real &y, const Real &z)
std::set< UInt > parseList(const std::string &list)
std::shared_ptr< solidETFESpace_Type > solidETFESpacePtr_Type
static Real lifeVedF(const Real &t, const Real &x, const Real &y, const Real &z, const ID &i)
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > analyticalFunction_Type
std::vector< vectorPtr_Type > listOfFiberDirections_Type
bool operator()(const char *VarName, bool Default) const
Definition: GetPot.hpp:2008
StructuralOperator< RegionMesh< LinearTetra > >::vector_Type vector_Type
std::shared_ptr< solidFESpace_Type > solidFESpacePtr_Type
std::shared_ptr< vectorFiberFunction_Type > vectorFiberFunctionPtr_Type
std::vector< fiberFunctionPtr_Type > vectorFiberFunction_Type