16 std::vector<double>&& absolute_tolerances,
17 std::vector<double>&& relative_tolerances,
18 std::vector<double>&& damping_alpha,
19 bool damping_alpha_switch,
22 _abstols(std::move(absolute_tolerances)),
23 _reltols(std::move(relative_tolerances)),
31 "The number of absolute and relative tolerances given must be the "
37 OGS_FATAL(
"The given tolerances vector is empty.");
46 OGS_FATAL(
"D.o.f. table has not been set.");
49 for (
unsigned global_component = 0; global_component <
_abstols.size();
58 "Convergence criterion, component {:d}: |dx|={:.4e}, |x|={:.4e}, "
60 global_component, error_dx, norm_x,
61 (norm_x == 0. ? std::numeric_limits<double>::quiet_NaN()
62 : (error_dx / norm_x)));
71 OGS_FATAL(
"D.o.f. table has not been set.");
74 for (
unsigned global_component = 0; global_component <
_abstols.size();
83 INFO(
"Convergence criterion, component {:d}: |r0|={:.4e}",
84 global_component, norm_res);
91 "Convergence criterion, component {:d}: |r|={:.4e}, "
92 "|r0|={:.4e}, |r|/|r0|={:.4e}",
93 global_component, norm_res, norm_res0,
94 (norm_res0 == 0. ? std::numeric_limits<double>::quiet_NaN()
95 : (norm_res / norm_res0)));
98 bool const satisfied_abs = norm_res <
_abstols[global_component];
101 bool const satisfied_rel =
115 OGS_FATAL(
"D.o.f. table or mesh have not been set.");
119 double damping_final = 1;
120 for (
unsigned global_component = 0;
124 auto const& ms =
_dof_table->getMeshSubset(global_component);
125 assert(ms.getMeshID() ==
_mesh->getID());
126 DBUG(
"Non-negative damping for component: {:d} alpha: {:g}",
131 auto index =
_dof_table->getGlobalIndex(l, global_component);
132 damping_final = std::min(
134 damping_orig / std::max(1.0, (minus_delta_x.
get(index) *
139 DBUG(
"Final damping value due to non-negative damping: {:g}",
141 return damping_final;
150 if (
_dof_table->getNumberOfGlobalComponents() !=
154 "The number of components in the DOF table ({:d}) and the number "
155 "of tolerances given ({:d}) do not match.",
161std::unique_ptr<ConvergenceCriterionPerComponentResidual>
177 auto const norm_type_str =
181 bool damping_alpha_switch =
true;
182 if ((!abstols) && (!reltols))
185 "At least one of absolute or relative tolerance has to be "
190 abstols = std::vector<double>(reltols->size());
194 reltols = std::vector<double>(abstols->size());
198 damping_alpha = std::vector<double>(abstols->size(), 0.0);
199 damping_alpha_switch =
false;
206 OGS_FATAL(
"Unknown vector norm type `{:s}'.", norm_type_str);
209 return std::make_unique<ConvergenceCriterionPerComponentResidual>(
210 std::move(*abstols), std::move(*reltols), std::move(*damping_alpha),
211 damping_alpha_switch, norm_type);
MathLib::EigenVector GlobalVector
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
std::optional< T > getConfigParameterOptional(std::string const ¶m) const
T getConfigParameter(std::string const ¶m) const
void checkConfigParameter(std::string const ¶m, std::string_view const value) const
double get(IndexType rowId) const
get entry
const std::vector< double > _damping_alpha
ConvergenceCriterionPerComponentResidual(std::vector< double > &&absolute_tolerances, std::vector< double > &&relative_tolerances, std::vector< double > &&damping_alpha, bool daming_alpha_switch, const MathLib::VecNormType norm_type)
double getDampingFactor(GlobalVector const &minus_delta_x, GlobalVector const &x, double damping_orig) override
MeshLib::Mesh const * _mesh
void setDOFTable(const LocalToGlobalIndexMap &dof_table, MeshLib::Mesh const &mesh) override
Sets the d.o.f. table used to extract data for a specific component.
bool _damping_alpha_switch
const std::vector< double > _abstols
LocalToGlobalIndexMap const * _dof_table
void checkResidual(const GlobalVector &residual) override
Check if the residual satisfies the convergence criterion.
void checkDeltaX(const GlobalVector &minus_delta_x, GlobalVector const &x) override
std::vector< double > _residual_norms_0
const std::vector< double > _reltols
ConvergenceCriterionPerComponent(const MathLib::VecNormType norm_type)
const MathLib::VecNormType _norm_type
void setLocalAccessibleVector(PETScVector const &x)
VecNormType convertStringToVecNormType(const std::string &str)
convert string to VecNormType
auto meshLocations(Mesh const &mesh, MeshItemType const item_type)
bool checkRelativeTolerance(const double reltol, const double numerator, const double denominator)
std::unique_ptr< ConvergenceCriterionPerComponentResidual > createConvergenceCriterionPerComponentResidual(const BaseLib::ConfigTree &config)
double norm(GlobalVector const &x, unsigned const global_component, MathLib::VecNormType norm_type, LocalToGlobalIndexMap const &dof_table)