This utility reads pre-computed velocity field data in toroidal coordinates and interpolates it onto an OpenFOAM mesh using trilinear interpolation.
First, you need to generate the velocity field data U[X, Y, phi]
in Python and save it as raw data files:
X.raw
- X-coordinate axis values (on any 2D cross-section)Y.raw
- Y-coordinate axis values (radial distance in y-z plane, but has the same sign as z)phi.raw
- Azimuthal coordinate values (in radians, from 0 to pi)U.raw
- Velocity field dataU[X, Y, phi]
Axis files (X.raw, Y.raw, phi.raw):
N
value1
value2
...
valueN
Velocity field file (U.raw):
Nx Ny Nphi
# Optional comment line
ux1 uy1 uz1
ux2 uy2 uz2
...
The velocity data should be stored with phi as the fastest varying index.
The readToroidalRaw
utility reads these files and interpolates the velocity field onto the OpenFOAM mesh:
# From your OpenFOAM case directory
readToroidalRaw
-X path/to/X.raw
- Custom path to X coordinate file-Y path/to/Y.raw
- Custom path to Y coordinate file-phi path/to/phi.raw
- Custom path to phi coordinate file-U path/to/U.raw
- Custom path to velocity field file
The utility performs the following coordinate transformation for each mesh cell center:
// Cartesian (x,y,z) → Toroidal (X,Y,phi)
X_query = x // Direct mapping
Y_query = sqrt(y² + z²) * sign(z) // Signed radial distance
phi_query = atan2(z, y) // Angular coordinate
For each mesh cell center, the utility:
- Maps the cell center coordinates
(x,y,z)
to toroidal coordinates(X,Y,phi)
- Finds the surrounding 8 data points in the
U[X,Y,phi]
grid - Performs trilinear interpolation to compute the velocity at the cell center
- Assigns the interpolated velocity to the cell
The utility writes the interpolated velocity field to 0/U
in the OpenFOAM case, which can then be used as initial conditions for simulations.
cd myUtilities/readToroidalRaw
wmake
# Place raw data files in initialU_data/ directory
# Run from OpenFOAM case root
readToroidalRaw -X ./initialU_data/X.raw -Y ./initialU_data/Y.raw -phi ./initialU_data/phi.raw -U ./initialU_data/U.raw
- The Y-coordinate uses signed radial distance to distinguish between upper (z > 0) and lower (z < 0) half-planes
- The utility clamps out-of-bounds queries to the nearest grid point
- Requires a valid OpenFOAM case with mesh already generated
- The output field
0/U
will have the same boundary conditions as specified in the original0/U
file