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 Experimental | ||
10 | * \ingroup Discretization | ||
11 | * \brief The grid variable class for finite volume schemes, | ||
12 | * storing variables on scv and scvf (volume and flux variables) | ||
13 | */ | ||
14 | #ifndef DUMUX_EXPERIMENTAL_FV_GRID_VARIABLES_HH | ||
15 | #define DUMUX_EXPERIMENTAL_FV_GRID_VARIABLES_HH | ||
16 | |||
17 | #include <utility> | ||
18 | #include <memory> | ||
19 | |||
20 | #include <dumux/common/typetraits/problem.hh> | ||
21 | #include <dumux/discretization/localview.hh> | ||
22 | #include <dumux/experimental/discretization/gridvariables.hh> | ||
23 | |||
24 | namespace Dumux::Experimental { | ||
25 | |||
26 | /*! | ||
27 | * \ingroup Experimental | ||
28 | * \ingroup Discretization | ||
29 | * \brief Finite volume-specific local view on grid variables. | ||
30 | * \tparam GV The grid variables class | ||
31 | */ | ||
32 | template<class GV> | ||
33 | class FVGridVariablesLocalView | ||
34 | { | ||
35 | using GridGeometry = typename GV::GridGeometry; | ||
36 | using FVElementGeometry = typename GridGeometry::LocalView; | ||
37 | |||
38 | using GridView = typename GridGeometry::GridView; | ||
39 | using Element = typename GridView::template Codim<0>::Entity; | ||
40 | |||
41 | using ElementVolumeVariables = typename GV::GridVolumeVariables::LocalView; | ||
42 | using ElementFluxVariablesCache = typename GV::GridFluxVariablesCache::LocalView; | ||
43 | |||
44 | public: | ||
45 | //! export corresponding grid-wide class | ||
46 | using GridVariables = GV; | ||
47 | |||
48 | //! Constructor | ||
49 | FVGridVariablesLocalView(const GridVariables& gridVariables) | ||
50 | : gridVariables_(&gridVariables) | ||
51 | , elemVolVars_(gridVariables.gridVolVars()) | ||
52 | , elemFluxVarsCache_(gridVariables.gridFluxVarsCache()) | ||
53 | {} | ||
54 | |||
55 | /*! | ||
56 | * \brief Bind this local view to a grid element. | ||
57 | * \param element The grid element | ||
58 | * \param fvGeometry Local view on the grid geometry | ||
59 | */ | ||
60 | void bind(const Element& element, | ||
61 | const FVElementGeometry& fvGeometry) | ||
62 | { | ||
63 | const auto& x = gridVariables().dofs(); | ||
64 | elemVolVars_.bind(element, fvGeometry, x); | ||
65 | elemFluxVarsCache_.bind(element, fvGeometry, elemVolVars_); | ||
66 | } | ||
67 | |||
68 | /*! | ||
69 | * \brief Bind only the volume variables local view to a grid element. | ||
70 | * \param element The grid element | ||
71 | * \param fvGeometry Local view on the grid geometry | ||
72 | */ | ||
73 | void bindElemVolVars(const Element& element, | ||
74 | const FVElementGeometry& fvGeometry) | ||
75 | { | ||
76 | elemVolVars_.bind(element, fvGeometry, gridVariables().dofs()); | ||
77 | |||
78 | // unbind flux variables cache | ||
79 | elemFluxVarsCache_ = localView(gridVariables().gridFluxVarsCache()); | ||
80 | } | ||
81 | |||
82 | //! return reference to the elem vol vars | ||
83 | const ElementVolumeVariables& elemVolVars() const { return elemVolVars_; } | ||
84 | ElementVolumeVariables& elemVolVars() { return elemVolVars_; } | ||
85 | |||
86 | //! return reference to the flux variables cache | ||
87 | const ElementFluxVariablesCache& elemFluxVarsCache() const { return elemFluxVarsCache_; } | ||
88 | ElementFluxVariablesCache& elemFluxVarsCache() { return elemFluxVarsCache_; } | ||
89 | |||
90 | //! Return reference to the grid variables | ||
91 | const GridVariables& gridVariables() const | ||
92 | { return *gridVariables_; } | ||
93 | |||
94 | private: | ||
95 | const GridVariables* gridVariables_; | ||
96 | ElementVolumeVariables elemVolVars_; | ||
97 | ElementFluxVariablesCache elemFluxVarsCache_; | ||
98 | }; | ||
99 | |||
100 | /*! | ||
101 | * \ingroup Experimental | ||
102 | * \ingroup Discretization | ||
103 | * \brief The grid variable class for finite volume schemes, storing | ||
104 | * variables on scv and scvf (volume and flux variables). | ||
105 | * \tparam GVV the type of the grid volume variables | ||
106 | * \tparam GFVC the type of the grid flux variables cache | ||
107 | * \tparam X the type used for solution vectors | ||
108 | */ | ||
109 | template<class GVV, class GFVC, class X> | ||
110 | 3 | class FVGridVariables | |
111 | : public GridVariables<typename ProblemTraits<typename GVV::Problem>::GridGeometry, X> | ||
112 | { | ||
113 | using Problem = typename GVV::Problem; | ||
114 | using GG = typename ProblemTraits<Problem>::GridGeometry; | ||
115 | |||
116 | using ParentType = GridVariables<GG, X>; | ||
117 | using ThisType = FVGridVariables<GVV, GFVC, X>; | ||
118 | |||
119 | public: | ||
120 | using typename ParentType::SolutionVector; | ||
121 | |||
122 | //! export type of the finite volume grid geometry | ||
123 | using GridGeometry = GG; | ||
124 | |||
125 | //! export type of the grid volume variables | ||
126 | using GridVolumeVariables = GVV; | ||
127 | |||
128 | //! export type of the volume variables | ||
129 | using VolumeVariables = typename GridVolumeVariables::VolumeVariables; | ||
130 | |||
131 | //! export primary variable type | ||
132 | using PrimaryVariables = typename VolumeVariables::PrimaryVariables; | ||
133 | |||
134 | //! export cache type for flux variables | ||
135 | using GridFluxVariablesCache = GFVC; | ||
136 | |||
137 | //! export the local view on this class | ||
138 | using LocalView = FVGridVariablesLocalView<ThisType>; | ||
139 | |||
140 | /*! | ||
141 | * \brief Constructor | ||
142 | * \param problem The problem to be solved | ||
143 | * \param gridGeometry The geometry of the computational grid | ||
144 | * \note This constructor initializes the solution using the | ||
145 | * initializer function in the given problem, and thus, | ||
146 | * this only compiles if the problem implements it. | ||
147 | */ | ||
148 | 1 | FVGridVariables(std::shared_ptr<Problem> problem, | |
149 | std::shared_ptr<const GridGeometry> gridGeometry) | ||
150 |
3/6✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
2 | : ParentType(gridGeometry, [problem] (auto& x) { problem->applyInitialSolution(x); }) |
151 | ✗ | , gridVolVars_(*problem) | |
152 |
3/10✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
|
2 | , gridFluxVarsCache_(*problem) |
153 | ✗ | {} | |
154 | |||
155 | /*! | ||
156 | * \brief Constructor with custom initialization of the solution. | ||
157 | * \param problem The problem to be solved | ||
158 | * \param gridGeometry The geometry of the computational grid | ||
159 | * \param solOrInitializer This can be either a reference to a solution | ||
160 | * vector, or an initializer lambda. | ||
161 | * See Dumux::Experimental::Variables. | ||
162 | */ | ||
163 | template<class SolOrInitializer> | ||
164 | 6 | FVGridVariables(std::shared_ptr<Problem> problem, | |
165 | std::shared_ptr<const GridGeometry> gridGeometry, | ||
166 | SolOrInitializer&& solOrInitializer) | ||
167 | : ParentType(gridGeometry, std::forward<SolOrInitializer>(solOrInitializer)) | ||
168 | 12 | , gridVolVars_(*problem) | |
169 |
2/6✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
24 | , gridFluxVarsCache_(*problem) |
170 | { | ||
171 | 12 | gridVolVars_.update(this->gridGeometry(), this->dofs()); | |
172 | 8 | gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, this->dofs(), true); | |
173 | 6 | } | |
174 | |||
175 | //! Update all variables that may be affected by a change in solution | ||
176 | void update(const SolutionVector& curSol) | ||
177 | { | ||
178 | ParentType::update(curSol); | ||
179 | |||
180 | // resize and update the volVars with the initial solution | ||
181 | gridVolVars_.update(this->gridGeometry(), curSol); | ||
182 | |||
183 | // update the flux variables caches | ||
184 | gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, curSol); | ||
185 | } | ||
186 | |||
187 | //! Force the update of all variables | ||
188 | void forceUpdateAll(const SolutionVector& curSol) | ||
189 | { | ||
190 | ParentType::update(curSol); | ||
191 | |||
192 | // resize and update the volVars with the initial solution | ||
193 | gridVolVars_.update(this->gridGeometry(), curSol); | ||
194 | |||
195 | // update the flux variables caches | ||
196 | gridFluxVarsCache_.update(this->gridGeometry(), gridVolVars_, curSol, true); | ||
197 | } | ||
198 | |||
199 | //! return the flux variables cache | ||
200 | const GridFluxVariablesCache& gridFluxVarsCache() const | ||
201 | { return gridFluxVarsCache_; } | ||
202 | |||
203 | //! return the flux variables cache | ||
204 | GridFluxVariablesCache& gridFluxVarsCache() | ||
205 | { return gridFluxVarsCache_; } | ||
206 | |||
207 | //! return the current volume variables | ||
208 | const GridVolumeVariables& gridVolVars() const | ||
209 | { return gridVolVars_; } | ||
210 | |||
211 | //! return the current volume variables | ||
212 | GridVolumeVariables& gridVolVars() | ||
213 | { return gridVolVars_; } | ||
214 | |||
215 | private: | ||
216 | GridVolumeVariables gridVolVars_; //!< the current volume variables (primary and secondary variables) | ||
217 | GridFluxVariablesCache gridFluxVarsCache_; //!< the flux variables cache | ||
218 | }; | ||
219 | |||
220 | } // end namespace Dumux::Experimental | ||
221 | |||
222 | #endif | ||
223 |