version 3.8
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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_MULTIDOMAIN_FV_GRIDGEOMETRY_HH
13#define DUMUX_MULTIDOMAIN_FV_GRIDGEOMETRY_HH
14
15#include <tuple>
16#include <memory>
17#include <utility>
18
19#include <dune/common/hybridutilities.hh>
20#include <dune/common/indices.hh>
21
22namespace Dumux {
23
24namespace Multidomain::Detail {
25
26template<class T>
28: public std::false_type {};
29
30template<class... Args>
31struct IsStdTuple_<std::tuple<Args...>>
32: public std::true_type {};
33
34template<class T>
35inline constexpr bool isStdTuple = IsStdTuple_<T>::value;
36
37} // end namespace Multidomain::Detail
38
44template<class MDTraits>
46{
47 static constexpr std::size_t numSubDomains = MDTraits::numSubDomains;
48
49 // unwrap the tuple and pass its elements as arguments to the constructor of the ith element
50 template<std::size_t i, class Tuple, size_t... Is>
51 void constructFromTupleOfArgs_(Tuple&& t, std::index_sequence<Is...>)
52 {
53 std::get<i>(gridGeometries_) = std::make_shared<Type<i>>(std::get<Is>(std::forward<Tuple>(t))...);
54 }
55
56 // construct the ith element in this multidomain wrapper
57 template<std::size_t i, class Arg>
58 void construct_(Arg&& arg)
59 {
60 using ArgT = std::decay_t<Arg>;
61 // use perfect forwarding of the argument(s) in both cases
62 if constexpr (Multidomain::Detail::template isStdTuple<ArgT>)
63 constructFromTupleOfArgs_<i>(std::forward<Arg>(arg), std::make_index_sequence<std::tuple_size_v<ArgT>>{});
64 else
65 std::get<i>(gridGeometries_) = std::make_shared<Type<i>>(std::forward<Arg>(arg));
66 }
67
68 // unwrap the tuple and pass its elements as arguments to the update function of the ith element
69 template<std::size_t i, class Tuple, size_t... Is>
70 void updateWithTupleOfArgs_(Tuple&& t, std::index_sequence<Is...>)
71 {
72 std::get<i>(gridGeometries_)->update(std::get<Is>(std::forward<Tuple>(t))...);
73 }
74
75 // update the ith element in this multidomain wrapper
76 template<std::size_t i, class Arg>
77 void update_(Arg&& arg)
78 {
79 using ArgT = std::decay_t<Arg>;
80 // use perfect forwarding of the argument(s) in both cases
81 if constexpr (Multidomain::Detail::template isStdTuple<ArgT>)
82 updateWithTupleOfArgs_<i>(std::forward<Arg>(arg), std::make_index_sequence<std::tuple_size_v<ArgT>>{});
83 else
84 std::get<i>(gridGeometries_)->update(std::forward<Arg>(arg));
85 }
86
87public:
89 template<std::size_t i>
90 using Type = typename MDTraits::template SubDomain<i>::GridGeometry;
91
93 template<std::size_t i>
94 using PtrType = std::shared_ptr<Type<i>>;
95
97 using TupleType = typename MDTraits::template Tuple<PtrType>;
98
110 template<typename... Args>
112 {
113 static_assert(numSubDomains == sizeof...(Args), "Number of arguments has to match number of subdomains");
114
115 using namespace Dune::Hybrid;
116 forEach(std::make_index_sequence<numSubDomains>{}, [this, t = std::forward_as_tuple(args...)](auto&& id)
117 {
118 constexpr auto i = std::decay_t<decltype(id)>::value;
119 this->construct_<i>(std::get<i>(t));
120 });
121 }
122
128 : gridGeometries_(std::move(ggTuple))
129 {}
130
142 template<typename... Args>
143 void update(Args&&... args)
144 {
145 static_assert(numSubDomains == sizeof...(Args), "Number of arguments has to match number of subdomains");
146
147 using namespace Dune::Hybrid;
148 forEach(std::make_index_sequence<numSubDomains>{}, [this, t = std::forward_as_tuple(args...)](auto&& id)
149 {
150 constexpr auto i = std::decay_t<decltype(id)>::value;
151 this->update_<i>(std::get<i>(t));
152 });
153 }
154
156 template<std::size_t i>
157 const Type<i>& operator[] (Dune::index_constant<i>) const
158 { return *std::get<i>(gridGeometries_); }
159
161 template<std::size_t i>
162 Type<i>& operator[] (Dune::index_constant<i>)
163 { return *std::get<i>(gridGeometries_); }
164
166 template<std::size_t i>
167 const PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{}) const
168 { return std::get<i>(gridGeometries_); }
169
171 template<std::size_t i>
172 PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{})
173 { return std::get<i>(gridGeometries_); }
174
179 { return gridGeometries_; }
180
184 const TupleType& asTuple() const
185 { return gridGeometries_; }
186
187private:
188
190 TupleType gridGeometries_;
191};
192
193} // end namespace Dumux
194
195#endif
A multidomain wrapper for multiple grid geometries.
Definition: multidomain/fvgridgeometry.hh:46
void update(Args &&... args)
Update all grid geometries (do this e.g. after grid adaption)
Definition: multidomain/fvgridgeometry.hh:143
typename MDTraits::template SubDomain< i >::GridGeometry Type
export base types of the stored type
Definition: multidomain/fvgridgeometry.hh:90
typename MDTraits::template Tuple< PtrType > TupleType
export type of tuple of pointers
Definition: multidomain/fvgridgeometry.hh:97
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:167
TupleType & asTuple()
Access the underlying tuple representation.
Definition: multidomain/fvgridgeometry.hh:178
const TupleType & asTuple() const
Access the underlying tuple representation.
Definition: multidomain/fvgridgeometry.hh:184
const Type< i > & operator[](Dune::index_constant< i >) const
return the grid geometry for domain with index i
Definition: multidomain/fvgridgeometry.hh:157
std::shared_ptr< Type< i > > PtrType
export pointer types the stored type
Definition: multidomain/fvgridgeometry.hh:94
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:172
MultiDomainFVGridGeometry(Args &&... args)
Construct grid geometries for all subdomains.
Definition: multidomain/fvgridgeometry.hh:111
MultiDomainFVGridGeometry(TupleType ggTuple)
Construct wrapper from a tuple of grid geometries.
Definition: multidomain/fvgridgeometry.hh:127
constexpr bool isStdTuple
Definition: multidomain/fvgridgeometry.hh:35
Definition: adapt.hh:17
Definition: multidomain/fvgridgeometry.hh:28