27 #ifndef NAVIERSTOKES_H 28 #define NAVIERSTOKES_H 1
30 #include <lifev/navier_stokes/solver/OseenSolver.hpp> 31 #include <lifev/core/mesh/ElementShapes.hpp> 32 #include <lifev/core/mesh/MeshData.hpp> 33 #include <lifev/core/array/MatrixEpetra.hpp> 34 #include <lifev/core/array/MapEpetra.hpp> 35 #include <lifev/core/mesh/MeshPartitioner.hpp> 36 #include <lifev/core/mesh/MeshData.hpp> 37 #include <lifev/navier_stokes/solver/OseenData.hpp> 38 #include <lifev/core/fem/FESpace.hpp> 39 #include <lifev/navier_stokes/fem/TimeAdvanceBDFNavierStokes.hpp> 40 #include <lifev/core/filter/ExporterEnsight.hpp> 41 #include <lifev/core/filter/ExporterHDF5.hpp> 42 #include <lifev/core/filter/ExporterVTK.hpp> 43 #include <lifev/core/filter/ExporterEmpty.hpp> 44 #include <lifev/core/mesh/MeshUtility.hpp> 45 #include <lifev/core/filter/PartitionIO.hpp> 51 using namespace LifeV;
76 boost::shared_ptr<Epetra_Comm> Comm,
77 const std::string defaultDataName =
"data",
78 const std::string outputName =
"result");
92 using namespace LifeV;
96 boost::shared_ptr<Epetra_Comm> Comm,
97 const std::string defaultDataName,
98 const std::string outputName):
102 std::string data_file_name = command_line.follow (defaultDataName.c_str(), 2,
"-f",
"--file");
103 M_dataFile.reset(
new GetPot ( data_file_name ) );
107 void NavierStokes::
run()
113 bool verbose = (M_comm->MyPID() == 0);
135 regularMesh3D( *fullMeshPtr, 1, 16, 16, 16,
false, 2.0, 2.0, 2.0, -1.0, -1.0, -1.0);
143 std::cout <<
"\n[Partioning the mesh ]\n\n";
145 MeshPartitioner<
mesh_Type > meshPart (fullMeshPtr, M_comm);
146 localMeshPtr = meshPart.meshPartition();
153 std::string uOrder = (*M_dataFile)(
"fluid/space_discretization/vel_order",
"P1");
154 std::string pOrder = (*M_dataFile)(
"fluid/space_discretization/pres_order",
"P1");
157 uFESpace.reset (
new feSpace_Type (localMeshPtr, uOrder, 3, M_comm) );
160 pFESpace.reset (
new feSpace_Type (localMeshPtr, pOrder, 1, M_comm) );
162 UInt totalPressDof = pFESpace->dof().numTotalDof();
163 UInt pressureOffset = uFESpace->fieldDim() * uFESpace->dof().numTotalDof();
166 std::cout <<
"\n\n[Total Velocity Dof = " << pressureOffset <<
" ]\n";
169 std::cout <<
"\n[Total Pressure Dof = " << totalPressDof <<
" ]\n";
180 std::cout <<
"\n[Setting boundary conditions ] \n";
182 bcH.addBC(
"S", 2, Essential, Full, u_dirichlet, 3 );
183 bcH.addBC(
"S", 1, Essential, Full, u_dirichlet, 3 );
184 bcH.addBC(
"S", 3, Essential, Full, u_dirichlet, 3 );
185 bcH.addBC(
"S", 4, Essential, Full, u_dirichlet, 3 );
186 bcH.addBC(
"S", 6, Essential, Full, u_dirichlet, 3 );
187 bcH.addBC(
"S", 5, Natural, Full, u_neumann, 3 );
188 bcH.bcUpdate ( *localMeshPtr, uFESpace->feBd(), uFESpace->dof() );
194 std::string
const exporterType = (*M_dataFile)(
"exporter/type",
"hdf5");
198 std::cout <<
"\n[Setting the exporter ] \n";
200 if (exporterType.compare (
"hdf5") == 0){
201 exporter.reset (
new ExporterHDF5<mesh_Type > ( *M_dataFile, M_outputFilename ) );
202 exporter->setMeshProcId ( localMeshPtr, M_comm->MyPID() );
204 else if(exporterType.compare (
"vtk") == 0){
205 exporter.reset (
new ExporterVTK<mesh_Type > ( *M_dataFile, M_outputFilename ) );
206 exporter->setMeshProcId ( localMeshPtr, M_comm->MyPID() );
214 std::cout <<
"\n[Initializing the solver ] \n";
216 boost::shared_ptr<OseenData> oseenData (
new OseenData() );
217 oseenData->setup ( (*M_dataFile) );
219 OseenSolver< mesh_Type > fluid (oseenData, *uFESpace, *pFESpace, M_comm);
226 vectorPtr_Type exactPressPtr (
new vector_Type(pFESpace->map(), Repeated) );
227 vectorPtr_Type exactVelPtr (
new vector_Type(uFESpace->map(), Repeated) );
228 pFESpace->interpolate (
static_cast<feSpace_Type::function_Type> ( exactPressure ), *exactPressPtr, 0 );
229 uFESpace->interpolate (
static_cast<feSpace_Type::function_Type> ( exactVelocity ), *exactVelPtr, 0 );
235 vectorPtr_Type velAndPressure (
new vector_Type (fullMap, exporter->mapType() ) );
237 exporter->addVariable ( ExporterData<mesh_Type>::VectorField,
"u", uFESpace, velAndPressure, UInt (0) );
238 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"p", pFESpace, velAndPressure, pressureOffset );
239 exporter->addVariable ( ExporterData<mesh_Type>::VectorField,
"u_exact", uFESpace, exactVelPtr, UInt (0) );
240 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"p_exact", pFESpace, exactPressPtr, UInt (0) );
241 exporter->postProcess ( 0 );
249 fluid.setUp (*M_dataFile);
252 Real dt = oseenData->dataTime()->timeStep();
253 Real t0 = oseenData->dataTime()->initialTime();
254 Real tFinal = oseenData->dataTime()->endTime();
256 oseenData->dataTime()->setTime (t0);
259 bdf.setup (oseenData->dataTimeAdvance()->orderBDF() );
262 std::vector<vectorPtr_Type> solutionStencil;
263 solutionStencil.resize ( bdf.bdfVelocity().size() );
264 for ( UInt i(0); i < bdf.bdfVelocity().size() ; ++i){
266 *velAndPressure *= 0;
267 uFESpace->interpolate (
static_cast<feSpace_Type::function_Type> ( exactVelocity ), *exactVelPtr, t0-i*dt );
268 velAndPressure->subset(*exactVelPtr, uFESpace->map(), 0, 0);
269 solutionStencil[ i ] = velAndPressure;
272 bdf.bdfVelocity().setInitialCondition (solutionStencil);
274 Real alphaOverDt = bdf.bdfVelocity().coefficientFirstDerivative ( 0 ) / oseenData->dataTime()->timeStep();
284 Real L2ErrorVelocity, H1ErrorVelocity, L2ErrorPressure;
286 for ( ; time <= tFinal + dt / 2.; time += dt, iter++){
289 std::cout <<
"\n [Solving for time = " << time <<
" ] \n";
291 oseenData->dataTime()->setTime (time);
294 bdf.bdfVelocity().extrapolation (u_star);
297 bdf.bdfVelocity().updateRHSContribution(dt);
299 fluid.setVelocityRhs(bdf.bdfVelocity().rhsContributionFirstDerivative());
303 rhs = fluid.matrixMass() * bdf.bdfVelocity().rhsContributionFirstDerivative();
306 fluid.updateSystem ( alphaOverDt, u_star, rhs );
309 fluid.iterate ( bcH );
312 bdf.bdfVelocity().shiftRight ( *fluid.solution() );
315 *velAndPressure = *fluid.solution();
318 pFESpace->interpolate (
static_cast<
typename feSpace_Type::function_Type> ( exactPressure ), *exactPressPtr, time );
319 uFESpace->interpolate (
static_cast<
typename feSpace_Type::function_Type> ( exactVelocity ), *exactVelPtr, time );
325 vector_Type uComputed ( uFESpace->map() , Repeated );
326 uComputed.subset( *fluid.solution() );
328 vector_Type pComputed ( pFESpace->map() , Repeated );
329 pComputed.subset( *fluid.solution(), uFESpace->dim() *uFESpace->fieldDim());
334 L2ErrorVelocity = uFESpace->l2Error(exactVelocity, uComputed, time);
337 H1ErrorVelocity = uFESpace->h1Error(solutionAnal, uComputed, time);
340 L2ErrorPressure = pFESpace->l20Error(exactPressure, pComputed, time);
343 std::cout <<
"\n [L2 error velocity = " << L2ErrorVelocity <<
" ] \n";
344 std::cout <<
"\n [H1 error velocity = " << H1ErrorVelocity <<
" ] \n";
345 std::cout <<
"\n [L2 error pressure = " << L2ErrorPressure <<
" ] \n\n";
349 exporter->postProcess ( time );
VectorEpetra - The Epetra Vector format Wrapper.
boost::shared_ptr< mesh_Type > meshPtr_Type
OseenSolver< mesh_Type > fluid_Type
std::string M_outputFilename
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
BCHandler - class for handling boundary conditions.
boost::shared_ptr< vector_Type > vectorPtr_Type
boost::shared_ptr< Exporter< mesh_Type > > exporterPtr_Type
VectorEpetra(const MapEpetra &map, const MapEpetraType &mapType=Unique, const combineMode_Type combineMode=Add)
Constructor - Using Maps.
BCFunctionBase - class that holds the function used for prescribing boundary conditions.
FESpace< mesh_Type, MapEpetra > feSpace_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
boost::shared_ptr< GetPot > M_dataFile
RegionMesh< LinearTetra > mesh_Type
NavierStokes(int argc, char **argv, boost::shared_ptr< Epetra_Comm > Comm, const std::string defaultDataName="data", const std::string outputName="result")
double Real
Generic real data.
boost::shared_ptr< feSpace_Type > feSpacePtr_Type
uint32_type UInt
generic unsigned integer (used mainly for addressing)
boost::shared_ptr< Epetra_Comm > M_comm