3.5-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
29// make the local view function available whenever we use this class
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 auto fvGeometry = localView(gridGeometry);
82 for (const auto& element : elements(gridGeometry.gridView()))
83 {
84 auto eIdx = gridGeometry.elementMapper().index(element);
85 fvGeometry.bindElement(element);
86
87 // get the element solution
88 auto elemSol = elementSolution(element, sol, gridGeometry);
89
90 // update the volvars of the element
91 volumeVariables_[eIdx].resize(fvGeometry.numScv());
92 for (auto&& scv : scvs(fvGeometry))
93 volumeVariables_[eIdx][scv.indexInElement()].update(elemSol, problem(), element, scv);
94 }
95 }
96
97 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
98 const VolumeVariables& volVars(const SubControlVolume& scv) const
99 { return volumeVariables_[scv.elementIndex()][scv.indexInElement()]; }
100
101 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
102 VolumeVariables& volVars(const SubControlVolume& scv)
103 { return volumeVariables_[scv.elementIndex()][scv.indexInElement()]; }
104
105 const VolumeVariables& volVars(const std::size_t eIdx, const std::size_t scvIdx) const
106 { return volumeVariables_[eIdx][scvIdx]; }
107
108 VolumeVariables& volVars(const std::size_t eIdx, const std::size_t scvIdx)
109 { return volumeVariables_[eIdx][scvIdx]; }
110
111 const Problem& problem() const
112 { return *problemPtr_; }
113
114private:
115 const Problem* problemPtr_;
116 std::vector<std::vector<VolumeVariables>> volumeVariables_;
117};
118
119
120// Specialization when the current volume variables are not stored
121template<class P, class VV, class Traits>
122class BoxGridVolumeVariables<P, VV, /*cachingEnabled*/false, Traits>
123{
125
126public:
128 using Problem = typename Traits::Problem;
129
131 using VolumeVariables = typename Traits::VolumeVariables;
132
134 static constexpr bool cachingEnabled = false;
135
137 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
138
139 BoxGridVolumeVariables(const Problem& problem) : problemPtr_(&problem) {}
140
141 template<class GridGeometry, class SolutionVector>
142 void update(const GridGeometry& gridGeometry, const SolutionVector& sol) {}
143
144 const Problem& problem() const
145 { return *problemPtr_;}
146
147private:
148 const Problem* problemPtr_;
149};
150
151} // end namespace Dumux
152
153#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==DiscretizationMethods::box, BoxElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for box schemes.
Definition: box/elementsolution.hh:118
Definition: adapt.hh:29
The local (stencil) volume variables class for box models.
Definition: box/elementvolumevariables.hh:42
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:98
const Problem & problem() const
Definition: box/gridvolumevariables.hh:111
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:102
VolumeVariables & volVars(const std::size_t eIdx, const std::size_t scvIdx)
Definition: box/gridvolumevariables.hh:108
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:105
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:123
const Problem & problem() const
Definition: box/gridvolumevariables.hh:144
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: box/gridvolumevariables.hh:137
typename Traits::VolumeVariables VolumeVariables
export the volume variables type
Definition: box/gridvolumevariables.hh:131
void update(const GridGeometry &gridGeometry, const SolutionVector &sol)
Definition: box/gridvolumevariables.hh:142
BoxGridVolumeVariables(const Problem &problem)
Definition: box/gridvolumevariables.hh:139
typename Traits::Problem Problem
export the problem type
Definition: box/gridvolumevariables.hh:128
The local element solution class for the box method.
The local volume variables class.