version 3.10-dev
multidomain/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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
13#ifndef DUMUX_MULTIDOMAIN_TRAITS_HH
14#define DUMUX_MULTIDOMAIN_TRAITS_HH
15
16#include <type_traits>
17#include <tuple>
18#include <utility>
19#include <memory>
20
21#include <dune/common/fmatrix.hh>
22#include <dune/common/indices.hh>
23
24#include <dune/istl/bcrsmatrix.hh>
25#include <dune/istl/multitypeblockvector.hh>
26#include <dune/istl/multitypeblockmatrix.hh>
27
31
33
34namespace Dumux {
35
36namespace Detail {
37
39template<class Scalar, class... JacobianBlocks>
41{
42 static_assert(std::conjunction_v<isBCRSMatrix<JacobianBlocks>...>, "Jacobian blocks have to be BCRSMatrices!");
43
44 template<std::size_t id>
45 using JacobianDiagBlock = typename std::tuple_element_t<id, std::tuple<JacobianBlocks...>>;
46
47 template<std::size_t id>
48 static constexpr decltype(auto) numEq()
49 { return JacobianDiagBlock<id>::block_type::rows; }
50
51 template <std::size_t id, class I> struct makeRow;
52
53 template <std::size_t id, std::size_t... Is>
54 struct makeRow<id, std::index_sequence<Is...>>
55 {
57 };
58
59 template <class I> struct makeMatrix;
60
61 template <std::size_t... Is>
62 struct makeMatrix<std::index_sequence<Is...>>
63 {
64 using type = Dune::MultiTypeBlockMatrix<typename makeRow<Is, std::index_sequence<Is...>>::type...>;
65 };
66
67 using Indices = std::index_sequence_for<JacobianBlocks...>;
68public:
69 using type = typename makeMatrix<Indices>::type;
70};
71
73template<template<std::size_t> class T, class Indices>
75{
76 template<std::size_t i>
77 using PtrType = std::shared_ptr<T<i>>;
78
80};
81
83template<template<std::size_t> class T, class Indices>
85{
86 template<std::size_t i>
87 using PtrType = std::shared_ptr<const T<i>>;
88
90};
91
93template<template<std::size_t> class SubDomainDiagBlocks, class Indices, class Scalar>
95{
96 template<typename... MatrixBlocks>
97 using M = typename createMultiTypeBlockMatrixType<Scalar, MatrixBlocks...>::type::type;
98
100};
101
102} // end namespace Detail
103
104/*
105 * \ingroup MultiDomain
106 * \brief A traits class every multidomain model has to provide
107 * \tparam SubDomainTypeTags the TypeTags of the sub domain problems
108 * \note should export the types
109 * \code
110 * //! the type tag of the sub domain problem with id
111 * template<std::size_t id>
112 * using SubDomainTypeTag = ...
113 *
114 * //! the index to access sub domain matrices and vectors
115 * //! to use with multitype matrices and vectors
116 * template<std::size_t id>
117 * using DomainIdx = ...
118 *
119 * //! the scalar type
120 * using Scalar = ...
121 *
122 * //! the solution vector type
123 * using SolutionVector = ...
124 *
125 * //! the residual vector type
126 * using ResidualVector = ...
127 *
128 * //! the jacobian type
129 * using JacobianMatrix = ...
130 * \endcode
131 */
132template<typename... SubDomainTypeTags>
134{
136 static constexpr std::size_t numSubDomains = sizeof...(SubDomainTypeTags);
137
138private:
139
141 template<std::size_t id>
142 using SubDomainTypeTag = typename std::tuple_element_t<id, std::tuple<SubDomainTypeTags...>>;
143
145 using Indices = std::make_index_sequence<numSubDomains>;
146
148 template<std::size_t id>
149 using SubDomainScalar = GetPropType<SubDomainTypeTag<id>, Properties::Scalar>;
150
152 template<std::size_t id>
153 using SubDomainJacobianMatrix = GetPropType<SubDomainTypeTag<id>, Properties::JacobianMatrix>;
154
156 template<std::size_t id>
157 using SubDomainSolutionVector = GetPropType<SubDomainTypeTag<id>, Properties::SolutionVector>;
158
160 template<std::size_t id>
161 using SubDomainResidualVector = typename Detail::NativeDuneVectorType<SubDomainSolutionVector<id>>::type;
162
163public:
164
165 /*
166 * \brief sub domain types
167 */
168 //\{
169
170 template<std::size_t id>
172 {
173 using Index = Dune::index_constant<id>;
174 using TypeTag = SubDomainTypeTag<id>;
175 using Grid = GetPropType<SubDomainTypeTag<id>, Properties::Grid>;
176 using GridGeometry = GetPropType<SubDomainTypeTag<id>, Properties::GridGeometry>;
177 using Problem = GetPropType<SubDomainTypeTag<id>, Properties::Problem>;
178 using GridVariables = GetPropType<SubDomainTypeTag<id>, Properties::GridVariables>;
179 using LocalResidual = GetPropType<SubDomainTypeTag<id>, Properties::LocalResidual>;
180 using IOFields = GetPropType<SubDomainTypeTag<id>, Properties::IOFields>;
181 using SolutionVector = GetPropType<SubDomainTypeTag<id>, Properties::SolutionVector>;
183 };
184
185 //\}
186
187 /*
188 * \brief multi domain types
189 */
190 //\{
191
194
197
200
203
204 //\}
205
206 /*
207 * \brief helper aliases to construct derived tuple types
208 */
209 //\{
210
212 template<template<std::size_t> class T>
214
216 template<template<std::size_t> class T>
218
220 template<template<std::size_t> class T>
222
223 //\}
224};
225
226} //end namespace Dumux
227
228#endif
a helper class to create a multitype matrix given the diagonal matrix blocks
Definition: multidomain/traits.hh:41
typename makeMatrix< Indices >::type type
Definition: multidomain/traits.hh:69
Definition: common/pdesolver.hh:26
Definition: variablesbackend.hh:34
Defines all properties used in Dumux.
Helper to extract native Dune vector types from particular Dumux types.
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
Type traits to be used with matrix types.
Definition: adapt.hh:17
helper alias to create the JacobianMatrix type
Definition: multidomain/traits.hh:95
typename createMultiTypeBlockMatrixType< Scalar, MatrixBlocks... >::type::type M
Definition: multidomain/traits.hh:97
typename makeFromIndexedType< M, SubDomainDiagBlocks, Indices >::type type
Definition: multidomain/traits.hh:99
helper alias to create a tuple of shared_ptr<const ...> from an indexed type
Definition: multidomain/traits.hh:85
typename makeFromIndexedType< std::tuple, PtrType, Indices >::type type
Definition: multidomain/traits.hh:89
std::shared_ptr< const T< i > > PtrType
Definition: multidomain/traits.hh:87
helper alias to create a tuple of shared_ptr<...> from an indexed type
Definition: multidomain/traits.hh:75
typename makeFromIndexedType< std::tuple, PtrType, Indices >::type type
Definition: multidomain/traits.hh:79
std::shared_ptr< T< i > > PtrType
Definition: multidomain/traits.hh:77
Definition: dunevectors.hh:56
typename NativeDuneVectorTypeImpl< V, Dune::Std::is_detected< Detail::DuneVectors::StateDetector, V >{} >::type type
Definition: dunevectors.hh:59
Definition: multidomain/traits.hh:172
GetPropType< SubDomainTypeTag< id >, Properties::GridGeometry > GridGeometry
Definition: multidomain/traits.hh:176
typename Detail::NativeDuneVectorType< SolutionVector >::type ResidualVector
Definition: multidomain/traits.hh:182
SubDomainTypeTag< id > TypeTag
Definition: multidomain/traits.hh:174
Dune::index_constant< id > Index
Definition: multidomain/traits.hh:173
GetPropType< SubDomainTypeTag< id >, Properties::IOFields > IOFields
Definition: multidomain/traits.hh:180
GetPropType< SubDomainTypeTag< id >, Properties::Problem > Problem
Definition: multidomain/traits.hh:177
GetPropType< SubDomainTypeTag< id >, Properties::GridVariables > GridVariables
Definition: multidomain/traits.hh:178
GetPropType< SubDomainTypeTag< id >, Properties::Grid > Grid
Definition: multidomain/traits.hh:175
GetPropType< SubDomainTypeTag< id >, Properties::SolutionVector > SolutionVector
Definition: multidomain/traits.hh:181
GetPropType< SubDomainTypeTag< id >, Properties::LocalResidual > LocalResidual
Definition: multidomain/traits.hh:179
Definition: multidomain/traits.hh:134
static constexpr std::size_t numSubDomains
the number of subdomains
Definition: multidomain/traits.hh:136
typename makeFromIndexedType< std::common_type_t, SubDomainScalar, Indices >::type Scalar
the scalar type
Definition: multidomain/traits.hh:193
typename makeFromIndexedType< Dune::MultiTypeBlockVector, SubDomainSolutionVector, Indices >::type SolutionVector
the solution vector type
Definition: multidomain/traits.hh:196
typename Detail::MultiDomainTupleSharedPtr< T, Indices >::type TupleOfSharedPtr
helper alias to create tuple<std::shared_ptr<...>> from indexed type
Definition: multidomain/traits.hh:217
typename makeFromIndexedType< Dune::MultiTypeBlockVector, SubDomainResidualVector, Indices >::type ResidualVector
the residual vector type
Definition: multidomain/traits.hh:199
typename makeFromIndexedType< std::tuple, T, Indices >::type Tuple
helper alias to create tuple<...> from indexed type
Definition: multidomain/traits.hh:213
typename Detail::MultiDomainMatrixType< SubDomainJacobianMatrix, Indices, Scalar >::type JacobianMatrix
the jacobian type
Definition: multidomain/traits.hh:202
typename Detail::MultiDomainTupleSharedPtrConst< T, Indices >::type TupleOfSharedPtrConst
helper alias to create tuple<std::shared_ptr<const ...>> from indexed type
Definition: multidomain/traits.hh:221
Definition: utility.hh:28
Utilities for template meta programming.