Line | Branch | Exec | Source |
---|---|---|---|
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 | // | ||
7 | /*! | ||
8 | * \file | ||
9 | * \ingroup Assembly | ||
10 | * \ingroup FaceCenteredStaggeredDiscretization | ||
11 | * \brief Calculates the element-wise residual for the box scheme | ||
12 | */ | ||
13 | #ifndef DUMUX_FACECENTERED_LOCAL_RESIDUAL_HH | ||
14 | #define DUMUX_FACECENTERED_LOCAL_RESIDUAL_HH | ||
15 | |||
16 | #include <dune/geometry/type.hh> | ||
17 | #include <dune/istl/matrix.hh> | ||
18 | |||
19 | #include <dumux/common/numeqvector.hh> | ||
20 | #include <dumux/common/properties.hh> | ||
21 | #include <dumux/assembly/fvlocalresidual.hh> | ||
22 | #include <dumux/discretization/extrusion.hh> | ||
23 | |||
24 | namespace Dumux { | ||
25 | |||
26 | /*! | ||
27 | * \ingroup Assembly | ||
28 | * \ingroup FaceCenteredStaggeredDiscretization | ||
29 | * \brief The element-wise residual for the box scheme | ||
30 | * \tparam TypeTag the TypeTag | ||
31 | */ | ||
32 | template<class TypeTag> | ||
33 | class FaceCenteredLocalResidual : public FVLocalResidual<TypeTag> | ||
34 | { | ||
35 | using ParentType = FVLocalResidual<TypeTag>; | ||
36 | using Scalar = GetPropType<TypeTag, Properties::Scalar>; | ||
37 | using Problem = GetPropType<TypeTag, Properties::Problem>; | ||
38 | using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>; | ||
39 | using GridView = typename GridGeometry::GridView; | ||
40 | using Element = typename GridView::template Codim<0>::Entity; | ||
41 | using ElementBoundaryTypes = GetPropType<TypeTag, Properties::ElementBoundaryTypes>; | ||
42 | using FVElementGeometry = typename GridGeometry::LocalView; | ||
43 | using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView; | ||
44 | using SubControlVolume = typename FVElementGeometry::SubControlVolume; | ||
45 | using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace; | ||
46 | using ElementFluxVariablesCache = typename GetPropType<TypeTag, Properties::GridFluxVariablesCache>::LocalView; | ||
47 | using NumEqVector = Dumux::NumEqVector<GetPropType<TypeTag, Properties::PrimaryVariables>>; | ||
48 | using Extrusion = Extrusion_t<GridGeometry>; | ||
49 | |||
50 | public: | ||
51 | using ElementResidualVector = typename ParentType::ElementResidualVector; | ||
52 |
1/2✓ Branch 1 taken 2574802 times.
✗ Branch 2 not taken.
|
2605838 | using ParentType::ParentType; |
53 | |||
54 | /*! | ||
55 | * \brief evaluate flux residuals for one sub control volume face and add to residual | ||
56 | * | ||
57 | */ | ||
58 | 285646218 | void evalFlux(ElementResidualVector& residual, | |
59 | const Problem& problem, | ||
60 | const Element& element, | ||
61 | const FVElementGeometry& fvGeometry, | ||
62 | const ElementVolumeVariables& elemVolVars, | ||
63 | const ElementBoundaryTypes& elemBcTypes, | ||
64 | const ElementFluxVariablesCache& elemFluxVarsCache, | ||
65 | const SubControlVolumeFace& scvf) const | ||
66 | { | ||
67 | 285646218 | const auto flux = evalFlux(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf); | |
68 |
2/4✗ Branch 0 not taken.
✓ Branch 1 taken 279288018 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 279288018 times.
|
571292436 | const auto& insideScv = fvGeometry.scv(scvf.insideScvIdx()); |
69 | 856938654 | residual[insideScv.localDofIndex()] += flux; | |
70 | 285646218 | } | |
71 | |||
72 | //! evaluate flux residuals for one sub control volume face | ||
73 | 285646218 | NumEqVector evalFlux(const Problem& problem, | |
74 | const Element& element, | ||
75 | const FVElementGeometry& fvGeometry, | ||
76 | const ElementVolumeVariables& elemVolVars, | ||
77 | const ElementBoundaryTypes& elemBcTypes, | ||
78 | const ElementFluxVariablesCache& elemFluxVarsCache, | ||
79 | const SubControlVolumeFace& scvf) const | ||
80 | { | ||
81 |
2/2✓ Branch 0 taken 17156648 times.
✓ Branch 1 taken 268489570 times.
|
285646218 | if (elemBcTypes.hasDirichlet()) |
82 | 17156648 | return this->asImp().maybeHandleDirichletBoundary(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf); | |
83 | |||
84 |
2/2✓ Branch 0 taken 2810798 times.
✓ Branch 1 taken 265678772 times.
|
268489570 | if (elemBcTypes.hasNeumann()) |
85 | 2810798 | return this->asImp().maybeHandleNeumannBoundary(problem, element, fvGeometry, elemVolVars, elemBcTypes, elemFluxVarsCache, scvf); | |
86 | |||
87 | 265678772 | return this->asImp().computeFlux(problem, element, fvGeometry, elemVolVars, scvf, elemFluxVarsCache, elemBcTypes); | |
88 | } | ||
89 | |||
90 | /*! | ||
91 | * \brief Calculate the source term of the equation | ||
92 | * | ||
93 | * \param problem The problem to solve | ||
94 | * \param element The DUNE Codim<0> entity for which the residual | ||
95 | * ought to be calculated | ||
96 | * \param fvGeometry The finite-volume geometry of the element | ||
97 | * \param elemVolVars The volume variables associated with the element stencil | ||
98 | * \param scv The sub-control volume over which we integrate the source term | ||
99 | * \note This is the default implementation for all models as sources are computed | ||
100 | * in the user interface of the problem | ||
101 | * | ||
102 | */ | ||
103 | 43559688 | NumEqVector computeSource(const Problem& problem, | |
104 | const Element& element, | ||
105 | const FVElementGeometry& fvGeometry, | ||
106 | const ElementVolumeVariables& elemVolVars, | ||
107 | const SubControlVolume& scv) const | ||
108 | { | ||
109 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
43559688 | NumEqVector source(0.0); |
110 | |||
111 | // add contributions from volume flux sources | ||
112 |
0/8✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
130559528 | source += problem.source(element, fvGeometry, elemVolVars, scv)[scv.dofAxis()]; |
113 | |||
114 | // add contribution from possible point sources | ||
115 |
0/2✗ Branch 1 not taken.
✗ Branch 2 not taken.
|
43559688 | source += problem.scvPointSources(element, fvGeometry, elemVolVars, scv)[scv.dofAxis()]; |
116 | |||
117 | 43559688 | return source; | |
118 | } | ||
119 | |||
120 | using ParentType::evalStorage; | ||
121 | |||
122 | /*! | ||
123 | * \brief Compute the storage local residual, i.e. the deviation of the | ||
124 | * storage term from zero for instationary problems. | ||
125 | * | ||
126 | * \param residual The residual vector to fill | ||
127 | * \param problem The problem to solve | ||
128 | * \param element The DUNE Codim<0> entity for which the residual | ||
129 | * ought to be calculated | ||
130 | * \param fvGeometry The finite-volume geometry of the element | ||
131 | * \param prevElemVolVars The volume averaged variables for all | ||
132 | * sub-control volumes of the element at the previous time level | ||
133 | * \param curElemVolVars The volume averaged variables for all | ||
134 | * sub-control volumes of the element at the current time level | ||
135 | * \param scv The sub control volume the storage term is integrated over | ||
136 | */ | ||
137 | 52411520 | void evalStorage(ElementResidualVector& residual, | |
138 | const Problem& problem, | ||
139 | const Element& element, | ||
140 | const FVElementGeometry& fvGeometry, | ||
141 | const ElementVolumeVariables& prevElemVolVars, | ||
142 | const ElementVolumeVariables& curElemVolVars, | ||
143 | const SubControlVolume& scv) const | ||
144 | { | ||
145 | 52411520 | const auto& curVolVars = curElemVolVars[scv]; | |
146 | 52411520 | const auto& prevVolVars = prevElemVolVars[scv]; | |
147 | |||
148 | // mass balance within the element. this is the | ||
149 | // \f$\frac{m}{\partial t}\f$ term if using implicit or explicit | ||
150 | // euler as time discretization. | ||
151 | // | ||
152 | |||
153 | //! Compute storage with the model specific storage residual | ||
154 | 52411520 | NumEqVector prevStorage = this->asImp().computeStorage(problem, scv, prevVolVars, true/*isPreviousStorage*/); | |
155 | 52411520 | NumEqVector storage = this->asImp().computeStorage(problem, scv, curVolVars, false/*isPreviousStorage*/); | |
156 | |||
157 | 52411520 | prevStorage *= prevVolVars.extrusionFactor(); | |
158 | 52411520 | storage *= curVolVars.extrusionFactor(); | |
159 | |||
160 | 52411520 | storage -= prevStorage; | |
161 | 104823040 | storage *= Extrusion::volume(fvGeometry, scv); | |
162 | 52411520 | storage /= this->timeLoop().timeStepSize(); | |
163 | |||
164 | 157234560 | residual[scv.localDofIndex()] += storage; | |
165 | 52411520 | } | |
166 | }; | ||
167 | |||
168 | } // end namespace Dumux | ||
169 | |||
170 | #endif | ||
171 |