Sunday, July 25, 2010

Script to generate cut sections for a CFD++ solution


This script will generate cut sections in CFD++/Tecplot format from a CFD++ solution file.
Techplot cut sections can be visualized in ParaView.

How to use this script:

Save the below script with a name say cfd_cuts and execute it in following way:

./cfd_cuts Min Max Number_of_cuts Axis

For example to make 10 cuts in X direction starting from 1.2 to 3 issue following command:

./cfd_cuts 1.2 3 10 x

#!/usr/bin/tclsh8.4

#User inputs


#Minimum value of axis


 set Min [format %0.3f [lindex $argv 0]]


#Maximum value of axis


 set Max [format %0.3f [lindex $argv 1]]


#Number of cuts in between Min and max value


 set Number [format %0.3f [lindex $argv 2]]


#Axis in which we need these cuts


 set Direction [lindex $argv 3]


#Calculating the intervals for cuts


 set Interval [expr (($Max-$Min)/($Number))]


#Opening files for writing CFD++ commands for cuts


 set fp [open "section_cuts.sh" w] 


 set fpt [open "section_cuts_tec.sh" w] 


#Loops for number of cuts


 set j $Min


 for {set i 0 } {$i <= $Number} {incr i} {


 puts $fp "npfcutpl $Direction= [expr $j] cellsin.bin  pltosout.bin mpf $Direction=[expr $j]m"


 puts $fpt "mpf3dtecp cut_$Direction=[expr $j]m.mpf3d 


cut_$Direction=[expr $j]m_tec"

 set j [expr $j+$Interval]


 }


#Closing files


 close $fp


 close $fpt


#Executing cuts commands for generating cuts in CFD++ format


 exec /usr/bin/sh section_cuts.sh


 puts "\033\[01;32mIf you want to convert CFD++ sections files into Tecplot files press y otherwise press n\n\033\[0m"


 set input [gets stdin]


 scan $input "%s" answer


 if {$answer == "y"} {


#Executing cuts commands for generating cuts in Tecplot format, these files can be visualize in ParaView


 exec /usr/bin/sh section_cuts_tec.sh


  } elseif {$answer == "n"} {


    exit 0


    } else {


    exit 0


    }

Let me know if you need any explanation.
Any comments are welcome. 
This script can be downloaded from here:
 

1 comment:

  1. hi Rawat,

    nice script! I have a similar issue if you want to interest. I have 2000 mpf3d files such as from *.mpf3d.1 to *.mpf3d.2000 and I need an animation. However, CFD++ gives just pltosout.bin.# for an animation. What do you suggest?

    ReplyDelete