3.6-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 const auto internalDirichletConstraints = asImp_().problem().hasInternalDirichletConstraint(this->element(), scvI);
225 if (internalDirichletConstraints.any())
226 {
227 const auto dirichletValues = asImp_().problem().internalDirichlet(this->element(), scvI);
228 // set the Dirichlet conditions in residual and jacobian
229 for (int eqIdx = 0; eqIdx < internalDirichletConstraints.size(); ++eqIdx)
230 if (internalDirichletConstraints[eqIdx])
231 applyDirichlet(scvI, dirichletValues, eqIdx, eqIdx);
232 }
233 }
234 }
235
236 template<typename ApplyFunction, class P = Problem, typename std::enable_if_t<!P::enableInternalDirichletConstraints(), int> = 0>
237 void enforceInternalDirichletConstraints(const ApplyFunction& applyDirichlet)
238 {}
239
241 const Problem& problem() const
242 { return assembler_.problem(); }
243
245 const Assembler& assembler() const
246 { return assembler_; }
247
249 const Element& element() const
250 { return element_; }
251
253 bool elementIsGhost() const
254 { return elementIsGhost_; }
255
257 const SolutionVector& curSol() const
258 { return curSol_; }
259
261 FVElementGeometry& fvGeometry()
262 { return fvGeometry_; }
263
265 ElementVolumeVariables& curElemVolVars()
266 { return curElemVolVars_; }
267
269 ElementVolumeVariables& prevElemVolVars()
270 { return prevElemVolVars_; }
271
273 ElementFluxVariablesCache& elemFluxVarsCache()
274 { return elemFluxVarsCache_; }
275
278 { return localResidual_; }
279
281 ElementBoundaryTypes& elemBcTypes()
282 { return elemBcTypes_; }
283
285 const FVElementGeometry& fvGeometry() const
286 { return fvGeometry_; }
287
289 const ElementVolumeVariables& curElemVolVars() const
290 { return curElemVolVars_; }
291
293 const ElementVolumeVariables& prevElemVolVars() const
294 { return prevElemVolVars_; }
295
297 const ElementFluxVariablesCache& elemFluxVarsCache() const
298 { return elemFluxVarsCache_; }
299
301 const ElementBoundaryTypes& elemBcTypes() const
302 { return elemBcTypes_; }
303
306 { return localResidual_; }
307
308protected:
309 Implementation &asImp_()
310 { return *static_cast<Implementation*>(this); }
311
312 const Implementation &asImp_() const
313 { return *static_cast<const Implementation*>(this); }
314
315 template<class T = TypeTag, typename std::enable_if_t<!GetPropType<T, Properties::GridVariables>::GridVolumeVariables::cachingEnabled, int> = 0>
316 VolumeVariables& getVolVarAccess(GridVolumeVariables& gridVolVars, ElementVolumeVariables& elemVolVars, const SubControlVolume& scv)
317 { return elemVolVars[scv]; }
318
319 template<class T = TypeTag, typename std::enable_if_t<GetPropType<T, Properties::GridVariables>::GridVolumeVariables::cachingEnabled, int> = 0>
320 VolumeVariables& getVolVarAccess(GridVolumeVariables& gridVolVars, ElementVolumeVariables& elemVolVars, const SubControlVolume& scv)
321 { return gridVolVars.volVars(scv); }
322
323private:
324
325 const Assembler& assembler_;
326 const Element& element_;
327 const SolutionVector& curSol_;
328
329 FVElementGeometry fvGeometry_;
330 ElementVolumeVariables curElemVolVars_;
331 ElementVolumeVariables prevElemVolVars_;
332 ElementFluxVariablesCache elemFluxVarsCache_;
333 ElementBoundaryTypes elemBcTypes_;
334
335 LocalResidual localResidual_;
336 bool elementIsGhost_;
337};
338
339
340} // end namespace Dumux
341
342#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
Adaption of the non-isothermal two-phase two-component flow model to problems with CO2.
Definition: adapt.hh:29
typename GetProp< TypeTag, Property >::type GetPropType
get the type alias defined in the property
Definition: propertysystem.hh:180
Definition: deprecated.hh:149
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:293
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:265
typename LocalResidual::ElementResidualVector ElementResidualVector
Definition: fvlocalassemblerbase.hh:68
ElementBoundaryTypes & elemBcTypes()
The element's boundary types.
Definition: fvlocalassemblerbase.hh:281
Implementation & asImp_()
Definition: fvlocalassemblerbase.hh:309
ElementVolumeVariables & prevElemVolVars()
The element volume variables of the provious time step.
Definition: fvlocalassemblerbase.hh:269
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:241
const ElementBoundaryTypes & elemBcTypes() const
The element's boundary types.
Definition: fvlocalassemblerbase.hh:301
const ElementFluxVariablesCache & elemFluxVarsCache() const
The element flux variables cache.
Definition: fvlocalassemblerbase.hh:297
const Implementation & asImp_() const
Definition: fvlocalassemblerbase.hh:312
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:289
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:305
FVElementGeometry & fvGeometry()
The global finite volume geometry.
Definition: fvlocalassemblerbase.hh:261
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:245
ElementFluxVariablesCache & elemFluxVarsCache()
The element flux variables cache.
Definition: fvlocalassemblerbase.hh:273
bool elementIsGhost() const
Returns if element is a ghost entity.
Definition: fvlocalassemblerbase.hh:253
LocalResidual & localResidual()
The local residual for the current element.
Definition: fvlocalassemblerbase.hh:277
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:249
VolumeVariables & getVolVarAccess(GridVolumeVariables &gridVolVars, ElementVolumeVariables &elemVolVars, const SubControlVolume &scv)
Definition: fvlocalassemblerbase.hh:316
const FVElementGeometry & fvGeometry() const
The finite volume geometry.
Definition: fvlocalassemblerbase.hh:285
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:257
Declares all properties used in Dumux.