A real-time FMX demo application that solves two-dimensional incompressible fluid flow on the sphere — the barotropic vorticity equation — by the spherical-harmonic spectral transform method, using the LUX.SphericalHarmonics library, and renders the vorticity field as a colored relief on a 3D globe.
- LUX :The LUXOPHIA standard library providing basic mathematical types such as vectors, matrices, and complex numbers.
- LUX.FMX.Graphics.D3 :A 3D graphics helper library built on the FireMonkey framework.
-
LUX.Sphere :A spherical geometry library for shapes, curves, and barycenter operations on the spheres
$S^2$ and$S^3$ . - LUX.SphericalHarmonics :A library for spherical harmonics and the associated Legendre functions.
-
Spectral transform method: the vorticity field is expanded in spherical harmonics with triangular truncation
$T_N$ ($N$ = 21 / 42 / 85 / 170, selectable at run time). The inverse Laplacian is exact in spectral space. -
Alias-free transform grid: the quadratic nonlinear term is evaluated on a longitude–Gauss-latitude grid with
$I \ge 3N+1$ and$J \ge (3N+1)/2$ , so no aliasing error enters the retained modes [3]. - Diffusion-free: the model contains no viscous or filter term (an optional hyperviscosity filter exists, default off). The flux form of the nonlinear term, evaluated by integration by parts, conserves both energy and enstrophy — numerical diffusion is zero, leaving only the truncation error of the RK4 time integration.
-
Rendering: vorticity is displayed as a radial relief of the sphere's vertices (ridge = positive, trough = negative), colored blue (trough) → white (zero) → red (ridge). The display mesh is always 256 × 128, resynthesized spectrally from the simulation coefficients (band-limited interpolation, exact), so even low resolutions look smooth. Surface normals are computed from the analytic derivatives
$\partial\zeta/\partial\theta$ ,$\partial\zeta/\partial\lambda$ of the spherical-harmonic expansion; the relief uses a$\tanh$ mapping (continuously differentiable). The camera orbits while the lights stay fixed in world space. - The info panel continuously shows the relative drift of energy and enstrophy, so the conservation (diffusion-free) property can be verified in real time.
- A companion application that visualizes the individual spherical-harmonic basis functions is available as SphericalHarmonics [9].
| Item | Result |
|---|---|
| Transform round-trip error (T170) | ~1e-13 |
| Rossby-wave phase speed vs. analytic solution | agrees to machine precision |
| Energy / enstrophy conservation (T85, 50 steps) | ~1e-12 |
| Speed (one RK4 step, Ryzen-class CPU) | T85 ≈ 6.5 ms / T170 ≈ 21 ms |
The model describes a non-divergent two-dimensional fluid covering the whole sphere (no land), with the vorticity
where
The vorticity is expanded in spherical harmonics [4] with triangular truncation
where
evaluated by the four-term recurrence engine TNALFsTerm4 of the LUX.SphericalHarmonics library. Since
The spherical harmonics are eigenfunctions of the Laplacian on
so the Laplacian is diagonal in spectral space and the inversion
as implemented in TSHFluid.Tendency.
One evaluation of the right-hand side of
-
Synthesis (spectral → grid):
$\zeta$ and the pseudo-velocities
are synthesized on the transform grid (Synthesize, SynthesizeUV) — equally spaced longitudes with FFT, Gauss–Legendre latitudes
-
Fluxes on the grid:
$A = U(\zeta+f)$ ,$B = V(\zeta+f)$ ; the maximum wind speed is recorded for the CFL condition. -
Analysis of the flux divergence (grid → spectral,
AnalyzeFluxDiv): using integration by parts against$\tilde{P}_n^m$ , the divergence
is obtained exactly in spectral space; the latitude integrals use Gauss–Legendre quadrature [6], which is exact for band-limited integrands.
Because the nonlinearity is quadratic, choosing the grid size
(the 3/2 de-aliasing rule [3], enforced by TSHTransform.FitGrid) removes all aliasing errors from the retained modes; combined with the flux form
Time stepping uses the classical fourth-order Runge–Kutta scheme [7] (TSHFluid.Step):
with the step size limited by the CFL-type condition (SuggestDt)
The conserved diagnostics, evaluated directly from the spectral coefficients, are the kinetic energy and the enstrophy:
The optional hyperviscosity filter (default off = fully diffusion-free) relaxes the highest wavenumbers after each step:
The initial condition (InitRandom) puts Gaussian random vorticity into the large scales
The display synthesizer (TSHTransform with Loose mode, requiring only the sampling condition
and the exact surface normal, using the analytic derivatives SynthesizeGrad), is
as implemented in TFluidSphere3D.MakeGeometry.
[Ownership] main form → scene, solver, display synthesizer
・TFormMain (Main.pas)
┣・TWorld3D ・・・ 3D scene (LUX.FMX.Graphics.D3)
┃ ┣・TCamera3D
┃ ┗・TLight3D ×3
┣・TFluidSphere3D ・・・ relief mesh (FluidSphere.pas)
┃ ┗・SetGrid / SetField ・・・ vertices, analytic normals, palette
┣・TSHFluid ・・・ BVE solver (LUX.SH.Fluid)
┃ ┣・Tendency / Step(RK4) / Energy / Enstrophy / SuggestDt
┃ ┗・TSHTransform ・・・ SH transform (LUX.SH.Transform)
┃ ┣・Synthesize / SynthesizeUV / SynthesizeGrad
┃ ┣・Analyze / AnalyzeFluxDiv ・・・ (Gauss-Legendre grid + FFT, TTask)
┃ ┗・TNALFsTerm4 ・・・ normalized ALFs (LUX.NALFs.Term4)
┗・TSHTransform (Loose) ・・・ display synthesizer, 256×128
[Inheritance] relief mesh shape
・TF3DShaper ・・・ (LUX.FMX.Graphics.D3)
┗・TFluidSphere3D ・・・ (FluidSphere.pas)
・SphericalFluid/
┣・SphericalFluid.dpr / .dproj ・・・ project (FMX application)
┣・Main.pas / Main.fmx ・・・ main form: UI, 3D scene, animation loop
┣・FluidSphere.pas ・・・ TFluidSphere3D: vorticity relief sphere
┗・_LIBRARY/LUXOPHIA/
┣・LUX.SH.Transform.pas ・・・ SH transform engine (under development)
┣・LUX.SH.Fluid.pas ・・・ BVE solver (under development)
┣・LUX/ ・・・ base math (vectors, matrices, complex)
┣・LUX.FMX.Graphics.D3/ ・・・ FMX 3D helpers (TWorld3D, TF3DShaper)
┣・LUX.Sphere/ ・・・ sphere shapes
┗・LUX.SphericalHarmonics/ ・・・ ALFs/NALFs tables
Library subtrees on GitHub: LUX ・ LUX.FMX.Graphics.D3 ・ LUX.Sphere ・ LUX.SphericalHarmonics
The LUX.SH.Transform engine parallelizes the latitude loops with TTask (one chunk per core) and pre-allocates all scratch buffers, so no memory is allocated inside the workers.
| UI | Function |
|---|---|
| Resolution | T21 / T42 / T85 (default) / T170 (triangular truncation / transform grid) |
| Reset | restart from a random large-scale ( |
| Rotation Rate |
Coriolis term ( |
| Relief Amplitude | height of the ridges and troughs |
| Time Scale | simulated time per real-time second |
| Hyperviscosity | high-wavenumber relaxation |
| Left mouse drag | orbit the camera |
The info panel continuously displays FPS, simulated time, maximum wind speed, and the relative drift of energy and enstrophy
Open SphericalFluid.dproj in RAD Studio (Delphi 13) and build. Target platforms defined in the project: Win32 and Win64 (Win64 is the primary target).
Command line:
dcc64 -B -$O+ -U"%BDS%\lib\win64\release" -R"%BDS%\lib\win64\release" -NSSystem;System.Win;Winapi -EWin64\Release -NUWin64\Release SphericalFluid.dpr- Barotropic vorticity equation — Wikipedia
- Bourke, W. (1972): An Efficient, One-Level, Primitive-Equation Spectral Model. Monthly Weather Review, 100, 683–689.
- Orszag, S. A. (1970): Transform Method for the Calculation of Vector-Coupled Sums: Application to the Spectral Form of the Vorticity Equation. Journal of the Atmospheric Sciences, 27, 890–895.
- Spherical harmonics — Wikipedia
- Associated Legendre polynomials — Wikipedia
- Gauss–Legendre quadrature — Wikipedia
- Runge–Kutta methods — Wikipedia
- Hack, J. J. and Jakob, R. (1992): Description of a Global Shallow Water Model Based on the Spectral Transform Method. NCAR Technical Note NCAR/TN-343+STR.
- SphericalHarmonics — 3D viewer application for spherical harmonics (LUXOPHIA).
Integrated Development Environment (IDE) for Creating Native Cross-Platform Apps.