PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
wallfunction.h
Go to the documentation of this file.
1#ifndef WALLFUNCTION_H
2#define WALLFUNCTION_H
3
4#include <petscpf.h>
5#include <petscdmswarm.h>
6#include <stdlib.h>
7#include <time.h>
8#include <math.h>
9#include <petsctime.h>
10#include <petscsys.h>
11#include <petscdmcomposite.h>
12#include <petscsystypes.h>
13
14// Include additional headers
15#include "variables.h" // Shared type definitions
16#include "ParticleSwarm.h" // Particle swarm functions
17#include "walkingsearch.h" // Particle location functions
18#include "grid.h" // Grid functions
19#include "logging.h" // Logging macros
20#include "io.h" // Data Input and Output functions
21#include "interpolation.h" // Interpolation routines
22#include "ParticleMotion.h" // Functions related to motion of particles
23#include "Boundaries.h" // Functions related to Boundary condition
24
25// ===========================================================================
26// Function Declarations
27// ===========================================================================
28
29/**
30 * @brief Computes roughness-modified log-law coefficient E
31 *
32 * The coefficient E accounts for wall roughness effects on the log-law:
33 * u+ = (1/κ) ln(E * y+)
34 *
35 * ROUGHNESS REGIMES:
36 * 1. Hydraulically smooth (ks+ < 2.25): E = exp(κ*B), no roughness effect
37 * 2. Transitional (2.25 < ks+ < 90): Smooth interpolation between regimes
38 * 3. Fully rough (ks+ > 90): E modified by roughness height
39 * where ks+ = u_τ * ks / ν (roughness Reynolds number)
40 *
41 * @param[in] friction_velocity Friction velocity u_τ
42 * @param[in] roughness_height Equivalent sand grain roughness height ks
43 * @param[in] kinematic_viscosity Kinematic viscosity ν
44 * @return Roughness-modified log-law coefficient E
45 *
46 * @note This follows the Nikuradse sand grain roughness correlation
47 */
48double E_coeff(double friction_velocity, double roughness_height, double kinematic_viscosity);
49
50/**
51 * @brief Computes velocity from log-law for rough walls
52 *
53 * Calculates the tangential velocity at a given wall distance using
54 * the roughness-modified log-law of the wall:
55 * - below the sublayer edge: u+ = y+
56 * - above it: u+ = (1/κ) ln(E * y+)
57 * where the edge is the y+ at which the two branches meet (about 11.45 for a smooth
58 * wall; it moves with E on a rough wall).
59 *
60 * @note Not called by the solver, which takes the friction velocity from the inverse
61 * @ref find_utau_hydset(); this forward form is the definition that inverse is
62 * tested against, and it agrees with it at every y+. Above y+ ~ 300 the flow
63 * leaves the logarithmic region; that limit is enforced on the first cell by the
64 * range check of LogWallModelDiagnostics(), not by this function.
65 *
66 * @param[in] kinematic_viscosity Kinematic viscosity ν
67 * @param[in] wall_distance Distance from wall y
68 * @param[in] friction_velocity Friction velocity u_τ
69 * @param[in] roughness_height Equivalent sand grain roughness ks
70 * @return Tangential velocity u_t
71 */
72double u_hydset_roughness(double kinematic_viscosity, double wall_distance,
73 double friction_velocity, double roughness_height);
74
75/**
76 * @brief Residual function for friction velocity equation (log-law with roughness)
77 *
78 * This function computes the residual for Newton-Raphson iteration:
79 * f(u_τ) = u_predicted(u_τ) - u_known
80 * where u_predicted comes from the log-law or linear law depending on y+.
81 *
82 * @param[in] kinematic_viscosity Kinematic viscosity
83 * @param[in] known_velocity Known velocity at distance y
84 * @param[in] wall_distance Distance from wall
85 * @param[in] friction_velocity_guess Current guess for u_τ
86 * @param[in] roughness_height Wall roughness height
87 * @return Residual value (should be zero at solution)
88 */
89double f_hydset(double kinematic_viscosity, double known_velocity,
90 double wall_distance, double friction_velocity_guess,
91 double roughness_height);
92
93/**
94 * @brief Numerical derivative of residual function
95 *
96 * Computes df/du_τ using finite differences for Newton-Raphson iteration.
97 *
98 * @param[in] kinematic_viscosity Kinematic viscosity
99 * @param[in] known_velocity Known velocity
100 * @param[in] wall_distance Distance from wall
101 * @param[in] friction_velocity_guess Current guess for u_τ
102 * @param[in] roughness_height Wall roughness
103 * @return Derivative df/du_τ
104 */
105double df_hydset(double kinematic_viscosity, double known_velocity,
106 double wall_distance, double friction_velocity_guess,
107 double roughness_height);
108
109/**
110 * @brief Solves for friction velocity using Newton-Raphson iteration
111 *
112 * Given a known velocity at a known distance from the wall, this function
113 * iteratively solves for the friction velocity u_τ that satisfies the
114 * roughness-modified log-law or linear law.
115 *
116 * ALGORITHM:
117 * Newton-Raphson: u_τ^(n+1) = u_τ^n - f(u_τ^n) / f'(u_τ^n)
118 * Convergence criterion: |u_τ^(n+1) - u_τ^n| < 1e-7
119 *
120 * @param[in] kinematic_viscosity Kinematic viscosity
121 * @param[in] known_velocity Velocity at reference point
122 * @param[in] wall_distance Distance from wall to reference point
123 * @param[in] initial_guess Initial guess for u_τ
124 * @param[in] roughness_height Wall roughness height
125 * @return Converged friction velocity u_τ
126 *
127 * @note Maximum 30 iterations; warns if convergence not achieved
128 * @note Typical convergence in 3-5 iterations for good initial guess
129 */
130double find_utau_hydset(double kinematic_viscosity, double known_velocity,
131 double wall_distance, double initial_guess,
132 double roughness_height);
133
134
135/**
136 * @brief Computes turbulent eddy viscosity ratio (ν_t / ν)
137 *
138 * Uses the mixing length model with van Driest damping:
139 * ν_t / ν = κ * y+ * [1 - exp(-y+ / A+)]²
140 * where A+ ≈ 19 is the damping coefficient.
141 *
142 * PHYSICAL INTERPRETATION:
143 * - Near wall (y+ → 0): ν_t → 0 (viscous effects dominate)
144 * - Far from wall (y+ >> A+): ν_t ~ κ * y+ (mixing length theory)
145 * - Damping function smoothly transitions between these limits
146 *
147 * @param[in] yplus Normalized wall distance y+ = y * u_τ / ν
148 * @return Eddy viscosity ratio ν_t / ν
149 *
150 * @note This is the standard mixing length model with van Driest damping
151 * @note Valid in the inner layer (y+ < 50-100)
152 */
153double nu_t(double yplus);
154
155/**
156 * @brief Integrates eddy viscosity profile from wall to distance y
157 *
158 * Computes integrals needed for non-equilibrium wall functions:
159 * If mode=0: ∫[0 to y] dy / (ν + ν_t)
160 * If mode=1: ∫[0 to y] y dy / (ν + ν_t)
161 *
162 * These integrals appear in the solution of the momentum equation
163 * with pressure gradients in the near-wall region.
164 *
165 * NUMERICAL METHOD:
166 * - Trapezoidal rule with 30 integration points
167 * - Higher-order correction at endpoints for accuracy
168 *
169 * @param[in] kinematic_viscosity Kinematic viscosity ν
170 * @param[in] wall_distance Distance from wall y
171 * @param[in] friction_velocity Friction velocity u_τ
172 * @param[in] integration_mode 0 for F integral, 1 for Fy integral
173 * @return Value of the integral
174 *
175 * @note Used in Cabot wall function for pressure gradient effects
176 */
177double integrate_1(double kinematic_viscosity, double wall_distance,
178 double friction_velocity, int integration_mode);
179
180/**
181 * @brief Computes wall shear stress with pressure gradient effects
182 *
183 * Solves the integrated momentum equation in the near-wall region:
184 * τ_w = (u - dp/dx * F_y) / F_1
185 * where F_1 and F_y are integrals of the effective viscosity profile.
186 *
187 * This accounts for non-equilibrium effects due to streamwise pressure gradients.
188 *
189 * @param[in] kinematic_viscosity Kinematic viscosity
190 * @param[in] friction_velocity Friction velocity u_τ
191 * @param[in] wall_distance Distance from wall
192 * @param[in] velocity Velocity at wall_distance
193 * @param[in] pressure_gradient_tangent Tangential pressure gradient dp/ds
194 * @return Wall shear stress τ_w
195 *
196 * @note This is more accurate than equilibrium wall functions in separated flows
197 */
198double taw(double kinematic_viscosity, double friction_velocity,
199 double wall_distance, double velocity, double pressure_gradient_tangent);
200
201/**
202 * @brief Computes velocity using Cabot wall function
203 *
204 * Reconstructs velocity from wall shear stress and pressure gradient:
205 * u = τ_w * F1 + (dp/dx) * Fy
206 *
207 * @note Not called by the solver, which takes the friction velocity from the inverse
208 * @ref find_utau_Cabot(); this forward form is the definition that inverse is
209 * tested against.
210 *
211 * @param[in] kinematic_viscosity Kinematic viscosity
212 * @param[in] wall_distance Distance from wall
213 * @param[in] friction_velocity Friction velocity
214 * @param[in] pressure_gradient_tangent Tangential pressure gradient
215 * @param[in] wall_shear_stress Wall shear stress
216 * @return Velocity at wall_distance
217 */
218double u_Cabot(double kinematic_viscosity, double wall_distance,
219 double friction_velocity, double pressure_gradient_tangent,
220 double wall_shear_stress);
221
222/**
223 * @brief Residual function for Cabot wall function
224 *
225 * Computes: f(u_τ) = u_τ - sqrt(|τ_w(u_τ)|)
226 * This enforces consistency between u_τ and τ_w.
227 *
228 * @param[in] kinematic_viscosity Kinematic viscosity
229 * @param[in] velocity Velocity
230 * @param[in] wall_distance Distance from wall
231 * @param[in] friction_velocity_guess Guess for u_τ
232 * @param[in] pressure_gradient_tangent Tangential pressure gradient
233 * @param[in] pressure_gradient_normal Normal pressure gradient (currently unused)
234 * @return Residual value
235 */
236double f_Cabot(double kinematic_viscosity, double velocity, double wall_distance,
237 double friction_velocity_guess, double pressure_gradient_tangent,
238 double pressure_gradient_normal);
239
240/**
241 * @brief Numerical derivative for Cabot wall function
242 *
243 * @param kinematic_viscosity Fluid kinematic viscosity.
244 * @param velocity Resolved tangential velocity at the wall-model point.
245 * @param wall_distance Normal distance from the wall.
246 * @param friction_velocity_guess Current friction-velocity iterate.
247 * @param pressure_gradient_tangent Tangential pressure-gradient contribution.
248 * @param pressure_gradient_normal Normal pressure-gradient contribution.
249 * @return Derivative of the Cabot residual with respect to friction velocity.
250 */
251double df_Cabot(double kinematic_viscosity, double velocity, double wall_distance,
252 double friction_velocity_guess, double pressure_gradient_tangent,
253 double pressure_gradient_normal);
254
255/**
256 * @brief Solves for friction velocity using Cabot wall function
257 *
258 * This non-equilibrium wall function accounts for pressure gradient effects,
259 * making it more accurate in separated or strongly accelerating/decelerating flows.
260 *
261 * @param[in] kinematic_viscosity Kinematic viscosity
262 * @param[in] velocity Velocity at reference point
263 * @param[in] wall_distance Distance from wall
264 * @param[in] initial_guess Initial guess for u_τ
265 * @param[in] pressure_gradient_tangent Tangential pressure gradient
266 * @param[in] pressure_gradient_normal Normal pressure gradient
267 * @param[out] friction_velocity Converged friction velocity
268 * @param[out] wall_shear_velocity Wall shear stress for velocity
269 * @param[out] wall_shear_normal Wall shear stress for normal pressure gradient
270 */
271void find_utau_Cabot(double kinematic_viscosity, double velocity, double wall_distance,
272 double initial_guess, double pressure_gradient_tangent,
273 double pressure_gradient_normal, double *friction_velocity,
274 double *wall_shear_velocity, double *wall_shear_normal);
275
276/**
277 * @brief Computes velocity using Werner-Wengle wall function
278 *
279 * The pointwise Werner-Wengle profile. Not called by the solver, which takes the friction
280 * velocity from its exact inverse, @ref find_utau_Werner(), at the reference cell; this
281 * forward form is the definition that inverse is tested against. Explicit relation:
282 * u+ = y+ below the sublayer edge (viscous sublayer)
283 * u+ = A * (y+)^B above it (power law)
284 * where A = 8.3, B = 1/7, and the edge is where the two meet, A^(7/6) = 11.8102.
285 *
286 * ADVANTAGES:
287 * - Explicit (no iteration required)
288 * - Computationally cheap
289 * - Reasonable accuracy for equilibrium boundary layers
290 *
291 * LIMITATIONS:
292 * - Less accurate than log-law for high Reynolds numbers
293 * - No pressure gradient effects
294 *
295 * @param[in] kinematic_viscosity Kinematic viscosity
296 * @param[in] wall_distance Distance from wall
297 * @param[in] friction_velocity Friction velocity
298 * @return Tangential velocity
299 */
300double u_Werner(double kinematic_viscosity, double wall_distance,
301 double friction_velocity);
302
303
304/**
305 * @brief Wall shear stress from the cell-integrated Werner-Wengle relation.
306 *
307 * @note Not wired into the solver. The profile is assumed to hold across a cell of height
308 * `wall_distance` and integrated, so `velocity` must be the AVERAGE over
309 * [0, wall_distance] - a finite-volume first-cell value with its full height. The
310 * wall function's reference is instead a point value at the second cell's centre;
311 * read as an average it over-predicts u_tau by about (1 + B)^(1/(1+B)), 12-14% on
312 * a wall-modelled channel at Re_tau ~ 1000. The solver uses the pointwise pair
313 * @ref find_utau_Werner() / @ref u_Werner(), which is also closed form. Kept, with
314 * its inverse @ref u_Werner_explicit(), for a caller that does supply a cell average.
315 *
316 * |u| <= u_m : tau_w = 2 nu |u| / y
317 * |u| > u_m : tau_w = [ (1-B)/2 A^((1+B)/(1-B)) (nu/y)^(1+B)
318 * + (1+B)/A (nu/y)^B |u| ]^(2/(1+B))
319 *
320 * with A = 8.3, B = 1/7, and the switch at u_m = nu/(2y) A^(2/(1-B)). That threshold
321 * depends only on the geometry and the fluid, which is what makes the inversion
322 * explicit; a threshold written in terms of the friction velocity would reintroduce the
323 * iteration the model exists to avoid. The two branches meet exactly at u_m.
324 *
325 * Pairs with @ref u_Werner_explicit(), which inverts it. Do not pair it with
326 * @ref u_Werner(), which is the pointwise profile rather than its cell integral.
327 *
328 * @param[in] kinematic_viscosity Kinematic viscosity.
329 * @param[in] velocity Wall-parallel speed at `wall_distance`, sign ignored.
330 * @param[in] wall_distance Normal distance the profile is integrated over.
331 * @return Wall shear stress, equal to the square of the friction velocity.
332 */
333double taw_Werner(double kinematic_viscosity, double velocity, double wall_distance);
334
335/**
336 * @brief Wall-parallel velocity at a distance, from the Werner-Wengle wall stress.
337 *
338 * The exact inverse of @ref taw_Werner(), branch for branch, so that a stress obtained
339 * from a velocity at one distance reproduces a consistent velocity at another. It is
340 * monotonically increasing in `wall_distance`, so a cell nearer the wall than the one
341 * the stress came from is always assigned the slower speed.
342 *
343 * The branch is selected on the stress rather than the velocity it is about to produce,
344 * using the same threshold expressed as tau_m = (nu/y)^2 A^(2/(1-B)).
345 *
346 * @param[in] kinematic_viscosity Kinematic viscosity.
347 * @param[in] wall_distance Normal distance to evaluate at.
348 * @param[in] wall_shear_stress Wall shear stress from @ref taw_Werner().
349 * @return Wall-parallel speed at `wall_distance`, non-negative.
350 */
351double u_Werner_explicit(double kinematic_viscosity, double wall_distance,
352 double wall_shear_stress);
353
354
355/**
356 * @brief Friction velocity from a point velocity, inverting @ref u_Werner() exactly.
357 *
358 * The closed-form inverse of the pointwise Werner-Wengle profile, branch for branch, and
359 * the solver's path. Along that profile U y / nu = (y+)^2 in the sublayer, so the branch
360 * is chosen from the data alone - sublayer while U y / nu <= (8.3^(7/6))^2, about 11.8102^2 - and each branch
361 * inverts explicitly:
362 *
363 * sublayer : u_tau = sqrt(nu |U| / y)
364 * power law : u_tau = ( |U| / (A (y/nu)^B) )^(1/(1+B)), A = 8.3, B = 1/7
365 *
366 * No iteration, so the residual it feeds stays smooth for a matrix-free Jacobian.
367 *
368 * @param[in] kinematic_viscosity Kinematic viscosity
369 * @param[in] velocity Wall-parallel speed at the reference point, sign ignored
370 * @param[in] wall_distance Distance from the wall to that point
371 * @param[in] initial_guess Unused; kept so existing callers need no change
372 * @return Friction velocity
373 */
374double find_utau_Werner(double kinematic_viscosity, double velocity,
375 double wall_distance, double initial_guess);
376
377
378
379
380#endif // WALLFUNCTION_H
Header file for Particle Motion and migration related functions.
Header file for Particle Swarm management functions.
Public interface for grid, solver, and metric setup routines.
Public interface for data input/output routines.
Logging utilities and macros for PETSc-based applications.
Main header file for a complex fluid dynamics solver.
Header file for particle location functions using the walking search algorithm.
double df_Cabot(double kinematic_viscosity, double velocity, double wall_distance, double friction_velocity_guess, double pressure_gradient_tangent, double pressure_gradient_normal)
Numerical derivative for Cabot wall function.
double f_Cabot(double kinematic_viscosity, double velocity, double wall_distance, double friction_velocity_guess, double pressure_gradient_tangent, double pressure_gradient_normal)
Residual function for Cabot wall function.
double u_Werner(double kinematic_viscosity, double wall_distance, double friction_velocity)
Computes velocity using Werner-Wengle wall function.
double u_hydset_roughness(double kinematic_viscosity, double wall_distance, double friction_velocity, double roughness_height)
Computes velocity from log-law for rough walls.
double u_Werner_explicit(double kinematic_viscosity, double wall_distance, double wall_shear_stress)
Wall-parallel velocity at a distance, from the Werner-Wengle wall stress.
double taw(double kinematic_viscosity, double friction_velocity, double wall_distance, double velocity, double pressure_gradient_tangent)
Computes wall shear stress with pressure gradient effects.
double find_utau_hydset(double kinematic_viscosity, double known_velocity, double wall_distance, double initial_guess, double roughness_height)
Solves for friction velocity using Newton-Raphson iteration.
double u_Cabot(double kinematic_viscosity, double wall_distance, double friction_velocity, double pressure_gradient_tangent, double wall_shear_stress)
Computes velocity using Cabot wall function.
void find_utau_Cabot(double kinematic_viscosity, double velocity, double wall_distance, double initial_guess, double pressure_gradient_tangent, double pressure_gradient_normal, double *friction_velocity, double *wall_shear_velocity, double *wall_shear_normal)
Solves for friction velocity using Cabot wall function.
double integrate_1(double kinematic_viscosity, double wall_distance, double friction_velocity, int integration_mode)
Integrates eddy viscosity profile from wall to distance y.
double f_hydset(double kinematic_viscosity, double known_velocity, double wall_distance, double friction_velocity_guess, double roughness_height)
Residual function for friction velocity equation (log-law with roughness)
double E_coeff(double friction_velocity, double roughness_height, double kinematic_viscosity)
Computes roughness-modified log-law coefficient E.
double taw_Werner(double kinematic_viscosity, double velocity, double wall_distance)
Wall shear stress from the cell-integrated Werner-Wengle relation.
double nu_t(double yplus)
Computes turbulent eddy viscosity ratio (ν_t / ν)
double df_hydset(double kinematic_viscosity, double known_velocity, double wall_distance, double friction_velocity_guess, double roughness_height)
Numerical derivative of residual function.
double find_utau_Werner(double kinematic_viscosity, double velocity, double wall_distance, double initial_guess)
Friction velocity from a point velocity, inverting u_Werner() exactly.