LifeV
lifev/structure/examples/example_anisotropicTraction/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 
64 #include <lifev/core/fem/TimeAdvance.hpp>
65 #include <lifev/core/fem/TimeAdvanceBDF.hpp>
66 
67 #include <lifev/core/mesh/MeshData.hpp>
68 #include <lifev/core/mesh/MeshPartitioner.hpp>
69 #include <lifev/core/filter/PartitionIO.hpp>
70 
71 #include <lifev/structure/solver/StructuralConstitutiveLawData.hpp>
72 
73 #include <lifev/structure/solver/StructuralConstitutiveLaw.hpp>
74 #include <lifev/structure/solver/StructuralOperator.hpp>
75 #include <lifev/structure/solver/isotropic/VenantKirchhoffMaterialLinear.hpp>
76 #include <lifev/structure/solver/isotropic/VenantKirchhoffMaterialNonLinearPenalized.hpp>
77 #include <lifev/structure/solver/isotropic/ExponentialMaterialNonLinear.hpp>
78 #include <lifev/structure/solver/isotropic/NeoHookeanMaterialNonLinear.hpp>
79 #include <lifev/structure/solver/isotropic/SecondOrderExponentialMaterialNonLinear.hpp>
80 
81 #include <lifev/structure/solver/anisotropic/StructuralAnisotropicConstitutiveLaw.hpp>
82 #include <lifev/structure/solver/anisotropic/HolzapfelMaterialNonLinear.hpp>
83 #include <lifev/structure/solver/anisotropic/HolzapfelGeneralizedMaterialNonLinear.hpp>
84 
85 
86 #include <lifev/core/filter/ExporterEnsight.hpp>
87 #ifdef HAVE_HDF5
88 #include <lifev/core/filter/ExporterHDF5.hpp>
89 #endif
90 #include <lifev/core/filter/ExporterEmpty.hpp>
91 
92 //Includes for the Expression Template
93 #include <lifev/eta/fem/ETFESpace.hpp>
94 
95 #include <iostream>
96 #include <fstream>
97 
98 #include "ud_functions.hpp"
99 
100 
101 using namespace LifeV;
102 
103 int returnValue = EXIT_FAILURE;
105 
106 namespace
107 {
108 static bool regIF = (PRECFactory::instance().registerProduct ( "Ifpack", &createIfpack ) );
109 static bool regML = (PRECFactory::instance().registerProduct ( "ML", &createML ) );
110 }
111 
112 
114 {
115  std::string stringList = list;
116  std::set<UInt> setList;
117  if ( list == "" )
118  {
119  return setList;
120  }
121  size_t commaPos = 0;
122  while ( commaPos != std::string::npos )
123  {
124  commaPos = stringList.find ( "," );
125  setList.insert ( atoi ( stringList.substr ( 0, commaPos ).c_str() ) );
126  stringList = stringList.substr ( commaPos + 1 );
127  }
128  setList.insert ( atoi ( stringList.c_str() ) );
129  return setList;
130 }
131 
132 
134 {
135 public:
136 
137 
138  // Public typedefs
145 
148 
149  // typedefs for fibers
150  // std function for fiber direction
151  typedef std::function<Real ( Real const&, Real const&, Real const&, Real const&, ID const& ) > fiberFunction_Type;
153 
156 
158 
159  typedef std::function<Real ( Real const&, Real const&, Real const&, Real const&, ID const& ) > fct_type;
160  //Exporters Typedefs
161  typedef LifeV::Exporter<mesh_Type > filter_Type;
163 
164 
165  typedef LifeV::ExporterEmpty<mesh_Type > emptyExporter_Type;
167 
168  typedef LifeV::ExporterEnsight<mesh_Type > ensightFilter_Type;
170 
171 #ifdef HAVE_HDF5
174 #endif
175 
176  /** @name Constructors, destructor
177  */
178  //@{
179  Structure ( int argc,
180  char** argv,
181  std::shared_ptr<Epetra_Comm> structComm );
182 
184  {}
185  //@}
186 
187  //@{
188  void run()
189  {
190  run3d();
191  }
192  //@}
193 
194 protected:
195 
196 private:
197 
198  /**
199  * run the 2D driven cylinder simulation
200  */
201  void run2d();
202 
203  /**
204  * run the 3D driven cylinder simulation
205  */
206  void run3d();
207 
208 private:
209  struct Private;
213 
214  //filterPtr_Type checkExporter;
215 
216 };
217 
218 
219 
221 {
223  rho (1), poisson (1), young (1), bulk (1), alpha (1), gamma (1)
224  {}
226 
228 
230 
231  static Real bcZero (const Real& /*t*/, const Real& /*X*/, const Real& /*Y*/, const Real& /*Z*/, const ID& /*i*/)
232  {
233  return 0.;
234  }
235 
236  static Real bcNonZero (const Real& /*t*/, const Real& /*X*/, const Real& /*Y*/, const Real& /*Z*/, const ID& /*i*/)
237  {
238  return 20000;
239  }
240 
241  static Real bcPressure (const Real& t, const Real& x, const Real& y, const Real& /*Z*/, const ID& i)
242  {
243  Real radius = 0.5;
244  Real pressure = 20000;
245 
246  if ( t >= 0.0 )
247  {
248  switch (i)
249  {
250  case 0:
251  return pressure * ( y / radius );
252  break;
253  case 1:
254  return pressure * ( x / radius );
255  break;
256  case 2:
257  return 0.0;
258  break;
259  }
260  }
261 
262  return 0;
263 
264  }
265 
266  static Real smoothPressure (const Real& t, const Real& x, const Real& y, const Real& /*Z*/, const ID& i)
267  {
268  Real radius = std::sqrt ( x * x + y * y );
269  Real pressure ( 0 );
270  Real highestPressure ( 199950 );
271  Real totalTime = 4.5;
272  Real halfTime = totalTime / 2.0;
273 
274  Real a = ( highestPressure / 2 ) * ( 1 / ( halfTime * halfTime ) );
275 
276  if ( t <= halfTime )
277  {
278  pressure = a * t * t;
279  }
280 
281  if ( t > halfTime )
282  {
283  pressure = - a * (t - totalTime) * (t - totalTime) + highestPressure;
284  }
285 
286  switch (i)
287  {
288  case 0:
289  return pressure * ( x / radius ) ;
290  break;
291  case 1:
292  return pressure * ( y / radius ) ;
293  break;
294  case 2:
295  return 0.0;
296  break;
297 
298  }
299  return 0;
300 
301  }
302 
303  static Real mergingPressures (const Real& t, const Real& x, const Real& y, const Real& /*Z*/, const ID& i)
304  {
305  Real radius = std::sqrt ( x * x + y * y );
306  Real pressure ( 0 );
307 
308  Real highestPressure ( 199950 );
309 
310  Real totalTime = 9.0;
311  Real halfTime = totalTime / 2.0;
312  Real quarterTime = halfTime / 2.0;
313 
314  Real aA = ( highestPressure / 2 ) * ( 1 / ( quarterTime * quarterTime ) );
315  Real aD = ( 2 * highestPressure ) * ( 1 / ( halfTime * halfTime ) );
316 
317  if ( t <= quarterTime )
318  {
319  pressure = aA * t * t;
320  }
321 
322  if ( t > quarterTime && t <= halfTime )
323  {
324  pressure = - aA * (t - halfTime) * (t - halfTime) + highestPressure;
325  }
326 
327  if ( t > halfTime && t <= 3 * quarterTime )
328  {
329  pressure = - aD * (t - halfTime) * (t - halfTime) + highestPressure;
330  }
331 
332  if ( t > 3 * quarterTime && t <= 4 * quarterTime )
333  {
334  pressure = aD * (t - totalTime) * (t - totalTime);
335  }
336 
337  switch (i)
338  {
339  case 0:
340  return pressure * ( x / radius ) ;
341  break;
342  case 1:
343  return pressure * ( y / radius ) ;
344  break;
345  case 2:
346  return 0.0;
347  break;
348 
349  }
350  return 0;
351 
352  }
353 
354  static Real pressureUsingNormal (const Real& t, const Real& /*X*/, const Real& /*Y*/, const Real& /*Z*/, const ID& /*i*/)
355  {
356 
357  return -5000;
358  // if( t < 15.0 )
359  // return -(300000/(2*3.1415962*0.5*40))*(1/15)*t;
360  // else
361  // return -300000/(2*3.1415962*0.5*40);
362  }
363 
364 };
365 
366 
367 
368 Structure::Structure ( int argc,
369  char** argv,
370  std::shared_ptr<Epetra_Comm> structComm) :
371  parameters ( new Private() )
372 {
373  GetPot command_line (argc, argv);
374  std::string data_file_name = command_line.follow ("data", 2, "-f", "--file");
375  GetPot dataFile ( data_file_name );
376  parameters->data_file_name = data_file_name;
377 
378  parameters->comm = structComm;
379  int ntasks = parameters->comm->NumProc();
380 
381  if (!parameters->comm->MyPID() )
382  {
383  std::cout << "My PID = " << parameters->comm->MyPID() << " out of " << ntasks << " running." << std::endl;
384  }
385 }
386 
387 
388 
389 void
391 {
392  std::cout << "2D cylinder test case is not available yet\n";
393 }
394 
395 
396 
397 void
399 {
400  bool verbose = (parameters->comm->MyPID() == 0);
401 
402  //! Number of boundary conditions for the velocity and mesh motion
403  std::shared_ptr<BCHandler> BCh ( new BCHandler() );
404 
405  //! dataElasticStructure
406  GetPot dataFile ( parameters->data_file_name.c_str() );
407 
408  std::shared_ptr<StructuralConstitutiveLawData> dataStructure (new StructuralConstitutiveLawData( ) );
409  dataStructure->setup (dataFile);
410 
411  //dataStructure->showMe();
412 
413  //Loading a partitoned mesh or reading a new one
414  const std::string partitioningMesh = dataFile ( "partitioningOffline/loadMesh", "no");
415 
416  //Creation of pointers
417  std::shared_ptr<MeshPartitioner<mesh_Type> > meshPart;
418  std::shared_ptr<mesh_Type> pointerToMesh;
419 
420  if ( ! (partitioningMesh.compare ("no") ) )
421  {
422  std::shared_ptr<mesh_Type > fullMeshPtr (new mesh_Type ( ( parameters->comm ) ) );
423  //Creating a new mesh from scratch
424  MeshData meshData;
425  meshData.setup (dataFile, "solid/space_discretization");
426  readMesh (*fullMeshPtr, meshData);
427 
428  meshPart.reset ( new MeshPartitioner<mesh_Type> (fullMeshPtr, parameters->comm ) );
429 
430  pointerToMesh = meshPart->meshPartition();
431  }
432  else
433  {
434  //Creating a mesh object from a partitioned mesh
435  const std::string partsFileName (dataFile ("partitioningOffline/hdf5_file_name", "NO_DEFAULT_VALUE.h5") );
436 
437 
438  std::shared_ptr<Epetra_MpiComm> mpiComm =
439  std::dynamic_pointer_cast<Epetra_MpiComm> (parameters->comm);
440 
441  PartitionIO<mesh_Type> partitionIO (partsFileName, mpiComm);
442 
443 
444  partitionIO.read (pointerToMesh);
445 
446  }
447 
448  std::string dOrder = dataFile ( "solid/space_discretization/order", "P1");
449 
450  //Mainly used for BCs assembling (Neumann type)
451  solidFESpacePtr_Type dFESpace ( new solidFESpace_Type (pointerToMesh, dOrder, 3, parameters->comm) );
452  solidFESpacePtr_Type dScalarFESpace ( new solidFESpace_Type (pointerToMesh, dOrder, 1, parameters->comm) );
453  solidETFESpacePtr_Type dETFESpace ( new solidETFESpace_Type (pointerToMesh, & (dFESpace->refFE() ), & (dFESpace->fe().geoMap() ), parameters->comm) );
454 
455  // Setting the fibers
456  vectorFiberFunctionPtr_Type pointerToVectorOfFamilies( new vectorFiberFunction_Type( ) );
457  (*pointerToVectorOfFamilies).resize( dataStructure->numberFibersFamilies( ) );
458 
459  listOfFiberDirections_Type fiberDirections;
460  fiberDirections.resize( dataStructure->numberFibersFamilies( ) );
461 
462  if( verbose )
463  std::cout << "Size of the number of families: " << (*pointerToVectorOfFamilies).size() << std::endl;
464 
465  fibersDirectionList setOfFiberFunctions;
466  setOfFiberFunctions.setupFiberDefinitions( dataStructure->numberFibersFamilies( ) );
467 
468  if (verbose)
469  {
470  std::cout << std::endl;
471  }
472 
473  std::string timeAdvanceMethod = dataFile ( "solid/time_discretization/method", "BDF");
474 
475  timeAdvance_Type timeAdvance ( TimeAdvanceFactory::instance().createObject ( timeAdvanceMethod ) );
476 
477  UInt OrderDev = 2;
478 
479  timeAdvance->setup (dataStructure->dataTimeAdvance()->orderBDF() , OrderDev);
480 
481  timeAdvance->setTimeStep (dataStructure->dataTime()->timeStep() );
482  //timeAdvance->showMe();
483 
484  //! #################################################################################
485  //! BOUNDARY CONDITIONS
486  //! #################################################################################
487  std::vector <ID> compx (1), compy (1), compz (1), compxy (2), compxz (2), compyz (2);
488  compx[0] = 0;
489  compy[0] = 1, compz[0] = 2;
490  compxy[0] = 0;
491  compxy[1] = 1;
492  compxz[0] = 0;
493  compxz[1] = 2;
494  compyz[0] = 1;
495  compyz[1] = 2;
496 
497  BCFunctionBase zero (bcZero);
498  BCFunctionBase nonZero;
499  BCFunctionBase pressure;
500 
501  nonZero.setFunction (bcNonZero);
502  pressure.setFunction (smoothPressure);
503 
504  //! =================================================================================
505  //! BC - traction -
506  //! =================================================================================
507  BCh->addBC ("EdgesIn", 20, Natural, Component, nonZero, compy);
508  BCh->addBC ("EdgesIn", 40, Essential, Component, zero, compy);
509 
510  //! Symmetry BC
511  BCh->addBC ("EdgesIn", 50, EssentialVertices, Component, zero, compxy);
512  BCh->addBC ("EdgesIn", 30, EssentialVertices, Component, zero, compyz);
513  BCh->addBC ("EdgesIn", 80, EssentialVertices, Component, zero, compxz);
514  BCh->addBC ("EdgesIn", 100, EssentialVertices, Full, zero, 3);
515 
516  BCh->addBC ("EdgesIn", 7, Essential, Component , zero, compx);
517  BCh->addBC ("EdgesIn", 3, Essential, Component , zero, compz);
518  //! =================================================================================
519 
520  //! =================================================================================
521  //! BC - shear -
522  //! =================================================================================
523  // BCh->addBC ("EdgesIn", 20, Natural, Component, nonZero, compz);
524  // BCh->addBC ("EdgesIn", 20, Essential, Component, zero, compxy);
525 
526  //! Symmetry BC
527  // BCh->addBC ("EdgesIn", 50, EssentialVertices, Component, zero, compxz);
528  // BCh->addBC ("EdgesIn", 30, EssentialVertices, Component, zero, compxz);
529  // BCh->addBC ("EdgesIn", 80, EssentialVertices, Component, zero, compxz);
530 
531  // BCh->addBC ("EdgesIn", 40, Essential, Full , zero, 3);
532  //! =================================================================================
533 
534 
535  // Case of a tube
536  //Condition for Inflation
537  // BCh->addBC ("EdgesIn", 200, Natural, Full, pressure, 3);
538  // BCh->addBC ("EdgesIn", 40, Natural, Full, zero, 3);
539  // BCh->addBC ("EdgesIn", 70, Essential, Full, zero, 3);
540  // BCh->addBC ("EdgesIn", 60, Essential, Full, zero, 3);
541 
542  //! 1. Constructor of the structuralSolver
543  StructuralOperator< RegionMesh<LinearTetra> > solid;
544 
545  //! 2. Setup of the structuralSolver
546  solid.setup (dataStructure,
547  dFESpace,
548  dETFESpace,
549  BCh,
550  parameters->comm);
551 
552  //! 3. Setting data from getPot
553  solid.setDataFromGetPot (dataFile);
554 
555  // Setting the vector of fibers functions
556  for( UInt k(1); k <= pointerToVectorOfFamilies->size( ); k++ )
557  {
558  // Setting up the name of the function to define the family
559  std::string family="Family";
560  // adding the number of the family
561  std::string familyNumber;
562  std::ostringstream number;
563  number << ( k );
564  familyNumber = number.str();
565 
566  // Name of the function to create
567  std::string creationString = family + familyNumber;
568  (*pointerToVectorOfFamilies)[ k-1 ].reset( new fiberFunction_Type() );
569  (*pointerToVectorOfFamilies)[ k-1 ] = setOfFiberFunctions.fiberDefinition( creationString );
570 
571  fiberDirections[ k-1 ].reset( new vector_Type(solid.displacement(), Unique) );
572  }
573  vectorPtr_Type thetaSection;
574  thetaSection.reset( new vector_Type( dScalarFESpace->map() ) );
575  vectorPtr_Type thetaRotation;
576  thetaRotation.reset( new vector_Type( dScalarFESpace->map() ) );
577 
578  vectorPtr_Type positionCenterVector;
579  positionCenterVector.reset( new vector_Type( dFESpace->map() ) );
580 
581  vectorPtr_Type localPositionVector;
582  localPositionVector.reset( new vector_Type( dFESpace->map() ) );
583 
584  //! 3.b Setting the fibers in the abstract class of Anisotropic materials
585  if( !dataStructure->constitutiveLaw().compare("anisotropic") )
586  solid.material()->anisotropicLaw()->setupFiberDirections( pointerToVectorOfFamilies );
587 
588  //! 4. Building system using TimeAdvance class
589  double timeAdvanceCoefficient = timeAdvance->coefficientSecondDerivative ( 0 ) / (dataStructure->dataTime()->timeStep() * dataStructure->dataTime()->timeStep() );
590  solid.buildSystem (timeAdvanceCoefficient);
591 
592 
593  //dataStructure->showMe();
594  //! =================================================================================
595  //! Temporal data and initial conditions
596  //! =================================================================================
597 
598  vectorPtr_Type rhs (new vector_Type (solid.displacement(), Unique) );
599  vectorPtr_Type disp (new vector_Type (solid.displacement(), Unique) );
600  vectorPtr_Type vel (new vector_Type (solid.displacement(), Unique) );
601  vectorPtr_Type acc (new vector_Type (solid.displacement(), Unique) );
602 
603  if (verbose)
604  {
605  std::cout << "S- initialization ... ";
606  }
607 
608  // Initialization
609  //Initialization of TimeAdvance
610  std::string const restart = dataFile ( "importer/restart", "none");
611  std::vector<vectorPtr_Type> solutionStencil;
612  solutionStencil.resize ( timeAdvance->size() );
613 
614  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > importerSolid;
615 
616  if ( restart.compare ( "none" ) )
617  {
618  //Reading fileNames - setting data for reading
619  std::string const importerType = dataFile ( "importer/type", "ensight");
620  std::string const fileName = dataFile ( "importer/filename", "structure");
621  std::string const initialLoaded = dataFile ( "importer/initialSol", "NO_DEFAULT_VALUE");
622  //LifeV::Real initialTime = dataFile ( "importer/initialTime", 0.0);
623 
624  //Creating the importer
625 #ifdef HAVE_HDF5
626  if ( !importerType.compare ("hdf5") )
627  {
628  importerSolid.reset ( new hdf5Filter_Type ( dataFile, fileName) );
629  }
630  else
631 #endif
632  {
633  if ( !importerType.compare ("none") )
634  {
635  importerSolid.reset ( new emptyExporter_Type ( dataFile, dFESpace->mesh(), "solid", dFESpace->map().comm().MyPID() ) );
636  }
637  else
638  {
639  importerSolid.reset ( new ensightFilter_Type ( dataFile, fileName) );
640  }
641  }
642 
643  importerSolid->setMeshProcId (dFESpace->mesh(), dFESpace->map().comm().MyPID() );
644 
645  //Creation of Exporter to check the loaded solution (working only for HDF5)
646  // std::string expVerFile = "verificationDisplExporter";
647  // LifeV::ExporterHDF5<RegionMesh<LinearTetra> > exporter( dataFile, pointerToMesh, expVerFile, parameters->comm->MyPID());
648  // vectorPtr_Type vectVer ( new vector_Type(solid.displacement(), LifeV::Unique ) );
649 
650  // exporter.addVariable( ExporterData<mesh_Type >::VectorField, "displVer", dFESpace, vectVer, UInt(0) );
651 
652  // exporter.postProcess(0.0);
653 
654  //Reading the displacement field and the timesteps need by the TimeAdvance class
655  vectorPtr_Type solidDisp (new vector_Type (dFESpace->map(), importerSolid->mapType() ) );
656 
657  std::string iterationString;
658 
659  // if( verbose )
660  // std::cout << "size TimeAdvance:" << timeAdvance->size() << std::endl;
661 
662  //Loading the stencil
663  iterationString = initialLoaded;
664  for (UInt iterInit = 0; iterInit < timeAdvance->size(); iterInit++ )
665  {
666  // if( verbose )
667  // std::cout << "new iterationString" << iterationString << std::endl;
668 
669  solidDisp.reset ( new vector_Type (solid.displacement(), Unique ) );
670  *solidDisp *= 0.0;
671 
672  LifeV::ExporterData<mesh_Type> solidDataReader (LifeV::ExporterData<mesh_Type>::VectorField, std::string ("displacement." + iterationString), dFESpace, solidDisp, UInt (0), LifeV::ExporterData<mesh_Type>::UnsteadyRegime );
673 
674  importerSolid->readVariable (solidDataReader);
675 
676  // if( verbose )
677  // std::cout << "Norm of the " << iterInit + 1 << "-th solution : " << solidDisp->norm2() << std::endl;
678 
679  //Exporting the just loaded solution (debug purposes)
680  // Real currentLoading(iterInit + 1.0);
681  // *vectVer = *solidDisp;
682  // exporter.postProcess( currentLoading );
683 
684  solutionStencil[ iterInit ] = solidDisp;
685 
686  //initializing the displacement field in the StructuralSolver class with the first solution
687  if ( !iterInit )
688  {
689  solid.initialize ( solidDisp );
690  }
691 
692  //Updating string name
693  int iterations = std::atoi (iterationString.c_str() );
694  iterations--;
695 
696  std::ostringstream iter;
697  iter.fill ( '0' );
698  iter << std::setw (5) << ( iterations );
699  iterationString = iter.str();
700 
701  }
702 
703  importerSolid->closeFile();
704 
705  //Putting the vector in the TimeAdvance Stencil
706  timeAdvance->setInitialCondition (solutionStencil);
707 
708  }
709  else //Initialize with zero vectors
710  {
711 
712  // if( verbose )
713  // std::cout << "Starting from scratch" << std::endl;
714 
715  vectorPtr_Type disp (new vector_Type (solid.displacement(), Unique) );
716 
717  for ( UInt previousPass = 0; previousPass < timeAdvance->size() ; previousPass++)
718  {
719  solutionStencil[ previousPass ] = disp;
720  }
721 
722  timeAdvance->setInitialCondition (solutionStencil);
723 
724  //It is automatically done actually. It's clearer if specified.
725  solid.initialize ( disp );
726  }
727 
728 
729  timeAdvance->setTimeStep ( dataStructure->dataTime()->timeStep() );
730 
731  timeAdvance->updateRHSContribution ( dataStructure->dataTime()->timeStep() );
732 
733  MPI_Barrier (MPI_COMM_WORLD);
734 
735  if (verbose )
736  {
737  std::cout << "ok." << std::endl;
738  }
739 
740  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporterSolid;
741 
742  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporterCheck;
743 
744 
745  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporter;
746 
747  std::string const exporterType = dataFile ( "exporter/type", "ensight");
748  std::string const exportFileName = dataFile ( "exporter/nameFile", "structure");
749 #ifdef HAVE_HDF5
750  if (exporterType.compare ("hdf5") == 0)
751  {
752  exporter.reset ( new ExporterHDF5<RegionMesh<LinearTetra> > ( dataFile, exportFileName ) );
753  }
754  else
755 #endif
756  {
757  if (exporterType.compare ("none") == 0)
758  {
759  exporter.reset ( new ExporterEmpty<RegionMesh<LinearTetra> > ( dataFile, pointerToMesh, exportFileName, parameters->comm->MyPID() ) );
760  }
761 
762  else
763  {
764  exporter.reset ( new ExporterEnsight<RegionMesh<LinearTetra> > ( dataFile, pointerToMesh, exportFileName, parameters->comm->MyPID() ) );
765  }
766  }
767 
768  exporter->setPostDir ( "./" );
769  exporter->setMeshProcId ( pointerToMesh, parameters->comm->MyPID() );
770 
771  vectorPtr_Type solidDisp ( new vector_Type (solid.displacement(), exporter->mapType() ) );
772  vectorPtr_Type solidVel ( new vector_Type (solid.displacement(), exporter->mapType() ) );
773  vectorPtr_Type solidAcc ( new vector_Type (solid.displacement(), exporter->mapType() ) );
774  vectorPtr_Type rhsVector ( new vector_Type (solid.displacement(), exporter->mapType() ) );
775 
776  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "displacement", dFESpace, solidDisp, UInt (0) );
777  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "velocity", dFESpace, solidVel, UInt (0) );
778  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "acceleration", dFESpace, solidAcc, UInt (0) );
779  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "forcingTerm", dFESpace, rhsVector, UInt (0) );
780 
781  if( !dataStructure->constitutiveLaw().compare("anisotropic") )
782  {
783  // Adding the fibers vectors
784  // Setting the vector of fibers functions
785  for( UInt k(1); k <= pointerToVectorOfFamilies->size( ); k++ )
786  {
787  // Setting up the name of the function to define the family
788  std::string family="Family-";
789  // adding the number of the family
790  std::string familyNumber;
791  std::ostringstream number;
792  number << ( k );
793  familyNumber = number.str();
794 
795  // Name of the function to create
796  std::string creationString = family + familyNumber;
797  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, creationString, dFESpace, fiberDirections[ k-1 ], UInt (0) );
798 
799  // Extracting the fibers vectors
800  *(fiberDirections[ k-1 ]) = solid.material()->anisotropicLaw()->ithFiberVector( k );
801  }
802  }
803 
804  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::ScalarField, "thetaSection", dScalarFESpace, thetaSection, UInt (0) );
805  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::ScalarField, "thetaRotation", dScalarFESpace, thetaRotation, UInt (0) );
806  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "positionCenter", dFESpace, positionCenterVector, UInt (0) );
807  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "localPosition", dFESpace, localPositionVector, UInt (0) );
808 
809  dScalarFESpace->interpolate ( static_cast<solidFESpace_Type::function_Type>( thetaFunction ),
810  *thetaSection,
811  0.0 );
812 
813  dScalarFESpace->interpolate ( static_cast<solidFESpace_Type::function_Type>( thetaRotationFunction ),
814  *thetaRotation,
815  0.0 );
816 
817  dFESpace->interpolate ( static_cast<solidFESpace_Type::function_Type>( positionCenter ),
818  *positionCenterVector,
819  0.0 );
820 
821  dFESpace->interpolate ( static_cast<solidFESpace_Type::function_Type>( localPosition ),
822  *localPositionVector,
823  0.0 );
824 
825  exporter->postProcess ( dataStructure->dataTime()->initialTime() );
826  std::cout.precision(16);
827 
828  int IDPoint = 157;// cube8x8.mesh
829 
830  //! 5. Initial data
831  Real initialTime = dataStructure->dataTime()->initialTime();
832  Real dt = dataStructure->dataTime()->timeStep();
833  Real T = dataStructure->dataTime()->endTime();
834 
835  //! 6. Setting the pillow saving for restart
836  UInt tol = dataStructure->dataTimeAdvance()->orderBDF() + 1;
837  UInt saveEvery = dataFile( "exporter/saveEvery", 1);
838  UInt r(0);
839  UInt d(0);
840  UInt iter(0);
841 
842  //! =============================================================================
843  //! Temporal loop
844  //! =============================================================================
845  // for (Real time = dt; time <= T; time += dt)
846  for (Real time = initialTime + dt; time <= T; time += dt)
847  {
848  dataStructure->dataTime()->setTime( time );
849 
850  if (verbose)
851  {
852  std::cout << std::endl;
853  std::cout << "S- Now we are at time " << dataStructure->dataTime()->time() << " s." << std::endl;
854  }
855 
856  //! 6. Updating right-hand side
857  *rhs *= 0;
858  timeAdvance->updateRHSContribution ( dt );
859  *rhs += *solid.massMatrix() * timeAdvance->rhsContributionSecondDerivative() / timeAdvanceCoefficient;
860  solid.setRightHandSide ( *rhs );
861 
862  //! 7. Iterate --> Calling Newton
863  solid.iterate ( BCh );
864 
865  timeAdvance->shiftRight ( solid.displacement() );
866 
867  *solidDisp = solid.displacement();
868  *solidVel = timeAdvance->firstDerivative();
869  *solidAcc = timeAdvance->secondDerivative();
870 
871  // This vector is to export the forcing term
872  *rhsVector = solid.rhsCopy();
873 
874  iter = iter + 1;
875 
876  r = iter % saveEvery;
877  d = iter - r;
878 
879  std::cout << "First component displacement at ID = "<< IDPoint << ": " << solid.displacement()[ IDPoint - 1 ] << std::endl;
880  std::cout << "Second component displacement at ID = "<< IDPoint << ": " <<
881  solid.displacement()[ IDPoint - 1 + dFESpace->dof().numTotalDof() ] << std::endl;
882  std::cout << "Third component displacement at ID = "<< IDPoint << ": " <<
883  solid.displacement()[ IDPoint - 1 + 2 * dFESpace->dof().numTotalDof() ] << std::endl;
884 
885 
886  if ( (iter - d) <= tol || ( (std::floor(d/saveEvery) + 1)*saveEvery - iter ) <= tol )
887  {
888  exporter->postProcess( time );
889  }
890  }
891 
892  //!--------------------------------------------------------------------------------------------------
893 
894  MPI_Barrier (MPI_COMM_WORLD);
895 }
896 
897 
898 int
899 main ( int argc, char** argv )
900 {
901 
902 #ifdef HAVE_MPI
903  MPI_Init (&argc, &argv);
904  std::shared_ptr<Epetra_MpiComm> Comm (new Epetra_MpiComm ( MPI_COMM_WORLD ) );
905  if ( Comm->MyPID() == 0 )
906  {
907  std::cout << "% using MPI" << std::endl;
908  }
909 #else
910  std::shared_ptr<Epetra_SerialComm> Comm ( new Epetra_SerialComm() );
911  std::cout << "% using serial Version" << std::endl;
912 #endif
913 
914  Structure structure ( argc, argv, Comm );
915  structure.run();
916 
917 #ifdef HAVE_MPI
918  MPI_Finalize();
919 #endif
920  return returnValue ;
921 }
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)
int main(int argc, char **argv)
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
static Real mergingPressures(const Real &t, const Real &x, const Real &y, const Real &, const ID &i)
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< fiberFunction_Type > fiberFunctionPtr_Type
std::shared_ptr< hdf5Filter_Type > hdf5FilterPtr_Type
FESpace< RegionMesh< LinearTetra >, MapEpetra > solidFESpace_Type
static Real bcZero(const Real &, const Real &, const Real &, const Real &, const ID &)
void run3d()
run the 3D driven cylinder simulation
uint32_type ID
IDs.
Definition: LifeV.hpp:194
ETFESpace< RegionMesh< LinearTetra >, MapEpetra, 3, 3 > solidETFESpace_Type
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
std::shared_ptr< vector_Type > vectorPtr_Type
double Real
Generic real data.
Definition: LifeV.hpp:175
static Real bcNonZero(const Real &, const Real &, const Real &, const Real &, const ID &)
std::shared_ptr< emptyExporter_Type > emptyExporterPtr_Type
static Real pressureUsingNormal(const Real &, const Real &, const Real &, const Real &, const ID &)
std::set< UInt > parseList(const std::string &list)
static Real bcPressure(const Real &, const Real &x, const Real &y, const Real &, const ID &i)
int operator()(const char *VarName, int Default) const
Definition: GetPot.hpp:2021
std::shared_ptr< solidETFESpace_Type > solidETFESpacePtr_Type
std::shared_ptr< LifeV::Exporter< mesh_Type > > filterPtr_Type
static Real smoothPressure(const Real &t, const Real &x, const Real &y, const Real &, const ID &i)
std::shared_ptr< TimeAdvance< vector_Type > > timeAdvance_Type
std::vector< vectorPtr_Type > listOfFiberDirections_Type
StructuralOperator< RegionMesh< LinearTetra > >::vector_Type vector_Type
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