27 #include <lifev/core/LifeV.hpp> 28 #include <lifev/core/util/LifeChrono.hpp> 29 #include <lifev/navier_stokes/solver/OseenSolver.hpp> 30 #include <lifev/core/mesh/MeshData.hpp> 31 #include <lifev/navier_stokes/solver/OseenData.hpp> 32 #include <lifev/core/array/MapEpetra.hpp> 33 #include <lifev/core/fem/FESpace.hpp> 34 #include <lifev/navier_stokes/fem/TimeAdvanceBDFNavierStokes.hpp> 35 #include <lifev/core/mesh/MeshPartitioner.hpp> 36 #include <lifev/core/filter/ExporterEnsight.hpp> 37 #include <lifev/core/filter/ExporterHDF5.hpp> 38 #include <lifev/core/filter/ExporterEmpty.hpp> 45 #include <Epetra_ConfigDefs.h> 47 #include "Epetra_MpiComm.h" 49 #include "Epetra_SerialComm.h" 53 using namespace LifeV;
96 int main (
int argc,
char** argv)
103 MPI_Init (&argc, &argv);
106 std::shared_ptr<Epetra_Comm> comm;
108 comm.reset (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
110 MPI_Comm_size (MPI_COMM_WORLD, &nproc);
112 comm.reset (
new Epetra_SerialComm() );
115 bool verbose (
false);
116 if (comm->MyPID() == 0)
120 <<
" +-----------------------------------------------+" << std::endl
121 <<
" | Cavity example for LifeV |" << std::endl
122 <<
" +-----------------------------------------------+" << std::endl
124 <<
" +-----------------------------------------------+" << std::endl
125 <<
" | Author: Gwenol Grandperrin |" << std::endl
126 <<
" | Date: October 25, 2010 |" << std::endl
127 <<
" +-----------------------------------------------+" << std::endl
130 std::cout <<
"[Initilization of MPI]" << std::endl;
132 std::cout <<
"Using MPI (" << nproc <<
" proc.)" << std::endl;
134 std::cout <<
"Using serial version" << std::endl;
150 std::cout << std::endl <<
"[Loading the data]" << std::endl;
153 const std::string dataFileName = command_line
.follow ("data", 2
, "-f", "--file");
161 std::cout << std::endl <<
"[Loading the mesh]" << std::endl;
164 meshData.setup (dataFile,
"fluid/space_discretization");
167 std::cout <<
"Mesh file: " << meshData.meshDir() << meshData.meshFile() << std::endl;
169 std::shared_ptr< mesh_Type > fullMeshPtr (
new mesh_Type);
170 readMesh (*fullMeshPtr, meshData);
172 MeshPartitioner<
mesh_Type > meshPart (fullMeshPtr, comm);
179 std::cout << std::endl <<
"[Creating the FE spaces]" << std::endl;
181 std::string uOrder = dataFile
( "fluid/space_discretization/vel_order", "P2");
182 std::string pOrder = dataFile
( "fluid/space_discretization/press_order", "P1");
183 if (verbose) std::cout <<
"FE for the velocity: " << uOrder << std::endl
184 <<
"FE for the pressure: " << pOrder << std::endl;
188 std::cout <<
"Building the velocity FE space... " << std::flush;
190 feSpacePtr_Type uFESpacePtr (
new feSpace_Type (meshPart.meshPartition(), uOrder, 3, comm) );
193 std::cout <<
"ok." << std::endl;
198 std::cout <<
"Building the pressure FE space... " << std::flush;
200 feSpacePtr_Type pFESpacePtr (
new feSpace_Type (meshPart.meshPartition(), pOrder, 1, comm) );
203 std::cout <<
"ok." << std::endl;
207 UInt totalVelDof = uFESpacePtr->map().map (Unique)->NumGlobalElements();
208 UInt totalPressDof = pFESpacePtr->map().map (Unique)->NumGlobalElements();
212 std::cout <<
"Total Velocity Dof: " << totalVelDof << std::endl;
216 std::cout <<
"Total Pressure Dof: " << totalPressDof << std::endl;
224 std::cout << std::endl <<
"[Boundary conditions]" << std::endl;
230 std::vector<ID> xComp (1);
235 bcH.addBC (
"Top" , TOP , Essential, Full , uLid , 3 );
236 bcH.addBC (
"Left" , LEFT , Essential, Full , uZero, 3 );
237 bcH.addBC (
"Front" , FRONT , Essential, Component, uZero, xComp );
238 bcH.addBC (
"Right" , RIGHT , Essential, Full , uZero, 3 );
239 bcH.addBC (
"Back" , BACK , Essential, Component, uZero, xComp );
240 bcH.addBC (
"Bottom", BOTTOM, Essential, Full , uZero, 3 );
243 std::vector<bcName_Type> fluxVector = bcH.findAllBCWithType ( Flux );
244 UInt numLM =
static_cast<UInt> ( fluxVector.size() );
246 UInt offset = uFESpacePtr->map().map (Unique)->NumGlobalElements()
247 + pFESpacePtr->map().map (Unique)->NumGlobalElements();
249 for (
UInt i = 0; i < numLM; ++i )
251 bcH.setOffset ( fluxVector[i], offset + i );
259 std::cout << std::endl <<
"[Creating the problem]" << std::endl;
261 std::shared_ptr< OseenData > oseenData (
new OseenData);
262 oseenData->setup ( dataFile );
267 std::cout <<
"Time discretization order " << oseenData->dataTimeAdvance()->orderBDF() << std::endl;
271 OseenSolver< mesh_Type > fluid (oseenData,
278 fluid.setUp (dataFile);
291 std::cout << std::endl <<
"[Initialization of the simulation]" << std::endl;
293 Real dt = oseenData->dataTime()->timeStep();
294 Real t0 = oseenData->dataTime()->initialTime();
295 Real tFinal = oseenData->dataTime()->endTime ();
299 bdf.setup (oseenData->dataTimeAdvance()->orderBDF() );
301 t0 -= dt * bdf.bdfVelocity().order();
309 oseenData->dataTime()->setTime (t0);
313 fluid.updateSystem (alpha, beta, rhs);
315 bdf.bdfVelocity().setInitialCondition ( *fluid.solution() );
318 for ( ; time <= oseenData->dataTime()->initialTime() + dt / 2.; time += dt)
320 oseenData->dataTime()->setTime (time);
322 fluid.updateSystem (alpha, beta, rhs);
324 bdf.bdfVelocity().shiftRight ( *fluid.solution() );
329 fluid.resetPreconditioner();
331 std::shared_ptr< ExporterHDF5<mesh_Type> > exporter;
333 std::string
const exporterType = dataFile
( "exporter/type", "ensight");
335 exporter.reset (
new ExporterHDF5<mesh_Type> ( dataFile,
"cavity_example" ) );
336 exporter->setPostDir (
"./" );
337 exporter->setMeshProcId ( meshPart.meshPartition(), comm->MyPID() );
340 velAndPressure.reset (
new vector_Type (*fluid.solution(), exporter->mapType() ) );
342 exporter->addVariable ( ExporterData<mesh_Type>::VectorField,
"velocity", uFESpacePtr,
343 velAndPressure, UInt (0) );
345 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"pressure", pFESpacePtr,
346 velAndPressure, UInt (3 * uFESpacePtr->dof().numTotalDof() ) );
347 exporter->postProcess ( 0 );
352 std::cout <<
"Initialization time: " << initChrono.diff() <<
" s." << std::endl;
360 std::cout << std::endl <<
"[Solving the problem]" << std::endl;
364 for ( ; time <= tFinal + dt / 2.; time += dt, iter++)
367 oseenData->dataTime()->setTime (time);
371 std::cout <<
"[t = " << oseenData->dataTime()->time() <<
" s.]" << std::endl;
376 double alpha = bdf.bdfVelocity().coefficientFirstDerivative ( 0 ) / oseenData->dataTime()->timeStep();
378 bdf.bdfVelocity().extrapolation (beta);
379 bdf.bdfVelocity().updateRHSContribution (oseenData->dataTime()->timeStep() );
380 rhs = fluid.matrixMass() * bdf.bdfVelocity().rhsContributionFirstDerivative();
382 fluid.getDisplayer().leaderPrint (
"alpha ", alpha);
383 fluid.getDisplayer().leaderPrint (
"\n");
384 fluid.getDisplayer().leaderPrint (
"norm beta ", beta.norm2() );
385 fluid.getDisplayer().leaderPrint (
"\n");
386 fluid.getDisplayer().leaderPrint (
"norm rhs ", rhs.norm2() );
387 fluid.getDisplayer().leaderPrint (
"\n");
389 fluid.updateSystem ( alpha, beta, rhs );
390 fluid.iterate ( bcH );
392 bdf.bdfVelocity().shiftRight ( *fluid.solution() );
397 vector_Type velpressure ( *fluid.solution(), Repeated );
399 velpressure = *fluid.solution();
400 vel.subset (velpressure);
401 press.subset (velpressure, uFESpacePtr->dim() *uFESpacePtr->fieldDim() );
404 bool verbose = (comm->MyPID() == 0);
408 *velAndPressure = *fluid.solution();
409 exporter->postProcess ( time );
414 std::cout <<
"Iteration time: " << iterChrono.diff() <<
" s." << std::endl << std::endl;
421 std::cout <<
"Total simulation time: " << globalChrono.diff() <<
" s." << std::endl;
424 exporter->closeFile();
Real fZero(const Real &, const Real &, const Real &, const Real &, const ID &)
fluid_Type::vector_Type vector_Type
void start()
Start the timer.
OseenSolver< mesh_Type > fluid_Type
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
BCHandler - class for handling boundary conditions.
Real lidBC(const Real &, const Real &, const Real &, const Real &, const ID &i)
BCFunctionBase - class that holds the function used for prescribing boundary conditions.
std::shared_ptr< vector_Type > vectorPtr_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
MeshData - class for handling spatial discretization.
FESpace< mesh_Type, MapEpetra > feSpace_Type
double Real
Generic real data.
std::shared_ptr< feSpace_Type > feSpacePtr_Type
const std::string operator()(const char *VarName, const char *Default) const
void stop()
Stop the timer.
RegionMesh< LinearTetra > mesh_Type
GetPot(const STRING_VECTOR &FileNameList)
const std::string follow(const char *Default, unsigned No, const char *Option,...)
int main(int argc, char **argv)
uint32_type UInt
generic unsigned integer (used mainly for addressing)