Skip to main content

Introduction

Geometric primitives — boxes, cylinders, spheres, hemispheres, and pill capsules — are the building blocks of CFD domain setup. The same five shapes serve three distinct purposes depending on how they are sized relative to the geometry:
  • Body of Influence (BOI): localised refinement volume for wakes, shear layers, and junctions.
  • MRF zone: cylindrical or pill-shaped rotating reference frame region surrounding a fan, propeller, or rotor.
  • Enclosure: large outer bounding volume establishing the fluid domain boundary.
Each primitive type maps naturally to one or more of these roles: Supported primitive types: box, cylinder, hemisphere, sphere, and pill This guide shows how to eliminate that step by writing custom Python helper classes that generate all geometry programmatically, sized from the mesh’s own bounding box at runtime. Key advantages over a manual CAD workflow:
  • One tool, three use cases — primitive type and offset ratio determine the intent.
  • Always up-to-date — bounding boxes derive from live mesh zonelets, adapting automatically when geometry changes.
  • Fully parameterised — axis direction, primitive type, and offsets are all runtime parameters.
  • Single script — mesh reading, CAD creation, and re-import run in one Python session.
The solution bridges two PyAnsys packages: Module architecture and data flow between PyPrimeMesh and PyAnsys Geometry
About the .fmd format. FMD (Fluent Meshing Data) is Ansys’s platform-agnostic binary CAD exchange format. It stores the solid body in a self-contained, OS-independent representation readable on Windows, Linux, or any Ansys-supported platform — no native CAD kernel required. This makes .fmd the ideal intermediate format when the geometry server and meshing session run on different machines or operating systems.
No CAD application is opened by the user. The entire pipeline — from reading a mesh file to appending a fully formed primitive volume — runs from a single Python script.

Code Structure

The solution is built around three Python classes you will implement:

_BBox — Bounding Box Container

A lightweight value object holding the six axis-aligned extents of the target region. It can be populated manually or converted from a Prime BoundingBox result.

Step 1 — Querying and Sizing the Bounding Box

The key differentiator of this workflow is deriving the bounding box directly from face zonelets rather than hard-coding coordinates. Implement a PrimitiveCreator class whose constructor queries the tight axis-aligned bounding box of any list of face zonelet IDs using prime.SurfaceUtilities.get_bounding_box_of_zonelets:
Once the bounding box is known, expand each face independently using per-axis offset ratios before passing it to _PrimitiveGenerator. A small ratio keeps the primitive snug for a BOI; a large ratio expands it into an enclosure:
Recompute the coordinates with the ratios applied:
Ratios greater than 1 produce large enclosure volumes; values near 0 produce snug BOI or MRF refinement zones. Expose a single public method add_boi that drives the full pipeline:

Step 2 — Implementing the Primitive Geometry Functions

All five primitives are implemented inside a _PrimitiveGenerator class. Each method follows the same pattern:
  1. Set length units to millimetres via DEFAULT_UNITS.LENGTH = UNITS.mm.
  2. Derive axis lengths and cross-section radius from the bounding box.
  3. Build a Sketch on a Plane anchored at the correct origin.
  4. Extrude or revolve the sketch into a solid body.

Shared Helpers

Before looking at individual primitives, two private helpers are used by all of them:
__cross_section_radius returns the largest circle that fits within the rectangular cross-section perpendicular to the chosen axis — i.e. half the shorter dimension of that face.

1. Box

The simplest primitive. A rectangular profile is sketched on a plane perpendicular to X and extruded along X by the full bounding-box length.
Key geometry call: Sketch.box() + Design.extrude_sketch() The sketch plane is placed at xmin with its local axes along Y and Z, so the extrusion travels in the +X direction for distance_x.
Note: Beyond the box, several other primitive geometries can be produced by the same generator simply by changing the orientation and profile passed to the sketch/extrude/revolve calls — for example a cylinder (circular profile extruded along axis_direction), a hemisphere (quarter-circle profile revolved 360° to form a dome cap), a sphere (circumscribed about the bounding box), a pill/capsule (cylinder with a hemisphere cap merged via Boolean union), and a frustum (tapered profile extruded along an axis). These follow the same bounding-box-driven approach shown above and are omitted here for brevity.

Step 3 — Dispatching the Correct Primitive

Add a single public create_boi method to _PrimitiveGenerator that selects the geometry function by name, writes the .fmd file, and shuts down the geometry service:
Once the solid is built the design is exported to an .fmd file — a platform-agnostic format readable on any Ansys-supported OS — and the geometry service is shut down.

Step 4 — Appending to the PyPrimeMesh Session

After the CAD file is written, __append_boi uses prime.FileIO to import it back as a new body part — appended to the existing model rather than replacing it. Mesh zonelets are pruned immediately so only the geometry zonelets remain, ready for size-field assignment, MRF setup, or outer-domain meshing:

End-to-End Usage Example

The following example shows a complete workflow: launching Prime, reading a mesh, and generating three primitives — a pill-shaped BOI, a cylinder MRF zone, and a box enclosure — each derived from a different set of zonelets.
Alternatively, if you already know the exact bounding box coordinates, pass use_defined_bounding_box=True and supply a _BBox instance directly:

Summary

This guide has shown how to write custom Python helper classes that generate geometric primitive volumes directly from PyPrimeMesh face zonelets, without opening a CAD application. Five primitive types — box, cylinder, hemisphere, sphere, and pill — cover the full range of CFD domain objects: localised BOI refinement zones, MRF rotating regions, and outer domain enclosures. Bounding boxes are computed at runtime from face zonelets, ensuring every primitive is automatically sized to the current geometry. Per-axis offset ratios give fine-grained control over how tightly or loosely each primitive wraps its target region. Once generated, each solid is exported as an .fmd file and appended back into the Prime model in the same Python session, making the workflow fully reproducible and easy to integrate into automated meshing pipelines. For more details, feel free to reach out on the Synopsys Developer Forum.