Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
reichardt_cpu.f90
Go to the documentation of this file.
1! Copyright (c) 2026, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
33!> Implements the CPU kernel for the `reichardt_t` type.
35 use num_types, only : rp
36 use math, only : neko_eps
38 implicit none
39 private
40
41 public :: reichardt_compute_cpu
42
43contains
44 !> Compute the wall shear stress on cpu using Reichardt's law.
45 !! @param u The x component of the sampled velocity.
46 !! @param v The y component of the sampled velocity.
47 !! @param w The z component of the sampled velocity.
48 !! @param n_x The x component of the wall normal.
49 !! @param n_y The y component of the wall normal.
50 !! @param n_z The z component of the wall normal.
51 !! @param nu The kinematic viscosity at the wall.
52 !! @param rho_w The density at the wall.
53 !! @param h The wall-normal distance of the sampling point.
54 !! @param tau_x The x component of the wall shear stress.
55 !! @param tau_y The y component of the wall shear stress.
56 !! @param tau_z The z component of the wall shear stress.
57 !! @param n_nodes The number of wall nodes.
58 !! @param kappa The von Karman coefficient.
59 !! @param C The amplitude of the exponential correction.
60 !! @param B1 The damping length scale, in wall units.
61 !! @param B2 The decay length scale of the second exponential term, in
62 !! wall units.
63 !! @param tstep The current time-step.
64 subroutine reichardt_compute_cpu(u, v, w, &
65 n_x, n_y, n_z, nu, rho_w, h, tau_x, tau_y, tau_z, n_nodes, &
66 kappa, C, B1, B2, tstep)
67 integer, intent(in) :: n_nodes, tstep
68 real(kind=rp), dimension(n_nodes), intent(in) :: u, v, w
69 real(kind=rp), dimension(n_nodes), intent(in) :: rho_w
70 real(kind=rp), dimension(n_nodes), intent(in) :: n_x, n_y, n_z, h, nu
71 real(kind=rp), dimension(n_nodes), intent(inout) :: tau_x, tau_y, tau_z
72 real(kind=rp), intent(in) :: kappa, c, b1, b2
73 integer :: i
74 real(kind=rp) :: ui, vi, wi, magu, utau, normu, guess, rho
75
76 !$omp parallel do private(i, ui, vi, wi, magu, utau, normu, guess, rho)
77 do i = 1, n_nodes
78 ! Load the sampled velocity
79 ui = u(i)
80 vi = v(i)
81 wi = w(i)
82 rho = rho_w(i)
83
84 ! Project on tangential direction
85 normu = ui * n_x(i) + vi * n_y(i) + wi * n_z(i)
86
87 ui = ui - normu * n_x(i)
88 vi = vi - normu * n_y(i)
89 wi = wi - normu * n_z(i)
90
91 magu = sqrt(ui**2 + vi**2 + wi**2)
92
93 ! No tangential velocity, no shear stress
94 if (magu .le. neko_eps) then
95 tau_x(i) = 0.0_rp
96 tau_y(i) = 0.0_rp
97 tau_z(i) = 0.0_rp
98 cycle
99 end if
100
101 ! Get initial guess for Newton solver
102 guess = tau_x(i)**2 + tau_y(i)**2 + tau_z(i)**2
103 if (tstep .eq. 1 .or. guess .le. 0.0_rp) then
104 guess = sqrt(magu * nu(i) / h(i))
105 else
106 guess = sqrt(sqrt(guess) / rho)
107 end if
108
109 utau = solve_cpu(magu, h(i), guess, nu(i), kappa, c, b1, b2)
110
111 ! Distribute according to the velocity vector
112 tau_x(i) = -rho*utau**2 * ui / magu
113 tau_y(i) = -rho*utau**2 * vi / magu
114 tau_z(i) = -rho*utau**2 * wi / magu
115 end do
116 !$omp end parallel do
117
118 end subroutine reichardt_compute_cpu
119
120 !> Evaluate Reichardt's law of the wall, u+ as a function of y+.
121 !! @param yp The wall-normal distance in wall units.
122 !! @param kappa The von Karman coefficient.
123 !! @param C The amplitude of the exponential correction.
124 !! @param B1 The damping length scale, in wall units.
125 !! @param B2 The decay length scale of the second exponential term.
126 pure function reichardt_up(yp, kappa, C, B1, B2) result(up)
127 real(kind=rp), intent(in) :: yp, kappa, c, b1, b2
128 real(kind=rp) :: up
129
130 up = log(1.0_rp + kappa*yp) / kappa + c * &
131 (1.0_rp - exp(-yp/b1) - yp/b1 * exp(-yp/b2))
132 end function reichardt_up
133
134 !> Evaluate the derivative du+/dy+ of Reichardt's law of the wall.
135 !! @param yp The wall-normal distance in wall units.
136 !! @param kappa The von Karman coefficient.
137 !! @param C The amplitude of the exponential correction.
138 !! @param B1 The damping length scale, in wall units.
139 !! @param B2 The decay length scale of the second exponential term.
140 pure function reichardt_dup(yp, kappa, C, B1, B2) result(dup)
141 real(kind=rp), intent(in) :: yp, kappa, c, b1, b2
142 real(kind=rp) :: dup
143
144 dup = 1.0_rp / (1.0_rp + kappa*yp) + c / b1 * &
145 (exp(-yp/b1) - (1.0_rp - yp/b2) * exp(-yp/b2))
146 end function reichardt_dup
147
148 !> Newton solver for the algebraic equation defined by the law on cpu.
149 !! Solves f(utau) = utau * u+(y utau / nu) - u = 0.
150 !! @param u The velocity value.
151 !! @param y The wall-normal distance.
152 !! @param guess Initial guess.
153 !! @param nu The molecular kinematic viscosity.
154 !! @param kappa The von Karman constant.
155 !! @param C The amplitude of the exponential correction.
156 !! @param B1 The damping length scale, in wall units.
157 !! @param B2 The decay length scale of the second exponential term.
158 function solve_cpu(u, y, guess, nu, kappa, C, B1, B2) result(utau)
159 real(kind=rp), intent(in) :: u
160 real(kind=rp), intent(in) :: y
161 real(kind=rp), intent(in) :: guess
162 real(kind=rp), intent(in) :: nu, kappa, c, b1, b2
163 real(kind=rp) :: yp, up, utau
164 real(kind=rp) :: error, f, df, old, tol
165 integer :: k, maxiter
166 logical :: converged
167 character(len=LOG_SIZE) :: log_msg
168
169 utau = guess
170 maxiter = 100
171 tol = max(1e-8_rp, 10.0_rp * neko_eps)
172 converged = .false.
173 error = 0.0_rp
174 f = 0.0_rp
175
176 do k = 1, maxiter
177 old = utau
178 yp = y * utau / nu
179 up = reichardt_up(yp, kappa, c, b1, b2)
180
181 ! Evaluate function and its derivative
182 f = utau * up - u
183 df = up + yp * reichardt_dup(yp, kappa, c, b1, b2)
184
185 ! Update solution, keeping utau positive
186 utau = utau - f / df
187 if (utau .le. 0.0_rp) utau = 0.5_rp * old
188
189 error = abs((old - utau)/old)
190
191 if (error .lt. tol) then
192 converged = .true.
193 exit
194 end if
195 end do
196
197 if (.not. converged) then
198 ! Called from inside an OpenMP loop, so serialise the log write.
199 !$omp critical
200 write(log_msg, *) "Newton not converged", error, f, utau
201 call neko_log%message(log_msg, neko_log_debug)
202 !$omp end critical
203 end if
204 end function solve_cpu
205end module reichardt_cpu
Logging routines.
Definition log.f90:34
integer, parameter, public neko_log_debug
Debug.
Definition log.f90:56
type(log_t), public neko_log
Global log stream.
Definition log.f90:92
integer, parameter, public log_size
Definition log.f90:46
Definition math.F90:60
real(kind=rp), parameter, public neko_eps
Machine epsilon .
Definition math.F90:70
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Implements the CPU kernel for the reichardt_t type.
pure real(kind=rp) function reichardt_dup(yp, kappa, c, b1, b2)
Evaluate the derivative du+/dy+ of Reichardt's law of the wall.
subroutine, public reichardt_compute_cpu(u, v, w, n_x, n_y, n_z, nu, rho_w, h, tau_x, tau_y, tau_z, n_nodes, kappa, c, b1, b2, tstep)
Compute the wall shear stress on cpu using Reichardt's law.
pure real(kind=rp) function reichardt_up(yp, kappa, c, b1, b2)
Evaluate Reichardt's law of the wall, u+ as a function of y+.
real(kind=rp) function solve_cpu(u, y, guess, nu, kappa, c, b1, b2)
Newton solver for the algebraic equation defined by the law on cpu. Solves f(utau) = utau * u+(y utau...
#define max(a, b)
Definition tensor.cu:40