47 using namespace LifeV;
86 f = std::bind ( &UOne, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
93 f = std::bind ( &dataProblem::analyticalSolution, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
100 f = std::bind ( &dataProblem::analyticalFlux, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
113 GetPot command_line (argc, argv);
114 Members->data_file_name = command_line.follow (
"data", 2,
"-f",
"--file");
115 Members->xml_file_name = command_line.follow (
"parameterList.xml",
"--xml");
117 GetPot dataFile ( Members->data_file_name );
119 Members->discretization_section =
"darcy";
122 Members->comm.reset (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
124 Members->comm.reset (
new Epetra_SerialComm() );
139 LifeChrono chronoTotal;
140 LifeChrono chronoReadAndPartitionMesh;
141 LifeChrono chronoBoundaryCondition;
142 LifeChrono chronoFiniteElementSpace;
143 LifeChrono chronoProblem;
144 LifeChrono chronoProcess;
145 LifeChrono chronoError;
148 std::shared_ptr < Displayer > displayer (
new Displayer ( Members->comm ) );
154 GetPot dataFile ( Members->data_file_name.c_str() );
160 displayer->leaderPrint (
"The Darcy solver\n" );
163 chronoReadAndPartitionMesh.start();
169 darcyData->setup ( dataFile );
172 darcyData_Type::paramListPtr_Type linearAlgebraList = Teuchos::rcp (
new darcyData_Type::paramList_Type );
173 linearAlgebraList = Teuchos::getParametersFromXmlFile ( Members->xml_file_name );
176 darcyData->setLinearAlgebraList ( linearAlgebraList );
182 meshData.setup ( dataFile, Members->discretization_section +
"/space_discretization");
185 regionMeshPtr_Type fullMeshPtr (
new regionMesh_Type ( Members->comm ) );
188 if ( meshData.meshType() !=
"structured" )
191 readMesh ( *fullMeshPtr, meshData );
196 const std::string structuredSection = Members->discretization_section +
"/space_discretization/";
199 regularMesh2D ( *fullMeshPtr, 0,
200 dataFile ( ( structuredSection +
"nx" ).data(), 4 ),
201 dataFile ( ( structuredSection +
"ny" ).data(), 4 ),
202 dataFile ( ( structuredSection +
"verbose" ).data(),
false ),
203 dataFile ( ( structuredSection +
"lx" ).data(), 1. ),
204 dataFile ( ( structuredSection +
"ly" ).data(), 1. ) );
208 regionMeshPtr_Type meshPtr;
211 MeshPartitioner< regionMesh_Type > meshPart;
214 meshPart.doPartition ( fullMeshPtr, Members->comm );
217 meshPtr = meshPart.meshPartition();
221 chronoReadAndPartitionMesh.stop();
224 displayer->leaderPrint (
"Time for read and partition the mesh ",
225 chronoReadAndPartitionMesh.diff(),
"\n" );
230 chronoBoundaryCondition.start();
232 bcHandlerPtr_Type bcDarcy (
new bcHandler_Type );
234 setBoundaryConditions ( bcDarcy );
237 chronoBoundaryCondition.stop();
240 displayer->leaderPrint (
"Time for create the boundary conditions handler ",
241 chronoBoundaryCondition.diff(),
"\n" );
246 chronoFiniteElementSpace.start();
249 const ReferenceFE* refFE_primal (
static_cast<ReferenceFE*> (NULL) );
250 const QuadratureRule* qR_primal (
static_cast<QuadratureRule*> (NULL) );
251 const QuadratureRule* bdQr_primal (
static_cast<QuadratureRule*> (NULL) );
253 refFE_primal = &feTriaP0;
254 qR_primal = &quadRuleTria4pt;
255 bdQr_primal = &quadRuleSeg1pt;
258 const ReferenceFE* refFE_dual (
static_cast<ReferenceFE*> (NULL) );
259 const QuadratureRule* qR_dual (
static_cast<QuadratureRule*> (NULL) );
260 const QuadratureRule* bdQr_dual (
static_cast<QuadratureRule*> (NULL) );
262 refFE_dual = &feTriaRT0;
263 qR_dual = &quadRuleTria4pt;
264 bdQr_dual = &quadRuleSeg1pt;
267 const ReferenceFE* refFE_dualInterpolate (
static_cast<ReferenceFE*> (NULL) );
268 const QuadratureRule* qR_dualInterpolate (
static_cast<QuadratureRule*> (NULL) );
269 const QuadratureRule* bdQr_dualInterpolate (
static_cast<QuadratureRule*> (NULL) );
271 refFE_dualInterpolate = &feTriaP0;
272 qR_dualInterpolate = &quadRuleTria4pt;
273 bdQr_dualInterpolate = &quadRuleSeg1pt;
277 const ReferenceFE* refFE_hybrid (
static_cast<ReferenceFE*> (NULL) );
278 const QuadratureRule* qR_hybrid (
static_cast<QuadratureRule*> (NULL) );
279 const QuadratureRule* bdQr_hybrid (
static_cast<QuadratureRule*> (NULL) );
281 refFE_hybrid = &feTriaRT0Hyb;
282 qR_hybrid = &quadRuleTria4pt;
283 bdQr_hybrid = &quadRuleSeg1pt;
286 fESpacePtr_Type p_FESpacePtr (
new fESpace_Type ( meshPtr, *refFE_primal, *qR_primal,
287 *bdQr_primal, 1, Members->comm ) );
290 fESpacePtr_Type u_FESpacePtr (
new fESpace_Type ( meshPtr, *refFE_dual, *qR_dual,
291 *bdQr_dual, 1, Members->comm ) );
294 fESpacePtr_Type hybrid_FESpacePtr (
new fESpace_Type ( meshPtr, *refFE_hybrid, *qR_hybrid,
295 *bdQr_hybrid, 1, Members->comm ) );
298 fESpacePtr_Type uInterpolate_FESpacePtr (
new fESpace_Type ( meshPtr, *refFE_dualInterpolate, *qR_dualInterpolate,
299 *bdQr_dualInterpolate, 2, Members->comm ) );
302 chronoFiniteElementSpace.stop();
305 displayer->leaderPrint (
"Time for create the finite element spaces ",
306 chronoFiniteElementSpace.diff(),
"\n" );
309 chronoProblem.start();
312 darcySolver_Type darcySolver;
315 chronoProblem.stop();
318 displayer->leaderPrint (
"Time for create the problem ", chronoProblem.diff(),
"\n" );
323 chronoProcess.start ();
326 darcySolver.setData ( darcyData );
329 darcySolver.setDisplayer ( displayer );
332 darcySolver.setup ();
337 scalarFieldPtr_Type primalField (
new scalarField_Type ( p_FESpacePtr ) );
340 scalarFieldPtr_Type dualField (
new scalarField_Type ( u_FESpacePtr ) );
343 scalarFieldPtr_Type hybridField (
new scalarField_Type ( hybrid_FESpacePtr ) );
346 vectorFieldPtr_Type dualInterpolated (
new vectorField_Type ( uInterpolate_FESpacePtr, Repeated ) );
351 darcySolver.setHybridField ( hybridField );
354 darcySolver.setPrimalField ( primalField );
357 darcySolver.setDualField ( dualField );
360 scalarFctPtr_Type scalarSourceFct (
new scalarSource );
361 darcySolver.setScalarSource ( scalarSourceFct );
364 vectorFctPtr_Type vectorSourceFct (
new vectorSource );
365 darcySolver.setVectorSource ( vectorSourceFct );
368 scalarFctPtr_Type reactionTermFct (
new reactionTerm );
369 darcySolver.setReactionTerm ( reactionTermFct );
372 matrixFctPtr_Type inversePermeabilityFct (
new inversePermeability );
373 darcySolver.setInversePermeability ( inversePermeabilityFct );
376 scalarFctPtr_Type initialPrimalFct (
new initialCondition );
377 darcySolver.setInitialPrimal ( initialPrimalFct );
380 scalarFctPtr_Type massFct (
new massFunction );
381 darcySolver.setMass ( massFct );
384 darcySolver.setBoundaryConditions ( bcDarcy );
387 std::shared_ptr< Exporter< regionMesh_Type > > exporter;
390 vectorPtr_Type primalExporter;
393 vectorPtr_Type dualExporter;
396 std::string
const exporterType = dataFile (
"exporter/type",
"none" );
399 const std::string exporterFileName = dataFile (
"exporter/file_name",
"PressureVelocity" );
403 if ( exporterType.compare (
"hdf5") == 0 )
405 exporter.reset (
new ExporterHDF5 < regionMesh_Type > ( dataFile, exporterFileName ) );
410 exporter.reset (
new ExporterEmpty < regionMesh_Type > ( dataFile, exporterFileName ) );
414 exporter->setPostDir ( dataFile (
"exporter/folder",
"./" ) );
416 exporter->setMeshProcId ( meshPtr, Members->comm->MyPID() );
419 primalExporter.reset (
new vector_Type ( primalField->getVector(), exporter->mapType() ) );
422 exporter->addVariable ( ExporterData < regionMesh_Type >::ScalarField,
423 dataFile (
"exporter/name_primal",
"Pressure" ),
426 static_cast<UInt> ( 0 ),
427 ExporterData < regionMesh_Type >::UnsteadyRegime,
428 ExporterData < regionMesh_Type >::Cell );
431 dualExporter.reset (
new vector_Type ( dualInterpolated->getVector(), exporter->mapType() ) );
434 exporter->addVariable ( ExporterData < regionMesh_Type >::VectorField,
435 dataFile (
"exporter/name_dual",
"Velocity" ),
436 uInterpolate_FESpacePtr,
438 static_cast<UInt> ( 0 ),
439 ExporterData < regionMesh_Type >::UnsteadyRegime,
440 ExporterData < regionMesh_Type >::Cell );
443 displayer->leaderPrint (
"Number of unknowns : ",
444 hybrid_FESpacePtr->map().map ( Unique )->NumGlobalElements(),
"\n" );
447 exporter->exportPID ( meshPtr, Members->comm );
450 *primalExporter = primalField->getVector ();
453 exporter->postProcess ( darcyData->dataTimePtr()->initialTime() );
456 bool isLastTimeStep (
false );
459 const Real endTime = darcyData->dataTimePtr()->endTime();
462 const Real tolTime = 1e-10;
465 Real currentTime = darcyData->dataTimePtr()->time();
468 while ( darcyData->dataTimePtr()->time() < endTime && !isLastTimeStep )
471 const Real leftTime = endTime - currentTime;
474 if ( darcyData->dataTimePtr()->timeStep() > leftTime + tolTime )
477 darcyData->dataTimePtr()->setTimeStep ( leftTime );
480 isLastTimeStep =
true;
484 darcyData->dataTimePtr()->updateTime();
487 currentTime = darcyData->dataTimePtr()->time();
490 if ( displayer->isLeader() )
492 darcyData->dataTimePtr()->showMe();
496 darcySolver.solve ();
501 *primalExporter = primalField->getVector ();
504 dualInterpolated->getVector() = uInterpolate_FESpacePtr->feToFEInterpolate (
505 *u_FESpacePtr, dualField->getVector() );
508 *dualExporter = dualInterpolated->getVector();
511 exporter->postProcess ( currentTime );
516 chronoProcess.stop();
519 displayer->leaderPrint (
"Time for process ", chronoProcess.diff(),
"\n" );
529 Real primalL2Norm (0), exactPrimalL2Norm (0), primalL2Error (0), primalL2RelativeError (0);
530 Real dualL2Norm (0), exactDualL2Norm (0), dualL2Error (0), dualL2RelativeError (0);
533 displayer->leaderPrint (
"\nPRESSURE ERROR\n" );
536 primalL2Norm = p_FESpacePtr->l2Norm ( primalField->getVector () );
539 displayer->leaderPrint (
" L2 norm of primal unknown: ", primalL2Norm,
"\n" );
542 exactPrimalL2Norm = p_FESpacePtr->l2NormFunction ( Members->getAnalyticalSolution(),
543 darcyData->dataTimePtr()->endTime() );
546 displayer->leaderPrint (
" L2 norm of primal exact: ", exactPrimalL2Norm,
"\n" );
549 primalL2Error = p_FESpacePtr->l2ErrorWeighted ( Members->getAnalyticalSolution(),
550 primalField->getVector(),
552 darcyData->dataTimePtr()->endTime() );
555 displayer->leaderPrint (
" L2 error of primal unknown: ", primalL2Error,
"\n" );
558 primalL2RelativeError = primalL2Error / exactPrimalL2Norm;
561 displayer->leaderPrint (
" L2 relative error of primal unknown: ", primalL2RelativeError,
"\n" );
564 displayer->leaderPrint (
"\nINTERPOLATED DARCY VELOCITY ERROR\n" );
567 dualL2Norm = uInterpolate_FESpacePtr->l2Norm ( dualInterpolated->getVector() );
570 displayer->leaderPrint (
" L2 norm of dual unknown: ", dualL2Norm,
"\n" );
573 exactDualL2Norm = uInterpolate_FESpacePtr->l2NormFunction ( Members->getAnalyticalFlux(),
574 darcyData->dataTimePtr()->endTime() );
577 displayer->leaderPrint (
" L2 norm of dual exact: ", exactDualL2Norm,
"\n" );
580 dualL2Error = uInterpolate_FESpacePtr->l2Error ( Members->getAnalyticalFlux(),
581 dualInterpolated->getVector(),
582 darcyData->dataTimePtr()->endTime(),
586 displayer->leaderPrint (
" L2 error of dual unknown: ", dualL2Error,
"\n" );
589 dualL2RelativeError = dualL2Error / exactDualL2Norm;
592 displayer->leaderPrint (
" L2 relative error of Dual unknown: ", dualL2RelativeError,
"\n" );
598 displayer->leaderPrint (
"Time for compute errors ", chronoError.diff(),
"\n" );
604 displayer->leaderPrint (
"Total time for the computation ", chronoTotal.diff(),
"\n" );
607 return primalL2Error;
Real UOne(const Real &, const Real &, const Real &, const Real &, const ID &)
Standard functions.
darcySolver_Type::dataPtr_Type darcyDataPtr_Type
fct_type getAnalyticalSolution()
std::shared_ptr< Epetra_Comm > comm
LifeV::Real run()
To lunch the simulation.
darcy_nonlinear(int argc, char **argv)
Constructor.
std::function< Real(const Real &, const Real &, const Real &, const Real &, const ID &) > fct_type
fct_type getAnalyticalFlux()
double Real
Generic real data.
std::string discretization_section
std::string data_file_name
std::string xml_file_name