28 #include <Epetra_ConfigDefs.h> 31 #include <Epetra_MpiComm.h> 33 #include <Epetra_SerialComm.h> 37 #include <lifev/core/LifeV.hpp> 38 #include <lifev/core/mesh/MeshData.hpp> 39 #include <lifev/core/mesh/MeshPartitioner.hpp> 40 #include <lifev/navier_stokes_blocks/solver/NavierStokesSolverBlocks.hpp> 41 #include <lifev/core/fem/TimeAndExtrapolationHandler.hpp> 42 #include <lifev/core/filter/ExporterEnsight.hpp> 43 #include <lifev/core/filter/ExporterHDF5.hpp> 44 #include <lifev/core/filter/ExporterVTK.hpp> 45 #include <Teuchos_XMLParameterListHelpers.hpp> 49 using namespace LifeV;
52 main (
int argc,
char** argv )
56 MPI_Init (&argc, &argv);
57 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_MpiComm (MPI_COMM_WORLD) );
58 if ( Comm->MyPID() == 0 )
63 std::shared_ptr<Epetra_Comm> Comm(
new Epetra_SerialComm () );
69 typedef RegionMesh<LinearTetra> mesh_Type;
70 typedef VectorEpetra vector_Type;
71 typedef std::shared_ptr<vector_Type> vectorPtr_Type;
74 const std::string defaultDataName =
"data";
76 std::string data_file_name = command_line.follow (defaultDataName.c_str(), 2,
"-f",
"--file");
77 GetPot dataFile( data_file_name );
80 std::shared_ptr<mesh_Type > fullMeshPtr (
new mesh_Type ( Comm ) );
82 meshData.setup (dataFile,
"fluid/space_discretization");
83 readMesh (*fullMeshPtr, meshData);
87 std::shared_ptr<mesh_Type > localMeshPtr (
new mesh_Type ( Comm ) );
88 localMeshPtr = meshPart.meshPartition();
93 ns.setup(localMeshPtr);
97 Real saveAfter = dataFile
("fluid/save_after", 0.0
);
99 bool useStabilization = dataFile
("fluid/stabilization/use", false);
100 std::string stabilizationType = dataFile(
"fluid/stabilization/type",
"none");
102 int saveEvery = dataFile
( "fluid/save_every", 1
);
103 int counterSaveEvery = saveEvery;
106 TimeAndExtrapolationHandler timeVelocity;
107 Real dt = dataFile
("fluid/time_discretization/timestep",0.0
);
108 Real t0 = dataFile
("fluid/time_discretization/initialtime",0.0
);
109 Real tFinal = dataFile
("fluid/time_discretization/endtime",0.0
);
110 UInt orderBDF = dataFile
("fluid/time_discretization/BDF_order",2
);
113 timeVelocity.setBDForder(orderBDF);
114 timeVelocity.setMaximumExtrapolationOrder(orderBDF);
115 timeVelocity.setTimeStep(dt);
118 vector_Type velocityInitial ( ns.uFESpace()->map() );
119 std::vector<vector_Type> initialStateVelocity;
120 velocityInitial *= 0 ;
121 for ( UInt i = 0; i < orderBDF; ++i )
122 initialStateVelocity.push_back(velocityInitial);
124 timeVelocity.initialize(initialStateVelocity);
126 TimeAndExtrapolationHandler timePressure;
127 if ( useStabilization && stabilizationType.compare(
"VMSLES_SEMI_IMPLICIT")==0 )
129 timePressure.setBDForder(orderBDF);
130 timePressure.setMaximumExtrapolationOrder(orderBDF);
131 timePressure.setTimeStep(dt);
133 vector_Type pressureInitial ( ns.pFESpace()->map() );
134 std::vector<vector_Type> initialStatePressure;
135 pressureInitial.zero();
136 for ( UInt i = 0; i < orderBDF; ++i )
137 initialStatePressure.push_back(pressureInitial);
139 timePressure.initialize(initialStatePressure);
143 std::string outputName = dataFile (
"exporter/filename",
"result");
144 std::shared_ptr< ExporterHDF5<mesh_Type > > exporter;
146 exporter.reset (
new ExporterHDF5<mesh_Type > ( dataFile, outputName ) );
147 exporter->setPostDir (
"./" );
148 exporter->setMeshProcId ( localMeshPtr, Comm->MyPID() );
149 vectorPtr_Type velocity(
new vector_Type(ns.uFESpace()->map(), exporter->mapType() ) );
150 vectorPtr_Type pressure(
new vector_Type(ns.pFESpace()->map(), exporter->mapType() ) );
151 exporter->addVariable ( ExporterData<mesh_Type>::VectorField,
"velocity", ns.uFESpace(), velocity, UInt (0) );
152 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"pressure", ns.pFESpace(), pressure, UInt (0) );
154 exporter->postProcess ( t0 );
157 std::shared_ptr<BCHandler> bc (
new BCHandler (*BCh_fluid ()) );
158 std::shared_ptr<BCHandler> bc_drag (
new BCHandler (*BCh_drag ()) );
159 std::shared_ptr<BCHandler> bc_lift (
new BCHandler (*BCh_lift ()) );
161 std::string preconditioner = dataFile(
"fluid/preconditionerType",
"none");
164 LifeChrono iterChrono;
167 vectorPtr_Type u_star(
new vector_Type(ns.uFESpace()->map(), Unique ) );
168 vectorPtr_Type p_star(
new vector_Type(ns.pFESpace()->map(), Unique ) );
169 vectorPtr_Type rhs_velocity(
new vector_Type(ns.uFESpace()->map(), Unique ) );
174 int time_step_count = 0;
178 Real factor = 2.0/(1000.0*22.0*22.0*S);
179 std::ofstream outputFile_coefficients;
183 outputFile_coefficients.open (
"Aerodynamic_Coefficients.txt");
184 outputFile_coefficients <<
"% time / X force / Y force \n" << std::flush;
187 for ( ; time <= tFinal + dt / 2.; time += dt)
189 time_step_count += 1;
192 std::cout <<
"\nWe are at time " << time <<
" s\n\n";
198 rhs_velocity->zero();
199 timeVelocity.extrapolate (orderBDF, *u_star);
200 timeVelocity.rhsContribution (*rhs_velocity);
202 if ( useStabilization && stabilizationType.compare(
"VMSLES_SEMI_IMPLICIT")==0 )
204 timePressure.extrapolate (orderBDF,*p_star);
209 ns.iterate( bc, time );
211 AerodynamicCoefficients = ns.computeForces(*bc_drag, *bc_lift);
215 std::cout <<
"\nDrag coefficient " << AerodynamicCoefficients[0]*factor <<
"\n";
216 std::cout <<
"\nLift coefficient " << AerodynamicCoefficients[1]*factor <<
"\n";
217 outputFile_coefficients << time <<
" " << AerodynamicCoefficients[0]*factor <<
" " << AerodynamicCoefficients[1]*factor <<
"\n" << std::flush;
226 std::cout <<
"\nTimestep solved in " << iterChrono.diff() <<
" s\n";
234 if ( time_step_count == counterSaveEvery )
236 if ( time >= saveAfter )
238 exporter->postProcess ( time );
242 else if ( orderBDF == 2 )
244 if ( time_step_count == (counterSaveEvery-1) )
246 if ( time >= saveAfter )
248 exporter->postProcess ( time );
251 else if ( time_step_count == counterSaveEvery )
253 if ( time >= saveAfter )
255 exporter->postProcess ( time );
257 counterSaveEvery += saveEvery;
261 timeVelocity.shift(*velocity);
263 if ( useStabilization && stabilizationType.compare(
"VMSLES_SEMI_IMPLICIT")==0 )
264 timePressure.shift(*pressure);
270 outputFile_coefficients.close();
273 exporter->closeFile();
280 std::cout <<
"\nMPI Finalization" << std::endl;
284 return ( EXIT_SUCCESS );
void setAlpha(const Real &alpha)
Set coefficient associated to the time discretization scheme.
double operator()(const char *VarName, const double &Default) const
void updateSystem(const vectorPtr_Type &u_star, const vectorPtr_Type &rhs_velocity)
Update the convective term and the right hand side.
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
std::shared_ptr< std::vector< Int > > M_isOnProc
void setExtrapolatedPressure(const vectorPtr_Type &pressure_extrapolated)
Set the extrapolated pressure vector (used by semi-implicit VMS-LES stabilization) ...
MeshData - class for handling spatial discretization.
void setParameters()
Set parameters of the solver.
double Real
Generic real data.
void updateVelocity(vectorPtr_Type &velocity)
Get the velocity vector.
void updatePressure(vectorPtr_Type &pressure)
Get the pressure vector.
void setTimeStep(const Real &dt)
Set time step.
int operator()(const char *VarName, int Default) const
void buildSystem()
Assemble constant terms.
bool operator()(const char *VarName, bool Default) const
int main(int argc, char **argv)
uint32_type UInt
generic unsigned integer (used mainly for addressing)