37 #include <lifev/multiscale/models/MultiscaleModelMultiscale.hpp> 39 #include <lifev/multiscale/algorithms/MultiscaleAlgorithmAitken.hpp> 40 #include <lifev/multiscale/algorithms/MultiscaleAlgorithmBroyden.hpp> 41 #include <lifev/multiscale/algorithms/MultiscaleAlgorithmExplicit.hpp> 42 #include <lifev/multiscale/algorithms/MultiscaleAlgorithmNewton.hpp> 44 #include <lifev/multiscale/couplings/MultiscaleCouplingBoundaryCondition.hpp> 45 #include <lifev/multiscale/couplings/MultiscaleCouplingMeanNormalStress.hpp> 46 #include <lifev/multiscale/couplings/MultiscaleCouplingMeanNormalStressValve.hpp> 47 #include <lifev/multiscale/couplings/MultiscaleCouplingMeanTotalNormalStress.hpp> 49 #if defined(LIFEV_HAS_ONEDFSI) && defined(LIFEV_HAS_FSI) 50 #include <lifev/multiscale/couplings/MultiscaleCouplingMeanNormalStressArea.hpp> 51 #include <lifev/multiscale/couplings/MultiscaleCouplingMeanTotalNormalStressArea.hpp> 70 #ifdef HAVE_LIFEV_DEBUG 71 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::MultiscaleModelMultiscale() \n";
76 multiscaleAlgorithmFactory_Type::instance().registerProduct ( Aitken, &createMultiscaleAlgorithmAitken );
77 multiscaleAlgorithmFactory_Type::instance().registerProduct ( Broyden, &createMultiscaleAlgorithmBroyden );
78 multiscaleAlgorithmFactory_Type::instance().registerProduct ( Explicit, &createMultiscaleAlgorithmExplicit );
79 multiscaleAlgorithmFactory_Type::instance().registerProduct ( Newton, &createMultiscaleAlgorithmNewton );
81 multiscaleCouplingFactory_Type::instance().registerProduct ( BoundaryCondition, &createMultiscaleCouplingBoundaryCondition );
82 multiscaleCouplingFactory_Type::instance().registerProduct ( MeanNormalStress, &createMultiscaleCouplingMeanNormalStress );
83 multiscaleCouplingFactory_Type::instance().registerProduct ( MeanNormalStressValve, &createMultiscaleCouplingMeanNormalStressValve );
84 multiscaleCouplingFactory_Type::instance().registerProduct ( MeanTotalNormalStress, &createMultiscaleCouplingMeanTotalNormalStress );
86 #if defined(LIFEV_HAS_ONEDFSI) && defined(LIFEV_HAS_FSI) 87 multiscaleCouplingFactory_Type::instance().registerProduct ( MeanNormalStressArea, &createMultiscaleCouplingMeanNormalStressArea );
88 multiscaleCouplingFactory_Type::instance().registerProduct ( MeanTotalNormalStressArea, &createMultiscaleCouplingMeanTotalNormalStressArea );
95 #ifdef HAVE_LIFEV_DEBUG 96 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::~MultiscaleModelMultiscale() \n";
100 for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
102 ( *i )->clearCouplingsList();
105 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
107 ( *i )->clearModelsList();
118 #ifdef HAVE_LIFEV_DEBUG 119 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::setupData( fileName ) \n";
122 multiscaleModel_Type::setupData ( fileName );
126 UInt myIDCounter (0);
127 std::map< UInt, UInt > modelsIDMap;
135 std::array< Real,
NDIM > geometryScale, geometryRotate, geometryTranslate;
141 GetPot dataFile ( fileName );
143 UInt modelsColumnsNumber = 3.0;
144 UInt couplingsColumnsNumber = 5.0;
145 UInt mpiGroupsColumnsNumber = 3.0;
146 UInt geometryColumnsNumber = 10.0;
148 UInt modelsLinesNumber = dataFile.vector_variable_size (
"Problem/models" ) / modelsColumnsNumber;
149 UInt couplingsLinesNumber = dataFile.vector_variable_size (
"Problem/couplings" ) / couplingsColumnsNumber;
150 UInt mpiGroupsLinesNumber = dataFile.vector_variable_size (
"Problem/mpiGroups" ) / mpiGroupsColumnsNumber;
151 UInt geometryLinesNumber = dataFile.vector_variable_size (
"Problem/offset" ) / geometryColumnsNumber;
156 for (
UInt fileMPIGroupsLine ( 0 ); fileMPIGroupsLine < mpiGroupsLinesNumber; ++fileMPIGroupsLine )
158 load = dataFile (
"Problem/mpiGroups", 0.0, fileMPIGroupsLine * mpiGroupsColumnsNumber + 1 );
159 string2numbersVector< UInt > ( dataFile (
"Problem/mpiGroups",
"undefined", fileMPIGroupsLine * mpiGroupsColumnsNumber + 2 ), modelsIDVector );
162 modelsIDVector.clear();
169 std::string path = dataFile (
"Problem/modelsPath",
"./" );
170 M_modelsList.resize ( M_commManager.myModelsNumber() );
171 for (
UInt fileModelsLine ( 0 ); fileModelsLine < modelsLinesNumber; ++fileModelsLine )
173 fileID = dataFile (
"Problem/models", 0, fileModelsLine * modelsColumnsNumber );
176 modelsIDMap[fileID] = myIDCounter;
177 model = multiscaleModelsMap[dataFile (
"Problem/models",
"undefined", fileModelsLine * modelsColumnsNumber + 1 )];
180 geometryScale[0] = M_geometryScale[0];
181 geometryScale[1] = M_geometryScale[1];
182 geometryScale[2] = M_geometryScale[2];
184 geometryRotate[0] = M_geometryRotate[0];
185 geometryRotate[1] = M_geometryRotate[1];
186 geometryRotate[2] = M_geometryRotate[2];
188 geometryTranslate[0] = M_geometryTranslate[0];
189 geometryTranslate[1] = M_geometryTranslate[1];
190 geometryTranslate[2] = M_geometryTranslate[2];
192 for (
UInt fileGeometryLine ( 0 ); fileGeometryLine < geometryLinesNumber; ++fileGeometryLine )
193 if ( fileID == dataFile (
"Problem/offset", 1., fileGeometryLine * geometryColumnsNumber ) )
195 geometryScale[0] *= dataFile (
"Problem/offset", 1., fileGeometryLine * geometryColumnsNumber + 1 );
196 geometryScale[1] *= dataFile (
"Problem/offset", 1., fileGeometryLine * geometryColumnsNumber + 2 );
197 geometryScale[2] *= dataFile (
"Problem/offset", 1., fileGeometryLine * geometryColumnsNumber + 3 );
199 geometryRotate[0] += dataFile (
"Problem/offset", 0., fileGeometryLine * geometryColumnsNumber + 4 ) *
M_PI / 180;
200 geometryRotate[1] += dataFile (
"Problem/offset", 0., fileGeometryLine * geometryColumnsNumber + 5 ) *
M_PI / 180;
201 geometryRotate[2] += dataFile (
"Problem/offset", 0., fileGeometryLine * geometryColumnsNumber + 6 ) *
M_PI / 180;
203 geometryTranslate[0] += dataFile (
"Problem/offset", 0., fileGeometryLine * geometryColumnsNumber + 7 );
204 geometryTranslate[1] += dataFile (
"Problem/offset", 0., fileGeometryLine * geometryColumnsNumber + 8 );
205 geometryTranslate[2] += dataFile (
"Problem/offset", 0., fileGeometryLine * geometryColumnsNumber + 9 );
208 M_modelsList[myIDCounter] = multiscaleModelPtr_Type ( multiscaleModelFactory_Type::instance().createObject ( model, multiscaleModelsMap ) );
209 M_modelsList[myIDCounter]->setID ( fileModelsLine + 1 );
210 M_modelsList[myIDCounter]->setCommunicator ( M_commManager.modelCommunicator ( fileID ) );
211 M_modelsList[myIDCounter]->setGeometry ( geometryScale, geometryRotate, geometryTranslate );
212 M_modelsList[myIDCounter]->setGlobalData ( M_globalData );
213 M_modelsList[myIDCounter]->setupData ( path + enum2String ( model, multiscaleModelsMap ) +
"/" 214 + dataFile (
"Problem/models",
"undefined", fileModelsLine * modelsColumnsNumber + 2 ) +
".dat" );
222 M_couplingsList.resize ( couplingsLinesNumber );
223 path = dataFile (
"Problem/couplingsPath",
"./" );
224 for (
UInt fileCouplingsLine ( 0 ); fileCouplingsLine < couplingsLinesNumber; ++fileCouplingsLine )
227 coupling = multiscaleCouplingsMap[dataFile (
"Problem/couplings",
"undefined", fileCouplingsLine * couplingsColumnsNumber + 1 )];
228 M_couplingsList.reserve ( ++myIDCounter );
229 M_couplingsList[fileCouplingsLine] = multiscaleCouplingPtr_Type ( multiscaleCouplingFactory_Type::instance().createObject ( coupling, multiscaleCouplingsMap ) );
230 M_couplingsList[fileCouplingsLine]->setID ( fileCouplingsLine );
231 M_couplingsList[fileCouplingsLine]->setCommunicator ( M_comm );
233 string2numbersVector< UInt > ( dataFile (
"Problem/couplings",
"undefined", fileCouplingsLine * couplingsColumnsNumber + 3 ), modelsIDVector );
234 string2numbersVector< UInt > ( dataFile (
"Problem/couplings",
"undefined", fileCouplingsLine * couplingsColumnsNumber + 4 ), boundaryIDVector );
236 M_couplingsList[fileCouplingsLine]->setModelsNumber ( modelsIDVector.size() );
237 for ( UInt j ( 0 ); j < modelsIDVector.size(); ++j )
238 if ( M_commManager.myModel ( modelsIDVector[j] ) )
240 M_couplingsList[fileCouplingsLine]->setModel ( j, M_modelsList[modelsIDMap[modelsIDVector[j]]] );
241 M_couplingsList[fileCouplingsLine]->setBoundaryID ( j, boundaryIDVector[j] );
242 M_modelsList[modelsIDMap[modelsIDVector[j]]]->addCoupling ( M_couplingsList[fileCouplingsLine] );
244 modelsIDVector.clear();
245 boundaryIDVector.clear();
247 M_couplingsList[fileCouplingsLine]->setGlobalData ( M_globalData );
248 M_couplingsList[fileCouplingsLine]->setupData ( path + enum2String ( coupling, multiscaleCouplingsMap ) +
"/" 249 + dataFile (
"Problem/couplings",
"undefined", fileCouplingsLine * couplingsColumnsNumber + 2 ) +
".dat" );
253 path = dataFile (
"Problem/algorithmsPath",
"./" );
254 algorithm = multiscaleAlgorithmsMap[ dataFile (
"Problem/algorithm",
"Explicit", 0 ) ];
255 M_algorithm = multiscaleAlgorithmPtr_Type ( multiscaleAlgorithmFactory_Type::instance().createObject ( algorithm, multiscaleAlgorithmsMap ) );
256 M_algorithm->setCommunicator ( M_comm );
257 M_algorithm->setupData ( path + enum2String ( algorithm, multiscaleAlgorithmsMap ) +
"/" + dataFile (
"Problem/algorithm",
"undefined", 1 ) +
".xml" );
264 #ifdef HAVE_LIFEV_DEBUG 265 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::setupModel() \n";
268 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
270 ( *i )->setupCoupling();
273 for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
275 ( *i )->setupModel();
278 M_algorithm->setMultiscaleModel (
this );
279 M_algorithm->setupAlgorithm();
286 #ifdef HAVE_LIFEV_DEBUG 287 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::buildModel() \n";
290 for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
292 ( *i )->buildModel();
295 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
297 ( *i )->initializeCouplingVariables();
300 if ( M_algorithm->type() != Explicit )
302 ( *i )->extrapolateCouplingVariables();
311 #ifdef HAVE_LIFEV_DEBUG 312 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::updateModel() \n";
315 for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
317 ( *i )->updateModel();
320 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
322 ( *i )->updateCoupling();
324 if ( M_algorithm->type() != Explicit )
326 ( *i )->extrapolateCouplingVariables();
330 ( *i )->initializeCouplingVariables();
339 #ifdef HAVE_LIFEV_DEBUG 340 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::solveModel() \n";
343 M_algorithm->subIterate();
350 #ifdef HAVE_LIFEV_DEBUG 351 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::updateSolution() \n";
354 for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
356 ( *i )->updateSolution();
364 #ifdef HAVE_LIFEV_DEBUG 365 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::saveSolution() \n";
368 for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
370 ( *i )->saveSolution();
373 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
375 ( *i )->saveSolution();
379 if ( M_globalData->dataTime()->isFirstTimeStep() )
382 std::string filename = multiscaleProblemFolder + multiscaleProblemPrefix +
"_Model_" + number2string ( M_ID ) +
"_" + number2string ( multiscaleProblemStep ) +
".mfile";
385 if ( M_comm->MyPID() == 0 )
387 std::remove ( filename.c_str() );
393 std::ofstream output;
394 output.open ( filename.c_str(), std::ios::app );
397 for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
398 if ( ( *i )->communicator()->MyPID() == 0 )
400 output <<
"Model ID: " << ( *i )->ID() <<
", Name: " << ( *i )->modelName() << std::endl;
406 if ( M_comm->MyPID() == 0 )
407 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
409 output <<
"Coupling ID: " << ( *i )->ID() <<
", Name: " << ( *i )->couplingName() << std::endl;
420 if ( M_comm->MyPID() == 0 )
422 multiscaleModel_Type::showMe();
423 std::cout <<
"Models number = " << M_modelsList.size() << std::endl
424 <<
"Couplings number = " << M_couplingsList.size() << std::endl << std::endl;
426 std::cout <<
"==================== Models Information =====================" << std::endl << std::endl;
429 for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
434 if ( M_comm->MyPID() == 0 )
436 std::cout <<
"=================== Couplings Information ===================" << std::endl << std::endl;
439 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
444 if ( M_comm->MyPID() == 0 )
446 std::cout <<
"================= Communicators Information =================" << std::endl << std::endl;
451 if ( M_comm->MyPID() == 0 )
453 std::cout <<
"=================== Algorithm Information ===================" << std::endl << std::endl;
456 M_algorithm->showMe();
462 return M_algorithm->couplingVariables()->norm2();
472 #ifdef HAVE_LIFEV_DEBUG 473 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::createCouplingMap( couplingMap ) \n";
480 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
482 ( *i )->createCouplingMap ( couplingMap );
490 #ifdef HAVE_LIFEV_DEBUG 491 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::importCouplingVariables( couplingVariables ) \n";
498 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
500 ( *i )->importCouplingVariables ( couplingVariables );
508 #ifdef HAVE_LIFEV_DEBUG 509 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::exportCouplingVariables( couplingVariables ) \n";
516 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
518 ( *i )->exportCouplingVariables ( couplingVariables );
526 #ifdef HAVE_LIFEV_DEBUG 527 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::computeCouplingResiduals() \n";
530 displayModelStatus (
"Solve" );
531 for ( multiscaleModelsContainerConstIterator_Type i = M_modelsList.begin(); i != M_modelsList.end(); ++i )
533 ( *i )->solveModel();
540 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
542 ( *i )->computeCouplingResiduals();
550 #ifdef HAVE_LIFEV_DEBUG 551 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::exportCouplingResiduals( couplingResiduals ) \n";
558 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
560 ( *i )->exportCouplingResiduals ( couplingResiduals );
568 #ifdef HAVE_LIFEV_DEBUG 569 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::exportJacobian() \n";
576 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
578 ( *i )->exportJacobian ( jacobian );
586 #ifdef HAVE_LIFEV_DEBUG 587 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::topologyChange() \n";
590 bool topologyChange (
false );
592 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
594 topologyChange = topologyChange || ( *i )->topologyChange();
597 return topologyChange;
607 #ifdef HAVE_LIFEV_DEBUG 608 debugStream ( 8110 ) <<
"MultiscaleModelMultiscale::couplingVariablesNumber() \n";
611 UInt couplingVariablesNumber = 0;
617 for ( multiscaleCouplingsContainerConstIterator_Type i = M_couplingsList.begin(); i != M_couplingsList.end(); ++i )
619 couplingVariablesNumber += ( *i )->couplingVariablesNumber();
622 return couplingVariablesNumber;
void exportCouplingVariables(multiscaleVector_Type &couplingVariables)
Export the values of the coupling variables.
void showMe()
Display some information about the multiscale problem (call after SetupProblem)
bool topologyChange()
Check if the topology is changed.
Real checkSolution() const
Return a specific scalar quantity to be used for a comparison with a reference value.
multiscaleCommPtr_Type M_comm
virtual ~MultiscaleModelMultiscale()
Destructor.
void updateModel()
Update the model.
MultiscaleModel()
The main constructor.
multiscaleCouplingsContainer_Type M_couplingsList
void setupModel()
Setup the model.
void updateInverseJacobian(const UInt &iQuadPt)
void setCommunicator(const multiscaleCommPtr_Type &comm)
Set the main epetra communicator.
void showMe()
Display some information about the communicators.
MultiscaleModelMultiscale()
Constructor.
Epetra_Import const & importer()
Getter for the Epetra_Import.
void setupData(const std::string &fileName)
Setup the data of the model.
void addGroup(const Real &load, const modelsID_Type &modelsID)
Add a group of models.
void buildModel()
Build the initial model.
MultiscaleModel multiscaleModel_Type
multiscaleAlgorithmPtr_Type M_algorithm
void createCouplingMap(MapEpetra &couplingMap)
Build the global map for the coupling vectors.
MatrixEpetra< Real > multiscaleMatrix_Type
MultiscaleCommunicatorsManager M_commManager
void saveSolution()
Save the solution.
void computeCouplingResiduals()
Compute the values of the interface residuals.
double Real
Generic real data.
void exportJacobian(multiscaleMatrix_Type &jacobian)
Export the Jacobian matrix.
std::vector< multiscaleID_Type > multiscaleIDContainer_Type
bool myModel(const UInt &modelID) const
Determine if the model is owned by the process.
void splitCommunicator()
Split the communicator among the models.
void exportCouplingResiduals(multiscaleVector_Type &couplingResiduals)
Export the values of the interface residuals.
void updateSolution()
Update the solution.
void solveModel()
Solve the model.
MultiscaleCommunicatorsManager()
Constructor.
MultiscaleModelMultiscale - Multiscale model.
UInt couplingVariablesNumber()
Get the number of the coupling variables.
void importCouplingVariables(const multiscaleVector_Type &couplingVariables)
Import the values of the coupling variables.
multiscaleModelsContainer_Type M_modelsList
uint32_type UInt
generic unsigned integer (used mainly for addressing)
VectorEpetra multiscaleVector_Type