# # Copyright (c) 2004 Programmed by Jonghyuk Lee # 2006 Revised by Youngjin Seo # This Gridgen script is generated for ANSYS users. # It can be distributed and modified freely for personal use only. # ################################################################################ # Glyph script for transferring Grids & BCs from Gridgen to ANSYS. # # Restriction : # * To define BCs or VCs, you must select STAR-CD for analysis S/W. # These BCs are converted to COMPONENTs in ANSYS, named after BCs' name. # * One BC should have ONLY ONE CONNECTOR/FACE. # * Use VCs in Gridgen to define different material or element type. # 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 in the folder in which this script is executed. # ################################################################################ gg::tkLoad set title_font {helvetica 18 bold } set label_font {times 12 bold italic} ################################################################################ # Make Widget ################################################################################ proc makeWidget { } { global title_font label_font label .title -text "Grid2ANSYS" .title configure -font $title_font pack .title -fill x -side top frame .hr1 -relief sunken -height 2 -bd 1 pack .hr1 -side top -padx 2 -fill x -pady 1 label .msg -text "Attention! You have to select STAR-CD as an Analysis S/W" .msg configure -font $label_font pack .msg -fill x -side top frame .hr2 -relief sunken -height 2 -bd 1 pack .hr2 -side top -padx 2 -fill x -pady 1 frame .input pack .input -fill x -padx 100 label .input.type -text "Element Type No. :" entry .input.entry -textvariable etype -width 10 label .input.eg -text " (e.g. : PLANE42, SOLID45 ...)" pack .input.type -side left -padx 3 -pady 3 pack .input.eg -side right -padx 3 -pady 3 pack .input.entry -side right -padx 3 -pady 3 frame .hr3 -relief sunken -height 2 -bd 1 pack .hr3 -side top -padx 2 -fill x -pady 1 frame .button pack .button -fill x -padx 2 -pady 1 button .button.cancel -text "Cancel" -command exit button .button.ok -text "OK" -command main pack .button.cancel -side right -padx 2 pack .button.ok -side right -padx 2 bind . { main } } ################################################################################ proc main { } { if {[etypeCheck]} { exit } if {[blkCheck]} { exit } aswExport fileOpen writeNodes writeElements writeNodeSet plotElements fileClose exit } ################################################################################ # Element Type Checking ################################################################################ proc etypeCheck { } { global etype if {$etype == ""} { tk_messageBox -icon error -title "Error..." -message " No Element Type.\n\ Please input element type number which will be used in ANSYS." -type ok return 1 } return 0 } ################################################################################ # Block existance checking ################################################################################ proc blkCheck { } { set Blks [gg::blkGetAll] if {$Blks == ""} { tk_messageBox -icon error -title "Error..." -message " No Blocks.\n\ Please make blocks before proceeding." -type ok return 1 } return 0 } ################################################################################ # Grids & BCs Export ################################################################################ proc aswExport { } { global cwd gg::aswSet "STAR-CD" set cwd [file dirname [info script]] gg::aswExport [file join $cwd "asw-output00"] } ################################################################################ # Make elements list. Spaces are removed. ################################################################################ proc MakeList {str} { set list "" set strlist [split $str] foreach chars $strlist { if {$chars != ""} { lappend list $chars } else { continue } } return $list } ################################################################################ # Eliminate unnecessary lists. ################################################################################ proc EliminateList {longlist} { set shortlist "" for {set i 1} {$i <= 2} {incr i} { set idx [lindex $longlist $i] lappend shortlist $idx } return $shortlist } ################################################################################ # Nodes 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" } ################################################################################ # File Open ################################################################################ proc fileOpen { } { global cwd global f1 f2 f3 f4 f5 set f1 [open [file join $cwd "asw-output.vrt"] r] ;# Node data file set f2 [open [file join $cwd "asw-output.cel"] r] ;# Element data file set f3 [open [file join $cwd "asw-output.bnd"] r] ;# Node set file set f4 [open [file join $cwd "ansys.inp"] w] ;# Output file name set f5 [open [file join $cwd "temp.ele"] w+] ;# Temporary file reserving elements data puts $f4 "/PREP7" puts $f4 "SHPP,OFF\n" } ################################################################################ # Write nodes data to ANSYS input file. ################################################################################ proc writeNodes { } { global f1 f4 puts $f4 "NBLOCK,3" puts $f4 "(1i8,3e20.9)" 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. ################################################################################ proc writeElements { } { global etype global f2 f4 f5 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,$etype" } 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 nodes set whose name is pre-defined in Gridgen via BCs. ################################################################################ proc writeNodeSet { } { global f3 f4 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)] 0 end] set nsetfmt [format "%8d" [llength $srtnset]] puts $f4 "CMBLOCK,$index,NODE,$nsetfmt" puts $f4 "(8i10)" PutNset $limit $srtnset } } ################################################################################ # View, Element plot ################################################################################ proc plotElements { } { global f4 puts $f4 "/NUMBER,1" puts $f4 "/PNUM,MAT,1" puts $f4 "EPLOT" } ################################################################################ # Close all files and delete temporary files ################################################################################ proc fileClose { } { global cwd global f1 f2 f3 f4 f5 close $f1 close $f2 close $f3 close $f4 close $f5 file delete [file join $cwd "asw-output.cel"] file delete [file join $cwd "asw-output.vrt"] file delete [file join $cwd "asw-output.bnd"] file delete [file join $cwd "asw-output.inp"] file delete [file join $cwd "temp.ele"] } ################################################################################ makeWidget ::tk::PlaceWindow . widget gg::tkLoop