version 3.8
porenetwork/2p/gridfluxvariablescache.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_PNM_2P_GRID_FLUXVARSCACHE_HH
13#define DUMUX_PNM_2P_GRID_FLUXVARSCACHE_HH
14
19#include "invasionstate.hh"
20
21namespace Dumux::PoreNetwork {
22
27template<class P, class FVC, class IS = TwoPInvasionState<P>>
29{
30 using Problem = P;
31 using FluxVariablesCache = FVC;
32 using InvasionState = IS;
33
34 template<class GridFluxVariablesCache, bool cachingEnabled>
36};
37
43template<class Problem,
44 class FluxVariablesCache,
45 bool cachingEnabled,
46 class Traits>
48
54template<class P, class FVC, class Traits>
55class PNMTwoPGridFluxVariablesCache<P, FVC, true, Traits>
56{
57 using Problem = typename Traits::Problem;
59 using InvasionState = typename Traits::InvasionState;
60
61public:
63 using FluxVariablesCache = typename Traits::FluxVariablesCache;
64
66 static constexpr bool cachingEnabled = true;
67
69 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
70
71 PNMTwoPGridFluxVariablesCache(const Problem& problem)
72 : problemPtr_(&problem)
73 , invasionState_(problem) {}
74
75 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
76 void update(const GridGeometry& gridGeometry,
77 const GridVolumeVariables& gridVolVars,
78 const SolutionVector& sol,
79 bool forceUpdate = true)
80 {
81 fluxVarsCache_.resize(gridGeometry.gridView().size(0));
82 auto fvGeometry = localView(gridGeometry);
83 auto elemVolVars = localView(gridVolVars);
84 for (const auto& element : elements(gridGeometry.gridView()))
85 {
86 auto eIdx = gridGeometry.elementMapper().index(element);
87
88 // bind the geometries and volume variables to the element (all the elements in stencil)
89 fvGeometry.bind(element);
90 elemVolVars.bind(element, fvGeometry, sol);
91
92 for (auto&& scvf : scvfs(fvGeometry))
93 cache(eIdx, scvf.index()).update(problem(), element, fvGeometry, elemVolVars, scvf, invasionState().invaded(element));
94 }
95 }
96
97 template<class FVElementGeometry, class ElementVolumeVariables>
98 void updateElement(const typename FVElementGeometry::Element& element,
99 const FVElementGeometry& fvGeometry,
100 const ElementVolumeVariables& elemVolVars)
101 {
102 if constexpr (FluxVariablesCache::isSolDependent)
103 {
104 const auto eIdx = fvGeometry.gridGeometry().elementMapper().index(element);
105 for (const auto& scvf : scvfs(fvGeometry))
106 cache(eIdx, scvf.index()).update(problem(), element, fvGeometry, elemVolVars, scvf, invasionState().invaded(element));
107 }
108 }
109
110 const Problem& problem() const
111 { return *problemPtr_; }
112
113 // access operator
114 const FluxVariablesCache& cache(std::size_t eIdx, [[maybe_unused]] std::size_t scvfIdx) const
115 { return fluxVarsCache_[eIdx]; }
116
117 // access operator
118 FluxVariablesCache& cache(std::size_t eIdx, [[maybe_unused]] std::size_t scvfIdx)
119 { return fluxVarsCache_[eIdx]; }
120
121 const InvasionState& invasionState() const
122 { return invasionState_; }
123
124 InvasionState& invasionState()
125 { return invasionState_; }
126
127private:
128 const Problem* problemPtr_;
129 std::vector<FluxVariablesCache> fluxVarsCache_;
130 InvasionState invasionState_;
131};
132
138template<class P, class FVC, class Traits>
139class PNMTwoPGridFluxVariablesCache<P, FVC, false, Traits>
140{
141 using Problem = typename Traits::Problem;
143 using InvasionState = typename Traits::InvasionState;
144
145 public:
147 using FluxVariablesCache = typename Traits::FluxVariablesCache;
148
150 static constexpr bool cachingEnabled = false;
151
153 using LocalView = typename Traits::template LocalView<ThisType, cachingEnabled>;
154
155 PNMTwoPGridFluxVariablesCache(const Problem& problem)
156 : problemPtr_(&problem)
157 , invasionState_(problem) {}
158
159 template<class GridGeometry, class GridVolumeVariables, class SolutionVector>
160 void update(const GridGeometry& gridGeometry,
161 const GridVolumeVariables& gridVolVars,
162 const SolutionVector& sol,
163 bool forceUpdate = true) {}
164
165 const Problem& problem() const
166 { return *problemPtr_; }
167
168 const InvasionState& invasionState() const
169 { return invasionState_; }
170
171 InvasionState& invasionState()
172 { return invasionState_; }
173
174private:
175 const Problem* problemPtr_;
176 InvasionState invasionState_;
177};
178} // end namespace Dumux::PoreNetwork
179
180#endif
Base class for the finite volume geometry for porenetwork models.
Definition: discretization/porenetwork/gridgeometry.hh:477
The flux variables caches for an element.
Definition: porenetwork/2p/elementfluxvariablescache.hh:28
The grid flux variables cache for the two-phase PNM hodling the invasion state of the throats.
Definition: porenetwork/2p/gridfluxvariablescache.hh:140
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: porenetwork/2p/gridfluxvariablescache.hh:153
const Problem & problem() const
Definition: porenetwork/2p/gridfluxvariablescache.hh:165
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: porenetwork/2p/gridfluxvariablescache.hh:147
InvasionState & invasionState()
Definition: porenetwork/2p/gridfluxvariablescache.hh:171
const InvasionState & invasionState() const
Definition: porenetwork/2p/gridfluxvariablescache.hh:168
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=true)
Definition: porenetwork/2p/gridfluxvariablescache.hh:160
PNMTwoPGridFluxVariablesCache(const Problem &problem)
Definition: porenetwork/2p/gridfluxvariablescache.hh:155
The grid flux variables cache for the two-phase PNM hodling the invasion state of the throats.
Definition: porenetwork/2p/gridfluxvariablescache.hh:56
const FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx) const
Definition: porenetwork/2p/gridfluxvariablescache.hh:114
void update(const GridGeometry &gridGeometry, const GridVolumeVariables &gridVolVars, const SolutionVector &sol, bool forceUpdate=true)
Definition: porenetwork/2p/gridfluxvariablescache.hh:76
const Problem & problem() const
Definition: porenetwork/2p/gridfluxvariablescache.hh:110
FluxVariablesCache & cache(std::size_t eIdx, std::size_t scvfIdx)
Definition: porenetwork/2p/gridfluxvariablescache.hh:118
typename Traits::template LocalView< ThisType, cachingEnabled > LocalView
export the type of the local view
Definition: porenetwork/2p/gridfluxvariablescache.hh:69
InvasionState & invasionState()
Definition: porenetwork/2p/gridfluxvariablescache.hh:124
typename Traits::FluxVariablesCache FluxVariablesCache
export the flux variable cache type
Definition: porenetwork/2p/gridfluxvariablescache.hh:63
void updateElement(const typename FVElementGeometry::Element &element, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &elemVolVars)
Definition: porenetwork/2p/gridfluxvariablescache.hh:98
const InvasionState & invasionState() const
Definition: porenetwork/2p/gridfluxvariablescache.hh:121
PNMTwoPGridFluxVariablesCache(const Problem &problem)
Definition: porenetwork/2p/gridfluxvariablescache.hh:71
Flux variable caches on a gridview.
Definition: porenetwork/2p/gridfluxvariablescache.hh:47
Global flux variable cache.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
Invasion state class for the two-phase PNM.
Free function to get the local view of a grid cache object.
Definition: discretization/porenetwork/fvelementgeometry.hh:24
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
Element flux variable cache.
Flux variable caches traits.
Definition: porenetwork/2p/gridfluxvariablescache.hh:29
FVC FluxVariablesCache
Definition: porenetwork/2p/gridfluxvariablescache.hh:31
IS InvasionState
Definition: porenetwork/2p/gridfluxvariablescache.hh:32
P Problem
Definition: porenetwork/2p/gridfluxvariablescache.hh:30