58 #include <Epetra_ConfigDefs.h> 61 #include <Epetra_MpiComm.h> 63 #include <Epetra_SerialComm.h> 67 #include <lifev/core/LifeV.hpp> 69 #include <lifev/core/mesh/MeshPartitioner.hpp> 70 #include <lifev/core/mesh/RegionMesh3DStructured.hpp> 71 #include <lifev/core/mesh/RegionMesh.hpp> 73 #include <lifev/core/array/MatrixEpetra.hpp> 74 #include <lifev/core/array/VectorEpetra.hpp> 76 #include <lifev/core/array/MatrixEpetraStructured.hpp> 77 #include <lifev/core/array/VectorEpetraStructured.hpp> 78 #include <lifev/core/array/MatrixEpetraStructuredUtility.hpp> 80 #include <lifev/eta/fem/ETFESpace.hpp> 81 #include <lifev/eta/expression/Integrate.hpp> 83 #include <lifev/core/fem/FESpace.hpp> 85 #include <lifev/core/util/LifeChrono.hpp> 87 #include <boost/shared_ptr.hpp> 96 using namespace LifeV;
110 int main (
int argc,
char** argv )
114 MPI_Init (&argc, &argv);
115 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_MpiComm (MPI_COMM_WORLD) );
117 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_SerialComm);
120 const bool verbose (Comm->MyPID() == 0);
125 std::cout <<
" -- Building and partitioning the mesh ... " << std::flush;
128 const UInt Nelements (10);
130 std::shared_ptr< mesh_Type > fullMeshPtr (
new mesh_Type ( Comm ) );
132 regularMesh3D ( *fullMeshPtr, 1, Nelements, Nelements, Nelements,
false,
136 std::shared_ptr< mesh_Type > meshPtr;
138 MeshPartitioner< mesh_Type > meshPart (fullMeshPtr, Comm);
139 meshPtr = meshPart.meshPartition();
146 std::cout <<
" done ! " << std::endl;
161 std::cout <<
" -- Building the spaces ... " << std::flush;
164 std::shared_ptr<ETFESpace< mesh_Type, MapEpetra, 3, 3 > > ETuSpace
165 (
new ETFESpace< mesh_Type, MapEpetra, 3, 3 > (meshPtr, &feTetraP2, Comm) );
167 std::shared_ptr<ETFESpace< mesh_Type, MapEpetra, 3, 1 > > ETpSpace
168 (
new ETFESpace< mesh_Type, MapEpetra, 3, 1 > (meshPtr, &feTetraP1, Comm) );
170 std::shared_ptr<ETFESpace< mesh_Type, MapEpetra, 3, 1 > > ETuCompSpace
171 (
new ETFESpace< mesh_Type, MapEpetra, 3, 1 > (meshPtr, &feTetraP2, Comm) );
175 std::cout <<
" done ! " << std::endl;
179 std::cout <<
" ---> Velocity dofs: " << ETuSpace->dof().numTotalDof() << std::endl;
183 std::cout <<
" ---> Pressure dofs: " << ETpSpace->dof().numTotalDof() << std::endl;
196 std::cout <<
" -- Assembly of the Stokes matrix (I) ... " << std::flush;
201 std::shared_ptr<blockMatrix_Type> ETsystemMatrixI (
new blockMatrix_Type ( ETuSpace->map() | ETpSpace->map() ) );
202 *ETsystemMatrixI *= 0.0;
205 using namespace ExpressionAssembly;
207 integrate ( elements (ETuSpace->mesh() ),
212 dot ( grad (phi_i) , grad (phi_j) )
215 >> ETsystemMatrixI->block (0, 0);
217 integrate ( elements (ETuSpace->mesh() ),
225 >> ETsystemMatrixI->block (0, 1);
227 integrate ( elements (ETuSpace->mesh() ),
235 >> ETsystemMatrixI->block (1, 0);
240 ETsystemMatrixI->globalAssemble();
244 std::cout <<
" done! " << std::endl;
248 std::cout <<
" Time: " << chronoI.diff() << std::endl;
265 std::cout <<
" -- Assembly of the Stokes matrix (II) ... " << std::flush;
270 std::shared_ptr<blockMatrix_Type> ETsystemMatrixII
271 (
new blockMatrix_Type ( ETuCompSpace->map() | ETuCompSpace->map() | ETuCompSpace->map() | ETpSpace->map() ) );
272 *ETsystemMatrixII *= 0.0;
275 using namespace ExpressionAssembly;
277 VectorSmall<3> e1 (1, 0, 0);
278 VectorSmall<3> e2 (0, 1, 0);
279 VectorSmall<3> e3 (0, 0, 1);
281 integrate ( elements (ETuSpace->mesh() ),
286 dot ( grad (phi_i) , grad (phi_j) )
289 >> ETsystemMatrixII->block (0, 0);
291 integrate ( elements (ETuSpace->mesh() ),
296 dot ( grad (phi_i) , grad (phi_j) )
299 >> ETsystemMatrixII->block (1, 1);
301 integrate ( elements (ETuSpace->mesh() ),
306 dot ( grad (phi_i) , grad (phi_j) )
309 >> ETsystemMatrixII->block (2, 2);
313 integrate ( elements (ETuSpace->mesh() ),
318 phi_j * dot (grad (phi_i), e1)
321 >> ETsystemMatrixII->block (0, 3);
323 integrate ( elements (ETuSpace->mesh() ),
328 phi_j * dot (grad (phi_i), e2)
331 >> ETsystemMatrixII->block (1, 3);
333 integrate ( elements (ETuSpace->mesh() ),
338 phi_j * dot (grad (phi_i), e3)
341 >> ETsystemMatrixII->block (2, 3);
344 integrate ( elements (ETuSpace->mesh() ),
349 phi_i * dot (grad (phi_j), e1)
352 >> ETsystemMatrixII->block (3, 0);
354 integrate ( elements (ETuSpace->mesh() ),
359 phi_i * dot (grad (phi_j), e2)
362 >> ETsystemMatrixII->block (3, 1);
364 integrate ( elements (ETuSpace->mesh() ),
369 phi_i * dot (grad (phi_j), e3)
372 >> ETsystemMatrixII->block (3, 2);
377 ETsystemMatrixII->globalAssemble();
381 std::cout <<
" done! " << std::endl;
385 std::cout <<
" Time: " << chronoII.diff() << std::endl;
402 std::cout <<
" -- Assembly of the Stokes matrix (III) ... " << std::flush;
404 LifeChrono chronoIII;
412 std::shared_ptr<blockMatrix_Type> ETcomponentMatrixIII
413 (
new blockMatrix_Type ( ETuCompSpace->map() ) );
414 *ETcomponentMatrixIII *= 0.0;
417 using namespace ExpressionAssembly;
419 integrate ( elements (ETuSpace->mesh() ),
424 dot ( grad (phi_i) , grad (phi_j) )
427 >> ETcomponentMatrixIII->block (0, 0);
430 ETcomponentMatrixIII->globalAssemble();
437 std::shared_ptr<blockMatrix_Type> ETsystemMatrixIII
438 (
new blockMatrix_Type ( ETuCompSpace->map() | ETuCompSpace->map() | ETuCompSpace->map() | ETpSpace->map() ) );
439 *ETsystemMatrixIII *= 0.0;
446 MatrixEpetraStructuredUtility::copyBlock (*ETcomponentMatrixIII->block (0, 0), *ETsystemMatrixIII->block (0, 0) );
447 MatrixEpetraStructuredUtility::copyBlock (*ETcomponentMatrixIII->block (0, 0), *ETsystemMatrixIII->block (1, 1) );
448 MatrixEpetraStructuredUtility::copyBlock (*ETcomponentMatrixIII->block (0, 0), *ETsystemMatrixIII->block (2, 2) );
455 using namespace ExpressionAssembly;
457 VectorSmall<3> e1 (1, 0, 0);
458 VectorSmall<3> e2 (0, 1, 0);
459 VectorSmall<3> e3 (0, 0, 1);
461 integrate ( elements (ETuSpace->mesh() ),
466 phi_j * dot (grad (phi_i), e1)
469 >> ETsystemMatrixIII->block (0, 3);
471 integrate ( elements (ETuSpace->mesh() ),
476 phi_j * dot (grad (phi_i), e2)
479 >> ETsystemMatrixIII->block (1, 3);
481 integrate ( elements (ETuSpace->mesh() ),
486 phi_j * dot (grad (phi_i), e3)
489 >> ETsystemMatrixIII->block (2, 3);
492 integrate ( elements (ETuSpace->mesh() ),
497 phi_i * dot (grad (phi_j), e1)
500 >> ETsystemMatrixIII->block (3, 0);
502 integrate ( elements (ETuSpace->mesh() ),
507 phi_i * dot (grad (phi_j), e2)
510 >> ETsystemMatrixIII->block (3, 1);
512 integrate ( elements (ETuSpace->mesh() ),
517 phi_i * dot (grad (phi_j), e3)
520 >> ETsystemMatrixIII->block (3, 2);
525 ETsystemMatrixIII->globalAssemble();
529 std::cout <<
" done! " << std::endl;
533 std::cout <<
" Time: " << chronoIII.diff() << std::endl;
551 std::cout <<
" -- Assembly of the Stokes matrix (IV) ... " << std::flush;
561 std::shared_ptr<blockMatrix_Type> ETcomponentMatrixIV
562 (
new blockMatrix_Type ( ETuCompSpace->map() ) );
563 *ETcomponentMatrixIV *= 0.0;
566 using namespace ExpressionAssembly;
568 integrate ( elements (ETuSpace->mesh() ),
573 dot ( grad (phi_i) , grad (phi_j) )
576 >> ETcomponentMatrixIV->block (0, 0);
579 ETcomponentMatrixIV->globalAssemble();
586 std::shared_ptr<blockMatrix_Type> ETsystemMatrixIV
587 (
new blockMatrix_Type ( ETuCompSpace->map() | ETuCompSpace->map() | ETuCompSpace->map() | ETpSpace->map() ) );
588 *ETsystemMatrixIV *= 0.0;
595 MatrixEpetraStructuredUtility::copyBlock (*ETcomponentMatrixIV->block (0, 0), *ETsystemMatrixIV->block (0, 0) );
596 MatrixEpetraStructuredUtility::copyBlock (*ETcomponentMatrixIV->block (0, 0), *ETsystemMatrixIV->block (1, 1) );
597 MatrixEpetraStructuredUtility::copyBlock (*ETcomponentMatrixIV->block (0, 0), *ETsystemMatrixIV->block (2, 2) );
604 ETsystemMatrixIV->setBlockStructure (ETuSpace->map() | ETpSpace->map() );
607 using namespace ExpressionAssembly;
609 integrate ( elements (ETuSpace->mesh() ),
617 >> ETsystemMatrixIV->block (0, 1);
619 integrate ( elements (ETuSpace->mesh() ),
627 >> ETsystemMatrixIV->block (1, 0);
632 ETsystemMatrixIV->globalAssemble();
636 std::cout <<
" done! " << std::endl;
640 std::cout <<
" Time: " << chronoIV.diff() << std::endl;
650 std::cout <<
" -- Computing the error ... " << std::flush;
653 std::shared_ptr<matrix_Type> checkMatrixIvsII (
new matrix_Type ( ETuSpace->map() + ETpSpace->map() ) );
654 *checkMatrixIvsII *= 0.0;
656 *checkMatrixIvsII += *ETsystemMatrixI;
657 *checkMatrixIvsII += (*ETsystemMatrixII) * (-1);
659 checkMatrixIvsII->globalAssemble();
661 Real errorNormIvsII ( checkMatrixIvsII->normInf() );
664 std::shared_ptr<matrix_Type> checkMatrixIvsIII (
new matrix_Type ( ETuSpace->map() + ETpSpace->map() ) );
665 *checkMatrixIvsIII *= 0.0;
667 *checkMatrixIvsIII += *ETsystemMatrixI;
668 *checkMatrixIvsIII += (*ETsystemMatrixIII) * (-1);
670 checkMatrixIvsIII->globalAssemble();
672 Real errorNormIvsIII ( checkMatrixIvsIII->normInf() );
675 std::shared_ptr<matrix_Type> checkMatrixIvsIV (
new matrix_Type ( ETuSpace->map() + ETpSpace->map() ) );
676 *checkMatrixIvsIV *= 0.0;
678 *checkMatrixIvsIV += *ETsystemMatrixI;
679 *checkMatrixIvsIV += (*ETsystemMatrixIV) * (-1);
681 checkMatrixIvsIV->globalAssemble();
683 Real errorNormIvsIV ( checkMatrixIvsIV->normInf() );
689 std::cout <<
" done ! " << std::endl;
693 std::cout <<
" I vs II : " << errorNormIvsII << std::endl;
697 std::cout <<
" I vs III : " << errorNormIvsIII << std::endl;
701 std::cout <<
" I vs IV : " << errorNormIvsIV << std::endl;
709 Real tolerance (1e-10);
711 if ( (errorNormIvsII < tolerance)
712 && (errorNormIvsIII < tolerance)
713 && (errorNormIvsIV < tolerance)
716 return ( EXIT_SUCCESS );
718 return ( EXIT_FAILURE );
int main(int argc, char **argv)
MatrixEpetra< Real > matrix_Type
MatrixEpetraStructured< Real > blockMatrix_Type
double Real
Generic real data.
RegionMesh< LinearTetra > mesh_Type
VectorEpetraStructured blockVector_Type