From d6284598cfb828b67a88e29c8e4070f5ca9fc578 Mon Sep 17 00:00:00 2001 From: Timo Koch <timo.koch@iws.uni-stuttgart.de> Date: Wed, 29 Jan 2020 14:13:19 +0100 Subject: [PATCH] [solver][istl] Rename GenericIstlBackend to IstlSolverFactoryBackend. Remove TypeTag alias. --- dumux/linear/CMakeLists.txt | 2 +- ...backend.hh => istlsolverfactorybackend.hh} | 61 +++++++++---------- test/freeflow/shallowwater/dambreak/main.cc | 18 +++++- .../richards/implicit/lens/main.cc | 19 +++++- 4 files changed, 61 insertions(+), 39 deletions(-) rename dumux/linear/{genericistlbackend.hh => istlsolverfactorybackend.hh} (87%) diff --git a/dumux/linear/CMakeLists.txt b/dumux/linear/CMakeLists.txt index 14e0505b49..f9ffe34368 100644 --- a/dumux/linear/CMakeLists.txt +++ b/dumux/linear/CMakeLists.txt @@ -2,7 +2,7 @@ install(FILES amgbackend.hh amgparallelhelpers.hh amgtraits.hh -genericistlbackend.hh +istlsolverfactorybackend.hh linearsolvertraits.hh linearsolveracceptsmultitypematrix.hh matrixconverter.hh diff --git a/dumux/linear/genericistlbackend.hh b/dumux/linear/istlsolverfactorybackend.hh similarity index 87% rename from dumux/linear/genericistlbackend.hh rename to dumux/linear/istlsolverfactorybackend.hh index f06f0e7d53..30862a982b 100644 --- a/dumux/linear/genericistlbackend.hh +++ b/dumux/linear/istlsolverfactorybackend.hh @@ -20,20 +20,15 @@ * \file * \ingroup Linear * \brief Provides a generic linear solver based on the ISTL that chooses the - * solver and preconditioner at runtime. Needs dune version 2.7.1 or - * higher + * solver and preconditioner at runtime */ -#ifndef DUMUX_GENERIC_ISTLBACKEND_HH -#define DUMUX_GENERIC_ISTLBACKEND_HH - -#include <dumux/linear/solver.hh> -#include <dumux/linear/amgtraits.hh> -#include <dumux/linear/amgparallelhelpers.hh> +#ifndef DUMUX_LINEAR_ISTL_SOLVERFACTORYBACKEND_HH +#define DUMUX_LINEAR_ISTL_SOLVERFACTORYBACKEND_HH +#include <dune/common/version.hh> #include <dune/common/parallel/mpihelper.hh> #include <dune/common/parametertree.hh> -#include <dune/common/parametertreeparser.hh> // preconditioners #include <dune/istl/preconditioners.hh> @@ -42,18 +37,24 @@ // solvers #include <dune/istl/solvers.hh> +#include <dumux/linear/solver.hh> +#include <dumux/linear/amgtraits.hh> +#include <dumux/linear/amgparallelhelpers.hh> + #if DUNE_VERSION_NEWER_REV(DUNE_ISTL,2,7,1) -namespace Dumux -{ +namespace Dumux { + /*! * \ingroup Linear - * \brief A linear solver using the ISTL solver factory + * \brief A linear solver using the dune-istl solver factory * allowing choosing the solver and preconditioner * at runtime. + * \note the solvers are configured via the input file + * \note Requires Dune version 2.7.1 or newer */ template <class Matrix, class Vector, class GridGeometry> -class GenericIstlBackend : public LinearSolver +class IstlSolverFactoryBackend : public LinearSolver { using GridView = typename GridGeometry::GridView; using AMGTraits = AmgTraits<Matrix, Vector, GridGeometry>; @@ -71,13 +72,14 @@ public: * * \param paramGroup the parameter group for parameter lookup */ - GenericIstlBackend(const std::string& paramGroup = "") - : firstCall_(true) + IstlSolverFactoryBackend(const std::string& paramGroup = "") + : firstCall_(true) { if (Dune::MPIHelper::getCollectiveCommunication().size() > 1) DUNE_THROW(Dune::InvalidStateException, "Using sequential constructor for parallel run. Use signature with gridView and dofMapper!"); convertParameterTree(paramGroup); } + /*! * \brief Construct the backend for parallel or sequential runs * @@ -85,14 +87,15 @@ public: * \param dofMapper an index mapper for dof entities * \param paramGroup the parameter group for parameter lookup */ - GenericIstlBackend(const GridView& gridView, - const DofMapper& dofMapper, - const std::string& paramGroup = "") - : phelper_(std::make_shared<ParallelISTLHelper<GridView, AMGTraits>>(gridView, dofMapper)) - , firstCall_(true) + IstlSolverFactoryBackend(const GridView& gridView, + const DofMapper& dofMapper, + const std::string& paramGroup = "") + : phelper_(std::make_shared<ParallelISTLHelper<GridView, AMGTraits>>(gridView, dofMapper)) + , firstCall_(true) { convertParameterTree(paramGroup); } + /*! * \brief Solve a linear system. * @@ -221,7 +224,7 @@ private: }; template<class Matrix, class Vector, class Geometry> -std::vector<std::array<std::string,2> > GenericIstlBackend<Matrix, Vector, Geometry>::istl2DumuxSolverParams = +std::vector<std::array<std::string,2> > IstlSolverFactoryBackend<Matrix, Vector, Geometry>::istl2DumuxSolverParams = { {"verbose", "Verbosity"}, {"maxit", "MaxIterations"}, {"reduction", "ResidualReduction"}, {"type", "Type"}, @@ -231,7 +234,7 @@ std::vector<std::array<std::string,2> > GenericIstlBackend<Matrix, Vector, Geome }; template<class Matrix, class Vector, class Geometry> -std::vector<std::array<std::string,2> > GenericIstlBackend<Matrix, Vector, Geometry>::istl2DumuxPreconditionerParams = +std::vector<std::array<std::string,2> > IstlSolverFactoryBackend<Matrix, Vector, Geometry>::istl2DumuxPreconditionerParams = { {"verbosity", "PreconditionerVerbosity"}, {"type", "PreconditionerType"}, {"iterations", "PreconditionerIterations"}, {"relaxation", "PreconditionerRelaxation"}, @@ -253,17 +256,9 @@ std::vector<std::array<std::string,2> > GenericIstlBackend<Matrix, Vector, Geome {"maxAggregateSize", "MaxAggregateSize"} }; -template<class TypeTag> -using IstlSolverBackend = GenericIstlBackend< - GetPropType<TypeTag, Properties::JacobianMatrix>, - GetPropType<TypeTag, Properties::SolutionVector>, - GetPropType<TypeTag, Properties::GridGeometry>>; } // end namespace Dumux + #else -#warn "Generic ISTL backend needs dune-istl > 2.7.0!" -#warn "Ignoring configuration parameters and falling back to AMG backend." -#include "amgbackend.hh" -template<class TypeTag> -using IstlSolverBackend = AMGBackend<TypeTag>; +#warning "Generic dune-istl solver factory backend needs dune-istl >= 2.7.1!" #endif // DUNE version check -#endif // DUMUX_GENERIC_ISTLBACKEND_HH +#endif // header guard diff --git a/test/freeflow/shallowwater/dambreak/main.cc b/test/freeflow/shallowwater/dambreak/main.cc index 6c0fbb1219..7b3d94b4f5 100644 --- a/test/freeflow/shallowwater/dambreak/main.cc +++ b/test/freeflow/shallowwater/dambreak/main.cc @@ -27,6 +27,7 @@ #include <ctime> #include <iostream> +#include <dune/common/version.hh> #include <dune/common/parallel/mpihelper.hh> #include <dune/common/timer.hh> #include <dune/grid/io/file/dgfparser/dgfexception.hh> @@ -39,7 +40,14 @@ #include <dumux/common/dumuxmessage.hh> #include <dumux/io/grid/gridmanager.hh> -#include <dumux/linear/genericistlbackend.hh> + +#include <dumux/linear/linearsolvertraits.hh> + +#if DUNE_VERSION_NEWER_REV(DUNE_ISTL,2,7,1) +#include <dumux/linear/istlsolverfactorybackend.hh> +#else +#include <dumux/linear/amgbackend.hh> +#endif #include <dumux/nonlinear/newtonsolver.hh> @@ -123,7 +131,13 @@ int main(int argc, char** argv) try auto assembler = std::make_shared<Assembler>(problem, gridGeometry, gridVariables, timeLoop, xOld); // the linear solver - using LinearSolver = Dumux::IstlSolverBackend<TypeTag>; +#if DUNE_VERSION_NEWER_REV(DUNE_ISTL,2,7,1) + using Matrix = GetPropType<TypeTag, Properties::JacobianMatrix>; + using Vector = Dune::BlockVector<Dune::FieldVector<typename SolutionVector::block_type::value_type, SolutionVector::block_type::dimension>>; + using LinearSolver = IstlSolverFactoryBackend<Matrix, Vector, GridGeometry>; +#else + using LinearSolver = AMGBiCGSTABBackend<LinearSolverTraits<GridGeometry>>; +#endif auto linearSolver = std::make_shared<LinearSolver>(leafGridView, gridGeometry->dofMapper()); // the non-linear solver diff --git a/test/porousmediumflow/richards/implicit/lens/main.cc b/test/porousmediumflow/richards/implicit/lens/main.cc index 1a095ab1d6..bb5251ec2a 100644 --- a/test/porousmediumflow/richards/implicit/lens/main.cc +++ b/test/porousmediumflow/richards/implicit/lens/main.cc @@ -27,6 +27,7 @@ #include <ctime> #include <iostream> +#include <dune/common/version.hh> #include <dune/common/parallel/mpihelper.hh> #include <dune/common/timer.hh> #include <dune/grid/io/file/dgfparser/dgfexception.hh> @@ -37,10 +38,15 @@ #include <dumux/common/parameters.hh> #include <dumux/common/valgrind.hh> #include <dumux/common/dumuxmessage.hh> +#include <dumux/linear/linearsolvertraits.hh> -#include <dumux/linear/genericistlbackend.hh> -#include <dumux/porousmediumflow/richards/newtonsolver.hh> +#if DUNE_VERSION_NEWER_REV(DUNE_ISTL,2,7,1) +#include <dumux/linear/istlsolverfactorybackend.hh> +#else +#include <dumux/linear/amgbackend.hh> +#endif +#include <dumux/porousmediumflow/richards/newtonsolver.hh> #include <dumux/assembly/fvassembler.hh> #include <dumux/io/vtkoutputmodule.hh> @@ -143,7 +149,14 @@ int main(int argc, char** argv) try auto assembler = std::make_shared<Assembler>(problem, gridGeometry, gridVariables, timeLoop, xOld); // the linear solver - using LinearSolver = Dumux::GenericIstlBackend<TypeTag>; +#if DUNE_VERSION_NEWER_REV(DUNE_ISTL,2,7,1) + using Matrix = GetPropType<TypeTag, Properties::JacobianMatrix>; + using Vector = Dune::BlockVector<Dune::FieldVector<typename SolutionVector::block_type::value_type, SolutionVector::block_type::dimension>>; + using LinearSolver = IstlSolverFactoryBackend<Matrix, Vector, GridGeometry>; +#else + using LinearSolver = AMGBiCGSTABBackend<LinearSolverTraits<GridGeometry>>; +#endif + auto linearSolver = std::make_shared<LinearSolver>(leafGridView, gridGeometry->dofMapper()); // the non-linear solver -- GitLab