3.1-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * 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_FV_LOCAL_ASSEMBLER_BASE_HH
25#define DUMUX_FV_LOCAL_ASSEMBLER_BASE_HH
26
27#include <dune/common/reservedvector.hh>
28#include <dune/grid/common/gridenums.hh> // for GhostEntity
29#include <dune/istl/matrixindexset.hh>
30
35
36namespace Dumux {
37
46template<class TypeTag, class Assembler, class Implementation, bool useImplicitAssembly>
48{
54 using SolutionVector = typename Assembler::ResidualType;
56 using FVElementGeometry = typename GetPropType<TypeTag, Properties::GridGeometry>::LocalView;
57 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
58 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
60 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
62 using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView;
63 using Element = typename GridView::template Codim<0>::Entity;
64 static constexpr auto numEq = GetPropType<TypeTag, Properties::ModelTraits>::numEq();
65
66public:
68 using ElementResidualVector = typename LocalResidual::ElementResidualVector;
69
73 explicit FVLocalAssemblerBase(const Assembler& assembler,
74 const Element& element,
75 const SolutionVector& curSol)
77 element,
78 curSol,
79 localView(assembler.gridGeometry()),
80 localView(assembler.gridVariables().curGridVolVars()),
81 localView(assembler.gridVariables().prevGridVolVars()),
82 localView(assembler.gridVariables().gridFluxVarsCache()),
84 element.partitionType() == Dune::GhostEntity)
85 {}
86
90 explicit FVLocalAssemblerBase(const Assembler& assembler,
91 const Element& element,
92 const SolutionVector& curSol,
93 const FVElementGeometry& fvGeometry,
94 const ElementVolumeVariables& curElemVolVars,
95 const ElementVolumeVariables& prevElemVolVars,
96 const ElementFluxVariablesCache& elemFluxVarsCache,
98 const bool elementIsGhost)
99 : assembler_(assembler)
100 , element_(element)
101 , curSol_(curSol)
102 , fvGeometry_(fvGeometry)
103 , curElemVolVars_(curElemVolVars)
104 , prevElemVolVars_(prevElemVolVars)
105 , elemFluxVarsCache_(elemFluxVarsCache)
106 , localResidual_(localResidual)
107 , elementIsGhost_(elementIsGhost)
108 {}
109
113 static constexpr bool isImplicit()
114 { return useImplicitAssembly; }
115
121 {
122 if (!isImplicit())
123 if (this->assembler().isStationaryProblem())
124 DUNE_THROW(Dune::InvalidStateException, "Using explicit jacobian assembler with stationary local residual");
125
126 if (elementIsGhost())
127 return ElementResidualVector(0.0);
128
131 }
132
137 ElementResidualVector evalLocalResidual(const ElementVolumeVariables& elemVolVars) const
138 {
139 if (!assembler().isStationaryProblem())
140 {
142 residual += evalLocalStorageResidual();
143 return residual;
144 }
145 else
146 return evalLocalFluxAndSourceResidual(elemVolVars);
147 }
148
155 {
158 }
159
166 ElementResidualVector evalLocalFluxAndSourceResidual(const ElementVolumeVariables& elemVolVars) const
167 {
168 return localResidual_.evalFluxAndSource(element_, fvGeometry_, elemVolVars, elemFluxVarsCache_, elemBcTypes_);
169 }
170
177 {
178 return localResidual_.evalStorage(element_, fvGeometry_, prevElemVolVars_, curElemVolVars_);
179 }
180
186 {
187 // get some references for convenience
188 const auto& element = this->element();
189 const auto& curSol = this->curSol();
190 const auto& prevSol = this->assembler().prevSol();
191 auto&& fvGeometry = this->fvGeometry();
192 auto&& curElemVolVars = this->curElemVolVars();
193 auto&& prevElemVolVars = this->prevElemVolVars();
194 auto&& elemFluxVarsCache = this->elemFluxVarsCache();
195
196 // bind the caches
197 fvGeometry.bind(element);
198
199 if (isImplicit())
200 {
203 if (!this->assembler().isStationaryProblem())
204 prevElemVolVars.bindElement(element, fvGeometry, this->assembler().prevSol());
205 }
206 else
207 {
209 prevElemVolVars.bind(element, fvGeometry, prevSol);
211 }
212 }
213
217 template<typename ApplyFunction, class P = Problem, typename std::enable_if_t<P::enableInternalDirichletConstraints(), int> = 0>
218 void enforceInternalDirichletConstraints(const ApplyFunction& applyDirichlet)
219 {
220 // enforce Dirichlet constraints strongly by overwriting partial derivatives with 1 or 0
221 // and set the residual to (privar - dirichletvalue)
222 for (const auto& scvI : scvs(this->fvGeometry()))
223 {
224 if (this->problem().hasInternalDirichletConstraint(this->element(), scvI))
225 {
226 const auto dirichletValues = this->problem().internalDirichlet(this->element(), scvI);
227 // set the Dirichlet conditions in residual and jacobian
228 for (int eqIdx = 0; eqIdx < numEq; ++eqIdx)
229 applyDirichlet(scvI, dirichletValues, eqIdx, eqIdx);
230 }
231 }
232 }
233
234 template<typename ApplyFunction, class P = Problem, typename std::enable_if_t<!P::enableInternalDirichletConstraints(), int> = 0>
235 void enforceInternalDirichletConstraints(const ApplyFunction& applyDirichlet)
236 {}
237
239 const Problem& problem() const
240 { return assembler_.problem(); }
241
243 const Assembler& assembler() const
244 { return assembler_; }
245
247 const Element& element() const
248 { return element_; }
249
251 bool elementIsGhost() const
252 { return elementIsGhost_; }
253
255 const SolutionVector& curSol() const
256 { return curSol_; }
257
259 FVElementGeometry& fvGeometry()
260 { return fvGeometry_; }
261
263 ElementVolumeVariables& curElemVolVars()
264 { return curElemVolVars_; }
265
267 ElementVolumeVariables& prevElemVolVars()
268 { return prevElemVolVars_; }
269
271 ElementFluxVariablesCache& elemFluxVarsCache()
272 { return elemFluxVarsCache_; }
273
276 { return localResidual_; }
277
279 ElementBoundaryTypes& elemBcTypes()
280 { return elemBcTypes_; }
281
283 const FVElementGeometry& fvGeometry() const
284 { return fvGeometry_; }
285
287 const ElementVolumeVariables& curElemVolVars() const
288 { return curElemVolVars_; }
289
291 const ElementVolumeVariables& prevElemVolVars() const
292 { return prevElemVolVars_; }
293
295 const ElementFluxVariablesCache& elemFluxVarsCache() const
296 { return elemFluxVarsCache_; }
297
299 const ElementBoundaryTypes& elemBcTypes() const
300 { return elemBcTypes_; }
301
304 { return localResidual_; }
305
306protected:
307 Implementation &asImp_()
308 { return *static_cast<Implementation*>(this); }
309
310 const Implementation &asImp_() const
311 { return *static_cast<const Implementation*>(this); }
312
313 template<class T = TypeTag, typename std::enable_if_t<!getPropValue<T, Properties::EnableGridVolumeVariablesCache>(), int> = 0>
314 VolumeVariables& getVolVarAccess(GridVolumeVariables& gridVolVars, ElementVolumeVariables& elemVolVars, const SubControlVolume& scv)
315 { return elemVolVars[scv]; }
316
317 template<class T = TypeTag, typename std::enable_if_t<getPropValue<T, Properties::EnableGridVolumeVariablesCache>(), int> = 0>
318 VolumeVariables& getVolVarAccess(GridVolumeVariables& gridVolVars, ElementVolumeVariables& elemVolVars, const SubControlVolume& scv)
319 { return gridVolVars.volVars(scv); }
320
321private:
322
323 const Assembler& assembler_;
324 const Element& element_;
325 const SolutionVector& curSol_;
326
327 FVElementGeometry fvGeometry_;
328 ElementVolumeVariables curElemVolVars_;
329 ElementVolumeVariables prevElemVolVars_;
330 ElementFluxVariablesCache elemFluxVarsCache_;
331 ElementBoundaryTypes elemBcTypes_;
332
333 LocalResidual localResidual_;
334 bool elementIsGhost_;
335};
336
337
338} // end namespace Dumux
339
340#endif
An enum class to define various differentiation methods available in order to compute the derivatives...
The infrastructure to retrieve run-time parameters from Dune::ParameterTrees.
A arithmetic block vector type based on DUNE's reserved vector.
GridCache::LocalView localView(const GridCache &gridCache)
Free function to get the local view of a grid cache object.
Definition: localview.hh:38
make the local view function available whenever we use the grid geometry
Definition: adapt.hh:29
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:149
Definition: common/properties/model.hh:34
A base class for all local assemblers.
Definition: fvlocalassemblerbase.hh:48
const ElementVolumeVariables & prevElemVolVars() const
The element volume variables of the provious time step.
Definition: fvlocalassemblerbase.hh:291
void bindLocalViews()
Convenience function bind and prepare all relevant variables required for the evaluation of the local...
Definition: fvlocalassemblerbase.hh:185
ElementResidualVector evalLocalResidual(const ElementVolumeVariables &elemVolVars) const
Evaluates the complete local residual for the current element.
Definition: fvlocalassemblerbase.hh:137
ElementVolumeVariables & curElemVolVars()
The current element volume variables.
Definition: fvlocalassemblerbase.hh:263
typename LocalResidual::ElementResidualVector ElementResidualVector
Definition: fvlocalassemblerbase.hh:68
ElementBoundaryTypes & elemBcTypes()
The element's boundary types.
Definition: fvlocalassemblerbase.hh:279
Implementation & asImp_()
Definition: fvlocalassemblerbase.hh:307
ElementVolumeVariables & prevElemVolVars()
The element volume variables of the provious time step.
Definition: fvlocalassemblerbase.hh:267
ElementResidualVector evalLocalResidual() const
Convenience function to evaluate the complete local residual for the current element....
Definition: fvlocalassemblerbase.hh:120
const Problem & problem() const
The problem.
Definition: fvlocalassemblerbase.hh:239
const ElementBoundaryTypes & elemBcTypes() const
The element's boundary types.
Definition: fvlocalassemblerbase.hh:299
const ElementFluxVariablesCache & elemFluxVarsCache() const
The element flux variables cache.
Definition: fvlocalassemblerbase.hh:295
const Implementation & asImp_() const
Definition: fvlocalassemblerbase.hh:310
FVLocalAssemblerBase(const Assembler &assembler, const Element &element, const SolutionVector &curSol, const FVElementGeometry &fvGeometry, const ElementVolumeVariables &curElemVolVars, const ElementVolumeVariables &prevElemVolVars, const ElementFluxVariablesCache &elemFluxVarsCache, const LocalResidual &localResidual, const bool elementIsGhost)
The constructor. General version explicitly expecting each argument.
Definition: fvlocalassemblerbase.hh:90
const ElementVolumeVariables & curElemVolVars() const
The current element volume variables.
Definition: fvlocalassemblerbase.hh:287
FVLocalAssemblerBase(const Assembler &assembler, const Element &element, const SolutionVector &curSol)
The constructor. Delegates to the general constructor.
Definition: fvlocalassemblerbase.hh:73
const LocalResidual & localResidual() const
The local residual for the current element.
Definition: fvlocalassemblerbase.hh:303
FVElementGeometry & fvGeometry()
The global finite volume geometry.
Definition: fvlocalassemblerbase.hh:259
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: fvlocalassemblerbase.hh:166
const Assembler & assembler() const
The assembler.
Definition: fvlocalassemblerbase.hh:243
ElementFluxVariablesCache & elemFluxVarsCache()
The element flux variables cache.
Definition: fvlocalassemblerbase.hh:271
bool elementIsGhost() const
Returns if element is a ghost entity.
Definition: fvlocalassemblerbase.hh:251
LocalResidual & localResidual()
The local residual for the current element.
Definition: fvlocalassemblerbase.hh:275
static constexpr bool isImplicit()
Returns true if the assembler considers implicit assembly.
Definition: fvlocalassemblerbase.hh:113
ElementResidualVector evalLocalFluxAndSourceResidual() const
Convenience function to evaluate the flux and source terms (i.e, the terms without a time derivative)...
Definition: fvlocalassemblerbase.hh:154
void enforceInternalDirichletConstraints(const ApplyFunction &applyDirichlet)
Enforces Dirichlet constraints if enabled in the problem.
Definition: fvlocalassemblerbase.hh:218
const Element & element() const
The current element.
Definition: fvlocalassemblerbase.hh:247
VolumeVariables & getVolVarAccess(GridVolumeVariables &gridVolVars, ElementVolumeVariables &elemVolVars, const SubControlVolume &scv)
Definition: fvlocalassemblerbase.hh:314
const FVElementGeometry & fvGeometry() const
The finite volume geometry.
Definition: fvlocalassemblerbase.hh:283
GetPropType< TypeTag, Properties::LocalResidual > LocalResidual
Definition: fvlocalassemblerbase.hh:67
ElementResidualVector evalLocalStorageResidual() const
Convenience function to evaluate storage term (i.e, the term with a time derivative) of the local res...
Definition: fvlocalassemblerbase.hh:176
const SolutionVector & curSol() const
The current solution.
Definition: fvlocalassemblerbase.hh:255
Declares all properties used in Dumux.