-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_inputs.py
More file actions
executable file
·68 lines (59 loc) · 2.09 KB
/
generate_inputs.py
File metadata and controls
executable file
·68 lines (59 loc) · 2.09 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 28 11:32:15 2023
@author: giangle
"""
from SALib.sample import sobol
from numpy import log10
import numpy as np
unchanged_inputs = {
"w_elec": ([1.342],"cm"),
}
inputs = {
"L": ([20, 200],"um"),
"lambda": ([5, 40], "1"),
"phi_star": ([15.21, 30.42], "mV"),
"k": ([5, 25], "S/m"),
"kappa_1": ([1.0E-5, 1.0E-3], "1"),
"kappa_2": ([1.0E1, 1.0E3], "1"),
"theta": ([0.25, 5], "1"),
##############################################################
# If using COMSOL_model/iV_model.mph, comment out the lines #
# below, i.e. no gamma, beta, chi, omega_bar inputs #
#"gamma": ([7, 17], "1"),
"beta": ([0.75, 1], "1"),
"omega_bar": ([1.0E-4, 1.0E-2], "Hz"),
"chi": ([1.0E-2, 1.0E0], "1"),
##############################################################
}
#log adjustment
corrected_inputs = dict()
for k,v in inputs.items():
bounds, unit = v
if len(bounds) == 2:
if bounds[1]/bounds[0] >99:
corrected_inputs["log10_"+k] = ([log10(bounds[0]), log10(bounds[1])], unit)
else:
corrected_inputs[k] = (bounds, unit)
else:
assert("Bound list of parameter {} does not contain 2 elements".format(k))
# make a list of sobol sampling
problem = {
'num_vars' : len(corrected_inputs),
'names' : corrected_inputs.keys(),
'bounds' : [bounds for bounds, _ in corrected_inputs.values()]
}
# Generate samples
param_values = sobol.sample(problem, 2**9)
# Save inputs to text file
file_name = "./model_input/unchanged_inputs.txt"
with open(file_name, "w") as f:
f.write("\t".join(unchanged_inputs.keys())+"\n")
f.write("\t".join([unit for _, unit in unchanged_inputs.values()])+"\n")
f.write("\t".join([str(v[0]) for v, _ in unchanged_inputs.values()])+"\n")
file_name = "./model_input/inputs.txt"
with open(file_name, "w") as f:
f.write("\t".join(corrected_inputs.keys())+"\n")
f.write("\t".join([unit for _, unit in corrected_inputs.values()])+"\n")
np.savetxt(f, param_values, fmt="%.3g", delimiter="\t")