<commit_before>"""
qiba_ve_pml.py - setup SGE scripts to launch sims on the cluster

Viscoelastic digital phantoms for the QIBA industry comparison.

<NAME>
<EMAIL>
2015-06-28
"""

import os
from math import sqrt as sqrt
import re

"""
Measured values:
    E2297-AX c(200) = 2.06 dc/df = 3.08
    E2297-BX c(200) = 2.44 dc/df = 3.72
    E2297-CX c(200) = 2.87 dc/df = 5.11

Closest match VE 3-param and associated phase velocities and phase velocity slopes:
    G_0 = 10 kPa, G_infinity = 2 kPa, beta = 6666.7 Pa-s, c(200) = 1.91, dc/df = 3.05
    G_0 = 15 kPa, G_infinity = 4 kPa, beta = 5500.0 Pa-s, c(200) = 2.49, dc/df = 3.49
    G_0 = 20 kPa, G_infinity = 4 kPa, beta = 4000.0 Pa-s, c(200) = 2.91, dc/df = 5.55
"""

VE = [{'G0': 10, 'GI': 2, 'BETA': 6666.7},
      {'G0': 15, 'GI': 4, 'BETA': 5500.0},
      {'G0': 20, 'GI': 4, 'BETA': 4000.0}
      ]

YoungsModuli = [x['G0'] * 3.0 for x in VE]  # kPa
ExcitationDurations = [167, 334]  # us, 500 and 1000 cycles @ 3 MHz
FocalDepths = [30, 50, 70]  # mm
Fnums = [2.0, 3.5]

root = '/pisgah/mlp6/scratch/QIBA-DigitalPhantoms'
femgit = '/home/mlp6/projects/fem'
indynFile = 'qiba_ve_pml.dyn'
slurmFile = 'qiba_ve_pml.sh'

for n, YM in enumerate(YoungsModuli):
    for FD in FocalDepths:
        for ED in ExcitationDurations:
            for FN in Fnums:

                strToReplace = {
                    'YM': YM * 10000.0,
                    'G0': VE[n]['G0'],
                    'GI': VE[n]['GI'],
                    'BETA': VE[n]['BETA'],
                    'BULK': YM * 10000.0 / (3 * (1 - 2 * 0.499)),
                    'TOFF1': ED,
                    'TOFF2': ED + 1,
                    'TRUN': 25 / sqrt(YM / 3)
                }

                re_strToReplace = re.compile('|'.join(strToReplace.keys()))

                sim_path = '%s/data/G0%.1fkPa/GI%.1fkPa/BETA%.1f/foc%imm/F%.1f/EXCDUR_%ius/' % \
                           (root, VE[n]['G0'], VE[n]['GI'], VE[n]['BETA'], FD, FN, ED)

                if not os.path.exists(sim_path):
                    os.makedirs(sim_path)

                os.chdir(sim_path)
                print(os.getcwd())

                if not os.path.exists('res_sim.mat'):
                    print('\tres_sim.mat missing . . . running ls-dyna')

                    indyn = open(root + '/dyna/' + indynFile, 'r')
                    outdyn = open(indynFile, 'w')

                    for i in indyn:
                        outdyn.write(re_strToReplace.sub(lambda j: strToReplace[j.group(0)], i))

                    indyn.close()
                    outdyn.close()

                    os.system("ln -fs %s/field/PointLoads-f3.00-"
                              "F%.1f-FD0.0%i-a0.45.dyn loads.dyn" %
                              (root, FN, FD)
                              )
                    os.system("ln -fs %s/mesh/nodesFoc%imm.dyn nodes.dyn" %
                              (root, FD)
                              )
                    os.system("ln -fs %s/mesh/elemsFoc%imm_pml.dyn "
                              "elems_pml.dyn" % (root, FD)
                              )
                    os.system("ln -fs %s/mesh/bcPMLfoc%imm.dyn bc_pml.dyn" %
                              (root, FD)
                              )
                    os.system('cp %s/dyna/%s .' % (root, slurmFile))

                    os.system('sbatch %s' % slurmFile)
                else:
                    print('res_sim.mat already exists')
<commit_msg>limit float prec in string sub syntax<commit_after>"""
qiba_ve_pml.py - setup SGE scripts to launch sims on the cluster

Viscoelastic digital phantoms for the QIBA industry comparison.

<NAME>
<EMAIL>
2015-06-28
"""

import os
from math import sqrt as sqrt
import re

"""
Measured values:
    E2297-AX c(200) = 2.06 dc/df = 3.08
    E2297-BX c(200) = 2.44 dc/df = 3.72
    E2297-CX c(200) = 2.87 dc/df = 5.11

Closest match VE 3-param and associated phase velocities and phase velocity slopes:
    G_0 = 10 kPa, G_infinity = 2 kPa, beta = 6666.7 Pa-s, c(200) = 1.91, dc/df = 3.05
    G_0 = 15 kPa, G_infinity = 4 kPa, beta = 5500.0 Pa-s, c(200) = 2.49, dc/df = 3.49
    G_0 = 20 kPa, G_infinity = 4 kPa, beta = 4000.0 Pa-s, c(200) = 2.91, dc/df = 5.55
"""

VE = [{'G0': 10, 'GI': 2, 'BETA': 6666.7},
      {'G0': 15, 'GI': 4, 'BETA': 5500.0},
      {'G0': 20, 'GI': 4, 'BETA': 4000.0}
      ]

YoungsModuli = [x['G0'] * 3.0 for x in VE]  # kPa
ExcitationDurations = [167, 334]  # us, 500 and 1000 cycles @ 3 MHz
FocalDepths = [30, 50, 70]  # mm
Fnums = [2.0, 3.5]

root = '/pisgah/mlp6/scratch/QIBA-DigitalPhantoms'
femgit = '/home/mlp6/projects/fem'
indynFile = 'qiba_ve_pml.dyn'
slurmFile = 'qiba_ve_pml.sh'

for n, YM in enumerate(YoungsModuli):
    for FD in FocalDepths:
        for ED in ExcitationDurations:
            for FN in Fnums:

                strToReplace = {
                    'YM': '%.1f' % (YM * 10000.0),
                    'G0': '%.1f' % (VE[n]['G0']),
                    'GI': '%.1f' % (VE[n]['GI']),
                    'BETA': '%.1f' % (VE[n]['BETA']),
                    'BULK': '%.1f' % (YM * 10000.0 / (3 * (1 - 2 * 0.499))),
                    'TOFF1': '%.1f' % ED,
                    'TOFF2': '%.1f' % (ED + 1),
                    'TRUN': '%.1f' % (25 / sqrt(YM / 3))
                }

                re_strToReplace = re.compile('|'.join(strToReplace.keys()))

                sim_path = '%s/data/G0%.1fkPa/GI%.1fkPa/BETA%.1f/foc%imm/F%.1f/EXCDUR_%ius/' % \
                           (root, VE[n]['G0'], VE[n]['GI'], VE[n]['BETA'], FD, FN, ED)

                if not os.path.exists(sim_path):
                    os.makedirs(sim_path)

                os.chdir(sim_path)
                print(os.getcwd())

                if not os.path.exists('res_sim.mat'):
                    print('\tres_sim.mat missing . . . running ls-dyna')

                    indyn = open(root + '/dyna/' + indynFile, 'r')
                    outdyn = open(indynFile, 'w')

                    for i in indyn:
                        outdyn.write(re_strToReplace.sub(lambda j: strToReplace[j.group(0)], i))

                    indyn.close()
                    outdyn.close()

                    os.system("ln -fs %s/field/PointLoads-f3.00-"
                              "F%.1f-FD0.0%i-a0.45.dyn loads.dyn" %
                              (root, FN, FD)
                              )
                    os.system("ln -fs %s/mesh/nodesFoc%imm.dyn nodes.dyn" %
                              (root, FD)
                              )
                    os.system("ln -fs %s/mesh/elemsFoc%imm_pml.dyn "
                              "elems_pml.dyn" % (root, FD)
                              )
                    os.system("ln -fs %s/mesh/bcPMLfoc%imm.dyn bc_pml.dyn" %
                              (root, FD)
                              )
                    os.system('cp %s/dyna/%s .' % (root, slurmFile))

                    os.system('sbatch %s' % slurmFile)
                else:
                    print('res_sim.mat already exists')

{'fraction_non_alphanumeric': 0.1540210287013356, 'fraction_numerical': 0.05825518613242398, 'mean_word_length': 1.3597049949715052, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2714345', 'n_tokens_mistral': 2942, 'n_tokens_neox': 2527, 'n_words': 564}