PICurv 0.1.0
A Parallel Particle-In-Cell Solver for Curvilinear LES
 
Loading...
Searching...
No Matches
Functions
wallfunction.h File Reference
#include <petscpf.h>
#include <petscdmswarm.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <petsctime.h>
#include <petscsys.h>
#include <petscdmcomposite.h>
#include <petscsystypes.h>
#include "variables.h"
#include "ParticleSwarm.h"
#include "walkingsearch.h"
#include "grid.h"
#include "logging.h"
#include "io.h"
#include "interpolation.h"
#include "ParticleMotion.h"
#include "Boundaries.h"
Include dependency graph for wallfunction.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

double E_coeff (double friction_velocity, double roughness_height, double kinematic_viscosity)
 Computes roughness-modified log-law coefficient E.
 
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 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 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_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 nu_t (double yplus)
 Computes turbulent eddy viscosity ratio (ν_t / ν)
 
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 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 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.
 
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 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.
 
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 u_Werner (double kinematic_viscosity, double wall_distance, double friction_velocity)
 Computes velocity using Werner-Wengle wall function.
 
double taw_Werner (double kinematic_viscosity, double velocity, double wall_distance)
 Wall shear stress from the cell-integrated Werner-Wengle relation.
 
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 find_utau_Werner (double kinematic_viscosity, double velocity, double wall_distance, double initial_guess)
 Friction velocity from a point velocity, inverting u_Werner() exactly.
 

Function Documentation

◆ E_coeff()

double E_coeff ( double  friction_velocity,
double  roughness_height,
double  kinematic_viscosity 
)

Computes roughness-modified log-law coefficient E.

The coefficient E accounts for wall roughness effects on the log-law: u+ = (1/κ) ln(E * y+)

ROUGHNESS REGIMES:

  1. Hydraulically smooth (ks+ < 2.25): E = exp(κ*B), no roughness effect
  2. Transitional (2.25 < ks+ < 90): Smooth interpolation between regimes
  3. Fully rough (ks+ > 90): E modified by roughness height where ks+ = u_τ * ks / ν (roughness Reynolds number)
Parameters
[in]friction_velocityFriction velocity u_τ
[in]roughness_heightEquivalent sand grain roughness height ks
[in]kinematic_viscosityKinematic viscosity ν
Returns
Roughness-modified log-law coefficient E
Note
This follows the Nikuradse sand grain roughness correlation

Computes roughness-modified log-law coefficient E.

See also
E_coeff()

Definition at line 77 of file wallfunction.c.

78{
79 // Compute roughness Reynolds number
80 double roughness_reynolds = friction_velocity * roughness_height / kinematic_viscosity;
81
82 double roughness_correction;
83
84 if (roughness_reynolds <= ROUGHNESS_TRANSITION_YPLUS) {
85 // Hydraulically smooth regime: no correction needed
86 roughness_correction = 0.0;
87 }
88 else if (roughness_reynolds < FULLY_ROUGH_YPLUS) {
89 // Transitional regime: smooth interpolation using sine function
90 // This provides a gradual transition between smooth and rough wall behavior
91 double max_correction = LOGLAW_B - 8.5 + (1.0 / KAPPA) * log(roughness_reynolds);
92
93 roughness_correction = max_correction *
94 sin(0.4258 * (log(roughness_reynolds) - 0.811));
95 }
96 else {
97 // Fully rough regime: maximum correction
98 roughness_correction = LOGLAW_B - 8.5 + (1.0 / KAPPA) * log(roughness_reynolds);
99 }
100
101 // Return E = exp[κ(B - ΔB)]
102 return exp(KAPPA * (LOGLAW_B - roughness_correction));
103}
#define ROUGHNESS_TRANSITION_YPLUS
Smooth-to-rough transition y+ threshold.
#define LOGLAW_B
Log-law intercept constant B for smooth walls.
#define FULLY_ROUGH_YPLUS
Fully rough regime y+ threshold.
#define KAPPA
von Karman constant (universal turbulence constant)
Here is the caller graph for this function:

◆ u_hydset_roughness()

double u_hydset_roughness ( double  kinematic_viscosity,
double  wall_distance,
double  friction_velocity,
double  roughness_height 
)

Computes velocity from log-law for rough walls.

Calculates the tangential velocity at a given wall distance using the roughness-modified log-law of the wall:

  • below the sublayer edge: u+ = y+
  • above it: u+ = (1/κ) ln(E * y+) where the edge is the y+ at which the two branches meet (about 11.45 for a smooth wall; it moves with E on a rough wall).
Note
Not called by the solver, which takes the friction velocity from the inverse find_utau_hydset(); this forward form is the definition that inverse is tested against, and it agrees with it at every y+. Above y+ ~ 300 the flow leaves the logarithmic region; that limit is enforced on the first cell by the range check of LogWallModelDiagnostics(), not by this function.
Parameters
[in]kinematic_viscosityKinematic viscosity ν
[in]wall_distanceDistance from wall y
[in]friction_velocityFriction velocity u_τ
[in]roughness_heightEquivalent sand grain roughness ks
Returns
Tangential velocity u_t

Computes velocity from log-law for rough walls.

See also
u_hydset_roughness()

Definition at line 134 of file wallfunction.c.

136{
137 // Normalized wall distance
138 double yplus = friction_velocity * wall_distance / kinematic_viscosity;
139 const double E = E_coeff(friction_velocity, roughness_height, kinematic_viscosity);
140
141 double tangential_velocity;
142
143 /* The forward form of exactly the relation find_utau_hydset() inverts, at every y+:
144 the logarithmic branch continues above y+ = 300 as it does in the inverse. Whether
145 the first cell lies where the law describes the flow is the range check in
146 LogWallModelDiagnostics(), not a property of the profile. */
147 if (yplus <= LogLawSublayerEdge(E)) {
148 // Viscous sublayer: linear velocity profile
149 tangential_velocity = friction_velocity * yplus;
150 }
151 else {
152 // Log-layer: logarithmic velocity profile with roughness correction
153 tangential_velocity = (friction_velocity / KAPPA) * log(E * yplus);
154 }
155
156 return tangential_velocity;
157}
static double LogLawSublayerEdge(double E)
The log law's sublayer edge for a given E: the y+ where u+ = y+ meets u+ = ln(E y+)/kappa.
double E_coeff(double friction_velocity, double roughness_height, double kinematic_viscosity)
Implementation of E_coeff().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ f_hydset()

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)

This function computes the residual for Newton-Raphson iteration: f(u_τ) = u_predicted(u_τ) - u_known where u_predicted comes from the log-law or linear law depending on y+.

Parameters
[in]kinematic_viscosityKinematic viscosity
[in]known_velocityKnown velocity at distance y
[in]wall_distanceDistance from wall
[in]friction_velocity_guessCurrent guess for u_τ
[in]roughness_heightWall roughness height
Returns
Residual value (should be zero at solution)

Residual function for friction velocity equation (log-law with roughness)

See also
f_hydset()

Definition at line 167 of file wallfunction.c.

170{
171 double yplus = friction_velocity_guess * wall_distance / kinematic_viscosity;
172 double E = E_coeff(friction_velocity_guess, roughness_height, kinematic_viscosity);
173 double residual;
174
175 if (yplus <= LogLawSublayerEdge(E)) {
176 // Viscous sublayer: u = u_τ * y+
177 residual = friction_velocity_guess * yplus - known_velocity;
178 }
179 else {
180 // Log-layer: u = (u_τ / κ) * ln(E * y+)
181 residual = friction_velocity_guess * (1.0 / KAPPA * log(E * yplus)) - known_velocity;
182 }
183
184 return residual;
185}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ df_hydset()

double df_hydset ( double  kinematic_viscosity,
double  known_velocity,
double  wall_distance,
double  friction_velocity_guess,
double  roughness_height 
)

Numerical derivative of residual function.

Computes df/du_τ using finite differences for Newton-Raphson iteration.

Parameters
[in]kinematic_viscosityKinematic viscosity
[in]known_velocityKnown velocity
[in]wall_distanceDistance from wall
[in]friction_velocity_guessCurrent guess for u_τ
[in]roughness_heightWall roughness
Returns
Derivative df/du_τ

Numerical derivative of residual function.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/wallfunction.h.

See also
df_hydset()

Definition at line 193 of file wallfunction.c.

196{
197 const double perturbation = 1.e-7;
198
199 double f_plus = f_hydset(kinematic_viscosity, known_velocity, wall_distance,
200 friction_velocity_guess + perturbation, roughness_height);
201
202 double f_minus = f_hydset(kinematic_viscosity, known_velocity, wall_distance,
203 friction_velocity_guess - perturbation, roughness_height);
204
205 return (f_plus - f_minus) / (2.0 * perturbation);
206}
double f_hydset(double kinematic_viscosity, double known_velocity, double wall_distance, double friction_velocity_guess, double roughness_height)
Implementation of f_hydset().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_utau_hydset()

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.

Given a known velocity at a known distance from the wall, this function iteratively solves for the friction velocity u_τ that satisfies the roughness-modified log-law or linear law.

ALGORITHM: Newton-Raphson: u_τ^(n+1) = u_τ^n - f(u_τ^n) / f'(u_τ^n) Convergence criterion: |u_τ^(n+1) - u_τ^n| < 1e-7

Parameters
[in]kinematic_viscosityKinematic viscosity
[in]known_velocityVelocity at reference point
[in]wall_distanceDistance from wall to reference point
[in]initial_guessInitial guess for u_τ
[in]roughness_heightWall roughness height
Returns
Converged friction velocity u_τ
Note
Maximum 30 iterations; warns if convergence not achieved
Typical convergence in 3-5 iterations for good initial guess

Solves for friction velocity using Newton-Raphson iteration.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/wallfunction.h.

See also
find_utau_hydset()

Definition at line 214 of file wallfunction.c.

217{
218 double friction_velocity = initial_guess;
219 double friction_velocity_old = initial_guess;
220
221 const int max_iterations = 30;
222 const double convergence_tolerance = 1.e-7;
223
224 int iteration;
225 for (iteration = 0; iteration < max_iterations; iteration++) {
226 // Newton-Raphson update
227 double residual = f_hydset(kinematic_viscosity, known_velocity, wall_distance,
228 friction_velocity_old, roughness_height);
229 double derivative = df_hydset(kinematic_viscosity, known_velocity, wall_distance,
230 friction_velocity_old, roughness_height);
231 if (derivative == 0.0 || !isfinite(derivative)) break;
232
233 friction_velocity = friction_velocity_old - residual / derivative;
234 /* The friction velocity is positive. The linear branch's residual u_tau^2 y/nu - U
235 has a mirror root at -u_tau, which an undamped step from a small guess can reach
236 (a rough wall made it common); halving toward the last positive iterate keeps the
237 iteration on the physical root. */
238 if (!(friction_velocity > 0.0)) friction_velocity = 0.5 * friction_velocity_old;
239
240 // Check convergence
241 if (fabs(friction_velocity - friction_velocity_old) < convergence_tolerance) {
242 break;
243 }
244
245 friction_velocity_old = friction_velocity;
246 }
247
248 // Warn if convergence not achieved
249 if (iteration == max_iterations) {
251 "WARNING: u_tau iteration did not converge after %d iterations. "
252 "Final difference: %le\n",
253 iteration, fabs(friction_velocity - friction_velocity_old));
254 }
255
256 return friction_velocity;
257}
#define LOCAL
Logging scope definitions for controlling message output.
Definition logging.h:45
#define LOG_ALLOW(scope, level, fmt,...)
Logging macro that checks both the log level and whether the calling function is in the allowed-funct...
Definition logging.h:214
@ LOG_DEBUG
Detailed debugging information.
Definition logging.h:32
double df_hydset(double kinematic_viscosity, double known_velocity, double wall_distance, double friction_velocity_guess, double roughness_height)
Implementation of df_hydset().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nu_t()

double nu_t ( double  yplus)

Computes turbulent eddy viscosity ratio (ν_t / ν)

Uses the mixing length model with van Driest damping: ν_t / ν = κ * y+ * [1 - exp(-y+ / A+)]² where A+ ≈ 19 is the damping coefficient.

PHYSICAL INTERPRETATION:

  • Near wall (y+ → 0): ν_t → 0 (viscous effects dominate)
  • Far from wall (y+ >> A+): ν_t ~ κ * y+ (mixing length theory)
  • Damping function smoothly transitions between these limits
Parameters
[in]yplusNormalized wall distance y+ = y * u_τ / ν
Returns
Eddy viscosity ratio ν_t / ν
Note
This is the standard mixing length model with van Driest damping
Valid in the inner layer (y+ < 50-100)

Computes turbulent eddy viscosity ratio (ν_t / ν)

See also
nu_t()

Definition at line 267 of file wallfunction.c.

268{
269 // van Driest damping function: [1 - exp(-y+ / A+)]²
270 double damping_function = 1.0 - exp(-yplus / DAMPING_COEFFICIENT);
271
272 // Mixing length model: ν_t / ν = κ * y+ * D²
273 return KAPPA * yplus * damping_function * damping_function;
274}
#define DAMPING_COEFFICIENT
Eddy viscosity damping coefficient (van Driest damping)
Here is the caller graph for this function:

◆ integrate_1()

double integrate_1 ( double  kinematic_viscosity,
double  wall_distance,
double  friction_velocity,
int  integration_mode 
)

Integrates eddy viscosity profile from wall to distance y.

Computes integrals needed for non-equilibrium wall functions: If mode=0: ∫[0 to y] dy / (ν + ν_t) If mode=1: ∫[0 to y] y dy / (ν + ν_t)

These integrals appear in the solution of the momentum equation with pressure gradients in the near-wall region.

NUMERICAL METHOD:

  • Trapezoidal rule with 30 integration points
  • Higher-order correction at endpoints for accuracy
Parameters
[in]kinematic_viscosityKinematic viscosity ν
[in]wall_distanceDistance from wall y
[in]friction_velocityFriction velocity u_τ
[in]integration_mode0 for F integral, 1 for Fy integral
Returns
Value of the integral
Note
Used in Cabot wall function for pressure gradient effects

Integrates eddy viscosity profile from wall to distance y.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/wallfunction.h.

See also
integrate_1()

Definition at line 282 of file wallfunction.c.

284{
285 /* Composite Simpson in s, with y = wall_distance * s^2. The integrand falls off like
286 1/y+ across the log layer, so uniform points in y left the near-wall rise under-sampled:
287 30 of them were about 33% off at y+ = 1000. Clustering them toward the wall as s^2 does
288 makes the mapped integrand smooth at every y+ the model is allowed to reach. */
289 const int intervals = 128; /* even */
290 const double ds = 1.0 / intervals;
291 double integral_sum = 0.0;
292
293 for (int i = 0; i <= intervals; i++) {
294 const double s_value = i * ds;
295 const double current_distance = wall_distance * s_value * s_value;
296 const double jacobian = 2.0 * wall_distance * s_value; /* dy/ds */
297 const double yplus = current_distance * friction_velocity / kinematic_viscosity;
298 const double denominator = (1.0 + nu_t(fabs(yplus))) * kinematic_viscosity;
299 const double integrand = ((integration_mode == 0) ? 1.0 : current_distance) / denominator * jacobian;
300 const double weight = (i == 0 || i == intervals) ? 1.0 : ((i % 2) ? 4.0 : 2.0);
301
302 integral_sum += weight * integrand;
303 }
304 return integral_sum * ds / 3.0;
305}
double nu_t(double yplus)
Implementation of nu_t().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ taw()

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.

Solves the integrated momentum equation in the near-wall region: τ_w = (u - dp/dx * F_y) / F_1 where F_1 and F_y are integrals of the effective viscosity profile.

This accounts for non-equilibrium effects due to streamwise pressure gradients.

Parameters
[in]kinematic_viscosityKinematic viscosity
[in]friction_velocityFriction velocity u_τ
[in]wall_distanceDistance from wall
[in]velocityVelocity at wall_distance
[in]pressure_gradient_tangentTangential pressure gradient dp/ds
Returns
Wall shear stress τ_w
Note
This is more accurate than equilibrium wall functions in separated flows

Computes wall shear stress with pressure gradient effects.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/wallfunction.h.

See also
taw()

Definition at line 317 of file wallfunction.c.

319{
320 // Compute integrated viscosity profiles
321 double F1 = integrate_1(kinematic_viscosity, wall_distance, friction_velocity, 0);
322 double Fy = integrate_1(kinematic_viscosity, wall_distance, friction_velocity, 1);
323
324 // Apply momentum balance: τ_w * F1 = u - (dp/dx) * Fy
325 return (1.0 / F1) * (velocity - pressure_gradient_tangent * Fy);
326}
double integrate_1(double kinematic_viscosity, double wall_distance, double friction_velocity, int integration_mode)
Implementation of integrate_1().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ u_Cabot()

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.

Reconstructs velocity from wall shear stress and pressure gradient: u = τ_w * F1 + (dp/dx) * Fy

Note
Not called by the solver, which takes the friction velocity from the inverse find_utau_Cabot(); this forward form is the definition that inverse is tested against.
Parameters
[in]kinematic_viscosityKinematic viscosity
[in]wall_distanceDistance from wall
[in]friction_velocityFriction velocity
[in]pressure_gradient_tangentTangential pressure gradient
[in]wall_shear_stressWall shear stress
Returns
Velocity at wall_distance

Computes velocity using Cabot wall function.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/wallfunction.h.

See also
u_Cabot()

Definition at line 334 of file wallfunction.c.

337{
338 double F1 = integrate_1(kinematic_viscosity, wall_distance, friction_velocity, 0);
339 double Fy = integrate_1(kinematic_viscosity, wall_distance, friction_velocity, 1);
340
341 return wall_shear_stress * F1 + pressure_gradient_tangent * Fy;
342}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ f_Cabot()

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.

Computes: f(u_τ) = u_τ - sqrt(|τ_w(u_τ)|) This enforces consistency between u_τ and τ_w.

Parameters
[in]kinematic_viscosityKinematic viscosity
[in]velocityVelocity
[in]wall_distanceDistance from wall
[in]friction_velocity_guessGuess for u_τ
[in]pressure_gradient_tangentTangential pressure gradient
[in]pressure_gradient_normalNormal pressure gradient (currently unused)
Returns
Residual value

Residual function for Cabot wall function.

See also
f_Cabot()

Definition at line 348 of file wallfunction.c.

351{
352 (void)pressure_gradient_normal;
353 double wall_shear = taw(kinematic_viscosity, friction_velocity_guess,
354 wall_distance, velocity, pressure_gradient_tangent);
355
356 return friction_velocity_guess - sqrt(fabs(wall_shear));
357}
double taw(double kinematic_viscosity, double friction_velocity, double wall_distance, double velocity, double pressure_gradient_tangent)
Implementation of taw().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ df_Cabot()

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.

Parameters
kinematic_viscosityFluid kinematic viscosity.
velocityResolved tangential velocity at the wall-model point.
wall_distanceNormal distance from the wall.
friction_velocity_guessCurrent friction-velocity iterate.
pressure_gradient_tangentTangential pressure-gradient contribution.
pressure_gradient_normalNormal pressure-gradient contribution.
Returns
Derivative of the Cabot residual with respect to friction velocity.

Numerical derivative for Cabot wall function.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/wallfunction.h.

See also
df_Cabot()

Definition at line 365 of file wallfunction.c.

368{
369 const double perturbation = 1.e-7;
370
371 double f_plus = f_Cabot(kinematic_viscosity, velocity, wall_distance,
372 friction_velocity_guess + perturbation,
373 pressure_gradient_tangent, pressure_gradient_normal);
374
375 double f_minus = f_Cabot(kinematic_viscosity, velocity, wall_distance,
376 friction_velocity_guess - perturbation,
377 pressure_gradient_tangent, pressure_gradient_normal);
378
379 return (f_plus - f_minus) / (2.0 * perturbation);
380}
double f_Cabot(double kinematic_viscosity, double velocity, double wall_distance, double friction_velocity_guess, double pressure_gradient_tangent, double pressure_gradient_normal)
Implementation of f_Cabot().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_utau_Cabot()

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.

This non-equilibrium wall function accounts for pressure gradient effects, making it more accurate in separated or strongly accelerating/decelerating flows.

Parameters
[in]kinematic_viscosityKinematic viscosity
[in]velocityVelocity at reference point
[in]wall_distanceDistance from wall
[in]initial_guessInitial guess for u_τ
[in]pressure_gradient_tangentTangential pressure gradient
[in]pressure_gradient_normalNormal pressure gradient
[out]friction_velocityConverged friction velocity
[out]wall_shear_velocityWall shear stress for velocity
[out]wall_shear_normalWall shear stress for normal pressure gradient

Solves for friction velocity using Cabot wall function.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/wallfunction.h.

See also
find_utau_Cabot()

Definition at line 388 of file wallfunction.c.

392{
393 double current_guess = initial_guess;
394 double new_guess;
395
396 const int max_iterations = 30;
397 const double convergence_tolerance = 1.e-10;
398
399 int iteration;
400 for (iteration = 0; iteration < max_iterations; iteration++) {
401 double residual = f_Cabot(kinematic_viscosity, velocity, wall_distance,
402 current_guess, pressure_gradient_tangent,
403 pressure_gradient_normal);
404
405 double derivative = df_Cabot(kinematic_viscosity, velocity, wall_distance,
406 current_guess, pressure_gradient_tangent,
407 pressure_gradient_normal);
408
409 new_guess = fabs(current_guess - residual / derivative);
410
411 if (fabs(current_guess - new_guess) < convergence_tolerance) {
412 break;
413 }
414
415 current_guess = new_guess;
416 }
417
418 if (fabs(current_guess - new_guess) > 1.e-5 && iteration >= 29) {
419 /* Per wall cell and step, so reported only the first time on each rank. */
420 static PetscBool reported = PETSC_FALSE;
421 if (!reported) {
422 reported = PETSC_TRUE;
424 "Cabot wall-function iteration reached its limit without the requested tolerance "
425 "(reported once per rank; later occurrences are not).\n");
426 }
427 }
428
429 *friction_velocity = new_guess;
430 *wall_shear_velocity = taw(kinematic_viscosity, new_guess, wall_distance,
431 velocity, pressure_gradient_tangent);
432 *wall_shear_normal = taw(kinematic_viscosity, new_guess, wall_distance,
433 0.0, pressure_gradient_normal);
434}
@ LOG_WARNING
Non-critical issues that warrant attention.
Definition logging.h:30
double df_Cabot(double kinematic_viscosity, double velocity, double wall_distance, double friction_velocity_guess, double pressure_gradient_tangent, double pressure_gradient_normal)
Implementation of df_Cabot().
Here is the call graph for this function:
Here is the caller graph for this function:

◆ u_Werner()

double u_Werner ( double  kinematic_viscosity,
double  wall_distance,
double  friction_velocity 
)

Computes velocity using Werner-Wengle wall function.

The pointwise Werner-Wengle profile. Not called by the solver, which takes the friction velocity from its exact inverse, find_utau_Werner(), at the reference cell; this forward form is the definition that inverse is tested against. Explicit relation: u+ = y+ below the sublayer edge (viscous sublayer) u+ = A * (y+)^B above it (power law) where A = 8.3, B = 1/7, and the edge is where the two meet, A^(7/6) = 11.8102.

ADVANTAGES:

  • Explicit (no iteration required)
  • Computationally cheap
  • Reasonable accuracy for equilibrium boundary layers

LIMITATIONS:

  • Less accurate than log-law for high Reynolds numbers
  • No pressure gradient effects
Parameters
[in]kinematic_viscosityKinematic viscosity
[in]wall_distanceDistance from wall
[in]friction_velocityFriction velocity
Returns
Tangential velocity

Computes velocity using Werner-Wengle wall function.

See also
u_Werner()

Definition at line 444 of file wallfunction.c.

446{
447 /* The pointwise profile. ApplyWallFunction() takes the friction velocity from its exact
448 inverse, find_utau_Werner(), at the reference cell. */
449 double yplus = friction_velocity * wall_distance / kinematic_viscosity;
450
451 // Werner-Wengle constants
452 const double power_law_coefficient = WERNER_A;
453 const double power_law_exponent = WERNER_B;
454
455 double velocity;
456
457 if (yplus <= WERNER_SUBLAYER_YPLUS) {
458 // Viscous sublayer: u+ = y+
459 velocity = yplus * friction_velocity;
460 }
461 else {
462 // Power-law region: u+ = A * (y+)^B
463 velocity = power_law_coefficient * pow(yplus, power_law_exponent) * friction_velocity;
464 }
465
466 return velocity;
467}
#define WERNER_SUBLAYER_YPLUS
Werner-Wengle sublayer edge: where u+ = y+ meets u+ = A (y+)^B, at A^(1/(1-B)).
#define WERNER_A
Werner-Wengle power-law coefficient A and exponent B in u+ = A (y+)^B.
#define WERNER_B
Here is the caller graph for this function:

◆ taw_Werner()

double taw_Werner ( double  kinematic_viscosity,
double  velocity,
double  wall_distance 
)

Wall shear stress from the cell-integrated Werner-Wengle relation.

Note
Not wired into the solver. The profile is assumed to hold across a cell of height wall_distance and integrated, so velocity must be the AVERAGE over [0, wall_distance] - a finite-volume first-cell value with its full height. The wall function's reference is instead a point value at the second cell's centre; read as an average it over-predicts u_tau by about (1 + B)^(1/(1+B)), 12-14% on a wall-modelled channel at Re_tau ~ 1000. The solver uses the pointwise pair find_utau_Werner() / u_Werner(), which is also closed form. Kept, with its inverse u_Werner_explicit(), for a caller that does supply a cell average.

|u| <= u_m : tau_w = 2 nu |u| / y |u| > u_m : tau_w = [ (1-B)/2 A^((1+B)/(1-B)) (nu/y)^(1+B)

  • (1+B)/A (nu/y)^B |u| ]^(2/(1+B))

with A = 8.3, B = 1/7, and the switch at u_m = nu/(2y) A^(2/(1-B)). That threshold depends only on the geometry and the fluid, which is what makes the inversion explicit; a threshold written in terms of the friction velocity would reintroduce the iteration the model exists to avoid. The two branches meet exactly at u_m.

Pairs with u_Werner_explicit(), which inverts it. Do not pair it with u_Werner(), which is the pointwise profile rather than its cell integral.

Parameters
[in]kinematic_viscosityKinematic viscosity.
[in]velocityWall-parallel speed at wall_distance, sign ignored.
[in]wall_distanceNormal distance the profile is integrated over.
Returns
Wall shear stress, equal to the square of the friction velocity.

Wall shear stress from the cell-integrated Werner-Wengle relation.

Full API contract is documented with the header declaration in include/wallfunction.h.

Definition at line 476 of file wallfunction.c.

477{
479 const double A = WERNER_A;
480 const double B = WERNER_B;
481 const double speed = fabs(velocity);
482 const double nu_over_y = kinematic_viscosity / wall_distance;
483
484 /* The switch is written in terms of the geometry alone. Expressing it through the
485 friction velocity, as the iterative residual does, makes the branch depend on the
486 answer and forces a Newton solve the closed form does not need. */
487 const double transition_speed = 0.5 * nu_over_y * pow(A, 2.0 / (1.0 - B));
488
489 if (speed <= transition_speed) {
490 /* Integrating u+ = y+ across the cell leaves the factor of two that separates
491 this from the pointwise relation tau_w = nu u / y. */
493 return 2.0 * kinematic_viscosity * speed / wall_distance;
494 }
495
496 {
497 const double term1 = 0.5 * (1.0 - B) * pow(A, (1.0 + B) / (1.0 - B)) *
498 pow(nu_over_y, 1.0 + B);
499 const double term2 = (1.0 + B) / A * pow(nu_over_y, B) * speed;
500
502 return pow(term1 + term2, 2.0 / (1.0 + B));
503 }
505}
#define PROFILE_HELPER_BEGIN
Marks the beginning of a profiled helper: timed only when enabled by name.
Definition logging.h:1014
#define PROFILE_HELPER_END
Alias of PROFILE_FUNCTION_END for a function that began with PROFILE_HELPER_BEGIN.
Definition logging.h:1033
Here is the caller graph for this function:

◆ u_Werner_explicit()

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.

The exact inverse of taw_Werner(), branch for branch, so that a stress obtained from a velocity at one distance reproduces a consistent velocity at another. It is monotonically increasing in wall_distance, so a cell nearer the wall than the one the stress came from is always assigned the slower speed.

The branch is selected on the stress rather than the velocity it is about to produce, using the same threshold expressed as tau_m = (nu/y)^2 A^(2/(1-B)).

Parameters
[in]kinematic_viscosityKinematic viscosity.
[in]wall_distanceNormal distance to evaluate at.
[in]wall_shear_stressWall shear stress from taw_Werner().
Returns
Wall-parallel speed at wall_distance, non-negative.

Wall-parallel velocity at a distance, from the Werner-Wengle wall stress.

Full API contract is documented with the header declaration in include/wallfunction.h.

Definition at line 514 of file wallfunction.c.

516{
518 const double A = WERNER_A;
519 const double B = WERNER_B;
520 const double stress = fabs(wall_shear_stress);
521 const double nu_over_y = kinematic_viscosity / wall_distance;
522
523 /* The same threshold as taw_Werner(), carried over to the stress side. The two
524 branches meet here exactly, so selecting on the stress cannot land on the wrong
525 side of the velocity switch. */
526 const double transition_stress = nu_over_y * nu_over_y * pow(A, 2.0 / (1.0 - B));
527
528 if (stress <= transition_stress) {
530 return stress * wall_distance / (2.0 * kinematic_viscosity);
531 }
532
533 {
534 const double offset = 0.5 * (1.0 - B) * pow(A, (1.0 + B) / (1.0 - B)) *
535 pow(nu_over_y, 1.0 + B);
536 /* Non-negative by construction above the threshold - it is zero only in the
537 limit of the switch - so the max guards roundoff, not a modelling case. */
538 const double bracket = PetscMax(pow(stress, 0.5 * (1.0 + B)) - offset, 0.0);
539
541 return A / (1.0 + B) * pow(1.0 / nu_over_y, B) * bracket;
542 }
544}
Here is the caller graph for this function:

◆ find_utau_Werner()

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.

The closed-form inverse of the pointwise Werner-Wengle profile, branch for branch, and the solver's path. Along that profile U y / nu = (y+)^2 in the sublayer, so the branch is chosen from the data alone - sublayer while U y / nu <= (8.3^(7/6))^2, about 11.8102^2 - and each branch inverts explicitly:

sublayer : u_tau = sqrt(nu |U| / y) power law : u_tau = ( |U| / (A (y/nu)^B) )^(1/(1+B)), A = 8.3, B = 1/7

No iteration, so the residual it feeds stays smooth for a matrix-free Jacobian.

Parameters
[in]kinematic_viscosityKinematic viscosity
[in]velocityWall-parallel speed at the reference point, sign ignored
[in]wall_distanceDistance from the wall to that point
[in]initial_guessUnused; kept so existing callers need no change
Returns
Friction velocity

Friction velocity from a point velocity, inverting u_Werner() exactly.

Full API contract (arguments, ownership, side effects) is documented with the header declaration in include/wallfunction.h.

See also
find_utau_Werner()

Definition at line 552 of file wallfunction.c.

554{
555 const double A = WERNER_A;
556 const double B = WERNER_B;
557 const double speed = fabs(velocity);
558 const double y_over_nu = wall_distance / kinematic_viscosity;
559 (void)initial_guess;
560
561 /* The exact inverse of `u_Werner()`, branch for branch. Along that profile
562 U y / nu = (y+)^2 in the sublayer, so the branch it was evaluated on is decided by
563 the data alone: the sublayer holds while U y / nu <= WERNER_SUBLAYER_YPLUS^2, the
564 same switch `u_Werner()` applies to y+. Both branches then invert explicitly. */
565 if (speed * y_over_nu <= WERNER_SUBLAYER_YPLUS * WERNER_SUBLAYER_YPLUS) {
566 return sqrt(speed / y_over_nu); /* U = u_tau^2 y / nu */
567 }
568 return pow(speed / (A * pow(y_over_nu, B)), 1.0 / (1.0 + B)); /* U = A u_tau^(1+B) (y/nu)^B */
569}
Here is the caller graph for this function: