33 #error test_structure cannot be compiled in 2D
37 #pragma GCC diagnostic ignored "-Wunused-variable" 38 #pragma GCC diagnostic ignored "-Wunused-parameter" 40 #include <Epetra_ConfigDefs.h> 43 #include <Epetra_MpiComm.h> 45 #include <Epetra_SerialComm.h> 49 #pragma GCC diagnostic warning "-Wunused-variable" 50 #pragma GCC diagnostic warning "-Wunused-parameter" 52 #include <lifev/core/LifeV.hpp> 53 #include <lifev/core/algorithm/PreconditionerIfpack.hpp> 54 #include <lifev/core/algorithm/PreconditionerML.hpp> 58 #include <lifev/core/array/MapEpetra.hpp> 60 #include <lifev/core/fem/TimeAdvance.hpp> 61 #include <lifev/core/fem/TimeAdvanceNewmark.hpp> 62 #include <lifev/core/fem/TimeAdvanceBDF.hpp> 64 #include <lifev/core/mesh/MeshData.hpp> 65 #include <lifev/core/mesh/MeshPartitioner.hpp> 67 #include <lifev/structure/solver/StructuralConstitutiveLawData.hpp> 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> 78 #include <lifev/core/filter/ExporterEnsight.hpp> 80 #include <lifev/core/filter/ExporterHDF5.hpp> 82 #include <lifev/core/filter/ExporterEmpty.hpp> 87 using namespace LifeV;
101 std::string stringList = list;
102 std::set<UInt> setList;
108 while ( commaPos != std::string::npos )
110 commaPos = stringList.find (
"," );
111 setList.insert ( atoi ( stringList.substr ( 0, commaPos ).c_str() ) );
112 stringList = stringList.substr ( commaPos + 1 );
114 setList.insert ( atoi ( stringList.c_str() ) );
128 std::shared_ptr<Epetra_Comm> structComm );
194 return - 0.058549 * ( x - 0.5 );
197 return ( 0.256942 / 2 ) * y;
200 return - 0.058549 * ( z + 0.5);
203 ERROR_MSG (
"This entry is not allowed: ud_functions.hpp");
216 std::shared_ptr<Epetra_Comm> structComm) :
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;
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. );
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;
238 parameters->comm = structComm;
239 int ntasks = parameters->comm->NumProc();
241 if (!parameters->comm->MyPID() )
243 std::cout <<
"My PID = " << parameters->comm->MyPID() <<
" out of " << ntasks <<
" running." << std::endl;
252 std::cout <<
"2D cylinder test case is not available yet\n";
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;
267 typedef LifeV::ExporterEnsight<mesh_Type > ensightFilter_Type;
268 typedef std::shared_ptr<ensightFilter_Type> ensightFilterPtr_Type;
271 typedef LifeV::ExporterHDF5<mesh_Type > hdf5Filter_Type;
272 typedef std::shared_ptr<hdf5Filter_Type> hdf5FilterPtr_Type;
275 bool verbose = (parameters->comm->MyPID() == 0);
278 std::shared_ptr<BCHandler> BCh (
new BCHandler() );
281 GetPot dataFile ( parameters->data_file_name.c_str() );
283 std::shared_ptr<StructuralConstitutiveLawData> dataStructure (
new StructuralConstitutiveLawData( ) );
284 dataStructure->setup (dataFile);
287 meshData.setup (dataFile,
"solid/space_discretization");
289 std::shared_ptr<RegionMesh<LinearTetra> > fullMeshPtr (
new RegionMesh<LinearTetra> ( parameters->comm ) );
290 readMesh (*fullMeshPtr, meshData);
292 MeshPartitioner< RegionMesh<LinearTetra> > meshPart ( fullMeshPtr, parameters->comm );
294 std::string dOrder = dataFile (
"solid/space_discretization/order",
"P1");
296 typedef FESpace< RegionMesh<LinearTetra>, MapEpetra > solidFESpace_type;
297 typedef std::shared_ptr<solidFESpace_type> solidFESpace_ptrtype;
299 typedef ETFESpace< RegionMesh<LinearTetra>, MapEpetra, 3, 3 > solidETFESpace_Type;
300 typedef std::shared_ptr<solidETFESpace_Type> solidETFESpacePtr_Type;
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) );
307 std::cout << std::endl;
310 std::string timeAdvanceMethod = dataFile (
"solid/time_discretization/method",
"Newmark");
312 std::cout <<
"Method: " << timeAdvanceMethod << std::endl;
314 timeAdvance_type timeAdvance ( TimeAdvanceFactory::instance().createObject ( timeAdvanceMethod ) );
319 if (timeAdvanceMethod ==
"Newmark")
321 timeAdvance->setup ( dataStructure->dataTimeAdvance()->coefficientsNewmark() , OrderDev);
324 if (timeAdvanceMethod ==
"BDF")
326 timeAdvance->setup (dataStructure->dataTimeAdvance()->orderBDF() , OrderDev);
329 timeAdvance->setTimeStep (dataStructure->dataTime()->timeStep() );
334 std::vector <ID> compx (1), compy (1), compz (1), compxy (2), compxz (2), compyz (2);
336 compy[0] = 1, compz[0] = 2;
344 BCFunctionBase zero (Private::bcZero);
345 BCFunctionBase nonZero (Private::bcNonZero);
350 BCh->addBC (
"EdgesIn", 20, Natural, Component, nonZero, compy);
351 BCh->addBC (
"EdgesIn", 40, Essential, Component, zero, compy);
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);
362 StructuralOperator< RegionMesh<LinearTetra> > solid;
365 solid.setup (dataStructure,
372 solid.setDataFromGetPot (dataFile);
375 double timeAdvanceCoefficient = timeAdvance->coefficientSecondDerivative ( 0 ) / (dataStructure->dataTime()->timeStep() * dataStructure->dataTime()->timeStep() );
376 solid.buildSystem (timeAdvanceCoefficient);
379 dataStructure->showMe();
385 Real dt = dataStructure->dataTime()->timeStep();
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) );
394 std::string
const restart = dataFile (
"importer/restart",
"none");
395 std::vector<vectorPtr_Type> solutionStencil;
396 solutionStencil.resize ( timeAdvance->size() );
398 std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > importerSolid;
399 if ( restart.compare (
"none" ) )
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");
409 if ( !importerType.compare (
"hdf5") )
411 importerSolid.reset (
new hdf5Filter_Type ( dataFile, fileName) );
416 if ( !importerType.compare (
"none") )
418 importerSolid.reset (
new emptyExporter_Type ( dataFile, dFESpace->mesh(),
"solid", dFESpace->map().comm().MyPID() ) );
422 importerSolid.reset (
new ensightFilter_Type ( dataFile, fileName) );
426 importerSolid->setMeshProcId (dFESpace->mesh(), dFESpace->map().comm().MyPID() );
438 vectorPtr_Type solidDisp (
new vector_Type (dFESpace->map(), importerSolid->mapType() ) );
440 std::string iterationString;
442 std::cout <<
"size TimeAdvance:" << timeAdvance->size() << std::endl;
445 iterationString = initialLoaded;
446 for (UInt iterInit = 0; iterInit < timeAdvance->size(); iterInit++ )
448 solidDisp.reset (
new vector_Type (dFESpace->map(), importerSolid->mapType() ) );
451 LifeV::ExporterData<mesh_Type> solidDataReader (LifeV::ExporterData<mesh_Type>::VectorField, std::string (
"displacement." + iterationString), dFESpace, solidDisp, UInt (0), LifeV::ExporterData<mesh_Type>::UnsteadyRegime );
453 importerSolid->readVariable (solidDataReader);
455 std::cout <<
"Norm of the " << iterInit + 1 <<
"-th solution : " << solidDisp->norm2() << std::endl;
463 solutionStencil[ iterInit ] = solidDisp;
467 solid.initialize ( solidDisp );
471 int iterations = std::atoi (iterationString.c_str() );
474 std::ostringstream iter;
476 iter << std::setw (5) << ( iterations );
477 iterationString = iter.str();
481 importerSolid->closeFile();
484 timeAdvance->setInitialCondition (solutionStencil);
490 std::cout <<
"S- initialization ... ";
493 std::vector<vectorPtr_Type> uv0;
495 if (timeAdvanceMethod ==
"Newmark")
497 uv0.push_back (disp);
502 vectorPtr_Type initialDisplacement (
new vector_Type (solid.displacement(), Unique) );
503 dFESpace->interpolate (
static_cast<solidFESpace_type::function_Type> ( Private::d0 ), *initialDisplacement, 0.0 );
505 if (timeAdvanceMethod ==
"BDF")
507 Real tZero = dataStructure->dataTime()->initialTime();
509 for ( UInt previousPass = 0; previousPass < timeAdvance->size() ; previousPass++)
511 Real previousTimeStep = tZero - previousPass * dt;
512 std::cout <<
"BDF " << previousTimeStep <<
"\n";
514 uv0.push_back (initialDisplacement);
518 timeAdvance->setInitialCondition (uv0);
520 timeAdvance->setTimeStep ( dt );
522 timeAdvance->updateRHSContribution ( dt );
542 solid.initialize ( initialDisplacement );
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 ) );
549 exporter.addVariable ( ExporterData<mesh_Type >::VectorField,
"displVer", dFESpace, vectVer, UInt (0) );
552 exporter.postProcess (0.0);
554 *vectVer = *initialDisplacement;
555 exporter.postProcess ( 1.0 );
558 MPI_Barrier (MPI_COMM_WORLD);
562 std::cout <<
"ok." << std::endl;
565 std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporter;
568 std::string
const exporterType = dataFile (
"exporter/type",
"ensight");
569 std::string
const exporterName = dataFile (
"exporter/name",
"structure");
572 if (exporterType.compare (
"hdf5") == 0)
574 exporter.reset (
new ExporterHDF5<RegionMesh<LinearTetra> > ( dataFile, exporterName ) );
580 if (exporterType.compare (
"none") == 0)
582 exporter.reset (
new ExporterEmpty<RegionMesh<LinearTetra> > ( dataFile, meshPart.meshPartition(), exporterName, parameters->comm->MyPID() ) );
587 exporter.reset (
new ExporterEnsight<RegionMesh<LinearTetra> > ( dataFile, meshPart.meshPartition(), exporterName, parameters->comm->MyPID() ) );
591 exporter->setPostDir (
"./" );
592 exporter->setMeshProcId ( meshPart.meshPartition(), parameters->comm->MyPID() );
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() ) );
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) );
612 *solidDisp = solid.displacement();
613 *solidVel = timeAdvance->firstDerivative();
614 *solidAcc = timeAdvance->secondDerivative();
616 exporter->postProcess ( 0 );
623 std::cout.precision (16);
628 int indexPoint = IDPoint - 1 + dFESpace->dof().numTotalDof();
640 for (dataStructure->dataTime()->setTime ( dt ) ; dataStructure->dataTime()->canAdvance( ); dataStructure->dataTime()->updateTime( ) )
646 std::cout << std::endl;
647 std::cout <<
"S- Now we are at time " << dataStructure->dataTime()->time() <<
" s." << std::endl;
652 timeAdvance->updateRHSContribution ( dt );
653 *rhs += *solid.massMatrix() * timeAdvance->rhsContributionSecondDerivative() / timeAdvanceCoefficient;
654 solid.setRightHandSide ( *rhs );
657 solid.iterate ( BCh );
659 timeAdvance->shiftRight ( solid.displacement() );
661 *solidDisp = solid.displacement();
662 *solidVel = timeAdvance->firstDerivative();
663 *solidAcc = timeAdvance->secondDerivative();
668 exporter->postProcess ( dataStructure->dataTime()->time() );
671 cout <<
"*********************************************************" << std::endl;
672 cout <<
" solid.disp()[ " << indexPoint <<
" ] = " << solid.displacement() [ indexPoint ] << std::endl;
673 cout <<
"*********************************************************" << std::endl;
677 normVect = solid.displacement().norm2();
678 std::cout <<
"The norm 2 of the displacement field is: " << normVect << std::endl;
682 MPI_Barrier (MPI_COMM_WORLD);
690 if ( time == 0.1 && std::fabs (dispNorm - 0.276527) <= 1e-5 )
694 if ( time == 0.2 && std::fabs (dispNorm - 0.276536) <= 1e-5 )
698 if ( time == 0.3 && std::fabs (dispNorm - 0.276529) <= 1e-5 )
702 if ( time == 0.4 && std::fabs (dispNorm - 0.276531) <= 1e-5 )
710 if ( time == 0.1 && std::fabs (dispNorm - 0.263348) <= 1e-5 )
714 if ( time == 0.2 && std::fabs (dispNorm - 0.263350) <= 1e-5 )
718 if ( time == 0.3 && std::fabs (dispNorm - 0.263350) <= 1e-5 )
722 if ( time == 0.4 && std::fabs (dispNorm - 0.263351) <= 1e-5 )
729 if ( time == 0.1 && std::fabs (dispNorm - 0.284844) <= 1e-5 )
733 if ( time == 0.2 && std::fabs (dispNorm - 0.284853) <= 1e-5 )
737 if ( time == 0.3 && std::fabs (dispNorm - 0.284846) <= 1e-5 )
741 if ( time == 0.4 && std::fabs (dispNorm - 0.284848) <= 1e-5 )
749 if ( time == 0.1 && std::fabs (dispNorm - 0.286120) <= 1e-5 )
753 if ( time == 0.2 && std::fabs (dispNorm - 0.286129) <= 1e-5 )
757 if ( time == 0.3 && std::fabs (dispNorm - 0.286122) <= 1e-5 )
761 if ( time == 0.4 && std::fabs (dispNorm - 0.286123) <= 1e-5 )
771 std::cout <<
"Correct value at time: " << time << std::endl;
782 MPI_Init (&argc, &argv);
783 std::shared_ptr<Epetra_MpiComm> Comm (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
784 if ( Comm->MyPID() == 0 )
786 std::cout <<
"% using MPI" << std::endl;
789 std::shared_ptr<Epetra_SerialComm> Comm (
new Epetra_SerialComm() );
790 std::cout <<
"% using serial Version" << std::endl;
793 Structure structure ( argc, argv, Comm );
std::shared_ptr< Epetra_Comm > comm
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)
void CheckResultLE(const Real &dispNorm, const Real &time)
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > fct_type
static const LifeV::UInt elm_nodes_num[]
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 &)
void CheckResultNH(const Real &dispNorm, const Real &time)
void run3d()
run the 3D driven cylinder simulation
static Real d0(const Real &, const Real &x, const Real &y, const Real &z, const ID &i)
std::string data_file_name
void run2d()
run the 2D driven cylinder simulation
MeshData - class for handling spatial discretization.
std::shared_ptr< Private > parameters
void CheckResultSVK(const Real &dispNorm, const Real &time)
double Real
Generic real data.
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)