Skip to content

interpolate NF axi-symmetirc numerical solutions as initial conditions for 3D cartesian coordinates simulation in openfoam

Notifications You must be signed in to change notification settings

zhizhiL/interpNF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Toroidal Data Interpolation Utility

This utility reads pre-computed velocity field data in toroidal coordinates and interpolates it onto an OpenFOAM mesh using trilinear interpolation.

Workflow Overview

1. Generate Raw Data Files (Python)

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 data U[X, Y, phi]

File Format:

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.

2. Run OpenFOAM Utility

The readToroidalRaw utility reads these files and interpolates the velocity field onto the OpenFOAM mesh:

# From your OpenFOAM case directory
readToroidalRaw

Command line options:

  • -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

3. Coordinate Transformation

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

4. Trilinear Interpolation

For each mesh cell center, the utility:

  1. Maps the cell center coordinates (x,y,z) to toroidal coordinates (X,Y,phi)
  2. Finds the surrounding 8 data points in the U[X,Y,phi] grid
  3. Performs trilinear interpolation to compute the velocity at the cell center
  4. Assigns the interpolated velocity to the cell

5. Output

The utility writes the interpolated velocity field to 0/U in the OpenFOAM case, which can then be used as initial conditions for simulations.

Building the Utility

cd myUtilities/readToroidalRaw
wmake

Usage Example

# 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

Notes

  • 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 original 0/U file

About

interpolate NF axi-symmetirc numerical solutions as initial conditions for 3D cartesian coordinates simulation in openfoam

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published