35 #include <Epetra_ConfigDefs.h> 38 #include <Epetra_MpiComm.h> 40 #include <Epetra_SerialComm.h> 43 #include <Teuchos_ParameterList.hpp> 44 #include <Teuchos_XMLParameterListHelpers.hpp> 45 #include <Teuchos_RCP.hpp> 47 #include <lifev/core/LifeV.hpp> 48 #include <lifev/core/mesh/RegionMesh.hpp> 49 #include <lifev/core/util/Displayer.hpp> 50 #include <lifev/core/algorithm/Preconditioner.hpp> 51 #include <lifev/core/algorithm/PreconditionerIfpack.hpp> 52 #include <lifev/core/algorithm/PreconditionerML.hpp> 53 #include <lifev/core/algorithm/PreconditionerLinearSolver.hpp> 57 #include <lifev/navier_stokes/solver/NavierStokesSolver/NavierStokesProblem.hpp> 58 #include <lifev/navier_stokes/solver/NavierStokesSolver/NavierStokesSolver.hpp> 59 #include <lifev/navier_stokes/solver/NavierStokesSolver/AssemblyPolicyStokes.hpp> 60 #include <lifev/navier_stokes/solver/NavierStokesSolver/AssemblyPolicyGeneralizedStokes.hpp> 61 #include <lifev/navier_stokes/solver/NavierStokesSolver/AssemblyPolicyNavierStokesSemiImplicit.hpp> 62 #include <lifev/navier_stokes/solver/NavierStokesSolver/AssemblyPolicyNavierStokesNewton.hpp> 63 #include <lifev/navier_stokes/solver/NavierStokesSolver/AssemblyPolicyNavierStokesPicard.hpp> 64 #include <lifev/navier_stokes/solver/NavierStokesSolver/TimeIterationPolicyLinear.hpp> 65 #include <lifev/navier_stokes/solver/NavierStokesSolver/TimeIterationPolicyNonlinear.hpp> 66 #include <lifev/navier_stokes/solver/NavierStokesSolver/TimeIterationPolicyNonlinearIncremental.hpp> 67 #include <lifev/navier_stokes/solver/NavierStokesSolver/InitPolicyInterpolation.hpp> 68 #include <lifev/navier_stokes/solver/NavierStokesSolver/InitPolicyProjection.hpp> 69 #include <lifev/navier_stokes/solver/NavierStokesSolver/InitPolicySolver.hpp> 70 #include <lifev/navier_stokes/solver/NavierStokesSolver/ExporterPolicyHDF5.hpp> 73 #include <lifev/navier_stokes/examples/TestCases/NavierStokesCavity.hpp> 74 #include <lifev/navier_stokes/examples/TestCases/NavierStokesEthierSteinman.hpp> 77 #include <lifev/navier_stokes/algorithm/PreconditionerLSC.hpp> 78 #include <lifev/navier_stokes/algorithm/PreconditionerPCD.hpp> 79 #include <lifev/navier_stokes/algorithm/PreconditionerSIMPLE.hpp> 80 #include <lifev/navier_stokes/algorithm/PreconditionerYosida.hpp> 82 using namespace LifeV;
110 const std::string& preconditionerName,
111 const std::string& precSection,
112 std::shared_ptr<NavierStokesProblem<mesh_Type> > nsProblem,
115 std::shared_ptr<Epetra_Comm> Comm,
116 const bool useMinusDiv )
118 if ( preconditionerName ==
"FromFile" )
120 std::string precName = dataFile
( "prec/prectype", "Ifpack" );
121 precPtr.reset ( PRECFactory::instance().createObject ( precName ) );
122 ASSERT ( precPtr.get() != 0,
" Preconditioner not set" );
123 precPtr->setDataFromGetPot ( dataFile, precSection );
125 #ifdef LIFEV_HAVE_TEKO 126 else if ( preconditionerName ==
"LSC" )
128 PreconditionerLSC* precLSCRawPtr ( 0 );
129 precLSCRawPtr =
new PreconditionerLSC;
130 precLSCRawPtr->setFESpace ( nsSolver.uFESpace(), nsSolver.pFESpace() );
131 precLSCRawPtr->setDataFromGetPot ( dataFile, precSection );
132 precPtr.reset ( precLSCRawPtr );
135 else if ( preconditionerName ==
"PCD" )
138 precPCDRawPtr =
new PreconditionerPCD;
139 precPCDRawPtr->setFESpace ( nsSolver.uFESpace(), nsSolver.pFESpace() );
140 precPCDRawPtr->setBCHandler ( nsSolver.bcHandler() );
141 precPCDRawPtr->setTimestep ( nsSolver.timestep() );
142 precPCDRawPtr->setViscosity ( nsProblem->viscosity() );
143 precPCDRawPtr->setDensity ( nsProblem->density() );
144 precPCDRawPtr->setComm ( Comm );
147 precPtr.reset ( precPCDRawPtr );
149 else if ( preconditionerName ==
"SIMPLE" )
152 precSIMPLERawPtr =
new PreconditionerSIMPLE;
153 precSIMPLERawPtr->setFESpace ( nsSolver.uFESpace(), nsSolver.pFESpace() );
155 precSIMPLERawPtr->setComm ( Comm );
156 precSIMPLERawPtr->setDataFromGetPot ( dataFile, precSection );
157 precPtr.reset ( precSIMPLERawPtr );
159 else if ( preconditionerName ==
"Yosida" )
162 precYosidaRawPtr =
new PreconditionerYosida;
163 precYosidaRawPtr->setFESpace ( nsSolver.uFESpace(), nsSolver.pFESpace() );
164 precYosidaRawPtr->setTimestep ( nsSolver.timestep() );
165 precYosidaRawPtr->setComm ( Comm );
167 precPtr.reset ( precYosidaRawPtr );
171 ASSERT (
false,
"The preconditioner is unknown." );
185 MPI_Init ( &argc, &argv );
187 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
189 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_SerialComm );
192 Displayer displayer ( Comm );
194 displayer.leaderPrint (
" +-----------------------------------------------+\n" );
195 displayer.leaderPrint (
" | Navier-Stokes Framework |\n" );
196 displayer.leaderPrint (
" +-----------------------------------------------+\n\n" );
197 displayer.leaderPrint (
" +-----------------------------------------------+\n" );
198 displayer.leaderPrint (
" | Author: Gwenol Grandperrin |\n" );
199 displayer.leaderPrint (
" | Date: 2013-12-03 |\n" );
200 displayer.leaderPrint (
" +-----------------------------------------------+\n" );
202 displayer.leaderPrint (
"\n[Initilization of MPI]\n" );
204 displayer.leaderPrint (
"Using MPI (", Comm->NumProc(),
" proc.)\n" );
206 displayer.leaderPrint (
"Using serial version\n" );
209 LifeChrono globalChrono;
210 globalChrono.start();
215 displayer.leaderPrint (
"\n[Loading the data]\n" );
221 GetPot command_line ( argc, argv );
222 const std::string datafileName = command_line.follow (
"data", 2,
"-f",
"--data" );
223 GetPot dataFile ( datafileName );
225 Teuchos::ParameterList mainList = * ( Teuchos::getParametersFromXmlFile ( datafileName +
".xml" ) );
227 std::string initPreconditionerName = mainList.get (
"Preconditioner for init",
"none" );
228 std::string preconditionerName = mainList.get (
"Preconditioner",
"none" );
233 displayer.leaderPrint (
"\n[Setup the test case]\n" );
236 Teuchos::ParameterList problemList = mainList.sublist (
"Navier-Stokes problem: Parameter list" );
237 const std::string benchmark = problemList.get (
"Test case name",
"none" );
238 const Real viscosity = problemList.get (
"Viscosity", 0.035 );
239 const Real density = problemList.get (
"Density", 1.0 );
240 const UInt meshRefinement = problemList.get (
"Mesh refinement", 2 );
241 std::string meshPath = problemList.get (
"Resources path",
"./Resources" );
242 meshPath.append (
"/");
245 std::shared_ptr< NavierStokesProblem< mesh_Type > > nsProblem;
246 if ( benchmark ==
"Cavity" )
248 nsProblem.reset (
new NavierStokesCavity );
250 else if ( benchmark ==
"Ethier-Steinman" )
252 nsProblem.reset (
new NavierStokesEthierSteinman );
256 displayer.leaderPrint (
"[Error] This benchmark does not exist\n" );
259 nsProblem->setMesh ( meshRefinement, meshPath );
260 nsProblem->setViscosity ( viscosity );
261 nsProblem->setDensity ( density );
263 displayer.leaderPrint (
"Test case : ", nsProblem->name(),
"\n" );
266 displayer.leaderPrint (
"Mesh refinement : ", meshRefinement,
"\n" );
267 displayer.leaderPrint (
"Mesh path : ", meshPath,
"\n" );
270 displayer.leaderPrint (
"Viscosity : ", viscosity,
"\n" );
271 displayer.leaderPrint (
"Density : ", density,
"\n" );
276 Teuchos::ParameterList nsSolverList = mainList.sublist (
"Navier-Stokes solver: Parameter list" );
277 bool useMinusDiv = nsSolverList.sublist (
"Time iteration: Parameter list" )
278 .sublist (
"Assembly: Parameter list" )
279 .get (
"Use minus divergence" ,
true );
283 nsSolver_Type nsSolver;
284 nsSolver.setProblem ( nsProblem );
285 nsSolver.setup ( nsSolverList );
286 basePrecPtr_Type precPtr;
287 setPreconditioner ( precPtr, initPreconditionerName,
288 "initprec", nsProblem, nsSolver, dataFile,
290 nsSolver.setPreconditioner ( precPtr );
299 setPreconditioner ( precPtr, preconditionerName,
300 "prec", nsProblem, nsSolver, dataFile,
302 nsSolver.setPreconditioner ( precPtr );
308 displayer.leaderPrintMax (
"\nTotal simulation time: ", globalChrono.diff(),
" s.\n" );
309 displayer.leaderPrint (
"\n[[END_SIMULATION]]\n" );
315 return ( EXIT_SUCCESS );
TimeIterationPolicyNonlinearIncremental< mesh_Type, AssemblyPolicyNavierStokesNewton< mesh_Type > > Newton
LifeV::Preconditioner basePrec_Type
InitPolicyProjection< SolverPolicyLinearSolver > InitProj
TimeIterationPolicyNonlinear< mesh_Type, AssemblyPolicyNavierStokesPicard< mesh_Type > > PicardOseen
PreconditionerPCD(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
default constructor
TimeIterationPolicyLinear< mesh_Type, AssemblyPolicyNavierStokesSemiImplicit< mesh_Type > > SemiImplicit
PreconditionerSIMPLE(std::shared_ptr< Epetra_Comm > comm=std::shared_ptr< Epetra_Comm >(new Epetra_MpiComm(MPI_COMM_WORLD)))
default constructor
InitPolicyInterpolation< mesh_Type > InitInter
void updateInverseJacobian(const UInt &iQuadPt)
void setDataFromGetPot(const GetPot &dataFile, const std::string §ion)
Setter using GetPot.
void setUseMinusDivergence(const bool &useMinusDivergence)
Setter to know if we used B or -B in the discretization of the Navier-Stokes equations.
RegionMesh< LinearTetra > mesh_Type
void setDataFromGetPot(const GetPot &dataFile, const std::string §ion)
Setter using GetPot.
NavierStokesSolver(commPtr_Type comm=commPtr_Type(new Epetra_MpiComm(MPI_COMM_WORLD)))
std::shared_ptr< basePrec_Type > basePrecPtr_Type
InitPolicySolver< mesh_Type, Stokes > InitStokes
int main(int argc, char **argv)
TimeIterationPolicyNonlinearIncremental< mesh_Type, AssemblyPolicyNavierStokesPicard< mesh_Type > > Picard
TimeIterationPolicyLinear< mesh_Type, AssemblyPolicyStokes< mesh_Type > > Stokes
Preconditioner - Abstract preconditioner class.
void setPreconditioner(basePrecPtr_Type &precPtr, const std::string &preconditionerName, const std::string &precSection, std::shared_ptr< NavierStokesProblem< mesh_Type > > nsProblem, const nsSolver_Type &nsSolver, const GetPot &dataFile, std::shared_ptr< Epetra_Comm > Comm, const bool useMinusDiv)
const std::string operator()(const char *VarName, const char *Default) const
TimeIterationPolicyLinear< mesh_Type, AssemblyPolicyGeneralizedStokes< mesh_Type > > GStokes
InitPolicySolver< mesh_Type, GStokes > InitGStokes
void setDampingFactor(const Real &dampingFactor)
Setter for the damping factor.
NavierStokesSolver< mesh_Type, InitStokes, SemiImplicit, HDF5Exporter > nsSolver_Type
ExporterPolicyHDF5< mesh_Type > HDF5Exporter
ExporterPolicyNoExporter NoExporter