From ed1d34ea5e900c638eed456e711ae1a36d1ec99d Mon Sep 17 00:00:00 2001 From: Kilian <kilian.weishaupt@iws.uni-stuttgart.de> Date: Wed, 3 Jun 2020 17:09:58 +0200 Subject: [PATCH] [typetraits] Add problem traits header and add specialization in disc headers --- dumux/common/typetraits/problem.hh | 51 ++++++++++++++++++++++++++++++ dumux/discretization/box.hh | 19 +++++++++++ dumux/discretization/ccmpfa.hh | 19 +++++++++++ dumux/discretization/cctpfa.hh | 19 +++++++++++ dumux/discretization/staggered.hh | 19 +++++++++++ 5 files changed, 127 insertions(+) create mode 100644 dumux/common/typetraits/problem.hh diff --git a/dumux/common/typetraits/problem.hh b/dumux/common/typetraits/problem.hh new file mode 100644 index 0000000000..c6aa0257ba --- /dev/null +++ b/dumux/common/typetraits/problem.hh @@ -0,0 +1,51 @@ +// -*- 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 3 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 Typetraits + * \brief Type traits for problem classes + */ +#ifndef DUMUX_TYPETRAITS_PROBLEM_HH +#define DUMUX_TYPETRAITS_PROBLEM_HH + +#include <type_traits> +#include <dumux/discretization/method.hh> + +namespace Dumux { + +// forward declare +namespace Impl { +template<class Problem, DiscretizationMethod dm> +struct ProblemTraits; +} // end namespace Impl + +/*! + * \ingroup Common + * \brief Type traits for problem classes. + */ +template<class Problem> +struct ProblemTraits +{ + using GridGeometry = std::decay_t<decltype(std::declval<Problem>().gridGeometry())>; + using BoundaryTypes = typename Impl::template ProblemTraits<Problem, GridGeometry::discMethod>::BoundaryTypes; +}; + +} // end namespace Dumux + +#endif diff --git a/dumux/discretization/box.hh b/dumux/discretization/box.hh index a9df7e72d9..db4a299607 100644 --- a/dumux/discretization/box.hh +++ b/dumux/discretization/box.hh @@ -30,6 +30,7 @@ #include <dumux/common/properties.hh> #include <dumux/common/boundaryflag.hh> +#include <dumux/common/typetraits/problem.hh> #include <dumux/assembly/boxlocalresidual.hh> @@ -96,6 +97,24 @@ template<class TypeTag> struct BaseLocalResidual<TypeTag, TTag::BoxModel> { using type = BoxLocalResidual<TypeTag>; }; } // namespace Properties + +namespace Impl { + +template<class Problem> +struct ProblemTraits<Problem, DiscretizationMethod::box> +{ +private: + using GG = std::decay_t<decltype(std::declval<Problem>().gridGeometry())>; + using Element = typename GG::GridView::template Codim<0>::Entity; + using SubControlVolume = typename GG::SubControlVolume; +public: + using GridGeometry = GG; + // BoundaryTypes is whatever the problem returns from boundaryTypes(element, scv) + using BoundaryTypes = std::decay_t<decltype(std::declval<Problem>().boundaryTypes(std::declval<Element>(), std::declval<SubControlVolume>()))>; +}; + +} // end namespace Impl + } // namespace Dumux #endif diff --git a/dumux/discretization/ccmpfa.hh b/dumux/discretization/ccmpfa.hh index 0abdf72c34..b457451f83 100644 --- a/dumux/discretization/ccmpfa.hh +++ b/dumux/discretization/ccmpfa.hh @@ -29,6 +29,7 @@ #include <dumux/common/properties.hh> #include <dumux/common/defaultmappertraits.hh> +#include <dumux/common/typetraits/problem.hh> #include <dumux/assembly/cclocalresidual.hh> @@ -158,6 +159,24 @@ struct ElementBoundaryTypes<TypeTag, TTag::CCMpfaModel> { using type = CCElement template<class TypeTag> struct BaseLocalResidual<TypeTag, TTag::CCMpfaModel> { using type = CCLocalResidual<TypeTag>; }; } // namespace Properties + +namespace Impl { + +template<class Problem> +struct ProblemTraits<Problem, DiscretizationMethod::ccmpfa> +{ +private: + using GG = std::decay_t<decltype(std::declval<Problem>().gridGeometry())>; + using Element = typename GG::GridView::template Codim<0>::Entity; + using SubControlVolumeFace = typename GG::SubControlVolumeFace; +public: + using GridGeometry = GG; + // BoundaryTypes is whatever the problem returns from boundaryTypes(element, scvf) + using BoundaryTypes = std::decay_t<decltype(std::declval<Problem>().boundaryTypes(std::declval<Element>(), std::declval<SubControlVolumeFace>()))>; +}; + +} // end namespace Impl + } // namespace Dumux #endif diff --git a/dumux/discretization/cctpfa.hh b/dumux/discretization/cctpfa.hh index b1c17411d5..bbce1cd7ad 100644 --- a/dumux/discretization/cctpfa.hh +++ b/dumux/discretization/cctpfa.hh @@ -28,6 +28,7 @@ #include <dumux/common/properties.hh> #include <dumux/common/boundaryflag.hh> +#include <dumux/common/typetraits/problem.hh> #include <dumux/assembly/cclocalresidual.hh> @@ -94,6 +95,24 @@ struct ElementBoundaryTypes<TypeTag, TTag::CCTpfaModel> { using type = CCElement template<class TypeTag> struct BaseLocalResidual<TypeTag, TTag::CCTpfaModel> { using type = CCLocalResidual<TypeTag>; }; } // namespace Properties + +namespace Impl { + +template<class Problem> +struct ProblemTraits<Problem, DiscretizationMethod::cctpfa> +{ +private: + using GG = std::decay_t<decltype(std::declval<Problem>().gridGeometry())>; + using Element = typename GG::GridView::template Codim<0>::Entity; + using SubControlVolumeFace = typename GG::SubControlVolumeFace; +public: + using GridGeometry = GG; + // BoundaryTypes is whatever the problem returns from boundaryTypes(element, scvf) + using BoundaryTypes = std::decay_t<decltype(std::declval<Problem>().boundaryTypes(std::declval<Element>(), std::declval<SubControlVolumeFace>()))>; +}; + +} // end namespace Impl + } // namespace Dumux #endif diff --git a/dumux/discretization/staggered.hh b/dumux/discretization/staggered.hh index ca73668c30..b07c3ac683 100644 --- a/dumux/discretization/staggered.hh +++ b/dumux/discretization/staggered.hh @@ -28,6 +28,7 @@ #define DUMUX_DISCRETIZATION_STAGGERD_HH #include <dumux/common/properties.hh> +#include <dumux/common/typetraits/problem.hh> #include <dumux/discretization/method.hh> #include <dumux/discretization/fvproperties.hh> @@ -199,6 +200,24 @@ public: }; } // namespace Properties + +namespace Impl { + +template<class Problem> +struct ProblemTraits<Problem, DiscretizationMethod::staggered> +{ +private: + using GG = std::decay_t<decltype(std::declval<Problem>().gridGeometry())>; + using Element = typename GG::GridView::template Codim<0>::Entity; + using SubControlVolumeFace = typename GG::SubControlVolumeFace; +public: + using GridGeometry = GG; + // BoundaryTypes is whatever the problem returns from boundaryTypes(element, scvf) + using BoundaryTypes = std::decay_t<decltype(std::declval<Problem>().boundaryTypes(std::declval<Element>(), std::declval<SubControlVolumeFace>()))>; +}; + +} // end namespace Impl + } // namespace Dumux #endif -- GitLab