3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
traits.hh
Go to the documentation of this file.
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*****************************************************************************
4 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
25#ifndef DUMUX_MULTIDOMAIN_TRAITS_HH
26#define DUMUX_MULTIDOMAIN_TRAITS_HH
27
28#include <type_traits>
29#include <tuple>
30#include <utility>
31#include <memory>
32
33#include <dune/common/fmatrix.hh>
34#include <dune/common/indices.hh>
35
36#include <dune/istl/bcrsmatrix.hh>
37#include <dune/istl/multitypeblockvector.hh>
38#include <dune/istl/multitypeblockmatrix.hh>
39
43
44namespace Dumux {
45
46namespace Detail {
47
49template<class Scalar, class... JacobianBlocks>
51{
53 template<bool...> struct boolPack;
54 template<bool... bools>
55 using all_true = std::is_same<boolPack<bools..., true>, boolPack<true, bools...>>;
56
57 static_assert(all_true<isBCRSMatrix<JacobianBlocks>::value...>::value, "Jacobian blocks have to be BCRSMatrices!");
58
59 template<std::size_t id>
60 using JacobianDiagBlock = typename std::tuple_element_t<id, std::tuple<JacobianBlocks...>>;
61
62 template<std::size_t id>
63 static constexpr decltype(auto) numEq()
64 { return JacobianDiagBlock<id>::block_type::rows; }
65
66 template <std::size_t id, class I> struct makeRow;
67
68 template <std::size_t id, std::size_t... Is>
69 struct makeRow<id, std::index_sequence<Is...>>
70 {
71 using type = Dune::MultiTypeBlockVector<Dune::BCRSMatrix<Dune::FieldMatrix<Scalar, numEq<id>(), numEq<Is>()>>...>;
72 };
73
74 template <class I> struct makeMatrix;
75
76 template <std::size_t... Is>
77 struct makeMatrix<std::index_sequence<Is...>>
78 {
79 using type = Dune::MultiTypeBlockMatrix<typename makeRow<Is, std::index_sequence<Is...>>::type...>;
80 };
81
82 using Indices = std::index_sequence_for<JacobianBlocks...>;
83public:
84 using type = typename makeMatrix<Indices>::type;
85};
86
88template<template<std::size_t> class T, class Indices>
90{
91 template<std::size_t i>
92 using PtrType = std::shared_ptr<T<i>>;
93
95};
96
98template<template<std::size_t> class T, class Indices>
100{
101 template<std::size_t i>
102 using PtrType = std::shared_ptr<const T<i>>;
103
105};
106
108template<template<std::size_t> class SubDomainDiagBlocks, class Indices, class Scalar>
110{
111 template<typename... MatrixBlocks>
112 using M = typename createMultiTypeBlockMatrixType<Scalar, MatrixBlocks...>::type::type;
113
115};
116
117} // end namespace Detail
118
119/*
120 * \ingroup MultiDomain
121 * \brief A traits class every multidomain model has to provide
122 * \tparam SubDomainTypeTags the TypeTags of the sub domain problems
123 * \note should export the types
124 * \code
125 * //! the type tag of the sub domain problem with id
126 * template<std::size_t id>
127 * using SubDomainTypeTag = ...
128 *
129 * //! the index to access sub domain matrices and vectors
130 * //! to use with multitype matrices and vectors
131 * template<std::size_t id>
132 * using DomainIdx = ...
133 *
134 * //! the scalar type
135 * using Scalar = ...
136 *
137 * //! the solution vector type
138 * using SolutionVector = ...
139 *
140 * //! the jacobian type
141 * using JacobianMatrix = ...
142 * \endcode
143 */
144template<typename... SubDomainTypeTags>
146{
148 static constexpr std::size_t numSubDomains = sizeof...(SubDomainTypeTags);
149
150private:
151
153 template<std::size_t id>
154 using SubDomainTypeTag = typename std::tuple_element_t<id, std::tuple<SubDomainTypeTags...>>;
155
157 using Indices = std::make_index_sequence<numSubDomains>;
158
160 template<std::size_t id>
162
164 template<std::size_t id>
165 using SubDomainJacobianMatrix = GetPropType<SubDomainTypeTag<id>, Properties::JacobianMatrix>;
166
168 template<std::size_t id>
169 using SubDomainSolutionVector = GetPropType<SubDomainTypeTag<id>, Properties::SolutionVector>;
170
171public:
172
173 /*
174 * \brief sub domain types
175 */
176 //\{
177
178 template<std::size_t id>
180 {
181 using Index = Dune::index_constant<id>;
182 using TypeTag = SubDomainTypeTag<id>;
185 using FVGridGeometry [[deprecated("Use GridGeometry instead. FVGridGeometry will be removed after 3.1!")]] = GridGeometry;
190 };
191
192 //\}
193
194 /*
195 * \brief multi domain types
196 */
197 //\{
198
201
204
207
208 //\}
209
210 /*
211 * \brief helper aliases to contruct derived tuple types
212 */
213 //\{
214
216 template<template<std::size_t> class T>
218
220 template<template<std::size_t> class T>
222
224 template<template<std::size_t> class T>
226
227 //\}
228};
229
230} //end namespace Dumux
231
232#endif
Type traits to be used with matrix types.
Utilities for template meta programming.
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
Property tag Indices
Definition: porousmediumflow/sequential/properties.hh:59
Property to specify the type of scalar values.
Definition: common/properties.hh:53
The DUNE grid type.
Definition: common/properties.hh:57
Property to specify the type of a problem which has to be solved.
Definition: common/properties.hh:69
A class helping models to define input and output fields.
Definition: common/properties.hh:78
Type of the global jacobian matrix.
Definition: common/properties.hh:82
Vector containing all primary variable vector of the grid.
Definition: common/properties.hh:84
Definition: common/properties.hh:150
The grid variables object managing variable data on the grid (volvars/fluxvars cache)
Definition: common/properties.hh:190
Definition: utility.hh:40
a helper class to create a multitype matrix given the diagonal matrix blocks
Definition: traits.hh:51
typename makeMatrix< Indices >::type type
Definition: traits.hh:84
helper alias to create a tuple of shared_ptr<...> from an indexed type
Definition: traits.hh:90
typename makeFromIndexedType< std::tuple, PtrType, Indices >::type type
Definition: traits.hh:94
std::shared_ptr< T< i > > PtrType
Definition: traits.hh:92
helper alias to create a tuple of shared_ptr<const ...> from an indexed type
Definition: traits.hh:100
typename makeFromIndexedType< std::tuple, PtrType, Indices >::type type
Definition: traits.hh:104
std::shared_ptr< const T< i > > PtrType
Definition: traits.hh:102
helper alias to create the JacobianMatrix type
Definition: traits.hh:110
typename createMultiTypeBlockMatrixType< Scalar, MatrixBlocks... >::type::type M
Definition: traits.hh:112
typename makeFromIndexedType< M, SubDomainDiagBlocks, Indices >::type type
Definition: traits.hh:114
Definition: traits.hh:146
static constexpr std::size_t numSubDomains
the number of subdomains
Definition: traits.hh:148
typename makeFromIndexedType< std::common_type_t, SubDomainScalar, Indices >::type Scalar
the scalar type
Definition: traits.hh:200
typename makeFromIndexedType< Dune::MultiTypeBlockVector, SubDomainSolutionVector, Indices >::type SolutionVector
the solution vector type
Definition: traits.hh:203
typename Detail::MultiDomainTupleSharedPtr< T, Indices >::type TupleOfSharedPtr
helper alias to create tuple<std::shared_ptr<...>> from indexed type
Definition: traits.hh:221
typename makeFromIndexedType< std::tuple, T, Indices >::type Tuple
helper alias to create tuple<...> from indexed type
Definition: traits.hh:217
typename Detail::MultiDomainMatrixType< SubDomainJacobianMatrix, Indices, Scalar >::type JacobianMatrix
the jacobian type
Definition: traits.hh:206
typename Detail::MultiDomainTupleSharedPtrConst< T, Indices >::type TupleOfSharedPtrConst
helper alias to create tuple<std::shared_ptr<const ...>> from indexed type
Definition: traits.hh:225
Definition: traits.hh:180
GetPropType< SubDomainTypeTag< id >, Properties::GridGeometry > GridGeometry
Definition: traits.hh:184
SubDomainTypeTag< id > TypeTag
Definition: traits.hh:182
Dune::index_constant< id > Index
Definition: traits.hh:181
GetPropType< SubDomainTypeTag< id >, Properties::IOFields > IOFields
Definition: traits.hh:188
GetPropType< SubDomainTypeTag< id >, Properties::Problem > Problem
Definition: traits.hh:186
GetPropType< SubDomainTypeTag< id >, Properties::GridVariables > GridVariables
Definition: traits.hh:187
GetPropType< SubDomainTypeTag< id >, Properties::Grid > Grid
Definition: traits.hh:183
GridGeometry FVGridGeometry
Definition: traits.hh:185
GetPropType< SubDomainTypeTag< id >, Properties::SolutionVector > SolutionVector
Definition: traits.hh:189
Declares all properties used in Dumux.