Skip to content

Export CGNS, Plot3D and VTK ​

Xall reads .grd and cc.par; most other solvers and post-processors read CGNS or Plot3D, and ParaView reads VTK. SHORE writes all three from a project or a mesh.

The code is examples/cookbook/exports.py (CGNS and Plot3D, needs the cgns extra, about 2 s) and examples/cookbook/exports_vtk.py (VTK, needs the vis extra). Both start from a project with two components, a cubed sphere and a background box:

python
shapes.sphere(radius=1.0, subdivisions=4).export("sphere.stl")
p = Project()
p.load_geometry("sphere.stl")
p.build_topology("cubed_sphere", nk=17, ds=1e-2, growth=1.15, ni=33, nj=64,
                 theta_cap=np.deg2rad(35.0))  # fmt: skip
p.march()
p.use_component("background")
p.build_primitive("box", vmin=(-4.0, -4.0, -4.0), vmax=(4.0, 4.0, 4.0), ni=33, nj=33, nk=33)
p.save("case.shore")

Write a CGNS file ​

bash
shore cgns case.shore -o case.cgns
shore cgns case.shore -c main -o sphere.cgns
python
p.write_cgns("case.cgns")  # every component with a mesh: a base each
p.write_cgns("sphere.cgns", components=["main"])
with h5py.File("case.cgns", "r") as f:
    for base in ("main", "background"):
        zones = [f[base][k] for k in f[base] if f[base][k].attrs.get("label") == b"Zone_t"]
        conn = sum(len(z.get("ZoneGridConnectivity", ())) for z in zones)
        bcs = sum(len(z.get("ZoneBC", ())) for z in zones)
        print(f"base {base}: {len(zones)} zones, {conn} 1-to-1 connections, {bcs} BCs")
text
base main: 6 zones, 24 1-to-1 connections, 12 BCs
base background: 1 zones, 0 1-to-1 connections, 6 BCs
Block modelCGNS
componentCGNSBase_t, named after the component
blockstructured Zone_t, named after the block label
SHARED / DIRICHLET / PERIODIC faceGridConnectivity1to1_t in both zones, with the transform from the face's AxisMap
WALL faceBC_t BCWall
SYMMETRY faceBC_t BCSymmetryPlane
FREE faceBC_t BCTypeUserDefined, tagged shore:FREE
  • Needs h5py: pip install "shore-mesh[cgns]". The file is CGNS/HDF5, library version 3.4.
  • -c / components= picks components (repeatable); the default is every component with a mesh.
  • The cubed sphere has 4 seams per block, written once in each zone: 24 connections. A face shared with several blocks (CH's body.k_hi) gets one connection per partner; nodes that match no partner are refused.
  • FREE faces (outer boundaries, overlap boundaries) are user-defined: set the far-field or overset condition in your solver set-up.
  • A background primitive (box, annulus, flat-caps) has no wall: its faces are FREE or seams (ADR 0055).

Write a Plot3D grid ​

bash
shore plot3d case.shore -o case.xyz
python
p.write_plot3d("case.xyz")
with open("case.xyz", "rb") as f:
    raw = f.read()
nblocks = int(np.frombuffer(raw, "<i4", 1, 4)[0])
dims = np.frombuffer(raw, "<i4", 3 * nblocks, 16).reshape(nblocks, 3)
print(f"case.xyz: {nblocks} blocks, dims {dims.tolist()}")
text
case.xyz: 7 blocks, dims [[33, 17, 17], [33, 17, 17], [33, 17, 17], [33, 17, 17], [17, 17, 17], [17, 17, 17], [33, 33, 33]]
  • Multi-block whole 3-D grid: no IBLANK, Fortran unformatted (4-byte record markers), double precision, little endian; node counts in the header.
  • Components are written in project order, blocks in component order. Plot3D carries no connectivity or boundary conditions; use CGNS when the reader needs them.

Write VTK for ParaView ​

python
shapes.sphere(radius=1.0, subdivisions=4).export("sphere.stl")
p = Project()
p.load_geometry("sphere.stl")
p.build_topology("cubed_sphere", nk=17, ds=1e-2, growth=1.15, ni=33, nj=64,
                 theta_cap=np.deg2rad(35.0))  # fmt: skip
p.march()
p.mesh.write_vtk("sphere")  # sphere.vtm: one block per HexBlock, cell data "Jacobian"
grid = pv.read("sphere.vtm")
print([(name, block.dimensions) for name, block in zip(grid.keys(), grid, strict=True)])
text
[('sub0', (33, 17, 17)), ('sub1', (33, 17, 17)), ('sub2', (33, 17, 17)), ('sub3', (33, 17, 17)), ('cap_north', (17, 17, 17)), ('cap_south', (17, 17, 17))]

From .geo files:

bash
shore export sphere_sub*.geo sphere_cap*.geo -o sphere.vtm
shore export sphere_sub0.geo -o sub0.vtm
  • Needs pyvista: pip install "shore-mesh[vis]".
  • Cell data Jacobian is attached by default (with_jacobian=False, --no-jacobian to skip).
  • A single .geo exported to a .vts is treated as a j-periodic O-grid block: a column is added that closes j. That is right for an ogrid block and wrong for any other; export other single blocks to .vtm (-o name.vtm), which keeps them open.

See also ​

Released under the MIT License.