Difference between revisions of "Thread:Talk:Sig Numerical Optimization/Salome and cfMesh parametrization"

From OpenFOAMWiki
m (Preparation of created boundary .stl files for cfMesh)
m (Preparation of created boundary .stl files for cfMesh)
Line 47: Line 47:
  
 
For that purpose I have written little bash script I called "stlCombine" which combines .stl files and outputs "mergedStl.stl" file.
 
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'''''
+
 
 +
'''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  
 
   #!/bin/bash  
 
   # how to run it: ./stlCombine [PATH TO DIRECTORY WITH .stl FILES] [PATH TO OUTPUT DIRECTORY]  
 
   # how to run it: ./stlCombine [PATH TO DIRECTORY WITH .stl FILES] [PATH TO OUTPUT DIRECTORY]  

Revision as of 14:13, 23 April 2016

Preparation of created boundary .stl files for cfMesh

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