3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
box/gridvolumevariables.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_DISCRETIZATION_BOX_GRID_VOLUMEVARIABLES_HH
25#define DUMUX_DISCRETIZATION_BOX_GRID_VOLUMEVARIABLES_HH
26
27#include <type_traits>
28
33
34namespace Dumux {
35
36template<class P, class VV>
38{
39 using Problem = P;
40 using VolumeVariables = VV;
41
42 template<class GridVolumeVariables, bool cachingEnabled>
44};
45
50template<class Problem,
51 class VolumeVariables,
52 bool enableGridVolVarsCache = false,
55
56// specialization in case of storing the volume variables
57template<class P, class VV, class Traits>
58class BoxGridVolumeVariables<P, VV, /*cachingEnabled*/true, Traits>
59{
61
62public:
64 using Problem = typename Traits::Problem;
65
67 using VolumeVariables = typename Traits::VolumeVariables;
68
70 static constexpr bool cachingEnabled = true;
71
73 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
74
75 BoxGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
76
77 template<class GridGeometry, class SolutionVector>
78 void update(const GridGeometry& gridGeometry, const SolutionVector& sol)
79 {
80 volumeVariables_.resize(gridGeometry.gridView().size(0));
81 for (const auto& element : elements(gridGeometry.gridView()))
82 {
83 auto eIdx = gridGeometry.elementMapper().index(element);
84
85 auto fvGeometry = localView(gridGeometry);
86 fvGeometry.bindElement(element);
87
88 // get the element solution
89 auto elemSol = elementSolution(element, sol, gridGeometry);
90
91 // update the volvars of the element
92 volumeVariables_[eIdx].resize(fvGeometry.numScv());
93 for (auto&& scv : scvs(fvGeometry))
94 volumeVariables_[eIdx][scv.indexInElement()].update(elemSol, problem(), element, scv);
95 }
96 }
97
98 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
99 const VolumeVariables& volVars(const SubControlVolume& scv) const
100 { return volumeVariables_[scv.elementIndex()][scv.indexInElement()]; }
101
102 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
103 VolumeVariables& volVars(const SubControlVolume& scv)
104 { return volumeVariables_[scv.elementIndex()][scv.indexInElement()]; }
105
106 const VolumeVariables& volVars(const std::size_t eIdx, const std::size_t scvIdx) const
107 { return volumeVariables_[eIdx][scvIdx]; }
108
109 VolumeVariables& volVars(const std::size_t eIdx, const std::size_t scvIdx)
110 { return volumeVariables_[eIdx][scvIdx]; }
111
112 const Problem& problem() const
113 { return *problemPtr_; }
114
115private:
116 const Problem* problemPtr_;
117 std::vector<std::vector<VolumeVariables>> volumeVariables_;
118};
119
120
121// Specialization when the current volume variables are not stored
122template<class P, class VV, class Traits>
123class BoxGridVolumeVariables<P, VV, /*cachingEnabled*/false, Traits>
124{
126
127public:
129 using Problem = typename Traits::Problem;
130
132 using VolumeVariables = typename Traits::VolumeVariables;
133
135 static constexpr bool cachingEnabled = false;
136
138 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
139
140 BoxGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
141
142 template<class GridGeometry, class SolutionVector>
143 void update(const GridGeometry& gridGeometry, const SolutionVector& sol) {}
144
145 const Problem& problem() const
146 { return *problemPtr_;}
147
148private:
149 const Problem* problemPtr_;
150};
151
152} // end namespace Dumux
153
154#endif
Free function to get the local view of a grid cache object.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethod::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:115
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
The local (stencil) volume variables class for box models.
Definition: box/elementvolumevariables.hh:41
Definition: box/gridvolumevariables.hh:38
VV VolumeVariables
Definition: box/gridvolumevariables.hh:40
P Problem
Definition: box/gridvolumevariables.hh:39
Base class for the grid volume variables.
Definition: box/gridvolumevariables.hh:54
Definition: box/gridvolumevariables.hh:59
const VolumeVariables & volVars(const SubControlVolume &scv) const
Definition: box/gridvolumevariables.hh:99
const Problem & problem() const
Definition: box/gridvolumevariables.hh:112
typename Traits::VolumeVariables VolumeVariables
export the volume variables type
Definition: box/gridvolumevariables.hh:67
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: box/gridvolumevariables.hh:78
VolumeVariables & volVars(const SubControlVolume &scv)
Definition: box/gridvolumevariables.hh:103
VolumeVariables & volVars(const std::size_t eIdx, const std::size_t scvIdx)
Definition: box/gridvolumevariables.hh:109
BoxGridVolumeVariables(const Problem &problem)
Definition: box/gridvolumevariables.hh:75
const VolumeVariables & volVars(const std::size_t eIdx, const std::size_t scvIdx) const
Definition: box/gridvolumevariables.hh:106
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: box/gridvolumevariables.hh:73
typename Traits::Problem Problem
export the problem type
Definition: box/gridvolumevariables.hh:64
Definition: box/gridvolumevariables.hh:124
const Problem & problem() const
Definition: box/gridvolumevariables.hh:145
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: box/gridvolumevariables.hh:138
typename Traits::VolumeVariables VolumeVariables
export the volume variables type
Definition: box/gridvolumevariables.hh:132
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: box/gridvolumevariables.hh:143
BoxGridVolumeVariables(const Problem &problem)
Definition: box/gridvolumevariables.hh:140
typename Traits::Problem Problem
export the problem type
Definition: box/gridvolumevariables.hh:129
The local element solution class for the box method.
The local volume variables class.