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 variables | ||
11 | */ | ||
12 | #ifndef DUMUX_MULTIDOMAIN_FV_GRID_VARIABLES_HH | ||
13 | #define DUMUX_MULTIDOMAIN_FV_GRID_VARIABLES_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 | #include <dumux/multidomain/fvgridgeometry.hh> | ||
23 | #include <dumux/multidomain/fvproblem.hh> | ||
24 | |||
25 | namespace Dumux { | ||
26 | |||
27 | /*! | ||
28 | * \ingroup MultiDomain | ||
29 | * \brief A multidomain wrapper for multiple grid variables | ||
30 | * \tparam MDTraits the multidomain traits | ||
31 | */ | ||
32 | template<class MDTraits> | ||
33 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | class MultiDomainFVGridVariables |
34 | { | ||
35 | using SolutionVector = typename MDTraits::SolutionVector; | ||
36 | static constexpr std::size_t numSubDomains = MDTraits::numSubDomains; | ||
37 | |||
38 | template<std::size_t i> | ||
39 | using GridGeometry = typename MDTraits::template SubDomain<i>::GridGeometry; | ||
40 | using GridGeometries = typename MDTraits::template TupleOfSharedPtrConst<GridGeometry>; | ||
41 | |||
42 | template<std::size_t i> | ||
43 | using Problem = typename MDTraits::template SubDomain<i>::Problem; | ||
44 | using Problems = typename MDTraits::template TupleOfSharedPtrConst<Problem>; | ||
45 | |||
46 | public: | ||
47 | //! export base types of the stored type | ||
48 | template<std::size_t i> | ||
49 | using Type = typename MDTraits::template SubDomain<i>::GridVariables; | ||
50 | |||
51 | //! export pointer types the stored type | ||
52 | template<std::size_t i> | ||
53 | using PtrType = std::shared_ptr<Type<i>>; | ||
54 | |||
55 | //! export type of tuple of pointers | ||
56 | using TupleType = typename MDTraits::template Tuple<PtrType>; | ||
57 | |||
58 | /*! | ||
59 | * \brief Construct the grid variables | ||
60 | * \param gridGeometries a multidomain wrapper of a grid geometry tuple | ||
61 | * \param problems a multidomain wrapper of a problem tuple | ||
62 | */ | ||
63 | 2 | MultiDomainFVGridVariables(MultiDomainFVGridGeometry<MDTraits> gridGeometries, MultiDomainFVProblem<MDTraits> problems) | |
64 | 2 | { | |
65 | using namespace Dune::Hybrid; | ||
66 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
14 | forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id) |
67 | { | ||
68 | 6 | constexpr auto i = std::decay_t<decltype(id)>::value; | |
69 |
9/36✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
|
6 | std::get<i>(gridVars_) = std::make_shared<Type<i>>( |
70 | 12 | problems.template get<i>(), gridGeometries.template get<i>() | |
71 | ); | ||
72 | }); | ||
73 | 2 | } | |
74 | |||
75 | /*! | ||
76 | * \brief Construct wrapper from a tuple of grid variables | ||
77 | * \param ggTuple a tuple of shared_ptrs to the grid variables | ||
78 | */ | ||
79 | MultiDomainFVGridVariables(TupleType ggTuple) | ||
80 | : gridVars_(std::move(ggTuple)) | ||
81 | {} | ||
82 | |||
83 | //! initialize all variables | ||
84 | ✗ | void init(const SolutionVector& sol) | |
85 | { | ||
86 | using namespace Dune::Hybrid; | ||
87 |
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>{}, [&](auto&& id) |
88 | { | ||
89 |
12/24✓ 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.
✓ 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.
|
24 | elementAt(gridVars_, id)->init(sol[id]); |
90 | }); | ||
91 | ✗ | } | |
92 | |||
93 | //! update all variables | ||
94 | void update(const SolutionVector& sol, bool forceFluxCacheUpdate = false) | ||
95 | { | ||
96 | using namespace Dune::Hybrid; | ||
97 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id) |
98 | { | ||
99 |
15/30✓ 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.
✓ 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.
|
30 | elementAt(gridVars_, id)->update(sol[id], forceFluxCacheUpdate); |
100 | }); | ||
101 | } | ||
102 | |||
103 | //! update all variables after grid adaption | ||
104 | void updateAfterGridAdaption(const SolutionVector& sol) | ||
105 | { | ||
106 | using namespace Dune::Hybrid; | ||
107 | forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id) | ||
108 | { | ||
109 | elementAt(gridVars_, id)->updateAfterGridAdaption(sol[id]); | ||
110 | }); | ||
111 | } | ||
112 | |||
113 | /*! | ||
114 | * \brief Sets the current state as the previous for next time step | ||
115 | * \note this has to be called at the end of each time step | ||
116 | */ | ||
117 | void advanceTimeStep() | ||
118 | { | ||
119 | using namespace Dune::Hybrid; | ||
120 | forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id) | ||
121 | { | ||
122 | elementAt(gridVars_, id)->advanceTimeStep(); | ||
123 | }); | ||
124 | } | ||
125 | |||
126 | //! resets state to the one before time integration | ||
127 | void resetTimeStep(const SolutionVector& sol) | ||
128 | { | ||
129 | using namespace Dune::Hybrid; | ||
130 | forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id) | ||
131 | { | ||
132 | elementAt(gridVars_, id)->resetTimeStep(sol[id]); | ||
133 | }); | ||
134 | } | ||
135 | |||
136 | //! return the grid variables for domain with index i | ||
137 | template<std::size_t i> | ||
138 | const Type<i>& operator[] (Dune::index_constant<i> id) const | ||
139 | { return *std::get<i>(gridVars_); } | ||
140 | |||
141 | //! return the grid variables for domain with index i | ||
142 | template<std::size_t i> | ||
143 | Type<i>& operator[] (Dune::index_constant<i> id) | ||
144 | { return *std::get<i>(gridVars_); } | ||
145 | |||
146 | //! access the ith grid variables pointer we are wrapping | ||
147 | template<std::size_t i> | ||
148 | const PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{}) const | ||
149 | { return std::get<i>(gridVars_); } | ||
150 | |||
151 | //! access the ith grid variables pointer we are wrapping | ||
152 | template<std::size_t i> | ||
153 | PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{}) | ||
154 | { return std::get<i>(gridVars_); } | ||
155 | |||
156 | /*! | ||
157 | * \brief Access the underlying tuple representation | ||
158 | */ | ||
159 | TupleType& asTuple() | ||
160 | { return gridVars_; } | ||
161 | |||
162 | /*! | ||
163 | * \brief Access the underlying tuple representation | ||
164 | */ | ||
165 | const TupleType& asTuple() const | ||
166 | { return gridVars_; } | ||
167 | |||
168 | private: | ||
169 | |||
170 | //! a tuple of points to all grid variables | ||
171 | TupleType gridVars_; | ||
172 | }; | ||
173 | |||
174 | } // end namespace Dumux | ||
175 | |||
176 | #endif | ||
177 |