36 #include <Epetra_ConfigDefs.h> 39 #include <Epetra_MpiComm.h> 41 #include <Epetra_SerialComm.h> 45 #include <lifev/core/LifeV.hpp> 47 #include <lifev/core/algorithm/PreconditionerIfpack.hpp> 48 #include <lifev/core/algorithm/PreconditionerML.hpp> 50 #include <lifev/core/algorithm/SolverAztecOO.hpp> 51 #include <lifev/core/algorithm/LinearSolver.hpp> 53 #include <lifev/core/array/MatrixEpetra.hpp> 56 #include <lifev/core/filter/ExporterHDF5.hpp> 58 #include <lifev/core/filter/ExporterVTK.hpp> 61 #include <lifev/core/fem/FESpace.hpp> 62 #include <lifev/core/fem/BCManage.hpp> 64 #include <lifev/core/mesh/RegionMesh1DStructured.hpp> 65 #include <lifev/core/mesh/MeshData.hpp> 67 #include <lifev/core/solver/ADRAssembler.hpp> 69 #include <Teuchos_ParameterList.hpp> 70 #include <Teuchos_XMLParameterListHelpers.hpp> 71 #include <Teuchos_RCP.hpp> 73 using namespace LifeV;
83 return std::sin (
M_PI * 0.5 * x );
94 main (
int argc,
char* argv[] )
98 MPI_Init (&argc, &argv);
105 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_MpiComm (MPI_COMM_WORLD) );
106 ASSERT ( Comm->NumProc() < 2,
"The test does not run in parallel." );
108 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_SerialComm);
111 typedef RegionMesh<LinearLine> mesh_Type;
112 typedef MatrixEpetra<Real> matrix_Type;
113 typedef VectorEpetra vector_Type;
114 typedef std::shared_ptr<vector_Type> vectorPtr_Type;
115 typedef FESpace<mesh_Type, MapEpetra> feSpace_Type;
117 typedef LifeV::Preconditioner basePrec_Type;
118 typedef std::shared_ptr<basePrec_Type> basePrecPtr_Type;
119 typedef LifeV::PreconditionerIfpack prec_Type;
120 typedef std::shared_ptr<prec_Type> precPtr_Type;
122 typedef std::shared_ptr<feSpace_Type> feSpacePtr_Type;
125 const bool verbose (Comm->MyPID() == 0);
131 std::cout <<
" -- Reading the data ... " << std::flush;
133 GetPot dataFile (
"data" );
136 std::cout <<
" done ! " << std::endl;
143 std::cout <<
" -- Reading the mesh ... " << std::flush;
146 std::shared_ptr< mesh_Type > meshPtr (
new mesh_Type ( Comm ) );
149 regularMesh1D ( *meshPtr, 0,
150 dataFile (
"mesh/n", 20 ),
151 dataFile (
"mesh/verbose",
false ),
152 dataFile (
"mesh/length", 1. ),
153 dataFile (
"mesh/origin", 0. ) );
157 std::cout <<
" done ! " << std::endl;
163 std::cout <<
" -- Building FESpaces ... " << std::flush;
165 feSpacePtr_Type uFESpace (
new feSpace_Type ( meshPtr, feSegP1, quadRuleSeg1pt, quadRuleNode1pt, 1, Comm ) );
168 std::cout <<
" done ! " << std::endl;
172 std::cout <<
" ---> Dofs: " << uFESpace->dof().numTotalDof() << std::endl;
179 std::cout <<
" -- Building assembler ... " << std::flush;
181 ADRAssembler<mesh_Type, matrix_Type, vector_Type> adrAssembler;
184 std::cout <<
" done! " << std::endl;
189 std::cout <<
" -- Setting up assembler ... " << std::flush;
191 adrAssembler.setFespace (uFESpace);
194 std::cout <<
" done! " << std::endl;
199 std::cout <<
" -- Defining the matrix ... " << std::flush;
201 std::shared_ptr<matrix_Type> systemMatrix (
new matrix_Type ( uFESpace->map() ) );
204 std::cout <<
" done! " << std::endl;
211 std::cout <<
" -- Adding the diffusion ... " << std::flush;
213 adrAssembler.addDiffusion (systemMatrix, 1.);
216 std::cout <<
" done! " << std::endl;
220 std::cout <<
" Time needed : " << adrAssembler.diffusionAssemblyChrono().diffCumul() << std::endl;
225 std::cout <<
" -- Adding the mass ... " << std::flush;
227 adrAssembler.addMass (systemMatrix,
M_PI *
M_PI );
230 std::cout <<
" done! " << std::endl;
235 std::cout <<
" -- Closing the matrix ... " << std::flush;
237 systemMatrix->globalAssemble();
240 std::cout <<
" done ! " << std::endl;
246 std::cout <<
" -- Building the RHS ... " << std::flush;
248 vector_Type rhs (uFESpace->map(), Repeated);
250 vector_Type fInterpolated (uFESpace->map(), Repeated);
251 uFESpace->interpolate (
static_cast<feSpace_Type::function_Type> ( fRhs ), fInterpolated, 0.0 );
252 adrAssembler.addMassRhs (rhs, fInterpolated);
253 rhs.globalAssemble();
257 std::cout <<
" done ! " << std::endl;
263 std::cout <<
" -- Building the BCHandler ... " << std::flush;
267 BCFunctionBase BCu (
static_cast<feSpace_Type::function_Type> ( exactSolution ) );
269 bchandler.addBC (
"Dirichlet", Structured1DLabel::LEFT, Essential, Full, BCu, 1);
270 bchandler.addBC (
"Dirichlet", Structured1DLabel::RIGHT, Essential, Full, BCu, 1);
274 std::cout <<
" done ! " << std::endl;
279 std::cout <<
" -- Updating the BCs ... " << std::flush;
281 bchandler.bcUpdate (*uFESpace->mesh(), uFESpace->feBd(), uFESpace->dof() );
284 std::cout <<
" done ! " << std::endl;
289 std::cout <<
" -- Applying the BCs ... " << std::flush;
291 vectorPtr_Type rhsBC (
new vector_Type (rhs, Unique) );
292 bcManage (*systemMatrix, *rhsBC, *uFESpace->mesh(), uFESpace->dof(), bchandler, uFESpace->feBd(), 1.0, 0.0);
296 std::cout <<
" done ! " << std::endl;
302 std::cout <<
" -- Building the solver ... " << std::flush;
304 LinearSolver linearSolver;
308 std::cout <<
" done ! " << std::endl;
313 std::cout <<
" -- Setting up the solver ... " << std::flush;
315 Teuchos::RCP< Teuchos::ParameterList > belosList = Teuchos::rcp (
new Teuchos::ParameterList );
316 belosList = Teuchos::getParametersFromXmlFile (
"SolverParamList.xml" );
318 linearSolver.setCommunicator ( Comm );
319 linearSolver.setParameters ( *belosList );
321 prec_Type* precRawPtr;
322 basePrecPtr_Type precPtr;
323 precRawPtr =
new prec_Type;
324 precRawPtr->setDataFromGetPot ( dataFile,
"prec" );
325 precPtr.reset ( precRawPtr );
326 linearSolver.setPreconditioner ( precPtr );
329 std::cout <<
" done ! " << std::endl;
334 std::cout <<
" -- Setting matrix in the solver ... " << std::flush;
336 linearSolver.setOperator ( systemMatrix );
339 std::cout <<
" done ! " << std::endl;
345 std::cout <<
" -- Defining the solution ... " << std::flush;
347 vectorPtr_Type solution (
new vector_Type (uFESpace->map(), Unique) );
350 std::cout <<
" done ! " << std::endl;
356 std::cout <<
" -- Solving the system ... " << std::flush;
358 linearSolver.setRightHandSide ( rhsBC );
359 linearSolver.solve ( solution );
362 std::cout <<
" done ! " << std::endl;
368 std::cout <<
" -- Computing the error ... " << std::flush;
370 vector_Type solutionErr (*solution);
371 uFESpace->interpolate (
static_cast<feSpace_Type::function_Type> ( exactSolution ), solutionErr, 0.0 );
372 solutionErr -= *solution;
374 Real l2error (uFESpace->l2Error (exactSolution, vector_Type (*solution, Repeated), 0.0) );
377 std::cout <<
" -- done ! " << std::endl;
381 std::cout <<
" ---> Norm L2 : " << l2error << std::endl;
383 Real linferror ( solutionErr.normInf() );
386 std::cout <<
" ---> Norm Inf : " << linferror << std::endl;
392 std::cout <<
" -- Defining the exporter ... " << std::flush;
396 ExporterHDF5<mesh_Type> exporter ( dataFile,
"solution" );
398 ExporterVTK<mesh_Type> exporter ( dataFile,
"solution" );
400 exporter.setMeshProcId ( meshPtr, Comm->MyPID() ) ;
403 std::cout <<
" done ! " << std::endl;
408 std::cout <<
" -- Defining the exported quantities ... " << std::flush;
411 std::shared_ptr<vector_Type> solutionPtr (
new vector_Type (*solution, Repeated) );
412 std::shared_ptr<vector_Type> solutionErrPtr (
new vector_Type (solutionErr, Repeated) );
416 std::cout <<
" done ! " << std::endl;
421 std::cout <<
" -- Updating the exporter ... " << std::flush;
423 exporter.addVariable ( ExporterData<mesh_Type>::ScalarField,
"solution", uFESpace, solutionPtr, UInt (0) );
424 exporter.addVariable ( ExporterData<mesh_Type>::ScalarField,
"error", uFESpace, solutionErrPtr, UInt (0) );
427 std::cout <<
" done ! " << std::endl;
432 std::cout <<
" -- Exporting ... " << std::flush;
434 exporter.postProcess (0);
437 std::cout <<
" done ! " << std::endl;
440 if ( std::fabs ( l2error - 0.0006169843149652788l ) > 1e-10 )
442 std::cout <<
" <!> Solution has changed !!! <!> " << std::endl;
445 if ( std::fabs ( linferror - 0.0001092814405985187l ) > 1e-10 )
447 std::cout <<
" <!> Solution has changed !!! <!> " << std::endl;
453 std::cout <<
"End Result: TEST PASSED" << std::endl;
462 return ( EXIT_SUCCESS );
Real exactSolution(const Real &t, const Real &x, const Real &y, const Real &z, const ID &)
static const LifeV::UInt elm_nodes_num[]
double Real
Generic real data.
Real fRhs(const Real &, const Real &x, const Real &, const Real &, const ID &)
int main(int argc, char **argv)