Boost Your CFD Workflow Productivity With An API: Part 1

Automating repetitive CFD tasks and performing batch operations more efficiently.

popularity

If you’re in the field of computational fluid dynamics testing or studies, you already know how much time and effort it takes to complete the tasks involved. Hours upon hours are spent on geometry clean-up, meshing, and post-processing. Furthermore, when you’re dealing with similar models that have new constraints or dimensions, the work can feel tedious. But don’t worry! There’s a way to simplify all of this: Automation. By automating the CFD workflow, you can save yourself countless hours. This is especially useful when optimizing variables for a design to get the best output, which often requires multiple runs of the model. With automation, you can simulate the maximum number of cases in the allotted time frame, giving you a significant advantage in the product design life cycle. The best part is that the Fidelity Python application programming interface (API) is here to help you achieve this by automating any CFD workflow to boost the productivity of your design cycle.

Why an API?

APIs are an excellent tool for automating repetitive tasks and performing batch operations more efficiently. They can help reduce workload time and boost productivity, especially when dealing with new designs that require similar workflows. Additionally, APIs can assess mesh convergence and simulation parameter sensitivity, perform mesh adaptation for simulation accuracy, and implement best practices among colleagues and teams. The Fidelity Python API is easily compatible with any versioning system, making it an ideal choice for use on both Windows and Linux systems. With the help of an integrated development environment (IDE), such as GitLab or GitHub, you can easily load the Fidelity Python API and take full advantage of its many benefits.

Why Python?

  • An easy-to-learn programming language
  • No compilation required
  • Exhaustive community and resources
  • Works on both Windows and Linux – no need to transfer or change the code
  • Compatible with many versioning systems, notebooks, etc.
  • Dedicated IDE that can load Fidelity Python API
  • Python is embedded into Fidelity for direct usage, including the most classic libraries, such as Math, Numpy, Matplotlib, etc., for CFD automated workflow.

About Fidelity Python API

The Fidelity Python API provides a comprehensive workflow, which includes CAD import, post-processing, project management, and job submission, among other essential features. It is crucial to note that the current version of the API uses Python 3.8.5 and is regularly updated to the most recent version.

Python scripts can be run in the following ways:

  •  Batch command – Fidelity opens and runs the script until the end and then closes.
  •  In the graphic user interface (GUI)

Running a Python script from a command line

Run a python script in a shell on Linux:

fidelity2022.2 -print -batch -noFork -script script_full_path/script.py

Run a python script in a command prompt on Windows:

"Installation_path\Fidelity 2022.2\fidelityClient.bat" -print -batch -noFork -script script_full_path\script.py

-batch: ensures that Fidelity is run in batch mode. When -batch is not specified, the GUI will open, and the script will run and is visible in the GUI.

-noFork: the user gets the terminal control back only after executing the script. When -noFork is not specified, the user will get the terminal control back right after initializing Fidelity (script will be executed in the background).

-print: enables the output in the shell.

-script script_full_path/script.py: specifies the Python script to be run.

Running a Python script from the GUI

I: From the project management panel

  • Click on the dotted matrix icon present on the PM panel
  • Select Run Python script
  • Select a Python script in the browser and click OK to run it.

While executing the script, a loading screen blocking the GUI will appear. Once the script has run, it is possible to undo or redo the step in one step using the undo/redo tabs on the panel. The execution of the script is encapsulated as a task in the action tree.

II: On selection

  • Select any entity in the tree (a geometry object, Mesh or Simulation setup, etc.)
  • Right-click and select Run Python script on the selection
  • Select a Python script in the browser and Ok to run it.

Fidelity returns the list of selected entities as arguments, making selecting arguments where we aim to run a script easily.

III. Python hooks

Python hooks can be integrated into the workflow to automatically execute Python commands before or after a specific task. These scripts are stored in Fidelity installation under /_resources/_hooks/ and under the corresponding subfolder:

  • _open_project to run a script after each project opening.
  • _post_import_geometry to run a script after geometry import.
  •  _pre_mesh_generation to run a script before mesh generation.
  • _post_mesh_generation to run a script after mesh generation.
  •  _pre_simulation to run a script before the simulation run.
  • _post_simulation to run a script after the simulation run.

Note:

  • Complete HTML documentation is provided, including all the modules, classes, and macros.
  • Cadence delivers training on Python and automation.
  • Scripts are also published on the COS platform. For instance, a script to automatically create a mesh setup based on selected geometry are available on COS.


Leave a Reply


(Note: This name will be displayed publicly)