-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleaner.py
70 lines (57 loc) · 2.01 KB
/
cleaner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
""" small script to remove Pimpact-files """
import os
import xml.etree.ElementTree as ET
import numpy as np
FIELDS = ['S', 'X', 'Y', 'Z']
def remove_until(i=0, path='./', nf=0):
""" removes restart files to certain iteration """
if i<99:
for j in range(1, i):
for ftype in FIELDS:
for f in range(2*nf+1):
if ftype == 'S':
key = 'pre'
else:
key = 'vel'+ftype
fname = key+'_restart'+str(j*100+f).zfill(5)+'.h5'
print('rm '+fname+'\t', end='')
try:
os.remove(path+fname)
print('check')
except OSError:
print('fail')
else:
print('Are you sure? i>=100')
def remove_auto(path='./'):
""" reads refine and then cleans """
refine = np.loadtxt('refinementTest.txt')
i = int(refine[-1, 0])
nf = int(refine[-1, 1])
remove_until(i=i, path=path, nf=nf)
def update(fname='parameterOut.xml', tol=1.e-6):
""" reads refine and changer parameter accordingly """
refine = np.loadtxt('refinementTest.txt')
nf = int(refine[-1, 1])
nf_inc = int(refine[-1, 4])
nf_new = nf + nf_inc
tol = 1.0e-6*float(2*nf_new+1)
print( 'nf: ', nf)
print( 'nf_inc: ', nf_inc)
print( 'tol: ', tol)
tree = ET.parse(fname)
root = tree.getroot()
# setting nf and npf
for child in root.iter('Parameter'):
if child.attrib['name'] == 'nf':
child.attrib['value'] = str(nf_new)
if child.attrib['name'] == 'npf':
child.attrib['value'] = str(nf_new)
# setting NormF
for child in root.iter('ParameterList'):
if child.attrib['name'] == 'Test 0':
for cchild in child.iter('Parameter'):
if cchild.attrib['name'] == 'Tolerance':
cchild.attrib['value'] = str(tol)
tree.write(fname)
if __name__ == "__main__":
print('hello')