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 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 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
6 | : ParentType(gridGeometry, "Stokes"), eps_(1e-6), couplingManager_(couplingManager) |
68 | { | ||
69 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | 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 | refTemperature_ = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.RefTemperature"); |
72 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | Scalar refRelativeHumidity = getParamFromGroup<Scalar>(this->paramGroup(), "Problem.RefRelHumidity"); |
73 | |||
74 | |||
75 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | diffCoeffAvgType_ = StokesDarcyCouplingOptions::stringToEnum(DiffusionCoefficientAveragingType{}, |
76 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | getParamFromGroup<std::string>(this->paramGroup(), "Problem.InterfaceDiffusionCoefficientAvg")); |
77 |
3/6✓ 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.
|
4 | problemName_ = getParam<std::string>("Vtk.OutputName") + "_" + getParamFromGroup<std::string>(this->paramGroup(), "Problem.Name"); |
78 | |||
79 | 2 | FluidState fluidState; | |
80 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | fluidState.setPressure(FluidSystem::phase0Idx, refPressure_); |
81 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | fluidState.setTemperature(refTemperature_); |
82 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | const auto h2oIdx = FluidSystem::compIdx(FluidSystem::MultiPhaseFluidSystem::H2OIdx); |
83 | 2 | Scalar vapPressure = FluidSystem::vaporPressure(fluidState, h2oIdx); | |
84 | 2 | refMoleFrac_ = refRelativeHumidity * vapPressure / refPressure_; | |
85 | 2 | } | |
86 | |||
87 | /*! | ||
88 | * \name Problem parameters | ||
89 | */ | ||
90 | // \{ | ||
91 | |||
92 | /*! | ||
93 | * \brief The problem name. | ||
94 | */ | ||
95 | 2 | const std::string& name() const | |
96 | { | ||
97 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | return problemName_; |
98 | } | ||
99 | |||
100 | /*! | ||
101 | * \brief Returns the sources within the domain. | ||
102 | * | ||
103 | * \param globalPos The global position | ||
104 | */ | ||
105 | 3111632 | NumEqVector sourceAtPos(const GlobalPosition &globalPos) const | |
106 |
2/2✓ Branch 0 taken 1689072 times.
✓ Branch 1 taken 656040 times.
|
5456744 | { return NumEqVector(0.0); } |
107 | |||
108 | // \} | ||
109 | /*! | ||
110 | * \name Boundary conditions | ||
111 | */ | ||
112 | // \{ | ||
113 | |||
114 | /*! | ||
115 | * \brief Specifies which kind of boundary condition should be | ||
116 | * used for which equation on a given boundary segment. | ||
117 | * | ||
118 | * \param element The finite element | ||
119 | * \param scvf The sub control volume face | ||
120 | */ | ||
121 | 1653922 | BoundaryTypes boundaryTypes(const Element& element, | |
122 | const SubControlVolumeFace& scvf) const | ||
123 | { | ||
124 |
2/2✓ Branch 1 taken 1411368 times.
✓ Branch 2 taken 242554 times.
|
1653922 | BoundaryTypes values; |
125 | |||
126 |
2/2✓ Branch 0 taken 882256 times.
✓ Branch 1 taken 152512 times.
|
1653922 | const auto& globalPos = scvf.center(); |
127 | |||
128 | #if NONISOTHERMAL | ||
129 | 1034768 | values.setNeumann(Indices::energyEqIdx); | |
130 | #endif | ||
131 | |||
132 |
4/4✓ Branch 0 taken 1411368 times.
✓ Branch 1 taken 242554 times.
✓ Branch 2 taken 507113 times.
✓ Branch 3 taken 904255 times.
|
1653922 | if (onUpperBoundary_(globalPos) || onLeftBoundary_(globalPos)) |
133 | { | ||
134 | 749667 | values.setDirichlet(Indices::velocityXIdx); | |
135 | 749667 | values.setDirichlet(Indices::velocityYIdx); | |
136 | 749667 | values.setNeumann(Indices::conti0EqIdx); | |
137 | 749667 | values.setNeumann(Indices::conti0EqIdx + 1); | |
138 | } | ||
139 | |||
140 |
2/2✓ Branch 0 taken 575807 times.
✓ Branch 1 taken 1078115 times.
|
1653922 | if (onRightBoundary_(globalPos)) |
141 | { | ||
142 | 575807 | values.setDirichlet(Indices::pressureIdx); | |
143 | 575807 | values.setOutflow(Indices::conti0EqIdx + 1); | |
144 | |||
145 | #if NONISOTHERMAL | ||
146 | 357480 | values.setOutflow(Indices::energyEqIdx); | |
147 | #endif | ||
148 | } | ||
149 | |||
150 | 3307844 | if (couplingManager().isCoupledEntity(CouplingManager::stokesIdx, scvf)) | |
151 | { | ||
152 | 328448 | values.setCouplingNeumann(Indices::conti0EqIdx); | |
153 | 328448 | values.setCouplingNeumann(Indices::conti0EqIdx + 1); | |
154 | 328448 | values.setCouplingNeumann(Indices::momentumYBalanceIdx); | |
155 | 328448 | values.setBeaversJoseph(Indices::momentumXBalanceIdx); | |
156 | } | ||
157 | 1653922 | return values; | |
158 | } | ||
159 | |||
160 | /*! | ||
161 | * \brief Evaluates the boundary conditions for a Dirichlet control volume. | ||
162 | */ | ||
163 | 371086 | PrimaryVariables dirichletAtPos(const GlobalPosition& pos) const | |
164 | { | ||
165 | PrimaryVariables values(0.0); | ||
166 |
2/12✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 7 taken 186804 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 16 taken 68694 times.
✗ Branch 17 not taken.
|
371086 | values = initialAtPos(pos); |
167 | |||
168 | return values; | ||
169 | } | ||
170 | |||
171 | /*! | ||
172 | * \brief Evaluates the boundary conditions for a Neumann control volume. | ||
173 | * | ||
174 | * \param element The element for which the Neumann boundary condition is set | ||
175 | * \param fvGeometry The fvGeometry | ||
176 | * \param elemVolVars The element volume variables | ||
177 | * \param elemFaceVars The element face variables | ||
178 | * \param scvf The boundary sub control volume face | ||
179 | */ | ||
180 | 194723 | NumEqVector neumann(const Element& element, | |
181 | const FVElementGeometry& fvGeometry, | ||
182 | const ElementVolumeVariables& elemVolVars, | ||
183 | const ElementFaceVariables& elemFaceVars, | ||
184 | const SubControlVolumeFace& scvf) const | ||
185 | { | ||
186 | 194723 | PrimaryVariables values(0.0); | |
187 | 194723 | const auto& globalPos = scvf.dofPosition(); | |
188 | 194723 | const auto& scv = fvGeometry.scv(scvf.insideScvIdx()); | |
189 | |||
190 | 194723 | FluidState fluidState; | |
191 | 194723 | updateFluidStateForBC_(fluidState, elemVolVars[scv].pressure()); | |
192 | |||
193 | 194723 | const Scalar density = useMoles ? fluidState.molarDensity(0) : fluidState.density(0); | |
194 | 194723 | const Scalar xVelocity = xVelocity_(globalPos); | |
195 | |||
196 | 194723 | if (onLeftBoundary_(globalPos)) | |
197 | { | ||
198 | // rho*v*X at inflow | ||
199 | 74101 | values[Indices::conti0EqIdx + 1] = -xVelocity * density * refMoleFrac(); | |
200 | 74101 | values[Indices::conti0EqIdx] = -xVelocity * density * (1.0 - refMoleFrac()); | |
201 | |||
202 | #if NONISOTHERMAL | ||
203 | 42220 | values[Indices::energyEqIdx] = -xVelocity * fluidState.density(0) * fluidState.enthalpy(0); | |
204 | #endif | ||
205 | } | ||
206 | |||
207 | 303944 | if(couplingManager().isCoupledEntity(CouplingManager::stokesIdx, scvf)) | |
208 | { | ||
209 | 85502 | values[Indices::momentumYBalanceIdx] = couplingManager().couplingData().momentumCouplingCondition(element, fvGeometry, elemVolVars, elemFaceVars, scvf); | |
210 | |||
211 | 85502 | const auto massFlux = couplingManager().couplingData().massCouplingCondition(element, fvGeometry, elemVolVars, elemFaceVars, scvf, diffCoeffAvgType_); | |
212 | 85502 | values[Indices::conti0EqIdx] = massFlux[0]; | |
213 | 85502 | values[Indices::conti0EqIdx + 1] = massFlux[1]; | |
214 | |||
215 | #if NONISOTHERMAL | ||
216 | 48356 | values[Indices::energyEqIdx] = couplingManager().couplingData().energyCouplingCondition(element, fvGeometry, elemVolVars, elemFaceVars, scvf, diffCoeffAvgType_); | |
217 | #endif | ||
218 | |||
219 | } | ||
220 | 194723 | return values; | |
221 | } | ||
222 | |||
223 | // \} | ||
224 | |||
225 | //! Get the coupling manager | ||
226 | 2353145 | const CouplingManager& couplingManager() const | |
227 | 1934147 | { return *couplingManager_; } | |
228 | |||
229 | /*! | ||
230 | * \name Volume terms | ||
231 | */ | ||
232 | // \{ | ||
233 | |||
234 | /*! | ||
235 | * \brief Evaluates the initial value for a control volume. | ||
236 | * | ||
237 | * \param globalPos The global position | ||
238 | */ | ||
239 | 2880182 | PrimaryVariables initialAtPos(const GlobalPosition &globalPos) const | |
240 | { | ||
241 | 2880182 | FluidState fluidState; | |
242 | 2880182 | updateFluidStateForBC_(fluidState, refPressure()); | |
243 | |||
244 | 2880182 | const Scalar density = FluidSystem::density(fluidState, 0); | |
245 | |||
246 | 2880182 | PrimaryVariables values(0.0); | |
247 | 2880182 | values[Indices::pressureIdx] = refPressure() + density*this->gravity()[1]*(globalPos[1] - this->gridGeometry().bBoxMin()[1]); | |
248 | 2880182 | values[Indices::conti0EqIdx + 1] = refMoleFrac(); | |
249 | 2880182 | values[Indices::velocityXIdx] = xVelocity_(globalPos); | |
250 | |||
251 | #if NONISOTHERMAL | ||
252 | 1584172 | values[Indices::temperatureIdx] = refTemperature(); | |
253 | #endif | ||
254 | |||
255 | 2880182 | return values; | |
256 | } | ||
257 | |||
258 | //! Returns the reference velocity. | ||
259 | 3074905 | const Scalar refVelocity() const | |
260 | 3074905 | { return refVelocity_ ;} | |
261 | |||
262 | //! Returns the reference pressure. | ||
263 | 5760364 | const Scalar refPressure() const | |
264 | 2880182 | { return refPressure_; } | |
265 | |||
266 | //! Returns the reference mole fraction. | ||
267 | 9104093 | const Scalar refMoleFrac() const | |
268 | 74101 | { return refMoleFrac_; } | |
269 | |||
270 | //! Returns the reference temperature. | ||
271 | 4659077 | const Scalar refTemperature() const | |
272 | 4659077 | { return refTemperature_; } | |
273 | |||
274 | |||
275 | 2 | void setTimeLoop(TimeLoopPtr timeLoop) | |
276 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | { timeLoop_ = timeLoop; } |
277 | |||
278 | Scalar time() const | ||
279 | { return timeLoop_->time(); } | ||
280 | |||
281 | /*! | ||
282 | * \brief Returns the intrinsic permeability of required as input parameter | ||
283 | * for the Beavers-Joseph-Saffman boundary condition. | ||
284 | */ | ||
285 | 142570 | Scalar permeability(const Element& element, const SubControlVolumeFace& scvf) const | |
286 | { | ||
287 | 142570 | return couplingManager().couplingData().darcyPermeability(element, scvf); | |
288 | } | ||
289 | |||
290 | /*! | ||
291 | * \brief Returns the alpha value required as input parameter for the | ||
292 | * Beavers-Joseph-Saffman boundary condition. | ||
293 | */ | ||
294 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 142570 times.
|
142570 | Scalar alphaBJ(const SubControlVolumeFace& scvf) const |
295 | { | ||
296 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 142570 times.
|
142570 | return couplingManager().problem(CouplingManager::darcyIdx).spatialParams().beaversJosephCoeffAtPos(scvf.center()); |
297 | } | ||
298 | |||
299 | // \} | ||
300 | |||
301 | private: | ||
302 |
2/2✓ Branch 0 taken 507113 times.
✓ Branch 1 taken 904255 times.
|
1411368 | bool onLeftBoundary_(const GlobalPosition &globalPos) const |
303 |
2/2✓ Branch 0 taken 507113 times.
✓ Branch 1 taken 904255 times.
|
1411368 | { return globalPos[0] < this->gridGeometry().bBoxMin()[0] + eps_; } |
304 | |||
305 |
2/2✓ Branch 0 taken 575807 times.
✓ Branch 1 taken 1078115 times.
|
1653922 | bool onRightBoundary_(const GlobalPosition &globalPos) const |
306 |
2/2✓ Branch 0 taken 575807 times.
✓ Branch 1 taken 1078115 times.
|
1653922 | { return globalPos[0] > this->gridGeometry().bBoxMax()[0] - eps_; } |
307 | |||
308 | bool onLowerBoundary_(const GlobalPosition &globalPos) const | ||
309 | { return globalPos[1] < this->gridGeometry().bBoxMin()[1] + eps_; } | ||
310 | |||
311 |
2/2✓ Branch 0 taken 1411368 times.
✓ Branch 1 taken 242554 times.
|
1653922 | bool onUpperBoundary_(const GlobalPosition &globalPos) const |
312 |
2/2✓ Branch 0 taken 1411368 times.
✓ Branch 1 taken 242554 times.
|
1653922 | { return globalPos[1] > this->gridGeometry().bBoxMax()[1] - eps_; } |
313 | |||
314 | //! Updates the fluid state to obtain required quantities for IC/BC | ||
315 | 3074905 | void updateFluidStateForBC_(FluidState& fluidState, const Scalar pressure) const | |
316 | { | ||
317 | 3074905 | fluidState.setTemperature(refTemperature()); | |
318 | 3074905 | fluidState.setPressure(0, pressure); | |
319 | 3074905 | fluidState.setSaturation(0, 1.0); | |
320 | 3074905 | fluidState.setMoleFraction(0, 1, refMoleFrac()); | |
321 | 3074905 | fluidState.setMoleFraction(0, 0, 1.0 - refMoleFrac()); | |
322 | |||
323 | typename FluidSystem::ParameterCache paramCache; | ||
324 | 3074905 | paramCache.updatePhase(fluidState, 0); | |
325 | |||
326 | 3074905 | const Scalar density = FluidSystem::density(fluidState, paramCache, 0); | |
327 | 3074905 | fluidState.setDensity(0, density); | |
328 | |||
329 | 3074905 | const Scalar molarDensity = FluidSystem::molarDensity(fluidState, paramCache, 0); | |
330 | 3074905 | fluidState.setMolarDensity(0, molarDensity); | |
331 | |||
332 | 3074905 | const Scalar enthalpy = FluidSystem::enthalpy(fluidState, paramCache, 0); | |
333 | 3074905 | fluidState.setEnthalpy(0, enthalpy); | |
334 | 3074905 | } | |
335 | |||
336 | //! Set the profile of the inflow velocity (horizontal direction). | ||
337 | 3074905 | const Scalar xVelocity_(const GlobalPosition &globalPos) const | |
338 | { | ||
339 | 3074905 | const Scalar vmax = refVelocity(); | |
340 |
2/2✓ Branch 0 taken 74101 times.
✓ Branch 1 taken 120622 times.
|
194723 | return 4 * vmax * (globalPos[1] - this->gridGeometry().bBoxMin()[1]) * (this->gridGeometry().bBoxMax()[1] - globalPos[1]) |
341 | 3074905 | / (height_() * height_()); | |
342 | } | ||
343 | |||
344 | // the height of the free-flow domain | ||
345 | 3074905 | const Scalar height_() const | |
346 |
2/2✓ Branch 0 taken 74101 times.
✓ Branch 1 taken 120622 times.
|
194723 | { return this->gridGeometry().bBoxMax()[1] - this->gridGeometry().bBoxMin()[1]; } |
347 | |||
348 | Scalar eps_; | ||
349 | |||
350 | Scalar refVelocity_; | ||
351 | Scalar refPressure_; | ||
352 | Scalar refMoleFrac_; | ||
353 | Scalar refTemperature_; | ||
354 | std::string problemName_; | ||
355 | TimeLoopPtr timeLoop_; | ||
356 | |||
357 | std::shared_ptr<CouplingManager> couplingManager_; | ||
358 | |||
359 | DiffusionCoefficientAveragingType diffCoeffAvgType_; | ||
360 | }; | ||
361 | } // end namespace Dumux | ||
362 | |||
363 | #endif | ||
364 |