3.5-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
multidomain/fvgridvariables.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_GRID_VARIABLES_HH
25#define DUMUX_MULTIDOMAIN_FV_GRID_VARIABLES_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
36
37namespace Dumux {
38
44template<class MDTraits>
46{
47 using SolutionVector = typename MDTraits::SolutionVector;
48 static constexpr std::size_t numSubDomains = MDTraits::numSubDomains;
49
50 template<std::size_t i>
51 using GridGeometry = typename MDTraits::template SubDomain<i>::GridGeometry;
52 using GridGeometries = typename MDTraits::template TupleOfSharedPtrConst<GridGeometry>;
53
54 template<std::size_t i>
55 using Problem = typename MDTraits::template SubDomain<i>::Problem;
56 using Problems = typename MDTraits::template TupleOfSharedPtrConst<Problem>;
57
58public:
60 template<std::size_t i>
61 using Type = typename MDTraits::template SubDomain<i>::GridVariables;
62
64 template<std::size_t i>
65 using PtrType = std::shared_ptr<Type<i>>;
66
68 using TupleType = typename MDTraits::template Tuple<PtrType>;
69
73 [[deprecated("Will be removed after release 3.5. Use one of the constructors instead.")]]
75
82 {
83 using namespace Dune::Hybrid;
84 forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id)
85 {
86 constexpr auto i = std::decay_t<decltype(id)>::value;
87 std::get<i>(gridVars_) = std::make_shared<Type<i>>(
88 problems.template get<i>(), gridGeometries.template get<i>()
89 );
90 });
91 }
92
98 : gridVars_(std::move(ggTuple))
99 {}
100
102 void init(const SolutionVector& sol)
103 {
104 using namespace Dune::Hybrid;
105 forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id)
106 {
107 elementAt(gridVars_, id)->init(sol[id]);
108 });
109 }
110
112 void update(const SolutionVector& sol, bool forceFluxCacheUpdate = false)
113 {
114 using namespace Dune::Hybrid;
115 forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id)
116 {
117 elementAt(gridVars_, id)->update(sol[id], forceFluxCacheUpdate);
118 });
119 }
120
122 void updateAfterGridAdaption(const SolutionVector& sol)
123 {
124 using namespace Dune::Hybrid;
125 forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id)
126 {
127 elementAt(gridVars_, id)->updateAfterGridAdaption(sol[id]);
128 });
129 }
130
136 {
137 using namespace Dune::Hybrid;
138 forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id)
139 {
140 elementAt(gridVars_, id)->advanceTimeStep();
141 });
142 }
143
145 void resetTimeStep(const SolutionVector& sol)
146 {
147 using namespace Dune::Hybrid;
148 forEach(std::make_index_sequence<numSubDomains>{}, [&](auto&& id)
149 {
150 elementAt(gridVars_, id)->resetTimeStep(sol[id]);
151 });
152 }
153
155 template<std::size_t i>
156 const Type<i>& operator[] (Dune::index_constant<i> id) const
157 { return *std::get<i>(gridVars_); }
158
160 template<std::size_t i>
161 Type<i>& operator[] (Dune::index_constant<i> id)
162 { return *std::get<i>(gridVars_); }
163
165 template<std::size_t i>
166 const PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{}) const
167 { return std::get<i>(gridVars_); }
168
170 template<std::size_t i>
171 PtrType<i>& get(Dune::index_constant<i> id = Dune::index_constant<i>{})
172 { return std::get<i>(gridVars_); }
173
175 template<std::size_t i>
176 [[deprecated("Will be removed after release 3.5. Use one of the constructors instead.")]]
177 void set(PtrType<i> p, Dune::index_constant<i> id = Dune::index_constant<i>{})
178 { Dune::Hybrid::elementAt(gridVars_, id) = p; }
179
184 [[deprecated("Use asTuple. Will be removed after release 3.5")]]
186 { return gridVars_; }
187
192 { return gridVars_; }
193
197 const TupleType& asTuple() const
198 { return gridVars_; }
199
200private:
201
203 TupleType gridVars_;
204};
205
206} // end namespace Dumux
207
208#endif
Definition: adapt.hh:29
A multidomain wrapper for multiple grid geometries.
Definition: multidomain/fvgridgeometry.hh:58
A multidomain wrapper for multiple grid variables.
Definition: multidomain/fvgridvariables.hh:46
typename MDTraits::template Tuple< PtrType > TupleType
export type of tuple of pointers
Definition: multidomain/fvgridvariables.hh:68
MultiDomainFVGridVariables(TupleType ggTuple)
Construct wrapper from a tuple of grid variables.
Definition: multidomain/fvgridvariables.hh:97
typename MDTraits::template SubDomain< i >::GridVariables Type
export base types of the stored type
Definition: multidomain/fvgridvariables.hh:61
const TupleType & asTuple() const
Access the underlying tuple representation.
Definition: multidomain/fvgridvariables.hh:197
void set(PtrType< i > p, Dune::index_constant< i > id=Dune::index_constant< i >{})
set the pointer for sub domain i
Definition: multidomain/fvgridvariables.hh:177
void update(const SolutionVector &sol, bool forceFluxCacheUpdate=false)
update all variables
Definition: multidomain/fvgridvariables.hh:112
MultiDomainFVGridVariables(MultiDomainFVGridGeometry< MDTraits > gridGeometries, MultiDomainFVProblem< MDTraits > problems)
Contruct the grid variables.
Definition: multidomain/fvgridvariables.hh:81
const Type< i > & operator[](Dune::index_constant< i > id) const
return the grid variables for domain with index i
Definition: multidomain/fvgridvariables.hh:156
void updateAfterGridAdaption(const SolutionVector &sol)
update all variables after grid adaption
Definition: multidomain/fvgridvariables.hh:122
const PtrType< i > & get(Dune::index_constant< i > id=Dune::index_constant< i >{}) const
access the ith grid variables pointer we are wrapping
Definition: multidomain/fvgridvariables.hh:166
std::shared_ptr< Type< i > > PtrType
export pointer types the stored type
Definition: multidomain/fvgridvariables.hh:65
MultiDomainFVGridVariables()=default
The default constructor.
void init(const SolutionVector &sol)
initialize all variables
Definition: multidomain/fvgridvariables.hh:102
void resetTimeStep(const SolutionVector &sol)
resets state to the one before time integration
Definition: multidomain/fvgridvariables.hh:145
PtrType< i > & get(Dune::index_constant< i > id=Dune::index_constant< i >{})
access the ith grid variables pointer we are wrapping
Definition: multidomain/fvgridvariables.hh:171
void advanceTimeStep()
Sets the current state as the previous for next time step.
Definition: multidomain/fvgridvariables.hh:135
TupleType & asTuple()
Access the underlying tuple representation.
Definition: multidomain/fvgridvariables.hh:191
TupleType getTuple()
return the grid variables tuple we are wrapping
Definition: multidomain/fvgridvariables.hh:185
A multidomain wrapper for multiple problems.
Definition: multidomain/fvproblem.hh:45
Multidomain wrapper for multiple problems.
Multidomain wrapper for multiple grid geometries.