This example network demonstrates how Python code can be integrated into the Flownex calculation procedure using a Quick Script component. This is particularly useful when users have implemented custom correlations, equations or calculations in Python that they wish to incorporate into a Flownex model.
PROJECT FILE
The network can be downloaded by clicking on the download button below:
NETWORK DESCRIPTION
In this example, Python is used to calculate a heat transfer coefficient using data obtained from Flownex. The calculated value is then returned to Flownex and used in the thermal calculation.
A Quick Script component is configured to define the inputs passed from Flownex to Python and the outputs returned to Flownex. The network is configured as shown in Figure 1.
The Quick Script component retrieves the Prandtl number (Pr), Reynolds number (Re), pipe length (L) and thermal conductivity (k) from the Pipe component, as shown in Figure 2. These input values are written to a CSV file named inputs.csv, which serves as the interface between Flownex and the Python code.
Once the input file has been generated, the Quick Script component executes the Python file specified in the script path. The Python code reads the input values from inputs.csv and uses them to perform the heat transfer calculations, as shown in Figure 3.
The Python code calculates the Nusselt number (Nu) and heat transfer coefficient (h), then writes the results to a CSV file named outputs.csv. The Quick Script component subsequently reads this file, extracts the calculated heat transfer coefficient and assigns it to the heat transfer coefficient input of the Composite Heat Transfer component, as shown in Figure 4.
RUNNING THE SIMULATION
Open
Calc HTC.pyin Visual Studio Code or an equivalent Python development environment.-
Run the Python file. In the terminal, identify the Python installation directory from the execution path displayed at the top of the terminal. Copy the directory path, excluding
\python.exe.
For this example, the directory is:C:\Users\tinashek\AppData\Local\Python\pythoncore-3.15-64
Alternatively, obtain the Python executable path by running the following command in the terminal:python -c "import sys; print(sys.executable)" Open the Flownex project and select the Quick Script component.
-
Under the "Python" settings, paste the copied directory into the "Python exe directory (no spaces allowed)" field. Ensure that the correct Python file is specified in the "Python file name" field.
Select the downstream node and change the mass flow rate to -0.9 kg/s.
Solve Steady State.
-
Select the Quick Script component and inspect the results. The calculated values should have changed, indicating that the Python code has been executed and the updated results have been returned to Flownex.