GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: dumux/test/multidomain/boundary/stokesdarcy/1p2c_1p2c/problem_stokes.hh
Date: 2025-04-12 19:19:20
Exec Total Coverage
Lines: 90 90 100.0%
Functions: 5 5 100.0%
Branches: 76 88 86.4%

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-FileCopyrightText: 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 BoundaryTests
10 * \brief A simple Navier-Stokes test problem for the staggered grid (Navier-)Stokes model.
11 */
12
13 #ifndef DUMUX_STOKES_SUBPROBLEM_HH
14 #define DUMUX_STOKES_SUBPROBLEM_HH
15
16 #include <dumux/common/properties.hh>
17 #include <dumux/common/parameters.hh>
18 #include <dumux/common/numeqvector.hh>
19 #include <dumux/common/timeloop.hh>
20 #include <dumux/freeflow/navierstokes/boundarytypes.hh>
21 #include <dumux/freeflow/navierstokes/staggered/problem.hh>
22
23 namespace Dumux {
24
25 /*!
26 * \ingroup BoundaryTests
27 * \brief Test problem for the one-phase (Navier-) Stokes problem.
28 *
29 * Horizontal flow from left to right with a parabolic velocity profile.
30 */
31 template <class TypeTag>
32 class StokesSubProblem : public NavierStokesStaggeredProblem<TypeTag>
33 {
34 using ParentType = NavierStokesStaggeredProblem<TypeTag>;
35 using GridView = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView;
36 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
37 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
38 using BoundaryTypes = Dumux::NavierStokesBoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>;
39 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
40 using FVElementGeometry = typename GridGeometry::LocalView;
41 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
42 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
43 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
44
45 using Element = typename GridView::template Codim<0>::Entity;
46 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
47
48 using CouplingManager = GetPropType<TypeTag, Properties::CouplingManager>;
49 using TimeLoopPtr = std::shared_ptr<TimeLoop<Scalar>>;
50
51 public:
52 3 StokesSubProblem(std::shared_ptr<const GridGeometry> gridGeometry, std::shared_ptr<CouplingManager> couplingManager)
53
2/4
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
9 : ParentType(gridGeometry, "Stokes"), eps_(1e-6), couplingManager_(couplingManager)
54 {
55
3/6
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 3 times.
✗ Branch 8 not taken.
6 problemName_ = getParam<std::string>("Vtk.OutputName") + "_" + getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name");
56
57 // determine whether to simulate a vertical or horizontal flow configuration
58 3 verticalFlow_ = problemName_.find("vertical") != std::string::npos;
59 3 }
60
61 /*!
62 * \name Problem parameters
63 */
64 // \{
65
66 /*!
67 * \brief The problem name.
68 */
69 3 const std::string& name() const
70 {
71
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 return problemName_;
72 }
73
74 /*!
75 * \brief Returns the sources within the domain.
76 *
77 * \param globalPos The global position
78 */
79 3870240 NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
80
2/2
✓ Branch 0 taken 1557600 times.
✓ Branch 1 taken 778800 times.
6206640 { return NumEqVector(0.0); }
81 // \}
82
83 /*!
84 * \name Boundary conditions
85 */
86 // \{
87
88 /*!
89 * \brief Specifies which kind of boundary condition should be
90 * used for which equation on a given boundary segment.
91 *
92 * \param element The finite element
93 * \param scvf The sub control volume face
94 */
95 939712 BoundaryTypes boundaryTypes(const Element& element,
96 const SubControlVolumeFace& scvf) const
97 {
98
2/2
✓ Branch 1 taken 615312 times.
✓ Branch 2 taken 324400 times.
939712 BoundaryTypes values;
99
100 939712 const auto& globalPos = scvf.dofPosition();
101
102
2/2
✓ Branch 0 taken 615312 times.
✓ Branch 1 taken 324400 times.
939712 if (verticalFlow_)
103 {
104 // inflow
105
2/2
✓ Branch 0 taken 140212 times.
✓ Branch 1 taken 475100 times.
615312 if(onUpperBoundary_(globalPos))
106 {
107 140212 values.setDirichlet(Indices::velocityXIdx);
108 140212 values.setDirichlet(Indices::velocityYIdx);
109 140212 values.setDirichlet(Indices::conti0EqIdx + 1);
110 }
111
112 // left/right wall
113
4/4
✓ Branch 0 taken 473352 times.
✓ Branch 1 taken 141960 times.
✓ Branch 2 taken 141960 times.
✓ Branch 3 taken 331392 times.
615312 if (onRightBoundary_(globalPos) || (onLeftBoundary_(globalPos)))
114 {
115 283920 values.setDirichlet(Indices::velocityXIdx);
116 283920 values.setDirichlet(Indices::velocityYIdx);
117 283920 values.setNeumann(Indices::conti0EqIdx);
118 283920 values.setNeumann(Indices::conti0EqIdx + 1);
119 }
120
121 }
122 else // horizontal flow
123 {
124
2/2
✓ Branch 0 taken 61840 times.
✓ Branch 1 taken 262560 times.
324400 if (onLeftBoundary_(globalPos))
125 {
126 61840 values.setDirichlet(Indices::conti0EqIdx + 1);
127 61840 values.setDirichlet(Indices::velocityXIdx);
128 61840 values.setDirichlet(Indices::velocityYIdx);
129 }
130
2/2
✓ Branch 0 taken 92320 times.
✓ Branch 1 taken 170240 times.
262560 else if (onRightBoundary_(globalPos))
131 {
132 92320 values.setDirichlet(Indices::pressureIdx);
133 92320 values.setOutflow(Indices::conti0EqIdx + 1);
134 }
135 else
136 {
137 170240 values.setDirichlet(Indices::velocityXIdx);
138 170240 values.setDirichlet(Indices::velocityYIdx);
139 170240 values.setNeumann(Indices::conti0EqIdx);
140 170240 values.setNeumann(Indices::conti0EqIdx + 1);
141 }
142 }
143
144 1879424 if(couplingManager().isCoupledEntity(CouplingManager::stokesIdx, scvf))
145 {
146 299940 values.setCouplingNeumann(Indices::conti0EqIdx);
147 299940 values.setCouplingNeumann(Indices::conti0EqIdx + 1);
148 299940 values.setCouplingNeumann(Indices::momentumYBalanceIdx);
149 299940 values.setBeaversJoseph(Indices::momentumXBalanceIdx);
150 }
151
152 939712 return values;
153 }
154
155 /*!
156 * \brief Evaluates the boundary conditions for a Dirichlet control volume.
157 */
158 315564 PrimaryVariables dirichletAtPos(const GlobalPosition& globalPos) const
159 {
160 PrimaryVariables values(0.0);
161 315564 values = initialAtPos(globalPos);
162
163
2/2
✓ Branch 0 taken 205164 times.
✓ Branch 1 taken 110400 times.
315564 if (verticalFlow_)
164 {
165 // Check if this a pure diffusion problem.
166
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 205162 times.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
205164 static const bool isDiffusionProblem = problemName_.find("diffusion") != std::string::npos;
167
168 205164 Scalar topMoleFraction = 1e-3;
169
170
2/2
✓ Branch 0 taken 20098 times.
✓ Branch 1 taken 185066 times.
205164 if (isDiffusionProblem)
171 {
172 // For the diffusion problem, change the top mole fraction after some time
173 // in order to revert the concentration gradient.
174
2/2
✓ Branch 0 taken 13392 times.
✓ Branch 1 taken 6706 times.
20098 if (time() >= 1e10)
175
2/2
✓ Branch 0 taken 69740 times.
✓ Branch 1 taken 135424 times.
205164 topMoleFraction = 0.0;
176 }
177 else // advection problem
178 {
179 // reverse the flow direction after some time for the advection problem
180
2/2
✓ Branch 0 taken 86978 times.
✓ Branch 1 taken 98088 times.
185066 if (time() >= 3e5)
181 98088 values[Indices::velocityYIdx] *= -1.0;
182 }
183
184
2/2
✓ Branch 0 taken 69740 times.
✓ Branch 1 taken 135424 times.
205164 if(globalPos[1] > this->gridGeometry().bBoxMax()[1] - eps_)
185 69740 values[Indices::conti0EqIdx + 1] = topMoleFraction;
186 }
187 else // horizontal flow
188 {
189
4/6
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 110399 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
110400 static const Scalar inletMoleFraction = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.InletMoleFraction");
190
2/2
✓ Branch 0 taken 50760 times.
✓ Branch 1 taken 59640 times.
110400 if(globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_)
191 50760 values[Indices::conti0EqIdx + 1] = inletMoleFraction;
192 }
193
194
195 315564 return values;
196 }
197
198 /*!
199 * \brief Evaluates the boundary conditions for a Neumann control volume.
200 *
201 * \param element The element for which the Neumann boundary condition is set
202 * \param fvGeometry The fvGeometry
203 * \param elemVolVars The element volume variables
204 * \param elemFaceVars The element face variables
205 * \param scvf The boundary sub control volume face
206 */
207 template<class ElementVolumeVariables, class ElementFaceVariables>
208 141056 NumEqVector neumann(const Element& element,
209 const FVElementGeometry& fvGeometry,
210 const ElementVolumeVariables& elemVolVars,
211 const ElementFaceVariables& elemFaceVars,
212 const SubControlVolumeFace& scvf) const
213 {
214 141056 NumEqVector values(0.0);
215
216 198952 if(couplingManager().isCoupledEntity(CouplingManager::stokesIdx, scvf))
217 {
218 83160 values[Indices::momentumYBalanceIdx] = couplingManager().couplingData().momentumCouplingCondition(element, fvGeometry, elemVolVars, elemFaceVars, scvf);
219
220 83160 const auto tmp = couplingManager().couplingData().massCouplingCondition(element, fvGeometry, elemVolVars, elemFaceVars, scvf);
221 83160 values[Indices::conti0EqIdx] = tmp[0];
222 83160 values[Indices::conti0EqIdx + 1] = tmp[1];
223 }
224 141056 return values;
225 }
226
227 // \}
228
229 //! Get the coupling manager
230 1434336 const CouplingManager& couplingManager() const
231 1163928 { return *couplingManager_; }
232
233 /*!
234 * \name Volume terms
235 */
236 // \{
237
238 /*!
239 * \brief Evaluates the initial value for a control volume.
240 *
241 * \param globalPos The global position
242 */
243 3415900 PrimaryVariables initialAtPos(const GlobalPosition& globalPos) const
244 {
245
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3415897 times.
3415900 PrimaryVariables values(0.0);
246 3415900 values[Indices::pressureIdx] = 1e5;
247
248
4/6
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3415897 times.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 3 times.
✗ Branch 7 not taken.
3415900 static const Scalar vMax = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.Velocity", 0.0);
249
250 6831800 auto parabolicProfile = [&](const GlobalPosition& globalPos, int coord)
251 {
252 3415900 return vMax * (globalPos[coord] - this->gridGeometry().bBoxMin()[coord])
253 3415900 * (this->gridGeometry().bBoxMax()[coord] - globalPos[coord])
254 3415900 / (0.25 * (this->gridGeometry().bBoxMax()[coord] - this->gridGeometry().bBoxMin()[coord])
255 3415900 * (this->gridGeometry().bBoxMax()[coord] - this->gridGeometry().bBoxMin()[coord]));
256 };
257
258
2/2
✓ Branch 0 taken 2351660 times.
✓ Branch 1 taken 1064240 times.
3415900 if (verticalFlow_)
259 2351660 values[Indices::velocityYIdx] = parabolicProfile(globalPos, 0);
260 else // horizontal flow
261 1064240 values[Indices::velocityXIdx] = parabolicProfile(globalPos, 1);
262
263 3415900 return values;
264 }
265
266 /*!
267 * \brief Returns the intrinsic permeability of required as input parameter
268 * for the Beavers-Joseph-Saffman boundary condition.
269 */
270 187248 Scalar permeability(const Element& element, const SubControlVolumeFace& scvf) const
271 {
272 187248 return couplingManager().couplingData().darcyPermeability(element, scvf);
273 }
274
275 /*!
276 * \brief Returns the alpha value required as input parameter for the
277 * Beavers-Joseph-Saffman boundary condition.
278 */
279 Scalar alphaBJ(const SubControlVolumeFace& scvf) const
280 {
281 return 1.0;
282 }
283
284 /*!
285 * \brief Sets the time loop pointer.
286 */
287 3 void setTimeLoop(TimeLoopPtr timeLoop)
288
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 { timeLoop_ = timeLoop; }
289
290 /*!
291 * \brief Returns the time.
292 */
293 205164 Scalar time() const
294
4/4
✓ Branch 0 taken 13392 times.
✓ Branch 1 taken 6706 times.
✓ Branch 2 taken 86978 times.
✓ Branch 3 taken 98088 times.
205164 { return timeLoop_->time(); }
295
296 // \}
297
298 private:
299
4/4
✓ Branch 0 taken 141960 times.
✓ Branch 1 taken 331392 times.
✓ Branch 2 taken 61840 times.
✓ Branch 3 taken 262560 times.
797752 bool onLeftBoundary_(const GlobalPosition &globalPos) const
300
4/4
✓ Branch 0 taken 141960 times.
✓ Branch 1 taken 331392 times.
✓ Branch 2 taken 61840 times.
✓ Branch 3 taken 262560 times.
797752 { return globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_; }
301
302
4/4
✓ Branch 0 taken 473352 times.
✓ Branch 1 taken 141960 times.
✓ Branch 2 taken 92320 times.
✓ Branch 3 taken 170240 times.
877872 bool onRightBoundary_(const GlobalPosition &globalPos) const
303
4/4
✓ Branch 0 taken 473352 times.
✓ Branch 1 taken 141960 times.
✓ Branch 2 taken 92320 times.
✓ Branch 3 taken 170240 times.
877872 { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; }
304
305 bool onLowerBoundary_(const GlobalPosition &globalPos) const
306 { return globalPos[1] < this->gridGeometry().bBoxMin()[1] + eps_; }
307
308
2/2
✓ Branch 0 taken 140212 times.
✓ Branch 1 taken 475100 times.
615312 bool onUpperBoundary_(const GlobalPosition &globalPos) const
309
2/2
✓ Branch 0 taken 140212 times.
✓ Branch 1 taken 475100 times.
615312 { return globalPos[1] > this->gridGeometry().bBoxMax()[1] - eps_; }
310
311 Scalar eps_;
312 bool verticalFlow_;
313 std::string problemName_;
314 std::shared_ptr<CouplingManager> couplingManager_;
315 TimeLoopPtr timeLoop_;
316 };
317 } // end namespace Dumux
318
319 #endif
320