Kategoriarkiv: Script

Parametric Turbine model with OpenFOAM+cfMesh case ready to run

I’ve made a parametric turbine case avaliable. Thank’s to my company Minesto for letting me do that.

I’ve done a parametric turbine using Ruby scripting language,
Have set up script for running the entire simulation using cfMesh for volume meshing, OpenFOAM for simulating fields. Openscad for watertunnel-geometry.

geometry simulation

The turbine geometry has pitch as input parameter, you can easily modify to suit your needs.

The simulation has watertunnel size as input parameter.

It’s a steady state MRF model and it runs in 5-10 minutes on a i7-processor. Refine to suit your needs…

 

Case:
turbine_model_bjorn_bergqvist_minesto_ab.tar

Readme file:

Author to this method is Bjorn Bergqvist. Please refer to me or communicate if
you use the turbine geometry model in your work.

Prerequisites:
OpenFOAM 2.?.? (used by 3_run_simulation.sh)
cfMesh (used by 2_create_volume_mesh.sh)
OpenSCAD (used by 2_create_volume_mesh.sh, tunnelfactor 1 is already
generated)
Ruby 2 with spliner gem (for splined pitch, otherwise any Ruby will do)
   (install with: "gem install spliner")

Description of files and directories:
Allrun
   Run through script 1_ to 3_

1_create_geometry.sh
   Not necessary to run. Turbine geometry with pitchmod=0 is
   already generated in geom/turbine.stl.
   Usage: ./1_create_geometry <pitchmod>
   were <pitchmod> is modification of turbine blade pich
   if you are unsure: use pitchmod=0

2_create_volume_mesh.sh
   Usage: ./1_create_volume_mesh.sh <tunnelfactor>
   where <tunnelfactor> is the size of the tunnel where the turbine is simulated
   if you are unsure: use tunnelfactor=1

3_run_simulation.sh
   Usage: ./3_run_simulation.sh <tunnelfactor>
   will run on 4 cpus
   (change in decomposeParDict and 3_run_simulation.sh for other cpu count)

post_moment_table.sh
   Averages moments and forces from 990 to 1000 iterations.

Allclean
   Removes generated mesh and simulation.

turbine_geometry
   The Bjorn Bergqvist(C) turbine geometry.

cfMesh.template
   Directory with files used by cfMesh.

simpleFoam.template
   Directory for simulation (steady state, MRF)

Dirty script for dirty meshes

If you have a messy polyMesh you might use this script. Modify it to suit your needs.

#!/bin/sh
# dirty script for dirty meshes
# author Bjorn Bergqvist
# http://www.discretizer.se
# removes cells which is/have:
# zeroVolumeCells, skewFaces, underdeterminedCells and lowQualityTetFaces
#
# if you have to type something before OpenFOAM commands
# qsub... or somthing
submit=""

# create a batch file for setSet
createBatchFile() {
  counter=0
  echo "cellSet cellsToKeep new" > $2
  for i in `grep Writing $1 |awk '{ print $NF }'`
    do

      if [ $i == "zeroVolumeCells" ]; then
        echo "cellSet cellsToKeep add cellToCell zeroVolumeCells any" >> $2
        echo `grep $i log.checkMesh`
        counter=$((counter+1)) 
      fi
      if [ $i == "skewFaces" ]; then
        echo "cellSet cellsToKeep add faceToCell skewFaces any" >> $2
        echo `grep $i log.checkMesh`
        counter=$((counter+1)) 
      fi
      if [ $i == "underdeterminedCells" ]; then
        echo "cellSet cellsToKeep add cellToCell underdeterminedCells any" >> $2
        echo `grep $i log.checkMesh`
        counter=$((counter+1)) 
      fi
      if [ $i == "lowQualityTetFaces" ]; then
        echo "cellSet cellsToKeep add faceToCell lowQualityTetFaces any" >> $2
        echo `grep $i log.checkMesh`
        counter=$((counter+1)) 
      fi
    done
    echo "cellSet cellsToKeep invert" >> $2
    echo "cellSet cellsToKeep subset" >> $2
    echo "quit" >> $2
    return $counter
}

logfile=log.txt
echo "" > $logfile

while :
do
  $submit checkMesh -allGeometry -allTopology -latestTime > log.checkMesh
  checkString=`grep 'The mesh has multiple regions' log.checkMesh`
  if [ ! ${#checkString} == 0 ]; then
    echo "multiple regions: splitMeshRegions"
    $submit splitMeshRegions -largestOnly >> $logfile
    $submit subsetMesh -overwrite region0 >> $logfile
    $submit createPatch -overwrite >> $logfile
    echo "rerun checkMesh"
    $submit checkMesh -allGeometry -allTopology -latestTime > log.checkMesh
  fi
  createBatchFile log.checkMesh batchForDeleting
  fileOk=$?
  echo "fileOk $fileOk"
  if [ $fileOk == 0 ]; then
    echo "nothing to do"
    exit 0
  fi
  $submit setSet -latestTime -batch batchForDeleting > $logfile
  $submit subsetMesh cellsToKeep >> $logfile
  $submit createPatch -overwrite >> $logfile
done

Typical output:

<<Writing 4 zero volume cells to set zeroVolumeCells
<<Writing 232 skew faces to set skewFaces
<<Writing 118 faces with low quality or negative volume decomposition tets to set lowQualityTetFaces
<<Writing 3806 under-determined cells to set underdeterminedCells
fileOk 4
multiple regions: splitMeshRegions
rerun checkMesh
<<Writing 114 skew faces to set skewFaces
<<Writing 1732 under-determined cells to set underdeterminedCells
fileOk 2
multiple regions: splitMeshRegions
rerun checkMesh
<<Writing 6 skew faces to set skewFaces
<<Writing 608 under-determined cells to set underdeterminedCells
fileOk 2
multiple regions: splitMeshRegions
rerun checkMesh
<<Writing 247 under-determined cells to set underdeterminedCells
fileOk 1
multiple regions: splitMeshRegions
rerun checkMesh
<<Writing 125 under-determined cells to set underdeterminedCells
fileOk 1
<<Writing 72 under-determined cells to set underdeterminedCells
fileOk 1
<<Writing 44 under-determined cells to set underdeterminedCells
fileOk 1
<<Writing 27 under-determined cells to set underdeterminedCells
fileOk 1
<<Writing 20 under-determined cells to set underdeterminedCells
fileOk 1
<<Writing 12 under-determined cells to set underdeterminedCells
fileOk 1
<<Writing 5 under-determined cells to set underdeterminedCells
fileOk 1
<<Writing 3 under-determined cells to set underdeterminedCells
fileOk 1
<<Writing 1 under-determined cells to set underdeterminedCells
fileOk 1
<<Writing 1 under-determined cells to set underdeterminedCells
fileOk 1
fileOk 0
nothing to do