64 #include <Epetra_ConfigDefs.h> 67 #include <Epetra_MpiComm.h> 69 #include <Epetra_SerialComm.h> 73 #include <lifev/core/array/MapEpetra.hpp> 74 #include <lifev/core/mesh/MeshData.hpp> 75 #include <lifev/core/mesh/MeshPartitioner.hpp> 77 #include <lifev/structure/solver/VenantKirchhoffViscoelasticSolver.hpp> 78 #include <lifev/structure/solver/VenantKirchhoffViscoelasticData.hpp> 80 #include <lifev/core/fem/TimeData.hpp> 81 #include <lifev/core/fem/FESpace.hpp> 83 #include <lifev/core/fem/TimeAdvance.hpp> 84 #include <lifev/core/fem/TimeAdvanceNewmark.hpp> 85 #include <lifev/core/fem/TimeAdvanceBDF.hpp> 87 #include <lifev/core/filter/ExporterEnsight.hpp> 88 #include <lifev/core/filter/ExporterHDF5.hpp> 89 #include <lifev/core/filter/ExporterEmpty.hpp> 102 using namespace LifeV;
131 f = std::bind (&UZero, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5);
143 problem::problem (
int argc,
145 std::shared_ptr<Epetra_Comm> structComm) :
146 members (
new Private() )
149 std::string data_file_name = command_line.follow (
"data", 2,
"-f",
"--file");
150 GetPot dataFile ( data_file_name );
151 members->data_file_name = data_file_name;
153 members->rho = dataFile (
"problem/physics/density", 1. );
155 std::cout <<
"density = " << members->rho << std::endl;
157 members->comm = structComm;
158 int ntasks = members->comm->NumProc();
160 if (!members->comm->MyPID() )
162 std::cout <<
"My PID = " << members->comm->MyPID() <<
" out of " << ntasks <<
" running." << std::endl;
172 typedef RegionMesh<LinearTetra> mesh_Type;
173 typedef VenantKirchhoffViscoelasticSolver< mesh_Type >::vector_type vector_Type;
174 typedef std::shared_ptr<vector_Type> vectorPtr_Type;
176 typedef std::shared_ptr< TimeAdvance< vector_Type > > TimeAdvance_type;
179 typedef std::shared_ptr<FESpace_type> FESpace_ptrtype;
181 bool verbose = (members->comm->MyPID() == 0);
187 GetPot dataFile ( members->data_file_name.c_str() );
188 std::shared_ptr<VenantKirchhoffViscoelasticData> dataProblem (
new VenantKirchhoffViscoelasticData( ) );
189 dataProblem->setup (dataFile,
"problem");
193 meshData.setup (dataFile,
"problem/space_discretization");
195 std::shared_ptr<mesh_Type > fullMeshPtr (
new mesh_Type ( members->comm ) );
196 readMesh (*fullMeshPtr, meshData);
198 std::shared_ptr<mesh_Type > localMeshPtr;
201 localMeshPtr = meshPart.meshPartition();
210 std::cout <<
"The Problem Solver" << std::flush;
215 std::string Order = dataFile (
"problem/space_discretization/order",
"P1");
217 if ( Order.compare (
"P1") == 0 )
221 std::cout <<
" Space order : P1" << std::flush;
225 else if ( Order.compare (
"P2") == 0 )
229 std::cout <<
" Space order : P2";
235 std::cout << std::endl;
241 std::string dOrder = dataFile (
"problem/space_discretization/order",
"P1");
243 FESpace_ptrtype feSpace (
new FESpace_type (localMeshPtr, dOrder, 1, members->comm) );
247 VenantKirchhoffViscoelasticSolver< mesh_Type > problem;
249 problem.setup (dataProblem, feSpace,
252 problem.setDataFromGetPot (dataFile);
255 BCFunctionBase uZero ( members->getUZero() );
256 BCFunctionBase uEx (uexact);
260 bcH.addBC (
"Top", TOP, Essential, Full, uEx, 1 );
261 bcH.addBC (
"Bottom", BOTTOM, Essential, Full, uEx, 1 );
262 bcH.addBC (
"Left", LEFT, Essential, Full, uEx, 1 );
263 bcH.addBC (
"Right", RIGHT, Essential, Full, uEx, 1 );
264 bcH.addBC (
"Front", FRONT, Essential, Full, uEx, 1 );
265 bcH.addBC (
"Back", BACK, Essential, Full, uEx, 1 );
267 std::ofstream out_norm;
270 out_norm.open (
"norm.txt");
275 <<
" H1_RelError \n";
281 std::string TimeAdvanceMethod = dataFile (
"problem/time_discretization/method",
"Newmark");
283 TimeAdvance_type timeAdvance ( TimeAdvanceFactory::instance().createObject ( TimeAdvanceMethod ) );
289 if (TimeAdvanceMethod ==
"Newmark")
291 timeAdvance->setup ( dataProblem->dataTimeAdvance()->coefficientsNewmark() , OrderDev);
294 if (TimeAdvanceMethod ==
"BDF")
296 timeAdvance->setup (dataProblem->dataTimeAdvance()->orderBDF() , OrderDev);
299 Real dt = dataProblem->dataTime()->timeStep();
300 Real T = dataProblem->dataTime()->endTime();
304 dataProblem->setup (dataFile,
"problem");
306 double alpha = timeAdvance->coefficientFirstDerivative ( 0 ) / ( dataProblem->dataTime()->timeStep() );
308 problem.buildSystem (alpha);
310 MPI_Barrier (MPI_COMM_WORLD);
314 std::cout <<
"ok." << std::endl;
318 MapEpetra uMap = problem.solution()->map();
321 vector_Type rhs ( uMap, Unique );
322 vector_Type rhsV ( uMap, Unique );
325 std::shared_ptr< Exporter<mesh_Type > > exporter;
327 std::string
const exporterType = dataFile (
"exporter/type",
"ensight");
330 if (exporterType.compare (
"hdf5") == 0)
332 exporter.reset (
new ExporterHDF5<mesh_Type > ( dataFile,
"problem" ) );
337 if (exporterType.compare (
"none") == 0)
339 exporter.reset (
new ExporterEmpty<mesh_Type > ( dataFile, localMeshPtr,
"problem", members ->comm->MyPID() ) );
343 exporter.reset (
new ExporterEnsight<mesh_Type > ( dataFile, localMeshPtr,
"problem", members->comm->MyPID() ) );
347 exporter->setPostDir (
"./" );
348 exporter->setMeshProcId ( localMeshPtr, members->comm->MyPID() );
350 vectorPtr_Type U (
new vector_Type (*problem.solution(), exporter->mapType() ) );
351 vectorPtr_Type V (
new vector_Type (*problem.solution(), exporter->mapType() ) );
352 vectorPtr_Type Exact (
new vector_Type (*problem.solution(), exporter->mapType() ) );
353 vectorPtr_Type vExact (
new vector_Type (*problem.solution(), exporter->mapType() ) );
354 vectorPtr_Type RHS (
new vector_Type (*problem.solution(), exporter->mapType() ) );
355 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"displacement",
356 feSpace, U, UInt (0) );
358 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"velocity",
359 feSpace, V, UInt (0) );
361 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"uexact",
362 feSpace, Exact, UInt (0) );
364 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"vexact",
365 feSpace, vExact, UInt (0) );
367 exporter->postProcess ( 0 );
372 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( d0 ), *U, 0.0 );
373 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( v0 ), *V, 0.0 );
377 std::vector<vectorPtr_Type> uv0;
379 if (TimeAdvanceMethod ==
"Newmark")
384 if (TimeAdvanceMethod ==
"BDF")
386 for ( UInt previousPass = 0; previousPass < dataProblem->dataTimeAdvance()->orderBDF() ; previousPass++)
388 Real previousTimeStep = -previousPass * dt;
389 feSpace->interpolate (
static_cast<FESpace_type::function_Type> (uexact ), *U, previousTimeStep );
398 timeAdvance->setInitialCondition (uv0);
400 timeAdvance-> setTimeStep (dataProblem->dataTime()->timeStep() );
402 timeAdvance->showMe();
404 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( uexact ), *Exact , 0);
405 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( v0 ), *vExact , 0);
407 *U = timeAdvance->solution();
408 *V = timeAdvance->firstDerivative();
410 for (
Real time = dt; time <= T; time += dt)
412 dataProblem->dataTime()->setTime (time);
416 std::cout << std::endl;
417 std::cout <<
" P - Now we are at time " << dataProblem->dataTime()->time() <<
" s." << std::endl;
422 timeAdvance->updateRHSContribution (dt);
423 rhsV = timeAdvance->rhsContributionFirstDerivative();
424 feSpace->l2ScalarProduct (source_in, rhs, time);
425 rhs += problem.matrMass() * rhsV;
428 problem.updateRHS (rhs);
431 problem.iterate ( bcH );
434 timeAdvance->shiftRight (*problem.solution() );
437 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( uexact ), *Exact , time);
438 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( v0 ), *vExact , time);
439 *U = timeAdvance->solution();
440 *V = timeAdvance->firstDerivative();
443 exporter->postProcess (time);
447 vector_Type u (*problem.solution(), Repeated);
449 Real H1_Error, H1_RelError, L2_Error, L2_RelError;
451 L2_Error = feSpace->l2Error (uexact, u, time , &L2_RelError);
452 H1_Error = feSpace->h1Error (uExact, u, time , &H1_RelError);
457 out_norm.open (
"norm.txt", std::ios::app);
458 out_norm << time <<
" " 461 << L2_RelError <<
" " 462 << H1_RelError <<
"\n";
466 MPI_Barrier (MPI_COMM_WORLD);
471 std::cout <<
"Total iteration time " << chrono.diff() <<
" s." << std::endl;
FESpace - Short description here please!
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Epetra_Import const & importer()
Getter for the Epetra_Import.
std::shared_ptr< std::vector< Int > > M_isOnProc
MeshData - class for handling spatial discretization.
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > fct_type
double Real
Generic real data.
std::shared_ptr< Epetra_Comm > comm
std::string data_file_name
uint32_type UInt
generic unsigned integer (used mainly for addressing)