Best practices#
Session management#
- Reuse Fluent sessions
Keep the same Fluent session open for multiple operations to improve performance. Only disconnect when you are finished or need a clean solver state.
- Clean shutdown
Always call
disconnectwhen finished to free resources.- Check status
Use
session_statusandsolver_statusto verify connection and iteration state before mutating operations.
Discover-generate-validate-execute loop#
For almost every non-trivial setup change:
Discover: Use
find_api,get_state, orlist_named_objectsbefore writing code.Validate: Use
validate_codeto catch sandbox violations before execution.Execute: Use
run_codeto apply the change.Verify: Use
summarize_setuporget_stateto confirm the result.
Never skip discovery for path-dependent settings (URF, Courant, UTL vs classic tree).
Code execution#
- Validate before running
Always call
validate_codeon generated or untrusted code beforerun_code.- Prefer targeted reads
Use
get_statewith specific paths rather than reading large subtrees.- Use named-object tools
Use
list_named_objectsandfind_named_objectinstead of guessing collection paths.
Mesh and diagnostics#
- Route mesh quality intents correctly
Use
mesh_qualityfor skewness, orthogonal quality, aspect ratio, andmesh.checkoutput. Do not userun_codewith invented PyFluent accessors.- Use compare_files for case diffs
compare_filesruns in isolated headless sessions and never touches the live workspace session.
Workflow design#
- Modular workflows
Break complex setup into smaller, verifiable steps.
- Error recovery
When
run_codefails, read the error, re-discover withget_state, and regenerate rather than retrying blindly.- Offline-first discovery
Use
find_apiandget_helpeven when offline; only call live tools when you need current values or mutations.
Performance#
- Minimize reconnects
Avoid repeated
connect/disconnectcycles within a single workflow.- Batch related changes
Combine related
run_codesnippets when safe. However, smaller steps are preferred for easier debugging.- Compare files sparingly
Using
compare_fileslaunches two headless Fluent sessions. Use it for explicit diff requests, not routine inspection.
Common patterns#
Boundary condition setup#
connectand load case/mesh.list_named_objects("setup.boundary_conditions.velocity_inlet")lists inlets.get_state(["setup.boundary_conditions.velocity_inlet.inlet-1"]) reads current values.validate_code→run_codeapplies the desired settings update.summarize_setup(scope="boundaries")verifies the boundary setup.
Convergence check#
solver_statuschecks if Fluent is iterating.simulation_reportreturns a structured solution report.get_state(["solution.monitors.residual"]) reads residuals.
Case comparison#
compare_files(path_a="baseline.cas.h5", path_b="modified.cas.h5").Reply with the pre-rendered
summarymarkdown table verbatim.