38 #include <lifev/multiscale/models/MultiscaleModelWindkessel0D.hpp> 66 #ifdef HAVE_LIFEV_DEBUG 67 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::MultiscaleModelWindkessel0D() \n";
80 #ifdef HAVE_LIFEV_DEBUG 81 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::setupData( fileName ) \n";
84 multiscaleModel_Type::setupData ( fileName );
86 GetPot dataFile ( fileName );
89 Real resistanceScalingFactor = dataFile (
"ScalingFactors/Resistance", M_globalData->scalingFactorResistance() );
90 Real complianceScalingFactor = dataFile (
"ScalingFactors/Compliance", M_globalData->scalingFactorCompliance() );
92 M_resistance1 = dataFile (
"Coefficients/Resistance1" , 1.0 ) * resistanceScalingFactor;
93 M_resistance2 = dataFile (
"Coefficients/Resistance2" , 1.0 ) * resistanceScalingFactor;
94 M_capacitance = dataFile (
"Coefficients/Capacitance" , 1.0 ) * complianceScalingFactor;
96 if ( M_globalData.get() )
102 M_bc->createHandler();
112 #ifdef HAVE_LIFEV_DEBUG 113 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::setupModel() \n";
118 M_bc->setPhysicalSolver ( M_data );
121 if ( M_bc->handler()->bc ( 1 ).bcType() != Voltage )
123 std::cout <<
"!!! Error: the Windkessel model support only stress boundary conditions on the right at the present time !!!" << std::endl;
131 #ifdef HAVE_LIFEV_DEBUG 132 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::buildModel() \n";
142 #ifdef HAVE_LIFEV_DEBUG 143 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::updateModel() \n";
150 M_bc->updatePhysicalSolverVariables();
152 M_pressureRight = -M_bc->handler()->bc ( 1 ).evaluate ( M_globalData->dataTime()->time() );
159 #ifdef HAVE_LIFEV_DEBUG 160 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::solveModel() \n";
163 displayModelStatus (
"Solve" );
165 switch ( M_bc->handler()->bc ( 0 ).bcType() )
169 M_flowRateLeft = M_bc->handler()->bc ( 0 ).evaluate ( M_globalData->dataTime()->time() );
170 M_pressureLeft = solveForPressure();
176 M_pressureLeft = -M_bc->handler()->bc ( 0 ).evaluate ( M_globalData->dataTime()->time() );
177 M_flowRateLeft = solveForFlowRate();
183 std::cout <<
"Warning: bcType \"" << M_bc->handler()->bc ( 0 ).bcType() <<
"\"not available!" << std::endl;
193 #ifdef HAVE_LIFEV_DEBUG 194 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::updateSolution() \n";
203 #ifdef HAVE_LIFEV_DEBUG 204 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::saveSolution() \n";
207 M_outputFile <<
" " << M_globalData->dataTime()->time()
208 <<
" " << M_flowRateLeft
209 <<
" " << M_pressureLeft << std::endl;
211 if ( M_globalData->dataTime()->isLastTimeStep() )
213 M_outputFile.close();
220 if ( M_comm->MyPID() == 0 )
222 multiscaleModel_Type::showMe();
224 std::cout <<
"Resistance1 = " << M_resistance1 << std::endl
225 <<
"Resistance2 = " << M_resistance2 << std::endl
226 <<
"Capacitance = " << M_capacitance << std::endl << std::endl;
243 base.setFunction ( std::bind ( function, std::placeholders::_1, std::placeholders::_1, std::placeholders::_1, std::placeholders::_1, std::placeholders::_1 ) );
245 M_bc->handler()->setBC ( boundaryFlag ( boundaryID ), Current, base );
252 base.setFunction ( std::bind ( function, std::placeholders::_1, std::placeholders::_1, std::placeholders::_1, std::placeholders::_1, std::placeholders::_1 ) );
254 M_bc->handler()->setBC ( boundaryFlag ( boundaryID ), Voltage, base );
260 if ( boundaryFlag ( boundaryID ) == 1 )
273 if ( boundaryFlag ( boundaryID ) == 1 )
289 GetPot dataFile ( fileName );
292 M_data->setTimeData ( M_globalData->dataTime() );
294 if ( !dataFile.checkVariable (
"Coefficients/VenousPressure" ) )
296 M_pressureRight = M_globalData->fluidVenousPressure();
298 M_data->setVenousPressure ( M_pressureRight );
305 #ifdef HAVE_LIFEV_DEBUG 306 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::initializeSolution() \n";
311 std::string fileName = multiscaleProblemFolder + multiscaleProblemPrefix +
"_Model_" + number2string ( M_ID ) +
"_" + number2string ( multiscaleProblemStep - 1 ) +
".mfile";
313 std::ifstream inputFile;
314 inputFile.open ( fileName.c_str(), std::ios::in );
316 if ( inputFile.is_open() )
320 std::vector<std::string> stringsVector;
324 std::getline ( inputFile, line,
'\n' );
327 while ( std::getline ( inputFile, line,
'\n' ) )
330 boost::split ( stringsVector, line, boost::is_any_of (
" " ), boost::token_compress_on );
333 if ( std::abs ( string2number ( stringsVector[1] ) - M_globalData->dataTime()->initialTime() ) <= deltaT )
335 deltaT = std::abs ( string2number ( stringsVector[1] ) - M_globalData->dataTime()->initialTime() );
337 M_flowRateLeft = string2number ( stringsVector[2] );
338 M_pressureLeft = string2number ( stringsVector[3] );
347 std::cerr <<
" !!! Error: cannot open fileName: " << fileName.c_str() <<
" !!!" << std::endl;
353 M_pressureLeft = M_globalData->solidExternalPressure();
355 switch ( M_bc->handler()->bc ( 0 ).bcType() )
359 M_flowRateLeft = M_bc->handler()->bc ( 0 ).evaluate ( M_globalData->dataTime()->time() );
372 std::cout <<
"Warning: bcType \"" << M_bc->handler()->bc ( 0 ).bcType() <<
"\"not available!" << std::endl;
383 #ifdef HAVE_LIFEV_DEBUG 384 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::setupExporterImporter() \n";
387 std::string file = multiscaleProblemFolder + multiscaleProblemPrefix +
"_Model_" + number2string ( M_ID ) +
"_" + number2string ( multiscaleProblemStep ) +
".mfile";
388 M_outputFile.open ( file.c_str(), std::ios::trunc );
389 M_outputFile << std::scientific << std::setprecision ( 15 )
390 <<
"% MODEL: " << M_modelName << std::endl
391 <<
"% TIME FLOW RATE PRESSURE" << std::endl;
397 #ifdef HAVE_LIFEV_DEBUG 398 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::solveForFlowRate() \n";
407 Real dt = M_globalData->dataTime()->timeStep();
413 return - 1.0 / ( K1 * K1 )
422 #ifdef HAVE_LIFEV_DEBUG 423 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::solveForPressure() \n";
432 Real dt = M_globalData->dataTime()->timeStep();
438 return - 1.0 / ( K1 * K1 )
448 #ifdef HAVE_LIFEV_DEBUG 449 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::solveLinearModel() \n";
452 if ( !solveLinearSystem )
458 displayModelStatus (
"Solve linear" );
459 switch ( M_bc->handler()->bc ( 0 ).bcType() )
463 M_tangentFlowRateLeft = 1.;
464 M_tangentPressureLeft = tangentSolveForPressure();
470 M_tangentPressureLeft = 1.;
471 M_tangentFlowRateLeft = -tangentSolveForFlowRate();
477 std::cout <<
"Warning: bcType \"" << M_bc->handler()->bc ( 0 ).bcType() <<
"\"not available!" << std::endl;
483 solveLinearSystem =
false;
489 #ifdef HAVE_LIFEV_DEBUG 490 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::tangentSolveForFlowRate() \n";
499 Real dt = M_globalData->dataTime()->timeStep();
504 return - ( K2 + K3 / dt ) / K1
505 - 1.0 / ( K1 * K1 ) * ( std::exp ( -K1 * dt ) * ( K2 / dt - ( K1 * K3 ) / dt ) - K2 / dt );
512 #ifdef HAVE_LIFEV_DEBUG 513 debugStream ( 8150 ) <<
"MultiscaleModelWindkessel0D::tangentSolveForPressure() \n";
522 Real dt = M_globalData->dataTime()->timeStep();
527 return - ( K2 + K3 / dt ) / K1
528 - 1.0 / ( K1 * K1 ) * ( std::exp ( -K1 * dt ) * ( K2 / dt - ( K1 * K3 ) / dt ) - K2 / dt );
Real solveForFlowRate()
Solving for the flow rate.
void initializeSolution()
Initialize the solution.
std::function< Real(const Real &, const Real &, const Real &, const Real &, const ID &) > function_Type
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 ...
flag_Type multiscaleID_Type
MultiscaleModel()
The main constructor.
void setupModel()
Setup the model.
void setupExporterImporter()
Real tangentSolveForPressure()
Solve the tangent problem for the flow rate.
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 imposeBoundaryFlowRate(const multiscaleID_Type &boundaryID, const function_Type &function)
Impose the flow rate on a specific interface of the model.
void updateInverseJacobian(const UInt &iQuadPt)
void buildModel()
Build the initial model.
void solveModel()
Solve the model.
Real M_tangentFlowRateLeft
void updateSolution()
Update the solution.
UInt multiscaleProblemStep
MultiscaleModel multiscaleModel_Type
MultiscaleInterface()
The main constructor.
void saveSolution()
Save the solution.
Real checkSolution() const
Return a specific scalar quantity to be used for a comparison with a reference value.
Real boundaryDeltaFlowRate(const multiscaleID_Type &boundaryID, bool &solveLinearSystem)
Get the variation of the flow rate (on a specific boundary interface) using the linear model...
void showMe()
Display some information about the model.
MultiscaleModelWindkessel0D - Multiscale model for Windkessel 0D terminals.
double Real
Generic real data.
MultiscaleModelWindkessel0D()
Constructor.
void setupGlobalData(const std::string &fileName)
Setup the global data of the model.
Real M_tangentPressureLeft
void setupData(const std::string &fileName)
Setup the data of the model.
void solveLinearModel(bool &solveLinearSystem)
Solve the tangent problem.
Real solveForPressure()
Solving for the pressure.
Real tangentSolveForFlowRate()
Solve the tangent problem for the flow rate.
MultiscaleInterface - The multiscale interface for fluid problems.
void updateModel()
Update the model.
std::ofstream M_outputFile
ZeroDimensionalFunction - A boundary conditions function for zero-dimensional models.