I did a little research on combining cfMesh, Salome and OpenFoam to create completely free and Open-source parametric CFD simulation. So I want to share my experiences and maybe somebody can give me some advice to correct me or use part of what I did. I tried to create parametric Ahmed body simulations and I had some success, so I created a little tutorial. I will explain how to create parametric geometries with Salome and meshes with cfMesh. All files explained in these thread can be downloaded from tutorials page: Parametric Ahmed body.
To couple Salome and cfMesh with Foam use scripts page: Foam's little helpers
Preparation of created boundary .stl files for cfMesh[edit]
After creating geometry boundary .stl files it is time to mesh the domain. Although it is not implemented in bash script it can be added very easily, because even meshing can be done automatically now thanks to Creative Fields, Ltd. and their free cfMesh.
First we need to prepare created .stl files for meshing with cfMesh. Each .stl file represent one patch, so to create closed domain all patches have to be combined in to one “big” .stl file. One thing you have to be careful about is to set patches names in new combined .stl file.
Example is shown for Bottom.stl file in Ahmed geometry. Bottom.stl file looks like this:
solid facet normal 0.000000e+00 0.000000e+00 -1.000000e+00 outer loop vertex -2.000000e+03 -2.000000e+03 0.000000e+00 vertex -2.000000e+03 2.000000e+03 0.000000e+00 vertex 7.000000e+03 2.000000e+03 0.000000e+00 endloop endfacet facet normal 0.000000e+00 0.000000e+00 -1.000000e+00 outer loop vertex 7.000000e+03 -2.000000e+03 0.000000e+00 vertex -2.000000e+03 -2.000000e+03 0.000000e+00 vertex 7.000000e+03 2.000000e+03 0.000000e+00 endloop endfacet endsolid
When all .stl files are combined together, part for patch Bottom should look like this:
…. endfacet endsolid Inlet solid Bottom facet normal 0.000000e+00 0.000000e+00 -1.000000e+00 outer loop vertex -2.000000e+03 -2.000000e+03 0.000000e+00 vertex -2.000000e+03 2.000000e+03 0.000000e+00 vertex 7.000000e+03 2.000000e+03 0.000000e+00 endloop endfacet facet normal 0.000000e+00 0.000000e+00 -1.000000e+00 outer loop vertex 7.000000e+03 -2.000000e+03 0.000000e+00 vertex -2.000000e+03 -2.000000e+03 0.000000e+00 vertex 7.000000e+03 2.000000e+03 0.000000e+00 endloop endfacet endsolid Bottom solid Outlet ….
For that purpose I have written little bash script I called "stlCombine" which combines .stl files and outputs "mergedStl.stl" file. EDIT: On OSX head command with -1 option doesn't work so change that line from tail -n +2 $file | head -n -1 >> $outputPath/mergedStl.stl to tail -n +2 $file | tail -r | tail -n +1 | tail -r >> $outputPath/mergedStl.stl
#!/bin/bash # how to run it: ./stlCombine [PATH TO DIRECTORY WITH .stl FILES] [PATH TO OUTPUT DIRECTORY] # example with ahmed is ./stlCombine ./ahmed/ahmed_25/constant/triSurface ./ahmed/ahmed_25 # get .stl files location/path specified with running script (from example ./ahmed/ahmed_25/constant/triSurface) filePath=$(cd $1 && pwd) # get merged file output location/path specified with running script (from example ./ahmed/ahmed_25) outputPath=$(cd $2 && pwd) # check if file mergedStl.stl exists. If it does delete it. if [ -f $filesPath/mergedStl.stl ] then rm $filesPath/mergedStl.stl fi # remove all temporary files from input directory (where .stl files are located) if [ -d "$filePath/*~" ]; then rm $filePath/*~ fi # add patch name: # change first and last line of every file in input location from solid to solid [.stl FILE NAME] and from endsolid to endsolid [.stl FILE NAME] # merge them together # example is from "solid" to "solid Bottom" and from "endsolid" to "endsolid Bottom" for file in $filePath/*.stl do # get .stl file name fileName=`basename $file` # remove .stl file extension patchName=`echo "$fileName" | cut -f1 -d'.'` # append line solid [.stl FILE NAME] (eg. solid Bottom ) to file mergedStl.stl echo "solid $patchName" >> $outputPath/mergedStl.stl # copy all lines except first and last one from loaded .stl file and append them to mergedStl.stl tail -n +2 $file | head -n -1 >> $outputPath/mergedStl.stl # append line endsolid [.stl FILE NAME] (eg. endsolid Bottom ) to file mergedStl.stl echo "endsolid $patchName" >> $outputPath/mergedStl.stl done