From 0b33e20a8b02cd8a5e58efa8cddb9f2b1c83c7ae Mon Sep 17 00:00:00 2001 From: Kilian Weishaupt <kilian.weishaupt@iws.uni-stuttgart.de> Date: Tue, 30 Jan 2018 16:44:10 +0100 Subject: [PATCH] [linearSolver] Add typetraits classes and clean up --- dumux/common/typetraits/CMakeLists.txt | 5 +++ dumux/common/typetraits/matrix.hh | 40 ++++++++++++++++++ dumux/common/typetraits/vector.hh | 42 +++++++++++++++++++ .../linearsolveracceptsmultitypematrix.hh | 30 +++++-------- dumux/linear/seqsolverbackend.hh | 8 +--- dumux/nonlinear/staggerednewtoncontroller.hh | 2 +- 6 files changed, 99 insertions(+), 28 deletions(-) create mode 100644 dumux/common/typetraits/CMakeLists.txt create mode 100644 dumux/common/typetraits/matrix.hh create mode 100644 dumux/common/typetraits/vector.hh diff --git a/dumux/common/typetraits/CMakeLists.txt b/dumux/common/typetraits/CMakeLists.txt new file mode 100644 index 0000000000..41bd98a128 --- /dev/null +++ b/dumux/common/typetraits/CMakeLists.txt @@ -0,0 +1,5 @@ +#install headers +install(FILES +matrix.hh +vector.hh +DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dumux/common/typetraits) diff --git a/dumux/common/typetraits/matrix.hh b/dumux/common/typetraits/matrix.hh new file mode 100644 index 0000000000..b9e8361461 --- /dev/null +++ b/dumux/common/typetraits/matrix.hh @@ -0,0 +1,40 @@ +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +// vi: set et ts=4 sw=4 sts=4: +/***************************************************************************** + * See the file COPYING for full copying permissions. * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *****************************************************************************/ +/*! + * \file + * \ingroup Common + * \brief Type traits to be used with matrix types + */ +#ifndef DUMUX_TYPETRAITS_MATRIX_HH +#define DUMUX_TYPETRAITS_MATRIX_HH + +#include <type_traits> + +namespace Dumux { + +//! Helper type to determine whether a given type is a Dune::BCRSMatrix +template<class T> struct isBCRSMatrix : public std::false_type {}; + +//! Helper type to determine whether a given type is a Dune::BCRSMatrix +template<class T> +struct isBCRSMatrix<Dune::BCRSMatrix<T> > : public std::true_type {}; + +} // end namespace Dumux + +#endif diff --git a/dumux/common/typetraits/vector.hh b/dumux/common/typetraits/vector.hh new file mode 100644 index 0000000000..6f40116cb1 --- /dev/null +++ b/dumux/common/typetraits/vector.hh @@ -0,0 +1,42 @@ +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +// vi: set et ts=4 sw=4 sts=4: +/***************************************************************************** + * See the file COPYING for full copying permissions. * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *****************************************************************************/ +/*! + * \file + * \ingroup Common + * \brief Type traits to be used with vector types + */ +#ifndef DUMUX_TYPETRAITS_VECTOR_HH +#define DUMUX_TYPETRAITS_VECTOR_HH + +#include <type_traits> +#include <dune/istl/multitypeblockvector.hh> + + +namespace Dumux { + + //! Helper type to determine whether a given type is a Dune::MultiTypeBlockVector + template<class T> struct isMultiTypeBlockVector : public std::false_type {}; + + //! Helper type to determine whether a given type is a Dune::MultiTypeBlockVector + template<class... T> + struct isMultiTypeBlockVector<Dune::MultiTypeBlockVector<T...> > : public std::true_type {}; + +} // end namespace Dumux + +#endif diff --git a/dumux/linear/linearsolveracceptsmultitypematrix.hh b/dumux/linear/linearsolveracceptsmultitypematrix.hh index da4058a4a5..3c98b4ccd3 100644 --- a/dumux/linear/linearsolveracceptsmultitypematrix.hh +++ b/dumux/linear/linearsolveracceptsmultitypematrix.hh @@ -29,49 +29,39 @@ namespace Dumux { //! The default -template<typename LinearSolver> -struct LinearSolverAcceptsMultiTypeMatrix -{ static constexpr bool value = true; }; - +template<class LinearSolver> +struct linearSolverAcceptsMultiTypeMatrix : public std::true_type {}; //! Solvers that don't accept multi-type matrices //! Those are all with ILU preconditioner that doesn't support the additional block level //! And the direct solvers that have BCRS Matrix hardcoded template<> -struct LinearSolverAcceptsMultiTypeMatrix<ILUnBiCGSTABBackend> -{ static constexpr bool value = false; }; +struct linearSolverAcceptsMultiTypeMatrix<ILUnBiCGSTABBackend> : public std::false_type {}; template<> -struct LinearSolverAcceptsMultiTypeMatrix<ILUnCGBackend> -{ static constexpr bool value = false; }; +struct linearSolverAcceptsMultiTypeMatrix<ILUnCGBackend> : public std::false_type {}; template<> -struct LinearSolverAcceptsMultiTypeMatrix<ILU0BiCGSTABBackend> -{ static constexpr bool value = false; }; +struct linearSolverAcceptsMultiTypeMatrix<ILU0BiCGSTABBackend> : public std::false_type {}; template<> -struct LinearSolverAcceptsMultiTypeMatrix<ILU0CGBackend> -{ static constexpr bool value = false; }; +struct linearSolverAcceptsMultiTypeMatrix<ILU0CGBackend> : public std::false_type {}; template<> -struct LinearSolverAcceptsMultiTypeMatrix<ILU0RestartedGMResBackend> -{ static constexpr bool value = false; }; +struct linearSolverAcceptsMultiTypeMatrix<ILU0RestartedGMResBackend> : public std::false_type {}; template<> -struct LinearSolverAcceptsMultiTypeMatrix<ILUnRestartedGMResBackend> -{ static constexpr bool value = false; }; +struct linearSolverAcceptsMultiTypeMatrix<ILUnRestartedGMResBackend> : public std::false_type {}; #if HAVE_SUPERLU template<> -struct LinearSolverAcceptsMultiTypeMatrix<SuperLUBackend> -{ static constexpr bool value = false; }; +struct linearSolverAcceptsMultiTypeMatrix<SuperLUBackend> : public std::false_type {}; #endif // HAVE_SUPERLU #if HAVE_UMFPACK template<> -struct LinearSolverAcceptsMultiTypeMatrix<UMFPackBackend> -{ static constexpr bool value = false; }; +struct linearSolverAcceptsMultiTypeMatrix<UMFPackBackend> : public std::false_type {}; #endif // HAVE_UMFPACK } // end namespace Dumux diff --git a/dumux/linear/seqsolverbackend.hh b/dumux/linear/seqsolverbackend.hh index 867b528f7d..bab4fb229b 100644 --- a/dumux/linear/seqsolverbackend.hh +++ b/dumux/linear/seqsolverbackend.hh @@ -34,18 +34,12 @@ #include <dumux/common/parameters.hh> #include <dumux/common/properties.hh> +#include <dumux/common/typetraits/matrix.hh> #include <dumux/linear/solver.hh> namespace Dumux { -//! Helper type to determine whether a given type is a Dune::BCRSMatrix -template<class T> struct isBCRSMatrix : public std::false_type {}; - -//! Helper type to determine whether a given type is a Dune::BCRSMatrix -template<class T> -struct isBCRSMatrix<Dune::BCRSMatrix<T> > : public std::true_type {}; - /*! * \ingroup Linear * \brief A general solver backend allowing arbitrary preconditioners and solvers. diff --git a/dumux/nonlinear/staggerednewtoncontroller.hh b/dumux/nonlinear/staggerednewtoncontroller.hh index 0d197727b0..634475d351 100644 --- a/dumux/nonlinear/staggerednewtoncontroller.hh +++ b/dumux/nonlinear/staggerednewtoncontroller.hh @@ -90,7 +90,7 @@ public: // solve by calling the appropriate implementation depending on whether the linear solver // is capable of handling MultiType matrices or not bool converged = solveLinearSystem_(ls, A, x, b, - std::integral_constant<bool, LinearSolverAcceptsMultiTypeMatrix<LinearSolver>::value>()); + std::integral_constant<bool, linearSolverAcceptsMultiTypeMatrix<LinearSolver>::value>()); // make sure all processes converged int convergedRemote = converged; -- GitLab