63 #include <Epetra_ConfigDefs.h> 66 #include <Epetra_MpiComm.h> 68 #include <Epetra_SerialComm.h> 72 #include <lifev/core/array/MapEpetra.hpp> 73 #include <lifev/core/mesh/MeshData.hpp> 74 #include <lifev/core/mesh/MeshPartitioner.hpp> 76 #include <lifev/structure/solver/VenantKirchhoffViscoelasticSolver.hpp> 77 #include <lifev/structure/solver/VenantKirchhoffViscoelasticData.hpp> 79 #include <lifev/core/fem/TimeData.hpp> 80 #include <lifev/core/fem/FESpace.hpp> 82 #include <lifev/core/fem/TimeAdvance.hpp> 83 #include <lifev/core/fem/TimeAdvanceNewmark.hpp> 84 #include <lifev/core/fem/TimeAdvanceBDF.hpp> 86 #include <lifev/core/filter/ExporterEnsight.hpp> 87 #include <lifev/core/filter/ExporterHDF5.hpp> 88 #include <lifev/core/filter/ExporterEmpty.hpp> 101 using namespace LifeV;
129 f = std::bind (&UZero, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5);
141 problem::problem (
int argc,
143 std::shared_ptr<Epetra_Comm> structComm) :
144 members (
new Private() )
147 std::string data_file_name = command_line.follow (
"data", 2,
"-f",
"--file");
148 GetPot dataFile ( data_file_name );
149 members->data_file_name = data_file_name;
151 members->rho = dataFile (
"problem/physics/density", 1. );
153 std::cout <<
"density = " << members->rho << std::endl;
155 members->comm = structComm;
156 int ntasks = members->comm->NumProc();
158 if (!members->comm->MyPID() )
160 std::cout <<
"My PID = " << members->comm->MyPID() <<
" out of " << ntasks <<
" running." << std::endl;
170 typedef RegionMesh<LinearTetra> mesh_Type;
171 typedef VenantKirchhoffViscoelasticSolver< mesh_Type >::vector_type vector_type;
172 typedef std::shared_ptr<vector_type> vector_ptrtype;
174 typedef std::shared_ptr< TimeAdvance< vector_type > > TimeAdvance_type;
176 typedef std::shared_ptr<FESpace_type> FESpace_ptrtype;
178 bool verbose = (members->comm->MyPID() == 0);
184 GetPot dataFile ( members->data_file_name.c_str() );
185 std::shared_ptr<VenantKirchhoffViscoelasticData> dataProblem (
new VenantKirchhoffViscoelasticData( ) );
186 dataProblem->setup (dataFile,
"problem");
189 meshData.setup (dataFile,
"problem/space_discretization");
191 std::shared_ptr<mesh_Type > fullMeshPtr (
new mesh_Type ( members->comm ) );
192 readMesh (*fullMeshPtr, meshData);
194 std::shared_ptr<mesh_Type > localMeshPtr;
197 localMeshPtr = meshPart.meshPartition();
206 std::string Order = dataFile (
"problem/space_discretization/order",
"P1");
208 if ( Order.compare (
"P1") == 0 )
212 std::cout <<
" Space order : P1" << std::flush;
216 else if ( Order.compare (
"P2") == 0 )
220 std::cout <<
" Space order : P2";
225 std::cout << std::endl;
231 std::string dOrder = dataFile (
"problem/space_discretization/order",
"P1");
233 FESpace_ptrtype feSpace (
new FESpace_type (localMeshPtr, dOrder, 1, members->comm) );
237 VenantKirchhoffViscoelasticSolver< mesh_Type > problem;
239 problem.setup (dataProblem, feSpace,
242 problem.setDataFromGetPot (dataFile);
246 BCFunctionBase uZero ( members->getUZero() );
247 BCFunctionBase uEx (uexact);
251 bcH.addBC (
"Top", TOP, Essential, Full, uEx, 1 );
252 bcH.addBC (
"Bottom", BOTTOM, Essential, Full, uEx, 1 );
253 bcH.addBC (
"Left", LEFT, Essential, Full, uEx, 1 );
254 bcH.addBC (
"Right", RIGHT, Essential, Full, uEx, 1 );
255 bcH.addBC (
"Front", FRONT, Essential, Full, uEx, 1 );
256 bcH.addBC (
"Back", BACK, Essential, Full, uEx, 1 );
258 std::ofstream out_norm;
261 out_norm.open (
"norm.txt");
266 <<
" H1_RelError \n";
272 std::string TimeAdvanceMethod = dataFile (
"problem/time_discretization/method",
"Newmark");
274 TimeAdvance_type timeAdvance ( TimeAdvanceFactory::instance().createObject ( TimeAdvanceMethod ) );
279 if (TimeAdvanceMethod ==
"Newmark")
281 timeAdvance->setup ( dataProblem->dataTimeAdvance()->coefficientsNewmark() , OrderDev);
284 if (TimeAdvanceMethod ==
"BDF")
286 timeAdvance->setup (dataProblem->dataTimeAdvance()->orderBDF() , OrderDev);
289 timeAdvance->setTimeStep (dataProblem->dataTime()->timeStep() );
290 timeAdvance->showMe();
293 dataProblem->setup (dataFile,
"problem");
297 double xi = timeAdvance->coefficientSecondDerivative ( 0 ) / ( dataProblem->dataTime()->timeStep() * dataProblem->dataTime()->timeStep() );
299 problem.buildSystem (xi);
302 MPI_Barrier (MPI_COMM_WORLD);
306 std::cout <<
"ok." << std::endl;
310 MapEpetra uMap = problem.solution()->map();
313 vector_type rhs ( uMap, Unique );
317 std::shared_ptr< Exporter<mesh_Type > > exporter;
319 std::string
const exporterType = dataFile (
"exporter/type",
"ensight");
322 if (exporterType.compare (
"hdf5") == 0)
324 exporter.reset (
new ExporterHDF5<mesh_Type > ( dataFile,
"problem" ) );
329 if (exporterType.compare (
"none") == 0)
331 exporter.reset (
new ExporterEmpty<mesh_Type > ( dataFile, localMeshPtr,
"problem", members ->comm->MyPID() ) );
335 exporter.reset (
new ExporterEnsight<mesh_Type > ( dataFile, localMeshPtr,
"problem", members->comm->MyPID() ) );
338 exporter->setPostDir (
"./" );
339 exporter->setMeshProcId ( localMeshPtr, members->comm->MyPID() );
341 vector_ptrtype U (
new vector_type (*problem.solution(), exporter->mapType() ) );
342 vector_ptrtype V (
new vector_type (*problem.solution(), exporter->mapType() ) );
343 vector_ptrtype W (
new vector_type (*problem.solution(), exporter->mapType() ) );
344 vector_ptrtype Exact (
new vector_type (*problem.solution(), exporter->mapType() ) );
345 vector_ptrtype vExact (
new vector_type (*problem.solution(), exporter->mapType() ) );
346 vector_ptrtype wExact (
new vector_type (*problem.solution(), exporter->mapType() ) );
347 vector_ptrtype RHS (
new vector_type (*problem.solution(), exporter->mapType() ) );
348 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"displacement",
349 feSpace, U, UInt (0) );
351 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"velocity",
352 feSpace, V, UInt (0) );
353 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"uexact",
354 feSpace, Exact, UInt (0) );
357 exporter->postProcess ( 0 );
360 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( d0 ), *U, 0.0 );
361 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( v0 ), *V, 0.0 );
362 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( a0 ), *W, 0.0 );
366 std::vector<vector_ptrtype> uv0;
368 Real dt = dataProblem->dataTime()->timeStep();
369 Real T = dataProblem->dataTime()->endTime();
371 if (TimeAdvanceMethod ==
"Newmark")
377 if (TimeAdvanceMethod ==
"BDF")
379 for ( UInt previousPass = 0; previousPass < dataProblem->dataTimeAdvance()->orderBDF() ; previousPass++)
381 Real previousTimeStep = -previousPass * dt;
382 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( uexact ), *U, previousTimeStep );
387 timeAdvance->setInitialCondition (uv0);
389 timeAdvance-> setTimeStep (dataProblem->dataTime()->timeStep() );
391 timeAdvance->updateRHSContribution (dataProblem->dataTime()->timeStep() );
393 vector_type uComputed (uMap, Repeated );
394 vector_type uExa (uMap, Repeated );
395 vector_type vExa (uMap, Repeated );
396 vector_type wExa (uMap, Repeated );
398 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( uexact ), *Exact, 0 );
399 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( v0 ), *vExact, 0 );
400 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( a0 ), *wExact, 0 );
402 *U = timeAdvance->solution();
403 *V = timeAdvance->firstDerivative();
404 *W = timeAdvance->secondDerivative();
407 exporter->postProcess ( 0 );
412 for (
Real time = dt; time <= T; time += dt)
414 dataProblem->dataTime()->setTime (time);
418 std::cout << std::endl;
419 std::cout <<
" P - Now we are at time " << dataProblem->dataTime()->time() <<
" s." << std::endl;
424 timeAdvance->updateRHSContribution ( dt );
428 feSpace->l2ScalarProduct (source_in, rhs, time);
429 rhs += problem.matrMass() * timeAdvance->rhsContributionSecondDerivative();
432 problem.updateRHS (rhs );
435 problem.iterate ( bcH );
438 timeAdvance->shiftRight (*problem.solution() );
441 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( uexact ), *Exact, time );
442 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( v0 ), *vExact, time );
443 feSpace->interpolate (
static_cast<FESpace_type::function_Type> ( a0 ), *wExact, time );
445 *U = timeAdvance->solution();
446 *V = timeAdvance->firstDerivative();
447 *W = timeAdvance->secondDerivative();
450 exporter->postProcess ( time );
454 vector_type u (*problem.solution(), Repeated);
458 Real H1_Error, H1_RelError, L2_Error, L2_RelError;
460 L2_Error = feSpace->l2Error (uexact, u, time , &L2_RelError);
461 H1_Error = feSpace->h1Error (uExact, u, time , &H1_RelError);
464 out_norm.open (
"norm.txt", std::ios::app);
465 out_norm << time <<
" " 468 << L2_RelError <<
" " 469 << H1_RelError <<
"\n";
472 MPI_Barrier (MPI_COMM_WORLD);
477 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)