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;
57 const Real& coefficient );
65 main (
int argc,
char** argv )
69 MPI_Init (&argc, &argv);
70 std::shared_ptr<Epetra_Comm> Comm (
new Epetra_MpiComm (MPI_COMM_WORLD) );
71 if ( Comm->MyPID() == 0 )
76 std::shared_ptr<Epetra_Comm> Comm(
new Epetra_SerialComm () );
85 const std::string defaultDataName =
"data";
87 std::string data_file_name = command_line.follow (defaultDataName.c_str(), 2,
"-f",
"--file");
88 GetPot dataFile( data_file_name );
91 std::shared_ptr<mesh_Type > fullMeshPtr (
new mesh_Type ( Comm ) );
93 meshData.setup (dataFile,
"fluid/space_discretization");
94 readMesh (*fullMeshPtr, meshData);
98 std::shared_ptr<mesh_Type > localMeshPtr (
new mesh_Type ( Comm ) );
99 localMeshPtr = meshPart.meshPartition();
104 ns.setup(localMeshPtr);
109 Real saveAfter = dataFile
("fluid/save_after", 0.0
);
111 bool useStabilization = dataFile
("fluid/stabilization/use", false);
112 std::string stabilizationType = dataFile(
"fluid/stabilization/type",
"none");
114 int saveEvery = dataFile
( "fluid/save_every", 1
);
115 int counterSaveEvery = saveEvery;
118 TimeAndExtrapolationHandler timeVelocity;
119 Real dt = dataFile
("fluid/time_discretization/timestep",0.0
);
120 Real t0 = dataFile
("fluid/time_discretization/initialtime",0.0
);
121 Real tFinal = dataFile
("fluid/time_discretization/endtime",0.0
);
122 UInt orderBDF = dataFile
("fluid/time_discretization/BDF_order",2
);
125 timeVelocity.setBDForder(orderBDF);
126 timeVelocity.setMaximumExtrapolationOrder(orderBDF);
127 timeVelocity.setTimeStep(dt);
130 vector_Type velocityInitial ( ns.uFESpace()->map() );
131 std::vector<vector_Type> initialStateVelocity;
132 velocityInitial *= 0 ;
133 for ( UInt i = 0; i < orderBDF; ++i )
134 initialStateVelocity.push_back(velocityInitial);
136 timeVelocity.initialize(initialStateVelocity);
138 TimeAndExtrapolationHandler timePressure;
139 if ( useStabilization && stabilizationType.compare(
"VMSLES_SEMI_IMPLICIT")==0 )
141 timePressure.setBDForder(orderBDF);
142 timePressure.setMaximumExtrapolationOrder(orderBDF);
143 timePressure.setTimeStep(dt);
145 vector_Type pressureInitial ( ns.pFESpace()->map() );
146 std::vector<vector_Type> initialStatePressure;
147 pressureInitial.zero();
148 for ( UInt i = 0; i < orderBDF; ++i )
149 initialStatePressure.push_back(pressureInitial);
151 timePressure.initialize(initialStatePressure);
155 std::string outputName = dataFile (
"exporter/filename",
"result");
156 std::shared_ptr< ExporterHDF5<mesh_Type > > exporter;
158 exporter.reset (
new ExporterHDF5<mesh_Type > ( dataFile, outputName ) );
159 exporter->setPostDir (
"./" );
160 exporter->setMeshProcId ( localMeshPtr, Comm->MyPID() );
161 vectorPtr_Type velocity(
new vector_Type(ns.uFESpace()->map(), exporter->mapType() ) );
162 vectorPtr_Type pressure(
new vector_Type(ns.pFESpace()->map(), exporter->mapType() ) );
163 exporter->addVariable ( ExporterData<mesh_Type>::VectorField,
"velocity", ns.uFESpace(), velocity, UInt (0) );
164 exporter->addVariable ( ExporterData<mesh_Type>::ScalarField,
"pressure", ns.pFESpace(), pressure, UInt (0) );
169 std::shared_ptr<BCHandler> bc (
new BCHandler (*BCh_fluid ()) );
170 std::shared_ptr<BCHandler> bc_preprocessing (
new BCHandler (*BCh_preprocessing ()) );
172 std::string preconditioner = dataFile(
"fluid/preconditionerType",
"none");
175 LifeChrono iterChrono;
178 vectorPtr_Type u_star(
new vector_Type(ns.uFESpace()->map(), Unique ) );
179 vectorPtr_Type p_star(
new vector_Type(ns.pFESpace()->map(), Unique ) );
180 vectorPtr_Type rhs_velocity(
new vector_Type(ns.uFESpace()->map(), Unique ) );
188 vectorPtr_Type laplacianSolution(
new vector_Type( ns.uFESpace_scalar()->map() ) );
189 laplacianSolution->zero();
190 ns.solveLaplacian(flag, bc_preprocessing, laplacianSolution);
192 BCFunctionBase one (oneFunction);
196 Real Q_hat_inflow = 0.0;
201 BCHandler bcH_laplacian_inflow;
202 bcH_laplacian_inflow.addBC(
"Inflow", 3, Essential, Full, one, 1 );
203 bcH_laplacian_inflow.bcUpdate ( *ns.uFESpace_scalar()->mesh(), ns.uFESpace_scalar()->feBd(), ns.uFESpace_scalar()->dof() );
205 ns.preprocessBoundary ( -ns.normal(3)[0], -ns.normal(3)[1], -ns.normal(3)[2], bcH_laplacian_inflow, Q_hat_inflow, laplacianSolution, 3,
206 Phi_h_inflow, V_hat_x_inflow, V_hat_y_inflow, V_hat_z_inflow );
209 std::cout <<
"\tValue of inflow, Q_hat = " << Q_hat_inflow << std::endl;
212 Real Q_hat_flag4 = 0.0;
217 BCHandler bcH_laplacian_flag4;
218 bcH_laplacian_flag4.addBC(
"Outflow4", 4, Essential, Full, one, 1 );
219 bcH_laplacian_flag4.bcUpdate ( *ns.uFESpace_scalar()->mesh(), ns.uFESpace_scalar()->feBd(), ns.uFESpace_scalar()->dof() );
221 ns.preprocessBoundary ( ns.normal(4)[0], ns.normal(4)[1], ns.normal(4)[2], bcH_laplacian_flag4, Q_hat_flag4, laplacianSolution, 4,
222 Phi_h_outflow4, V_hat_x_flag4, V_hat_y_flag4, V_hat_z_flag4 );
225 std::cout <<
"\tValue of outflow 4, Q_hat = " << Q_hat_flag4 << std::endl;
228 Real Q_hat_flag5 = 0.0;
233 BCHandler bcH_laplacian_flag5;
234 bcH_laplacian_flag5.addBC(
"Outflow5", 5, Essential, Full, one, 1 );
235 bcH_laplacian_flag5.bcUpdate ( *ns.uFESpace_scalar()->mesh(), ns.uFESpace_scalar()->feBd(), ns.uFESpace_scalar()->dof() );
237 ns.preprocessBoundary ( ns.normal(5)[0], ns.normal(5)[1], ns.normal(5)[2], bcH_laplacian_flag5, Q_hat_flag5, laplacianSolution, 5,
238 Phi_h_outflow5, V_hat_x_flag5, V_hat_y_flag5, V_hat_z_flag5 );
241 std::cout <<
"\tValue of outflow 5, Q_hat = " << Q_hat_flag5 << std::endl;
244 Real Q_hat_flag6 = 0.0;
249 BCHandler bcH_laplacian_flag6;
250 bcH_laplacian_flag6.addBC(
"Outflow6", 6, Essential, Full, one, 1 );
251 bcH_laplacian_flag6.bcUpdate ( *ns.uFESpace_scalar()->mesh(), ns.uFESpace_scalar()->feBd(), ns.uFESpace_scalar()->dof() );
253 ns.preprocessBoundary ( ns.normal(6)[0], ns.normal(6)[1], ns.normal(6)[2], bcH_laplacian_flag6, Q_hat_flag6, laplacianSolution, 6,
254 Phi_h_outflow6, V_hat_x_flag6, V_hat_y_flag6, V_hat_z_flag6 );
257 std::cout <<
"\tValue of outflow 6, Q_hat = " << Q_hat_flag6 << std::endl;
260 Real Q_hat_flag7 = 0.0;
265 BCHandler bcH_laplacian_flag7;
266 bcH_laplacian_flag7.addBC(
"Outflow7", 7, Essential, Full, one, 1 );
267 bcH_laplacian_flag7.bcUpdate ( *ns.uFESpace_scalar()->mesh(), ns.uFESpace_scalar()->feBd(), ns.uFESpace_scalar()->dof() );
269 ns.preprocessBoundary ( ns.normal(7)[0], ns.normal(7)[1], ns.normal(7)[2], bcH_laplacian_flag7, Q_hat_flag7, laplacianSolution, 7,
270 Phi_h_outflow7, V_hat_x_flag7, V_hat_y_flag7, V_hat_z_flag7 );
273 std::cout <<
"\tValue of outflow 7, Q_hat = " << Q_hat_flag7 << std::endl;
276 Real Q_hat_flag8 = 0.0;
281 BCHandler bcH_laplacian_flag8;
282 bcH_laplacian_flag8.addBC(
"Outflow8", 8, Essential, Full, one, 1 );
283 bcH_laplacian_flag8.bcUpdate ( *ns.uFESpace_scalar()->mesh(), ns.uFESpace_scalar()->feBd(), ns.uFESpace_scalar()->dof() );
285 ns.preprocessBoundary ( ns.normal(8)[0], ns.normal(8)[1], ns.normal(8)[2], bcH_laplacian_flag8, Q_hat_flag8, laplacianSolution, 8,
286 Phi_h_outflow8, V_hat_x_flag8, V_hat_y_flag8, V_hat_z_flag8);
289 std::cout <<
"\tValue of outflow 8, Q_hat = " << Q_hat_flag8 << std::endl;
292 Real Q_hat_flag9 = 0.0;
297 BCHandler bcH_laplacian_flag9;
298 bcH_laplacian_flag9.addBC(
"Outflow9", 9, Essential, Full, one, 1 );
299 bcH_laplacian_flag9.bcUpdate ( *ns.uFESpace_scalar()->mesh(), ns.uFESpace_scalar()->feBd(), ns.uFESpace_scalar()->dof() );
301 ns.preprocessBoundary ( ns.normal(9)[0], ns.normal(9)[1], ns.normal(9)[2], bcH_laplacian_flag9, Q_hat_flag9, laplacianSolution, 9,
302 Phi_h_outflow9, V_hat_x_flag9, V_hat_y_flag9, V_hat_z_flag9);
309 velAndPressure_flowrates.reset (
new vector_Type ( ns.uFESpace()->map(), Unique ) );
313 velAndPressure_inflow_reference.reset (
new vector_Type (ns.uFESpace()->map(), Unique ) );
314 velAndPressure_inflow_reference->zero();
315 velAndPressure_inflow_reference->subset(*V_hat_x_inflow,ns.uFESpace_scalar()->map(), 0, 0);
316 velAndPressure_inflow_reference->subset(*V_hat_y_inflow,ns.uFESpace_scalar()->map(), 0, ns.uFESpace()->map().mapSize()/3 );
317 velAndPressure_inflow_reference->subset(*V_hat_z_inflow,ns.uFESpace_scalar()->map(), 0, 2*ns.uFESpace()->map().mapSize()/3 );
321 velAndPressure_outflow4_reference.reset (
new vector_Type (ns.uFESpace()->map(), Unique ) );
322 velAndPressure_outflow4_reference->zero();
323 velAndPressure_outflow4_reference->subset(*V_hat_x_flag4,ns.uFESpace_scalar()->map(), 0, 0);
324 velAndPressure_outflow4_reference->subset(*V_hat_y_flag4,ns.uFESpace_scalar()->map(), 0, ns.uFESpace()->map().mapSize()/3 );
325 velAndPressure_outflow4_reference->subset(*V_hat_z_flag4,ns.uFESpace_scalar()->map(), 0, 2*ns.uFESpace()->map().mapSize()/3 );
329 velAndPressure_outflow5_reference.reset (
new vector_Type (ns.uFESpace()->map(), Unique ) );
330 velAndPressure_outflow5_reference->zero();
331 velAndPressure_outflow5_reference->subset(*V_hat_x_flag5,ns.uFESpace_scalar()->map(), 0, 0);
332 velAndPressure_outflow5_reference->subset(*V_hat_y_flag5,ns.uFESpace_scalar()->map(), 0, ns.uFESpace()->map().mapSize()/3 );
333 velAndPressure_outflow5_reference->subset(*V_hat_z_flag5,ns.uFESpace_scalar()->map(), 0, 2*ns.uFESpace()->map().mapSize()/3 );
337 velAndPressure_outflow6_reference.reset (
new vector_Type (ns.uFESpace()->map(), Unique ) );
338 velAndPressure_outflow6_reference->zero();
339 velAndPressure_outflow6_reference->subset(*V_hat_x_flag6,ns.uFESpace_scalar()->map(), 0, 0);
340 velAndPressure_outflow6_reference->subset(*V_hat_y_flag6,ns.uFESpace_scalar()->map(), 0, ns.uFESpace()->map().mapSize()/3 );
341 velAndPressure_outflow6_reference->subset(*V_hat_z_flag6,ns.uFESpace_scalar()->map(), 0, 2*ns.uFESpace()->map().mapSize()/3 );
345 velAndPressure_outflow7_reference.reset (
new vector_Type (ns.uFESpace()->map(), Unique ) );
346 velAndPressure_outflow7_reference->zero();
347 velAndPressure_outflow7_reference->subset(*V_hat_x_flag7,ns.uFESpace_scalar()->map(), 0, 0);
348 velAndPressure_outflow7_reference->subset(*V_hat_y_flag7,ns.uFESpace_scalar()->map(), 0, ns.uFESpace()->map().mapSize()/3 );
349 velAndPressure_outflow7_reference->subset(*V_hat_z_flag7,ns.uFESpace_scalar()->map(), 0, 2*ns.uFESpace()->map().mapSize()/3 );
353 velAndPressure_outflow8_reference.reset (
new vector_Type (ns.uFESpace()->map(), Unique ) );
354 velAndPressure_outflow8_reference->zero();
355 velAndPressure_outflow8_reference->subset(*V_hat_x_flag8,ns.uFESpace_scalar()->map(), 0, 0);
356 velAndPressure_outflow8_reference->subset(*V_hat_y_flag8,ns.uFESpace_scalar()->map(), 0, ns.uFESpace()->map().mapSize()/3 );
357 velAndPressure_outflow8_reference->subset(*V_hat_z_flag8,ns.uFESpace_scalar()->map(), 0, 2*ns.uFESpace()->map().mapSize()/3 );
361 velAndPressure_outflow9_reference.reset (
new vector_Type (ns.uFESpace()->map(), Unique ) );
362 velAndPressure_outflow9_reference->zero();
363 velAndPressure_outflow9_reference->subset(*V_hat_x_flag9,ns.uFESpace_scalar()->map(), 0, 0);
364 velAndPressure_outflow9_reference->subset(*V_hat_y_flag9,ns.uFESpace_scalar()->map(), 0, ns.uFESpace()->map().mapSize()/3 );
365 velAndPressure_outflow9_reference->subset(*V_hat_z_flag9,ns.uFESpace_scalar()->map(), 0, 2*ns.uFESpace()->map().mapSize()/3 );
368 velAndPressure_inflow.reset (
new vector_Type ( ns.uFESpace()->map(), Unique ) );
371 velAndPressure_outflow4.reset (
new vector_Type ( ns.uFESpace()->map(), Unique ) );
374 velAndPressure_outflow5.reset (
new vector_Type ( ns.uFESpace()->map(), Unique ) );
377 velAndPressure_outflow6.reset (
new vector_Type ( ns.uFESpace()->map(), Unique ) );
380 velAndPressure_outflow7.reset (
new vector_Type ( ns.uFESpace()->map(), Unique ) );
383 velAndPressure_outflow8.reset (
new vector_Type ( ns.uFESpace()->map(), Unique ) );
386 velAndPressure_outflow9.reset (
new vector_Type ( ns.uFESpace()->map(), Unique ) );
390 Real i_HeartBeat = 0.0;
392 int time_step_count = 0;
394 for ( ; time <= tFinal + dt / 2.; time += dt)
396 time_step_count += 1;
411 Real T_heartbeat = 0.8;
413 if ( time < T_heartbeat )
417 else if ( time >= T_heartbeat && time < 2*T_heartbeat )
421 else if ( time >= 2*T_heartbeat && time < 3*T_heartbeat )
425 else if ( time >= 3*T_heartbeat && time < 4*T_heartbeat )
430 if ( (time >= 0.05 && time <= 0.42) || (time >= (0.05+T_heartbeat) && time <= (0.42+T_heartbeat) ) || (time >= (0.05+2*T_heartbeat) && time <= (0.42+2*T_heartbeat) ) || (time >= (0.05+3*T_heartbeat) && time <= (0.42+3*T_heartbeat) ) )
432 Q = -2.314569820334801e+09*std::pow(time-i_HeartBeat*T_heartbeat,9) +
433 4.952537061974133e+09*std::pow(time-i_HeartBeat*T_heartbeat,8) -
434 4.532060231242586e+09*std::pow(time-i_HeartBeat*T_heartbeat,7) +
435 2.325743716202249e+09*std::pow(time-i_HeartBeat*T_heartbeat,6) -
436 7.387577876374097e+08*std::pow(time-i_HeartBeat*T_heartbeat,5) +
437 1.514516710083440e+08*std::pow(time-i_HeartBeat*T_heartbeat,4) -
438 2.018053394181958e+07*std::pow(time-i_HeartBeat*T_heartbeat,3) +
439 1.667954643625200e+06*std::pow(time-i_HeartBeat*T_heartbeat,2) -
440 7.160662399848596e+04*(time-i_HeartBeat*T_heartbeat) +
441 1.184312187078482e+03;
458 Real pressureValue = 1500.0/2.51*(Q_inflow - Q_flag4 - Q_flag5 - Q_flag6 - Q_flag7 - Q_flag8 - Q_flag9);
462 std::cout <<
"\nImposing outflow pressure of " << pressureValue <<
" dyne/cm^2\n\n";
465 Real alpha_flowrate_inflow = Q_inflow/Q_hat_inflow;
466 Real alpha_flowrate_flag4 = Q_flag4/Q_hat_flag4;
467 Real alpha_flowrate_flag5 = Q_flag5/Q_hat_flag5;
468 Real alpha_flowrate_flag6 = Q_flag6/Q_hat_flag6;
469 Real alpha_flowrate_flag7 = Q_flag7/Q_hat_flag7;
470 Real alpha_flowrate_flag8 = Q_flag8/Q_hat_flag8;
471 Real alpha_flowrate_flag9 = Q_flag9/Q_hat_flag9;
475 std::cout <<
"Q_inflow: " << Q_inflow << std::endl << std::endl;
476 std::cout <<
"Q_flag4: " << Q_flag4 << std::endl << std::endl;
477 std::cout <<
"Q_flag5: " << Q_flag5 << std::endl << std::endl;
478 std::cout <<
"Q_flag6: " << Q_flag6 << std::endl << std::endl;
479 std::cout <<
"Q_flag7: " << Q_flag7 << std::endl << std::endl;
480 std::cout <<
"Q_flag8: " << Q_flag8 << std::endl << std::endl;
481 std::cout <<
"Q_flag9: " << Q_flag9 << std::endl << std::endl;
482 std::cout <<
"Q_outflow: " << Q_inflow - Q_flag4 - Q_flag5 - Q_flag6 - Q_flag7 - Q_flag8 - Q_flag9 << std::endl << std::endl;
487 scaleInflowVector(velAndPressure_outflow4_reference
, velAndPressure_outflow4
, alpha_flowrate_flag4
);
488 scaleInflowVector(velAndPressure_outflow5_reference
, velAndPressure_outflow5
, alpha_flowrate_flag5
);
489 scaleInflowVector(velAndPressure_outflow6_reference
, velAndPressure_outflow6
, alpha_flowrate_flag6
);
490 scaleInflowVector(velAndPressure_outflow7_reference
, velAndPressure_outflow7
, alpha_flowrate_flag7
);
491 scaleInflowVector(velAndPressure_outflow8_reference
, velAndPressure_outflow8
, alpha_flowrate_flag8
);
492 scaleInflowVector(velAndPressure_outflow9_reference
, velAndPressure_outflow9
, alpha_flowrate_flag9
);
524 velAndPressure_flowrates->zero();
525 *velAndPressure_flowrates += *velAndPressure_inflow;
526 *velAndPressure_flowrates += *velAndPressure_outflow4;
527 *velAndPressure_flowrates += *velAndPressure_outflow5;
528 *velAndPressure_flowrates += *velAndPressure_outflow6;
529 *velAndPressure_flowrates += *velAndPressure_outflow7;
530 *velAndPressure_flowrates += *velAndPressure_outflow8;
531 *velAndPressure_flowrates += *velAndPressure_outflow9;
534 std::cout <<
"\nWe are at time " << time <<
" s\n\n";
540 rhs_velocity->zero();
541 timeVelocity.extrapolate (orderBDF, *u_star);
542 timeVelocity.rhsContribution (*rhs_velocity);
544 if ( useStabilization && stabilizationType.compare(
"VMSLES_SEMI_IMPLICIT")==0 )
546 timePressure.extrapolate (orderBDF,*p_star);
551 ns.iterate( bc, time, velAndPressure_flowrates );
559 std::cout <<
"\nTimestep solved in " << iterChrono.diff() <<
" s\n";
569 if ( time_step_count == (counterSaveEvery-1) )
571 exporter->postProcess ( time );
573 else if ( time_step_count == counterSaveEvery )
575 exporter->postProcess ( time );
576 counterSaveEvery += saveEvery;
579 else if ( orderBDF == 2 )
589 if ( time_step_count == counterSaveEvery )
591 if ( time >= saveAfter )
593 exporter->postProcess ( time );
595 counterSaveEvery += saveEvery;
599 timeVelocity.shift(*velocity);
601 if ( useStabilization && stabilizationType.compare(
"VMSLES_SEMI_IMPLICIT")==0 )
602 timePressure.shift(*pressure);
606 exporter->closeFile();
613 std::cout <<
"\nMPI Finalization" << std::endl;
617 return ( EXIT_SUCCESS );
622 const Real& coefficient )
625 *vecScaled += *vecNotScaled;
626 *vecScaled *= coefficient;
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)
Real oneFunction(const Real &, const Real &, const Real &, const Real &, const ID &)
std::shared_ptr< vector_Type > vectorPtr_Type
void setupPostProc()
Additional setup for postprocessing on boundaries.
RegionMesh< LinearTetra > mesh_Type
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)
void scaleInflowVector(const vectorPtr_Type &vecNotScaled, vectorPtr_Type &vecScaled, const Real &coefficient)
uint32_type UInt
generic unsigned integer (used mainly for addressing)