36 #include <Epetra_ConfigDefs.h> 39 #include <Epetra_MpiComm.h> 41 #include <Epetra_SerialComm.h> 44 #include <Teuchos_ParameterList.hpp> 45 #include <Teuchos_XMLParameterListHelpers.hpp> 46 #include <Teuchos_RCP.hpp> 49 #include <lifev/core/LifeV.hpp> 50 #include <lifev/core/mesh/RegionMesh3DStructured.hpp> 51 #include <lifev/core/mesh/MeshData.hpp> 52 #include <lifev/core/mesh/RegionMesh.hpp> 53 #include <lifev/core/mesh/MeshUtility.hpp> 54 #include <lifev/core/mesh/MeshPartitioner.hpp> 55 #include <lifev/core/fem/FESpace.hpp> 56 #include <lifev/core/fem/BCManage.hpp> 57 #include <lifev/core/array/MatrixEpetra.hpp> 58 #include <lifev/core/solver/ADRAssembler.hpp> 59 #include <lifev/core/algorithm/PreconditionerLinearSolver.hpp> 60 #include <lifev/core/algorithm/SolverAztecOO.hpp> 61 #include <lifev/core/algorithm/LinearSolver.hpp> 62 #include <lifev/core/function/Laplacian.hpp> 64 #define TEST_TOLERANCE 1e-13
66 using namespace LifeV;
80 typedef LifeV::PreconditionerLinearSolver
prec_Type;
92 Real uRelativeError, uL2Error;
93 uL2Error = uFESpace->l2Error (Laplacian::uexact, velocity, 0, &uRelativeError );
96 std::cout <<
"Velocity" << std::endl;
100 std::cout <<
" L2 error : " << uL2Error << std::endl;
104 std::cout <<
" Relative error: " << uRelativeError << std::endl;
116 MPI_Init (&argc, &argv);
119 bool verbose (
true );
124 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
126 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_SerialComm );
129 verbose = (Comm->MyPID() == 0);
134 <<
" +-----------------------------------------------+" << std::endl
135 <<
" | LinearSolverPreconditioner Test |" << std::endl
136 <<
" +-----------------------------------------------+" << std::endl
138 <<
" +-----------------------------------------------+" << std::endl
139 <<
" | Author: Gwenol Grandperrin |" << std::endl
140 <<
" | Date: 2013-01-16 |" << std::endl
141 <<
" +-----------------------------------------------+" << std::endl
144 std::cout <<
"[Initilization of MPI]" << std::endl;
146 std::cout <<
"Using MPI (" << Comm->NumProc() <<
" proc.)" << std::endl;
148 std::cout <<
"Using serial version" << std::endl;
157 std::cout << std::endl <<
"[Loading the data]" << std::endl;
159 LifeChrono globalChrono;
161 globalChrono.start();
164 GetPot command_line ( argc, argv );
165 const std::string dataFileName = command_line.follow (
"data", 2,
"-f",
"--file" );
166 GetPot dataFile ( dataFileName );
170 const UInt numMeshElem = dataFile (
"mesh/num_elements", 10);
171 const std::string uOrder = dataFile (
"finite_element/velocity",
"P1" );
174 Laplacian::setModes ( 1, 1, 1 );
181 std::cout << std::endl <<
"[Loading the mesh]" << std::endl;
184 meshPtr_Type fullMeshPtr (
new mesh_Type );
185 const UInt& geoDim =
static_cast<UInt> ( mesh_Type::S_geoDimensions );
190 regularMesh3D ( *fullMeshPtr,
192 numMeshElem, numMeshElem, numMeshElem,
197 if ( verbose ) std::cout <<
"Mesh source: regular mesh(" 198 << numMeshElem <<
"x" << numMeshElem <<
"x" << numMeshElem <<
")" << std::endl;
202 std::cout <<
"Mesh size : " << MeshUtility::MeshStatistics::computeSize ( *fullMeshPtr ).maxH << std::endl;
206 std::cout <<
"Partitioning the mesh ... " << std::endl;
209 meshPtr_Type meshPtr;
211 MeshPartitioner< mesh_Type > meshPart ( fullMeshPtr, Comm );
212 meshPtr = meshPart.meshPartition();
221 std::cout << std::endl <<
"[Creating the FE spaces]" << std::endl;
225 std::cout <<
"FE for the velocity: " << uOrder << std::endl;
230 std::cout <<
"Building the velocity FE space ... " << std::flush;
232 fespacePtr_Type uFESpace (
new fespace_Type ( meshPtr, uOrder, geoDim, Comm ) );
235 std::cout <<
"ok." << std::endl;
239 UInt numDofs = geoDim * uFESpace->dof().numTotalDof();
243 std::cout <<
"Total Velocity Dof: " << numDofs << std::endl;
251 std::cout << std::endl <<
"[Boundary conditions]" << std::endl;
254 BCFunctionBase uExact ( Laplacian::uexact );
255 BCFunctionBase fRHS ( Laplacian::f );
259 std::cout <<
"Setting Dirichlet BC... " << std::flush;
261 for ( UInt iDirichlet ( 1 ); iDirichlet <= 26; ++iDirichlet )
263 bcHandler.addBC (
"Wall", iDirichlet, Essential, Full, uExact, geoDim );
267 std::cout <<
"ok." << std::endl;
271 bcHandler.bcUpdate ( *uFESpace->mesh(), uFESpace->feBd(), uFESpace->dof() );
278 std::cout << std::endl <<
"[Matrices Assembly]" << std::endl;
283 std::cout <<
"Setting up assembler... " << std::flush;
285 ADRAssembler<mesh_Type, matrix_Type, vector_Type> adrAssembler;
286 adrAssembler.setup ( uFESpace, uFESpace );
289 std::cout <<
"done" << std::endl;
294 std::cout <<
"Defining the matrices... " << std::flush;
296 std::shared_ptr<matrix_Type> systemMatrix (
new matrix_Type ( uFESpace->map() ) );
299 std::cout <<
"done" << std::endl;
304 std::cout <<
"Adding the viscous stress... " << std::flush;
306 adrAssembler.addDiffusion ( systemMatrix, 1.0 );
309 std::cout <<
"done" << std::endl;
317 std::cout << std::endl <<
"[Solvers initialization]" << std::endl;
319 prec_Type* precRawPtr;
320 basePrecPtr_Type precPtr;
321 precRawPtr =
new prec_Type;
322 precRawPtr->setDataFromGetPot ( dataFile,
"prec/LinearSolver" );
323 precPtr.reset ( precRawPtr );
327 std::cout <<
"Setting up LinearSolver (Belos)... " << std::flush;
329 Teuchos::RCP< Teuchos::ParameterList > belosList = Teuchos::rcp (
new Teuchos::ParameterList );
330 belosList = Teuchos::getParametersFromXmlFile (
"SolverParamList.xml" );
332 LinearSolver linearSolver;
333 linearSolver.setCommunicator ( Comm );
334 linearSolver.setParameters ( *belosList );
335 linearSolver.setPreconditioner ( precPtr );
338 std::cout <<
"done" << std::endl;
340 linearSolver.showMe();
347 std::cout << std::endl <<
"[Initialization of the simulation]" << std::endl;
351 std::cout <<
"Creation of vectors... " << std::flush;
354 std::shared_ptr<vector_Type> rhs;
355 rhs.reset (
new vector_Type ( uFESpace->map(), Repeated ) );
357 vector_Type fInterpolated ( uFESpace->map(), Repeated );
358 adrAssembler.addMassRhs ( *rhs, fRHS, 0.0 );
359 rhs->globalAssemble();
362 std::cout <<
"done" << std::endl;
366 uFESpace->interpolate ( uExact, fInterpolated, 0.0 );
371 std::cout <<
"Applying BC... " << std::flush;
373 systemMatrix->globalAssemble();
374 std::shared_ptr<vector_Type> rhsBC;
375 rhsBC.reset (
new vector_Type ( *rhs, Unique ) );
376 bcManage ( *systemMatrix, *rhsBC, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
379 std::cout <<
"done" << std::endl;
384 std::cout << std::endl <<
"Solving the system with LinearSolver (Belos)... " << std::endl;
386 std::shared_ptr<vector_Type> solution;
387 solution.reset (
new vector_Type ( uFESpace->map(), Unique ) );
388 linearSolver.setOperator ( systemMatrix );
389 linearSolver.setRightHandSide ( rhsBC );
390 linearSolver.solve ( solution );
397 std::cout << std::endl <<
"[Errors computation]" << std::endl;
400 vector_Type solution2Err ( *solution );
402 uFESpace->interpolate (
static_cast<function_Type> ( Laplacian::uexact ), solution2Err, 0.0 );
403 solution2Err -= *solution;
408 std::cout <<
"Linear solver Belos" << std::endl;
410 printErrors ( *solution, uFESpace, verbose );
418 std::cout << std::endl <<
"Total simulation time: " << globalChrono.diff() <<
" s." << std::endl;
422 std::cout << std::endl <<
"[[END_SIMULATION]]" << std::endl;
425 exit_status = (linearSolver.numIterations() >= 6 || precRawPtr->solverPtr()->numIterations() >= 8);
437 std::cout <<
"The number of iterations has changed." << std::endl;
441 std::cout <<
"Test status: FAILED" << std::endl;
443 return ( EXIT_FAILURE );
449 std::cout <<
"Test status: SUCCESS" << std::endl;
452 return ( EXIT_SUCCESS );
LifeV::Preconditioner basePrec_Type
LifeV::PreconditionerIfpack prec_Type
std::shared_ptr< mesh_Type > meshPtr_Type
FESpace - Short description here please!
FESpace< mesh_Type, MapEpetra > fespace_Type
RegionMesh< LinearTetra > mesh_Type
std::shared_ptr< basePrec_Type > basePrecPtr_Type
void printErrors(const vector_Type &solution, fespacePtr_Type uFESpace, bool verbose)
double Real
Generic real data.
std::shared_ptr< fespace_Type > fespacePtr_Type
MatrixEpetra< Real > matrix_Type
std::shared_ptr< VectorEpetra > vectorPtr_Type
int main(int argc, char **argv)
std::function< Real(Real const &, Real const &, Real const &, Real const &, UInt const &) > function_Type
std::shared_ptr< prec_Type > precPtr_Type