3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
multidomain/fvgridgeometry.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 *****************************************************************************/
24#ifndef DUMUX_MULTIDOMAIN_FV_GRIDGEOMETRY_HH
25#define DUMUX_MULTIDOMAIN_FV_GRIDGEOMETRY_HH
26
27#include <tuple>
28#include <memory>
29#include <utility>
30
31#include <dune/common/hybridutilities.hh>
32#include <dune/common/indices.hh>
33
34namespace Dumux {
35
36namespace Multidomain::Detail {
37
38template<class T>
40: public std::false_type {};
41
42template<class... Args>
43struct IsStdTuple_<std::tuple<Args...>>
44: public std::true_type {};
45
46template<class T>
47inline constexpr bool isStdTuple = IsStdTuple_<T>::value;
48
49} // end namespace Multidomain::Detail
50
56template<class MDTraits>
58{
59 static constexpr std::size_t numSubDomains = MDTraits::numSubDomains;
60
61 // unwrap the tuple and pass its elements as arguments to the constructor of the ith element
62 template<std::size_t i, class Tuple, size_t... Is>
63 void constructFromTupleOfArgs_(Tuple&& t, std::index_sequence<Is...>)
64 {
65 std::get<i>(gridGeometries_) = std::make_shared<Type<i>>(std::get<Is>(std::forward<Tuple>(t))...);
66 }
67
68 // construct the ith element in this multidomain wrapper
69 template<std::size_t i, class Arg>
70 void construct_(Arg&& arg)
71 {
72 using ArgT = std::decay_t<Arg>;
73 // use perfect forwarding of the argument(s) in both cases
74 if constexpr (Multidomain::Detail::template isStdTuple<ArgT>)
75 constructFromTupleOfArgs_<i>(std::forward<Arg>(arg), std::make_index_sequence<std::tuple_size_v<ArgT>>{});
76 else
77 std::get<i>(gridGeometries_) = std::make_shared<Type<i>>(std::forward<Arg>(arg));
78 }
79
80 // unwrap the tuple and pass its elements as arguments to the update function of the ith element
81 template<std::size_t i, class Tuple, size_t... Is>
82 void updateWithTupleOfArgs_(Tuple&& t, std::index_sequence<Is...>)
83 {
84 std::get<i>(gridGeometries_)->update(std::get<Is>(std::forward<Tuple>(t))...);
85 }
86
87 // update the ith element in this multidomain wrapper
88 template<std::size_t i, class Arg>
89 void update_(Arg&& arg)
90 {
91 using ArgT = std::decay_t<Arg>;
92 // use perfect forwarding of the argument(s) in both cases
93 if constexpr (Multidomain::Detail::template isStdTuple<ArgT>)
94 updateWithTupleOfArgs_<i>(std::forward<Arg>(arg), std::make_index_sequence<std::tuple_size_v<ArgT>>{});
95 else
96 std::get<i>(gridGeometries_)->update(std::forward<Arg>(arg));
97 }
98
99 // remove this after 3.5
100 template<std::size_t i>
101 using GV = typename MDTraits::template SubDomain<i>::GridGeometry::GridView;
102 using GVTuple = typename MDTraits::template Tuple<GV>;
103
104public:
106 template<std::size_t i>
107 using Type = typename MDTraits::template SubDomain<i>::GridGeometry;
108
110 template<std::size_t i>
111 using PtrType = std::shared_ptr<Type<i>>;
112
114 using TupleType = typename MDTraits::template Tuple<PtrType>;
115
119 [[deprecated("Will be removed after release 3.5. Use variadic constructor!")]]
121
133 template<typename... Args>
135 {
136 static_assert(numSubDomains == sizeof...(Args), "Number of arguments has to match number of subdomains");
137
138 using namespace Dune::Hybrid;
139 forEach(std::make_index_sequence<numSubDomains>{}, [this, t = std::forward_as_tuple(args...)](auto&& id)
140 {
141 constexpr auto i = std::decay_t<decltype(id)>::value;
142 this->construct_<i>(std::get<i>(t));
143 });
144 }
145
151 : gridGeometries_(std::move(ggTuple))
152 {}
153
157 [[deprecated("Will be removed after release 3.5. Use variadic constructor!")]]
159 {
160 using namespace Dune::Hybrid;
161 forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id)
162 {
163 constexpr auto i = std::decay_t<decltype(id)>::value;
164 this->construct_<i>(std::get<i>(gvTuple));
165 });
166 }
167
179 template<typename... Args>
180 void update(Args&&... args)
181 {
182 static_assert(numSubDomains == sizeof...(Args), "Number of arguments has to match number of subdomains");
183
184 using namespace Dune::Hybrid;
185 forEach(std::make_index_sequence<numSubDomains>{}, [this, t = std::forward_as_tuple(args...)](auto&& id)
186 {
187 constexpr auto i = std::decay_t<decltype(id)>::value;
188 this->update_<i>(std::get<i>(t));
189 });
190 }
191
195 [[deprecated("Will be removed after release 3.5. Use variadic update!")]]
196 void update()
197 {
198 using namespace Dune::Hybrid;
199 forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id)
200 {
201 elementAt(gridGeometries_, id)->update();
202 });
203 }
204
206 template<std::size_t i>
207 const Type<i>& operator[] (Dune::index_constant<i>) const
208 { return *std::get<i>(gridGeometries_); }
209
211 template<std::size_t i>
212 Type<i>& operator[] (Dune::index_constant<i>)
213 { return *std::get<i>(gridGeometries_); }
214
216 template<std::size_t i>
217 const PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{}) const
218 { return std::get<i>(gridGeometries_); }
219
221 template<std::size_t i>
222 PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{})
223 { return std::get<i>(gridGeometries_); }
224
226 template<std::size_t i>
227 [[deprecated("Will be removed after release 3.5. Use one of the constructors instead.")]]
228 void set(PtrType<i> p, Dune::index_constant<i> id = Dune::index_constant<i>{})
229 { std::get<i>(gridGeometries_) = p; }
230
235 [[deprecated("Use asTuple. Will be removed after release 3.5")]]
237 { return gridGeometries_; }
238
243 { return gridGeometries_; }
244
248 const TupleType& asTuple() const
249 { return gridGeometries_; }
250
251private:
252
254 TupleType gridGeometries_;
255};
256
257} // end namespace Dumux
258
259#endif
Definition: adapt.hh:29
constexpr bool isStdTuple
Definition: multidomain/fvgridgeometry.hh:47
Definition: multidomain/fvgridgeometry.hh:40
A multidomain wrapper for multiple grid geometries.
Definition: multidomain/fvgridgeometry.hh:58
TupleType getTuple()
return the grid variables tuple we are wrapping
Definition: multidomain/fvgridgeometry.hh:236
void update(Args &&... args)
Update all grid geometries (do this e.g. after grid adaption)
Definition: multidomain/fvgridgeometry.hh:180
MultiDomainFVGridGeometry(GVTuple gvTuple)
Construct wrapper from a tuple of grid views.
Definition: multidomain/fvgridgeometry.hh:158
void set(PtrType< i > p, Dune::index_constant< i > id=Dune::index_constant< i >{})
set the pointer for sub domain i
Definition: multidomain/fvgridgeometry.hh:228
typename MDTraits::template SubDomain< i >::GridGeometry Type
export base types of the stored type
Definition: multidomain/fvgridgeometry.hh:107
typename MDTraits::template Tuple< PtrType > TupleType
export type of tuple of pointers
Definition: multidomain/fvgridgeometry.hh:114
const PtrType< i > & get(Dune::index_constant< i > id=Dune::index_constant< i >{}) const
! access the grid geometry pointer for domain with index i
Definition: multidomain/fvgridgeometry.hh:217
TupleType & asTuple()
Access the underlying tuple representation.
Definition: multidomain/fvgridgeometry.hh:242
MultiDomainFVGridGeometry()=default
The default constructor.
void update()
Update all grid geometries (do this again after grid adaption)
Definition: multidomain/fvgridgeometry.hh:196
const TupleType & asTuple() const
Access the underlying tuple representation.
Definition: multidomain/fvgridgeometry.hh:248
const Type< i > & operator[](Dune::index_constant< i >) const
return the grid geometry for domain with index i
Definition: multidomain/fvgridgeometry.hh:207
std::shared_ptr< Type< i > > PtrType
export pointer types the stored type
Definition: multidomain/fvgridgeometry.hh:111
PtrType< i > & get(Dune::index_constant< i > id=Dune::index_constant< i >{})
! access the the grid geometry pointer for domain with index i
Definition: multidomain/fvgridgeometry.hh:222
MultiDomainFVGridGeometry(Args &&... args)
Construct grid geometries for all subdomains.
Definition: multidomain/fvgridgeometry.hh:134
MultiDomainFVGridGeometry(TupleType ggTuple)
Construct wrapper from a tuple of grid geometries.
Definition: multidomain/fvgridgeometry.hh:150