3.6-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
99public:
101 template<std::size_t i>
102 using Type = typename MDTraits::template SubDomain<i>::GridGeometry;
103
105 template<std::size_t i>
106 using PtrType = std::shared_ptr<Type<i>>;
107
109 using TupleType = typename MDTraits::template Tuple<PtrType>;
110
122 template<typename... Args>
124 {
125 static_assert(numSubDomains == sizeof...(Args), "Number of arguments has to match number of subdomains");
126
127 using namespace Dune::Hybrid;
128 forEach(std::make_index_sequence<numSubDomains>{}, [this, t = std::forward_as_tuple(args...)](auto&& id)
129 {
130 constexpr auto i = std::decay_t<decltype(id)>::value;
131 this->construct_<i>(std::get<i>(t));
132 });
133 }
134
140 : gridGeometries_(std::move(ggTuple))
141 {}
142
154 template<typename... Args>
155 void update(Args&&... args)
156 {
157 static_assert(numSubDomains == sizeof...(Args), "Number of arguments has to match number of subdomains");
158
159 using namespace Dune::Hybrid;
160 forEach(std::make_index_sequence<numSubDomains>{}, [this, t = std::forward_as_tuple(args...)](auto&& id)
161 {
162 constexpr auto i = std::decay_t<decltype(id)>::value;
163 this->update_<i>(std::get<i>(t));
164 });
165 }
166
168 template<std::size_t i>
169 const Type<i>& operator[] (Dune::index_constant<i>) const
170 { return *std::get<i>(gridGeometries_); }
171
173 template<std::size_t i>
174 Type<i>& operator[] (Dune::index_constant<i>)
175 { return *std::get<i>(gridGeometries_); }
176
178 template<std::size_t i>
179 const PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{}) const
180 { return std::get<i>(gridGeometries_); }
181
183 template<std::size_t i>
184 PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{})
185 { return std::get<i>(gridGeometries_); }
186
191 { return gridGeometries_; }
192
196 const TupleType& asTuple() const
197 { return gridGeometries_; }
198
199private:
200
202 TupleType gridGeometries_;
203};
204
205} // end namespace Dumux
206
207#endif
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
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
void update(Args &&... args)
Update all grid geometries (do this e.g. after grid adaption)
Definition: multidomain/fvgridgeometry.hh:155
typename MDTraits::template SubDomain< i >::GridGeometry Type
export base types of the stored type
Definition: multidomain/fvgridgeometry.hh:102
typename MDTraits::template Tuple< PtrType > TupleType
export type of tuple of pointers
Definition: multidomain/fvgridgeometry.hh:109
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:179
TupleType & asTuple()
Access the underlying tuple representation.
Definition: multidomain/fvgridgeometry.hh:190
const TupleType & asTuple() const
Access the underlying tuple representation.
Definition: multidomain/fvgridgeometry.hh:196
const Type< i > & operator[](Dune::index_constant< i >) const
return the grid geometry for domain with index i
Definition: multidomain/fvgridgeometry.hh:169
std::shared_ptr< Type< i > > PtrType
export pointer types the stored type
Definition: multidomain/fvgridgeometry.hh:106
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:184
MultiDomainFVGridGeometry(Args &&... args)
Construct grid geometries for all subdomains.
Definition: multidomain/fvgridgeometry.hh:123
MultiDomainFVGridGeometry(TupleType ggTuple)
Construct wrapper from a tuple of grid geometries.
Definition: multidomain/fvgridgeometry.hh:139