37 #include <Epetra_ConfigDefs.h> 39 #include <Epetra_MpiComm.h> 41 #include <Epetra_SerialComm.h> 44 #include <lifev/core/LifeV.hpp> 45 #include <lifev/core/util/LifeChronoManager.hpp> 47 #include <lifev/core/mesh/MeshPartitioner.hpp> 48 #include <lifev/core/mesh/RegionMesh3DStructured.hpp> 49 #include <lifev/core/mesh/RegionMesh.hpp> 50 #include <lifev/core/array/MatrixEpetra.hpp> 52 #include <lifev/core/fem/BCManage.hpp> 53 #include <lifev/eta/fem/ETFESpace.hpp> 54 #include <lifev/eta/expression/BuildGraph.hpp> 55 #include <lifev/eta/expression/Integrate.hpp> 56 #include <Epetra_FECrsGraph.h> 58 #include <Teuchos_ParameterList.hpp> 59 #include <Teuchos_XMLParameterListHelpers.hpp> 60 #include <Teuchos_RCP.hpp> 61 #include <lifev/core/algorithm/LinearSolver.hpp> 62 #include <lifev/core/algorithm/PreconditionerIfpack.hpp> 64 #include <lifev/core/filter/ExporterHDF5.hpp> 66 #include <boost/shared_ptr.hpp> 68 #include <lifev/eta/examples/laplacian/laplacianFunctor.hpp> 69 #include <lifev/core/mesh/RegionMesh.hpp> 70 #include <lifev/core/mesh/ElementShapes.hpp> 71 #include <lifev/core/mesh/MeshEntityContainer.hpp> 72 #include <lifev/core/mesh/MeshData.hpp> 74 using namespace LifeV;
94 return sin(
M_PI * y ) * sin(
M_PI * z ) * sin (
M_PI * x );
117 int main (
int argc,
char** argv )
122 MPI_Init ( &argc, &argv );
123 std::shared_ptr< Epetra_Comm > Comm (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
125 std::shared_ptr< Epetra_Comm > Comm (
new Epetra_SerialComm );
129 LifeChrono globalChrono;
130 LifeChrono initChrono;
132 globalChrono.start();
136 GetPot command_line ( argc, argv );
137 const std::string dataFileName = command_line.follow (
"data", 2,
"-f",
"--file" );
138 GetPot dataFile ( dataFileName );
140 const bool verbose ( Comm->MyPID() == 0 );
144 std::cout <<
"-- Building and partitioning the mesh... " << std::flush;
155 typedef RegionMesh< LinearTetra > mesh_Type;
157 std::shared_ptr< mesh_Type > fullMeshPtr (
new mesh_Type ( Comm ) );
161 regularMesh3D ( *fullMeshPtr, 0,
162 dataFile(
"mesh/nx", 15 ), dataFile(
"mesh/ny", 15 ), dataFile(
"mesh/nz", 15 ),
163 dataFile (
"mesh/verbose",
false ),
164 2.0, 2.0, 2.0, -1.0, -1.0, -1.0 );
168 const UInt overlap ( dataFile(
"mesh/overlap", 0 ) );
170 std::shared_ptr< mesh_Type > localMeshPtr;
172 MeshPartitioner< mesh_Type > meshPart;
176 meshPart.setPartitionOverlap ( overlap );
179 meshPart.doPartition ( fullMeshPtr, Comm );
180 localMeshPtr = meshPart.meshPartition();
189 std::cout <<
" done in " << initChrono.diff() <<
" s!" << std::endl;
201 typedef FESpace< mesh_Type, MapEpetra > uSpaceStd_Type;
202 typedef std::shared_ptr< uSpaceStd_Type > uSpaceStdPtr_Type;
204 typedef ETFESpace< mesh_Type, MapEpetra, 3, 1 > uSpaceETA_Type;
205 typedef std::shared_ptr< uSpaceETA_Type > uSpaceETAPtr_Type;
207 typedef FESpace<mesh_Type, MapEpetra>::function_Type function_Type;
211 std::cout <<
"-- Building finite elements spaces... " << std::flush;
215 uSpaceStdPtr_Type uFESpace (
new uSpaceStd_Type ( localMeshPtr, dataFile(
"finite_element/degree",
"P1" ), 1, Comm ) );
216 uSpaceETAPtr_Type ETuFESpace (
new uSpaceETA_Type ( localMeshPtr, & ( uFESpace->refFE() ), & ( uFESpace->fe().geoMap() ), Comm ) );
222 std::cout <<
" done in " << initChrono.diff() <<
" s! (Dofs: " << uFESpace->dof().numTotalDof() <<
")" << std::endl;
225 typedef Epetra_FECrsGraph graph_Type;
226 typedef std::shared_ptr<Epetra_FECrsGraph> graphPtr_Type;
228 typedef MatrixEpetra< Real > matrix_Type;
229 typedef std::shared_ptr< MatrixEpetra< Real > > matrixPtr_Type;
230 typedef VectorEpetra vector_Type;
231 typedef std::shared_ptr<VectorEpetra> vectorPtr_Type;
234 graphPtr_Type systemGraph;
235 matrixPtr_Type systemMatrix;
242 systemGraph.reset (
new graph_Type ( Copy, * ( uFESpace->map().map( Unique ) ), 50,
true ) );
246 systemGraph.reset (
new graph_Type ( Copy, * ( uFESpace->map().map( Unique ) ), 50 ) );
252 std::cout <<
"-- Assembling matrix graph... " << std::flush;
257 using namespace ExpressionAssembly;
260 elements ( localMeshPtr ),
264 dot ( grad ( phi_i ) , grad ( phi_j ) )
270 systemGraph->GlobalAssemble();
276 systemMatrix.reset(
new matrix_Type ( ETuFESpace->map(), *systemGraph,
true ) );
282 systemMatrix.reset(
new matrix_Type ( ETuFESpace->map(), *systemGraph ) );
290 std::cout <<
" done in " << initChrono.diff() <<
" s!" << std::endl;
294 systemMatrix->zero();
301 std::cout <<
"-- Assembling the Laplace matrix... " << std::flush;
305 using namespace ExpressionAssembly;
308 elements ( localMeshPtr ),
312 dot ( grad ( phi_i ) , grad ( phi_j ) )
321 std::cout <<
" done in " << initChrono.diff() <<
" s!" << std::endl;
328 vectorPtr_Type rhsLap;
329 vectorPtr_Type solutionLap;
334 rhsLap.reset (
new vector_Type ( uFESpace->map(), Unique, Zero ) );
335 solutionLap.reset (
new vector_Type ( uFESpace->map(), Unique, Zero ) );
341 rhsLap.reset (
new vector_Type ( uFESpace->map(), Unique ) );
342 solutionLap.reset (
new vector_Type ( uFESpace->map(), Unique ) );
350 std::shared_ptr<laplacianFunctor< Real > > laplacianSourceFunctor (
new laplacianFunctor< Real >( sourceFunction ) );
353 using namespace ExpressionAssembly;
356 elements ( localMeshPtr ),
359 eval(laplacianSourceFunctor, X) * phi_i
368 ExporterHDF5< mesh_Type > exporter ( dataFile,
"exporter" );
369 exporter.setMeshProcId( localMeshPtr, Comm->MyPID() );
370 exporter.setPrefix(
"laplace" );
371 exporter.setPostDir(
"./" );
373 exporter.addVariable ( ExporterData< mesh_Type >::ScalarField,
"temperature", uFESpace, solutionLap, UInt ( 0 ) );
382 std::cout <<
"-- Setting boundary conditions... " << std::flush;
384 systemMatrix->globalAssemble();
385 rhsLap->globalAssemble();
392 BCFunctionBase ZeroBC ( zeroFunction );
393 BCFunctionBase OneBC ( nonZeroFunction );
395 bcHandler.addBC(
"Back", BACK, Essential, Full, ZeroBC, 1 );
396 bcHandler.addBC(
"Left", LEFT, Essential, Full, ZeroBC, 1 );
397 bcHandler.addBC(
"Top", TOP, Essential, Full, ZeroBC, 1 );
399 bcHandler.addBC(
"Front", FRONT, Essential, Full, ZeroBC, 1 );
400 bcHandler.addBC(
"Right", RIGHT, Essential, Full, ZeroBC, 1 );
401 bcHandler.addBC(
"Bottom", BOTTOM, Essential, Full, ZeroBC, 1 );
403 bcHandler.bcUpdate( *uFESpace->mesh(), uFESpace->feBd(), uFESpace->dof() );
406 bcManage ( *systemMatrix, *rhsLap, *uFESpace->mesh(), uFESpace->dof(), bcHandler, uFESpace->feBd(), 1.0, 0.0 );
412 std::cout <<
" done in " << initChrono.diff() <<
" s!" << std::endl;
419 typedef LinearSolver::SolverType solver_Type;
421 typedef LifeV::Preconditioner basePrec_Type;
422 typedef std::shared_ptr<basePrec_Type> basePrecPtr_Type;
423 typedef PreconditionerIfpack prec_Type;
424 typedef std::shared_ptr<prec_Type> precPtr_Type;
429 std::cout <<
"-- Setting up the solver ... " << std::flush;
435 LinearSolver linearSolver ( Comm );
436 linearSolver.setOperator ( systemMatrix );
438 Teuchos::RCP< Teuchos::ParameterList > aztecList = Teuchos::rcp (
new Teuchos::ParameterList );
439 aztecList = Teuchos::getParametersFromXmlFile (
"SolverParamList.xml" );
441 linearSolver.setParameters ( *aztecList );
443 prec_Type* precRawPtr;
444 basePrecPtr_Type precPtr;
445 precRawPtr =
new prec_Type;
446 precRawPtr->setDataFromGetPot ( dataFile,
"prec" );
447 precPtr.reset ( precRawPtr );
449 linearSolver.setPreconditioner ( precPtr );
455 std::cout <<
" done in " << initChrono.diff() <<
" s!" << std::endl;
465 std::cout <<
"-- Solving problem ... " << std::flush;
471 linearSolver.setRightHandSide( rhsLap );
472 linearSolver.solve( solutionLap );
477 function_Type uEx(uExactFunction);
480 vectorPtr_Type uExPtrInterpolated(
new vector_Type (uFESpace->map(), Repeated) );
482 uExPtrInterpolated->zero();
484 uFESpace->interpolate (uEx, *uExPtrInterpolated, 0.0);
486 exporter.addVariable ( ExporterData< mesh_Type >::ScalarField,
"realTemperature", uFESpace, uExPtrInterpolated, UInt ( 0 ) );
490 Real L2ErrorLap = 0.0;
491 Real TotL2ErrorLap = 0.0;
493 Real H1SeminormLap = 0.0;
494 Real TotH1SeminormLap = 0.0;
496 std::shared_ptr<laplacianFunctor< Real > > laplacianExactFunctor (
new laplacianFunctor< Real >( uExactFunction ) );
497 std::shared_ptr<laplacianFunctor< VectorSmall<3> > > laplacianExactGradientFunctor (
new laplacianFunctor< VectorSmall<3> >( uGradExactFunction ) );
500 using namespace ExpressionAssembly;
503 elements ( localMeshPtr ),
505 ( eval(laplacianExactFunctor, X) - value (ETuFESpace, *solutionLap) )
506 * ( eval(laplacianExactFunctor, X) - value (ETuFESpace, *solutionLap) )
512 using namespace ExpressionAssembly;
515 elements ( localMeshPtr ),
517 dot( eval(laplacianExactGradientFunctor, X) - grad( ETuFESpace, *solutionLap ),
518 eval(laplacianExactGradientFunctor, X) - grad( ETuFESpace, *solutionLap ) )
524 Comm->SumAll (&L2ErrorLap, &TotL2ErrorLap, 1);
525 Comm->SumAll (&H1SeminormLap, &TotH1SeminormLap, 1);
529 std::cout <<
"TotError General in L2 norm is " << sqrt( TotL2ErrorLap ) << std::endl;
530 std::cout <<
"TotError General in H1 norm is " << sqrt( TotL2ErrorLap + TotH1SeminormLap ) << std::endl;
536 std::cout <<
" done in " << initChrono.diff() <<
" s!" << std::endl;
539 exporter.postProcess( 0 );
540 exporter.closeFile();
546 std::cout << std::endl <<
"Problem solved in " << globalChrono.diff() <<
" s!" << std::endl;
553 return ( EXIT_SUCCESS );
int main(int argc, char **argv)
VectorSmall< 3 > uGradExactFunction(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
Real & operator[](UInt const &i)
Operator [].
Real sourceFunction(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
Real uExactFunction(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
double Real
Generic real data.
Real zeroFunction(const Real &, const Real &, const Real &, const Real &, const ID &)
Real nonZeroFunction(const Real &t, const Real &, const Real &, const Real &, const ID &)