-
Notifications
You must be signed in to change notification settings - Fork 0
/
quickstart.py
165 lines (153 loc) · 5.89 KB
/
quickstart.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python3
import numpy as np
from scipy import pi
import ctypes
import time
class gfunc(object):
def __init__(self, model='ils'):
self.model = model
# INFINITE LINE SOURCE MODEL
if model == 'ils':
self.lib = np.ctypeslib.load_library('libils.so', '.')
self.lib.calc_responsefcn.argtypes = [
ctypes.POINTER(ctypes.c_int),
np.ctypeslib.ndpointer(dtype=np.float64),
np.ctypeslib.ndpointer(dtype=np.float64)
]
self.lib.calc_responsefcn.restype = ctypes.c_void_p
# INFINITE CYLINDER SOURCE MODEL
if model == 'ics':
self.lib = np.ctypeslib.load_library('libics.so', '.')
self.lib.set_params.argtypes = [ ctypes.POINTER(ctypes.c_double) ]
self.lib.set_params.restype = ctypes.c_void_p
self.lib.calc_responsefcn.argtypes = [
ctypes.POINTER(ctypes.c_int),
np.ctypeslib.ndpointer(dtype=np.float64),
np.ctypeslib.ndpointer(dtype=np.float64)
]
self.lib.calc_responsefcn.restype = ctypes.c_void_p
# COMPOSITE-MEDIUM INFINITE LINE SOURCE MODEL
if model == 'cmils':
self.lib = np.ctypeslib.load_library('libcmils.so', '.')
self.lib.set_params.argtypes = [
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double)
]
self.lib.set_params.restype = ctypes.c_void_p
self.lib.calc_responsefcn.argtypes = [
ctypes.POINTER(ctypes.c_int),
np.ctypeslib.ndpointer(dtype=np.float64),
np.ctypeslib.ndpointer(dtype=np.float64)
]
self.lib.calc_responsefcn.restype = ctypes.c_void_p
def main():
r_b = 0.060 # (m)
r_po = 0.032 / 2 # (m)
D = 0.035 # (m)
RA = (D + r_po) / r_b
RB = (D - r_po) / r_b
RD = D / r_b
R = r_b / r_b
ks = 2.50 # (W m-1 K-1)
Cs = 3.0e+6 # (J m-3 K-1)
alpha_s = ks / Cs # (m2 s-1)
kb = 1.80
Cb = 3.8e+6
#kb = ks # (W m-1 K-1)
#Cb = Cs # (J m-3 K-1)
alpha_b = kb / Cb # (m2 s-1)
alpha = np.sqrt(alpha_b / alpha_s)
k = ks / kb
tmin = 60.0 # (s)
tmax = 60.0 * 60 * 24 * 365 * 10 # (s)
t = np.logspace(np.log10( tmin ), np.log10( tmax + 1 ), num=100, endpoint=True)
# ILS-------------------------------------------------
start = time.time()
Fo_ils = alpha_s * t / (r_b*r_b)
#Fo_ils = alpha_s * t / (D*D)
gfunc_ils = gfunc('ils')
f_ils = np.zeros_like(Fo_ils)
n = ctypes.byref(ctypes.c_int(Fo_ils.size))
gfunc_ils.lib.calc_responsefcn(n, Fo_ils, f_ils)
G_ils = 1 / (4 * pi * ks) * f_ils
print(f' ils: {time.time() - start}')
# ILS-------------------------------------------------
# ICS-------------------------------------------------
start = time.time()
Fo_ics = alpha_s * t / (r_b*r_b)
gfunc_ics = gfunc('ics')
gfunc_ics.lib.set_params( ctypes.byref(ctypes.c_double(R)) )
f_ics = np.zeros_like(Fo_ics)
n = ctypes.byref(ctypes.c_int(Fo_ics.size))
gfunc_ics.lib.calc_responsefcn(n, Fo_ics, f_ics)
G_ics = 1 / (pi*pi * ks) * f_ics
print(f' ics: {time.time() - start}')
# CMILS-------------------------------------------------
# CMILS-------------------------------------------------
start = time.time()
Fo_cmils = alpha_b * t / (r_b*r_b)
gfunc_cmils = gfunc('cmils')
gfunc_cmils.lib.set_params(
ctypes.byref(ctypes.c_double(RA)),
ctypes.byref(ctypes.c_double(RB)),
ctypes.byref(ctypes.c_double(RD)),
ctypes.byref(ctypes.c_double(alpha)),
ctypes.byref(ctypes.c_double(k))
)
# full
f_cmils = np.zeros_like(Fo_cmils)
n = ctypes.byref(ctypes.c_int(Fo_cmils.size))
gfunc_cmils.lib.calc_responsefcn(n, Fo_cmils, f_cmils)
G_cmils = 1 / (2 * pi * kb) * f_cmils
print(f'cmils: {time.time() - start}')
# CMILS-------------------------------------------------
# plot
import matplotlib.pyplot as plt
plt.rcParams['font.size'] = 10
plt.rcParams['font.family'] = 'serif'
plt.rcParams['mathtext.fontset'] = 'stix'
fig = plt.figure(figsize=(5,5), tight_layout=True)
ax = fig.add_subplot(1, 1, 1)
sc = ax.scatter(
t, G_ils,
facecolor = 'none',
edgecolor = 'black',
marker = 'o',
s = 20,
lw = 0.5,
label = 'ILS'
)
sc = ax.scatter(
t, G_ics,
color = 'black',
marker = '+',
s = 20,
lw = 0.5,
label = 'ICS'
)
sc = ax.scatter(
t, G_cmils,
facecolor = 'none',
edgecolor = 'black',
marker = '^',
s = 20,
lw = 0.5,
label = 'CM-ILS (at U-tube wall)'
)
ax.set_xlabel('time')
ax.set_ylabel('$G(t)$')
ax.set_xscale('log')
ax.set_title(
r'$k_\mathrm{s} = %.2f$ $k_\mathrm{b} = %.2f$' % (ks, kb),
fontsize=10
)
ax.set_xticks( [ 60, 60 * 60, 60 * 60 * 24, 60 * 60 * 24 * 365, 60 * 60 * 24 * 365 * 10 ] )
ax.set_xticklabels( ['1 min', '1 hour', '1 day', '1 year', '10 year'] )
ax.minorticks_off()
plt.legend(frameon=False)
plt.show()
if __name__ == '__main__':
main()