version 3.8
experimental/assembly/fvlocalassemblerbase.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//
13#ifndef DUMUX_EXPERIMENTAL_FV_LOCAL_ASSEMBLER_BASE_HH
14#define DUMUX_EXPERIMENTAL_FV_LOCAL_ASSEMBLER_BASE_HH
15
16#include <dune/common/reservedvector.hh>
17#include <dune/grid/common/gridenums.hh> // for GhostEntity
18#include <dune/istl/matrixindexset.hh>
19
25
26namespace Dumux::Experimental {
27
36template<class TypeTag, class Assembler, class Implementation>
38{
44 using SolutionVector = typename Assembler::SolutionVector;
46 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
47 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
48 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
50 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
52 using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView;
53 using Element = typename GridView::template Codim<0>::Entity;
54 static constexpr auto numEq = GetPropType<TypeTag, Properties::ModelTraits>::numEq();
55
56public:
57 using LocalResidual = std::decay_t<decltype(std::declval<Assembler>().localResidual())>;
58 using ElementResidualVector = typename LocalResidual::ElementResidualVector;
59
63 explicit FVLocalAssemblerBase(const Assembler& assembler,
64 const Element& element,
65 const SolutionVector& curSol)
67 element,
68 curSol,
69 localView(assembler.gridGeometry()),
70 localView(assembler.gridVariables().curGridVolVars()),
71 localView(assembler.gridVariables().gridFluxVarsCache()),
73 element.partitionType() == Dune::GhostEntity,
75 {}
76
80 explicit FVLocalAssemblerBase(const Assembler& assembler,
81 const Element& element,
82 const SolutionVector& curSol,
83 const FVElementGeometry& fvGeometry,
84 const ElementVolumeVariables& curElemVolVars,
85 const ElementFluxVariablesCache& elemFluxVarsCache,
87 const bool elementIsGhost,
88 const bool isImplicit)
89 : assembler_(assembler)
90 , element_(element)
91 , curSol_(curSol)
92 , fvGeometry_(fvGeometry)
93 , curElemVolVars_(curElemVolVars)
94 , elemFluxVarsCache_(elemFluxVarsCache)
95 , localOperator_(localResidual)
96 , elementIsGhost_(elementIsGhost)
97 , isImplicit_(isImplicit)
98 {}
99
105 {
106 if (elementIsGhost())
107 return ElementResidualVector(0.0);
108
110 }
111
116 ElementResidualVector evalLocalResidual(const ElementVolumeVariables& elemVolVars) const
117 {
118 if (!assembler().isStationaryProblem())
119 {
121 residual += evalStorage();
122 return residual;
123 }
124 else
125 return evalLocalFluxAndSourceResidual(elemVolVars);
126 }
127
134 {
136 }
137
144 ElementResidualVector evalLocalFluxAndSourceResidual(const ElementVolumeVariables& elemVolVars) const
145 {
146 return localOperator_.evalFluxAndSource(element_, fvGeometry_, elemVolVars, elemFluxVarsCache_, elemBcTypes_);
147 }
148
155 {
156 return localOperator_.evalStorage(fvGeometry_, curElemVolVars_);
157 }
158
164 {
165 // get some references for convenience
166 const auto& element = this->element();
167 const auto& curSol = this->curSol();
168 auto&& fvGeometry = this->fvGeometry();
169 auto&& curElemVolVars = this->curElemVolVars();
170 auto&& elemFluxVarsCache = this->elemFluxVarsCache();
171
172 // bind the caches
173 fvGeometry.bind(element);
174 if (std::abs(this->localResidual().spatialWeight()) < 1e-6)
176 else
177 {
180 }
181 }
182
186 template<typename ApplyFunction, class P = Problem, typename std::enable_if_t<P::enableInternalDirichletConstraints(), int> = 0>
187 void enforceInternalDirichletConstraints(const ApplyFunction& applyDirichlet)
188 {
189 // enforce Dirichlet constraints strongly by overwriting partial derivatives with 1 or 0
190 // and set the residual to (privar - dirichletvalue)
191 for (const auto& scvI : scvs(this->fvGeometry()))
192 {
193 const auto internalDirichletConstraints = asImp_().problem().hasInternalDirichletConstraint(this->element(), scvI);
194 if (internalDirichletConstraints.any())
195 {
196 const auto dirichletValues = asImp_().problem().internalDirichlet(this->element(), scvI);
197 // set the Dirichlet conditions in residual and jacobian
198 for (int eqIdx = 0; eqIdx < internalDirichletConstraints.size(); ++eqIdx)
199 if (internalDirichletConstraints[eqIdx])
200 applyDirichlet(scvI, dirichletValues, eqIdx, eqIdx);
201 }
202 }
203 }
204
205 template<typename ApplyFunction, class P = Problem, typename std::enable_if_t<!P::enableInternalDirichletConstraints(), int> = 0>
206 void enforceInternalDirichletConstraints(const ApplyFunction& applyDirichlet)
207 {}
208
210 const Problem& problem() const
211 { return assembler_.problem(); }
212
214 const Assembler& assembler() const
215 { return assembler_; }
216
218 const Element& element() const
219 { return element_; }
220
222 bool elementIsGhost() const
223 { return elementIsGhost_; }
224
226 const SolutionVector& curSol() const
227 { return curSol_; }
228
230 FVElementGeometry& fvGeometry()
231 { return fvGeometry_; }
232
234 ElementVolumeVariables& curElemVolVars()
235 { return curElemVolVars_; }
236
238 ElementFluxVariablesCache& elemFluxVarsCache()
239 { return elemFluxVarsCache_; }
240
243 { return localOperator_; }
244
246 ElementBoundaryTypes& elemBcTypes()
247 { return elemBcTypes_; }
248
250 const FVElementGeometry& fvGeometry() const
251 { return fvGeometry_; }
252
254 const ElementVolumeVariables& curElemVolVars() const
255 { return curElemVolVars_; }
256
258 const ElementFluxVariablesCache& elemFluxVarsCache() const
259 { return elemFluxVarsCache_; }
260
262 const ElementBoundaryTypes& elemBcTypes() const
263 { return elemBcTypes_; }
264
267 { return localOperator_; }
268
270 bool isImplicit() const
271 { return isImplicit_; }
272
273protected:
274 Implementation &asImp_()
275 { return *static_cast<Implementation*>(this); }
276
277 const Implementation &asImp_() const
278 { return *static_cast<const Implementation*>(this); }
279
280 template<class T = TypeTag, typename std::enable_if_t<!GetPropType<T, Properties::GridVariables>::GridVolumeVariables::cachingEnabled, int> = 0>
281 VolumeVariables& getVolVarAccess(GridVolumeVariables& gridVolVars, ElementVolumeVariables& elemVolVars, const SubControlVolume& scv)
282 { return elemVolVars[scv]; }
283
284 template<class T = TypeTag, typename std::enable_if_t<GetPropType<T, Properties::GridVariables>::GridVolumeVariables::cachingEnabled, int> = 0>
285 VolumeVariables& getVolVarAccess(GridVolumeVariables& gridVolVars, ElementVolumeVariables& elemVolVars, const SubControlVolume& scv)
286 { return gridVolVars.volVars(scv); }
287
288private:
289
290 const Assembler& assembler_;
291 const Element& element_;
292 const SolutionVector& curSol_;
293
294 FVElementGeometry fvGeometry_;
295 ElementVolumeVariables curElemVolVars_;
296 ElementFluxVariablesCache elemFluxVarsCache_;
297 ElementBoundaryTypes elemBcTypes_;
298
299 LocalResidual localOperator_;
300 bool elementIsGhost_;
301 bool isImplicit_;
302};
303
304} // end namespace Dumux
305
306#endif
A base class for all local assemblers.
Definition: experimental/assembly/fvlocalassemblerbase.hh:38
const ElementBoundaryTypes & elemBcTypes() const
The element's boundary types.
Definition: experimental/assembly/fvlocalassemblerbase.hh:262
ElementVolumeVariables & curElemVolVars()
The current element volume variables.
Definition: experimental/assembly/fvlocalassemblerbase.hh:234
const ElementVolumeVariables & curElemVolVars() const
The current element volume variables.
Definition: experimental/assembly/fvlocalassemblerbase.hh:254
bool isImplicit() const
If the time stepping scheme is implicit.
Definition: experimental/assembly/fvlocalassemblerbase.hh:270
void bindLocalViews()
Convenience function bind and prepare all relevant variables required for the evaluation of the local...
Definition: experimental/assembly/fvlocalassemblerbase.hh:163
ElementResidualVector evalLocalResidual() const
Convenience function to evaluate the complete local residual for the current element....
Definition: experimental/assembly/fvlocalassemblerbase.hh:104
const ElementFluxVariablesCache & elemFluxVarsCache() const
The element flux variables cache.
Definition: experimental/assembly/fvlocalassemblerbase.hh:258
bool elementIsGhost() const
Returns if element is a ghost entity.
Definition: experimental/assembly/fvlocalassemblerbase.hh:222
ElementResidualVector evalLocalFluxAndSourceResidual() const
Convenience function to evaluate the flux and source terms (i.e, the terms without a time derivative)...
Definition: experimental/assembly/fvlocalassemblerbase.hh:133
ElementResidualVector evalStorage() const
Convenience function to evaluate storage term (i.e, the term with a time derivative) of the local res...
Definition: experimental/assembly/fvlocalassemblerbase.hh:154
const FVElementGeometry & fvGeometry() const
The finite volume geometry.
Definition: experimental/assembly/fvlocalassemblerbase.hh:250
const Problem & problem() const
The problem.
Definition: experimental/assembly/fvlocalassemblerbase.hh:210
LocalResidual & localResidual()
The local residual for the current element.
Definition: experimental/assembly/fvlocalassemblerbase.hh:242
const Implementation & asImp_() const
Definition: experimental/assembly/fvlocalassemblerbase.hh:277
void enforceInternalDirichletConstraints(const ApplyFunction &applyDirichlet)
Enforces Dirichlet constraints if enabled in the problem.
Definition: experimental/assembly/fvlocalassemblerbase.hh:187
VolumeVariables & getVolVarAccess(GridVolumeVariables &gridVolVars, ElementVolumeVariables &elemVolVars, const SubControlVolume &scv)
Definition: experimental/assembly/fvlocalassemblerbase.hh:281
const Element & element() const
The current element.
Definition: experimental/assembly/fvlocalassemblerbase.hh:218
ElementResidualVector evalLocalFluxAndSourceResidual(const ElementVolumeVariables &elemVolVars) const
Evaluates the flux and source terms (i.e, the terms without a time derivative) of the local residual ...
Definition: experimental/assembly/fvlocalassemblerbase.hh:144
const LocalResidual & localResidual() const
The local residual for the current element.
Definition: experimental/assembly/fvlocalassemblerbase.hh:266
const SolutionVector & curSol() const
The current solution.
Definition: experimental/assembly/fvlocalassemblerbase.hh:226
FVLocalAssemblerBase(const Assembler &assembler, const Element &element, const SolutionVector &curSol)
The constructor. Delegates to the general constructor.
Definition: experimental/assembly/fvlocalassemblerbase.hh:63
typename LocalResidual::ElementResidualVector ElementResidualVector
Definition: experimental/assembly/fvlocalassemblerbase.hh:58
ElementResidualVector evalLocalResidual(const ElementVolumeVariables &elemVolVars) const
Evaluates the complete local residual for the current element.
Definition: experimental/assembly/fvlocalassemblerbase.hh:116
const Assembler & assembler() const
The assembler.
Definition: experimental/assembly/fvlocalassemblerbase.hh:214
FVElementGeometry & fvGeometry()
The global finite volume geometry.
Definition: experimental/assembly/fvlocalassemblerbase.hh:230
Implementation & asImp_()
Definition: experimental/assembly/fvlocalassemblerbase.hh:274
ElementFluxVariablesCache & elemFluxVarsCache()
The element flux variables cache.
Definition: experimental/assembly/fvlocalassemblerbase.hh:238
FVLocalAssemblerBase(const Assembler &assembler, const Element &element, const SolutionVector &curSol, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const LocalResidual &localResidual, const bool elementIsGhost, const bool isImplicit)
The constructor. General version explicitly expecting each argument.
Definition: experimental/assembly/fvlocalassemblerbase.hh:80
ElementBoundaryTypes & elemBcTypes()
The element's boundary types.
Definition: experimental/assembly/fvlocalassemblerbase.hh:246
std::decay_t< decltype(std::declval< Assembler >().localResidual())> LocalResidual
Definition: experimental/assembly/fvlocalassemblerbase.hh:57
Defines all properties used in Dumux.
An enum class to define various differentiation methods available in order to compute the derivatives...
Helper classes to compute the integration elements.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:26
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:296
Definition: experimental/assembly/cclocalassembler.hh:36
Definition: common/pdesolver.hh:24
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
A arithmetic block vector type based on DUNE's reserved vector.