36 #include <Epetra_ConfigDefs.h> 39 #include <Epetra_MpiComm.h> 41 #include <Epetra_SerialComm.h> 45 #include <lifev/core/LifeV.hpp> 48 #include <lifev/core/algorithm/PreconditionerIfpack.hpp> 49 #include <lifev/core/algorithm/PreconditionerML.hpp> 51 #include <lifev/core/algorithm/SolverAztecOO.hpp> 52 #include <lifev/core/algorithm/LinearSolver.hpp> 54 #include <lifev/core/array/MatrixEpetra.hpp> 56 #include <lifev/core/filter/ExporterEnsight.hpp> 58 #include <lifev/core/fem/FESpace.hpp> 59 #include <lifev/core/fem/BCManage.hpp> 61 #include <lifev/core/mesh/MeshPartitioner.hpp> 62 #include <lifev/core/mesh/RegionMesh3DStructured.hpp> 63 #include <lifev/core/mesh/RegionMesh.hpp> 65 #include <lifev/core/solver/ADRAssembler.hpp> 66 #include <lifev/core/mesh/MeshData.hpp> 68 #include <Teuchos_ParameterList.hpp> 69 #include <Teuchos_XMLParameterListHelpers.hpp> 70 #include <Teuchos_RCP.hpp> 72 using namespace LifeV;
88 Real exactSolution (
const Real& ,
const Real& x,
const Real& ,
const Real& ,
const ID& )
90 Real seps (std::sqrt (epsilon) );
91 return std::exp (seps * x) / (std::exp (seps) - std::exp (-seps) );
98 Real exactSolution (
const Real& ,
const Real& x,
const Real& ,
const Real& ,
const ID& )
100 return (std::exp (x / epsilon) - 1 ) / ( std::exp (1 / epsilon) - 1);
103 Real betaFct (
const Real& ,
const Real& ,
const Real& ,
const Real& ,
const ID& i )
105 return Real (i == 0);
114 return std::sin (x + y) + z * z / 2;
120 return 2 * std::sin (x + y) - 1;
144 MPI_Init (&argc, &argv);
145 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_MpiComm (MPI_COMM_WORLD) );
147 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_SerialComm);
150 const bool verbose (Comm->MyPID() == 0);
156 std::cout <<
" -- Reading the data ... " << std::flush;
158 GetPot dataFile (
"data" );
161 std::cout <<
" done ! " << std::endl;
164 const UInt Nelements (dataFile (
"mesh/nelements", 10) );
167 std::cout <<
" ---> Number of elements : " << Nelements << std::endl;
174 std::cout <<
" -- Building the mesh ... " << std::flush;
176 std::shared_ptr< mesh_Type > fullMeshPtr (
new RegionMesh<LinearTetra> ( Comm ) );
177 regularMesh3D ( *fullMeshPtr, 1, Nelements, Nelements, Nelements,
false,
182 std::cout <<
" done ! " << std::endl;
187 std::cout <<
" -- Partitioning the mesh ... " << std::flush;
189 std::shared_ptr< mesh_Type > meshPtr;
191 MeshPartitioner< mesh_Type > meshPart (fullMeshPtr, Comm);
192 meshPtr = meshPart.meshPartition();
196 std::cout <<
" done ! " << std::endl;
201 std::cout <<
" -- Freeing the global mesh ... " << std::flush;
206 std::cout <<
" done ! " << std::endl;
213 std::cout <<
" -- Building FESpaces ... " << std::flush;
215 std::string uOrder (
"P1");
216 std::string bOrder (
"P1");
217 std::shared_ptr<FESpace< mesh_Type, MapEpetra > > uFESpace (
new FESpace< mesh_Type, MapEpetra > (meshPtr, uOrder, 1, Comm) );
218 std::shared_ptr<FESpace< mesh_Type, MapEpetra > > betaFESpace (
new FESpace< mesh_Type, MapEpetra > (meshPtr, bOrder, 3, Comm) );
221 std::cout <<
" done ! " << std::endl;
225 std::cout <<
" ---> Dofs: " << uFESpace->dof().numTotalDof() << std::endl;
232 std::cout <<
" -- Building assembler ... " << std::flush;
234 ADRAssembler<mesh_Type, matrix_Type, vector_Type> adrAssembler;
237 std::cout <<
" done! " << std::endl;
242 std::cout <<
" -- Setting up assembler ... " << std::flush;
244 adrAssembler.setup (uFESpace, betaFESpace);
247 std::cout <<
" done! " << std::endl;
252 std::cout <<
" -- Defining the matrix ... " << std::flush;
254 std::shared_ptr<matrix_Type> systemMatrix (
new matrix_Type ( uFESpace->map() ) );
255 *systemMatrix *= 0.0;
258 std::cout <<
" done! " << std::endl;
265 std::cout <<
" -- Adding the diffusion ... " << std::flush;
267 adrAssembler.addDiffusion (systemMatrix, epsilon);
270 std::cout <<
" done! " << std::endl;
274 std::cout <<
" Time needed : " << adrAssembler.diffusionAssemblyChrono().diffCumul() << std::endl;
277 #ifdef TEST_ADVECTION 280 std::cout <<
" -- Adding the advection ... " << std::flush;
282 vector_Type beta (betaFESpace->map(), Repeated);
283 betaFESpace->interpolate (betaFct, beta, 0.0);
284 adrAssembler.addAdvection (systemMatrix, beta);
287 std::cout <<
" done! " << std::endl;
293 std::cout <<
" -- Adding the mass ... " << std::flush;
295 adrAssembler.addMass (systemMatrix, 1.0);
298 std::cout <<
" done! " << std::endl;
304 std::cout <<
" -- Closing the matrix ... " << std::flush;
306 systemMatrix->globalAssemble();
309 std::cout <<
" done ! " << std::endl;
313 Real matrixNorm (systemMatrix->norm1() );
316 std::cout <<
" ---> Norm 1 : " << matrixNorm << std::endl;
318 if ( std::fabs (matrixNorm - 1.68421 ) > 1e-3)
320 std::cout <<
" <!> Matrix has changed !!! <!> " << std::endl;
329 std::cout <<
" -- Building the RHS ... " << std::flush;
332 vector_Type rhs (uFESpace->map(), Repeated);
336 vector_Type fInterpolated (uFESpace->map(), Repeated);
337 fInterpolated *= 0.0;
338 uFESpace->interpolate (
static_cast<feSpace_Type::function_Type> ( fRhs ), fInterpolated, 0.0 );
339 adrAssembler.addMassRhs (rhs, fInterpolated);
340 rhs.globalAssemble();
345 std::cout <<
" done ! " << std::endl;
352 std::cout <<
" -- Building the BCHandler ... " << std::flush;
355 BCFunctionBase BCu ( exactSolution );
356 bchandler.addBC (
"Dirichlet", 1, Essential, Full, BCu, 1);
357 for (UInt i (2); i <= 6; ++i)
359 bchandler.addBC (
"Dirichlet", i, Essential, Full, BCu, 1);
363 std::cout <<
" done ! " << std::endl;
368 std::cout <<
" -- Updating the BCs ... " << std::flush;
370 bchandler.bcUpdate (*uFESpace->mesh(), uFESpace->feBd(), uFESpace->dof() );
373 std::cout <<
" done ! " << std::endl;
378 std::cout <<
" -- Applying the BCs ... " << std::flush;
380 vectorPtr_Type rhsBC (
new vector_Type (rhs, Unique) );
381 bcManage (*systemMatrix, *rhsBC, *uFESpace->mesh(), uFESpace->dof(), bchandler, uFESpace->feBd(), 1.0, 0.0);
385 std::cout <<
" done ! " << std::endl;
397 std::cout <<
" -- Building the solver ... " << std::flush;
399 LinearSolver linearSolver;
401 Teuchos::RCP< Teuchos::ParameterList > belosList = Teuchos::rcp (
new Teuchos::ParameterList );
402 belosList = Teuchos::getParametersFromXmlFile (
"SolverParamList.xml" );
404 linearSolver.setCommunicator ( Comm );
405 linearSolver.setParameters ( *belosList );
407 prec_Type* precRawPtr;
408 basePrecPtr_Type precPtr;
409 precRawPtr =
new prec_Type;
410 precRawPtr->setDataFromGetPot ( dataFile,
"prec" );
411 precPtr.reset ( precRawPtr );
412 linearSolver.setPreconditioner ( precPtr );
415 std::cout <<
" done ! " << std::endl;
420 std::cout <<
" -- Setting up the solver ... " << std::flush;
425 std::cout <<
" done ! " << std::endl;
430 std::cout <<
" -- Setting matrix in the solver ... " << std::flush;
432 linearSolver.setOperator ( systemMatrix );
435 std::cout <<
" done ! " << std::endl;
442 std::cout <<
" -- Defining the solution ... " << std::flush;
444 vectorPtr_Type solution (
new vector_Type (uFESpace->map(), Unique) );
448 std::cout <<
" done ! " << std::endl;
455 std::cout <<
" -- Solving the system ... " << std::flush;
457 linearSolver.setRightHandSide ( rhsBC );
458 linearSolver.solve ( solution );
461 std::cout <<
" done ! " << std::endl;
472 std::cout <<
" -- Computing the error ... " << std::flush;
474 vector_Type solutionErr (*solution);
476 uFESpace->interpolate (
static_cast<feSpace_Type::function_Type> ( exactSolution ), solutionErr, 0.0 );
477 solutionErr -= *solution;
479 Real l2error (uFESpace->l2Error (exactSolution, vector_Type (*solution, Repeated), 0.0) );
482 std::cout <<
" -- done ! " << std::endl;
486 std::cout <<
" ---> Norm L2 : " << l2error << std::endl;
488 Real linferror ( solutionErr.normInf() );
491 std::cout <<
" ---> Norm Inf : " << linferror << std::endl;
495 if (l2error > 0.0055)
497 std::cout <<
" <!> Solution has changed !!! <!> " << std::endl;
500 if (linferror > 0.0046)
502 std::cout <<
" <!> Solution has changed !!! <!> " << std::endl;
510 std::cout <<
" -- Defining the exporter ... " << std::flush;
512 ExporterEnsight<mesh_Type> exporter ( dataFile, meshPtr,
"solution", Comm->MyPID() ) ;
515 std::cout <<
" done ! " << std::endl;
520 std::cout <<
" -- Defining the exported quantities ... " << std::flush;
523 std::shared_ptr<vector_Type> solutionPtr (
new vector_Type (*solution, Repeated) );
524 std::shared_ptr<vector_Type> solutionErrPtr (
new vector_Type (solutionErr, Repeated) );
528 std::cout <<
" done ! " << std::endl;
533 std::cout <<
" -- Updating the exporter ... " << std::flush;
535 exporter.addVariable ( ExporterData<mesh_Type>::ScalarField,
"solution", uFESpace, solutionPtr, UInt (0) );
536 exporter.addVariable ( ExporterData<mesh_Type>::ScalarField,
"error", uFESpace, solutionErrPtr, UInt (0) );
539 std::cout <<
" done ! " << std::endl;
544 std::cout <<
" -- Exporting ... " << std::flush;
546 exporter.postProcess (0);
549 std::cout <<
" done ! " << std::endl;
554 std::cout <<
"End Result: TEST PASSED" << std::endl;
561 return ( EXIT_SUCCESS );
VectorEpetra - The Epetra Vector format Wrapper.
LifeV::Preconditioner basePrec_Type
Real exactSolution(const Real &t, const Real &x, const Real &y, const Real &z, const ID &)
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
std::shared_ptr< vector_Type > vectorPtr_Type
MatrixEpetra< Real > matrix_Type
static const LifeV::UInt elm_nodes_num[]
LifeV::PreconditionerIfpack prec_Type
FESpace< mesh_Type, MapEpetra > feSpace_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
RegionMesh< LinearTetra > mesh_Type
double Real
Generic real data.
std::shared_ptr< prec_Type > precPtr_Type
std::shared_ptr< basePrec_Type > basePrecPtr_Type
std::shared_ptr< feSpace_Type > feSpacePtr_Type
Real fRhs(const Real &, const Real &x, const Real &, const Real &, const ID &)
int main(int argc, char **argv)