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/LifeChrono.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.;
101 int main (
int argc,
char** argv )
105 MPI_Init (&argc, &argv);
113 std::shared_ptr<Epetra_Comm> comm (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
115 std::shared_ptr<Epetra_Comm> comm (
new Epetra_SerialComm );
118 GetPot dataFile (
"data_2d" );
119 const bool isLeader ( comm->MyPID() == 0 );
120 const bool verbose ( dataFile (
"miscellaneous/verbose", 0 ) && isLeader );
122 #ifdef HAVE_LIFEV_DEBUG 123 std::ofstream debugOut (
125 ( comm->NumProc() > 1 ? std::to_string ( comm->MyPID() ) :
"s" ) +
128 std::ofstream debugOut (
"/dev/null" );
135 std::cout <<
" -- Reading the mesh ... " << std::flush;
137 std::shared_ptr< mesh_Type > fullMeshPtr (
new mesh_Type() );
138 if ( dataFile (
"mesh/mesh_type",
"structured" ) ==
"structured" )
140 regularMesh2D ( *fullMeshPtr, 0,
141 dataFile (
"mesh/nx", 20 ), dataFile (
"mesh/ny", 20 ),
142 dataFile (
"mesh/verbose",
false ),
143 dataFile (
"mesh/lx", 1. ), dataFile (
"mesh/ly", 1. ) );
147 MeshData meshData (dataFile,
"mesh");
148 readMesh (*fullMeshPtr, meshData);
152 std::cout <<
" done ! " << std::endl;
156 std::cout <<
"mesh elements = " << fullMeshPtr->numElements() <<
"\n" 157 <<
"mesh points = " << fullMeshPtr->numPoints() << std::endl;
162 std::cout <<
" -- Partitioning the mesh ... " << std::flush;
167 std::shared_ptr< mesh_Type > localMesh;
169 MeshPartitioner< mesh_Type > meshPart;
170 meshPart.doPartition ( fullMeshPtr, comm );
171 localMesh = meshPart.meshPartition();
176 std::cout <<
"partitioning time = " << partTime.diff() << std::endl;
180 std::cout <<
"part mesh elements = " << localMesh->numElements() <<
"\n" 181 <<
"part mesh points = " << localMesh->numPoints() << std::endl;
186 LifeChrono partTimeR;
188 std::shared_ptr< mesh_Type > localMeshR;
190 MeshPartitioner< mesh_Type > meshPartR;
191 meshPartR.setPartitionOverlap ( 1 );
192 meshPartR.doPartition ( fullMeshPtr, comm );
193 localMeshR = meshPartR.meshPartition();
198 std::cout <<
"partitioningR time = " << partTimeR.diff() << std::endl;
205 std::cout <<
" done ! " << std::endl;
210 std::cout <<
" -- Freeing the global mesh ... " << std::flush;
215 std::cout <<
" done ! " << std::endl;
222 std::cout <<
" -- Building FESpaces ... " << std::flush;
224 uSpaceStdPtr_Type uSpaceStd (
new uSpaceStd_Type ( localMesh,
"P2", 2, comm ) );
225 uSpaceStdPtr_Type uSpaceStdR (
new uSpaceStd_Type ( localMeshR,
"P2", 2, comm ) );
227 uSpacePtr_Type uSpace (
new uSpace_Type ( localMesh, &feTriaP2, & (uSpaceStd->fe().geoMap() ), comm) );
228 uSpacePtr_Type uSpaceR (
new uSpace_Type ( localMeshR, &feTriaP2, & (uSpaceStdR->fe().geoMap() ), comm) );
230 pSpacePtr_Type pSpace (
new pSpace_Type ( localMesh, &feTriaP1, & (uSpaceStd->fe().geoMap() ), comm) );
231 pSpacePtr_Type pSpaceR (
new pSpace_Type ( localMeshR, &feTriaP1, & (uSpaceStdR->fe().geoMap() ), comm) );
235 std::cout <<
" done ! " << std::endl;
239 std::cout <<
" ---> Dofs: " << uSpace->dof().numTotalDof() << std::endl;
246 std::cout <<
" -- Defining the matrix ... " << std::flush;
248 matrixPtr_Type systemMatrix (
new matrix_Type ( uSpace->map() | pSpace->map() ) );
249 matrixPtr_Type systemMatrixR (
new matrix_Type ( uSpaceR->map() | pSpaceR->map(), 50,
true ) );
252 std::cout <<
" done! " << std::endl;
256 using namespace ExpressionAssembly;
258 integrate ( elements ( localMesh ),
263 dot ( grad (phi_i) , grad (phi_j) )
266 >> systemMatrix->block (0, 0);
268 integrate ( elements ( localMesh ),
276 >> systemMatrix->block (0, 1);
278 integrate ( elements ( localMesh ),
286 >> systemMatrix->block (1, 0);
289 systemMatrix->globalAssemble();
292 using namespace ExpressionAssembly;
294 integrate ( elements ( localMeshR ),
299 dot ( grad (phi_i) , grad (phi_j) )
302 >> systemMatrixR->block (0, 0);
304 integrate ( elements ( localMeshR ),
312 >> systemMatrixR->block (0, 1);
314 integrate ( elements ( localMeshR ),
322 >> systemMatrixR->block (1, 0);
325 systemMatrixR->fillComplete();
333 matrix_Type matrixDiff ( *systemMatrix );
334 matrixDiff -= *systemMatrixR;
336 Real diff = matrixDiff.normInf();
340 std::cout <<
"Norm of the difference between the 2 matrices = " << diff << std::endl;
345 std::cout <<
" -- Building the RHS ... " << std::flush;
348 vector_Type rhs ( uSpaceStd->map() | pSpace->map(), Unique );
350 vectorStd_Type fInterpolated ( uSpace->map(), Repeated );
351 uSpaceStd->interpolate (
static_cast<uSpaceStd_Type::function_Type> (fRhs), fInterpolated, 0.0 );
354 using namespace ExpressionAssembly;
356 integrate ( elements ( localMesh ),
359 dot (value (uSpace, fInterpolated), phi_i)
364 debugOut <<
"noGA\n" << rhs.epetraVector();
366 rhs.globalAssemble();
368 debugOut <<
"\n" << rhs.epetraVector();
370 vector_Type rhsR ( uSpaceStdR->map() | pSpaceR->map(), Unique, Zero );
372 vectorStd_Type fInterpolatedR ( uSpaceR->map(), Repeated );
373 uSpaceStdR->interpolate (
static_cast<uSpaceStd_Type::function_Type> (fRhs), fInterpolatedR, 0.0 );
376 using namespace ExpressionAssembly;
378 integrate ( elements ( localMeshR ),
381 dot (value (uSpaceR, fInterpolatedR), phi_i)
386 debugOut <<
"RnoGA\n" << rhsR.epetraVector();
388 rhsR.globalAssemble();
390 debugOut <<
"R\n" << rhsR.epetraVector();
392 vector_Type vectorDiff ( rhs );
395 Real diffNormV = vectorDiff.normInf();
399 std::cout <<
"Norm of the difference between the 2 vectors = " << diffNormV << std::endl;
408 std::cout <<
"End Result: TEST PASSED" << std::endl;
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.
MatrixEpetraStructured - class of block matrix.
class ETFESpace A light, templated version of the FESpace
std::shared_ptr< uSpace_Type > uSpacePtr_Type
std::shared_ptr< matrix_Type > matrixPtr_Type