37 #include <lifev/multiscale/algorithms/MultiscaleAlgorithmBroyden.hpp> 60 #ifdef HAVE_LIFEV_DEBUG 61 debugStream ( 8014 ) <<
"MultiscaleAlgorithmBroyden::MultiscaleAlgorithmBroyden() \n";
74 #ifdef HAVE_LIFEV_DEBUG 75 debugStream ( 8014 ) <<
"MultiscaleAlgorithmBroyden::setupData( fileName ) \n";
80 solverParametersList = Teuchos::getParametersFromXmlFile ( fileName );
83 setAlgorithmName ( solverParametersList->sublist (
"Multiscale",
true,
"" ) );
84 setAlgorithmParameters ( solverParametersList->sublist (
"Multiscale Algorithm",
true,
"" ) );
87 M_solver.setCommunicator ( M_comm );
88 M_solver.setParameters ( solverParametersList->sublist (
"Linear Solver List",
true,
"" ) );
92 MultiscaleAlgorithmBroyden::setupAlgorithm()
95 #ifdef HAVE_LIFEV_DEBUG 96 debugStream ( 8014 ) <<
"MultiscaleAlgorithmBroyden::setupAlgorithm() \n";
99 multiscaleAlgorithm_Type::setupAlgorithm();
102 #if ( H5_VERS_MAJOR > 1
|| ( H5_VERS_MAJOR == 1
&& H5_VERS_MINOR > 8
) || ( H5_VERS_MAJOR == 1
&& H5_VERS_MINOR == 8
&& H5_VERS_RELEASE >= 7
) ) 103 #ifdef BROYDEN_IMPORTJACOBIAN 105 if ( multiscaleProblemStep > 0 )
107 importJacobianFromHDF5();
115 MultiscaleAlgorithmBroyden::subIterate()
118 #ifdef HAVE_LIFEV_DEBUG 119 debugStream ( 8014 ) <<
"MultiscaleAlgorithmBroyden::subIterate() \n";
122 multiscaleAlgorithm_Type::subIterate();
125 if ( checkResidual ( 0 ) )
128 #if ( H5_VERS_MAJOR > 1
|| ( H5_VERS_MAJOR == 1
&& H5_VERS_MINOR > 8
) || ( H5_VERS_MAJOR == 1
&& H5_VERS_MINOR == 8
&& H5_VERS_RELEASE >= 7
) ) 129 exportJacobianToHDF5();
135 M_multiscale->exportCouplingVariables ( *M_couplingVariables );
137 multiscaleVectorPtr_Type delta (
new multiscaleVector_Type ( *M_couplingResiduals, Unique ) );
140 for ( UInt subIT (1); subIT <= M_subiterationsMaximumNumber; ++subIT )
145 if ( M_jacobian.get() == 0 || M_iterationsLimitReached || M_multiscale->topologyChange() )
147 assembleJacobianMatrix();
148 M_iterationsLimitReached =
false;
153 broydenJacobianUpdate ( *delta );
157 M_solver.setOperator ( M_jacobian );
158 M_solver.setRightHandSide ( M_couplingResiduals );
161 M_solver.solve ( delta );
167 *M_couplingVariables += *delta;
170 M_multiscale->importCouplingVariables ( *M_couplingVariables );
172 if ( subIT >= M_iterationsLimitForReset )
174 M_iterationsLimitReached =
true;
178 if ( checkResidual ( subIT ) )
181 #if ( H5_VERS_MAJOR > 1
|| ( H5_VERS_MAJOR == 1
&& H5_VERS_MINOR > 8
) || ( H5_VERS_MAJOR == 1
&& H5_VERS_MINOR == 8
&& H5_VERS_RELEASE >= 7
) ) 182 exportJacobianToHDF5();
189 save ( M_subiterationsMaximumNumber, M_couplingResiduals->norm2() );
191 multiscaleErrorCheck ( Tolerance,
"Broyden algorithm residual: " + number2string ( M_couplingResiduals->norm2() ) +
192 " (required: " + number2string ( M_tolerance ) +
")\n", M_multiscale->communicator() == 0 );
196 MultiscaleAlgorithmBroyden::showMe()
198 if ( M_comm->MyPID() == 0 )
200 multiscaleAlgorithm_Type::showMe();
202 std::cout <<
"Initialize as identity matrix = " << M_initializeAsIdentityMatrix << std::endl;
203 std::cout <<
"Reset limit = " << M_iterationsLimitForReset << std::endl;
204 std::cout <<
"Enable orthogonalization = " << M_orthogonalization << std::endl;
205 std::cout <<
"Orthogonalization memory size = " << M_orthogonalizationSize << std::endl;
206 std::cout << std::endl << std::endl;
214 MultiscaleAlgorithmBroyden::setAlgorithmParameters (
const multiscaleParameterList_Type& parameterList )
216 multiscaleAlgorithm_Type::setAlgorithmParameters ( parameterList );
218 M_initializeAsIdentityMatrix = parameterList.get<
bool> (
"Initialize as identity matrix" );
219 M_iterationsLimitForReset =
static_cast <UInt> ( M_subiterationsMaximumNumber
220 * parameterList.get<Real> (
"Iterations limit for reset" ) );
222 M_orthogonalization = parameterList.get<
bool> (
"Orthogonalization" );
223 M_orthogonalizationSize = parameterList.get<UInt> (
"Orthogonalization size" );
230 MultiscaleAlgorithmBroyden::assembleJacobianMatrix()
233 M_jacobian.reset (
new multiscaleMatrix_Type ( M_couplingVariables->map(), 50 ) );
235 if ( M_initializeAsIdentityMatrix )
237 M_jacobian->insertValueDiagonal ( 1 );
241 M_multiscale->exportJacobian ( *M_jacobian );
244 M_jacobian->globalAssemble();
249 M_orthogonalizationContainer.clear();
253 MultiscaleAlgorithmBroyden::broydenJacobianUpdate (
const multiscaleVector_Type& delta )
255 M_jacobian->openCrsMatrix();
258 if ( M_orthogonalization )
261 multiscaleVector_Type orthogonalization ( delta, Unique );
262 for ( containerIterator_Type i = M_orthogonalizationContainer.begin(); i != M_orthogonalizationContainer.end() ; ++i )
264 orthogonalization -= orthogonalization.dot ( *i ) * *i;
266 orthogonalization /= orthogonalization.norm2();
269 orthogonalizationUpdate ( delta );
272 M_jacobian->addDyadicProduct ( ( *M_couplingResiduals ) / orthogonalization.dot ( delta ), orthogonalization );
278 M_jacobian->addDyadicProduct ( ( *M_couplingResiduals ) / delta.dot ( delta ), delta );
281 M_jacobian->globalAssemble();
287 MultiscaleAlgorithmBroyden::orthogonalizationUpdate (
const multiscaleVector_Type& delta )
289 if ( M_orthogonalizationContainer.size() < M_orthogonalizationSize )
291 M_orthogonalizationContainer.push_back ( delta );
295 M_orthogonalizationContainer.pop_front();
296 M_orthogonalizationContainer.push_back ( delta );
303 MultiscaleAlgorithmBroyden::exportJacobianToHDF5()
306 if ( M_couplingVariables->size() == 0 )
311 if ( M_multiscale->globalData()->dataTime()->timeStepNumber() % multiscaleSaveEachNTimeSteps == 0 || M_multiscale->globalData()->dataTime()->isLastTimeStep() )
312 if ( M_jacobian.get() != nullptr )
314 if ( M_comm->MyPID() == 0 )
316 std::cout <<
" MS- Exporting Jacobian matrix ... " << std::flush;
319 LifeChrono exportJacobianChrono;
320 exportJacobianChrono.start();
322 M_jacobian->exportToHDF5 ( multiscaleProblemFolder + multiscaleProblemPrefix +
"_AlgorithmJacobian" +
"_" + number2string ( multiscaleProblemStep ), number2string ( M_multiscale->globalData()->dataTime()->timeStepNumber() ), M_truncate );
325 exportJacobianChrono.stop();
326 Real jacobianChrono ( exportJacobianChrono.globalDiff ( *M_comm ) );
327 if ( M_comm->MyPID() == 0 )
329 std::cout <<
"done in " << jacobianChrono <<
" s." << std::endl;
337 MultiscaleAlgorithmBroyden::importJacobianFromHDF5()
340 if ( M_couplingVariables->size() == 0 )
345 if ( M_comm->MyPID() == 0 )
347 std::cout <<
" MS- Importing Jacobian matrix " << std::flush;
350 LifeChrono importJacobianChrono;
351 importJacobianChrono.start();
353 M_jacobian.reset (
new multiscaleMatrix_Type ( M_couplingVariables->map(), 50 ) );
354 M_jacobian->importFromHDF5 ( multiscaleProblemFolder + multiscaleProblemPrefix +
"_AlgorithmJacobian" +
"_" + number2string ( multiscaleProblemStep - 1 ), number2string ( M_multiscale->globalData()->dataTime()->timeStepNumber() ) );
356 importJacobianChrono.stop();
357 Real jacobianChrono ( importJacobianChrono.globalDiff ( *M_comm ) );
358 if ( M_comm->MyPID() == 0 )
360 std::cout <<
"done in " << jacobianChrono <<
" s. (Time " << M_multiscale->globalData()->dataTime()->time() <<
", Iteration " << M_multiscale->globalData()->dataTime()->timeStepNumber() <<
")" << std::endl;
MultiscaleAlgorithmBroyden()
Constructor.
MultiscaleAlgorithm()
Constructor.
UInt M_iterationsLimitForReset
multiscaleMatrixPtr_Type M_jacobian
bool M_initializeAsIdentityMatrix
bool M_iterationsLimitReached
void importJacobianFromHDF5()
Import Jacobian matrix from an HDF5 file.
void setupData(const std::string &fileName)
Setup the data of the algorithm using a data file.
MultiscaleAlgorithm multiscaleAlgorithm_Type
container_Type M_orthogonalizationContainer
UInt M_orthogonalizationSize
LinearSolver::parameterListPtr_Type multiscaleParameterListPtr_Type