35 #ifndef TEST_REPEATED_MESH__ 36 #define TEST_REPEATED_MESH__ 38 #include <Epetra_ConfigDefs.h> 41 #include <Epetra_MpiComm.h> 43 #include <Epetra_SerialComm.h> 47 #include <lifev/core/LifeV.hpp> 49 #include <lifev/core/array/MatrixEpetra.hpp> 51 #include <lifev/core/fem/FESpace.hpp> 53 #include <lifev/core/mesh/MeshPartitioner.hpp> 54 #include <lifev/core/mesh/RegionMesh2DStructured.hpp> 55 #include <lifev/core/mesh/RegionMesh.hpp> 56 #include <lifev/core/mesh/MeshData.hpp> 58 #include <lifev/core/solver/ADRAssembler.hpp> 60 #include <lifev/core/util/LifeChronoManager.hpp> 63 #include <lifev/core/filter/ExporterHDF5.hpp> 66 using namespace LifeV;
70 return sin ( x ) - 1.;
93 regularMesh2D ( *fullMeshPtr, 0,
94 dataFile (
"mesh/nx", 20 ), dataFile (
"mesh/ny", 20 ),
95 dataFile (
"mesh/verbose",
false ),
96 dataFile (
"mesh/lx", 1. ), dataFile (
"mesh/ly", 1. ) );
111 regularMesh3D ( *fullMeshPtr, 0,
112 dataFile (
"mesh/nelem", 8 ), dataFile (
"mesh/nelem", 8 ), dataFile (
"mesh/nelem", 8 ),
113 dataFile (
"mesh/verbose",
false ),
114 dataFile (
"mesh/length", 1. ), dataFile (
"mesh/length", 1. ), dataFile (
"mesh/length", 1. ) );
147 M_comm.reset (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
149 M_comm.reset (
new Epetra_SerialComm );
151 M_chronoMgr.reset (
new LifeChronoManager<> ( M_comm ) );
155 int TestRepeatedMesh<Dim>::run()
157 int returnValue = EXIT_SUCCESS;
159 M_chronoMgr->add (
"Initialization Time", &initTime );
162 GetPot dataFile (
"data" );
163 const bool isLeader ( M_comm->MyPID() == 0 );
164 const bool verbose = dataFile (
"miscellaneous/verbose", 0 ) && isLeader;
166 #ifdef HAVE_LIFEV_DEBUG 167 std::ofstream debugOut ( (
"repeated_mesh." + ( M_comm->NumProc() > 1 ? std::to_string( M_comm->MyPID() ) :
"s" ) +
".out" ).c_str() );
169 std::ofstream debugOut (
"/dev/null" );
177 M_chronoMgr->add (
"Mesh reading/creation Time", &initTime );
182 std::cout <<
" -- Reading the mesh ... " << std::flush;
184 meshPtr_Type fullMeshPtr (
new mesh_Type() );
185 if ( dataFile (
"mesh/mesh_type",
"structured" ) ==
"structured" )
187 fullMeshPtr = DimSelector<Dim>::generateRegularMesh ( dataFile );
191 MeshData meshData (dataFile,
"mesh");
192 readMesh (*fullMeshPtr, meshData);
196 std::cout <<
" done ! " << std::endl;
200 std::cout <<
"mesh elements = " << fullMeshPtr->numElements() <<
"\n" 201 <<
"mesh points = " << fullMeshPtr->numPoints() << std::endl;
208 std::cout <<
" -- Partitioning the mesh ... " << std::flush;
212 M_chronoMgr->add (
"Partition Time", &partTime );
214 meshPtr_Type localMesh;
216 MeshPartitioner< mesh_Type > meshPart;
217 meshPart.doPartition ( fullMeshPtr, M_comm );
218 localMesh = meshPart.meshPartition();
226 Int localMeshNum[ 2 ];
227 localMeshNum[ 0 ] = localMesh->numElements();
228 localMeshNum[ 1 ] = localMesh->numPoints();
229 Int maxMeshNum[ 2 ] = { 0, 0 };
230 M_comm->MaxAll ( localMeshNum, maxMeshNum, 2 );
234 std::cout <<
"part mesh elements = " << maxMeshNum[ 0 ] <<
"\n" 235 <<
"part mesh points = " << maxMeshNum[ 1 ] << std::endl;
238 LifeChrono partTimeR;
239 M_chronoMgr->add (
"Partition Time (R)", &partTimeR );
241 meshPtr_Type localMeshR;
243 MeshPartitioner< mesh_Type > meshPartR;
244 meshPartR.setPartitionOverlap ( 1 );
245 meshPartR.doPartition ( fullMeshPtr, M_comm );
246 localMeshR = meshPartR.meshPartition();
254 localMeshNum[ 0 ] = localMeshR->numElements();
255 localMeshNum[ 1 ] = localMeshR->numPoints();
258 M_comm->MaxAll ( localMeshNum, maxMeshNum, 2 );
262 std::cout <<
"part mesh elements (R) = " << maxMeshNum[ 0 ] <<
"\n" 263 <<
"part mesh points (R) = " << maxMeshNum[ 1 ] << std::endl;
268 std::cout <<
" done ! " << std::endl;
273 std::cout <<
" -- Freeing the global mesh ... " << std::flush;
276 #ifdef HAVE_LIFEV_DEBUG 277 ASSERT ( fullMeshPtr.use_count() == 0,
"full mesh not properly freed." );
281 std::cout <<
" done ! " << std::endl;
288 std::cout <<
" -- Building FESpaces ... " << std::flush;
290 std::string uOrder = dataFile (
"fe/type",
"P1" );
291 LifeChrono feSpaceTime;
292 M_chronoMgr->add (
"FESpace creation Time", &feSpaceTime );
294 feSpacePtr_Type uFESpace (
new feSpace_Type ( localMesh, uOrder, 1, M_comm ) );
297 LifeChrono feSpaceTimeR;
298 M_chronoMgr->add (
"FESpace creation Time (R)", &feSpaceTimeR );
299 feSpaceTimeR.start();
300 feSpacePtr_Type uFESpaceR (
new feSpace_Type ( localMeshR, uOrder, 1, M_comm ) );
305 std::cout <<
" done ! " << std::endl;
309 std::cout <<
" ---> Dofs: " << uFESpaceR->dof().numTotalDof() << std::endl;
316 std::cout <<
" -- Building assembler ... " << std::flush;
320 M_chronoMgr->add (
"Matrix initialization Time", &matTime );
322 ADRAssembler<mesh_Type, matrix_Type, vector_Type> adrAssembler;
323 adrAssembler.setFespace ( uFESpace );
324 matrixPtr_Type systemMatrix (
new matrix_Type ( uFESpace->map() ) );
328 M_chronoMgr->add (
"Matrix initialization Time (R)", &matTimeR );
330 ADRAssembler<mesh_Type, matrix_Type, vector_Type> adrAssemblerR;
331 adrAssemblerR.setFespace ( uFESpaceR );
332 matrixPtr_Type systemMatrixR (
new matrix_Type ( uFESpaceR->map(), 50,
true ) );
337 std::cout <<
" done! " << std::endl;
344 std::cout <<
" -- Adding the diffusion ... " << std::flush;
349 std::cout <<
" done! " << std::endl;
352 UInt timeSteps = dataFile (
"miscellaneous/timesteps", 1 );
354 LifeChrono assemblyTime;
355 M_chronoMgr->add (
"Assembly Time", &assemblyTime );
356 assemblyTime.start();
357 for ( UInt n = 0; n < timeSteps; n++ )
359 systemMatrix->zero();
360 adrAssembler.addDiffusion ( systemMatrix, 1. );
361 adrAssembler.addMass ( systemMatrix, 1. );
362 systemMatrix->globalAssemble();
367 std::cout <<
"assembly time = " << assemblyTime.diff() << std::endl;
370 LifeChrono assemblyTimeR;
371 M_chronoMgr->add (
"Assembly Time (R)", &assemblyTimeR );
372 assemblyTimeR.start();
373 for ( UInt n = 0; n < timeSteps; n++ )
375 systemMatrixR->zero();
376 adrAssemblerR.addDiffusion ( systemMatrixR, 1. );
377 adrAssemblerR.addMass ( systemMatrixR, 1. );
378 systemMatrixR->fillComplete();
380 assemblyTimeR.stop();
383 std::cout <<
"assemblyR time = " << assemblyTimeR.diff() << std::endl;
401 LifeChrono checkMatTime;
402 M_chronoMgr->add (
"Check (Matrix) Time", &checkMatTime );
403 checkMatTime.start();
404 matrix_Type matrixDiff ( *systemMatrix );
405 matrixDiff -= *systemMatrixR;
407 Real diff = matrixDiff.normInf();
412 std::cout <<
"Norm of the difference between the 2 matrices = " << diff << std::endl;
417 std::cout <<
" -- Building the RHS ... " << std::flush;
421 M_chronoMgr->add (
"Rhs build Time", &rhsTime );
423 vector_Type rhs ( uFESpace->map(), Unique );
424 adrAssembler.addMassRhs ( rhs, fRhs, 0. );
425 rhs.globalAssemble();
429 M_chronoMgr->add (
"Rhs build Time (R)", &rhsTimeR );
431 vector_Type rhsR ( uFESpaceR->map(), Unique, Zero );
432 adrAssemblerR.addMassRhs ( rhsR, fRhs, 0. );
433 rhsR.globalAssemble ();
436 LifeChrono checkVecTime;
437 M_chronoMgr->add (
"Check (Vector) Time", &checkVecTime );
438 checkVecTime.start();
439 vector_Type vectorDiff ( rhs );
442 Real diffNormV = vectorDiff.normInf();
447 std::cout <<
"Norm of the difference between the 2 vectors = " << diffNormV << std::endl;
452 vector_Type rhs2 ( uFESpace->map(), Unique );
453 vector_Type f ( uFESpace->map(), Repeated );
454 uFESpace->interpolate (
static_cast<
typename feSpace_Type::function_Type> ( fRhs ), f, 0.0 );
455 adrAssembler.addMassRhs ( rhs2, f );
456 rhs2.globalAssemble();
458 vector_Type rhs2R ( uFESpaceR->map(), Unique );
459 vector_Type fR ( uFESpaceR->map(), Repeated );
460 uFESpaceR->interpolate (
static_cast<
typename feSpace_Type::function_Type> ( fRhs ), fR, 0.0 );
461 adrAssemblerR.addMassRhs ( rhs2R, fR );
462 rhs2R.globalAssemble ( Zero );
464 vector_Type vectorDiff2 ( rhs2 );
465 vectorDiff2 -= rhs2R;
467 Real diffNormV2 = vectorDiff2.normInf();
471 std::cout <<
"Norm of the difference between the 2 vectors = " << diffNormV2 << std::endl;
478 if ( dataFile (
"exporter/enable",
false ) )
480 ExporterHDF5<mesh_Type> exporter ( dataFile, localMeshR,
"pid", M_comm->MyPID() );
481 exporter.exportPID ( localMeshR, M_comm,
true );
482 exporter.postProcess ( 0. );
486 vector_Type rhsCopy ( rhs, Repeated );
487 vector_Type rhsCopyR ( rhsR, Repeated, Add );
488 Real l2Error = uFESpace->l2Error ( fRhs, rhsCopy, 0.0 );
489 Real l2ErrorR = uFESpaceR->l2Error ( fRhs, rhsCopyR, 0.0 );
490 Real diffL2Error = std::fabs ( l2Error - l2ErrorR );
494 std::cout <<
"difference in l2error = " << diffL2Error << std::endl;
503 std::cout <<
"End Result: TEST PASSED" << std::endl;
508 returnValue = EXIT_FAILURE;
512 M_chronoMgr->print();
VectorEpetra - The Epetra Vector format Wrapper.
RegionMesh< elem_Type > mesh_Type
std::shared_ptr< mesh_Type > meshPtr_Type
std::shared_ptr< Epetra_Comm > commPtr_Type
RegionMesh< elem_Type > mesh_Type
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
static meshPtr_Type generateRegularMesh(GetPot const &dataFile)
std::shared_ptr< matrix_Type > matrixPtr_Type
RegionMesh< elem_Type > mesh_Type
FESpace< mesh_Type, MapEpetra > feSpace_Type
std::shared_ptr< feSpace_Type > feSpacePtr_Type
std::shared_ptr< mesh_Type > meshPtr_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
std::shared_ptr< mesh_Type > meshPtr_Type
DimSelector< Dim >::elem_Type elem_Type
static meshPtr_Type generateRegularMesh(GetPot const &dataFile)
MatrixEpetra< Real > matrix_Type
double Real
Generic real data.
RegionMesh< elem_Type > mesh_Type
static meshPtr_Type generateRegularMesh(GetPot const &dataFile)
Real fRhs(const Real &, const Real &x, const Real &, const Real &, const ID &)
std::unique_ptr< LifeChronoManager<> > M_chronoMgr
std::shared_ptr< mesh_Type > meshPtr_Type