1#!/bin/bash 2 3nargs=3 # Arguments of the script: 4 # time step 5 # number parts 6 # number of syncio files wanted 7 8### Function die called when there is a problem 9function die() { 10 echo -e "${1}" 11 exit 1 12} 13 14 15### Function check_field_geombc 16function check_field_geombc() { 17# All the critical fields that phasta needs in geombc are listed below. Update this list if needed for your application. Do not forget to update N_geombc_fields_double etc below 18# The format is the following: geombc, field name, double or integer, block or header, number of integer in the header after < >. 19 20 #field_fun="$@" # get all args 21 #field_fun=$(echo $argfun | awk '{print $1}') #Name of the field 22 #filefun=$1 23 file_double_field_geombc_fun=$1 24 file_integer_field_geombc_fun=$2 25 field_fun=$3 26 list_interior_tpblocks_fun=$4 27 list_boundary_tpblocks_fun=$5 28 29 ### Double fields first (compulsary for the converter for now) 30 31 teststring="co-ordinates" 32 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 33 echo "geombc, $field_fun, double, block, 2;" >> $file_double_field_geombc_fun 34 fi 35 36 teststring="boundary condition array" 37 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 38 echo "geombc, $field_fun, double, block, 1;" >> $file_double_field_geombc_fun 39 fi 40 41 # Trying to keep the order identical. 42 # After 'boundary condition array' (already treated above) comes usually 'nbc values', which is the last double field 43 teststring="boundary condition array" 44 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 45 while read line 46 do 47 field=`echo $line | awk '{$1="";$2="";$3="";print $0}'` 48 49 echo "geombc, nbc values $field, double, block, 8;" | sed -e 's/ */ /g' >> $file_double_field_geombc_fun # sed remove extra space 50 done < $list_boundary_tpblocks_fun 51 fi 52 53 ### Integer fields next 54 55 teststring="number of interior tpblocks" 56 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 57 echo "geombc, $field_fun, integer, header, 1;" >> $file_integer_field_geombc_fun 58 fi 59 60 # This will include all the interior topologies 61 #teststring="connectivity interior" 62 #if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 63 # echo "geombc, "$field_fun", integer, block, 7;" >> $file_integer_field_geombc_fun 64 #fi 65 66 teststring="number of interior elements" 67 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 68 echo "geombc, "$field_fun", integer, header, 1;" >> $file_integer_field_geombc_fun 69 fi 70 71 # This will include 72 # "number of nodes in the mesh", 73 # "number of nodes" 74 # "number of nodes with Dirichlet BCs" 75 teststring="number of nodes" 76 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 77 echo "geombc, "$field_fun", integer, header, 1;" >> $file_integer_field_geombc_fun 78 fi 79 80 teststring="maximum number of element nodes" 81 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 82 echo "geombc, "$field_fun", integer, header, 1;" >> $file_integer_field_geombc_fun 83 fi 84 85 teststring="number of modes" 86 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 87 echo "geombc, "$field_fun", integer, header, 1;" >> $file_integer_field_geombc_fun 88 fi 89 90 teststring="bc mapping array" 91 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 92 echo "geombc, "$field_fun", integer, block, 1;" >> $file_integer_field_geombc_fun 93 fi 94 95 teststring="bc codes array" 96 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 97 echo "geombc, "$field_fun", integer, block, 1;" >> $file_integer_field_geombc_fun 98 fi 99 100 teststring="number of boundary tpblocks" 101 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 102 echo "geombc, "$field_fun", integer, header, 1;" >> $file_integer_field_geombc_fun 103 fi 104 105 #teststring="connectivity boundary" 106 #if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 107 # echo "geombc, "$field_fun", integer, block, 8;" >> $file_integer_field_geombc_fun 108 #fi 109 110 #teststring="nbc codes" 111 #if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 112 # echo "geombc, "$field_fun", integer, block, 8;" >> $file_integer_field_geombc_fun 113 #fi 114 115 teststring="number of boundary elements" 116 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 117 echo "geombc, "$field_fun", integer, header, 1;" >> $file_integer_field_geombc_fun 118 fi 119 120 teststring="size of ilwork array" 121 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 122 echo "geombc, "$field_fun", integer, header, 1;" >> $file_integer_field_geombc_fun 123 fi 124 125 teststring="ilwork" 126 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 127 echo "geombc, "$field_fun", integer, block, 1;" >> $file_integer_field_geombc_fun 128 fi 129 130 teststring="periodic masters array" 131 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 132 echo "geombc, "$field_fun", integer, block, 1;" >> $file_integer_field_geombc_fun 133 fi 134 135 # NSpre and others produces a field named "number of shapefunctions soved on processor" 136 # Phasta now tries to read "number of shape functions@partID" in readnblk.f so reflect that change here 137 # The converter will be able to still find "number of shapefunctions soved on processor" in the old geombc.dat 138 # when looking for "number of shape functions". But phasta-SyncIO needs "number of shape functions" 139 teststring="number of shapefunctions soved on processor" 140 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 141 echo "geombc, number of shape functions, integer, header, 1;" >> $file_integer_field_geombc_fun 142 echo "WARNING: 'number of shapefunctions soved on processor' is renamed 'number of shape functions' for readnblk.f" 143 fi 144 # This is in case the name in NSpre or phParAdapt fixes the name of the field 'number of shapefunctions soved on processor' 145 teststring="number of shape functions" 146 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 147 echo "WARNING: Has 'number of shapefunctions soved on processor' be renamed in 'number of shape functions' in gembc.dat.## ?" 148 echo "Make sure phasta-SyncIO will be able to read it, as the '?' is not effective any more with the new SyncIO format (names are unique because of partID!)" 149 echo "geombc, "$field_fun", integer, block, 1;" >> $file_integer_field_geombc_fun 150 fi 151 152 # Trying to keep the order identical. 153 # For phParAdapt, after 'number of nodes in the mesh' (already treated above) comes usually 'connectivity interior'. 154 # But there is no such field generated with NSpre so let us use "number of shapefunctions soved on processor" which is common to both. 155 # Moreover, in readnblk.f, the connectivity is read just after "number of shapefunctions soved on processor" so makes sense. 156 # NOTE that we also add a new field called 'total number of interior tpblocks'. This field will be saved in the new syncIO geombc files. 157 #teststring="number of nodes in the mesh" 158 teststring="number of shapefunctions soved on processor" 159 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 160 161 echo "geombc, total number of interior tpblocks, integer, header, 1;" >> $file_integer_field_geombc_fun 162 echo "WARNING: a new field called 'total number of interior tpblocks' will be added in the new geombc files" 163 164 while read line 165 do 166 field=`echo $line | awk '{$1="";$2="";$3="";print $0}'` 167 echo "geombc, connectivity interior $field, integer, block, 7;" | sed -e 's/ */ /g' >> $file_integer_field_geombc_fun # sed remove extra space 168 done < $list_interior_tpblocks_fun 169 fi 170 171 # Trying to keep the order identical. 172 # After 'number of nodes in the mesh' (already treated above) comes usually 'connectivity boundary' and 'nbc code' 173 # NOTE that we also add a new field called 'total number of boundary tpblocks'. This field will be saved in the new syncIO geombc files. 174 teststring="number of boundary tpblocks" 175 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 176 177 echo "geombc, total number of boundary tpblocks, integer, header, 1;" >> $file_integer_field_geombc_fun 178 echo "WARNING: a new field called 'total number of boundary tpblocks' will be added in the new geombc files" 179 180 while read line 181 do 182 field=`echo $line | awk '{$1="";$2="";$3="";print $0}'` 183 184 echo "geombc, connectivity boundary $field, integer, block, 8;" | sed -e 's/ */ /g' >> $file_integer_field_geombc_fun # sed remove extra space 185 echo "geombc, nbc codes $field, integer, block, 8;" | sed -e 's/ */ /g' >> $file_integer_field_geombc_fun # sed remove extra space 186 done < $list_boundary_tpblocks_fun 187 fi 188} 189 190 191### Function check_field_restart 192function check_field_restart() { 193# All the critical fields that phasta needs in restart are listed below. Update this list if needed for your application. 194# The format is the following: restart, field name, double or integer, block or header, number of integer in the header after < >. 195 196 #field_fun="$@" # get all args 197 #field_fun=$(echo $argfun | awk '{print $1}') #Name of the field 198 #filefun=$1 199 file_double_field_restart_fun=$1 200 file_integer_field_restart_fun=$2 201 field_fun=$3 202 203 ### Double fields first (compulsary for the converter for now) 204 205 teststring="solution" 206 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 207 echo "restart, $field_fun, double, block, 3;" >> $file_double_field_restart_fun 208 fi 209 210 ### Integer fields next 211 212 teststring="byteorder magic number" 213 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 214 echo "restart, $field_fun, integer, block, 1;" >> $file_integer_field_restart_fun 215 fi 216 217 #teststring="number of modes" # Already in the geombc files and read by phasta from the geombc files 218 #if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 219 # echo "restart, $field_fun, integer, header, 1;" >> $file_integer_field_restart_fun 220 #fi 221 222 #teststring="number of variables" # Was required for the converter. Info now read from the solution field 223 #if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 224 # echo "restart, $field_fun, integer, header, 1;" >> $file_integer_field_restart_fun 225 #fi 226 227} 228 229 230##################################################################### 231### End of functions - Beginning of the script 232##################################################################### 233 234 235### Check that user entered proper number of args 236if [ "${#}" -lt "$nargs" ] || [ "$1" == "-h" ]; then 237 die "\n Check usage: \n $0\n\n \$1: <time step>\n \$2: <number of parts>\n \$3: <number of SyncIO files>\n\n" 238fi 239 240 241### Read arguments of the script 242N_steps=$1 243N_parts=$2 244N_files=$3 245 246echo "Time step: $N_steps" 247echo "Number of parts: $N_parts" 248echo "Number of SyncIO files: $N_files" 249echo "" 250 251dir=$N_parts-procs_case 252 253 254### Do a couple of sanity check on the input parameters of the script 255if [ ! -d $dir ]; then 256 die "$N_parts-procs_case does not exist\n Aborting" 257fi 258 259if [ ! -e $dir/restart.$N_steps.1 ]; then 260 die "Time step $N_steps does not exist in $N_parts-procs_case\n Aborting" 261fi 262 263resmodulo=$(($N_parts % $N_files)) 264if [ "$resmodulo" -ne "0" ]; then 265 die "The number of SyncIO files requested $N_files is not a multiple of the number of parts $N_parts\n Aborting" 266fi 267 268 269### First, count the interior and boundary topology blocks 270list_interior_tpblocks=list_interior_tpblocks.dat 271grep -aH ' : < ' $dir/geombc.dat.* | grep 'connectivity interior' | awk -F : '{print $1,$2}' | awk '{$1=""; print $0}' | sort | uniq -c > $list_interior_tpblocks 272interior_tpblocks=`cat $list_interior_tpblocks | wc -l` 273echo "There are $interior_tpblocks different interior tp blocks in all the geombc files:" 274cat $list_interior_tpblocks 275echo "" 276 277list_boundary_tpblocks=list_boundary_tpblocks.dat 278grep -aH ' : < ' $dir/geombc.dat.* | grep 'connectivity boundary' | awk -F : '{print $1,$2}' | awk '{$1=""; print $0}' | sort | uniq -c > $list_boundary_tpblocks 279boundary_tpblocks=`cat $list_boundary_tpblocks | wc -l` 280echo "There are $boundary_tpblocks different boundary tp blocks in all the geombc files:" 281cat $list_boundary_tpblocks 282echo "" 283 284 285### Grep all the fields from geombc.dat.1 (posix file) 286file_grep_geombc=grep_geombc_posix.dat 287grep -a ' : < ' $dir/geombc.dat.1 > $file_grep_geombc 288 289 290### Get only the fields name from geombc.dat.1 and remove any extra unwanted space 291file_field_geombc=field_geombc_posix.dat 292cat $file_grep_geombc | awk -F : '{print $1}' | sed -e 's/ */ /g' | sed -e 's/^[ \t]*//g' | sed -e 's/[ \t]*$//g' > $file_field_geombc 293 294 295### Now check which fields are critical for phasta and save the double fields in $file_double_field_geombc and the integer fields in $file_integer_field_geombc for future use 296file_double_field_geombc=file_double_field_geombc.dat 297if [ -e $file_double_field_geombc ]; then 298 rm $file_double_field_geombc 299fi 300 301file_integer_field_geombc=file_integer_field_geombc.dat 302if [ -e $file_integer_field_geombc ]; then 303 rm $file_integer_field_geombc 304fi 305 306while read line 307do 308 field=`echo $line` 309 check_field_geombc "$file_double_field_geombc" "$file_integer_field_geombc" "$field" "$list_interior_tpblocks" "$list_boundary_tpblocks" 310done < $file_field_geombc 311 312 313### Grep all the fields from restart.##.1 (posix file) 314file_grep_restart=grep_restart_posix.dat 315grep -a ' : < ' $dir/restart.$N_steps.1 > $file_grep_restart 316 317 318### Get only the fields name from restart.##.1 and remove any extra unwanted space 319file_field_restart=field_restart_posix.dat 320cat $file_grep_restart | awk -F : '{print $1}' | sed -e 's/ */ /g' | sed -e 's/^[ \t]*//g' | sed -e 's/[ \t]*$//g' > $file_field_restart 321 322 323### Now check which fields are critical for phasta and save the double fields in $file_double_field_geombc and the integer fields in $file_integer_field_geombc for future use 324file_double_field_restart=file_double_field_restart.dat 325if [ -e $file_double_field_restart ]; then 326 rm $file_double_field_restart 327fi 328 329file_integer_field_restart=file_integer_field_restart.dat 330if [ -e $file_integer_field_restart ]; then 331 rm $file_integer_field_restart 332fi 333 334while read line 335do 336 field=`echo $line` 337 check_field_restart "$file_double_field_restart" "$file_integer_field_restart" "$field" 338done < $file_field_restart 339 340echo "" 341 342 343### Start to write now IO.O2N.input 344file=IO.O2N.input 345if [ -e $file ]; then 346 rm $file 347fi 348 349N_geombc_fields_double=`cat $file_double_field_geombc | wc -l` 350N_geombc_fields_integer=`cat $file_integer_field_geombc | wc -l` 351N_restart_fields_double=`cat $file_double_field_restart | wc -l` 352N_restart_fields_integer=`cat $file_integer_field_restart | wc -l` 353 354echo "N-geombc-fields-double: $N_geombc_fields_double;" >> $file 355echo "N-geombc-fields-integer: $N_geombc_fields_integer;" >> $file 356echo "N-restart-fields-double: $N_restart_fields_double;" >> $file 357echo "N-restart-fields-integer: $N_restart_fields_integer;" >> $file 358echo "N-steps: $N_steps;" >> $file 359echo "N-parts: $N_parts;" >> $file 360echo "N-files: $N_files;" >> $file 361 362# The converter expects first the geombc double in IO.O2N.input, then geombc integer, then restart double, then restart integer. 363cat $file_double_field_geombc >> $file 364cat $file_integer_field_geombc >> $file 365cat $file_double_field_restart >> $file 366cat $file_integer_field_restart >> $file 367 368### Some cleaning 369rm $list_boundary_tpblocks 370rm $list_interior_tpblocks 371rm $file_grep_geombc 372rm $file_grep_restart 373rm $file_field_geombc 374rm $file_field_restart 375rm $file_double_field_geombc 376rm $file_integer_field_geombc 377rm $file_double_field_restart 378rm $file_integer_field_restart 379 380echo "$file generated for the converter" 381 382