Newer
Older
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
import configparser as cp
import os
import h5py
def remove_comment(str, char = "#"):
split_str = str.split(char, 1)
return split_str[0]
# tag = 'simulation', 'experiment', 'output'
def read_h5file(tag = 'simulation'):
# read config ini
config = cp.ConfigParser()
config_path = os.path.join('tools/config.ini')
config.read(config_path)
path = config.get('directories', tag)
# read hdf5 output file
h5path = os.path.join(path)
return h5py.File(os.path.join(h5path, 'output.h5'), 'r')
# tag = 'simulation', 'experiment', 'output'
def read_params(file_name, tag = 'simulation'):
# read config ini
config = cp.ConfigParser()
config_path = os.path.join('tools/config.ini')
config.read(config_path)
path = config.get('directories', tag)
# read cfg parameter file
params = cp.ConfigParser()
params_path = os.path.join(path, file_name)
params.read(params_path)
#with open(params_path) as stream:
# params.read_string("[top]\n" + stream.read())
out = {
'L' : float(remove_comment(params.get('boundary.friction', 'L'))),
'V0' : float(remove_comment(params.get('boundary.friction', 'V0'))),
'mu0': float(remove_comment(params.get('boundary.friction', 'mu0'))),
'a' : float(remove_comment(params.get('boundary.friction.weakening', 'a'))),
'b' : float(remove_comment(params.get('boundary.friction.weakening', 'b'))),
'bodyCount' : int(remove_comment(params.get('problem', 'bodyCount'))),
'finalTime' : float(remove_comment(params.get('problem', 'finalTime'))),
'finalVelocity' : float(remove_comment(params.get('boundary.dirichlet', 'finalVelocity')))
}
return out