GCC Code Coverage Report


Directory: ../../../builds/dumux-repositories/
File: /builds/dumux-repositories/dumux/test/multidomain/boundary/stokesdarcy/1p2c_2p2c/problem_stokes.hh
Date: 2024-09-21 20:52:54
Exec Total Coverage
Lines: 85 97 87.6%
Functions: 6 12 50.0%
Branches: 114 168 67.9%

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 BoundaryTests
10 * \brief A simple Stokes test problem for the staggered grid (Navier-)Stokes model.
11 */
12
13 #ifndef DUMUX_STOKES1P2C_SUBPROBLEM_HH
14 #define DUMUX_STOKES1P2C_SUBPROBLEM_HH
15
16 #include <dumux/common/properties.hh>
17 #include <dumux/common/parameters.hh>
18 #include <dumux/common/timeloop.hh>
19 #include <dumux/common/numeqvector.hh>
20
21 #include <dumux/freeflow/navierstokes/boundarytypes.hh>
22 #include <dumux/freeflow/navierstokes/staggered/problem.hh>
23
24 #include <dumux/multidomain/boundary/stokesdarcy/couplingdata.hh>
25
26 namespace Dumux {
27
28 /*!
29 * \ingroup BoundaryTests
30 * \brief Test problem for the one-phase (Navier-) Stokes problem.
31 *
32 * Horizontal flow from left to right with a parabolic velocity profile.
33 */
34 template <class TypeTag>
35 class StokesSubProblem : public NavierStokesStaggeredProblem<TypeTag>
36 {
37 using ParentType = NavierStokesStaggeredProblem<TypeTag>;
38
39 using GridView = typename GetPropType<TypeTag, Properties::GridGeometry>::GridView;
40 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
41 using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
42 using Indices = typename GetPropType<TypeTag, Properties::ModelTraits>::Indices;
43 using BoundaryTypes = Dumux::NavierStokesBoundaryTypes<GetPropType<TypeTag, Properties::ModelTraits>::numEq()>;
44
45 using GridGeometry = GetPropType<TypeTag, Properties::GridGeometry>;
46 using FVElementGeometry = typename GridGeometry::LocalView;
47 using SubControlVolumeFace = typename FVElementGeometry::SubControlVolumeFace;
48 using Element = typename GridView::template Codim<0>::Entity;
49 using ElementVolumeVariables = typename GetPropType<TypeTag, Properties::GridVolumeVariables>::LocalView;
50 using ElementFaceVariables = typename GetPropType<TypeTag, Properties::GridFaceVariables>::LocalView;
51 using FluidState = GetPropType<TypeTag, Properties::FluidState>;
52
53 using GlobalPosition = typename Element::Geometry::GlobalCoordinate;
54
55 using PrimaryVariables = GetPropType<TypeTag, Properties::PrimaryVariables>;
56 using NumEqVector = Dumux::NumEqVector<PrimaryVariables>;
57
58 using CouplingManager = GetPropType<TypeTag, Properties::CouplingManager>;
59 using TimeLoopPtr = std::shared_ptr<TimeLoop<Scalar>>;
60
61 using DiffusionCoefficientAveragingType = typename StokesDarcyCouplingOptions::DiffusionCoefficientAveragingType;
62
63 static constexpr bool useMoles = GetPropType<TypeTag, Properties::ModelTraits>::useMoles();
64
65 public:
66 2 StokesSubProblem(std::shared_ptr<const GridGeometry> gridGeometry, std::shared_ptr<CouplingManager> couplingManager)
67
5/18
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 2 times.
✗ Branch 9 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 2 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
6 : ParentType(gridGeometry, "Stokes"), eps_(1e-6), couplingManager_(couplingManager)
68 {
69
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
4 refVelocity_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.RefVelocity");
70
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 refPressure_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.RefPressure");
71
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 refMoleFrac_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.refMoleFrac");
72
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 refTemperature_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.RefTemperature");
73
74
2/6
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
2 diffCoeffAvgType_ = StokesDarcyCouplingOptions::stringToEnum(DiffusionCoefficientAveragingType{},
75
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 getParamFromGroup<std::string>(this->paramGroup(), "Problem.InterfaceDiffusionCoefficientAvg"));
76
8/24
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 2 times.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 2 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 2 times.
✗ Branch 17 not taken.
✓ Branch 18 taken 2 times.
✗ Branch 19 not taken.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
2 problemName_ = getParam<std::string>("Vtk.OutputName") + "_" + getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name");
77 2 }
78
79 /*!
80 * \name Problem parameters
81 */
82 // \{
83
84 /*!
85 * \brief The problem name.
86 */
87 const std::string& name() const
88 {
89
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 return problemName_;
90 }
91
92 /*!
93 * \brief Returns the sources within the domain.
94 *
95 * \param globalPos The global position
96 */
97 NumEqVector sourceAtPos(const GlobalPosition &globalPos) const
98 3102464 { return NumEqVector(0.0); }
99
100 // \}
101 /*!
102 * \name Boundary conditions
103 */
104 // \{
105
106 /*!
107 * \brief Specifies which kind of boundary condition should be
108 * used for which equation on a given boundary segment.
109 *
110 * \param element The finite element
111 * \param scvf The sub control volume face
112 */
113 1649876 BoundaryTypes boundaryTypes(const Element& element,
114 const SubControlVolumeFace& scvf) const
115 {
116 1649876 BoundaryTypes values;
117
118
2/2
✓ Branch 0 taken 1407912 times.
✓ Branch 1 taken 241964 times.
1649876 const auto& globalPos = scvf.center();
119
120 #if NONISOTHERMAL
121
2/2
✓ Branch 0 taken 882256 times.
✓ Branch 1 taken 152512 times.
1034768 values.setNeumann(Indices::energyEqIdx);
122 #endif
123
124 6115576 if (onUpperBoundary_(globalPos) || onLeftBoundary_(globalPos))
125 {
126 747854 values.setDirichlet(Indices::velocityXIdx);
127 747854 values.setDirichlet(Indices::velocityYIdx);
128 747854 values.setNeumann(Indices::conti0EqIdx);
129 747854 values.setNeumann(Indices::conti0EqIdx + 1);
130 }
131
132 3299752 if (onRightBoundary_(globalPos))
133 {
134 574382 values.setDirichlet(Indices::pressureIdx);
135 574382 values.setOutflow(Indices::conti0EqIdx + 1);
136
137 #if NONISOTHERMAL
138 357480 values.setOutflow(Indices::energyEqIdx);
139 #endif
140 }
141
142
2/2
✓ Branch 0 taken 327640 times.
✓ Branch 1 taken 1322236 times.
1649876 if (couplingManager().isCoupledEntity(CouplingManager::stokesIdx, scvf))
143 {
144 327640 values.setCouplingNeumann(Indices::conti0EqIdx);
145 327640 values.setCouplingNeumann(Indices::conti0EqIdx + 1);
146 327640 values.setCouplingNeumann(Indices::momentumYBalanceIdx);
147 327640 values.setBeaversJoseph(Indices::momentumXBalanceIdx);
148 }
149 1649876 return values;
150 }
151
152 /*!
153 * \brief Evaluates the boundary conditions for a Dirichlet control volume.
154 */
155 PrimaryVariables dirichletAtPos(const GlobalPosition& pos) const
156 {
157 369988 PrimaryVariables values(0.0);
158
1/10
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 7 taken 186240 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
369988 values = initialAtPos(pos);
159
160 return values;
161 }
162
163 /*!
164 * \brief Evaluates the boundary conditions for a Neumann control volume.
165 *
166 * \param element The element for which the Neumann boundary condition is set
167 * \param fvGeometry The fvGeometry
168 * \param elemVolVars The element volume variables
169 * \param elemFaceVars The element face variables
170 * \param scvf The boundary sub control volume face
171 */
172 194170 NumEqVector neumann(const Element& element,
173 const FVElementGeometry& fvGeometry,
174 const ElementVolumeVariables& elemVolVars,
175 const ElementFaceVariables& elemFaceVars,
176 const SubControlVolumeFace& scvf) const
177 {
178 194170 PrimaryVariables values(0.0);
179 194170 const auto& globalPos = scvf.dofPosition();
180 388340 const auto& scv = fvGeometry.scv(scvf.insideScvIdx());
181
182 194170 FluidState fluidState;
183 194170 updateFluidStateForBC_(fluidState, elemVolVars[scv].pressure());
184
185
2/2
✓ Branch 0 taken 73894 times.
✓ Branch 1 taken 120276 times.
194170 const Scalar density = useMoles ? fluidState.molarDensity(0) : fluidState.density(0);
186 388340 const Scalar xVelocity = xVelocity_(globalPos);
187
188 388340 if (onLeftBoundary_(globalPos))
189 {
190 // rho*v*X at inflow
191 73894 values[Indices::conti0EqIdx + 1] = -xVelocity * density * refMoleFrac();
192 105568 values[Indices::conti0EqIdx] = -xVelocity * density * (1.0 - refMoleFrac());
193
194 #if NONISOTHERMAL
195 168880 values[Indices::energyEqIdx] = -xVelocity * fluidState.density(0) * fluidState.enthalpy(0);
196 #endif
197 }
198
199
2/2
✓ Branch 0 taken 85256 times.
✓ Branch 1 taken 108914 times.
194170 if(couplingManager().isCoupledEntity(CouplingManager::stokesIdx, scvf))
200 {
201 85256 values[Indices::momentumYBalanceIdx] = couplingManager().couplingData().momentumCouplingCondition(element, fvGeometry, elemVolVars, elemFaceVars, scvf);
202
203 85256 const auto massFlux = couplingManager().couplingData().massCouplingCondition(element, fvGeometry, elemVolVars, elemFaceVars, scvf, diffCoeffAvgType_);
204 170512 values[Indices::conti0EqIdx] = massFlux[0];
205 207412 values[Indices::conti0EqIdx + 1] = massFlux[1];
206
207 #if NONISOTHERMAL
208 48356 values[Indices::energyEqIdx] = couplingManager().couplingData().energyCouplingCondition(element, fvGeometry, elemVolVars, elemFaceVars, scvf, diffCoeffAvgType_);
209 #endif
210
211 }
212 194170 return values;
213 }
214
215 // \}
216
217 //! Get the coupling manager
218 const CouplingManager& couplingManager() const
219 3858604 { return *couplingManager_; }
220
221 /*!
222 * \name Volume terms
223 */
224 // \{
225
226 /*!
227 * \brief Evaluates the initial value for a control volume.
228 *
229 * \param globalPos The global position
230 */
231 2871616 PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const
232 {
233 2871616 FluidState fluidState;
234 2871616 updateFluidStateForBC_(fluidState, refPressure());
235
236 2871616 const Scalar density = FluidSystem::density(fluidState, 0);
237
238 2871616 PrimaryVariables values(0.0);
239 22972928 values[Indices::pressureIdx] = refPressure() + density*this->gravity()[1]*(globalPos[1] - this->gridGeometry().bBoxMin()[1]);
240 5743232 values[Indices::conti0EqIdx + 1] = refMoleFrac();
241 8614848 values[Indices::velocityXIdx] = xVelocity_(globalPos);
242
243 #if NONISOTHERMAL
244 3168344 values[Indices::temperatureIdx] = refTemperature();
245 #endif
246
247 2871616 return values;
248 }
249
250 //! Returns the reference velocity.
251 const Scalar refVelocity() const
252 { return refVelocity_ ;}
253
254 //! Returns the reference pressure.
255 const Scalar refPressure() const
256 { return refPressure_; }
257
258 //! Returns the reference mass fraction.
259 const Scalar refMoleFrac() const
260 { return refMoleFrac_; }
261
262 //! Returns the reference temperature.
263 const Scalar refTemperature() const
264 { return refTemperature_; }
265
266
267 void setTimeLoop(TimeLoopPtr timeLoop)
268
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 { timeLoop_ = timeLoop; }
269
270 Scalar time() const
271 { return timeLoop_->time(); }
272
273 /*!
274 * \brief Returns the intrinsic permeability of required as input parameter
275 * for the Beavers-Joseph-Saffman boundary condition.
276 */
277 Scalar permeability(const Element& element, const SubControlVolumeFace& scvf) const
278 {
279 return couplingManager().couplingData().darcyPermeability(element, scvf);
280 }
281
282 /*!
283 * \brief Returns the alpha value required as input parameter for the
284 * Beavers-Joseph-Saffman boundary condition.
285 */
286 Scalar alphaBJ(const SubControlVolumeFace& scvf) const
287 {
288 return couplingManager().problem(CouplingManager::darcyIdx).spatialParams().beaversJosephCoeffAtPos(scvf.center());
289 }
290
291 // \}
292
293 private:
294 bool onLeftBoundary_(const GlobalPosition &globalPos) const
295
18/18
✓ Branch 0 taken 73894 times.
✓ Branch 1 taken 120276 times.
✓ Branch 2 taken 73894 times.
✓ Branch 3 taken 120276 times.
✓ Branch 4 taken 73894 times.
✓ Branch 5 taken 120276 times.
✓ Branch 6 taken 73894 times.
✓ Branch 7 taken 120276 times.
✓ Branch 8 taken 505890 times.
✓ Branch 9 taken 902022 times.
✓ Branch 10 taken 505890 times.
✓ Branch 11 taken 902022 times.
✓ Branch 12 taken 505890 times.
✓ Branch 13 taken 902022 times.
✓ Branch 14 taken 505890 times.
✓ Branch 15 taken 902022 times.
✓ Branch 16 taken 505890 times.
✓ Branch 17 taken 902022 times.
7816240 { return globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_; }
296
297 bool onRightBoundary_(const GlobalPosition &globalPos) const
298
10/10
✓ Branch 0 taken 574382 times.
✓ Branch 1 taken 1075494 times.
✓ Branch 2 taken 574382 times.
✓ Branch 3 taken 1075494 times.
✓ Branch 4 taken 574382 times.
✓ Branch 5 taken 1075494 times.
✓ Branch 6 taken 574382 times.
✓ Branch 7 taken 1075494 times.
✓ Branch 8 taken 574382 times.
✓ Branch 9 taken 1075494 times.
8249380 { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; }
299
300 bool onLowerBoundary_(const GlobalPosition &globalPos) const
301 { return globalPos[1] < this->gridGeometry().bBoxMin()[1] + eps_; }
302
303 bool onUpperBoundary_(const GlobalPosition &globalPos) const
304
10/10
✓ Branch 0 taken 1407912 times.
✓ Branch 1 taken 241964 times.
✓ Branch 2 taken 1407912 times.
✓ Branch 3 taken 241964 times.
✓ Branch 4 taken 1407912 times.
✓ Branch 5 taken 241964 times.
✓ Branch 6 taken 1407912 times.
✓ Branch 7 taken 241964 times.
✓ Branch 8 taken 1407912 times.
✓ Branch 9 taken 241964 times.
8249380 { return globalPos[1] > this->gridGeometry().bBoxMax()[1] - eps_; }
305
306 //! Updates the fluid state to obtain required quantities for IC/BC
307 3065786 void updateFluidStateForBC_(FluidState& fluidState, const Scalar pressure) const
308 {
309 3065786 fluidState.setTemperature(refTemperature());
310 3065786 fluidState.setPressure(0, pressure);
311 3065786 fluidState.setSaturation(0, 1.0);
312 3065786 fluidState.setMoleFraction(0, 1, refMoleFrac());
313 3065786 fluidState.setMoleFraction(0, 0, 1.0 - refMoleFrac());
314
315 typename FluidSystem::ParameterCache paramCache;
316 3065786 paramCache.updatePhase(fluidState, 0);
317
318 3065786 const Scalar density = FluidSystem::density(fluidState, paramCache, 0);
319 3065786 fluidState.setDensity(0, density);
320
321 3065786 const Scalar molarDensity = FluidSystem::molarDensity(fluidState, paramCache, 0);
322 3065786 fluidState.setMolarDensity(0, molarDensity);
323
324 3065786 const Scalar enthalpy = FluidSystem::enthalpy(fluidState, paramCache, 0);
325 6131572 fluidState.setEnthalpy(0, enthalpy);
326 3065786 }
327
328 //! Set the profile of the inflow velocity (horizontal direction).
329 const Scalar xVelocity_(const GlobalPosition &globalPos) const
330 {
331 3065786 const Scalar vmax = refVelocity();
332
16/16
✓ Branch 0 taken 73894 times.
✓ Branch 1 taken 120276 times.
✓ Branch 2 taken 73894 times.
✓ Branch 3 taken 120276 times.
✓ Branch 4 taken 73894 times.
✓ Branch 5 taken 120276 times.
✓ Branch 6 taken 73894 times.
✓ Branch 7 taken 120276 times.
✓ Branch 8 taken 73894 times.
✓ Branch 9 taken 120276 times.
✓ Branch 10 taken 73894 times.
✓ Branch 11 taken 120276 times.
✓ Branch 12 taken 73894 times.
✓ Branch 13 taken 120276 times.
✓ Branch 14 taken 73894 times.
✓ Branch 15 taken 120276 times.
1553360 return 4 * vmax * (globalPos[1] - this->gridGeometry().bBoxMin()[1]) * (this->gridGeometry().bBoxMax()[1] - globalPos[1])
333 9197358 / (height_() * height_());
334 }
335
336 // the height of the free-flow domain
337 const Scalar height_() const
338
26/26
✓ Branch 0 taken 73894 times.
✓ Branch 1 taken 120276 times.
✓ Branch 2 taken 73894 times.
✓ Branch 3 taken 120276 times.
✓ Branch 4 taken 73894 times.
✓ Branch 5 taken 120276 times.
✓ Branch 6 taken 73894 times.
✓ Branch 7 taken 120276 times.
✓ Branch 8 taken 73894 times.
✓ Branch 9 taken 120276 times.
✓ Branch 10 taken 73894 times.
✓ Branch 11 taken 120276 times.
✓ Branch 12 taken 73894 times.
✓ Branch 13 taken 120276 times.
✓ Branch 14 taken 73894 times.
✓ Branch 15 taken 120276 times.
✓ Branch 16 taken 73894 times.
✓ Branch 17 taken 120276 times.
✓ Branch 18 taken 73894 times.
✓ Branch 19 taken 120276 times.
✓ Branch 20 taken 73894 times.
✓ Branch 21 taken 120276 times.
✓ Branch 22 taken 73894 times.
✓ Branch 23 taken 120276 times.
✓ Branch 24 taken 73894 times.
✓ Branch 25 taken 120276 times.
2524210 { return this->gridGeometry().bBoxMax()[1] - this->gridGeometry().bBoxMin()[1]; }
339
340 Scalar eps_;
341
342 Scalar refVelocity_;
343 Scalar refPressure_;
344 Scalar refMoleFrac_;
345 Scalar refTemperature_;
346 std::string problemName_;
347 TimeLoopPtr timeLoop_;
348
349 std::shared_ptr<CouplingManager> couplingManager_;
350
351 DiffusionCoefficientAveragingType diffCoeffAvgType_;
352 };
353 } // end namespace Dumux
354
355 #endif
356