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-SyncIO requires now a field named "number of shape functions@partID" read from readnblk.f. 137 # Therefore, rename this field accordingly here 138 # Beware: in some version of NSpre, the historic spelling mistake "soved" has been replaced by "solved" 139 teststring1="number of shapefunctions soved on processor" 140 teststring2="number of shapefunctions solved on processor" 141 if [ "${field_fun:0:${#teststring1}}" == "$teststring1" ] || [ "${field_fun:0:${#teststring2}}" == "$teststring2" ]; then 142 echo "geombc, number of shape functions, integer, header, 1;" >> $file_integer_field_geombc_fun 143 echo "INFO: 'number of shapefunctions soved on processor' is renamed 'number of shape functions' for readnblk.f" 144 fi 145 146 # Trying to keep the order identical. 147 # For phParAdapt, after 'number of nodes in the mesh' (already treated above) comes usually 'connectivity interior'. 148 # But there is no such field generated with NSpre so we use instead "number of shapefunctions soved on processor" which is common to both. 149 # Moreover, in readnblk.f, the connectivity is read just after "number of shapefunctions soved on processor" so this ordering is coherent. 150 # 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. 151 #teststring="number of nodes in the mesh" 152 teststring1="number of shapefunctions soved on processor" 153 teststring2="number of shapefunctions solved on processor" 154 if [ "${field_fun:0:${#teststring1}}" == "$teststring1" ] || [ "${field_fun:0:${#teststring2}}" == "$teststring2" ]; then 155 156 echo "geombc, total number of interior tpblocks, integer, header, 1;" >> $file_integer_field_geombc_fun 157 echo "INFO: a new field called 'total number of interior tpblocks' will be added in the new geombc files" 158 159 while read line 160 do 161 field=`echo $line | awk '{$1="";$2="";$3="";print $0}'` 162 echo "geombc, connectivity interior $field, integer, block, 7;" | sed -e 's/ */ /g' >> $file_integer_field_geombc_fun # sed remove extra space 163 done < $list_interior_tpblocks_fun 164 fi 165 166 # Trying to keep the order identical. 167 # After 'number of nodes in the mesh' (already treated above) comes usually 'connectivity boundary' and 'nbc code' 168 # 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. 169 teststring="number of boundary tpblocks" 170 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 171 172 echo "geombc, total number of boundary tpblocks, integer, header, 1;" >> $file_integer_field_geombc_fun 173 echo "INFO: a new field called 'total number of boundary tpblocks' will be added in the new geombc files" 174 175 while read line 176 do 177 field=`echo $line | awk '{$1="";$2="";$3="";print $0}'` 178 179 echo "geombc, connectivity boundary $field, integer, block, 8;" | sed -e 's/ */ /g' >> $file_integer_field_geombc_fun # sed remove extra space 180 echo "geombc, nbc codes $field, integer, block, 8;" | sed -e 's/ */ /g' >> $file_integer_field_geombc_fun # sed remove extra space 181 done < $list_boundary_tpblocks_fun 182 fi 183} 184 185 186### Function check_field_restart 187function check_field_restart() { 188# All the critical fields that phasta needs in restart are listed below. Update this list if needed for your application. 189# The format is the following: restart, field name, double or integer, block or header, number of integer in the header after < >. 190 191 #field_fun="$@" # get all args 192 #field_fun=$(echo $argfun | awk '{print $1}') #Name of the field 193 #filefun=$1 194 file_double_field_restart_fun=$1 195 file_integer_field_restart_fun=$2 196 field_fun=$3 197 198 ### Double fields first (compulsary for the converter for now) 199 200 teststring="solution" 201 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 202 echo "restart, $field_fun, double, block, 3;" >> $file_double_field_restart_fun 203 fi 204 205 ### Integer fields next 206 207 teststring="byteorder magic number" 208 if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 209 echo "restart, $field_fun, integer, block, 1;" >> $file_integer_field_restart_fun 210 fi 211 212 #teststring="number of modes" # Already in the geombc files and read by phasta from the geombc files 213 #if [ "${field_fun:0:${#teststring}}" == "$teststring" ]; then #we compare the first letters of the string 214 # echo "restart, $field_fun, integer, header, 1;" >> $file_integer_field_restart_fun 215 #fi 216 217 #teststring="number of variables" # Was required for the converter. Info now read from the solution field 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} 223 224 225##################################################################### 226### End of functions - Beginning of the script 227##################################################################### 228 229 230### Check that user entered proper number of args 231if [ "${#}" -lt "$nargs" ] || [ "$1" == "-h" ]; then 232 die "\n Check usage: \n $0\n\n \$1: <time step>\n \$2: <number of parts>\n \$3: <number of SyncIO files>\n\n" 233fi 234 235 236### Read arguments of the script 237N_steps=$1 238N_parts=$2 239N_files=$3 240 241echo "Time step: $N_steps" 242echo "Number of parts: $N_parts" 243echo "Number of SyncIO files: $N_files" 244echo "" 245 246dir=$N_parts-procs_case 247 248 249### Do a couple of sanity check on the input parameters of the script 250if [ ! -d $dir ]; then 251 die "$N_parts-procs_case does not exist\n Aborting" 252fi 253 254if [ ! -e $dir/restart.$N_steps.1 ]; then 255 die "Time step $N_steps does not exist in $N_parts-procs_case\n Aborting" 256fi 257 258resmodulo=$(($N_parts % $N_files)) 259if [ "$resmodulo" -ne "0" ]; then 260 die "The number of SyncIO files requested $N_files is not a multiple of the number of parts $N_parts\n Aborting" 261fi 262 263 264### First, count the interior and boundary topology blocks 265list_interior_tpblocks=list_interior_tpblocks.dat 266grep -aH ' : < ' $dir/geombc.dat.* | grep 'connectivity interior' | awk -F : '{print $1,$2}' | awk '{$1=""; print $0}' | sort | uniq -c > $list_interior_tpblocks 267interior_tpblocks=`cat $list_interior_tpblocks | wc -l` 268echo "There are $interior_tpblocks different interior tp blocks in all the geombc files:" 269cat $list_interior_tpblocks 270echo "" 271 272list_boundary_tpblocks=list_boundary_tpblocks.dat 273grep -aH ' : < ' $dir/geombc.dat.* | grep 'connectivity boundary' | awk -F : '{print $1,$2}' | awk '{$1=""; print $0}' | sort | uniq -c > $list_boundary_tpblocks 274boundary_tpblocks=`cat $list_boundary_tpblocks | wc -l` 275echo "There are $boundary_tpblocks different boundary tp blocks in all the geombc files:" 276cat $list_boundary_tpblocks 277echo "" 278 279 280### Grep all the fields from geombc.dat.1 (posix file) 281file_grep_geombc=grep_geombc_posix.dat 282grep -a ' : < ' $dir/geombc.dat.1 > $file_grep_geombc 283 284 285### Get only the fields name from geombc.dat.1 and remove any extra unwanted space 286file_field_geombc=field_geombc_posix.dat 287cat $file_grep_geombc | awk -F : '{print $1}' | sed -e 's/ */ /g' | sed -e 's/^[ \t]*//g' | sed -e 's/[ \t]*$//g' > $file_field_geombc 288 289 290### 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 291file_double_field_geombc=file_double_field_geombc.dat 292if [ -e $file_double_field_geombc ]; then 293 rm $file_double_field_geombc 294fi 295 296file_integer_field_geombc=file_integer_field_geombc.dat 297if [ -e $file_integer_field_geombc ]; then 298 rm $file_integer_field_geombc 299fi 300 301while read line 302do 303 field=`echo $line` 304 check_field_geombc "$file_double_field_geombc" "$file_integer_field_geombc" "$field" "$list_interior_tpblocks" "$list_boundary_tpblocks" 305done < $file_field_geombc 306 307### Double check that the topologies have been correctly found 308interior_tpblocks2=`grep 'connectivity interior' $file_integer_field_geombc | wc -l` 309if [ "x$interior_tpblocks" != "x$interior_tpblocks2" ]; then 310 echo "" 311 echo "ERROR: Missing connectivity interior, probably due to a spelling issue ($interior_tpblocks2 != $interior_tpblocks)" 312 echo "ERROR: Check that \"number of shapefunctions soved on processor\" or \"number of shapefunctions solved on processor\"" 313 echo "ERROR: is present in your geombc files" 314 echo "" 315fi 316 317boundary_tpblocks2=`grep 'connectivity boundary' $file_integer_field_geombc | wc -l` 318if [ "x$boundary_tpblocks" != "x$boundary_tpblocks2" ]; then 319 echo "" 320 echo "ERROR: Missing connectivity boundary ($boundary_tpblocks2 != $boundary_tpblocks)" 321 echo "" 322fi 323 324### Grep all the fields from restart.##.1 (posix file) 325file_grep_restart=grep_restart_posix.dat 326grep -a ' : < ' $dir/restart.$N_steps.1 > $file_grep_restart 327 328 329### Get only the fields name from restart.##.1 and remove any extra unwanted space 330file_field_restart=field_restart_posix.dat 331cat $file_grep_restart | awk -F : '{print $1}' | sed -e 's/ */ /g' | sed -e 's/^[ \t]*//g' | sed -e 's/[ \t]*$//g' > $file_field_restart 332 333 334### 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 335file_double_field_restart=file_double_field_restart.dat 336if [ -e $file_double_field_restart ]; then 337 rm $file_double_field_restart 338fi 339 340file_integer_field_restart=file_integer_field_restart.dat 341if [ -e $file_integer_field_restart ]; then 342 rm $file_integer_field_restart 343fi 344 345while read line 346do 347 field=`echo $line` 348 check_field_restart "$file_double_field_restart" "$file_integer_field_restart" "$field" 349done < $file_field_restart 350 351echo "" 352 353 354### Start to write now IO.O2N.input 355file=IO.O2N.input 356if [ -e $file ]; then 357 rm $file 358fi 359 360N_geombc_fields_double=`cat $file_double_field_geombc | wc -l` 361N_geombc_fields_integer=`cat $file_integer_field_geombc | wc -l` 362N_restart_fields_double=`cat $file_double_field_restart | wc -l` 363N_restart_fields_integer=`cat $file_integer_field_restart | wc -l` 364 365echo "N-geombc-fields-double: $N_geombc_fields_double;" >> $file 366echo "N-geombc-fields-integer: $N_geombc_fields_integer;" >> $file 367echo "N-restart-fields-double: $N_restart_fields_double;" >> $file 368echo "N-restart-fields-integer: $N_restart_fields_integer;" >> $file 369echo "N-steps: $N_steps;" >> $file 370echo "N-parts: $N_parts;" >> $file 371echo "N-files: $N_files;" >> $file 372 373# The converter expects first the geombc double in IO.O2N.input, then geombc integer, then restart double, then restart integer. 374cat $file_double_field_geombc >> $file 375cat $file_integer_field_geombc >> $file 376cat $file_double_field_restart >> $file 377cat $file_integer_field_restart >> $file 378 379### Some cleaning 380rm $list_boundary_tpblocks 381rm $list_interior_tpblocks 382rm $file_grep_geombc 383rm $file_grep_restart 384rm $file_field_geombc 385rm $file_field_restart 386rm $file_double_field_geombc 387rm $file_integer_field_geombc 388rm $file_double_field_restart 389rm $file_integer_field_restart 390 391echo "$file generated for the converter" 392 393