version 3.10-dev
cvfe/elementvolumevariables.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// SPDX-FileCopyrightInfo: Copyright © DuMux Project contributors, see AUTHORS.md in root folder
5// SPDX-License-Identifier: GPL-3.0-or-later
6//
12#ifndef DUMUX_DISCRETIZATION_CVFE_ELEMENT_VOLUMEVARIABLES_HH
13#define DUMUX_DISCRETIZATION_CVFE_ELEMENT_VOLUMEVARIABLES_HH
14
15#include <type_traits>
16#include <utility>
17#include <vector>
18
20
21namespace Dumux {
22
30template<class GVV, bool cachingEnabled>
32
38template<class GVV>
39class CVFEElementVolumeVariables<GVV, /*cachingEnabled*/true>
40{
41public:
44
46 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
47
50 : gridVolVarsPtr_(&gridVolVars) {}
51
52 const VolumeVariables& operator [](std::size_t scvIdx) const
53 { return gridVolVars().volVars(eIdx_, scvIdx); }
54
55 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
56 const VolumeVariables& operator [](const SubControlVolume& scv) const
57 { return gridVolVars().volVars(eIdx_, scv.indexInElement()); }
58
64 template<class FVElementGeometry, class SolutionVector>
65 CVFEElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
66 const FVElementGeometry& fvGeometry,
67 const SolutionVector& sol) &&
68 {
69 this->bindElement(element, fvGeometry, sol);
70 return std::move(*this);
71 }
72
73 // For compatibility reasons with the case of not storing the vol vars.
74 // function to be called before assembling an element, preparing the vol vars within the stencil
75 template<class FVElementGeometry, class SolutionVector>
76 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
77 const FVElementGeometry& fvGeometry,
78 const SolutionVector& sol) &
79 {
80 bindElement(element, fvGeometry, sol);
81 }
82
88 template<class FVElementGeometry, class SolutionVector>
89 CVFEElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
90 const FVElementGeometry& fvGeometry,
91 const SolutionVector& sol) &&
92 {
93 this->bindElement(element, fvGeometry, sol);
94 return std::move(*this);
95 }
96
97 // function to prepare the vol vars within the element
98 template<class FVElementGeometry, class SolutionVector>
99 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
100 const FVElementGeometry& fvGeometry,
101 const SolutionVector& sol) &
102 {
103 eIdx_ = fvGeometry.gridGeometry().elementMapper().index(element);
104 }
105
108 { return *gridVolVarsPtr_; }
109
110private:
111 const GridVolumeVariables* gridVolVarsPtr_;
112 std::size_t eIdx_;
113};
114
115
120template<class GVV>
121class CVFEElementVolumeVariables<GVV, /*cachingEnabled*/false>
122{
123public:
126
128 using VolumeVariables = typename GridVolumeVariables::VolumeVariables;
129
132 : gridVolVarsPtr_(&gridVolVars) {}
133
139 template<class FVElementGeometry, class SolutionVector>
140 CVFEElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
141 const FVElementGeometry& fvGeometry,
142 const SolutionVector& sol) &&
143 {
144 this->bindElement(element, fvGeometry, sol);
145 return std::move(*this);
146 }
147
148 // specialization for control-volume finite element, simply forwards to the bindElement method
149 template<class FVElementGeometry, class SolutionVector>
150 void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
151 const FVElementGeometry& fvGeometry,
152 const SolutionVector& sol) &
153 {
154 bindElement(element, fvGeometry, sol);
155 }
156
162 template<class FVElementGeometry, class SolutionVector>
163 CVFEElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
164 const FVElementGeometry& fvGeometry,
165 const SolutionVector& sol) &&
166 {
167 this->bindElement(element, fvGeometry, sol);
168 return std::move(*this);
169 }
170
171 // specialization for control-volume finite element
172 template<class FVElementGeometry, class SolutionVector>
173 void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim<0>::Entity& element,
174 const FVElementGeometry& fvGeometry,
175 const SolutionVector& sol) &
176 {
177 // get the solution at the dofs of the element
178 auto elemSol = elementSolution(element, sol, fvGeometry.gridGeometry());
179
180 // resize volume variables to the required size
181 volumeVariables_.resize(fvGeometry.numScv());
182 for (auto&& scv : scvs(fvGeometry))
183 volumeVariables_[scv.indexInElement()].update(elemSol, gridVolVars().problem(), element, scv);
184 }
185
186 const VolumeVariables& operator [](std::size_t scvIdx) const
187 { return volumeVariables_[scvIdx]; }
188
189 VolumeVariables& operator [](std::size_t scvIdx)
190 { return volumeVariables_[scvIdx]; }
191
192 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
193 const VolumeVariables& operator [](const SubControlVolume& scv) const
194 { return volumeVariables_[scv.indexInElement()]; }
195
196 template<class SubControlVolume, typename std::enable_if_t<!std::is_integral<SubControlVolume>::value, int> = 0>
197 VolumeVariables& operator [](const SubControlVolume& scv)
198 { return volumeVariables_[scv.indexInElement()]; }
199
202 { return *gridVolVarsPtr_; }
203
204private:
205 const GridVolumeVariables* gridVolVarsPtr_;
206 std::vector<VolumeVariables> volumeVariables_;
207};
208
209} // end namespace Dumux
210
211#endif
CVFEElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: cvfe/elementvolumevariables.hh:140
GVV GridVolumeVariables
export type of the grid volume variables
Definition: cvfe/elementvolumevariables.hh:125
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: cvfe/elementvolumevariables.hh:201
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: cvfe/elementvolumevariables.hh:150
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: cvfe/elementvolumevariables.hh:128
CVFEElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: cvfe/elementvolumevariables.hh:131
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: cvfe/elementvolumevariables.hh:173
CVFEElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: cvfe/elementvolumevariables.hh:163
void bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: cvfe/elementvolumevariables.hh:76
void bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &
Definition: cvfe/elementvolumevariables.hh:99
CVFEElementVolumeVariables(const GridVolumeVariables &gridVolVars)
Constructor.
Definition: cvfe/elementvolumevariables.hh:49
const GridVolumeVariables & gridVolVars() const
The global volume variables object we are a restriction of.
Definition: cvfe/elementvolumevariables.hh:107
CVFEElementVolumeVariables bind(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: cvfe/elementvolumevariables.hh:65
typename GridVolumeVariables::VolumeVariables VolumeVariables
export type of the volume variables
Definition: cvfe/elementvolumevariables.hh:46
GVV GridVolumeVariables
export type of the grid volume variables
Definition: cvfe/elementvolumevariables.hh:43
CVFEElementVolumeVariables bindElement(const typename FVElementGeometry::GridGeometry::GridView::template Codim< 0 >::Entity &element, const FVElementGeometry &fvGeometry, const SolutionVector &sol) &&
bind the local view (r-value overload) This overload is called when an instance of this class is a te...
Definition: cvfe/elementvolumevariables.hh:89
The local (stencil) volume variables class for control-volume finite element.
Definition: cvfe/elementvolumevariables.hh:31
Element solution classes and factory functions.
auto elementSolution(const Element &element, const SolutionVector &sol, const GridGeometry &gg) -> std::enable_if_t< GridGeometry::discMethod==DiscretizationMethods::cctpfa||GridGeometry::discMethod==DiscretizationMethods::ccmpfa, CCElementSolution< typename GridGeometry::LocalView, std::decay_t< decltype(std::declval< SolutionVector >()[0])> > >
Make an element solution for cell-centered schemes.
Definition: cellcentered/elementsolution.hh:101
Definition: adapt.hh:17