26 #include <life/lifecore/LifeV.hpp> 27 #include <life/lifecore/LifeChrono.hpp> 28 #include <life/lifesolver/OseenSolver.hpp> 29 #include <life/lifemesh/MeshData.hpp> 30 #include <life/lifesolver/OseenData.hpp> 31 #include <life/lifearray/MapEpetra.hpp> 32 #include <life/lifefem/FESpace.hpp> 33 #include <life/lifefem/TimeAdvanceBDFNavierStokes.hpp> 34 #include <life/lifemesh/MeshPartitioner.hpp> 35 #include <life/lifefilters/ExporterEnsight.hpp> 36 #include <life/lifefilters/ExporterHDF5.hpp> 37 #include <life/lifefilters/ExporterEmpty.hpp> 41 #include <Epetra_ConfigDefs.h> 43 #include "Epetra_MpiComm.h" 45 #include "Epetra_SerialComm.h" 86 int main (
int argc,
char** argv)
93 MPI_Init (&argc, &argv);
96 std::shared_ptr<Epetra_Comm> comm;
98 comm.reset (
new Epetra_MpiComm ( MPI_COMM_WORLD ) );
100 MPI_Comm_size (MPI_COMM_WORLD, &nproc);
102 comm.reset (
new Epetra_SerialComm() );
105 bool verbose (
false);
106 if (comm->MyPID() == 0)
110 <<
" +-----------------------------------------------+" << std::endl
111 <<
" | Cavity example for LifeV |" << std::endl
112 <<
" +-----------------------------------------------+" << std::endl
114 <<
" +-----------------------------------------------+" << std::endl
115 <<
" | Author: Gwenol Grandperrin |" << std::endl
116 <<
" | Date: October 25, 2010 |" << std::endl
117 <<
" +-----------------------------------------------+" << std::endl
120 std::cout <<
"[Initilization of MPI]" << std::endl;
122 std::cout <<
"Using MPI (" << nproc <<
" proc.)" << std::endl;
124 std::cout <<
"Using serial version" << std::endl;
129 LifeV::LifeChrono globalChrono;
130 LifeV::LifeChrono initChrono;
131 LifeV::LifeChrono iterChrono;
132 globalChrono.start();
140 std::cout << std::endl <<
"[Loading the data]" << std::endl;
142 GetPot command_line (argc, argv);
143 const std::string dataFileName = command_line.follow (
"data", 2,
"-f",
"--file");
144 GetPot dataFile (dataFileName);
151 std::cout << std::endl <<
"[Loading the mesh]" << std::endl;
153 LifeV::MeshData meshData;
154 meshData.setup (dataFile,
"fluid/space_discretization");
157 std::cout <<
"Mesh file: " << meshData.meshDir() << meshData.meshFile() << std::endl;
159 std::shared_ptr< mesh_Type > fullMeshPtr (
new mesh_Type);
160 LifeV::readMesh (*fullMeshPtr, meshData);
162 std::shared_ptr< mesh_Type > localMeshPtr;
164 LifeV::MeshPartitioner< mesh_Type > meshPart (fullMeshPtr, comm);
165 localMeshPtr = meshPart.meshPartition();
173 std::cout << std::endl <<
"[Creating the FE spaces]" << std::endl;
175 std::string uOrder = dataFile (
"fluid/space_discretization/vel_order",
"P2");
176 std::string pOrder = dataFile (
"fluid/space_discretization/press_order",
"P1");
177 if (verbose) std::cout <<
"FE for the velocity: " << uOrder << std::endl
178 <<
"FE for the pressure: " << pOrder << std::endl;
182 std::cout <<
"Building the velocity FE space... " << std::flush;
184 feSpacePtr_Type uFESpacePtr (
new feSpace_Type (localMeshPtr, uOrder, 3, comm) );
187 std::cout <<
"ok." << std::endl;
192 std::cout <<
"Building the pressure FE space... " << std::flush;
194 feSpacePtr_Type pFESpacePtr (
new feSpace_Type (localMeshPtr, pOrder, 1, comm) );
197 std::cout <<
"ok." << std::endl;
201 LifeV::UInt totalVelDof = uFESpacePtr->map().map (LifeV::Unique)->NumGlobalElements();
202 LifeV::UInt totalPressDof = pFESpacePtr->map().map (LifeV::Unique)->NumGlobalElements();
206 std::cout <<
"Total Velocity Dof: " << totalVelDof << std::endl;
210 std::cout <<
"Total Pressure Dof: " << totalPressDof << std::endl;
218 std::cout << std::endl <<
"[Boundary conditions]" << std::endl;
221 LifeV::BCFunctionBase uZero (fZero);
222 LifeV::BCFunctionBase uLid (lidBC);
224 std::vector<LifeV::ID> xComp (1);
227 LifeV::BCHandler bcH;
229 bcH.addBC (
"Top" , TOP , LifeV::Essential, LifeV::Full , uLid , 3 );
230 bcH.addBC (
"Left" , LEFT , LifeV::Essential, LifeV::Full , uZero, 3 );
231 bcH.addBC (
"Front" , FRONT , LifeV::Essential, LifeV::Component, uZero, xComp );
232 bcH.addBC (
"Right" , RIGHT , LifeV::Essential, LifeV::Full , uZero, 3 );
233 bcH.addBC (
"Back" , BACK , LifeV::Essential, LifeV::Component, uZero, xComp );
234 bcH.addBC (
"Bottom", BOTTOM, LifeV::Essential, LifeV::Full , uZero, 3 );
237 std::vector<LifeV::bcName_Type> fluxVector = bcH.findAllBCWithType ( LifeV::Flux );
238 LifeV::UInt numLM =
static_cast<LifeV::UInt> ( fluxVector.size() );
240 LifeV::UInt offset = uFESpacePtr->map().map (LifeV::Unique)->NumGlobalElements()
241 + pFESpacePtr->map().map (LifeV::Unique)->NumGlobalElements();
243 for ( LifeV::UInt i = 0; i < numLM; ++i )
245 bcH.setOffset ( fluxVector[i], offset + i );
253 std::cout << std::endl <<
"[Creating the problem]" << std::endl;
255 std::shared_ptr<LifeV::OseenData> oseenData (
new LifeV::OseenData() );
256 oseenData->setup ( dataFile );
260 std::cout <<
"Time discretization order " << oseenData->dataTime()->orderBDF() << std::endl;
264 LifeV::OseenSolver< mesh_Type > fluid (oseenData,
270 fluid.setUp (dataFile);
276 LifeV::MapEpetra fullMap (fluid.getMap() );
279 MPI_Barrier (MPI_COMM_WORLD);
286 std::cout << std::endl <<
"[Initialization of the simulation]" << std::endl;
288 LifeV::Real dt = oseenData->dataTime()->timeStep();
289 LifeV::Real t0 = oseenData->dataTime()->initialTime();
290 LifeV::Real tFinal = oseenData->dataTime()->endTime ();
293 LifeV::TimeAdvanceBDFNavierStokes<vector_Type> bdf;
294 bdf.setup (oseenData->dataTime()->orderBDF() );
297 t0 -= dt * bdf.bdfVelocity().order();
302 MPI_Barrier (MPI_COMM_WORLD);
305 oseenData->dataTime()->setTime (t0);
309 fluid.updateSystem (0.0, beta, rhs);
311 bdf.bdfVelocity().setInitialCondition ( *fluid.solution() );
313 LifeV::Real time = t0 + dt;
314 for ( ; time <= oseenData->dataTime()->initialTime() + dt / 2.; time += dt)
316 oseenData->dataTime()->setTime (time);
318 fluid.updateSystem (0.0, beta, rhs);
320 bdf.bdfVelocity().shiftRight ( *fluid.solution() );
325 fluid.resetPreconditioner();
327 std::shared_ptr< LifeV::ExporterHDF5<mesh_Type> > exporter;
331 std::string
const exporterType = dataFile (
"exporter/type",
"ensight");
333 exporter.reset (
new LifeV::ExporterHDF5<mesh_Type> ( dataFile,
"cavity_example" ) );
334 exporter->setPostDir (
"./" );
335 exporter->setMeshProcId ( localMeshPtr, comm->MyPID() );
337 velAndPressure.reset (
new vector_Type (*fluid.solution(), exporter->mapType() ) );
339 exporter->addVariable ( LifeV::ExporterData<mesh_Type>::VectorField,
"velocity", uFESpacePtr,
340 velAndPressure, LifeV::UInt (0) );
342 exporter->addVariable ( LifeV::ExporterData<mesh_Type>::ScalarField,
"pressure", pFESpacePtr,
343 velAndPressure, LifeV::UInt (3 * uFESpacePtr->dof().numTotalDof() ) );
344 exporter->postProcess ( 0 );
349 std::cout <<
"Initialization time: " << initChrono.diff() <<
" s." << std::endl;
357 std::cout << std::endl <<
"[Solving the problem]" << std::endl;
361 for ( ; time <= tFinal + dt / 2.; time += dt, iter++)
364 oseenData->dataTime()->setTime (time);
368 std::cout <<
"[t = " << oseenData->dataTime()->time() <<
" s.]" << std::endl;
373 double alpha = bdf.bdfVelocity().coefficientFirstDerivative ( 0 ) / oseenData->dataTime()->timeStep();
376 bdf.bdfVelocity().extrapolation ( beta );
377 bdf.bdfVelocity().updateRHSContribution (oseenData->dataTime()->timeStep() );
378 rhs = fluid.matrixMass() * bdf.bdfVelocity().rhsContributionFirstDerivative();
380 fluid.getDisplayer().leaderPrint (
"alpha ", alpha);
381 fluid.getDisplayer().leaderPrint (
"\n");
382 fluid.getDisplayer().leaderPrint (
"norm beta ", beta.norm2() );
383 fluid.getDisplayer().leaderPrint (
"\n");
384 fluid.getDisplayer().leaderPrint (
"norm rhs ", rhs.norm2() );
385 fluid.getDisplayer().leaderPrint (
"\n");
387 fluid.updateSystem ( alpha, beta, rhs );
388 fluid.iterate ( bcH );
390 bdf.bdfVelocity().shiftRight ( *fluid.solution() );
393 vector_Type vel (uFESpacePtr->map(), LifeV::Repeated);
394 vector_Type press (pFESpacePtr->map(), LifeV::Repeated);
395 vector_Type velpressure ( *fluid.solution(), LifeV::Repeated );
397 velpressure = *fluid.solution();
398 vel.subset (velpressure);
399 press.subset (velpressure, uFESpacePtr->dim() *uFESpacePtr->fieldDim() );
402 bool verbose = (comm->MyPID() == 0);
406 *velAndPressure = *fluid.solution();
407 exporter->postProcess ( time );
410 MPI_Barrier (MPI_COMM_WORLD);
415 std::cout <<
"Iteration time: " << iterChrono.diff() <<
" s." << std::endl << std::endl;
422 std::cout <<
"Total simulation time: " << globalChrono.diff() <<
" s." << std::endl;
425 exporter->closeFile();
LifeV::RegionMesh< LifeV::LinearTetra > mesh_Type
LifeV::Real fZero(const LifeV::Real &, const LifeV::Real &, const LifeV::Real &, const LifeV::Real &, const LifeV::ID &)
std::shared_ptr< feSpace_Type > feSpacePtr_Type
LifeV::OseenSolver< mesh_Type > fluid_Type
int main(int argc, char **argv)
LifeV::Real lidBC(const LifeV::Real &t, const LifeV::Real &, const LifeV::Real &, const LifeV::Real &, const LifeV::ID &i)
LifeV::FESpace< mesh_Type, LifeV::MapEpetra > feSpace_Type
std::shared_ptr< vector_Type > vectorPtr_Type
fluid_Type::vector_Type vector_Type