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/util/LifeChronoManager.hpp> 49 #include <lifev/core/array/MatrixEpetraStructured.hpp> 50 #include <lifev/core/array/VectorEpetraStructured.hpp> 52 #include <lifev/core/fem/FESpace.hpp> 54 #include <lifev/core/mesh/MeshPartitioner.hpp> 55 #include <lifev/core/mesh/RegionMesh2DStructured.hpp> 56 #include <lifev/core/mesh/RegionMesh.hpp> 57 #include <lifev/core/mesh/MeshData.hpp> 59 #include <lifev/eta/fem/ETFESpace.hpp> 60 #include <lifev/eta/expression/Integrate.hpp> 62 using namespace LifeV;
66 return sin ( x ) + y * y / 2.;
104 int main (
int argc,
char** argv )
108 MPI_Init (&argc, &argv);
117 commPtr_Type comm (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
121 LifeChronoManager<> chronoMgr ( comm );
124 chronoMgr.add (
"Initialization Time", &initTime );
127 GetPot dataFile (
"data_2d" );
128 const bool isLeader ( comm->MyPID() == 0 );
129 const bool verbose ( dataFile (
"miscellaneous/verbose", 0 ) && isLeader );
131 #ifdef HAVE_LIFEV_DEBUG 132 std::ofstream debugOut (
134 ( comm->NumProc() > 1 ? std::to_string ( comm->MyPID() ) :
"s" ) +
137 std::ofstream debugOut (
"/dev/null" );
145 chronoMgr.add (
"Mesh reading/creation Time", &initTime );
150 std::cout <<
" -- Reading the mesh ... " << std::flush;
152 meshPtr_Type fullMeshPtr (
new mesh_Type() );
153 if ( dataFile (
"mesh/mesh_type",
"structured" ) ==
"structured" )
155 regularMesh2D ( *fullMeshPtr, 0,
156 dataFile (
"mesh/nx", 20 ), dataFile (
"mesh/ny", 20 ),
157 dataFile (
"mesh/verbose",
false ),
158 dataFile (
"mesh/lx", 1. ), dataFile (
"mesh/ly", 1. ) );
162 MeshData meshData (dataFile,
"mesh");
163 readMesh (*fullMeshPtr, meshData);
167 std::cout <<
" done ! " << std::endl;
171 std::cout <<
"mesh elements = " << fullMeshPtr->numElements() <<
"\n" 172 <<
"mesh points = " << fullMeshPtr->numPoints() << std::endl;
179 std::cout <<
" -- Partitioning the mesh ... " << std::flush;
183 chronoMgr.add (
"Partition Time", &partTime );
185 meshPtr_Type localMesh;
187 MeshPartitioner< mesh_Type > meshPart;
188 meshPart.doPartition ( fullMeshPtr, comm );
189 localMesh = meshPart.meshPartition();
193 Int localMeshNum[ 2 ];
194 localMeshNum[ 0 ] = localMesh->numElements();
195 localMeshNum[ 1 ] = localMesh->numPoints();
196 Int maxMeshNum[ 2 ] = { 0, 0 };
197 comm->MaxAll ( localMeshNum, maxMeshNum, 2 );
201 std::cout <<
"part mesh elements = " << maxMeshNum[ 0 ] <<
"\n" 202 <<
"part mesh points = " << maxMeshNum[ 1 ] << std::endl;
205 LifeChrono partTimeR;
206 chronoMgr.add (
"Partition Time (R)", &partTimeR );
208 meshPtr_Type localMeshR;
210 MeshPartitioner< mesh_Type > meshPartR;
211 meshPartR.setPartitionOverlap ( 1 );
212 meshPartR.doPartition ( fullMeshPtr, comm );
213 localMeshR = meshPartR.meshPartition();
217 localMeshNum[ 0 ] = localMeshR->numElements();
218 localMeshNum[ 1 ] = localMeshR->numPoints();
221 comm->MaxAll ( localMeshNum, maxMeshNum, 2 );
225 std::cout <<
"part mesh elements (R) = " << maxMeshNum[ 0 ] <<
"\n" 226 <<
"part mesh points (R) = " << maxMeshNum[ 1 ] << std::endl;
231 std::cout <<
" done ! " << std::endl;
236 std::cout <<
" -- Freeing the global mesh ... " << std::flush;
240 #ifdef HAVE_LIFEV_DEBUG 241 ASSERT ( fullMeshPtr.use_count() == 0,
"full mesh not properly freed." );
245 std::cout <<
" done ! " << std::endl;
252 std::cout <<
" -- Building FESpaces ... " << std::flush;
254 LifeChrono feSpaceTime;
255 chronoMgr.add (
"FESpace creation Time", &feSpaceTime );
257 uSpaceStdPtr_Type uSpaceStd (
new uSpaceStd_Type ( localMesh,
"P2", 2, comm ) );
258 uSpacePtr_Type uSpace (
new uSpace_Type ( localMesh, &feTriaP2, & (uSpaceStd->fe().geoMap() ), comm) );
259 pSpacePtr_Type pSpace (
new pSpace_Type ( localMesh, &feTriaP1, & (uSpaceStd->fe().geoMap() ), comm) );
262 LifeChrono feSpaceTimeR;
263 chronoMgr.add (
"FESpace creation Time (R)", &feSpaceTimeR );
264 feSpaceTimeR.start();
265 uSpaceStdPtr_Type uSpaceStdR (
new uSpaceStd_Type ( localMeshR,
"P2", 2, comm ) );
266 uSpacePtr_Type uSpaceR (
new uSpace_Type ( localMeshR, &feTriaP2, & (uSpaceStdR->fe().geoMap() ), comm) );
267 pSpacePtr_Type pSpaceR (
new pSpace_Type ( localMeshR, &feTriaP1, & (uSpaceStdR->fe().geoMap() ), comm) );
272 std::cout <<
" done ! " << std::endl;
276 std::cout <<
" ---> Dofs: " << uSpace->dof().numTotalDof() << std::endl;
283 std::cout <<
" -- Defining and filling the matrix ... " << std::flush;
287 chronoMgr.add (
"Matrix creation Time", &matTime );
289 matrixPtr_Type systemMatrix (
new matrix_Type ( uSpace->map() | pSpace->map() ) );
292 LifeChrono assemblyTime;
293 chronoMgr.add (
"Assembly Time", &assemblyTime );
294 assemblyTime.start();
296 using namespace ExpressionAssembly;
298 integrate ( elements ( localMesh ),
303 dot ( grad (phi_i) , grad (phi_j) )
306 >> systemMatrix->block (0, 0);
308 integrate ( elements ( localMesh ),
316 >> systemMatrix->block (0, 1);
318 integrate ( elements ( localMesh ),
326 >> systemMatrix->block (1, 0);
328 systemMatrix->globalAssemble();
332 chronoMgr.add (
"Matrix creation Time (R)", &matTimeR );
334 matrixPtr_Type systemMatrixR (
new matrix_Type ( uSpaceR->map() | pSpaceR->map(), 50,
true ) );
337 LifeChrono assemblyTimeR;
338 chronoMgr.add (
"Assembly Time (R)", &assemblyTimeR );
339 assemblyTimeR.start();
341 using namespace ExpressionAssembly;
343 integrate ( elements ( localMeshR ),
348 dot ( grad (phi_i) , grad (phi_j) )
351 >> systemMatrixR->block (0, 0);
353 integrate ( elements ( localMeshR ),
361 >> systemMatrixR->block (0, 1);
363 integrate ( elements ( localMeshR ),
371 >> systemMatrixR->block (1, 0);
373 systemMatrixR->fillComplete();
378 std::cout <<
" done! " << std::endl;
383 LifeChrono checkMatTime;
384 chronoMgr.add (
"Check (Matrix) Time", &checkMatTime );
385 checkMatTime.start();
386 matrix_Type matrixDiff ( *systemMatrix );
387 matrixDiff -= *systemMatrixR;
389 Real diff = matrixDiff.normInf();
394 std::cout <<
"Norm of the difference between the 2 matrices = " << diff << std::endl;
399 std::cout <<
" -- Building the RHS ... " << std::flush;
403 chronoMgr.add (
"Rhs build Time", &rhsTime );
405 vector_Type rhs ( uSpaceStd->map() | pSpace->map(), Unique );
407 vectorStd_Type fInterpolated ( uSpace->map(), Repeated );
408 uSpaceStd->interpolate (
static_cast<uSpaceStd_Type::function_Type> (fRhs), fInterpolated, 0.0 );
411 using namespace ExpressionAssembly;
413 integrate ( elements ( localMesh ),
416 dot (value (uSpace, fInterpolated), phi_i)
420 rhs.globalAssemble();
424 chronoMgr.add (
"Rhs build Time (R)", &rhsTimeR );
426 vector_Type rhsR ( uSpaceStdR->map() | pSpaceR->map(), Unique, Zero );
428 vectorStd_Type fInterpolatedR ( uSpaceR->map(), Repeated );
429 uSpaceStdR->interpolate (
static_cast<uSpaceStd_Type::function_Type> (fRhs), fInterpolatedR, 0.0 );
432 using namespace ExpressionAssembly;
434 integrate ( elements ( localMeshR ),
437 dot (value (uSpaceR, fInterpolatedR), phi_i)
441 rhsR.globalAssemble();
444 LifeChrono checkVecTime;
445 chronoMgr.add (
"Check (Vector) Time", &checkVecTime );
446 checkVecTime.start();
447 vector_Type vectorDiff ( rhs );
450 Real diffNormV = vectorDiff.normInf();
455 std::cout <<
"Norm of the difference between the 2 vectors = " << diffNormV << std::endl;
462 returnValue = EXIT_SUCCESS;
465 std::cout <<
"End Result: TEST PASSED" << std::endl;
470 returnValue = EXIT_FAILURE;
VectorEpetra - The Epetra Vector format Wrapper.
int main(int argc, char **argv)
Real exactSolution(const Real &, const Real &x, const Real &y, const Real &, const ID &)
std::shared_ptr< uSpaceStd_Type > uSpaceStdPtr_Type
Real fRhs(const Real &, const Real &, const Real &, const Real &, const ID &i)
FESpace< mesh_Type, MapEpetra > uSpaceStd_Type
MatrixEpetraStructured< Real > matrix_Type
ETFESpace< mesh_Type, MapEpetra, 2, 1 > pSpace_Type
VectorEpetraStructured - class of block vector.
VectorEpetraStructured vector_Type
VectorEpetra vectorStd_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
std::shared_ptr< pSpace_Type > pSpacePtr_Type
RegionMesh< LinearTriangle > mesh_Type
ETFESpace< mesh_Type, MapEpetra, 2, 2 > uSpace_Type
double Real
Generic real data.
std::shared_ptr< Epetra_Comm > commPtr_Type
MatrixEpetraStructured - class of block matrix.
class ETFESpace A light, templated version of the FESpace
std::shared_ptr< uSpace_Type > uSpacePtr_Type
std::shared_ptr< mesh_Type > meshPtr_Type
std::shared_ptr< matrix_Type > matrixPtr_Type