GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/multidomain/fvgridgeometry.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 15 23 65.2%
Functions: 10 36 27.8%
Branches: 31 84 36.9%

Line Branch Exec Source
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 //
7 /*!
8 * \file
9 * \ingroup MultiDomain
10 * \brief Multidomain wrapper for multiple grid geometries
11 */
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
22 namespace Dumux {
23
24 namespace Multidomain::Detail {
25
26 template<class T>
27 struct IsStdTuple_
28 : public std::false_type {};
29
30 template<class... Args>
31 struct IsStdTuple_<std::tuple<Args...>>
32 : public std::true_type {};
33
34 template<class T>
35 inline constexpr bool isStdTuple = IsStdTuple_<T>::value;
36
37 } // end namespace Multidomain::Detail
38
39 /*!
40 * \ingroup MultiDomain
41 * \brief A multidomain wrapper for multiple grid geometries
42 * \tparam MDTraits The multidomain traits
43 */
44 template<class MDTraits>
45
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
6 class MultiDomainFVGridGeometry
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 7 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
3/6
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4 times.
7 std::get<i>(gridGeometries_) = std::make_shared<Type<i>>(std::forward<Arg>(arg));
66 7 }
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 8 std::get<i>(gridGeometries_)->update(std::forward<Arg>(arg));
85 }
86
87 public:
88 //! export base types of the stored type
89 template<std::size_t i>
90 using Type = typename MDTraits::template SubDomain<i>::GridGeometry;
91
92 //! export pointer types the stored type
93 template<std::size_t i>
94 using PtrType = std::shared_ptr<Type<i>>;
95
96 //! export type of tuple of pointers
97 using TupleType = typename MDTraits::template Tuple<PtrType>;
98
99 /*!
100 * \brief Construct grid geometries for all subdomains
101 * \param args a list of arguments to pass to the constructors
102 *
103 * The number of arguments has to match the number of subdomains.
104 * In case a constructor needs multiple arguments, they have to be wrapped in a std::tuple.
105 * Use std::make_tuple and possible wrap arguments using std::ref / std::cref or use std::forward_as_tuple.
106 * If an argument is a tuple, it will be unpacked and its members will be passed to the constructor.
107 * In the corner case where you need to pass a tuple to the constructor,
108 * you therefore need to additionally wrap the tuple in a tuple before passing.
109 */
110 template<typename... Args>
111 2 MultiDomainFVGridGeometry(Args&&... args)
112 2 {
113 static_assert(numSubDomains == sizeof...(Args), "Number of arguments has to match number of subdomains");
114
115 using namespace Dune::Hybrid;
116
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 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 2 }
122
123 /*!
124 * \brief Construct wrapper from a tuple of grid geometries
125 * \param ggTuple a tuple of shared_ptrs to the grid geometries
126 */
127 MultiDomainFVGridGeometry(TupleType ggTuple)
128
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
8 : gridGeometries_(std::move(ggTuple))
129 {}
130
131 /*!
132 * \brief Update all grid geometries (do this e.g. after grid adaption)
133 * \param args a list of arguments to pass to the update functions
134 *
135 * The number of arguments has to match the number of subdomains.
136 * In case the update function needs multiple arguments, they have to be wrapped in a std::tuple.
137 * Use std::make_tuple and possible wrap arguments using std::ref / std::cref or use std::forward_as_tuple.
138 * If an argument is a tuple, it will be unpacked and its members will be passed to the constructor.
139 * In the corner case where you need to pass a tuple to the constructor,
140 * you therefore need to additionally wrap the tuple in a tuple before passing.
141 */
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
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
14 forEach(std::make_index_sequence<numSubDomains>{}, [this, t = std::forward_as_tuple(args...)](auto&& id)
149 {
150 4 constexpr auto i = std::decay_t<decltype(id)>::value;
151 8 this->update_<i>(std::get<i>(t));
152 });
153 }
154
155 //! return the grid geometry for domain with index i
156 template<std::size_t i>
157 const Type<i>& operator[] (Dune::index_constant<i>) const
158 { return *std::get<i>(gridGeometries_); }
159
160 //! return the grid geometry for domain with index i
161 template<std::size_t i>
162 Type<i>& operator[] (Dune::index_constant<i>)
163
9/18
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 2 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 2 times.
✗ Branch 26 not taken.
18 { return *std::get<i>(gridGeometries_); }
164
165 ///! access the grid geometry pointer for domain with index i
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
170 ///! access the the grid geometry pointer for domain with index i
171 template<std::size_t i>
172 PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{})
173
12/24
✓ Branch 13 taken 2 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 2 times.
✗ Branch 20 not taken.
✓ Branch 22 taken 2 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 2 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 2 times.
✗ Branch 29 not taken.
✓ Branch 31 taken 2 times.
✗ Branch 32 not taken.
✓ Branch 34 taken 2 times.
✗ Branch 35 not taken.
✓ Branch 37 taken 2 times.
✗ Branch 38 not taken.
✓ Branch 40 taken 2 times.
✗ Branch 41 not taken.
✓ Branch 43 taken 2 times.
✗ Branch 44 not taken.
✓ Branch 46 taken 2 times.
✗ Branch 47 not taken.
20 { return std::get<i>(gridGeometries_); }
174
175 /*!
176 * \brief Access the underlying tuple representation
177 */
178 TupleType& asTuple()
179 { return gridGeometries_; }
180
181 /*!
182 * \brief Access the underlying tuple representation
183 */
184 const TupleType& asTuple() const
185 { return gridGeometries_; }
186
187 private:
188
189 //! a tuple of points to all grid variables
190 TupleType gridGeometries_;
191 };
192
193 } // end namespace Dumux
194
195 #endif
196