37 #include <lifev/multiscale/couplings/MultiscaleCoupling.hpp> 67 #ifdef HAVE_LIFEV_DEBUG 68 debugStream ( 8200 ) <<
"MultiscaleCoupling::MultiscaleCoupling() \n";
80 #ifdef HAVE_LIFEV_DEBUG 81 debugStream ( 8200 ) <<
"MultiscaleCoupling::setupData( fileName ) \n";
84 GetPot dataFile ( fileName );
87 M_couplingName = dataFile (
"Multiscale/couplingName",
"couplingName" );
89 M_timeInterpolationOrder = dataFile (
"Multiscale/timeInterpolationOrder", 0 );
90 M_flowRateInterfaces = dataFile (
"Multiscale/flowRateInterfaces", 0 );
101 M_localCouplingVariables.reserve ( M_timeInterpolationOrder + 1 );
120 return M_models[localModelID]->communicator()->MyPID() == 0 ?
true :
false;
127 #ifdef HAVE_LIFEV_DEBUG 128 debugStream ( 8200 ) <<
"MultiscaleCoupling::createCouplingMap( couplingMap ) \n";
131 M_couplingVariablesOffset = couplingMap.map ( Unique )->NumGlobalElements();
140 #ifdef HAVE_LIFEV_DEBUG 141 debugStream ( 8200 ) <<
"MultiscaleCoupling::extrapolateCouplingVariables() \n";
148 interpolateCouplingVariables ( M_globalData->dataTime()->nextTime(), extrapolatedCouplingVariables );
151 UInt couplingVariablesSize ( M_localCouplingVariables.size() );
154 ++couplingVariablesSize;
155 M_localCouplingVariables.push_back ( multiscaleVectorPtr_Type (
new VectorEpetra ( localCouplingVariables ( 0 ) ) ) );
159 for (
UInt i (1) ; i < couplingVariablesSize ; ++i )
166 #ifdef HAVE_LIFEV_DEBUG 167 for ( UInt i ( 0 ); i < M_couplingVariablesNumber; ++i )
169 debugStream ( 8200 ) <<
"C(" << M_couplingVariablesOffset + i <<
") = " << ( localCouplingVariables ( 0 ) ) [i] <<
"\n";
179 UInt couplingVariablesSize ( M_localCouplingVariables.size() );
183 for (
UInt i (0) ; i < couplingVariablesSize ; ++i )
185 timeContainer[i] = M_globalData->dataTime()->time() - i * M_globalData->dataTime()->timeStep();
189 interpolatedCouplingVariables
*= 0;
192 for ( UInt i (0) ; i < M_localCouplingVariables.size() ; ++i )
195 for ( UInt j (0) ; j < M_localCouplingVariables.size() ; ++j )
198 base *= (t - timeContainer[j]) / (timeContainer[i] - timeContainer[j]);
201 interpolatedCouplingVariables += base * localCouplingVariables ( i );
209 #ifdef HAVE_LIFEV_DEBUG 210 debugStream ( 8200 ) <<
"MultiscaleCoupling::exportJacobian( jacobian ) \n";
216 bool solveLinearSystem;
229 perturbedModelsList.clear();
233 for ( multiscaleModelsContainerIterator_Type j = perturbedModelsList.begin() ; j < perturbedModelsList.end() ; ++j )
235 solveLinearSystem =
true;
238 for ( UInt k (0) ; k < ( *j )->couplingsNumber() ; ++k )
240 ( *j )->coupling ( k )->insertJacobianDeltaCoefficients ( jacobian, column, ( *j )->ID(), solveLinearSystem );
254 #ifdef HAVE_LIFEV_DEBUG 255 debugStream ( 8200 ) <<
"MultiscaleCoupling::saveSolution() \n";
263 Real flowRate ( multiscaleDynamicCast< MultiscaleInterface > ( M_models[i] )->boundaryFlowRate ( M_boundaryIDs[i] ) );
264 Real stress ( multiscaleDynamicCast< MultiscaleInterface > ( M_models[i] )->boundaryMeanNormalStress ( M_boundaryIDs[i] ) );
265 Real totalStress ( multiscaleDynamicCast< MultiscaleInterface > ( M_models[i] )->boundaryMeanTotalNormalStress ( M_boundaryIDs[i] ) );
266 Real area ( multiscaleDynamicCast< MultiscaleInterface > ( M_models[i] )->boundaryArea ( M_boundaryIDs[i] ) );
270 std::ofstream output;
271 output << std::scientific << std::setprecision ( 15 );
273 std::string filename = multiscaleProblemFolder + multiscaleProblemPrefix +
"_Coupling_" + number2string ( M_ID )
274 +
"_Flag_" + number2string ( i )
275 +
"_" + number2string ( multiscaleProblemStep ) +
".mfile";
277 if ( M_globalData->dataTime()->timeStepNumber() == 0 || ( multiscaleProblemStep > 0 &&
278 M_globalData->dataTime()->round ( M_globalData->dataTime()->time() - ( multiscaleSaveEachNTimeSteps - 1 ) * M_globalData->dataTime()->timeStep() ) == M_globalData->dataTime()->round ( M_globalData->dataTime()->initialTime() ) ) )
280 output.open ( filename.c_str(), std::ios::trunc );
281 output <<
"% Coupling Type: " << enum2String ( M_type, multiscaleCouplingsMap ) << std::endl;
282 output <<
"% Coupling Name: " << M_couplingName << std::endl;
283 output <<
"% Model: " << number2string ( M_models[i]->ID() ) << std::endl;
284 output <<
"% Boundary Flag: " << number2string ( M_models[i]->boundaryFlag ( M_boundaryIDs[i] ) ) << std::endl << std::endl;
285 output <<
"% TIME FLOW RATE STRESS TOTAL STRESS AREA" << std::endl;
289 output.open ( filename.c_str(), std::ios::app );
291 output <<
" " << M_globalData->dataTime()->time() <<
" " << flowRate <<
" " << stress <<
" " << totalStress <<
" " << area << std::endl;
303 std::cout <<
"Coupling id = " << M_ID << std::endl
304 <<
"Coupling name = " << M_couplingName << std::endl
305 <<
"Coupling type = " << enum2String ( M_type, multiscaleCouplingsMap ) << std::endl << std::endl;
307 std::cout <<
"Interpolation order = " << M_timeInterpolationOrder << std::endl
308 <<
"Flow interfaces = " << M_flowRateInterfaces << std::endl << std::endl;
310 std::cout <<
"Models ID(s) = ";
314 std::cout << M_models[i]->ID() <<
" ";
316 std::cout << std::endl;
317 std::cout <<
"Models type(s) = ";
321 std::cout << enum2String ( M_models[i]->type(), multiscaleModelsMap ) <<
" ";
323 std::cout << std::endl;
324 std::cout <<
"Flags list = ";
328 std::cout << M_boundaryIDs[i] <<
" ";
330 std::cout << std::endl << std::endl;
342 std::cout <<
"R(" << M_couplingVariablesOffset + i <<
") = " << ( *M_localCouplingResiduals ) [i] << std::endl;
355 std::cout <<
"C(" << M_couplingVariablesOffset + i <<
") = " << localCouplingVariables ( 0 ) [i] << std::endl;
369 if ( M_models[localID]->ID() == ID )
374 std::cout <<
" !!! WARNING: modelGlobalToLocalID was not able to find the model ID !!! " << std::endl;
385 std::vector<Int> myGlobalElements ( M_couplingVariablesNumber );
386 for ( UInt i = 0 ; i < myGlobalElements.size() ; ++i )
388 myGlobalElements[i] = i;
392 MapEpetra map ( -1,
static_cast< Int > ( myGlobalElements.size() ), &myGlobalElements[0], M_comm );
395 M_localCouplingVariables.push_back ( multiscaleVectorPtr_Type (
new VectorEpetra ( map, Repeated ) ) );
396 M_localCouplingResiduals.reset (
new VectorEpetra ( map, Repeated ) );
403 for ( UInt i ( 0 ) ; i < M_localCouplingVariables.size() ; ++i )
405 localCouplingVariables ( i ) = 0;
415 repeatedLocalVector
= uniqueLocalVector;
428 multiscaleErrorCheck ( ModelType,
"Invalid model type [" + enum2String ( model->type(), multiscaleModelsMap ) +
429 "] for coupling type [" + enum2String ( M_type, multiscaleCouplingsMap ) +
"]\n", model->communicator()->MyPID() == 0 );
UInt modelGlobalToLocalID(const UInt &ID) const
Get the model local ID through global ID.
void switchErrorMessage(const multiscaleModelPtr_Type &model)
Display and error message for the specific model.
UInt myModelsNumber() const
Determine the number of models owned by this coupling.
VectorEpetra & subset(const VectorEpetra &vector, const UInt offset=0)
Set the current vector to a subset of the given vector with an offset.
multiscaleDataPtr_Type M_globalData
UInt M_timeInterpolationOrder
std::vector< Real > timeContainer_Type
multiscaleCommPtr_Type M_comm
void showMeCouplingVariables() const
Display the local coupling variables.
void interpolateCouplingVariables(const Real &t, multiscaleVector_Type &interpolatedCouplingVariables) const
Lagrange interpolation/extrapolation of the coupling variables at selected time.
void createLocalVectors()
Create the local vectors of the coupling.
UInt M_couplingVariablesOffset
MapEpetra & operator+=(const MapEpetra &epetraMap)
Addition operator.
void extrapolateCouplingVariables()
Extrapolate the values of the coupling variables for the next time step.
void importCouplingVector(multiscaleVector_Type &repeatedLocalVector, const multiscaleVector_Type &uniqueGlobalVector, const combineMode_Type &combineMode=Add)
Import the content of the unique global vector into the repeated local vector.
int32_type Int
Generic integer data.
MultiscaleCoupling()
Constructor.
void exportCouplingVector(multiscaleVector_Type &uniqueGlobalVector, const multiscaleVector_Type &repeatedLocalVector, const combineMode_Type &combineMode=Add)
Export the content of the repeated local vector into the unique global vector.
void updateInverseJacobian(const UInt &iQuadPt)
std::map< std::string, couplings_Type > multiscaleCouplingsMap
UInt modelsNumber() const
Get the number of models connected by the coupling.
std::shared_ptr< multiscaleModel_Type > multiscaleModelPtr_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
virtual void insertJacobianConstantCoefficients(multiscaleMatrix_Type &jacobian)=0
Insert constant coefficients into the Jacobian matrix.
couplingVariablesContainer_Type M_localCouplingVariables
void saveSolution()
save the coupling variables information on a file
multiscaleModelsContainer_Type M_models
multiscaleVector_Type & localCouplingVariables(const UInt &id)
VectorEpetra & replace(const VectorEpetra &vector, const Int &offset)
Replace part of the vector with a given vector.
const MapEpetra & map() const
Return the MapEpetra of the vector.
UInt M_couplingVariablesNumber
MatrixEpetra< Real > multiscaleMatrix_Type
virtual void setupCouplingVariablesNumber()=0
Setup the coupling variables number.
std::vector< multiscaleModelPtr_Type > multiscaleModelsContainer_Type
bool isModelLeaderProcess(const UInt &localModelID) const
Determine if this is the model leader process.
void resetCouplingHistory()
Reset the history of the couplings.
void exportJacobian(multiscaleMatrix_Type &jacobian)
Export the Jacobian matrix.
couplingFunctionsContainer_Type M_localCouplingFunctions
multiscaleVectorPtr_Type M_localCouplingResiduals
double Real
Generic real data.
multiscaleIDContainer_Type M_boundaryIDs
void showMeResiduals() const
Display the local residuals vector.
virtual void exportListOfPerturbedModels(const UInt &localCouplingVariableID, multiscaleModelsContainer_Type &perturbedModelsList)=0
Build the list of models affected by the perturbation of the local coupling variable.
bool myModel(const UInt &localModelID) const
Determine if the model is owned by this coupling.
VectorEpetra & operator*=(const data_type &scalar)
Multiplication operator.
VectorEpetra(const VectorEpetra &vector)
Copy constructor.
VectorEpetra & operator=(const VectorEpetra &vector)
Affectation operator.
virtual void setupData(const std::string &fileName)
Setup the data of the coupling.
void createCouplingMap(MapEpetra &couplingMap)
Build the global map for the coupling vectors.
MultiscaleCoupling - The Multiscale Physical Coupling.
VectorEpetra(const VectorEpetra &vector, const MapEpetraType &mapType, const combineMode_Type &combineMode)
Copy constructor.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
VectorEpetra multiscaleVector_Type
void showMe()
Display some information about the coupling.