Wave Visualisation¶
Fluidmec provides reusable scientific visualisation functions for linear regular surface gravity waves.
Installation¶
The numerical data functions require only NumPy.
For plotting and animation support:
pip install "fluidmec[visualization]"
Regular-wave configuration¶
from fluidmec.visualization import RegularWave
wave = RegularWave(
wave_height=2.0,
period=8.0,
depth=20.0,
density=1025.0,
)
print(wave.wavelength)
print(wave.group_velocity)
print(wave.energy_flux)
The configuration is immutable. Dispersion and derived wave quantities are cached when first requested.
Numerical fields¶
from fluidmec.visualization import wave_field_data
data = wave_field_data(
wave,
time=2.0,
nx=241,
nz=81,
)
print(data["u"].shape)
print(data["dynamic_pressure"].max())
Field arrays have shape (nz, nx).
All dimensional numerical data use SI units.
Velocity and acceleration¶
The linear velocity components are
Local acceleration is
Nonlinear convective acceleration is excluded.
Pressure decomposition¶
Numerical pressure data are expressed in Pa. Pressure plots use kPa.
Reusable plots¶
from fluidmec.visualization import (
plot_velocity_field,
plot_pressure_field,
)
fig, ax = plot_velocity_field(wave)
fig.savefig(
"velocity_field.png",
dpi=300,
bbox_inches="tight",
)
fig, ax = plot_pressure_field(
wave,
component="dynamic",
)
Plotting functions return figure and axes objects. They do not automatically display, save or close figures.
Existing Matplotlib axes¶
import matplotlib.pyplot as plt
from fluidmec.visualization import plot_velocity_field
fig, ax = plt.subplots()
plot_velocity_field(wave, ax=ax)
Particle trajectories¶
import numpy as np
from fluidmec.visualization import particle_orbit_data
time = np.linspace(0, wave.period, 200)
data = particle_orbit_data(
wave,
x0=10.0,
z0=-5.0,
time=time,
)
Particle coordinates represent first-order closed orbits. Stokes drift is not included.
Particle animation¶
from fluidmec.visualization import animate_particle_orbits
fig, animation = animate_particle_orbits(
wave,
frames=120,
fps=20,
)
animation.save(
"particle_motion.gif",
writer="pillow",
fps=20,
dpi=120,
)
The caller must retain the animation object.
Directional wave surfaces¶
from fluidmec.visualization import plot_directional_surface
fig, ax = plot_directional_surface(
wave,
direction_deg=35.0,
)
Direction is measured counterclockwise from the positive x-axis.
Wave groups and energy transport¶
The regular-wave reference energy is
The energy flux per unit crest width is
The wave group visualisation uses two nearby frequencies and the finite-depth dispersion relation.
Applicability diagrams¶
The theory-selection map uses the preliminary screening rules implemented in Fluidmec's wave applicability module.
The boundaries are heuristic and do not guarantee the validity of a particular wave theory.
Scientific limitations¶
- First-order linear regular surface gravity waves.
- Incompressible, inviscid and irrotational flow.
- Constant water depth and horizontal seabed.
- No background currents.
- No nonlinear convective acceleration.
- No Stokes drift.
- No breaking-wave or turbulence simulation.
- Pressure and velocity fields use the mean water column.
- Three-dimensional surfaces represent directional plane waves, not full three-dimensional CFD.
- Energy values refer to the reference regular wave.
API reference¶
Numerical data for regular-wave visualisation.
All dimensional quantities use SI units.
The calculations represent first-order, incompressible, inviscid, irrotational surface gravity waves over a horizontal impermeable seabed.
Coordinates use z = 0 at the still-water level and z = -depth at the seabed.
The numerical functions do not require Matplotlib.
RegularWave
dataclass
¶
Configuration for a linear regular gravity wave.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave_height
|
float
|
Non-negative crest-to-trough wave height [m]. |
required |
period
|
float
|
Positive wave period [s]. |
required |
depth
|
float
|
Positive still-water depth [m]. |
required |
density
|
float
|
Positive fluid density [kg/m^3]. Defaults to 1025 kg/m^3. |
1025.0
|
gravity
|
float
|
Positive gravitational acceleration [m/s^2]. |
ENGINEERING_GRAVITY
|
phase_offset
|
float
|
Initial phase offset [rad]. |
0.0
|
Notes
Wave number is obtained from linear dispersion. The configuration does not enforce small-amplitude applicability or guarantee that waves are unbroken.
Use assess_wave_applicability for preliminary physical applicability screening.
Source code in src/fluidmec/visualization/wave_data.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
as_float_array
¶
as_float_array(value: ArrayLike, name: str) -> np.ndarray
Convert input to a finite floating-point array.
Source code in src/fluidmec/core/_validation.py
13 14 15 16 17 18 19 20 21 22 23 24 | |
validate_non_negative
¶
validate_non_negative(value: ArrayLike, name: str) -> np.ndarray
Validate non-negative numerical inputs.
Source code in src/fluidmec/core/_validation.py
41 42 43 44 45 46 47 48 49 50 51 52 | |
validate_positive
¶
validate_positive(value: ArrayLike, name: str) -> np.ndarray
Validate strictly positive numerical inputs.
Source code in src/fluidmec/core/_validation.py
27 28 29 30 31 32 33 34 35 36 37 38 | |
cosh_depth_factor
¶
cosh_depth_factor(wave_number: ArrayLike, z: ArrayLike, depth: ArrayLike) -> float | np.ndarray
Calculate the stable hyperbolic cosine depth factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave_number
|
array_like
|
Positive wave number in rad/m. |
required |
z
|
array_like
|
Vertical coordinate in metres, satisfying -h <= z <= 0. |
required |
depth
|
array_like
|
Positive still-water depth in metres. |
required |
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Dimensionless cosine depth attenuation factor. |
Notes
Governing expression:
C = cosh(k*(z+h))/cosh(k*h)
Stable exponential formulation:
C = exp(k*z)*(1 + exp(-2*k*(z+h)))
/ (1 + exp(-2*k*h))
All exponential arguments are non-positive within the mean water column.
At z = 0, C = 1.
Source code in src/fluidmec/waves/airy.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
group_velocity_factor
¶
group_velocity_factor(dimensionless_depth: ArrayLike) -> float | np.ndarray
Calculate the dimensionless group velocity factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimensionless_depth
|
array_like
|
Dimensionless water depth kh. Non-negative. |
required |
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Group velocity factor n = cg/cp. Values lie between 0.5 and 1. |
Notes
Equation:
n = 0.5*(1 + 2*kh/sinh(2*kh))
The shallow-water limit at kh = 0 is defined as n = 1.
An exponential reformulation avoids overflow in sinh. NumPy expm1 reduces cancellation for small arguments.
For kh >= 20, the correction to 0.5 is below ordinary double-precision floating-point resolution.
Examples:
>>> group_velocity_factor(0.0)
1.0
>>> group_velocity_factor(100.0)
0.5
Source code in src/fluidmec/waves/velocity.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
sinh_depth_factor
¶
sinh_depth_factor(wave_number: ArrayLike, z: ArrayLike, depth: ArrayLike) -> float | np.ndarray
Calculate the stable hyperbolic sine depth factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave_number
|
array_like
|
Positive wave number in rad/m. |
required |
z
|
array_like
|
Vertical coordinate in metres, satisfying -h <= z <= 0. |
required |
depth
|
array_like
|
Positive still-water depth in metres. |
required |
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Dimensionless sine depth attenuation factor. |
Notes
Governing expression:
S = sinh(k*(z+h))/cosh(k*h)
Stable exponential formulation:
S = exp(k*z)*(1 - exp(-2*k*(z+h)))
/ (1 + exp(-2*k*h))
NumPy expm1 is used to reduce cancellation close to the seabed.
At z = -h, S = 0. At z = 0, S = tanh(k*h).
Source code in src/fluidmec/waves/airy.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
solve_wave_number
¶
solve_wave_number(period: ArrayLike, depth: ArrayLike, gravity: ArrayLike = ENGINEERING_GRAVITY, *, method: str = 'newton', tolerance: float = 1e-10, max_iterations: int = 100) -> float | np.ndarray
Solve the linear wave dispersion relation for k.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
period
|
array_like
|
Wave period T, in seconds. Positive. |
required |
depth
|
array_like
|
Still-water depth h, in metres. Positive. |
required |
gravity
|
array_like
|
Gravitational acceleration g, in m/s^2. |
ENGINEERING_GRAVITY
|
method
|
(newton, bisection)
|
Safeguarded Newton-Raphson or bisection. |
"newton"
|
tolerance
|
float
|
Relative dimensionless residual tolerance. Must be between zero and one, exclusive. |
1e-10
|
max_iterations
|
int
|
Maximum number of solver evaluations. |
100
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Positive wave-number magnitude k, in rad/m. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If physical inputs or solver options are invalid. |
RuntimeError
|
If the solver does not converge. |
Notes
Solves:
x*tanh(x) = mu
where x = kh and mu = omega**2h/g.
Convergence criterion:
abs(x*tanh(x) - mu) / mu <= tolerance
Newton steps outside the root bracket are replaced by bisection steps.
Supports NumPy broadcasting. Every array element must converge before the function returns.
The result is based on linear gravity wave theory, without current or surface tension.
Source code in src/fluidmec/waves/dispersion.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | |
_scalar
¶
_scalar(value, name, *, positive=False, non_negative=False)
Validate a finite scalar configuration value.
Source code in src/fluidmec/visualization/wave_data.py
35 36 37 38 39 40 41 42 43 44 45 46 47 | |
_count
¶
_count(value, name, minimum=2)
Validate an integer grid or sample count.
Source code in src/fluidmec/visualization/wave_data.py
50 51 52 53 54 55 56 57 58 59 60 61 | |
_finite_fields
¶
_finite_fields(data)
Reject nonfinite numerical outputs.
Source code in src/fluidmec/visualization/wave_data.py
64 65 66 67 68 69 70 71 72 | |
wave_field_data
¶
wave_field_data(wave: RegularWave, time: float = 0.0, *, wavelengths: float = 2.0, nx: int = 241, nz: int = 81) -> dict
Evaluate linear wave fields on a rectangular grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Validated regular-wave configuration. |
required |
time
|
float
|
Evaluation time [s]. |
0.0
|
wavelengths
|
float
|
Positive horizontal domain length in wavelengths. |
2.0
|
nx
|
int
|
Horizontal and vertical grid sample counts. |
241
|
nz
|
int
|
Horizontal and vertical grid sample counts. |
241
|
Returns:
| Type | Description |
|---|---|
dict
|
x, z : one-dimensional coordinates [m]. X, Z : two-dimensional mesh coordinates [m]. eta : surface elevation along x [m]. u, w : velocity components [m/s]. speed : velocity magnitude [m/s]. ax, az : local acceleration components [m/s^2]. acceleration : acceleration magnitude [m/s^2]. dynamic_pressure : pressure perturbation [Pa]. hydrostatic_pressure : hydrostatic gauge pressure [Pa]. gauge_pressure : total linearised gauge pressure [Pa]. |
Notes
Field arrays have shape (nz, nx). The domain is the mean water column, not the instantaneous moving free-surface domain.
Acceleration is first-order local acceleration; nonlinear convective acceleration is excluded.
Source code in src/fluidmec/visualization/wave_data.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
particle_orbit_data
¶
particle_orbit_data(wave: RegularWave, x0, z0, time) -> dict
Calculate first-order particle orbital coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Regular-wave configuration. |
required |
x0
|
array_like
|
Mean horizontal particle positions [m]. |
required |
z0
|
array_like
|
Mean vertical positions [m], within [-depth, 0]. |
required |
time
|
array_like
|
Evaluation times [s]. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
X, Z : instantaneous particle positions [m]. xi, zeta : first-order displacements [m]. horizontal_radius, vertical_radius : orbital semi-axis lengths [m]. |
Notes
Inputs follow standard NumPy broadcasting rules. These trajectories are first-order closed orbits. Stokes drift and nonlinear particle advection are not represented.
Source code in src/fluidmec/visualization/wave_data.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
directional_surface_data
¶
directional_surface_data(wave: RegularWave, time: float = 0.0, *, direction_deg: float = 0.0, wavelengths: float = 2.0, nx: int = 121, ny: int = 121) -> dict
Calculate a directional linear plane-wave surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Regular-wave configuration. |
required |
time
|
float
|
Evaluation time [s]. |
0.0
|
direction_deg
|
float
|
Propagation direction measured counterclockwise from the positive x-axis [degrees]. |
0.0
|
wavelengths
|
float
|
Side length of the square domain in wavelengths. |
2.0
|
nx
|
int
|
Grid sample counts. |
121
|
ny
|
int
|
Grid sample counts. |
121
|
Returns:
| Type | Description |
|---|---|
dict
|
X, Y : horizontal mesh coordinates [m]. eta : surface elevation [m]. kx, ky : directional wave-number components [rad/m]. |
Notes
This is a directional plane wave, not a nonlinear three-dimensional free-surface flow solution.
Source code in src/fluidmec/visualization/wave_data.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
wave_packet_data
¶
wave_packet_data(wave: RegularWave, time: float = 0.0, *, frequency_fraction: float = 0.05, wavelengths: float = 20.0, nx: int = 2001) -> dict
Calculate a two-frequency dispersive wave group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Reference wave configuration. |
required |
time
|
float
|
Evaluation time [s]. |
0.0
|
frequency_fraction
|
float
|
Fractional angular-frequency half-separation. Must lie strictly between zero and one. |
0.05
|
wavelengths
|
float
|
Domain length in reference wavelengths. |
20.0
|
nx
|
int
|
Horizontal sample count. |
2001
|
Returns:
| Type | Description |
|---|---|
dict
|
x : horizontal coordinate [m]. eta : superposed wave elevation [m]. envelope : absolute modulation envelope [m]. envelope_velocity : finite-difference group speed [m/s]. phase_velocity : carrier phase speed [m/s]. group_velocity : reference analytical group speed [m/s]. energy_density : reference wave energy [J/m^2]. energy_flux : reference wave energy flux [W/m]. |
Notes
Each component has half the reference amplitude. The maximum combined envelope equals the reference amplitude.
The reference energy and flux are for the original regular wave, not the mean energy of the two-wave superposition.
Source code in src/fluidmec/visualization/wave_data.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |
Reusable scientific plots for linear regular waves.
Plotting functions return Matplotlib figure and axes objects. They do not call show(), savefig() or close().
The user owns the returned figure and its lifecycle.
RegularWave
dataclass
¶
Configuration for a linear regular gravity wave.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave_height
|
float
|
Non-negative crest-to-trough wave height [m]. |
required |
period
|
float
|
Positive wave period [s]. |
required |
depth
|
float
|
Positive still-water depth [m]. |
required |
density
|
float
|
Positive fluid density [kg/m^3]. Defaults to 1025 kg/m^3. |
1025.0
|
gravity
|
float
|
Positive gravitational acceleration [m/s^2]. |
ENGINEERING_GRAVITY
|
phase_offset
|
float
|
Initial phase offset [rad]. |
0.0
|
Notes
Wave number is obtained from linear dispersion. The configuration does not enforce small-amplitude applicability or guarantee that waves are unbroken.
Use assess_wave_applicability for preliminary physical applicability screening.
Source code in src/fluidmec/visualization/wave_data.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
breaking_utilisation
¶
breaking_utilisation(wave_height: ArrayLike, wavelength: ArrayLike, depth: ArrayLike, *, coefficient: float = MICHE_COEFFICIENT, breaker_index: float = DEFAULT_BREAKER_INDEX) -> ScalarOrArray
Calculate utilisation of the combined breaking limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave_height
|
array_like
|
Non-negative regular wave height H [m]. |
required |
wavelength
|
array_like
|
Positive wavelength L [m]. |
required |
depth
|
array_like
|
Positive still-water depth h [m]. |
required |
coefficient
|
float
|
Positive Miche coefficient [-]. |
MICHE_COEFFICIENT
|
breaker_index
|
float
|
Positive empirical breaker index [-]. |
DEFAULT_BREAKER_INDEX
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Ratio H/min(H_Miche, H_depth), dimensionless. |
Notes
This is equivalent to the maximum utilisation of the two individual adopted criteria.
Source code in src/fluidmec/waves/applicability.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
miche_breaking_steepness
¶
miche_breaking_steepness(wavelength: ArrayLike, depth: ArrayLike, coefficient: float = MICHE_COEFFICIENT) -> ScalarOrArray
Calculate Miche's approximate limiting steepness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wavelength
|
array_like
|
Positive wavelength L [m]. |
required |
depth
|
array_like
|
Positive still-water depth h [m]. |
required |
coefficient
|
float
|
Positive Miche coefficient, default 0.142. |
MICHE_COEFFICIENT
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Limiting dimensionless wave steepness Hb/L. |
Notes
Hb/L = coefficienttanh(2pi*h/L).
The criterion approximates a limiting regular-wave steepness and is not a dynamic breaking model.
Source code in src/fluidmec/waves/applicability.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
recommend_wave_theory
¶
recommend_wave_theory(wave_height: ArrayLike, wavelength: ArrayLike, depth: ArrayLike, *, coefficient: float = MICHE_COEFFICIENT, breaker_index: float = DEFAULT_BREAKER_INDEX, warning_ratio: float = DEFAULT_WARNING_RATIO, linear_ka_limit: float = 0.05, linear_height_ratio_limit: float = 0.1, linear_ursell_limit: float = 1.0, cnoidal_ursell_limit: float = 26.0, cnoidal_depth_limit: float = 0.1, steep_ka_limit: float = 0.3) -> TextOrArray
Recommend candidate wave theories for screening.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave_height
|
array_like
|
Non-negative regular wave height H [m]. |
required |
wavelength
|
array_like
|
Positive wavelength L [m]. |
required |
depth
|
array_like
|
Positive still-water depth h [m]. |
required |
coefficient
|
float
|
Positive Miche coefficient [-]. |
MICHE_COEFFICIENT
|
breaker_index
|
float
|
Positive empirical breaker index [-]. |
DEFAULT_BREAKER_INDEX
|
warning_ratio
|
float
|
Breaking utilisation warning threshold (0, 1). |
DEFAULT_WARNING_RATIO
|
linear_ka_limit
|
float
|
Maximum dimensionless amplitude for the adopted linear-wave screening rule. |
0.05
|
linear_height_ratio_limit
|
float
|
Maximum H/h for the linear screening rule. |
0.1
|
linear_ursell_limit
|
float
|
Maximum Ursell number for the linear rule outside the deep-water regime. |
1.0
|
cnoidal_ursell_limit
|
float
|
Minimum Ursell number for the cnoidal candidate rule. |
26.0
|
cnoidal_depth_limit
|
float
|
Maximum relative depth h/L for the cnoidal candidate rule. |
0.1
|
steep_ka_limit
|
float
|
Dimensionless amplitude above which a higher-order numerical theory is suggested. |
0.3
|
Returns:
| Type | Description |
|---|---|
str or ndarray
|
Candidate theory label. |
Notes
The decision rules are configurable heuristics. They are not universal theory-validity boundaries.
The Ursell number is primarily relevant to long waves. Its linear screening condition is therefore not imposed in the deep-water regime.
A recommendation does not verify a particular solver, accuracy tolerance or engineering design.
Source code in src/fluidmec/waves/applicability.py
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 | |
get_pyplot
¶
get_pyplot()
Load Matplotlib only when a plotting function is called.
Returns:
| Type | Description |
|---|---|
module
|
Matplotlib pyplot module. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If Matplotlib is unavailable. |
Notes
Fluidmec does not change the user's Matplotlib backend. Headless applications should select Agg before plotting.
Source code in src/fluidmec/visualization/_backend.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
directional_surface_data
¶
directional_surface_data(wave: RegularWave, time: float = 0.0, *, direction_deg: float = 0.0, wavelengths: float = 2.0, nx: int = 121, ny: int = 121) -> dict
Calculate a directional linear plane-wave surface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Regular-wave configuration. |
required |
time
|
float
|
Evaluation time [s]. |
0.0
|
direction_deg
|
float
|
Propagation direction measured counterclockwise from the positive x-axis [degrees]. |
0.0
|
wavelengths
|
float
|
Side length of the square domain in wavelengths. |
2.0
|
nx
|
int
|
Grid sample counts. |
121
|
ny
|
int
|
Grid sample counts. |
121
|
Returns:
| Type | Description |
|---|---|
dict
|
X, Y : horizontal mesh coordinates [m]. eta : surface elevation [m]. kx, ky : directional wave-number components [rad/m]. |
Notes
This is a directional plane wave, not a nonlinear three-dimensional free-surface flow solution.
Source code in src/fluidmec/visualization/wave_data.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 | |
particle_orbit_data
¶
particle_orbit_data(wave: RegularWave, x0, z0, time) -> dict
Calculate first-order particle orbital coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Regular-wave configuration. |
required |
x0
|
array_like
|
Mean horizontal particle positions [m]. |
required |
z0
|
array_like
|
Mean vertical positions [m], within [-depth, 0]. |
required |
time
|
array_like
|
Evaluation times [s]. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
X, Z : instantaneous particle positions [m]. xi, zeta : first-order displacements [m]. horizontal_radius, vertical_radius : orbital semi-axis lengths [m]. |
Notes
Inputs follow standard NumPy broadcasting rules. These trajectories are first-order closed orbits. Stokes drift and nonlinear particle advection are not represented.
Source code in src/fluidmec/visualization/wave_data.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
wave_field_data
¶
wave_field_data(wave: RegularWave, time: float = 0.0, *, wavelengths: float = 2.0, nx: int = 241, nz: int = 81) -> dict
Evaluate linear wave fields on a rectangular grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Validated regular-wave configuration. |
required |
time
|
float
|
Evaluation time [s]. |
0.0
|
wavelengths
|
float
|
Positive horizontal domain length in wavelengths. |
2.0
|
nx
|
int
|
Horizontal and vertical grid sample counts. |
241
|
nz
|
int
|
Horizontal and vertical grid sample counts. |
241
|
Returns:
| Type | Description |
|---|---|
dict
|
x, z : one-dimensional coordinates [m]. X, Z : two-dimensional mesh coordinates [m]. eta : surface elevation along x [m]. u, w : velocity components [m/s]. speed : velocity magnitude [m/s]. ax, az : local acceleration components [m/s^2]. acceleration : acceleration magnitude [m/s^2]. dynamic_pressure : pressure perturbation [Pa]. hydrostatic_pressure : hydrostatic gauge pressure [Pa]. gauge_pressure : total linearised gauge pressure [Pa]. |
Notes
Field arrays have shape (nz, nx). The domain is the mean water column, not the instantaneous moving free-surface domain.
Acceleration is first-order local acceleration; nonlinear convective acceleration is excluded.
Source code in src/fluidmec/visualization/wave_data.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
wave_packet_data
¶
wave_packet_data(wave: RegularWave, time: float = 0.0, *, frequency_fraction: float = 0.05, wavelengths: float = 20.0, nx: int = 2001) -> dict
Calculate a two-frequency dispersive wave group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Reference wave configuration. |
required |
time
|
float
|
Evaluation time [s]. |
0.0
|
frequency_fraction
|
float
|
Fractional angular-frequency half-separation. Must lie strictly between zero and one. |
0.05
|
wavelengths
|
float
|
Domain length in reference wavelengths. |
20.0
|
nx
|
int
|
Horizontal sample count. |
2001
|
Returns:
| Type | Description |
|---|---|
dict
|
x : horizontal coordinate [m]. eta : superposed wave elevation [m]. envelope : absolute modulation envelope [m]. envelope_velocity : finite-difference group speed [m/s]. phase_velocity : carrier phase speed [m/s]. group_velocity : reference analytical group speed [m/s]. energy_density : reference wave energy [J/m^2]. energy_flux : reference wave energy flux [W/m]. |
Notes
Each component has half the reference amplitude. The maximum combined envelope equals the reference amplitude.
The reference energy and flux are for the original regular wave, not the mean energy of the two-wave superposition.
Source code in src/fluidmec/visualization/wave_data.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 | |
_axes
¶
_axes(ax=None, figsize=(12, 6))
Create axes or reuse user-supplied axes.
Source code in src/fluidmec/visualization/wave_plots.py
33 34 35 36 37 38 39 40 41 42 43 | |
_style
¶
_style(ax, title, xlabel, ylabel)
Apply consistent scientific axis labels.
Source code in src/fluidmec/visualization/wave_plots.py
46 47 48 49 50 51 52 53 54 55 | |
_wave_boundaries
¶
_wave_boundaries(ax, wave, data)
Draw reference surface, SWL and seabed.
Source code in src/fluidmec/visualization/wave_plots.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
_levels
¶
_levels(values, *, signed=False)
Generate nondegenerate contour levels.
Source code in src/fluidmec/visualization/wave_plots.py
92 93 94 95 96 97 98 99 100 101 102 | |
plot_surface_elevation
¶
plot_surface_elevation(wave: RegularWave, time: float = 0.0, *, ax=None, wavelengths: float = 2.0)
Plot linear free-surface elevation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Regular-wave configuration. |
required |
time
|
float
|
Evaluation time [s]. |
0.0
|
ax
|
Axes
|
Existing axes. |
None
|
wavelengths
|
float
|
Horizontal domain length in wavelengths. |
2.0
|
Returns:
| Type | Description |
|---|---|
(figure, axes)
|
Matplotlib figure and axes. |
Source code in src/fluidmec/visualization/wave_plots.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
_vector_field
¶
_vector_field(wave, time, ax, wavelengths, *, acceleration=False)
Render a velocity or local acceleration field.
Source code in src/fluidmec/visualization/wave_plots.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
plot_velocity_field
¶
plot_velocity_field(wave: RegularWave, time: float = 0.0, *, ax=None, wavelengths: float = 2.0)
Plot first-order velocity contours and vectors.
Velocity magnitude is expressed in m/s. Arrow directions represent local velocity vectors. Arrow lengths are scaled for visual readability.
Returns a Matplotlib figure and axes.
Source code in src/fluidmec/visualization/wave_plots.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
plot_acceleration_field
¶
plot_acceleration_field(wave: RegularWave, time: float = 0.0, *, ax=None, wavelengths: float = 2.0)
Plot first-order local acceleration vectors.
Magnitude is expressed in m/s^2. Nonlinear convective acceleration is excluded.
Returns a Matplotlib figure and axes.
Source code in src/fluidmec/visualization/wave_plots.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
plot_pressure_field
¶
plot_pressure_field(wave: RegularWave, time: float = 0.0, *, component: str = 'dynamic', ax=None, wavelengths: float = 2.0)
Plot wave pressure contours in kPa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Regular-wave configuration. |
required |
time
|
float
|
Evaluation time [s]. |
0.0
|
component
|
(dynamic, hydrostatic, gauge)
|
Pressure component to display. |
"dynamic"
|
ax
|
Axes
|
Existing axes. |
None
|
wavelengths
|
float
|
Horizontal domain length in wavelengths. |
2.0
|
Returns:
| Type | Description |
|---|---|
(figure, axes)
|
Matplotlib figure and axes. |
Notes
Gauge pressure excludes atmospheric pressure. Dynamic pressure is a signed perturbation. Calculations use the mean water column.
Source code in src/fluidmec/visualization/wave_plots.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
plot_particle_orbits
¶
plot_particle_orbits(wave: RegularWave, *, ax=None, samples: int = 241)
Plot first-order particle orbital trajectories.
Trajectories are evaluated over one wave period. Mean particle locations span the water column.
Returns a Matplotlib figure and axes.
Notes
Equal axis scaling preserves orbital geometry. No second-order Stokes drift is included.
Source code in src/fluidmec/visualization/wave_plots.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 | |
plot_directional_surface
¶
plot_directional_surface(wave: RegularWave, time: float = 0.0, *, direction_deg: float = 30.0, wavelengths: float = 2.0, ax=None)
Plot a three-dimensional directional wave surface.
Direction is measured counterclockwise from +x in degrees. Surface elevation is expressed in metres.
Returns a Matplotlib figure and 3D axes.
Notes
Vertical visual exaggeration may result from the figure aspect ratio. Coordinate labels retain SI units.
Source code in src/fluidmec/visualization/wave_plots.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | |
plot_energy_transport
¶
plot_energy_transport(wave: RegularWave, time: float = 0.0, *, frequency_fraction: float = 0.05, ax=None)
Plot a two-frequency wave group and its envelope.
Displays carrier phase velocity and finite-difference envelope velocity, together with reference regular-wave energy density and flux.
Returns a Matplotlib figure and axes.
Source code in src/fluidmec/visualization/wave_plots.py
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 | |
plot_wave_applicability
¶
plot_wave_applicability(wave: RegularWave | None = None, *, ax=None, resolution: int = 300)
Plot heuristic wave theory applicability regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave or None
|
Optional wave configuration to mark on the diagram. |
None
|
ax
|
Axes
|
Existing axes. |
None
|
resolution
|
int
|
Sample count along each dimension. |
300
|
Returns:
| Type | Description |
|---|---|
(figure, axes)
|
Matplotlib figure and axes. |
Notes
Regions follow Fluidmec's configurable screening conventions, not experimentally validated universal theory boundaries.
Source code in src/fluidmec/visualization/wave_plots.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 | |
Animations of first-order regular-wave particle motion.
RegularWave
dataclass
¶
Configuration for a linear regular gravity wave.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave_height
|
float
|
Non-negative crest-to-trough wave height [m]. |
required |
period
|
float
|
Positive wave period [s]. |
required |
depth
|
float
|
Positive still-water depth [m]. |
required |
density
|
float
|
Positive fluid density [kg/m^3]. Defaults to 1025 kg/m^3. |
1025.0
|
gravity
|
float
|
Positive gravitational acceleration [m/s^2]. |
ENGINEERING_GRAVITY
|
phase_offset
|
float
|
Initial phase offset [rad]. |
0.0
|
Notes
Wave number is obtained from linear dispersion. The configuration does not enforce small-amplitude applicability or guarantee that waves are unbroken.
Use assess_wave_applicability for preliminary physical applicability screening.
Source code in src/fluidmec/visualization/wave_data.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
get_animation
¶
get_animation()
Load the optional Matplotlib animation module.
Source code in src/fluidmec/visualization/_backend.py
34 35 36 37 38 39 40 41 42 43 44 | |
get_pyplot
¶
get_pyplot()
Load Matplotlib only when a plotting function is called.
Returns:
| Type | Description |
|---|---|
module
|
Matplotlib pyplot module. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If Matplotlib is unavailable. |
Notes
Fluidmec does not change the user's Matplotlib backend. Headless applications should select Agg before plotting.
Source code in src/fluidmec/visualization/_backend.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
_count
¶
_count(value, name, minimum=2)
Validate an integer grid or sample count.
Source code in src/fluidmec/visualization/wave_data.py
50 51 52 53 54 55 56 57 58 59 60 61 | |
particle_orbit_data
¶
particle_orbit_data(wave: RegularWave, x0, z0, time) -> dict
Calculate first-order particle orbital coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Regular-wave configuration. |
required |
x0
|
array_like
|
Mean horizontal particle positions [m]. |
required |
z0
|
array_like
|
Mean vertical positions [m], within [-depth, 0]. |
required |
time
|
array_like
|
Evaluation times [s]. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
X, Z : instantaneous particle positions [m]. xi, zeta : first-order displacements [m]. horizontal_radius, vertical_radius : orbital semi-axis lengths [m]. |
Notes
Inputs follow standard NumPy broadcasting rules. These trajectories are first-order closed orbits. Stokes drift and nonlinear particle advection are not represented.
Source code in src/fluidmec/visualization/wave_data.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
animate_particle_orbits
¶
animate_particle_orbits(wave: RegularWave, *, frames: int = 120, fps: int = 20, periods: int = 1)
Animate first-order water-particle trajectories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wave
|
RegularWave
|
Regular-wave configuration. |
required |
frames
|
int
|
Number of animation frames, at least two. |
120
|
fps
|
int
|
Positive playback frame rate. |
20
|
periods
|
int
|
Number of physical wave periods represented. |
1
|
Returns:
| Name | Type | Description |
|---|---|---|
figure |
Figure
|
Animation figure. |
animation |
FuncAnimation
|
Animation object retained by the caller. |
Notes
Playback duration is frames/fps seconds, which may differ from the represented physical time.
Particle paths use first-order closed trajectories. Stokes drift, breaking, turbulence and nonlinear free-surface motion are not represented.
The function does not save or display the animation.
Source code in src/fluidmec/visualization/wave_animation.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
Headless rendering¶
Fluidmec supports non-interactive scientific rendering using Matplotlib's Agg backend.
Linux, Docker and cloud servers¶
export MPLBACKEND=Agg
Windows PowerShell¶
$env:MPLBACKEND = "Agg"
Python configuration¶
import matplotlib
matplotlib.use("Agg")
from fluidmec.visualization import (
RegularWave,
plot_velocity_field,
)
wave = RegularWave(2.0, 8.0, 20.0)
fig, ax = plot_velocity_field(wave)
fig.savefig("velocity_field.png", dpi=300)
The backend should be selected before importing pyplot.
Headless rendering supports PNG, PDF, SVG and GIF generation without a graphical display server.
Fluidmec does not automatically override the user's Matplotlib backend.