To use this script you have to specify your Mach number range, your AoA range and number of processor on which you want to run your jobs.
You also need to set up your first case using GUI for starting mach number and starting AoA .
In your polar directory you should have following files:
cellsin.bin
exbcsin.bin
nodesin.bin
mcfd.bc
mcfd.inp
infout1f.inp
cfd_sub (Your job launching file based on your scheduler SGE , PBS etc.)
polar (Polar script copy and paste from below)
inputs.dat (Input for polar script)
inputs.dat file should be in following format:
MACH_LIST 0.12 0.5 1 1.17
ALPHA_LIST 0.2 2.3 3.9 6
NPROCS 128
polar file is as follows:
foreach fl {mcfd.inp inputs.dat infout1f.inp cellsin.bin exbcsin.bin nodesin.bin mcfd.bc cfd_sub} {
if {[file exists $fl] == 0} {
puts "$fl file does not exist. Can not continue. Aborting ...."
exit 0
}
}
set fui [open "inputs.dat" r]
set file_data [read $fui]
set data [split $file_data "\n"]
set mkey [lindex $data 0]
set ml [llength $mkey]
set akey [lindex $data 1]
set al [llength $akey]
set nprocs [lindex $data 2]
set NPROCS [lindex $nprocs 1]
close $fui
set Old_mach_dir [glob -nocomplain Mach_*]
foreach filename $Old_mach_dir {
if {[file exists $filename]} {
puts "Previous $filename directory found. Deleting it.\n"
file delete -force $filename
puts "Deleted previous $filename directory\n"
} else {
puts "No Previous $filename file found\n"
}
}
set Pres [exec cat mcfd.inp | grep -A2 primitive | cut -d " " -f2 | head -2 | tail -1]
set Temp [exec cat mcfd.inp | grep -A2 primitive | cut -d " " -f3 | head -2 | tail -1]
set Uin [exec cat mcfd.inp | grep -A2 primitive | cut -d " " -f4 | head -2 | tail -1]
set Vin [exec cat mcfd.inp | grep -A2 primitive | cut -d " " -f5 | head -2 | tail -1]
set Win [exec cat mcfd.inp | grep -A2 primitive | cut -d " " -f6 | head -2 | tail -1]
set Win [exec cat mcfd.inp | grep -A2 primitive | cut -d " " -f6 | head -2 | tail -1]
set U [expr {sqrt($Uin*$Uin+$Vin*$Vin+$Win*$Win)}]
set Alti [exec cat mcfd.inp | grep aero_altid | awk {{print $2}}]
exec sed -e {s/^.*aero_pres.*/aero_pres PRESS/} -e {s/^.*aero_temp.*/aero_temp TEMP/} -e {s/^.*aero_u.*/aero_u VELOX/} -e {s/^.*aero_v.*/aero_v VELOY/} -e {s/^.*aero_w.*/aero_w VELOZ/} -e {s/^.*aero_ma.*/aero_ma MACH/} -e {s/^.*aero_alpha.*/aero_alpha ALPHA/} -e s/$Pres/PRESS/g -e s/$Temp/TEMP/g -e s/$Uin\ $Vin\ $Win/VELOX\ VELOY\ VELOZ/g < mcfd.inp > mcfd.data
exec sed -e {s/^.*alpha.*/alpha ALPHA/} -e {s/^.*uref.*/uref UREF/} < infout1f.inp > infout1f.data
set Sound [exec /opt/METACOMP/CFD++10.1/mlib/mcfd.10.1/exec/atmosprp 0.0 kilometers | tr -s ' ' | grep Sound | tr -s ' ' | cut -d " " -f11]
set WDIR [exec pwd]
set jf [open "$WDIR/jobs.sh" w]
puts "\n"
puts "=========================================================="
puts "You have selected following inputs for your simulations =="
puts "=========================================================="
puts "\n"
puts [exec cat inputs.dat]
puts "\n"
puts "\033\[01;32mType y/n and press enter to continue/quit\n\033\[0m"
set input [gets stdin]
scan $input "%s" answer
if {$answer == "y"} {
puts "\nContinuing ...\n"
} elseif {$answer == "n"} {
puts "\nQuitting ...\n"
exit 0
} else {
puts "\nQuitting ...\n"
exit 0
}
if {[file exists mcpusin.bin.$NPROCS]} {
puts "\033\[01;32mmcpusin.bin.$NPROCS already exist. If you would like to use it press y otherwise press n\n\033\[0m"
set finput [gets stdin]
scan $finput "%s" fanswer
if {$fanswer == "y"} {
puts "\nPrevious mcpusin.bin.$NPROCS will be used\n"
} elseif {$fanswer == "n"} {
puts "\nCrating $NPROCS partitions\n"
exec /opt/METACOMP/CFD++10.1/mlib/mcfd.10.1/exec/tometis pmetis $NPROCS
}
} else {
puts "\nHICrating $NPROCS partitions\n"
exec /opt/METACOMP/CFD++10.1/mlib/mcfd.10.1/exec/tometis pmetis $NPROCS
}
puts "Creating directory structure\n"
for {set j 1} {$j<$ml} {incr j} {
set Mach [lindex $mkey $j]
set DIR Mach_$Mach
file mkdir $DIR
cd $DIR
for {set i 1} {$i<$al} {incr i} {
set Alpha [lindex $akey $i]
set Starting_Alpha [lindex $akey 1]
set DIR Alpha_$Alpha
file mkdir $DIR
cd $DIR
set CDIR [exec pwd]
set U [expr {$Mach*$Sound}]
set u [expr {$U*cos(($Alpha*3.14159)/180)}]
set v 0.0
set w [expr {$U*sin(($Alpha*3.14159)/180)}]
file copy ../../mcfd.data .
file copy ../../infout1f.data .
file copy ../../cfd_sub .
file link -symbolic cellsin.bin ../../cellsin.bin
file link -symbolic nodesin.bin ../../nodesin.bin
file link -symbolic exbcsin.bin ../../exbcsin.bin
file link -symbolic mcfd.bc ../../mcfd.bc
file link -symbolic mcpusin.bin.$NPROCS ../../mcpusin.bin.$NPROCS
puts "Creating mcfd.inp file for Mach=$Mach and Alpha=$Alpha\n"
exec sed -e s/PRESS/$Pres/ -e s/TEMP/$Temp/ -e s/VELOX/$u/ -e s/VELOY/$v/ -e s/VELOZ/$w/ -e s/MACH/$Mach/ -e s/ALPHA/$Alpha/ < mcfd.data > mcfd.inp
exec sed -e s/ALPHA/$Alpha/ -e s/UREF/$U/ < infout1f.data > infout1f.inp
file delete mcfd.data
file delete infout1f.data
if {$Alpha != $Starting_Alpha} {
exec sed -e s/mc_filecopy\ cdepsout.bin\ cdepsin.bin/mc_filecopy\ \.\.\\/Alpha_[lindex $akey [expr $i-1]]\\/cdepsout.bin\ cdepsin.bin/ -e s/istart\ 0/istart\ 1/ < mcfd.inp > mcfd.inp.new
file copy -force mcfd.inp.new mcfd.inp
file delete mcfd.inp.new
}
puts $jf "cd $CDIR"
puts $jf "./cfd_sub"
puts $jf "sleep 30s"
cd ..
}
cd ../
}
close $jf
#Deleting unused files
file delete mcfd_metis.graph
file delete mcfd.data
file delete infout1f.data
puts "Directory structure has been created and all required files are placed accordingly\n"
puts "A job file called jobs.sh has been created in your working directory\n"
puts "\033\[01;32mIf you want to fire your jobs press y otherwise press n\n\033\[0m"
set input_j [gets stdin]
scan $input_j "%s" answer
if {$answer == "y"} {
puts "\nContinuing ...\n"
exec sh jobs.sh
} elseif {$answer == "n"} {
exit 0
} else {
exit 0
}
Let me know if you need any explanation.
This is a preliminary script hence there is lot of scope to improve it.
So please post your comments.
To check the script with out installing CFD++ do following things:
Create following files in a directory using touch command:
touch cellsin.bin nodesin.bin exbcsin.bin mcfd.bc mcpusin.bin.128 cfd_sub
Download following files:
polar
inputs.dat
infout1f.inp
mcfd.inp
Now to generate the Mach and Alpha polar run polar script by ./polar
No comments:
Post a Comment