version 3.10-dev
boundaryfluxes.hh
Go to the documentation of this file.
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//
18#ifndef DUMUX_SHALLOWWATER_BOUNDARYFLUXES_HH
19#define DUMUX_SHALLOWWATER_BOUNDARYFLUXES_HH
20
21#include <array>
22#include <cmath>
23#include <algorithm>
24
25namespace Dumux::ShallowWater {
26
39template<class Scalar, class GlobalPosition>
40std::array<Scalar, 3> fixedWaterDepthBoundary(const Scalar waterDepthBoundary,
41 const Scalar waterDepthInside,
42 const Scalar velocityXInside,
43 const Scalar velocityYInside,
44 const Scalar gravity,
45 const GlobalPosition& nxy)
46
47{
48 std::array<Scalar, 3> cellStateOutside;
49 cellStateOutside[0] = waterDepthBoundary;
50
51 using std::sqrt;
52 const auto uboundIn = nxy[0] * velocityXInside + nxy[1] * velocityYInside;
53 const auto uboundQut = uboundIn + 2.0 * sqrt(gravity * waterDepthInside) - 2.0 * sqrt(gravity * cellStateOutside[0]);
54
55 cellStateOutside[1] = (nxy[0] * uboundQut); // we only use the normal part
56 cellStateOutside[2] = (nxy[1] * uboundQut); // we only use the normal part
57
58 return cellStateOutside;
59}
60
73template<class Scalar, class GlobalPosition>
74std::array<Scalar, 3> fixedDischargeBoundary(const Scalar dischargeBoundary,
75 const Scalar waterDepthInside,
76 const Scalar velocityXInside,
77 const Scalar velocityYInside,
78 const Scalar gravity,
79 const GlobalPosition& nxy)
80{
81 std::array<Scalar, 3> cellStateOutside;
82 using std::abs;
83 using std::sqrt;
84 using std::max;
85
86 // only impose if abs(q) > 0
87 if (abs(dischargeBoundary) > 1.0e-9)
88 {
89 const auto uboundIn = nxy[0]*velocityXInside + nxy[1]*velocityYInside;
90 const auto alphal = uboundIn + 2.0*sqrt(gravity * waterDepthInside);
91
92 //initial guess for hstar solved with newton
93 constexpr Scalar tol_hstar = 1.0E-12;
94 constexpr Scalar ink_hstar = 1.0E-9;
95 constexpr int maxstep_hstar = 30;
96
97 Scalar hstar = 0.1;
98 for (int i = 0; i < maxstep_hstar; ++i)
99 {
100 Scalar f_hstar = alphal - dischargeBoundary/hstar - 2 * sqrt(gravity * hstar);
101 Scalar df_hstar = (f_hstar -(alphal - dischargeBoundary/(hstar + ink_hstar) - 2 * sqrt(gravity * (hstar+ink_hstar))))/ink_hstar;
102 Scalar dx_hstar = -f_hstar/df_hstar;
103 hstar = max(hstar - dx_hstar,0.001);
104
105 if (dx_hstar*dx_hstar < tol_hstar)
106 break;
107 }
108
109 const auto qinner = (nxy[0] * waterDepthInside * velocityYInside) - (nxy[1] * waterDepthInside * velocityXInside);
110 cellStateOutside[0] = hstar;
111 cellStateOutside[1] = (nxy[0] * dischargeBoundary - nxy[1] * qinner)/hstar;
112 cellStateOutside[2] = (nxy[1] * dischargeBoundary + nxy[0] * qinner)/hstar;
113 }
114
115 return cellStateOutside;
116}
117
127template<class PrimaryVariables, class Scalar, class GlobalPosition>
128std::array<Scalar, 3> noslipWallBoundary(const Scalar alphaWall,
129 const Scalar turbulentViscosity,
130 const PrimaryVariables& state,
131 const GlobalPosition& cellCenterToBoundaryFaceCenter,
132 const GlobalPosition& unitNormal)
133{
134 // only impose if abs(alphaWall) > 0
135 using std::abs;
136 if (abs(alphaWall) <= 1.0e-9)
137 return {};
138
139 const auto waterDepth = state[0];
140 // regularization: Set gradients to zero for drying cell
141 // Use LET-limiter instead for differentiability?
142 if (waterDepth <= 0.001)
143 return {};
144
145 const auto xVelocity = state[1];
146 const auto yVelocity = state[2];
147 const auto distance = cellCenterToBoundaryFaceCenter.two_norm();
148
149 // Compute the velocity gradients
150 // Outside - inside cell: therefore the minus-sign
151 // Only when cell contains sufficient water.
152 const auto gradU = -alphaWall * xVelocity/distance;
153 const auto gradV = -alphaWall * yVelocity/distance;
154
155 // Factor that takes the direction of the unit vector into account
156 const auto direction = (unitNormal*cellCenterToBoundaryFaceCenter)/distance;
157
158 // Compute the viscosity/diffusive fluxes at the rough wall
159 return {
160 0.0,
161 -turbulentViscosity*waterDepth*gradU*direction,
162 -turbulentViscosity*waterDepth*gradV*direction
163 };
164}
165
174template<class PrimaryVariables, class Scalar, class GlobalPosition>
175std::array<Scalar, 3> nikuradseWallBoundary(const Scalar ksWall,
176 const PrimaryVariables& state,
177 const GlobalPosition& cellCenterToBoundaryFaceCenter,
178 const GlobalPosition& unitNormal)
179{
180 // only impose if abs(ksWall) > 0
181 using std::abs;
182 if (abs(ksWall) <= 1.0e-9)
183 return {};
184
185 using std::hypot;
186 const Scalar xVelocity = state[1];
187 const Scalar yVelocity = state[2];
188 const Scalar velocityMagnitude = hypot(xVelocity, yVelocity);
189 const Scalar distance = cellCenterToBoundaryFaceCenter.two_norm();
190 const Scalar y0w = ksWall/30.0;
191 constexpr Scalar kappa2 = 0.41*0.41;
192
193 // should distance/y0w be limited to not become too small?
194 using std::log; using std::max;
195 const auto logYPlus = log(distance/y0w+1.0);
196 const auto fac = kappa2*velocityMagnitude / max(1.0e-3,logYPlus*logYPlus);
197
198 // Factor that takes the direction of the unit vector into account
199 const auto direction = (unitNormal*cellCenterToBoundaryFaceCenter)/distance;
200
201 // wall shear stress vector
202 const auto tauWx = direction*fac*xVelocity;
203 const auto tauWy = direction*fac*yVelocity;
204
205 // Compute the viscosity/diffusive fluxes at the rough wall
206 const auto waterDepth = state[0];
207 return {0.0, waterDepth*tauWx, waterDepth*tauWy};
208}
209
210} // end namespace Dumux::ShallowWater
211
212#endif
static ctype distance(const Dune::FieldVector< ctype, dimWorld > &a, const Dune::FieldVector< ctype, dimWorld > &b)
Compute the shortest distance between two points.
Definition: distance.hh:282
Vector unitNormal(const Vector &v)
Create a vector normal to the given one (v is expected to be non-zero)
Definition: normal.hh:58
Definition: exactriemann.hh:19
std::array< Scalar, 3 > fixedDischargeBoundary(const Scalar dischargeBoundary, const Scalar waterDepthInside, const Scalar velocityXInside, const Scalar velocityYInside, const Scalar gravity, const GlobalPosition &nxy)
Compute the outer cell state for a fixed discharge boundary.
Definition: boundaryfluxes.hh:74
std::array< Scalar, 3 > nikuradseWallBoundary(const Scalar ksWall, const PrimaryVariables &state, const GlobalPosition &cellCenterToBoundaryFaceCenter, const GlobalPosition &unitNormal)
Compute the viscosity/diffusive flux at a rough wall boundary using Nikuradse formulation.
Definition: boundaryfluxes.hh:175
std::array< Scalar, 3 > noslipWallBoundary(const Scalar alphaWall, const Scalar turbulentViscosity, const PrimaryVariables &state, const GlobalPosition &cellCenterToBoundaryFaceCenter, const GlobalPosition &unitNormal)
Compute the viscosity/diffusive flux at a rough wall boundary using no-slip formulation.
Definition: boundaryfluxes.hh:128
std::array< Scalar, 3 > fixedWaterDepthBoundary(const Scalar waterDepthBoundary, const Scalar waterDepthInside, const Scalar velocityXInside, const Scalar velocityYInside, const Scalar gravity, const GlobalPosition &nxy)
Compute the outer cell state for fixed water depth boundary.
Definition: boundaryfluxes.hh:40