GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/dumux/common/staggeredfvproblem.hh
Date: 2024-05-04 19:09:25
Exec Total Coverage
Lines: 22 29 75.9%
Functions: 85 235 36.2%
Branches: 13 30 43.3%

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 Core
10 * \ingroup StaggeredDiscretization
11 * \brief Base class for all staggered fv problems
12 */
13 #ifndef DUMUX_STAGGERD_FV_PROBLEM_HH
14 #define DUMUX_STAGGERD_FV_PROBLEM_HH
15
16 #include <dune/common/rangeutilities.hh>
17
18 #include <dumux/common/properties.hh>
19 #include <dumux/common/fvproblemwithspatialparams.hh>
20 #include <dumux/common/numeqvector.hh>
21
22 namespace Dumux {
23
24 /*!
25 * \ingroup Core
26 * \ingroup StaggeredDiscretization
27 * \brief Base class for all staggered finite-volume problems
28 *
29 * \note All quantities (regarding the units) are specified assuming a
30 * three-dimensional world. Problems discretized using 2D grids
31 * are assumed to be extruded by \f$1 m\f$ and 1D grids are assumed
32 * to have a cross section of \f$1m \times 1m\f$.
33 */
34 template<class TypeTag>
35 8 class StaggeredFVProblem : public FVProblemWithSpatialParams<TypeTag>
36 {
37 using ParentType = FVProblemWithSpatialParams<TypeTag>;
38 using Implementation = GetPropType<TypeTag, Properties::Problem>;
39 using GridView = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView;
40 using Element = typename GridView::template Codim<0>::Entity;
41
42 using GridVariables = GetPropType<TypeTag, Properties::GridVariables>;
43 using GridVolumeVariables = typename GridVariables::GridVolumeVariables;
44 using ElementVolumeVariables = typename GridVolumeVariables::LocalView;
45 using GridFaceVariables = typename GridVariables::GridFaceVariables;
46 using ElementFaceVariables = typename GridFaceVariables::LocalView;
47
48 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
49 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
50 using FVElementGeometry = typename GridGeometry::LocalView;
51 using SubControlVolume = typename FVElementGeometry::SubControlVolume;
52 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
53 using NumEqVector = Dumux::NumEqVector<GetPropType<TypeTag, Properties::PrimaryVariables>>;
54
55 using CoordScalar = typename GridView::ctype;
56 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
57
58 static constexpr auto cellCenterIdx = GridGeometry::cellCenterIdx();
59 static constexpr auto faceIdx = GridGeometry::faceIdx();
60
61 static constexpr auto numEqCellCenter = getPropValue<TypeTag, Properties::NumEqCellCenter>();
62 static constexpr auto numEqFace = getPropValue<TypeTag, Properties::NumEqFace>();
63
64 public:
65 /*!
66 * \brief Constructor
67 * \param gridGeometry The finite volume grid geometry
68 * \param paramGroup The parameter group in which to look for runtime parameters first (default is "")
69 */
70 99 StaggeredFVProblem(std::shared_ptr<const GridGeometry> gridGeometry,
71 const std::string& paramGroup = "")
72
2/6
✓ Branch 2 taken 75 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 75 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
99 : ParentType(gridGeometry, paramGroup)
73 99 { }
74
75 /*!
76 * \brief Returns whether a fixed Dirichlet value shall be used at a given cell.
77 *
78 * \param element The finite element
79 * \param fvGeometry The finite-volume geometry
80 * \param scv The sub control volume
81 * \param pvIdx The primary variable index
82 */
83 bool isDirichletCell(const Element& element,
84 const FVElementGeometry& fvGeometry,
85 const SubControlVolume& scv,
86 int pvIdx) const
87 { return false; }
88
89 /*!
90 * \brief Evaluate the source term for all phases within a given
91 * sub-control-volume (-face).
92 *
93 * This is the method for the case where the source term is
94 * potentially solution dependent and requires some quantities that
95 * are specific to the fully-implicit method.
96 *
97 * \param element The finite element
98 * \param fvGeometry The finite-volume geometry
99 * \param elemVolVars All volume variables for the element
100 * \param elementFaceVars All face variables for the element
101 * \param e The geometrical entity on which the source shall be applied (scv or scvf)
102 *
103 * For this method, the return parameter stores the conserved quantity rate
104 * generated or annihilate per volume unit. Positive values mean
105 * that the conserved quantity is created, negative ones mean that it vanishes.
106 */
107 template<class ElementVolumeVariables, class ElementFaceVariables, class Entity>
108 NumEqVector source(const Element &element,
109 const FVElementGeometry& fvGeometry,
110 const ElementVolumeVariables& elemVolVars,
111 const ElementFaceVariables& elementFaceVars,
112 const Entity &e) const
113 {
114 // forward to solution independent, fully-implicit specific interface
115
0/8
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
378673072 return this->asImp_().sourceAtPos(e.center());
116 }
117
118 /*!
119 * \brief Evaluate the boundary conditions for a neumann
120 * boundary segment.
121 *
122 * This is the method for the case where the Neumann condition is
123 * potentially solution dependent
124 * \param element The finite element
125 * \param fvGeometry The finite-volume geometry
126 * \param elemVolVars All volume variables for the element
127 * \param elemFaceVars All face variables for the element
128 * \param scvf The sub control volume face
129 *
130 * Negative values mean influx.
131 * E.g. for the mass balance that would the mass flux in \f$ [ kg / (m^2 \cdot s)] \f$.
132 */
133 NumEqVector neumann(const Element& element,
134 const FVElementGeometry& fvGeometry,
135 const ElementVolumeVariables& elemVolVars,
136 const ElementFaceVariables& elemFaceVars,
137 const SubControlVolumeFace& scvf) const
138 {
139 // forward it to the interface with only the global position
140
0/2
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1127440 return this->asImp_().neumannAtPos(scvf.ipGlobal());
141 }
142
143 /*!
144 * \brief Evaluate the initial value for an element (for cell-centered primary variables)
145 * or face (for velocities)
146 *
147 * \param entity The dof entity (element or vertex)
148 */
149 template<class Entity>
150 PrimaryVariables initial(const Entity& entity) const
151 {
152 352903858 return this->asImp_().initialAtPos(entity.center());
153 }
154
155 /*!
156 * \brief Applies the initial solution for all degrees of freedom of the grid.
157 *
158 */
159 template<class SolutionVector>
160 40 void applyInitialSolution(SolutionVector& sol) const
161 {
162 120 sol[cellCenterIdx].resize(this->gridGeometry().numCellCenterDofs());
163 120 sol[faceIdx].resize(this->gridGeometry().numFaceDofs());
164
165 80 auto fvGeometry = localView(this->gridGeometry());
166
1/2
✓ Branch 3 taken 14632 times.
✗ Branch 4 not taken.
29304 for (const auto& element : elements(this->gridGeometry().gridView()))
167 {
168 14592 fvGeometry.bindElement(element);
169
170 // loop over sub control volumes
171
4/4
✓ Branch 2 taken 14592 times.
✓ Branch 3 taken 14592 times.
✓ Branch 4 taken 14592 times.
✓ Branch 5 taken 14592 times.
53368 for (auto&& scv : scvs(fvGeometry))
172 {
173 // let the problem do the dirty work of nailing down
174 // the initial solution.
175 14592 auto initPriVars = this->asImp_().initial(scv);
176 27728 this->asImp_().applyInitialCellCenterSolution(sol, scv, initPriVars);
177 }
178
179 // loop over faces
180
4/4
✓ Branch 0 taken 58368 times.
✓ Branch 1 taken 14592 times.
✓ Branch 2 taken 58368 times.
✓ Branch 3 taken 14592 times.
125920 for(auto&& scvf : scvfs(fvGeometry))
181 {
182 58368 auto initPriVars = this->asImp_().initial(scvf);
183 116736 this->asImp_().applyInitialFaceSolution(sol, scvf, initPriVars);
184 }
185 }
186 40 }
187
188
189 //! Applies the initial cell center solution
190 template<class SolutionVector>
191 void applyInitialCellCenterSolution(SolutionVector& sol,
192 const SubControlVolume& scv,
193 const PrimaryVariables& initSol) const
194 {
195 // while the container within the actual solution vector holds numEqCellCenter
196 // elements, we need to specify an offset to get the correct entry of the initial solution
197 static constexpr auto offset = PrimaryVariables::dimension - numEqCellCenter;
198
199
2/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 28246 times.
✓ Branch 3 taken 8936 times.
37182 for(int pvIdx = 0; pvIdx < numEqCellCenter; ++pvIdx)
200 197756 sol[cellCenterIdx][scv.dofIndex()][pvIdx] = initSol[pvIdx + offset];
201 }
202
203 //! Applies the initial face solution
204 template<class SolutionVector>
205 void applyInitialFaceSolution(SolutionVector& sol,
206 const SubControlVolumeFace& scvf,
207 const PrimaryVariables& initSol) const
208 {
209 for(int pvIdx = 0; pvIdx < numEqFace; ++pvIdx)
210 sol[faceIdx][scvf.dofIndex()][pvIdx] = initSol[pvIdx];
211 }
212
213 };
214
215 } // end namespace Dumux
216
217 #endif
218