45 using namespace LifeV;
62 const Real Pi = 3.14159265358979323846264338328;
76 return 20.*std::exp ( - ( std::pow ( x * std::cos (2.*Pi * t) + y * std::sin (2.*Pi * t), 2.) + std::pow ( - x * std::sin (2.*Pi * t) + y * std::cos (2.*Pi * t), 2. ) ) );
84 const std::vector<Real>& u )
86 Vector physicalFluxVector (
static_cast<
UInt> (3) );
89 Real Entry0 = y * u[0] * u[1];
92 Real Entry1 = x * u[0] * u[2];
97 physicalFluxVector (
static_cast<UInt> (0) ) = Entry0;
98 physicalFluxVector (
static_cast<UInt> (1) ) = Entry1;
99 physicalFluxVector (
static_cast<UInt> (2) ) = Entry2;
101 return physicalFluxVector;
109 const std::vector<Real>& u )
111 Vector firstDerivativePhysicalFluxVector (
static_cast<
UInt> (3) );
114 Real Entry0 = y * u[1];
117 Real Entry1 = x * u[2];
122 firstDerivativePhysicalFluxVector (
static_cast<UInt> (0) ) = Entry0;
123 firstDerivativePhysicalFluxVector (
static_cast<UInt> (1) ) = Entry1;
124 firstDerivativePhysicalFluxVector (
static_cast<UInt> (2) ) = Entry2;
126 return firstDerivativePhysicalFluxVector;
241 f = std::bind ( &dataProblem::UOne, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
248 f = std::bind ( &dataProblem::UZero, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
255 f = std::bind ( &dataProblem::analyticalSolution, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
262 f = std::bind ( &dataProblem::physicalFlux, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
269 f = std::bind ( &dataProblem::firstDerivativePhysicalFlux, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
276 f = std::bind ( &dataProblem::source_in, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
283 f = std::bind ( &dataProblem::initialCondition, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
290 f = std::bind ( & dataProblem::initialCondition, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
297 f = std::bind ( & dataProblem::dual, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
311 GetPot command_line (argc, argv);
312 const std::string data_file_name = command_line.follow (
"data", 2,
"-f",
"--file");
313 GetPot dataFile ( data_file_name );
315 Members->data_file_name = data_file_name;
316 Members->discretization_section =
"hyperbolic";
319 std::cout <<
"Epetra Initialization" << std::endl;
320 Members->comm.reset (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
322 Members->comm.reset (
new Epetra_SerialComm() );
335 typedef SolverAztecOO solver_type;
337 typedef hyper::vector_Type vector_type;
338 typedef std::shared_ptr<vector_type> vector_ptrtype;
339 typedef FESpace< RegionMesh, MapEpetra > feSpace_Type;
340 typedef std::shared_ptr< feSpace_Type > feSpacePtr_Type;
342 LifeChrono chronoTotal;
343 LifeChrono chronoReadAndPartitionMesh;
344 LifeChrono chronoBoundaryCondition;
345 LifeChrono chronoFiniteElementSpace;
346 LifeChrono chronoProblem;
347 LifeChrono chronoProcess;
348 LifeChrono chronoTimeStep;
349 LifeChrono chronoError;
355 GetPot dataFile ( Members->data_file_name.c_str() );
358 bool isLeader = ( Members->comm->MyPID() == 0 );
366 std::cout <<
"The hyperbolic solver" << std::endl << std::flush;
370 chronoReadAndPartitionMesh.start();
376 dataHyperbolic.setup ( dataFile );
382 meshData.setup ( dataFile, Members->discretization_section +
"/space_discretization");
385 std::shared_ptr<RegionMesh> fullMeshPtr (
new RegionMesh ( Members->comm ) );
388 readMesh ( *fullMeshPtr, meshData );
391 std::shared_ptr<RegionMesh> meshPtr;
394 meshPtr = meshPart.meshPartition();
398 chronoReadAndPartitionMesh.stop();
402 std::cout <<
"Time for read and partition the mesh " <<
403 chronoReadAndPartitionMesh.diff() << std::endl << std::flush;
408 chronoBoundaryCondition.start();
410 BCFunctionBase dirichletBDfun;
412 dirichletBDfun.setFunction ( dataProblem::dirichlet );
414 BCHandler bcHyperbolic;
416 bcHyperbolic.addBC (
"Top", TOP, Essential, Scalar, dirichletBDfun );
417 bcHyperbolic.addBC (
"Bottom", BOTTOM, Essential, Scalar, dirichletBDfun );
418 bcHyperbolic.addBC (
"Left", LEFT, Essential, Scalar, dirichletBDfun );
419 bcHyperbolic.addBC (
"Right", RIGHT, Essential, Scalar, dirichletBDfun );
420 bcHyperbolic.addBC (
"Front", FRONT, Essential, Scalar, dirichletBDfun );
421 bcHyperbolic.addBC (
"Back", BACK, Essential, Scalar, dirichletBDfun );
424 chronoBoundaryCondition.stop();
429 std::cout <<
"Time for create the boundary conditions handler " <<
430 chronoBoundaryCondition.diff() << std::endl << std::flush;
437 chronoFiniteElementSpace.start();
453 pressure_refFE_dualInterpolate = &feTetraP0;
458 FESpace< RegionMesh, MapEpetra > pressure_uInterpolate_FESpace ( meshPtr, *pressure_refFE_dualInterpolate, *pressure_qR_dualInterpolate,
459 *pressure_bdQr_dualInterpolate, 3, Members->comm );
462 vector_ptrtype pressure_dualInterpolated (
new vector_type ( pressure_uInterpolate_FESpace.map(), Repeated ) );
464 pressure_uInterpolate_FESpace.interpolate (
static_cast<FESpace< RegionMesh, MapEpetra >::function_Type> ( dataProblem::dual ), *pressure_dualInterpolated, 0 );
467 feSpacePtr_Type feSpacePtr (
new feSpace_Type ( meshPtr,
474 GhostHandler<RegionMesh> ghost ( fullMeshPtr, meshPtr, feSpacePtr->mapPtr(), Members->comm );
477 chronoFiniteElementSpace.stop();
481 std::cout <<
"Time for create the finite element spaces " <<
482 chronoFiniteElementSpace.diff() << std::endl << std::flush;
485 chronoProblem.start();
488 hyper hyperbolicSolver ( dataHyperbolic,
490 ghost.ghostMapOnElementsFV(),
494 chronoProblem.stop();
497 hyperbolicSolver.getDisplayer().leaderPrint (
"Time for create the problem ",
498 chronoProblem.diff(),
"\n" );
503 chronoProcess.start();
506 hyperbolicSolver.setup();
509 hyperbolicSolver.setSourceTerm ( Members->getSource() );
512 hyperbolicSolver.setInitialSolution ( Members->getInitialCondition() );
515 hyperbolicSolver.setMassTerm ( Members->getMass() );
518 GodunovNumericalFlux < RegionMesh > numericalFlux ( Members->getPhysicalFlux(),
519 Members->getFirstDerivativePhysicalFlux(),
520 pressure_uInterpolate_FESpace,
522 "hyperbolic/numerical_flux/" );
525 numericalFlux.setExternalField ( pressure_dualInterpolated );
528 hyperbolicSolver.setNumericalFlux ( numericalFlux );
531 hyperbolicSolver.setBoundaryCondition ( bcHyperbolic );
534 std::shared_ptr< Exporter< RegionMesh > > exporter;
537 vector_ptrtype exporterSolution;
540 std::string
const exporterType = dataFile (
"exporter/type",
"ensight");
544 if ( exporterType.compare (
"hdf5") == 0 )
546 exporter.reset (
new ExporterHDF5< RegionMesh > ( dataFile, dataFile (
"exporter/file_name",
"Concentration" ) ) );
549 exporter->setPostDir ( dataFile (
"exporter/folder",
"./" ) );
551 exporter->setMeshProcId ( meshPtr, Members->comm->MyPID() );
556 if ( exporterType.compare (
"none") == 0 )
558 exporter.reset (
new ExporterEmpty< RegionMesh > ( dataFile, dataFile (
"exporter/file_name",
"Concentration" ) ) );
561 exporter->setPostDir ( dataFile (
"exporter/folder",
"./" ) );
563 exporter->setMeshProcId ( meshPtr, Members->comm->MyPID() );
567 exporter.reset (
new ExporterEnsight< RegionMesh > ( dataFile, dataFile (
"exporter/file_name",
"Concentration" ) ) );
570 exporter->setPostDir ( dataFile (
"exporter/folder",
"./" ) );
572 exporter->setMeshProcId ( meshPtr, Members->comm->MyPID() );
577 exporter->exportPID ( meshPtr, Members->comm );
580 exporter->exportFlags ( meshPtr, Members->comm );
583 exporterSolution.reset (
new vector_type ( *hyperbolicSolver.solution(),
584 exporter->mapType() ) );
587 exporter->addVariable ( ExporterData<RegionMesh>::ScalarField,
588 "Concentration", feSpacePtr,
590 static_cast<UInt> ( 0 ),
591 ExporterData<RegionMesh>::UnsteadyRegime,
592 ExporterData<RegionMesh>::Cell );
595 hyperbolicSolver.getDisplayer().leaderPrint (
"Number of unknowns : ",
596 feSpacePtr->map().map (Unique)->NumGlobalElements(),
"\n" );
603 *exporterSolution = *hyperbolicSolver.solution();
606 exporter->postProcess ( dataHyperbolic.dataTime()->initialTime() );
612 bool isLastTimeStep (
false );
615 while ( dataHyperbolic.dataTime()->canAdvance() && !isLastTimeStep )
619 chronoTimeStep.start();
622 if ( dataHyperbolic.dataTime()->isLastTimeStep() )
625 timeStep = dataHyperbolic.dataTime()->leftTime();
628 isLastTimeStep =
true;
633 timeStep = hyperbolicSolver.CFL();
637 dataHyperbolic.dataTime()->setTimeStep ( timeStep );
640 dataHyperbolic.dataTime()->updateTime();
643 if ( hyperbolicSolver.getDisplayer().isLeader() )
645 dataHyperbolic.dataTime()->showMe();
649 hyperbolicSolver.solveOneTimeStep();
654 *exporterSolution = *hyperbolicSolver.solution();
657 dataHyperbolic.dataTime()->updateTime();
660 exporter->postProcess ( dataHyperbolic.dataTime()->time() );
663 chronoTimeStep.stop();
666 hyperbolicSolver.getDisplayer().leaderPrint (
"Time for current time step ",
667 chronoTimeStep.diff(),
"\n" );
672 chronoProcess.stop();
675 hyperbolicSolver.getDisplayer().leaderPrint (
"Time for process ",
676 chronoProcess.diff(),
"\n" );
684 Real L2Norm (0), exactL2Norm (0), L2Error (0), L2RelativeError (0);
687 hyperbolicSolver.getDisplayer().leaderPrint (
"\nERROR\n" );
690 L2Norm = feSpacePtr->l2Norm ( *hyperbolicSolver.solution() );
693 hyperbolicSolver.getDisplayer().leaderPrint (
" L2 norm of solution: ",
697 exactL2Norm = feSpacePtr->l2NormFunction ( Members->getAnalyticalSolution(),
698 dataHyperbolic.dataTime()->endTime() );
701 hyperbolicSolver.getDisplayer().leaderPrint (
" L2 norm of exact solution: ",
705 L2Error = feSpacePtr->l2ErrorWeighted ( Members->getAnalyticalSolution(),
706 *hyperbolicSolver.solution(),
708 dataHyperbolic.dataTime()->endTime() );
711 hyperbolicSolver.getDisplayer().leaderPrint (
" L2 error: ",
715 L2RelativeError = L2Error / L2Norm;
718 hyperbolicSolver.getDisplayer().leaderPrint (
" L2 relative error: ",
719 L2RelativeError,
"\n" );
725 hyperbolicSolver.getDisplayer().leaderPrint (
"Time for compute errors ",
726 chronoError.diff(),
"\n" );
732 hyperbolicSolver.getDisplayer().leaderPrint (
"Total time for the computation ",
733 chronoTotal.diff(),
"\n" );
Real UOne(const Real &, const Real &, const Real &, const Real &, const ID &)
Real dirichlet(const Real &t, const Real &x, const Real &y, const Real &z, const ID &ic)
hyperbolic(int argc, char **argv)
Constructors.
Real dual(const Real &, const Real &, const Real &, const Real &, const ID &ic)
FESpace - Short description here please!
const QuadratureRule quadRuleTetra15pt(pt_tetra_15pt, 5, "Quadrature rule 15 points on a tetraedra", TETRA, 15, 5)
const QuadratureRule quadRuleTria4pt(pt_tria_4pt, 3, "Quadrature rule 4 points on a triangle", TRIANGLE, 4, 3)
Real UZero(const Real &, const Real &, const Real &, const Real &, const ID &)
vectorFct_type getPhysicalFlux()
vectorFct_type getFirstDerivativePhysicalFlux()
Vector firstDerivativePhysicalFlux(const Real &, const Real &x, const Real &y, const Real &, const std::vector< Real > &u)
std::string discretization_section
Real initialCondition(const Real &, const Real &x, const Real &y, const Real &z, const ID &ic)
Class for 3D, 2D and 1D Mesh.
std::function< Real(const Real &, const Real &, const Real &, const Real &, const ID &) > fct_type
std::shared_ptr< std::vector< Int > > M_isOnProc
std::function< Vector(const Real &, const Real &, const Real &, const Real &, const std::vector< Real > &) > vectorFct_type
MeshData - class for handling spatial discretization.
HyperbolicSolver Implements an hyperbolic solver.
std::shared_ptr< Epetra_Comm > comm
Real analyticalSolution(const Real &t, const Real &x, const Real &y, const Real &, const ID &)
Analytical solution.
double Real
Generic real data.
LifeV::Real run()
Methods.
The class for a reference Lagrangian finite element.
Real source_in(const Real &, const Real &, const Real &, const Real &, const ID &)
Real mass(const Real &, const Real &, const Real &, const Real &, const ID &)
Vector physicalFlux(const Real &, const Real &x, const Real &y, const Real &, const std::vector< Real > &u)
fct_type getAnalyticalSolution()
QuadratureRule - The basis class for storing and accessing quadrature rules.
std::string data_file_name
const QuadratureRule quadRuleTria1pt(pt_tria_1pt, 1, "Quadrature rule 1 point on a triangle", TRIANGLE, 1, 1)
uint32_type UInt
generic unsigned integer (used mainly for addressing)
fct_type getInitialCondition()