# # Copyright (c) 2004 Programmed by Jonghyuk Lee # # This Gridgen script is generated for ANSYS users. # It is distributed and modified freely for personal use only. # ################################################################################ # Glf script for Gridgen to ANSYS. # # Restriction : # * To define BCs or VCs, you must select STAR-CD(2D) for analysis S/W. # These BCs are converted to COMPONENT in ANSYS, named with BC's name. # * One BC should have ONLY ONE CONNECTOR. # * Use VCs in Gridgen to define different materials or element types. # The VCs must be numbered successively with starting number 1. # * This script DO NOT generate the commands concerning materials(MP,REAL...). # Only element type command,ET, will be written. # * Output file name is "ansys.inp". # * Output file is saved the folder in which this script is executed. # ################################################################################ ################################################################################ # Block existance checking ################################################################################ set Blks [gg::blkGetAll] if { $Blks == "" } { puts "No block exist." exit } ################################################################################ # Set analysis software invironments ################################################################################ gg::aswSet "STAR-CD" -dim 2 set cwd [ file dirname [info script]] set tempfile [ file join $cwd "test.u" ] gg::aswExport $tempfile unset tempfile ################################################################################ # Make a list from a input line. Spaces are removed. ################################################################################ proc MakeList { str } { set list "" set strlist [split $str] foreach chars $strlist { if { $chars != "" } { lappend list $chars } } return $list } ################################################################################ # Eliminate unnecessary indices of list. ################################################################################ proc EliminateList { longlist } { set shortlist "" for { set i 1 } { $i <= 4 } { incr i } { set idx [lindex $longlist $i] lappend shortlist $idx } return $shortlist } ################################################################################ # Node set data format.(8 elements per line) ################################################################################ proc PutNset { lt list } { global f4 set i 1 foreach nset $list { if { $i == 0 } { puts $f4 [format "%10d" $nset] } else { puts -nonewline $f4 [format "%10d" $nset] } set i [expr ($i+1) % $lt] } puts $f4 "\n" } ################################################################################ # # Start main script. # ################################################################################ set f1 [ open [ file join $cwd "test.vrt" ] r ] ;# Node data file set f2 [ open [ file join $cwd "test.cel" ] r ] ;# Element data file set f3 [ open [ file join $cwd "test.bnd" ] r ] ;# Node set file # set fn [ file rootname $filename ] set f4 [ open [ file join $cwd "ansys.inp" ] w ] ;# Output file name set f5 [ open [ file join $cwd "temp.ele" ] w+ ] ;# Temporary file saved elements data puts $f4 "/PREP7" puts $f4 "SHPP,OFF\n" ################################################################################ # # Write nodes data to ANSYS input file. # ################################################################################ puts $f4 "NBLOCK,3" puts $f4 "(1i8,3e20.9e3)" while { [ eof $f1 ] != 1 } { set line [ gets $f1 ] if { "$line" == "" } { puts $f4 $line } else { set nnum [string trim [string range $line 0 14]] set xcoord [string trim [string range $line 15 30]] set ycoord [string trim [string range $line 31 46]] set zcoord [string trim [string range $line 47 62]] set nfmt [format "%8d%20.9e%20.9e%20.9e" \ $nnum $xcoord $ycoord $zcoord] puts $f4 $nfmt } } ################################################################################ # # Write elements data to ANSYS input file. # ################################################################################ set matTemp 0 while { [ eof $f2 ] != 1 } { set line [ gets $f2 ] if { "$line" == "" } { continue } else { set elist [MakeList $line] set elnum [lindex $elist 0] set mat [lindex $elist 9] set real $mat set type $mat set esys 0 if { $matTemp < $mat } { set matTemp $mat } for { set i 1 } { $i <= 8 } { incr i } { set e${i} [ lindex $elist $i ] } set efmt [format "%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d%8d" \ $elnum $type $real $mat $esys $e1 $e2 $e3 $e4 $e5 $e6 $e7 $e8] puts $f5 $efmt } } for { set i 1 } { $i <= $matTemp } { incr i} { puts $f4 "ET,$i,42" } puts $f4 "EBLOCK,8" puts $f4 "(13i8)" seek $f5 0 start set f5data [split [read $f5] \n] foreach eledata [lrange $f5data 0 end-1] { puts $f4 $eledata } puts $f4 "-1\n" ################################################################################ # # Define node set which name is pre-defined in Gridgen via BCs. # ################################################################################ set tmpname temp set limit 8 while { [ eof $f3 ] != 1 } { set line [ gets $f3 ] if {[ string match "*NONE*" $line ] || "$line" == ""} { continue } else { set alllist [MakeList $line] set nsetlist [EliminateList $alllist] set cmname [lrange $alllist 7 end] foreach nd $nsetlist { lappend conlist($cmname) $nd } } } foreach index [array names conlist] { set srtnset [lrange [lsort -integer -unique $conlist($index)] 1 end] set nsetfmt [format "%8d" [llength $srtnset]] puts $f4 "CMBLOCK,$index,NODE,$nsetfmt" puts $f4 "(8i10)" PutNset $limit $srtnset } ################################################################################ # # View, Element plot # ################################################################################ puts $f4 "/NUMBER,1" puts $f4 "/PNUM,MAT,1" puts $f4 "/VIEW ,1,1,1,1" puts $f4 "EPLOT" ################################################################################ # # Close all files and delete temporary files # ################################################################################ close $f1 close $f2 close $f3 close $f4 close $f5 file delete [ file join $cwd "test.cel" ] file delete [ file join $cwd "test.vrt" ] file delete [ file join $cwd "test.bnd" ] file delete [ file join $cwd "test.inp" ] file delete [ file join $cwd "temp.ele" ]