3.6-git
DUNE for Multi-{Phase, Component, Scale, Physics, ...} flow and transport in porous media
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 * See the file COPYING for full copying permissions. *
5 * *
6 * This program is free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 *****************************************************************************/
30#ifndef DUMUX_SHALLOWWATER_BOUNDARYFLUXES_HH
31#define DUMUX_SHALLOWWATER_BOUNDARYFLUXES_HH
32
33#include <array>
34#include <cmath>
35#include <algorithm>
36
37namespace Dumux::ShallowWater {
38
51template<class Scalar, class GlobalPosition>
52std::array<Scalar, 3> fixedWaterDepthBoundary(const Scalar waterDepthBoundary,
53 const Scalar waterDepthInside,
54 const Scalar velocityXInside,
55 const Scalar velocityYInside,
56 const Scalar gravity,
57 const GlobalPosition& nxy)
58
59{
60 std::array<Scalar, 3> cellStateOutside;
61 cellStateOutside[0] = waterDepthBoundary;
62
63 using std::sqrt;
64 const auto uboundIn = nxy[0] * velocityXInside + nxy[1] * velocityYInside;
65 const auto uboundQut = uboundIn + 2.0 * sqrt(gravity * waterDepthInside) - 2.0 * sqrt(gravity * cellStateOutside[0]);
66
67 cellStateOutside[1] = (nxy[0] * uboundQut); // we only use the normal part
68 cellStateOutside[2] = (nxy[1] * uboundQut); // we only use the normal part
69
70 return cellStateOutside;
71}
72
85template<class Scalar, class GlobalPosition>
86std::array<Scalar, 3> fixedDischargeBoundary(const Scalar dischargeBoundary,
87 const Scalar waterDepthInside,
88 const Scalar velocityXInside,
89 const Scalar velocityYInside,
90 const Scalar gravity,
91 const GlobalPosition& nxy)
92{
93 std::array<Scalar, 3> cellStateOutside;
94 using std::abs;
95 using std::sqrt;
96 using std::max;
97
98 // only impose if abs(q) > 0
99 if (abs(dischargeBoundary) > 1.0e-9)
100 {
101 const auto uboundIn = nxy[0]*velocityXInside + nxy[1]*velocityYInside;
102 const auto alphal = uboundIn + 2.0*sqrt(gravity * waterDepthInside);
103
104 //initial guess for hstar solved with newton
105 constexpr Scalar tol_hstar = 1.0E-12;
106 constexpr Scalar ink_hstar = 1.0E-9;
107 constexpr int maxstep_hstar = 30;
108
109 Scalar hstar = 0.1;
110 for (int i = 0; i < maxstep_hstar; ++i)
111 {
112 Scalar f_hstar = alphal - dischargeBoundary/hstar - 2 * sqrt(gravity * hstar);
113 Scalar df_hstar = (f_hstar -(alphal - dischargeBoundary/(hstar + ink_hstar) - 2 * sqrt(gravity * (hstar+ink_hstar))))/ink_hstar;
114 Scalar dx_hstar = -f_hstar/df_hstar;
115 hstar = max(hstar - dx_hstar,0.001);
116
117 if (dx_hstar*dx_hstar < tol_hstar)
118 break;
119 }
120
121 const auto qinner = (nxy[0] * waterDepthInside * velocityYInside) - (nxy[1] * waterDepthInside * velocityXInside);
122 cellStateOutside[0] = hstar;
123 cellStateOutside[1] = (nxy[0] * dischargeBoundary - nxy[1] * qinner)/hstar;
124 cellStateOutside[2] = (nxy[1] * dischargeBoundary + nxy[0] * qinner)/hstar;
125 }
126
127 return cellStateOutside;
128}
129
139template<class PrimaryVariables, class Scalar, class GlobalPosition>
140std::array<Scalar, 3> noslipWallBoundary(const Scalar alphaWall,
141 const Scalar turbulentViscosity,
142 const PrimaryVariables& state,
143 const GlobalPosition& cellCenterToBoundaryFaceCenter,
144 const GlobalPosition& unitNormal)
145{
146 // only impose if abs(alphaWall) > 0
147 using std::abs;
148 if (abs(alphaWall) <= 1.0e-9)
149 return {};
150
151 const auto waterDepth = state[0];
152 // regularization: Set gradients to zero for drying cell
153 // Use LET-limiter instead for differentiability?
154 if (waterDepth <= 0.001)
155 return {};
156
157 const auto xVelocity = state[1];
158 const auto yVelocity = state[2];
159 const auto distance = cellCenterToBoundaryFaceCenter.two_norm();
160
161 // Compute the velocity gradients
162 // Outside - inside cell: therefore the minus-sign
163 // Only when cell contains sufficient water.
164 const auto gradU = -alphaWall * xVelocity/distance;
165 const auto gradV = -alphaWall * yVelocity/distance;
166
167 // Factor that takes the direction of the unit vector into account
168 const auto direction = (unitNormal*cellCenterToBoundaryFaceCenter)/distance;
169
170 // Compute the viscosity/diffusive fluxes at the rough wall
171 return {
172 0.0,
173 -turbulentViscosity*waterDepth*gradU*direction,
174 -turbulentViscosity*waterDepth*gradV*direction
175 };
176}
177
186template<class PrimaryVariables, class Scalar, class GlobalPosition>
187std::array<Scalar, 3> nikuradseWallBoundary(const Scalar ksWall,
188 const PrimaryVariables& state,
189 const GlobalPosition& cellCenterToBoundaryFaceCenter,
190 const GlobalPosition& unitNormal)
191{
192 // only impose if abs(ksWall) > 0
193 using std::abs;
194 if (abs(ksWall) <= 1.0e-9)
195 return {};
196
197 using std::hypot;
198 const Scalar xVelocity = state[1];
199 const Scalar yVelocity = state[2];
200 const Scalar velocityMagnitude = hypot(xVelocity, yVelocity);
201 const Scalar distance = cellCenterToBoundaryFaceCenter.two_norm();
202 const Scalar y0w = ksWall/30.0;
203 constexpr Scalar kappa2 = 0.41*0.41;
204
205 // should distance/y0w be limited to not become too small?
206 using std::log; using std::max;
207 const auto logYPlus = log(distance/y0w+1.0);
208 const auto fac = kappa2*velocityMagnitude / max(1.0e-3,logYPlus*logYPlus);
209
210 // Factor that takes the direction of the unit vector into account
211 const auto direction = (unitNormal*cellCenterToBoundaryFaceCenter)/distance;
212
213 // wall shear stress vector
214 const auto tauWx = direction*fac*xVelocity;
215 const auto tauWy = direction*fac*yVelocity;
216
217 // Compute the viscosity/diffusive fluxes at the rough wall
218 const auto waterDepth = state[0];
219 return {0.0, waterDepth*tauWx, waterDepth*tauWy};
220}
221
222} // end namespace Dumux::ShallowWater
223
224#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:294
Vector unitNormal(const Vector &v)
Create a vector normal to the given one (v is expected to be non-zero)
Definition: normal.hh:70
Definition: exactriemann.hh:31
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:86
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:187
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:140
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:52