From 9eaaef4d153fda65a9de9bc476c51f700c7641a4 Mon Sep 17 00:00:00 2001 From: Christoph Lehmann <christoph.lehmann@ufz.de> Date: Fri, 19 Aug 2016 10:50:56 +0200 Subject: [PATCH] [NL] added conv crit interface --- NumLib/ODESolver/ConvergenceCriterion.cpp | 34 +++++++++++ NumLib/ODESolver/ConvergenceCriterion.h | 71 +++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 NumLib/ODESolver/ConvergenceCriterion.cpp create mode 100644 NumLib/ODESolver/ConvergenceCriterion.h diff --git a/NumLib/ODESolver/ConvergenceCriterion.cpp b/NumLib/ODESolver/ConvergenceCriterion.cpp new file mode 100644 index 00000000000..74b5cf521ff --- /dev/null +++ b/NumLib/ODESolver/ConvergenceCriterion.cpp @@ -0,0 +1,34 @@ +/** + * \copyright + * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#include "ConvergenceCriterion.h" +#include "BaseLib/ConfigTree.h" +#include "BaseLib/Error.h" + +#include "ConvergenceCriterionDeltaX.h" +#include "ConvergenceCriterionPerComponentDeltaX.h" + +namespace NumLib +{ +std::unique_ptr<ConvergenceCriterion> createConvergenceCriterion( + const BaseLib::ConfigTree& config) +{ + //! \ogs_file_param{process__convergence_criterion__type} + auto const type = config.peekConfigParameter<std::string>("type"); + + if (type == "DeltaX") { + return createConvergenceCriterionDeltaX(config); + } else if (type == "PerComponentDeltaX") { + return createConvergenceCriterionPerComponentDeltaX(config); + } + + OGS_FATAL("There is no convergence criterion of type `%s'.", type.c_str()); +} + +} // NumLib diff --git a/NumLib/ODESolver/ConvergenceCriterion.h b/NumLib/ODESolver/ConvergenceCriterion.h new file mode 100644 index 00000000000..79e1a6333c2 --- /dev/null +++ b/NumLib/ODESolver/ConvergenceCriterion.h @@ -0,0 +1,71 @@ +/** + * \copyright + * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef NUMLIB_CONVERGENCECRITERION_H +#define NUMLIB_CONVERGENCECRITERION_H + +#include <memory> +#include "NumLib/NumericsConfig.h" + +namespace BaseLib { +class ConfigTree; +} // BaseLib + +namespace NumLib +{ +/*! Convergence criterion for nonlinear solvers. + * + * It is able to check the difference of the solution vector between iterations + * and the residual of the nonlinear equation system. + */ +class ConvergenceCriterion +{ +public: + //! Tells if the change of the solution between iterations is checked. + //! + //! \remark + //! This method allows to save some computations if no such check will be + //! done. + virtual bool hasDeltaXCheck() const = 0; + + //! Tells if the residual is checked. + //! + //! \remark + //! This method allows to save some computations if no such check will be + //! done. + virtual bool hasResidualCheck() const = 0; + + //! Check if the change of the solution between iterations satisfies the + //! convergence criterion. + //! + //! \remark + //! The Newton-Raphson solver computes \c minus_delta_x. \c x is needed for + //! relative tolerances. + virtual void checkDeltaX(GlobalVector const& minus_delta_x, + GlobalVector const& x) = 0; + + //! Check if the residual satisfies the convergence criterion. + virtual void checkResidual(GlobalVector const& residual) = 0; + + //! Indicate that a new iteration now starts. + virtual void reset() = 0; + + //! Tell if the convergence criterion is satisfied. + virtual bool isSatisfied() const = 0; + + ~ConvergenceCriterion() = default; +}; + +//! Creates a convergence criterion from the given configuration. +std::unique_ptr<ConvergenceCriterion> createConvergenceCriterion( + BaseLib::ConfigTree const& config); + +} // namespace NumLib + +#endif // NUMLIB_CONVERGENCECRITERION_H -- GitLab