37 #include <lifev/multiscale/framework/MultiscaleSolver.hpp> 60 #ifdef HAVE_LIFEV_DEBUG 61 debugStream ( 8000 ) <<
"MultiscaleSolver::MultiscaleSolver() \n";
68 multiscaleModelFactory_Type::instance().registerProduct ( Multiscale, &createMultiscaleModelMultiscale );
69 #if defined(LIFEV_HAS_NAVIERSTOKES) 70 multiscaleModelFactory_Type::instance().registerProduct ( Fluid3D, &createMultiscaleModelFluid3D );
72 #if defined(LIFEV_HAS_FSI) 73 multiscaleModelFactory_Type::instance().registerProduct ( FSI3D, &createMultiscaleModelFSI3D );
75 #if defined(LIFEV_HAS_ONEDFSI) 76 multiscaleModelFactory_Type::instance().registerProduct ( FSI1D, &createMultiscaleModelFSI1D );
78 #if defined(LIFEV_HAS_ZERODIMENSIONAL) 79 multiscaleModelFactory_Type::instance().registerProduct ( Windkessel0D, &createMultiscaleModelWindkessel0D );
80 multiscaleModelFactory_Type::instance().registerProduct ( ZeroDimensional, &createMultiscaleModelZeroDimensional );
91 #ifdef HAVE_LIFEV_DEBUG 92 debugStream ( 8000 ) <<
"MultiscaleSolver::setupData( fileName, problemFolder ) \n";
96 GetPot dataFile ( fileName );
99 multiscaleProblemFolder = problemFolder;
105 if ( dataFile (
"Solver/Restart/Restart",
false ) )
107 multiscaleProblemStep = dataFile (
"Solver/Restart/RestartFromStepNumber", 0 ) + 1;
111 multiscaleProblemPrefix = dataFile (
"Solver/Output/ProblemPrefix",
"Multiscale" );
114 multiscaleSaveEachNTimeSteps = dataFile (
"Solver/Output/SaveEach", 1 );
117 M_model = multiscaleModelPtr_Type ( multiscaleModelFactory_Type::instance().createObject ( multiscaleModelsMap[ dataFile (
"Problem/ProblemType",
"Multiscale" ) ], multiscaleModelsMap ) );
119 M_model->setID ( 0 );
120 M_model->setCommunicator ( M_comm );
123 M_globalData->readData ( dataFile );
124 M_model->setGlobalData ( M_globalData );
125 M_model->setupData ( dataFile (
"Problem/ProblemFile",
"./MultiscaleDatabase/Models/NoModel" ) +
".dat" );
132 M_model->setupModel();
137 M_model->saveSolution();
141 M_globalData->dataTime()->updateTime();
142 M_globalData->dataTime()->setInitialTime ( M_globalData->dataTime()->time() );
149 #ifdef HAVE_LIFEV_DEBUG 150 debugStream ( 8000 ) <<
"MultiscaleSolver::solveProblem() \n";
159 Real totalSimulationTime (0);
160 Real timeStepTime (0);
162 for ( ; M_globalData->dataTime()->canAdvance(); M_globalData->dataTime()->updateTime() )
165 globalChrono.start();
167 if ( M_comm->MyPID() == 0 )
169 std::cout << std::endl;
170 std::cout <<
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << std::endl;
171 std::cout <<
" MULTISCALE FRAMEWORK" << std::endl;
172 std::cout <<
" time = " << M_globalData->dataTime()->time() <<
" s;" 173 <<
" time step number = " << M_globalData->dataTime()->timeStepNumber() << std::endl;
174 std::cout <<
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << std::endl << std::endl;
178 buildUpdateChrono.start();
179 if ( M_globalData->dataTime()->isFirstTimeStep() )
181 M_model->buildModel();
185 M_model->updateModel();
187 buildUpdateChrono.stop();
191 M_model->solveModel();
195 updateSolutionChrono.start();
196 M_model->updateSolution();
197 updateSolutionChrono.stop();
201 if ( M_globalData->dataTime()->timeStepNumber() % multiscaleSaveEachNTimeSteps == 0 || M_globalData->dataTime()->isLastTimeStep() )
203 M_model->saveSolution();
211 timeStepTime = globalChrono.globalDiff ( *M_comm );
214 totalSimulationTime += timeStepTime;
216 if ( M_comm->MyPID() == 0 )
218 std::cout <<
" MS- Total iteration time: " << timeStepTime <<
" s" << std::endl;
219 std::cout <<
" MS- Total simulation time: " << totalSimulationTime <<
" s" << std::endl;
223 saveCPUTime ( timeStepTime, buildUpdateChrono.globalDiff ( *M_comm ), solveChrono.globalDiff ( *M_comm ),
224 updateSolutionChrono.globalDiff ( *M_comm ), saveChrono.globalDiff ( *M_comm ) );
228 Real computedSolution ( M_model->checkSolution() );
229 Real relativeError ( std::abs ( ( referenceSolution - computedSolution ) / referenceSolution ) );
230 if ( referenceSolution >= 0. && relativeError > tolerance )
231 multiscaleErrorCheck ( Solution,
"Problem solution: " + number2string ( computedSolution ) +
232 " (Reference solution: " + number2string ( referenceSolution ) +
233 "; Relative error: " + number2string ( relativeError ) +
")\n", M_comm->MyPID() == 0 );
241 if ( M_comm->MyPID() == 0 )
243 std::cout << std::endl << std::endl
244 <<
"=============== Multiscale Solver Information ===============" << std::endl << std::endl;
246 std::cout <<
"Cores per node = " << multiscaleCoresPerNode << std::endl
247 <<
"Problem folder = " << multiscaleProblemFolder << std::endl
248 <<
"Problem prefix = " << multiscaleProblemPrefix << std::endl
249 <<
"Problem step = " << multiscaleProblemStep << std::endl
250 <<
"Save each = " << multiscaleSaveEachNTimeSteps <<
" time steps" << std::endl << std::endl;
252 M_globalData->showMe();
254 std::cout << std::endl << std::endl;
259 if ( M_comm->MyPID() == 0 )
261 std::cout <<
"=============================================================" << std::endl << std::endl;
271 const Real& updateSolutionCPUTime,
const Real& saveCPUTime )
const 273 if ( M_comm->MyPID() == 0 )
275 std::ofstream outputFile;
276 outputFile << std::scientific << std::setprecision ( 15 );
278 std::string filename = multiscaleProblemFolder + multiscaleProblemPrefix +
"_CPUTime_" + number2string ( multiscaleProblemStep ) +
".mfile";
280 if ( M_globalData->dataTime()->isFirstTimeStep() )
282 outputFile.open ( filename.c_str(), std::ios::trunc );
283 outputFile <<
"% ITERATION TIME TOTAL BUILD/UPDATE " 284 "SOLVE UPDATE SOLUTION SAVE" << std::endl;
288 outputFile.open ( filename.c_str(), std::ios::app );
290 outputFile <<
" " << number2string ( M_globalData->dataTime()->timeStepNumber() )
291 <<
" " << M_globalData->dataTime()->time()
292 <<
" " << totalCPUTime <<
" " << buildUpdateCPUTime <<
" " << solveCPUTime
293 <<
" " << updateSolutionCPUTime <<
" " << saveCPUTime << std::endl;
302 Int iterationNumber ( 0 );
303 Real initialTime ( 0. );
305 if ( M_comm->MyPID() == 0 )
307 std::string fileName = multiscaleProblemFolder + multiscaleProblemPrefix +
"_CPUTime_" + number2string ( multiscaleProblemStep - 1 ) +
".mfile";
309 std::ifstream inputFile;
310 inputFile.open ( fileName.c_str(), std::ios::in );
312 if ( inputFile.is_open() )
316 std::vector<std::string> stringsVector;
317 std::vector< std::pair< Int, Real > > iterationAndTime;
318 std::pair<
Int,
Real > selectedIterationAndTime;
321 std::getline ( inputFile, line,
'\n' );
324 while ( std::getline ( inputFile, line,
'\n' ) )
326 boost::split ( stringsVector, line, boost::is_any_of (
" " ), boost::token_compress_on );
327 if ( string2number ( stringsVector[7] ) > 0 )
329 iterationAndTime.push_back ( std::make_pair ( string2number ( stringsVector[1] ), string2number ( stringsVector[2] ) ) );
337 selectedIterationAndTime = iterationAndTime.front();
338 for ( std::vector< std::pair< Int, Real > >::const_iterator i = iterationAndTime.begin(); i < iterationAndTime.end() ; ++i )
339 if ( std::fabs ( selectedIterationAndTime.second - M_globalData->dataTime()->time() ) >= std::fabs ( (*i).second - M_globalData->dataTime()->time() ) )
341 selectedIterationAndTime = *i;
345 iterationNumber = selectedIterationAndTime.first;
346 initialTime = selectedIterationAndTime.second;
350 std::cerr <<
" !!! Error: cannot open file: " << fileName.c_str() <<
" !!!" << std::endl;
355 M_comm->Broadcast ( &iterationNumber, 1, 0 );
356 M_comm->Broadcast ( &initialTime, 1, 0 );
359 M_globalData->dataTime()->setTimeStepNumber ( iterationNumber );
360 M_globalData->dataTime()->setInitialTime ( initialTime );
361 M_globalData->dataTime()->setTime ( initialTime );
void showMe() const
Display some information about the Multiscale problem (should be called after setupProblem) ...
std::string multiscaleProblemFolder
int32_type Int
Generic integer data.
void importIterationNumber()
Import iteration number from the CPU file.
void multiscaleMapsDefinition()
Define the map of the MS objects.
void updateInverseJacobian(const UInt &iQuadPt)
UInt multiscaleProblemStep
bool solveProblem(const Real &referenceSolution=-1., const Real &tolerance=1e-8)
Run the time-loop to solve the Multiscale problem.
void saveCPUTime(const Real &totalCPUTime, const Real &buildUpdateCPUTime, const Real &solveCPUTime, const Real &updateSolutionCPUTime, const Real &saveCPUTime) const
Save CPU time at each time step.
UInt multiscaleCoresPerNode
multiscaleCommPtr_Type M_comm
std::string multiscaleProblemPrefix
double Real
Generic real data.
MultiscaleSolver()
Constructor.
void setupProblem(const std::string &fileName, const std::string &problemName, const UInt &coresPerNode)
Setup the problem.
multiscaleModelPtr_Type M_model
UInt multiscaleSaveEachNTimeSteps
MultiscaleSolver - The Multiscale solver.
uint32_type UInt
generic unsigned integer (used mainly for addressing)