37 #include <lifev/multiscale/models/MultiscaleModelFluid3D.hpp> 48 multiscaleModel_Type (),
49 MultiscaleInterface (),
74 #ifdef HAVE_LIFEV_DEBUG 75 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::MultiscaleModelFluid3D() \n";
88 #ifdef HAVE_LIFEV_DEBUG 89 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::setupData( fileName ) \n";
92 multiscaleModel_Type::setupData ( fileName );
93 M_fileName = fileName;
95 GetPot dataFile ( fileName );
98 M_data->setup ( dataFile );
99 if ( M_globalData.get() )
105 M_meshData->setup ( dataFile,
"fluid/space_discretization" );
108 M_subiterationsMaximumNumber = dataFile (
"fluid/miscellaneous/SubITMax", 0 );
109 M_tolerance = dataFile (
"fluid/miscellaneous/Tolerance", 1.e-6 );
111 M_generalizedAitken.setDefaultOmega ( dataFile (
"fluid/miscellaneous/Omega", 1.e-3 ) );
112 M_generalizedAitken.setOmegaMin ( dataFile (
"fluid/miscellaneous/range", M_generalizedAitken.defaultOmegaFluid() / 1024, 0 ) );
113 M_generalizedAitken.setOmegaMax ( dataFile (
"fluid/miscellaneous/range", M_generalizedAitken.defaultOmegaFluid() * 1024, 1 ) );
114 M_generalizedAitken.useDefaultOmega ( dataFile (
"fluid/miscellaneous/fixedOmega",
false ) );
115 M_generalizedAitken.setMinimizationType ( dataFile (
"fluid/miscellaneous/inverseOmega",
true ) );
118 M_bc->fillHandler ( fileName,
"fluid" );
128 #ifdef HAVE_LIFEV_DEBUG 129 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::setupModel() \n";
139 M_lmDOF = M_bc->handler()->numberOfBCWithType ( Flux );
140 setupBCOffset ( M_bc->handler() );
143 M_fluid.reset (
new fluid_Type ( M_data, *M_uFESpace, *M_pFESpace, M_comm, M_lmDOF ) );
144 M_bc->setPhysicalSolver ( M_fluid );
146 GetPot dataFile ( M_fileName );
147 M_fluid->setUp ( dataFile );
150 M_map.reset (
new MapEpetra ( M_fluid->getMap() ) );
153 M_bdf.reset (
new bdf_Type);
154 M_bdf->setup (M_data->dataTimeAdvance()->orderBDF() );
157 M_beta.reset (
new fluidVector_Type ( M_map ) );
158 M_rhs.reset (
new fluidVector_Type ( M_map ) );
161 M_exporter->setMeshProcId ( M_mesh->meshPartition(), M_comm->MyPID() );
163 M_solution.reset (
new fluidVector_Type ( *M_fluid->solution(), M_exporter->mapType() ) );
164 if ( M_exporter->mapType() == Unique )
166 M_solution->setCombineMode ( Zero );
169 M_exporter->addVariable ( IOData_Type::VectorField,
"Velocity (fluid)", M_uFESpace, M_solution,
static_cast<UInt> ( 0 ) );
170 M_exporter->addVariable ( IOData_Type::ScalarField,
"Pressure (fluid)", M_pFESpace, M_solution,
static_cast<UInt> ( 3 * M_uFESpace->dof().numTotalDof() ) );
183 #ifdef HAVE_LIFEV_DEBUG 184 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::buildModel() \n";
192 M_fluid->buildSystem();
195 M_bdf->bdfVelocity().setInitialCondition ( *M_fluid->solution() );
198 if ( M_data->isStokes() )
201 *M_beta = *M_fluid->solution();
206 M_alpha = M_bdf->bdfVelocity().coefficientFirstDerivative ( 0 ) / M_data->dataTime()->timeStep();
207 M_bdf->bdfVelocity().extrapolation (*M_beta);
209 M_bdf->bdfVelocity().updateRHSContribution ( M_data->dataTime()->timeStep() );
210 *M_rhs = M_fluid->matrixMass() * M_bdf->bdfVelocity().rhsContributionFirstDerivative();
214 M_fluid->updateSystem ( M_alpha, *M_beta, *M_rhs );
217 M_bc->updatePhysicalSolverVariables();
224 #ifdef HAVE_LIFEV_DEBUG 225 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::updateModel() \n";
229 M_bdf->bdfVelocity().shiftRight ( *M_fluid->solution() );
232 M_alpha = M_bdf->bdfVelocity().coefficientFirstDerivative ( 0 ) / M_data->dataTime()->timeStep();
233 M_bdf->bdfVelocity().extrapolation (*M_beta);
235 M_bdf->bdfVelocity().updateRHSContribution ( M_data->dataTime()->timeStep() );
236 *M_rhs = M_fluid->matrixMass() * M_bdf->bdfVelocity().rhsContributionFirstDerivative();
239 M_fluid->updateSystem ( M_alpha, *M_beta, *M_rhs );
242 M_bc->updatePhysicalSolverVariables();
245 M_fluid->resetPreconditioner (
true );
255 #ifdef HAVE_LIFEV_DEBUG 256 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::solveModel() \n";
260 displayModelStatus (
"Solve" );
261 M_fluid->iterate ( *M_bc->handler() );
266 Real residual = ( *M_beta - *M_fluid->solution() ).norm2();
268 if ( M_comm->MyPID() == 0 )
270 std::cout <<
" F- Residual: " << residual << std::endl;
273 M_generalizedAitken.restart();
282 *M_beta += M_generalizedAitken.computeDeltaLambdaScalar ( *M_beta, *M_beta - *M_fluid->solution() );
285 M_fluid->updateSystem ( M_alpha, *M_beta, *M_rhs );
286 M_bc->updatePhysicalSolverVariables();
290 M_fluid->iterate ( *M_bc->handler() );
293 residual = ( *M_beta - *M_fluid->solution() ).norm2();
296 if ( M_comm->MyPID() == 0 )
298 std::cout <<
" F- Sub-iteration n.: " << subIT << std::endl;
299 std::cout <<
" F- Residual: " << residual << std::endl;
309 #ifdef HAVE_LIFEV_DEBUG 310 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::updateSolution() \n";
313 *M_solution = *M_fluid->solution();
320 #ifdef HAVE_LIFEV_DEBUG 321 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::saveSolution() \n";
325 M_exporter->postProcess ( M_data->dataTime()->time() );
328 if ( M_data->dataTime()->isLastTimeStep() )
330 M_exporter->closeFile();
339 if ( M_comm->MyPID() == 0 )
341 multiscaleModel_Type::showMe();
343 std::cout <<
"Velocity FE order = " << M_data->uOrder() << std::endl
344 <<
"Pressure FE order = " << M_data->pOrder() << std::endl << std::endl;
346 std::cout <<
"Velocity DOF = " << 3 * M_uFESpace->dof().numTotalDof() << std::endl
347 <<
"Pressure DOF = " << M_pFESpace->dof().numTotalDof() << std::endl
348 <<
"lmDOF = " << M_lmDOF << std::endl << std::endl;
350 std::cout <<
"Fluid mesh maxH = " << MeshUtility::MeshStatistics::computeSize ( *M_mesh->meshPartition() ).maxH << std::endl
351 <<
"Fluid mesh meanH = " << MeshUtility::MeshStatistics::computeSize ( *M_mesh->meshPartition() ).meanH << std::endl << std::endl;
353 std::cout <<
"NS SubITMax = " << M_subiterationsMaximumNumber << std::endl
354 <<
"NS Tolerance = " << M_tolerance << std::endl << std::endl << std::endl << std::endl;
361 return M_solution->norm2();
371 base.setFunction ( function );
373 M_bc->handler()->addBC (
"CouplingFlowRate_Model_" + number2string ( M_ID ) +
"_BoundaryID_" + number2string ( boundaryID ), boundaryFlag ( boundaryID ), Flux, Full, base, 3 );
380 base.setFunction ( function );
382 M_bc->handler()->addBC (
"CouplingStress_Model_" + number2string ( M_ID ) +
"_BoundaryID_" + number2string ( boundaryID ), boundaryFlag ( boundaryID ), Natural, Normal, base );
390 return M_fluid->linearFlux ( boundaryFlag ( boundaryID ) );
398 return M_fluid->linearMeanNormalStress ( boundaryFlag ( boundaryID ), *M_linearBC );
406 return M_fluid->linearMeanTotalNormalStress ( boundaryFlag ( boundaryID ), *M_linearBC );
417 M_fluid->initialize ( *M_solution );
427 #ifdef HAVE_LIFEV_DEBUG 428 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::setupGlobalData( fileName ) \n";
431 GetPot dataFile ( fileName );
434 M_data->setTimeData ( M_globalData->dataTime() );
437 if ( !dataFile.checkVariable (
"fluid/physics/density" ) )
439 M_data->setDensity ( M_globalData->fluidDensity() );
441 if ( !dataFile.checkVariable (
"fluid/physics/viscosity" ) )
443 M_data->setViscosity ( M_globalData->fluidViscosity() );
451 #ifdef HAVE_LIFEV_DEBUG 452 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::initializeSolution() \n";
455 if ( multiscaleProblemStep > 0 )
457 M_importer->setMeshProcId ( M_mesh->meshPartition(), M_comm->MyPID() );
459 M_importer->addVariable ( IOData_Type::VectorField,
"Velocity (fluid)", M_uFESpace, M_solution,
static_cast <UInt> ( 0 ) );
460 M_importer->addVariable ( IOData_Type::ScalarField,
"Pressure (fluid)", M_pFESpace, M_solution,
static_cast <UInt> ( 3 * M_uFESpace->dof().numTotalDof() ) );
463 M_exporter->setTimeIndex ( M_importer->importFromTime ( M_data->dataTime()->initialTime() ) + 1 );
466 M_importer->closeFile();
474 M_fluid->initialize ( *M_solution );
480 GetPot dataFile ( fileName );
483 const std::string exporterType = dataFile (
"exporter/type",
"ensight" );
486 if ( !exporterType.compare (
"hdf5" ) )
488 M_exporter.reset (
new hdf5IOFile_Type() );
492 M_exporter.reset (
new ensightIOFile_Type() );
494 M_exporter->setDataFromGetPot ( dataFile );
495 M_exporter->setPrefix ( multiscaleProblemPrefix +
"_Model_" + number2string ( M_ID ) +
"_" + number2string ( multiscaleProblemStep ) );
496 M_exporter->setPostDir ( multiscaleProblemFolder );
499 const std::string importerType = dataFile (
"importer/type",
"ensight" );
502 if ( !importerType.compare (
"hdf5" ) )
504 M_importer.reset (
new hdf5IOFile_Type() );
508 M_importer.reset (
new ensightIOFile_Type() );
510 M_importer->setDataFromGetPot ( dataFile );
511 M_importer->setPrefix ( multiscaleProblemPrefix +
"_Model_" + number2string ( M_ID ) +
"_" + number2string ( multiscaleProblemStep - 1 ) );
512 M_importer->setPostDir ( multiscaleProblemFolder );
519 std::shared_ptr< mesh_Type > fluidMesh (
new mesh_Type ( M_comm ) );
520 readMesh ( *fluidMesh, *M_meshData );
523 fluidMesh->meshTransformer().transformMesh ( M_geometryScale, M_geometryRotate, M_geometryTranslate );
526 M_mesh.reset (
new MeshPartitioner_Type ( fluidMesh, M_comm ) );
533 #ifdef HAVE_LIFEV_DEBUG 534 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::setupFEspace() \n";
542 if ( M_data->uOrder().compare (
"P2" ) == 0 )
544 u_refFE = &feTetraP2;
548 else if ( M_data->uOrder().compare (
"P1" ) == 0 )
550 u_refFE = &feTetraP1;
554 else if ( M_data->uOrder().compare (
"P1Bubble" ) == 0 )
556 u_refFE = &feTetraP1bubble;
562 if ( M_comm->MyPID() == 0 )
564 std::cout << M_data->uOrder() <<
" Velocity FE not implemented yet." << std::endl;
566 exit ( EXIT_FAILURE );
574 if ( M_data->pOrder().compare (
"P2" ) == 0 )
576 p_refFE = &feTetraP2;
580 else if ( M_data->pOrder().compare (
"P1" ) == 0 )
582 p_refFE = &feTetraP1;
588 if ( M_comm->MyPID() == 0 )
590 std::cout << M_data->pOrder() <<
" pressure FE not implemented yet." << std::endl;
592 exit ( EXIT_FAILURE );
595 M_uFESpace.reset (
new FESpace_Type ( M_mesh->meshPartition(), *u_refFE, *u_qR, *u_bdQr, 3, M_comm ) );
596 M_pFESpace.reset (
new FESpace_Type ( M_mesh->meshPartition(), *p_refFE, *p_qR, *p_bdQr, 1, M_comm ) );
603 #ifdef HAVE_LIFEV_DEBUG 604 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::setupDOF \n";
607 M_lmDOF = M_bc->handler()->numberOfBCWithType ( Flux );
614 #ifdef HAVE_LIFEV_DEBUG 615 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::setupBCOffset( BC ) \n";
618 UInt offset = M_uFESpace->map().map ( Unique )->NumGlobalElements() + M_pFESpace->map().map ( Unique )->NumGlobalElements();
620 std::vector< bcName_Type > fluxVector = bc->findAllBCWithType ( Flux );
623 bc->setOffset ( fluxVector[i], offset + i );
631 #ifdef HAVE_LIFEV_DEBUG 632 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::setupLinearModel( ) \n";
636 M_linearBC.reset (
new bc_Type ( *M_bc->handler() ) );
639 BCFunctionBase bcBaseDeltaZero;
640 bcBaseDeltaZero.setFunction ( std::bind ( &MultiscaleModelFluid3D::bcFunctionDeltaZero,
this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 ) );
642 for ( bc_Type::bcBaseIterator_Type i = M_linearBC->begin() ; i != M_linearBC->end() ; ++i )
644 i->setBCFunction ( bcBaseDeltaZero );
652 #ifdef HAVE_LIFEV_DEBUG 653 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::updateLinearModel() \n";
661 M_fluid->updateLinearSystem ( M_fluid->matrixNoBC(), M_alpha, *M_beta, *M_fluid->solution(),
662 vectorZero, vectorZero, vectorZero, vectorZero );
672 #ifdef HAVE_LIFEV_DEBUG 673 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::solveLinearModel() \n";
676 if ( !solveLinearSystem )
689 displayModelStatus (
"Solve linear" );
690 M_fluid->solveLinearSystem ( *M_linearBC );
695 solveLinearSystem =
false;
702 #ifdef HAVE_LIFEV_DEBUG 703 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::imposePerturbation() \n";
706 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplings.begin(); i < M_couplings.end(); ++i )
707 if ( ( *i )->isPerturbed() )
709 BCFunctionBase bcBaseDeltaOne;
710 bcBaseDeltaOne.setFunction ( std::bind ( &MultiscaleModelFluid3D::bcFunctionDeltaOne,
this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 ) );
712 M_linearBC->findBCWithFlag ( boundaryFlag ( ( *i )->boundaryID ( ( *i )->modelGlobalToLocalID ( M_ID ) ) ) ).setBCFunction ( bcBaseDeltaOne );
722 #ifdef HAVE_LIFEV_DEBUG 723 debugStream ( 8120 ) <<
"MultiscaleModelFluid3D::resetPerturbation() \n";
726 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplings.begin(); i < M_couplings.end(); ++i )
727 if ( ( *i )->isPerturbed() )
729 BCFunctionBase bcBaseDeltaZero;
730 bcBaseDeltaZero.setFunction ( std::bind ( &MultiscaleModelFluid3D::bcFunctionDeltaZero,
this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 ) );
732 M_linearBC->findBCWithFlag ( boundaryFlag ( ( *i )->boundaryID ( ( *i )->modelGlobalToLocalID ( M_ID ) ) ) ).setBCFunction ( bcBaseDeltaZero );
void solveModel()
Solve the model.
Real boundaryDeltaMeanTotalNormalStress(const multiscaleID_Type &boundaryID, bool &solveLinearSystem)
Get the variation of the integral of the mean total normal stress (on a specific boundary interface) ...
const QuadratureRule quadRuleTetra64pt(pt_tetra_64pt, 6, "Quadrature rule 64 points on a tetraedra", TETRA, 64, 7)
void setupDOF()
Setup the DOF of the model.
void solveLinearModel(bool &solveLinearSystem)
Solve the linear problem.
const QuadratureRule quadRuleTetra15pt(pt_tetra_15pt, 5, "Quadrature rule 15 points on a tetraedra", TETRA, 15, 5)
std::shared_ptr< bc_Type > bcPtr_Type
UInt M_subiterationsMaximumNumber
const QuadratureRule quadRuleTetra4pt(pt_tetra_4pt, 2, "Quadrature rule 4 points on a tetraedra", TETRA, 4, 2)
Real boundaryDeltaMeanNormalStress(const multiscaleID_Type &boundaryID, bool &solveLinearSystem)
Get the variation of the integral of the mean normal stress (on a specific boundary interface) using ...
void buildModel()
Build the initial model.
void setupBCOffset(const bcPtr_Type &BC)
Setup the offset for fluxes boundary conditions.
Real checkSolution() const
Return a specific scalar quantity to be used for a comparison with a reference value.
void initializeSolution()
Initialize the solution.
Real boundaryDeltaFlowRate(const multiscaleID_Type &boundaryID, bool &solveLinearSystem)
Get the variation of the flow rate (on a specific boundary interface) using the linear model...
FESpacePtr_Type M_pFESpace
void updateSolution()
Update the solution.
void setupGlobalData(const std::string &fileName)
Setup the global data of the model.
fluidVectorPtr_Type M_beta
MultiscaleModelFluid3D()
Constructor.
fluid_Type::vector_Type fluidVector_Type
void setupFEspace()
Setup the FE space for pressure and velocity.
void setSolution(const fluidVectorPtr_Type &solution)
Set the solution vector.
fluidVectorPtr_Type M_solution
void saveSolution()
Save the solution.
void imposePerturbation()
Impose the coupling perturbation on the correct BC inside the BCHandler.
void setupModel()
Setup the model.
void imposeBoundaryMeanNormalStress(const multiscaleID_Type &boundaryID, const function_Type &function)
Impose the integral of the mean normal stress on a specific boundary interface of the model...
void setupMesh()
Setup the mesh for the fluid problem.
double Real
Generic real data.
const QuadratureRule quadRuleTria3pt(pt_tria_3pt, 2, "Quadrature rule 3 points on a triangle", TRIANGLE, 3, 2)
The class for a reference Lagrangian finite element.
IOFilePtr_Type M_exporter
void updateModel()
Update the model.
FESpacePtr_Type M_uFESpace
fluidVectorPtr_Type M_rhs
void resetPerturbation()
Reset all the coupling perturbations imposed on the BCHandler.
void setupExporterImporter(const std::string &fileName)
Setup the exporter and the importer.
QuadratureRule - The basis class for storing and accessing quadrature rules.
void updateLinearModel()
Update the linear system matrix and vectors.
ExporterHDF5< mesh_Type > hdf5IOFile_Type
void setupLinearModel()
Setup the linear model.
IOFilePtr_Type M_importer
uint32_type UInt
generic unsigned integer (used mainly for addressing)
void showMe()
Display some information about the model.
void imposeBoundaryFlowRate(const multiscaleID_Type &boundaryID, const function_Type &function)
Impose the flow rate on a specific interface of the model.
std::shared_ptr< fluidVector_Type > fluidVectorPtr_Type
void setupData(const std::string &fileName)
Setup the data of the model.