Copyright (c) 2023-2025 Antmicro
This project contains scripts used for thermal simulation and data visualization. You can learn more about the project from the following blog note.
The thermal-simulation-scripts pipeline has been tested and validated with the following dependencies::
Calculix= 2.20ParaView= 6.0.0python= 3.11.2pipFreeCAD= 1.0.0ccx2paraviewffmpeg
On Debian-based systems, these dependencies can be installed using:
sudo apt install -y calculix-ccx python3 python3-pip libxrender1 tar wget libgl1-mesa-glx libegl1 libosmesa6 ffmpeg wget -O freecad.AppImage "https://github.com/FreeCAD/FreeCAD/releases/download/1.0.0/FreeCAD_1.0.0-conda-Linux-x86_64-py311.AppImage"
sudo chmod +x freecad.AppImage
./freecad.AppImage --appimage-extract
sudo mv squashfs-root /usr/local/share/freecad
sudo ln -s /usr/local/share/freecad/AppRun /usr/local/bin/freecad
echo 'export FREECAD_PATH="/usr/local/share/freecad"' >> ~/.bashrc && source ~/.bashrc
rm freecad.AppImagesudo mkdir /opt/paraview
sudo wget -O /opt/paraview/paraview.tar.gz "https://www.paraview.org/paraview-downloads/download.php?submit=Download&version=v6.0&type=binary&os=Linux&downloadFile=ParaView-6.0.0-MPI-Linux-Python3.12-x86_64.tar.gz"
sudo tar -xvzf /opt/paraview/paraview.tar.gz --strip-components=1 -C /opt/paraview
sudo rm /opt/paraview/paraview.tar.gz
echo 'export PATH=/opt/paraview/bin:$PATH' >> ~/.bashrc
source ~/.bashrcClone the repository:
git clone http://github.com/antmicro/thermal-simulation-scripts
cd thermal-simulation-scriptsInstallation should be performed in an isolated python environment to avoid dependency conflicts:
sudo apt update
sudo apt install pipx
pipx ensurepath
pipx install . --include-depsThe script can be run using the following commands:
tprefor pre-processing tasks.tpostfor simulation post-processing.
The first step in a thermal simulation is to define constraints for each surface of the 3D model and convert it into a mesh using FreeCAD. This process results in a .FCStd format file.
This step prepares the simulation. The .FCStd file should be sufficient, but additional settings can be configured.
tpre parse-fcstd --fcstd <path_to_fcstd> --inp [inp_dir] --log [settings_dir]<path_to_fcstd>: Path to FreeCad design file (.FCStd)[inp_directory]: Optional output directory for generating simulation input file (.inp)[setting_dir]: Optional output directory for generating simulation settings file (.json)
To generate report in markdown format use the following command.
The report includes data from simulation.json, and optionally, user comments provided under the user_comments key in config.json.
tpre report --sim [path_to_settings_file] --config [path_to_config_file] --report-dir [report dir][path_to_settings_file]: Optional path to simulation settings file (simulation.json)[path_to_config_file]: Optional path to config file (config.json)[report dir]: Optional path to report file (.md)
To run the simulation using CalculiX:
ccx <path_to_inp_file>Refer to the CalculiX manual for further details.
ccx2paraview <frd_file> vtk<frd_file>: Path to the CalculiX output.frdfile.
tpost csv --vtk [vtk_directory] --sta [sta_file] --output [output_file][vtk_directory]: Optional path to directory with.vtkfiles.[sta_file]: Optional path to.stafile (output from CalculiX).[output_file]: Optional path for the output CSV file.
The output CSV contains:
- Time [s]
- Maximum/Minimum temperature in Kelvin and Celsius
tpost plot --csv [data_file] --output [output_dir] --sim [simulation_json][data_file]: Optional path to simulation.csvfile.[output_dir]: Optional directory where graphs will be saved.[simulation_json]: Optional simulation JSON file.
Graphs generated:
- Temperature vs. time (Kelvin & Celsius)
- Highest/Lowest temperatures
- Temperature differences
- Simulation iterations over time
All of them will be saved in /graphs/.
To compare characteristics on a common graph use:
tpost compare-csv --csv1 <1st_csv_file> --csv2 <2nd_csv_file>Run tpost compare-csv --help for advanced options.
tpost previewImages colored with temperature gradients will be generated in /previews/.
tpost animationAnimation frames will be saved in /animations/.
To create an animation in .webm format, use e.g. ffmpeg
ffmpeg -framerate <fps> -i <input_frames> <animation_path><fps>: frames per second
<input_frames>: path to animation frames - can be used with wildcards
<animation_path>: file path to the animation
Blender animations utilize Antmicro's scene setup and rendering tool PCBooth.
Animation scripts require:
.vtkfiles that are obtained in converting simulation resultsconfig.json[Optional] containingcamera_customparameters needed if PCBooth is set to use custom camera
Use this command to generate .gltf files from .vtk files:
tpost generate-gltfThen convert .gltf file to .blend:
tpost gltf-to-blend --gltf <path-to-gltf>Prepare the .blend for PCBooth with:
tpost process-blendRender frame with PCBooth:
pcbooth -b <path-to-blend> -c <pcbooth-job-name>Add color scale bar:
rsvg-convert -a -h <height> -o scale.png <colormap_scale.svg>
composite -gravity east scale.png <frame.png> <output.png>where:
<height>is the height of the frame in pixels.<scale.svg>is the color bar.svggenerated usinggenerate_svg_palette.<frame.png>is the frame image rendered with PCBooth.<output.png>is the output path where the frame and color bar are combined.
Generate gltf files with the following command:
tpost generate-gltfthen in the /designs/ directory run
../src/postprocessing/blender_animation.sh <gltf_dir> where:
<gltf_dir>is path to gltf directory created withtpost generate-gltf
cd designs
tpre parse-fcstd --fcstd example.FCStd
tpre reportexport OMP_NUM_THREADS=16
ccx FEMMeshGmshccx2paraview FEMMeshGmsh.frd vtk
mkdir -p vtk
mv *.vtk vtk/Generate graphs, previews and animation frames:
tpost csv
tpost plot
tpost preview
tpost animationTo generate animations from ParaView output frames:
ffmpeg -framerate 5 -i animations/ISO_%6d.png animations/iso.webm
ffmpeg -framerate 5 -i animations/TOP_%6d.png animations/top.webm
ffmpeg -framerate 5 -i animations/BOTTOM_%6d.png animations/bottom.webmtpost generate-gltf
../src/postprocessing/blender_animation.sh gltfSimulating natural convection requires calculating the film coefficients for the surfaces. These coefficients can be estimated using an initial guess for the surface temperature. However, since predicting the surface temperature accurately is complex, this method alone may not provide precise results.
The Bisection Algorithm is used to improve accuracy. It iterates over a given temperature range, comparing the simulated final temperature with the temperature assumed in the film coefficient calculator. With each iteration, the temperature range is reduced until the difference between the simulated and assumed temperatures is within a specified tolerance. Then the algorithm returns the final temperature and the corresponding film coefficients.
Using sparse mesh is recommended for this algorithm
Define the Heat Flux Load constraints in FreeCad.
Then assign each face that dissipates heat to one of them.
Rename each Heat Flux Load to a custom name.
In this example, 3 Heat Flux Load constraints were defined:
- vertical
- horizontal_up
- horizontal_down
In /designs/, create config.json (or edit if it exists):
- In the
filmdictionary, specify entries for eachHeat Flux Loadconstraint defined in FreeCad - In the
temperaturedictionary, specify themax,minandtolerancevalues.
Visit config section for in detail information. Config for this example can be found in config.json.
./src/preprocessing/find_coef.sh designs/example.FCStd designs/The 1st argument is the path to the .FCStd file and the 2nd argument is the path to the /designs/ directory.
Convergence temperature and calculated coefficients are displayed at the end of the log.
config.json is used to store information needed for automated film coefficient estimation and Blender visualization flow.
It also allows adding user comments to the simulation report. Allowed fields with their structure are listed below:
{
"film":{
<constraint1_name>:[
<characteristic_length>,
<orientation>
],
<constraint2_name>:[
...
]
},
"temperature":{
"max":<max_temp>,
"min":<min_temp>,
"tolerance":<tol>
},
"camera_custom":{
...
},
"user_comments":{
...
}
}<constraint_name>is the constraint name defined in FreeCad<characteristic_length>is height (in case of vertical plane approximation) or the smaller dimension (in case of horizontal plane approximation) [mm]<orientation>isvertical,horizontal_uporhorizontal_down<max_temp>is the upper boundary of automatic film coefficient search area [Celsius]<min_temp>is the lower boundary of automatic film coefficient search area [Celsius]<tol>is the acceptable difference of calculated and simulated temperature in automatic film coefficient search [Celsius]camera_customstores Blender camera data and is defined automatically withtpost save-configuser_commentsthe content of it will be parsed to the README.md withtpost reportcommand
This project is published under the Apache-2.0 License.
