LifeV
lifev/structure/examples/example_tractionWithSymmetry/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 Christophe Prud'homme <christophe.prudhomme@epfl.ch>
29  \date 2005-04-16
30  */
31 
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 #include <lifev/core/algorithm/PreconditionerIfpack.hpp>
54 #include <lifev/core/algorithm/PreconditionerML.hpp>
55 
56 
57 //Include fils which were in the structure.cpp file
58 #include <lifev/core/array/MapEpetra.hpp>
59 
60 #include <lifev/core/fem/TimeAdvance.hpp>
61 #include <lifev/core/fem/TimeAdvanceNewmark.hpp>
62 #include <lifev/core/fem/TimeAdvanceBDF.hpp>
63 
64 #include <lifev/core/mesh/MeshData.hpp>
65 #include <lifev/core/mesh/MeshPartitioner.hpp>
66 
67 #include <lifev/structure/solver/StructuralConstitutiveLawData.hpp>
68 
69 #include <lifev/structure/solver/StructuralConstitutiveLaw.hpp>
70 #include <lifev/structure/solver/StructuralOperator.hpp>
71 #include <lifev/structure/solver/VenantKirchhoffMaterialLinear.hpp>
72 #include <lifev/structure/solver/VenantKirchhoffMaterialNonLinear.hpp>
73 #include <lifev/structure/solver/VenantKirchhoffMaterialNonLinearPenalized.hpp>
74 #include <lifev/structure/solver/NeoHookeanMaterialNonLinear.hpp>
75 #include <lifev/structure/solver/ExponentialMaterialNonLinear.hpp>
76 #include <lifev/structure/solver/SecondOrderExponentialMaterialNonLinear.hpp>
77 
78 #include <lifev/core/filter/ExporterEnsight.hpp>
79 #ifdef HAVE_HDF5
80 #include <lifev/core/filter/ExporterHDF5.hpp>
81 #endif
82 #include <lifev/core/filter/ExporterEmpty.hpp>
83 
84 #include <iostream>
85 
86 
87 using namespace LifeV;
88 
89 int returnValue = EXIT_FAILURE;
91 
92 namespace
93 {
94 static bool regIF = (PRECFactory::instance().registerProduct ( "Ifpack", &createIfpack ) );
95 static bool regML = (PRECFactory::instance().registerProduct ( "ML", &createML ) );
96 }
97 
98 
100 {
101  std::string stringList = list;
102  std::set<UInt> setList;
103  if ( list == "" )
104  {
105  return setList;
106  }
107  size_t commaPos = 0;
108  while ( commaPos != std::string::npos )
109  {
110  commaPos = stringList.find ( "," );
111  setList.insert ( atoi ( stringList.substr ( 0, commaPos ).c_str() ) );
112  stringList = stringList.substr ( commaPos + 1 );
113  }
114  setList.insert ( atoi ( stringList.c_str() ) );
115  return setList;
116 }
117 
118 
119 class Structure
120 {
121 public:
122 
123  /** @name Constructors, destructor
124  */
125  //@{
126  Structure ( int argc,
127  char** argv,
128  std::shared_ptr<Epetra_Comm> structComm );
129 
131  {}
132  //@}
133 
134  //@{
135  void run()
136  {
137  run3d();
138  }
139  void CheckResultLE (const Real& dispNorm, const Real& time);
140  void CheckResultSVK (const Real& dispNorm, const Real& time);
141  void CheckResultEXP (const Real& dispNorm, const Real& time);
142  void CheckResultNH (const Real& dispNorm, const Real& time);
143  void resultChanged (Real time);
144  //@}
145 
146 protected:
147 
148 private:
149 
150  /**
151  * run the 2D driven cylinder simulation
152  */
153  void run2d();
154 
155  /**
156  * run the 3D driven cylinder simulation
157  */
158  void run3d();
159 
160 private:
161  struct Private;
163 };
164 
165 
166 
167 struct Structure::Private
168 {
170  rho (1), poisson (1), young (1), bulk (1), alpha (1), gamma (1)
171  {}
172  typedef std::function<Real ( Real const&, Real const&, Real const&, Real const&, ID const& ) > fct_type;
173  double rho, poisson, young, bulk, alpha, gamma;
174 
176 
178 
179  static Real bcZero (const Real& /*t*/, const Real& /*X*/, const Real& /*Y*/, const Real& /*Z*/, const ID& /*i*/)
180  {
181  return 0.;
182  }
183 
184  static Real bcNonZero (const Real& /*t*/, const Real& /*X*/, const Real& /*Y*/, const Real& /*Z*/, const ID& /*i*/)
185  {
186  return 70000; //136400.0
187  }
188 
189  static Real d0 (const Real& /*t*/, const Real& x, const Real& y, const Real& z, const ID& i)
190  {
191  switch (i)
192  {
193  case 0:
194  return - 0.058549 * ( x - 0.5 );
195  break;
196  case 1:
197  return ( 0.256942 / 2 ) * y;
198  break;
199  case 2:
200  return - 0.058549 * ( z + 0.5);
201  break;
202  default:
203  ERROR_MSG ("This entry is not allowed: ud_functions.hpp");
204  return 0.;
205  break;
206  }
207  }
208 
209 
210 };
211 
212 
213 
214 Structure::Structure ( int argc,
215  char** argv,
216  std::shared_ptr<Epetra_Comm> structComm) :
217  parameters ( new Private() )
218 {
219  GetPot command_line (argc, argv);
220  std::string data_file_name = command_line.follow ("data", 2, "-f", "--file");
221  GetPot dataFile ( data_file_name );
222  parameters->data_file_name = data_file_name;
223 
224  parameters->rho = dataFile ( "solid/physics/density", 1. );
225  parameters->young = dataFile ( "solid/physics/young", 1. );
226  parameters->poisson = dataFile ( "solid/physics/poisson", 1. );
227  parameters->bulk = dataFile ( "solid/physics/bulk", 1. );
228  parameters->alpha = dataFile ( "solid/physics/alpha", 1. );
229  parameters->gamma = dataFile ( "solid/physics/gamma", 1. );
230 
231  std::cout << "density = " << parameters->rho << std::endl
232  << "young = " << parameters->young << std::endl
233  << "poisson = " << parameters->poisson << std::endl
234  << "bulk = " << parameters->bulk << std::endl
235  << "alpha = " << parameters->alpha << std::endl
236  << "gamma = " << parameters->gamma << std::endl;
237 
238  parameters->comm = structComm;
239  int ntasks = parameters->comm->NumProc();
240 
241  if (!parameters->comm->MyPID() )
242  {
243  std::cout << "My PID = " << parameters->comm->MyPID() << " out of " << ntasks << " running." << std::endl;
244  }
245 }
246 
247 
248 
249 void
250 Structure::run2d()
251 {
252  std::cout << "2D cylinder test case is not available yet\n";
253 }
254 
255 
256 
257 void
258 Structure::run3d()
259 {
260  typedef StructuralOperator< RegionMesh<LinearTetra> >::vector_Type vector_Type;
261  typedef std::shared_ptr<vector_Type> vectorPtr_Type;
262  typedef std::shared_ptr< TimeAdvance< vector_Type > > timeAdvance_type;
263  typedef RegionMesh<LifeV::LinearTetra > mesh_Type;
264  typedef LifeV::ExporterEmpty<mesh_Type > emptyExporter_Type;
265  typedef std::shared_ptr<emptyExporter_Type> emptyExporterPtr_Type;
266 
267  typedef LifeV::ExporterEnsight<mesh_Type > ensightFilter_Type;
268  typedef std::shared_ptr<ensightFilter_Type> ensightFilterPtr_Type;
269 
270 #ifdef HAVE_HDF5
271  typedef LifeV::ExporterHDF5<mesh_Type > hdf5Filter_Type;
272  typedef std::shared_ptr<hdf5Filter_Type> hdf5FilterPtr_Type;
273 #endif
274 
275  bool verbose = (parameters->comm->MyPID() == 0);
276 
277  //! Number of boundary conditions for the velocity and mesh motion
278  std::shared_ptr<BCHandler> BCh ( new BCHandler() );
279 
280  //! dataElasticStructure
281  GetPot dataFile ( parameters->data_file_name.c_str() );
282 
283  std::shared_ptr<StructuralConstitutiveLawData> dataStructure (new StructuralConstitutiveLawData( ) );
284  dataStructure->setup (dataFile);
285 
286  MeshData meshData;
287  meshData.setup (dataFile, "solid/space_discretization");
288 
289  std::shared_ptr<RegionMesh<LinearTetra> > fullMeshPtr (new RegionMesh<LinearTetra> ( parameters->comm ) );
290  readMesh (*fullMeshPtr, meshData);
291 
292  MeshPartitioner< RegionMesh<LinearTetra> > meshPart ( fullMeshPtr, parameters->comm );
293 
294  std::string dOrder = dataFile ( "solid/space_discretization/order", "P1");
295 
296  typedef FESpace< RegionMesh<LinearTetra>, MapEpetra > solidFESpace_type;
297  typedef std::shared_ptr<solidFESpace_type> solidFESpace_ptrtype;
298 
299  typedef ETFESpace< RegionMesh<LinearTetra>, MapEpetra, 3, 3 > solidETFESpace_Type;
300  typedef std::shared_ptr<solidETFESpace_Type> solidETFESpacePtr_Type;
301 
302 
303  solidFESpace_ptrtype dFESpace ( new solidFESpace_type (meshPart, dOrder, 3, parameters->comm) );
304  solidETFESpacePtr_Type dETFESpace ( new solidETFESpace_Type (meshPart, & (dFESpace->refFE() ), & (dFESpace->fe().geoMap() ), parameters->comm) );
305  if (verbose)
306  {
307  std::cout << std::endl;
308  }
309 
310  std::string timeAdvanceMethod = dataFile ( "solid/time_discretization/method", "Newmark");
311 
312  std::cout << "Method: " << timeAdvanceMethod << std::endl;
313 
314  timeAdvance_type timeAdvance ( TimeAdvanceFactory::instance().createObject ( timeAdvanceMethod ) );
315 
316  UInt OrderDev = 2;
317 
318  //! initialization of parameters of time Advance method:
319  if (timeAdvanceMethod == "Newmark")
320  {
321  timeAdvance->setup ( dataStructure->dataTimeAdvance()->coefficientsNewmark() , OrderDev);
322  }
323 
324  if (timeAdvanceMethod == "BDF")
325  {
326  timeAdvance->setup (dataStructure->dataTimeAdvance()->orderBDF() , OrderDev);
327  }
328 
329  timeAdvance->setTimeStep (dataStructure->dataTime()->timeStep() );
330 
331  //! #################################################################################
332  //! BOUNDARY CONDITIONS
333  //! #################################################################################
334  std::vector <ID> compx (1), compy (1), compz (1), compxy (2), compxz (2), compyz (2);
335  compx[0] = 0;
336  compy[0] = 1, compz[0] = 2;
337  compxy[0] = 0;
338  compxy[1] = 1;
339  compxz[0] = 0;
340  compxz[1] = 2;
341  compyz[0] = 1;
342  compyz[1] = 2;
343 
344  BCFunctionBase zero (Private::bcZero);
345  BCFunctionBase nonZero (Private::bcNonZero);
346 
347  //! =================================================================================
348  //! BC for StructuredCube4_test_structuralsolver.mesh
349  //! =================================================================================
350  BCh->addBC ("EdgesIn", 20, Natural, Component, nonZero, compy);
351  BCh->addBC ("EdgesIn", 40, Essential, Component, zero, compy);
352 
353  BCh->addBC ("SymmetryX", 5, Essential, Component, zero, compx);
354  BCh->addBC ("SymmetryY", 3, Essential, Component, zero, compz);
355  BCh->addBC ("edgeone", 100, EssentialVertices, Full, zero, 3);
356  BCh->addBC ("edgetwo", 50, EssentialVertices, Component, zero, compxy);
357  BCh->addBC ("edgetwo", 30, EssentialVertices, Component, zero, compyz);
358  BCh->addBC ("edgetwo", 80, EssentialVertices, Component, zero, compxz);
359 
360 
361  //! 1. Constructor of the structuralSolver
362  StructuralOperator< RegionMesh<LinearTetra> > solid;
363 
364  //! 2. Setup of the structuralSolver
365  solid.setup (dataStructure,
366  dFESpace,
367  dETFESpace,
368  BCh,
369  parameters->comm);
370 
371  //! 3. Setting data from getPot
372  solid.setDataFromGetPot (dataFile);
373 
374  //! 4. Building system using TimeAdvance class
375  double timeAdvanceCoefficient = timeAdvance->coefficientSecondDerivative ( 0 ) / (dataStructure->dataTime()->timeStep() * dataStructure->dataTime()->timeStep() );
376  solid.buildSystem (timeAdvanceCoefficient);
377 
378 
379  dataStructure->showMe();
380  //! =================================================================================
381  //! Temporal data and initial conditions
382  //! =================================================================================
383 
384  //! 5. Initial data
385  Real dt = dataStructure->dataTime()->timeStep();
386  //Real T = dataStructure->dataTime()->endTime();
387 
388  vectorPtr_Type rhs (new vector_Type (solid.displacement(), Unique) );
389  vectorPtr_Type disp (new vector_Type (solid.displacement(), Unique) );
390  vectorPtr_Type vel (new vector_Type (solid.displacement(), Unique) );
391  vectorPtr_Type acc (new vector_Type (solid.displacement(), Unique) );
392 
393  //Initialization of TimeAdvance
394  std::string const restart = dataFile ( "importer/restart", "none");
395  std::vector<vectorPtr_Type> solutionStencil;
396  solutionStencil.resize ( timeAdvance->size() );
397 
398  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > importerSolid;
399  if ( restart.compare ( "none" ) )
400  {
401  //Reading fileNames - setting data for reading
402  std::string const importerType = dataFile ( "importer/type", "ensight");
403  std::string const fileName = dataFile ( "importer/filename", "structure");
404  std::string const initialLoaded = dataFile ( "importer/initialSol", "NO_DEFAULT_VALUE");
405  //LifeV::Real initialTime = dataFile ( "importer/initialTime", 0.0);
406 
407  //Creating the importer
408 #ifdef HAVE_HDF5
409  if ( !importerType.compare ("hdf5") )
410  {
411  importerSolid.reset ( new hdf5Filter_Type ( dataFile, fileName) );
412  }
413  else
414 #endif
415  {
416  if ( !importerType.compare ("none") )
417  {
418  importerSolid.reset ( new emptyExporter_Type ( dataFile, dFESpace->mesh(), "solid", dFESpace->map().comm().MyPID() ) );
419  }
420  else
421  {
422  importerSolid.reset ( new ensightFilter_Type ( dataFile, fileName) );
423  }
424  }
425 
426  importerSolid->setMeshProcId (dFESpace->mesh(), dFESpace->map().comm().MyPID() );
427 
428  //Creation of Exporter to check the loaded solution (working only for HDF5)
429  // std::string expVerFile = "verificationDisplExporter";
430  // LifeV::ExporterHDF5<RegionMesh<LinearTetra> > exporter( dataFile, meshPart.meshPartition(), expVerFile, parameters->comm->MyPID());
431  // vectorPtr_Type vectVer ( new vector_Type(solid.displacement(), LifeV::Unique ) );
432 
433  // exporter.addVariable( ExporterData<mesh_Type >::VectorField, "displVer", dFESpace, vectVer, UInt(0) );
434 
435  // exporter.postProcess(0.0);
436 
437  //Reading the displacement field and the timesteps need by the TimeAdvance class
438  vectorPtr_Type solidDisp (new vector_Type (dFESpace->map(), importerSolid->mapType() ) );
439 
440  std::string iterationString;
441 
442  std::cout << "size TimeAdvance:" << timeAdvance->size() << std::endl;
443 
444  //Loading the stencil
445  iterationString = initialLoaded;
446  for (UInt iterInit = 0; iterInit < timeAdvance->size(); iterInit++ )
447  {
448  solidDisp.reset (new vector_Type (dFESpace->map(), importerSolid->mapType() ) );
449  *solidDisp *= 0.0;
450 
451  LifeV::ExporterData<mesh_Type> solidDataReader (LifeV::ExporterData<mesh_Type>::VectorField, std::string ("displacement." + iterationString), dFESpace, solidDisp, UInt (0), LifeV::ExporterData<mesh_Type>::UnsteadyRegime );
452 
453  importerSolid->readVariable (solidDataReader);
454 
455  std::cout << "Norm of the " << iterInit + 1 << "-th solution : " << solidDisp->norm2() << std::endl;
456 
457  //Exporting the just loaded solution (debug purposes)
458  // Real currentLoading(iterInit + 1.0);
459  // *vectVer = *solidDisp;
460  // exporter.postProcess( currentLoading );
461 
462  //solutionStencil.push_back( solidDisp );
463  solutionStencil[ iterInit ] = solidDisp;
464  //initializing the displacement field in the StructuralSolver class with the first solution
465  if ( !iterInit )
466  {
467  solid.initialize ( solidDisp );
468  }
469 
470  //Updating string name
471  int iterations = std::atoi (iterationString.c_str() );
472  iterations--;
473 
474  std::ostringstream iter;
475  iter.fill ( '0' );
476  iter << std::setw (5) << ( iterations );
477  iterationString = iter.str();
478 
479  }
480 
481  importerSolid->closeFile();
482 
483  //Putting the vector in the TimeAdvance Stencil
484  timeAdvance->setInitialCondition (solutionStencil);
485  }
486  else
487  {
488  if (verbose)
489  {
490  std::cout << "S- initialization ... ";
491  }
492 
493  std::vector<vectorPtr_Type> uv0;
494 
495  if (timeAdvanceMethod == "Newmark")
496  {
497  uv0.push_back (disp);
498  uv0.push_back (vel);
499  uv0.push_back (acc);
500  }
501 
502  vectorPtr_Type initialDisplacement (new vector_Type (solid.displacement(), Unique) );
503  dFESpace->interpolate ( static_cast<solidFESpace_type::function_Type> ( Private::d0 ), *initialDisplacement, 0.0 );
504 
505  if (timeAdvanceMethod == "BDF")
506  {
507  Real tZero = dataStructure->dataTime()->initialTime();
508 
509  for ( UInt previousPass = 0; previousPass < timeAdvance->size() ; previousPass++)
510  {
511  Real previousTimeStep = tZero - previousPass * dt;
512  std::cout << "BDF " << previousTimeStep << "\n";
513  //uv0.push_back(disp);
514  uv0.push_back (initialDisplacement);
515  }
516  }
517 
518  timeAdvance->setInitialCondition (uv0);
519 
520  timeAdvance->setTimeStep ( dt );
521 
522  timeAdvance->updateRHSContribution ( dt );
523 
524 
525  // debug purposes
526  // vector_Type RHSfirstTerm( timeAdvance->rhsContributionFirstDerivative() );
527  // vector_Type RHSsecondTerm( timeAdvance->rhsContributionSecondDerivative() );
528 
529  // vector_Type velInitialize( timeAdvance->firstDerivative() );
530  // vector_Type accInitialize( timeAdvance->secondDerivative() );
531 
532 
533  // std::cout << "Norm RHS 1: " << RHSfirstTerm.norm2() << std::endl;
534  // std::cout << "Norm RHS 2: " << RHSsecondTerm.norm2() << std::endl;
535 
536 
537  // std::cout << "Velocity 1: " << velInitialize.norm2() << std::endl;
538  // std::cout << "Acceleration 2: " << accInitialize.norm2() << std::endl;
539 
540  //In the case of non-zero displacement
541  //solid.initialize( disp );
542  solid.initialize ( initialDisplacement );
543  //Let's verify that the set displacement is the one I expect
544  //Creation of Exporter to check the loaded solution (working only for HDF5)
545  std::string expVerFile = "verificationDisplExporter";
546  LifeV::ExporterHDF5<RegionMesh<LinearTetra> > exporter ( dataFile, meshPart.meshPartition(), expVerFile, parameters->comm->MyPID() );
547  vectorPtr_Type vectVer ( new vector_Type (solid.displacement(), LifeV::Unique ) );
548 
549  exporter.addVariable ( ExporterData<mesh_Type >::VectorField, "displVer", dFESpace, vectVer, UInt (0) );
550 
551  //Let's get the initial displacement and velocity
552  exporter.postProcess (0.0);
553 
554  *vectVer = *initialDisplacement; //*disp;
555  exporter.postProcess ( 1.0 );
556 
557  }
558  MPI_Barrier (MPI_COMM_WORLD);
559 
560  if (verbose )
561  {
562  std::cout << "ok." << std::endl;
563  }
564 
565  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporter;
566  // std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporterCheck;
567 
568  std::string const exporterType = dataFile ( "exporter/type", "ensight");
569  std::string const exporterName = dataFile ( "exporter/name", "structure");
570  // std::string const exporterCheckName = dataFile ( "exporter/nameCheck", "verifyVectors");
571 #ifdef HAVE_HDF5
572  if (exporterType.compare ("hdf5") == 0)
573  {
574  exporter.reset ( new ExporterHDF5<RegionMesh<LinearTetra> > ( dataFile, exporterName ) );
575  // exporterCheck.reset ( new ExporterHDF5<RegionMesh<LinearTetra> > ( dataFile, exporterCheckName ) );
576  }
577  else
578 #endif
579  {
580  if (exporterType.compare ("none") == 0)
581  {
582  exporter.reset ( new ExporterEmpty<RegionMesh<LinearTetra> > ( dataFile, meshPart.meshPartition(), exporterName, parameters->comm->MyPID() ) );
583  }
584 
585  else
586  {
587  exporter.reset ( new ExporterEnsight<RegionMesh<LinearTetra> > ( dataFile, meshPart.meshPartition(), exporterName, parameters->comm->MyPID() ) );
588  }
589  }
590 
591  exporter->setPostDir ( "./" );
592  exporter->setMeshProcId ( meshPart.meshPartition(), parameters->comm->MyPID() );
593 
594  // exporterCheck->setPostDir ( "./" );
595  // exporterCheck->setMeshProcId ( meshPart.meshPartition(), parameters->comm->MyPID() );
596 
597  vectorPtr_Type solidDisp ( new vector_Type (solid.displacement(), exporter->mapType() ) );
598  vectorPtr_Type solidVel ( new vector_Type (solid.displacement(), exporter->mapType() ) );
599  vectorPtr_Type solidAcc ( new vector_Type (solid.displacement(), exporter->mapType() ) );
600 
601  // vectorPtr_Type rhsCopy ( new vector_Type (solid.displacement(), exporterCheck->mapType() ) );
602  // vectorPtr_Type residualCopy ( new vector_Type (solid.displacement(), exporterCheck->mapType() ) );
603 
604  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "displacement", dFESpace, solidDisp, UInt (0) );
605  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "velocity", dFESpace, solidVel, UInt (0) );
606  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "acceleration", dFESpace, solidAcc, UInt (0) );
607 
608  // exporterCheck->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "rhs", dFESpace, rhsCopy, UInt (0) );
609  // exporterCheck->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "residual", dFESpace, residualCopy, UInt (0) );
610 
611  //Let's get the initial quantities
612  *solidDisp = solid.displacement();
613  *solidVel = timeAdvance->firstDerivative();
614  *solidAcc = timeAdvance->secondDerivative();
615 
616  exporter->postProcess ( 0 );
617  //exporterCheck->postProcess ( 0 );
618 
619 
620  //!--------------------------------------------------------------------------------------------
621  //! MATLAB FILE WITH DISPLACEMENT OF A CHOSEN POINT
622  //!--------------------------------------------------------------------------------------------
623  std::cout.precision (16);
624 
625  // Used to debug
626  int IDPoint = 158;
627  // This one depends on the direction of the deformation
628  int indexPoint = IDPoint - 1 + dFESpace->dof().numTotalDof();
629  //!--------------------------------------------------------------------------------------------
630  //!The update of the RHS is done by the TimeAdvance class
631  //solid.updateSystem();
632  //! =================================================================================
633 
634 
635 
636  //! =============================================================================
637  //! Temporal loop
638  //! =============================================================================
639  // for (Real time = dt; time <= T; time += dt)
640  for (dataStructure->dataTime()->setTime ( dt ) ; dataStructure->dataTime()->canAdvance( ); dataStructure->dataTime()->updateTime( ) )
641  {
642  // dataStructure->dataTime()->setTime(time);
643 
644  if (verbose)
645  {
646  std::cout << std::endl;
647  std::cout << "S- Now we are at time " << dataStructure->dataTime()->time() << " s." << std::endl;
648  }
649 
650  //! 6. Updating right-hand side
651  *rhs *= 0;
652  timeAdvance->updateRHSContribution ( dt );
653  *rhs += *solid.massMatrix() * timeAdvance->rhsContributionSecondDerivative() / timeAdvanceCoefficient;
654  solid.setRightHandSide ( *rhs );
655 
656  //! 7. Iterate --> Calling Newton
657  solid.iterate ( BCh );
658 
659  timeAdvance->shiftRight ( solid.displacement() );
660 
661  *solidDisp = solid.displacement();
662  *solidVel = timeAdvance->firstDerivative();
663  *solidAcc = timeAdvance->secondDerivative();
664 
665  // *rhsCopy = solid.rhsCopy();
666  // *residualCopy = solid.residualCopy();
667 
668  exporter->postProcess ( dataStructure->dataTime()->time() );
669  //exporterCheck->postProcess ( dataStructure->dataTime()->time() );
670 
671  cout << "*********************************************************" << std::endl;
672  cout << " solid.disp()[ " << indexPoint << " ] = " << solid.displacement() [ indexPoint ] << std::endl;
673  cout << "*********************************************************" << std::endl;
674 
675 
676  Real normVect;
677  normVect = solid.displacement().norm2();
678  std::cout << "The norm 2 of the displacement field is: " << normVect << std::endl;
679 
680  //!--------------------------------------------------------------------------------------------------
681 
682  MPI_Barrier (MPI_COMM_WORLD);
683  }
684 }
685 
686 
687 
688 void Structure::CheckResultLE (const Real& dispNorm, const Real& time)
689 {
690  if ( time == 0.1 && std::fabs (dispNorm - 0.276527) <= 1e-5 )
691  {
692  this->resultChanged (time);
693  }
694  if ( time == 0.2 && std::fabs (dispNorm - 0.276536) <= 1e-5 )
695  {
696  this->resultChanged (time);
697  }
698  if ( time == 0.3 && std::fabs (dispNorm - 0.276529) <= 1e-5 )
699  {
700  this->resultChanged (time);
701  }
702  if ( time == 0.4 && std::fabs (dispNorm - 0.276531) <= 1e-5 )
703  {
704  this->resultChanged (time);
705  }
706 }
707 
708 void Structure::CheckResultSVK (const Real& dispNorm, const Real& time)
709 {
710  if ( time == 0.1 && std::fabs (dispNorm - 0.263348) <= 1e-5 )
711  {
712  this->resultChanged (time);
713  }
714  if ( time == 0.2 && std::fabs (dispNorm - 0.263350) <= 1e-5 )
715  {
716  this->resultChanged (time);
717  }
718  if ( time == 0.3 && std::fabs (dispNorm - 0.263350) <= 1e-5 )
719  {
720  this->resultChanged (time);
721  }
722  if ( time == 0.4 && std::fabs (dispNorm - 0.263351) <= 1e-5 )
723  {
724  this->resultChanged (time);
725  }
726 }
727 void Structure::CheckResultEXP (const Real& dispNorm, const Real& time)
728 {
729  if ( time == 0.1 && std::fabs (dispNorm - 0.284844) <= 1e-5 )
730  {
731  this->resultChanged (time);
732  }
733  if ( time == 0.2 && std::fabs (dispNorm - 0.284853) <= 1e-5 )
734  {
735  this->resultChanged (time);
736  }
737  if ( time == 0.3 && std::fabs (dispNorm - 0.284846) <= 1e-5 )
738  {
739  this->resultChanged (time);
740  }
741  if ( time == 0.4 && std::fabs (dispNorm - 0.284848) <= 1e-5 )
742  {
743  this->resultChanged (time);
744  }
745 }
746 
747 void Structure::CheckResultNH (const Real& dispNorm, const Real& time)
748 {
749  if ( time == 0.1 && std::fabs (dispNorm - 0.286120) <= 1e-5 )
750  {
751  this->resultChanged (time);
752  }
753  if ( time == 0.2 && std::fabs (dispNorm - 0.286129) <= 1e-5 )
754  {
755  this->resultChanged (time);
756  }
757  if ( time == 0.3 && std::fabs (dispNorm - 0.286122) <= 1e-5 )
758  {
759  this->resultChanged (time);
760  }
761  if ( time == 0.4 && std::fabs (dispNorm - 0.286123) <= 1e-5 )
762  {
763  this->resultChanged (time);
764  }
765 }
766 
767 
768 
770 {
771  std::cout << "Correct value at time: " << time << std::endl;
772  returnValue = EXIT_SUCCESS;
773 }
774 
775 
776 
777 int
778 main ( int argc, char** argv )
779 {
780 
781 #ifdef HAVE_MPI
782  MPI_Init (&argc, &argv);
783  std::shared_ptr<Epetra_MpiComm> Comm (new Epetra_MpiComm ( MPI_COMM_WORLD ) );
784  if ( Comm->MyPID() == 0 )
785  {
786  std::cout << "% using MPI" << std::endl;
787  }
788 #else
789  std::shared_ptr<Epetra_SerialComm> Comm ( new Epetra_SerialComm() );
790  std::cout << "% using serial Version" << std::endl;
791 #endif
792 
793  Structure structure ( argc, argv, Comm );
794  structure.run();
795 
796 #ifdef HAVE_MPI
797  MPI_Finalize();
798 #endif
799  return returnValue ;
800 }
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
void CheckResultLE(const Real &dispNorm, const Real &time)
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > fct_type
std::shared_ptr< hdf5Filter_Type > hdf5FilterPtr_Type
void CheckResultEXP(const Real &dispNorm, const Real &time)
static Real bcZero(const Real &, const Real &, const Real &, const Real &, const ID &)
#define ERROR_MSG(A)
Definition: LifeAssert.hpp:69
void CheckResultNH(const Real &dispNorm, const Real &time)
void run3d()
run the 3D driven cylinder simulation
uint32_type ID
IDs.
Definition: LifeV.hpp:194
static Real d0(const Real &, const Real &x, const Real &y, const Real &z, const ID &i)
void run2d()
run the 2D driven cylinder simulation
MeshData - class for handling spatial discretization.
Definition: MeshData.hpp:72
void CheckResultSVK(const Real &dispNorm, const Real &time)
double Real
Generic real data.
Definition: LifeV.hpp:175
static Real bcNonZero(const Real &, const Real &, const Real &, const Real &, const ID &)
std::set< UInt > parseList(const std::string &list)
void resultChanged(Real time)
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191