-
Notifications
You must be signed in to change notification settings - Fork 27
/
cooling_model.py
executable file
·46 lines (32 loc) · 1 KB
/
cooling_model.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
#!/usr/bin/env python3
import sys
import json
import numpy as np
# author: Jalal Lakhlili
# ... A test model: Cooling Coffee_Cup from Uncertainpy
# it is used by PCE and QMC tests
def model(time, T_0, kappa, T_env):
# For the ODE integration
from scipy.integrate import odeint
# The equation describing the model
def f(T, time, kappa, T_env):
return -kappa * (T - T_env)
# Solving the equation by intergration
temp = odeint(f, T_0, time, args=(kappa, T_env))[:, 0]
# The output temperature
return temp
# ...
if __name__ == '__main__':
json_input = sys.argv[1]
with open(json_input, "r") as f:
inputs = json.load(f)
kappa = float(inputs['kappa'])
t_env = float(inputs['t_env'])
temp0 = float(inputs['T0'])
t = np.linspace(0, 200, 150)
output_filename = inputs['out_file']
te = model(t, temp0, kappa, t_env)
# output csv file
np.savetxt(output_filename, te,
delimiter=",", comments='',
header='te')