35 #ifndef NAVIERSTOKESSOLVER_HPP 36 #define NAVIERSTOKESSOLVER_HPP 40 #include <boost/shared_ptr.hpp> 44 #include <Epetra_MpiComm.h> 46 #include <Epetra_SerialComm.h> 49 #include <Teuchos_ParameterList.hpp> 50 #include <Teuchos_XMLParameterListHelpers.hpp> 51 #include <Teuchos_RCP.hpp> 54 #include <lifev/core/LifeV.hpp> 55 #include <lifev/core/array/MapEpetra.hpp> 56 #include <lifev/core/array/MatrixEpetra.hpp> 57 #include <lifev/core/array/VectorEpetra.hpp> 58 #include <lifev/core/mesh/RegionMesh.hpp> 59 #include <lifev/core/util/Displayer.hpp> 60 #include <lifev/core/util/LifeAssert.hpp> 61 #include <lifev/core/util/LifeChrono.hpp> 62 #include <lifev/core/fem/FESpace.hpp> 63 #include <lifev/core/fem/BCHandler.hpp> 64 #include <lifev/core/fem/BCManage.hpp> 65 #include <lifev/core/fem/TimeAdvanceBDF.hpp> 66 #include <lifev/navier_stokes/solver/OseenAssembler.hpp> 68 #include <lifev/navier_stokes/solver/NavierStokesSolver/ExporterPolicyNoExporter.hpp> 69 #include <lifev/navier_stokes/solver/NavierStokesSolver/NavierStokesProblem.hpp> 76 class NavierStokesSolver :
private InitPolicy,
public virtual TimeIterationPolicy,
private ExporterPolicy
107 NavierStokesSolver (
commPtr_Type comm = commPtr_Type (
new Epetra_SerialComm ) );
122 void setup ( Teuchos::ParameterList& list );
217 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
224 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
230 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
234 ASSERT ( M_nsProblem->hasExactSolution(),
"The problem does not have an exact solution" );
236 vector_Type velocity ( M_uFESpace->map(), Repeated );
237 vector_Type pressure ( M_pFESpace->map(), Repeated );
238 M_displayer.leaderPrint (
"[Computing errors]\n" );
239 velocity.subset ( *M_solution );
240 pressure.subset ( *M_solution, M_uFESpace->fieldDim() * M_uFESpace->dof().numTotalDof() );
241 Real uRelativeError, pRelativeError, uL2Error, pL2Error;
242 uL2Error = M_uFESpace->l2Error ( M_nsProblem->uexact(), velocity, M_currentTime, &uRelativeError );
243 pL2Error = M_pFESpace->l20Error ( M_nsProblem->pexact(), pressure, M_currentTime, &pRelativeError );
245 M_displayer.leaderPrint (
" L2 error : ", uL2Error,
"\n" );
246 M_displayer.leaderPrint (
" Relative error: ", uRelativeError,
"\n" );
248 M_displayer.leaderPrint (
" L2 error : ", pL2Error,
"\n");
249 M_displayer.leaderPrint (
" Relative error: ", pRelativeError,
"\n" );
252 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
259 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
263 ASSERT ( M_nsProblem.get() != 0,
"NavierStokesSolver::init : Error: You must set a Navier-Stokes problem first." );
266 std::string uOrder = list.get (
"Velocity FE",
"P2" );
267 std::string pOrder = list.get (
"Pressure FE",
"P1" );
270 Teuchos::ParameterList timeList = list.sublist (
"Time: Parameter list" );
271 M_initialTime = timeList.get (
"Initial time", 0.0 );
272 M_endTime = timeList.get (
"Final time", 1e-2 );
273 M_timestep = timeList.get (
"Timestep", 1e-3 );
276 Teuchos::ParameterList solverList = list.sublist (
"Solver: Parameter list" );
277 M_usePreviousSolutionAsGuess = solverList.get (
"Use previous solution as guess",
false );
282 M_displayer.leaderPrint (
"\n[Loading the mesh]\n" );
283 M_nsProblem->mesh ( M_mesh );
288 M_displayer.leaderPrint (
"\n[Creating the FE spaces]\n" );
292 M_displayer.leaderPrint (
"FE for the velocity: ", uOrder,
"\n" );
293 M_displayer.leaderPrint (
"FE for the pressure: ", pOrder,
"\n" );
295 M_displayer.leaderPrint (
"Building the velocity FE space ... " );
296 M_uFESpace.reset (
new fespace_Type ( M_mesh, uOrder, 3, M_comm ) );
299 M_displayer.leaderPrint (
"Building the pressure FE space ... " );
300 M_pFESpace.reset (
new fespace_Type ( M_mesh, pOrder, 1, M_comm ) );
304 M_solutionMap.reset (
new map_Type ( M_uFESpace->map() + M_pFESpace->map() ) );
307 UInt pressureOffset = M_uFESpace->fieldDim() * M_uFESpace->dof().numTotalDof();
309 M_displayer.leaderPrint (
"Total Velocity Dof: ", pressureOffset,
"\n" );
310 M_displayer.leaderPrint (
"Total Pressure Dof: ", M_pFESpace->dof().numTotalDof(),
"\n" );
313 M_displayer.leaderPrintMax (
"FE spaces building time: ", feSpaceChrono
.diff(),
" s.\n");
318 M_displayer.leaderPrint (
"\n[Boundary conditions]\n" );
323 M_bcHandler.reset (
new bcContainer_Type );
326 M_nsProblem->boundaryConditions ( M_bcHandler );
330 M_bcHandler->bcUpdate ( *M_mesh, M_uFESpace->feBd(), M_uFESpace->dof() );
338 M_displayer.leaderPrint (
"Creation of vectors... " );
339 M_solution.reset (
new vector_Type ( *M_solutionMap, Unique ) );
342 M_bdf.reset (
new bdf_Type );
343 M_bdf->setup ( TimeIterationPolicy::BDFOrder );
346 Teuchos::ParameterList exporterList = list.sublist (
"Exporter: Parameter list" );
347 ExporterPolicy::initExporter ( exporterList,
351 Teuchos::ParameterList timeIterationList = list.sublist (
"Time iteration: Parameter list" );
352 TimeIterationPolicy::initTimeIteration ( timeIterationList );
354 InitPolicy::setupInit ( timeIterationList ) ;
358 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
368 if ( M_nsProblem->hasExactSolution() )
374 ExporterPolicy::exportSolution ();
377 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
382 M_displayer.leaderPrint (
"\n[Solving the problem]\n" );
406 M_bdf->shiftRight ( *M_solution );
408 ExporterPolicy::exportSolution ();
413 if ( M_nsProblem->hasExactSolution() )
421 MPI_Barrier ( MPI_COMM_WORLD );
426 M_displayer.leaderPrintMax (
"Time of the temporal loop: ", nsTimeLoopChrono
.diff(),
" s.\n");
429 ExporterPolicy::finalizeExporter();
432 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
439 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
446 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
453 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
460 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
467 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
474 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
481 template<
class Mesh,
class InitPolicy,
class TimeIterationPolicy,
class ExporterPolicy >
VectorEpetra - The Epetra Vector format Wrapper.
MatrixEpetra< Real > matrix_Type
bool M_usePreviousSolutionAsGuess
void start()
Start the timer.
bcContainerPtr_Type bcHandler() const
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
Displayer(const commPtr_Type &comm)
void printErrors()
Prints the error of the finite element solution vector.
BCHandler - class for handling boundary conditions.
std::shared_ptr< assembler_Type > assemblerPtr_Type
void setup(Teuchos::ParameterList &list)
Setup all the parameters.
fespacePtr_Type M_pFESpace
mapPtr_Type M_solutionMap
std::shared_ptr< fespace_Type > fespacePtr_Type
Real endTime() const
Returns the end time.
std::shared_ptr< comm_Type > commPtr_Type
void updateInverseJacobian(const UInt &iQuadPt)
Real timestep() const
Returns the timestep.
std::shared_ptr< bdf_Type > bdfPtr_Type
Real initialTime() const
Returns the initial time.
void solve()
Solves the Navier-Stokes equations.
OseenAssembler< Mesh, matrix_Type, vector_Type > assembler_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
fespacePtr_Type pFESpace() const
Returns the FE space for the pressure.
std::shared_ptr< map_Type > mapPtr_Type
BCHandler bcContainer_Type
fespacePtr_Type M_uFESpace
std::shared_ptr< Mesh > meshPtr_Type
NavierStokesSolver(commPtr_Type comm=commPtr_Type(new Epetra_MpiComm(MPI_COMM_WORLD)))
Real diff()
Compute the difference in time between start and stop.
FESpace< Mesh, map_Type > fespace_Type
void init()
Computes an initial solutions, or several solutions, if needed.
meshPtr_Type mesh() const
bcContainerPtr_Type M_bcHandler
Real currentTime() const
Returns the current time.
double Real
Generic real data.
std::shared_ptr< NavierStokesProblem< Mesh > > NSProblemPtr_Type
TimeAdvanceBDF< vector_Type > bdf_Type
void stop()
Stop the timer.
vectorPtr_Type M_solution
void setProblem(NSProblemPtr_Type nsProblem)
Setup the problem to be solved.
fespacePtr_Type uFESpace() const
Returns the FE space for the velocity.
std::shared_ptr< matrix_Type > matrixPtr_Type
std::shared_ptr< VectorEpetra > vectorPtr_Type
NSProblemPtr_Type problem() const
Returns the type of problem (e.g. Navier-Stokes)
Displayer - This class is used to display messages in parallel simulations.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
std::shared_ptr< bcContainer_Type > bcContainerPtr_Type
NSProblemPtr_Type M_nsProblem