34 #pragma GCC diagnostic ignored "-Wunused-variable" 35 #pragma GCC diagnostic ignored "-Wunused-parameter" 37 #include <Epetra_ConfigDefs.h> 40 #include <Epetra_MpiComm.h> 42 #include <Epetra_SerialComm.h> 46 #include <Teuchos_ParameterList.hpp> 47 #include <Teuchos_XMLParameterListHelpers.hpp> 48 #include <Teuchos_RCP.hpp> 51 #pragma GCC diagnostic warning "-Wunused-variable" 52 #pragma GCC diagnostic warning "-Wunused-parameter" 54 #include <lifev/core/LifeV.hpp> 57 #include <lifev/core/algorithm/PreconditionerIfpack.hpp> 58 #include <lifev/core/algorithm/PreconditionerML.hpp> 59 #include <lifev/core/algorithm/SolverAztecOO.hpp> 60 #include <lifev/core/algorithm/LinearSolver.hpp> 62 #include <lifev/core/array/MatrixBlockMonolithicEpetra.hpp> 63 #include <lifev/core/array/VectorBlockMonolithicEpetra.hpp> 65 #include <lifev/core/util/LifeChrono.hpp> 67 #include <lifev/eta/expression/Integrate.hpp> 69 #include <lifev/core/fem/BCHandler.hpp> 70 #include <lifev/core/fem/BCManage.hpp> 71 #include <lifev/eta/fem/ETFESpace.hpp> 72 #include <lifev/core/fem/DOFInterface3Dto3D.hpp> 73 #include <lifev/core/fem/GradientRecovery.hpp> 75 #include <lifev/core/filter/ExporterEnsight.hpp> 76 #include <lifev/core/filter/ExporterHDF5.hpp> 78 #include <lifev/core/mesh/MeshPartitioner.hpp> 79 #include <lifev/core/mesh/RegionMesh3DStructured.hpp> 80 #include <lifev/core/mesh/RegionMesh.hpp> 81 #include <lifev/core/mesh/MeshUtility.hpp> 82 #include <lifev/core/mesh/MeshData.hpp> 84 #include <lifev/level_set/fem/LevelSetQRAdapter.hpp> 87 using namespace LifeV;
99 return std::sin (
pi * y ) * std::cos (
pi * x ) * std::exp ( z ) ;
104 return ( - pi * pi * std::sin (pi * y) * std::cos (pi * x ) * std::exp ( z )
105 - pi * pi * std::sin (pi * y) * std::cos (pi * x ) * std::exp ( z )
106 + std::sin (pi * y) * cos (pi * x ) * exp ( z ) );
111 MatrixSmall<3, 3> hessian;
113 hessian[0][0] = - pi * pi * std::sin ( pi * y ) * std::cos ( pi * x ) * std::exp ( z );
115 hessian[0][1] = - pi * pi * std::sin (pi * x ) * std::cos (pi * y) * std::exp ( z );
116 hessian[1][0] = hessian[0][1];
118 hessian[0][2] = - pi * std::sin ( pi * y ) * std::sin ( pi * x ) * std::exp ( z );
119 hessian[2][0] = hessian[0][2];
121 hessian[1][1] = - pi * pi * std::sin ( pi * y ) * std::cos ( pi * x ) * std::exp ( z );
122 hessian[2][2] = std::sin ( pi * y ) * cos ( pi * x ) * exp ( z );
124 hessian[1][2] = pi * std::cos ( pi * y ) * std::cos ( pi * x ) * std::exp ( z );
125 hessian[2][1] = hessian[1][2];
128 gradient
[0
] = -
pi * std::sin (
pi * y ) * std::sin (
pi * x ) * std::exp ( z );
129 gradient
[1
] =
pi * std::cos (
pi * y ) * std::cos (
pi * x ) * std::exp ( z );
130 gradient
[2
] = std::sin (
pi * y ) * std::cos (
pi * x ) * std::exp ( z );
134 Real traceHessian = hessian[0][0] + hessian[1][1] + hessian[2][2];
142 return ( nu * gradient.dot ( normal ) + alpha * uExact ( 0, x, y, z, 0 )
143 - beta * ( traceHessian - ( hessian * normal ).dot ( normal ) ) );
169 return uExact ( 0
, spaceCoordinates
[0
], spaceCoordinates
[1
], spaceCoordinates
[2
] , 0
) ;
185 Real x = spaceCoordinates
[0
];
186 Real y = spaceCoordinates
[1
];
187 Real z = spaceCoordinates
[2
];
188 gradient
[0
] = -
pi * std::sin (
pi * y ) * std::sin (
pi * x ) * std::exp ( z );
189 gradient
[1
] =
pi * std::cos (
pi * y ) * std::cos (
pi * x ) * std::exp ( z );
190 gradient
[2
] = std::sin (
pi * y ) * std::cos (
pi * x ) * std::exp ( z );
234 int main (
int argc,
char** argv )
238 MPI_Init (&argc, &argv);
239 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_MpiComm (MPI_COMM_WORLD) );
241 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_SerialComm);
245 bool verbose = (Comm->MyPID() == 0);
248 GetPot command_line (argc, argv);
249 std::string data_file_name = command_line.follow (
"data", 2,
"-f",
"--file");
250 GetPot dataFile ( data_file_name );
254 dataMesh.setup (dataFile,
"mesh");
255 std::shared_ptr < mesh_Type > fullMeshPtr (
new mesh_Type);
256 readMesh (*fullMeshPtr, dataMesh);
259 MeshPartitioner< mesh_Type > meshPart (fullMeshPtr, Comm);
260 std::shared_ptr < mesh_Type > localMeshPtr (
new mesh_Type);
261 localMeshPtr = meshPart.meshPartition();
268 std::cout <<
" Building FESpaces " << std::endl;
271 std::string uOrder (
"P1");
273 std::shared_ptr<FESpace< mesh_Type, MapEpetra > > uFESpace (
new FESpace< mesh_Type, MapEpetra > (localMeshPtr, uOrder, 1, Comm) );
277 std::cout << std::endl <<
" ### Dof Summary ###: " << std::endl;
281 std::cout <<
" u : " << uFESpace->map().map (Unique)->NumGlobalElements() << std::endl;
286 std::cout <<
" Building EA FESpaces " << std::endl;
289 std::shared_ptr<ETFESpace< mesh_Type, MapEpetra, 3, 1 > > ETuFESpace (
new ETFESpace< mesh_Type, MapEpetra, 3, 1 > (localMeshPtr, & (uFESpace->refFE() ), Comm) );
291 vectorPtr_Type uSolution (
new vector_Type ( ETuFESpace->map() , Unique) );
295 std::cout <<
" Building the solvers " << std::endl;
301 std::cout <<
"Setting up LinearSolver (AztecOO)... " << std::flush;
304 prec_Type* precRawPtr;
305 basePrecPtr_Type precPtr;
306 precRawPtr =
new prec_Type;
307 precRawPtr->setDataFromGetPot ( dataFile,
"prec" );
308 precPtr.reset ( precRawPtr );
310 Teuchos::RCP< Teuchos::ParameterList > belosList = Teuchos::rcp (
new Teuchos::ParameterList );
311 belosList = Teuchos::getParametersFromXmlFile (
"SolverParamList.xml" );
313 LinearSolver linearSolver;
314 linearSolver.setCommunicator ( Comm );
315 linearSolver.setParameters ( *belosList );
316 linearSolver.setPreconditioner ( precPtr );
319 std::cout <<
"done" << std::endl;
324 std::cout <<
" Building the exporter " << std::endl;
327 std::string
const exporterFileName = dataFile (
"exporter/filename",
"cube");
328 ExporterHDF5<mesh_Type> exporter ( dataFile, meshPart.meshPartition(), exporterFileName, Comm->MyPID() );
329 exporter.setMultimesh (
false);
331 std::shared_ptr<vector_Type> uExported (
new vector_Type (ETuFESpace->map(), exporter.mapType() ) );
332 std::shared_ptr<vector_Type> errorExported (
new vector_Type (ETuFESpace->map(), exporter.mapType() ) );
334 exporter.addVariable ( ExporterData<mesh_Type>::ScalarField,
"u", uFESpace, uExported, UInt (0) );
335 exporter.addVariable ( ExporterData<mesh_Type>::ScalarField,
"err", uFESpace, errorExported, UInt (0) );
337 LifeChrono ChronoItem;
341 std::cout <<
" Assembling the matrix ... " << std::flush;
344 QuadratureBoundary myBDQR (buildTetraBDQR (quadRuleTria4pt) );
346 matrixPtr_Type systemMatrix (
new matrix_Type ( ETuFESpace->map() ) );
347 *systemMatrix *= 0.0;
350 using namespace ExpressionAssembly;
353 elements (ETuFESpace->mesh() ),
360 value (nu) * dot (grad (phi_i) , grad (phi_j) )
365 integrate ( boundary (ETuFESpace->mesh(), wall),
371 value ( alpha ) * phi_j * phi_i
373 + value ( beta ) * dot ( ( grad (phi_j) - dot ( grad (phi_j) , Nface ) * Nface ) ,
374 ( grad (phi_i) - dot ( grad (phi_i) , Nface ) * Nface ) )
383 std::cout << ChronoItem.diff() <<
" s" << std::endl;
388 std::cout <<
" Assembling the rhs ... " << std::flush;
393 std::shared_ptr<LaplacianExactFunctor> laplacianFctRhs (
new LaplacianExactFunctor );
394 std::shared_ptr<GRobinRhsFunctor> gRobinFctRhs (
new GRobinRhsFunctor );
396 vector_Type uRhs ( ETuFESpace->map() , Repeated );
400 using namespace ExpressionAssembly;
402 integrate ( elements (ETuFESpace->mesh() ),
408 value (-nu) * eval ( laplacianFctRhs, X ) * phi_i
414 integrate ( boundary (ETuFESpace->mesh(), wall),
419 eval ( gRobinFctRhs, X ) * phi_i
428 std::cout << ChronoItem.diff() <<
" s" << std::endl;
431 vectorPtr_Type uRhsUnique (
new vector_Type ( uRhs, Unique ) );
433 systemMatrix->globalAssemble();
437 std::cout <<
"[Navier-Stokes] Applying Dirichlet boundary conditions ... " << std::flush;
442 BCFunctionBase uexBCFct ( uExact );
444 bcHandler.addBC (
"Wall2", 31, Essential, Full, uexBCFct, 1);
445 bcHandler.addBC (
"Corners", 32, EssentialEdges, Full, uexBCFct, 1);
447 bcHandler.bcUpdate ( *meshPart.meshPartition(), uFESpace->feBd(), uFESpace->dof() );
448 bcManage (*systemMatrix, *uRhsUnique,
449 *uFESpace->mesh(), uFESpace->dof(),
450 bcHandler, uFESpace->feBd(), 1.0, Real (0.0) );
456 std::cout << ChronoItem.diff() <<
" s" << std::endl;
461 std::cout <<
" Solving the system " << std::endl;
465 linearSolver.setOperator ( systemMatrix );
466 linearSolver.setRightHandSide ( uRhsUnique );
467 linearSolver.solve ( uSolution );
469 *uExported = *uSolution;
470 vector_Type errorVector ( ETuFESpace->map() , Unique , Zero);
471 vector_Type uexVector ( uFESpace->map(), Unique);
472 uFESpace->interpolate ( uExact, uexVector, 0);
473 errorVector = uexVector - *uSolution;
474 *errorExported = errorVector;
475 exporter.postProcess ( 1.0 );
479 std::cout <<
" Evaluate Errors " << std::endl;
482 Real errorL2SquaredLocal ( 0.0 );
483 Real errorH1SquaredLocal ( 0.0 );
484 Real errorL2Squared ( 0.0 );
485 Real errorH1Squared ( 0.0 );
486 Real errorH1BoundarySquared ( 0.0 );
488 vector_Type errorH1BoundaryVector ( ETuFESpace->map(), Repeated );
489 vector_Type errorH1BoundaryVectorUnique ( ETuFESpace->map() );
491 std::shared_ptr<uExactFunctor> uExactFct (
new uExactFunctor );
492 std::shared_ptr<gradExactFunctor> gradExactFct (
new gradExactFunctor );
495 using namespace ExpressionAssembly;
497 elements (ETuFESpace->mesh() ),
501 dot ( ( eval ( gradExactFct, X ) - grad ( ETuFESpace , *uSolution ) ) ,
502 ( eval ( gradExactFct, X ) - grad ( ETuFESpace , *uSolution ) ) )
505 >> errorH1SquaredLocal;
509 elements (ETuFESpace->mesh() ),
513 ( eval ( uExactFct, X ) - value ( ETuFESpace , *uSolution ) ) * ( eval ( uExactFct, X ) - value ( ETuFESpace , *uSolution ) )
516 >> errorL2SquaredLocal;
518 integrate ( boundary (ETuFESpace->mesh(), wall),
523 dot ( ( eval ( gradExactFct, X ) - dot ( eval ( gradExactFct, X ) , Nface ) * Nface )
524 - ( grad ( ETuFESpace , *uSolution ) - dot ( grad ( ETuFESpace , *uSolution ) , Nface ) * Nface ) ,
525 ( eval ( gradExactFct, X ) - dot ( eval ( gradExactFct, X ) , Nface ) * Nface )
526 - ( grad ( ETuFESpace , *uSolution ) - dot ( grad ( ETuFESpace , *uSolution ) , Nface ) * Nface )
528 ( eval ( uExactFct, X ) - value ( ETuFESpace , *uSolution ) )
529 * ( eval ( uExactFct, X ) - value ( ETuFESpace , *uSolution ) ) * phi_i
533 >> errorH1BoundaryVector;
538 Comm->SumAll (&errorH1SquaredLocal, &errorH1Squared, 1);
539 Comm->SumAll (&errorL2SquaredLocal, &errorL2Squared, 1);
541 vector_Type oneVector ( ETuFESpace->map(), Unique );
542 errorH1BoundaryVectorUnique = errorH1BoundaryVector;
545 errorH1BoundarySquared = errorH1BoundaryVectorUnique.dot ( oneVector );
549 std::cout <<
" l2 error norm " << std::sqrt ( errorL2Squared ) << std::endl;
551 std::cout <<
" H1 error norm " << sqrt ( errorH1Squared ) << std::endl;
553 std::cout <<
" H1 Gamma error norm " << std::sqrt ( errorH1BoundarySquared ) << std::endl;
556 exporter.closeFile();
558 Real tolerance (1e-5);
559 bool success (
false );
561 if ( ( abs ( sqrt (errorL2Squared) - 0.0768669 ) < tolerance )
562 && ( abs ( sqrt (errorH1Squared) - 1.76249 ) < tolerance )
563 && ( abs ( sqrt (errorH1BoundarySquared) - 2.35064 ) < tolerance )
573 std::cout <<
"End Result: TEST NOT PASSED" << std::endl;
580 std::cout <<
"End Result: TEST PASSED" << std::endl;
590 return ( EXIT_FAILURE );
594 return ( EXIT_SUCCESS );
VectorEpetra - The Epetra Vector format Wrapper.
Real gRobinRhs(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
std::shared_ptr< matrix_Type > matrixPtr_Type
LifeV::Preconditioner basePrec_Type
std::shared_ptr< vector_Type > vectorPtr_Type
Real uExact(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
return_Type operator()(const VectorSmall< 3 > spaceCoordinates)
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
Real const & operator[](UInt const &i) const
Operator [].
VectorSmall< 3 > return_Type
void updateInverseJacobian(const UInt &iQuadPt)
static const LifeV::UInt elm_nodes_num[]
gradExactFunctor(const gradExactFunctor &)
void normalize()
Normalize vector.
PreconditionerIfpack(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
Empty constructor.
Real & operator[](UInt const &i)
Operator [].
GRobinRhsFunctor(const GRobinRhsFunctor &)
RegionMesh< LinearTetra > mesh_Type
LaplacianExactFunctor(const LaplacianExactFunctor &)
return_Type operator()(const VectorSmall< 3 > spaceCoordinates)
Real laplacianExact(const Real &, const Real &x, const Real &y, const Real &z, const ID &)
std::shared_ptr< prec_Type > precPtr_Type
LifeV::PreconditionerIfpack prec_Type
std::shared_ptr< basePrec_Type > basePrecPtr_Type
return_Type operator()(const VectorSmall< 3 > spaceCoordinates)
double Real
Generic real data.
Preconditioner - Abstract preconditioner class.
uExactFunctor(const uExactFunctor &)
int main(int argc, char **argv)
MatrixEpetra< Real > matrix_Type
uint32_type UInt
generic unsigned integer (used mainly for addressing)
return_Type operator()(const VectorSmall< 3 > spaceCoordinates)