-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.py
268 lines (210 loc) · 8.33 KB
/
errors.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
import numpy as np
import scipy
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.patches import FancyArrowPatch
from mpl_toolkits.mplot3d import proj3d
from ipywidgets import *
from matplotlib.widgets import Slider
from matplotlib.widgets import Slider
# Parameters for a water droplet in air at standard laboratory conditions
gamma = 0.0728 # N/m, surface tension of water at 20 deg C
rho = 1000 # kg/m3, density
g = 9.81 # m/s2
from ddgclib import *
from ddgclib._complex import *
from ddgclib._curvatures import * # plot_surface#, curvature
from ddgclib._capillary_rise_flow import * #plot_surface#, curvature
from ddgclib._eos import *
from ddgclib._misc import *
from ddgclib._plotting import *
# Colour scheme for surfaces
db = np.array([129, 160, 189]) / 255 # Dark blue
lb = np.array([176, 206, 234]) / 255 # Light blue
cdist = 1e-12
# Replot error data
Nmax = 21
#lp_error = np.zeros(Nmax - 3)
Nlist = list((range(3, Nmax)))
Nlist = list((range(4, Nmax)))
erange = []
lp_error = []
Nmax = 21
refinement = 1
phi = 2
r = 1 # m, Radius of the capillary tube
r = 0.5e-3 # m, Radius of the capillary tube
theta_p = 20 * np.pi / 180.0 # Three phase contact angle (breaks?!?!)
theta_p = 21 * np.pi / 180.0 # Three phase contact angle
theta_p = 25.0 * np.pi / 180.0 # Three phase contact angle
theta_p = 19.0 * np.pi / 180.0 # Three phase contact angle
theta_p = 20.001 * np.pi / 180.0 # Three phase contact angle
R = r / np.cos(theta_p) # = R at theta = 0
N = 8
fig, axes, HC = cape_rise_plot(r, theta_p, gamma, N=N, refinement=refinement)
axes.grid(False)
axes.set_xticks([])
axes.set_yticks([])
axes.set_zticks([])
plt.axis('off')
N = 5
fig, axes, HC = cape_rise_plot(r, theta_p, gamma, N=N, refinement=refinement)
axes.grid(False)
axes.set_xticks([])
axes.set_yticks([])
axes.set_zticks([])
plt.axis('off')
#for N in range(4, Nmax + 1):
for N in range(5, Nmax + 1):
F, nn, HC, bV, K_f, H_f = cap_rise_init_N(r, theta_p, gamma, N=N,
refinement=refinement,
cdist=cdist
)
HC.V.merge_all(cdist=cdist)
if 0:
fig, axes, fig_s, axes_s = HC.plot_complex()
axes.set_zlim(-r, 0.0)
axes.set_zlim(-2*r, 2*r)
if 0:
fig, axes, HC = cape_rise_plot(r, theta_p, gamma, N=N, refinement=0)
(HNda_v_cache, K_H_cache, C_ijk_v_cache, HN_i, HNdA_ij_dot_hnda_i,
K_H_2, HNdA_i_Cij) = int_curvatures(HC, bV, r, theta_p, printout=0)
# Laplacian error
P_L = gamma*(2.0/R) # Analytical solution
print(f'P_L = {P_L}')
print(f'HNdA_ij_dot_hnda_i = {HNdA_ij_dot_hnda_i}')
H_dis = HNdA_ij_dot_hnda_i[0]
L_error = 100 *(P_L - gamma * H_dis)/(P_L)
lp_error.append(abs(L_error))
if 0:
plt.figure()
yr = K_H_2 - K_f
xr = list(range(len(yr)))
plt.plot(xr, yr, label='K_H_2 - K_f')
yr = HNdA_ij_dot_hnda_i - H_f
print(f'yr = {yr}')
plt.plot(xr, yr, label='HNdA_ij_dot_hnda_i - H_f')
plt.ylabel('Difference')
plt.xlabel('Vertex No.')
plt.legend()
max_int_e = 0.0
ern = 0.0
for v in bV:
#for v in HC.V:
for v2 in v.nn:
if v2 in bV:
a = v.x_a
b = v2.x_a
print(f'numpy.linalg.norm(a - b) = {numpy.linalg.norm(a - b)}')
#if N == 14:
# print(f'numpy.linalg.norm(a - b) = {numpy.linalg.norm(a - b)}')
# continue
ern = 0.5 * numpy.linalg.norm(a - b) ** 2 / (12 * (2)**2)
max_int_e += ern
#break
#ern = 2*numpy.linalg.norm(a - b)
#ern = 0.5 * numpy.linalg.norm(a - b) **2
#ern += 0.5 * numpy.linalg.norm(a - b) **2
#max_int_e += ern
#break
#erange.append( max_int_e/r )
print(f'len(bV) = {len(bV) }')
erange.append( (max_int_e/r)/len(bV) )
# erange.append( max_int_e/r )
print(f'erange = {erange}')
erange
# Computed from step size on Euclidean metric for cap rise:
geo_error = erange
plot.figure()
# plt.plot(N, lp_error, 'x', label='$\Delta p \frac{\Delta p - \Delta p}{\Delta p}$')
if 0:
plt.plot(Nlist, lp_error, 'x')
plt.plot(Nlist, lp_error, 'x', label='Young-Laplace error: $(\Delta p - \Delta\hat{ p})/\Delta p $')
plt.plot(Nlist, geo_error, 'X', label='Integration error (Trapezoidal rule $O(h^3)$)')
plt.legend()
plt.xlabel(r'N (number of boundary vertices)')
plt.ylabel(r'Error (%)')
if 0:
plt.semilogy(Nlist, lp_error, 'x')
plt.semilogy(Nlist, lp_error, 'x', label='Young-Laplace error: $(\Delta p - \Delta\hat{ p})/\Delta p $')
plt.semilogy(Nlist, geo_error, 'X', label='Integration error (Trapezoidal rule $O(h^3)$)')#
# 2021.09.28
if 0:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax2 = ax.twinx()
ln1 = ax2.semilogy(Nlist, np.abs(lp_error), 'x', color='tab:blue',
label='Young-Laplace error: $(F_{cap} - \hat{F_{cap}}) / F_{cap} $')
ax2.set_ylabel(r'Young-Laplace error (%)')
ax.set_xlabel(r'N (number of boundary vertices)')
ln2 = ax.semilogy(Nlist, geo_error, 'X', color='tab:orange',
label='Integration error (p-normed trapezoidal rule $O(h^3)$)')
ax.set_ylabel(r'Integration error (%)')
ax2.set_ylim([1e-15, 1e-13])
ax.set_ylim([10e-3, 1])
ax.set_ylim([10e-3, 1])
lns = ln1 + ln2
labs = [l.get_label() for l in lns]
ax.legend(lns, labs, loc=0)
plt.tick_params(axis='y', which='minor')
if 1:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax2 = ax.twinx()
print(f'lp_error = {lp_error}')
ln1 = ax2.loglog(Nlist, np.abs(lp_error), 'x', color='tab:blue',
label='Young-Laplace error: $(F_{cap} - \hat{F_{cap}}) / F_{cap} $')
ax2.set_ylabel(r'Young-Laplace error (%)')
ax.set_xlabel(r'$n$ (number of boundary vertices)')
eps = (geo_error[-1] - geo_error[0])/(Nlist[-1] - Nlist[0])
print(f' eps = {eps**(-1)}')
ln2 = ax.loglog(Nlist, geo_error, 'X', color='tab:orange',
label=f'Integration error (p-normed trapezoidal rule $O(h^2)$)')
#f', $\varepsilon$ = {eps}')
ax.set_ylabel(f'Integration error (%)')
x, y = Nlist, geo_error
x, y = np.float32(x), np.float32(y)
z = numpy.polyfit(x, y, 1)
z = np.polyfit(np.log10(x), np.log10(y), 1)
p = numpy.poly1d(z)
#ax.loglog(x, 10 **p(x), "r--")
p = np.poly1d(z)
# the line equation:
print("y=%.6fx+(%.6f)" % (z[0], z[1]))
#ax2.set_ylim([1e-15, 1e-13])
ax2.set_ylim([1e-15, 1e-12])
# ax.set_ylim([10e-3, 1])
# ax.set_ylim([10e-3, 1])
lns = ln1 + ln2
labs = [l.get_label() for l in lns]
ax.legend(lns, labs, loc=0)
plt.tick_params(axis='y', which='minor')
if 1:
from matplotlib import pyplot as plt, ticker as mticker
ax.xaxis.set_minor_formatter(mticker.ScalarFormatter())
ax2.xaxis.set_minor_formatter(mticker.ScalarFormatter())
# ax.xaxis.get_major_formatter().set_scientific(False)
# ax2.xaxis.get_major_formatter().set_scientific(False)
# ax.ticklabel_format(style='plain', axis='x')
# ax2.ticklabel_format(style='plain', axis='x')
import matplotlib
#matplotlib.pyplot.xticks(Nlist)
#print(help(matplotlib.pyplot.xticks))
plt.tick_params(axis='y', which='minor')
if 0:
plot.figure()
fig, ax1 = plt.subplots()
color = 'tab:orange'
ax1.set_ylabel('Young-Laplace error: $\Delta p - \Delta\hat{ p} $', color=color) # we already handled the x-label with ax1
#ax1.semilogy(Nlist, lp_error, 'x', color=color)
ax1.plot(Nlist, lp_error, 'x', color=color)
ax1.tick_params(axis='y', labelcolor=color)
color = 'tab:red'
ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis
ax2.set_xlabel(r'N (number of boundary vertices)')
ax2.set_ylabel('Integration error (Trapezoidal rule $O(h^3)$)', color=color)
ax2.plot(Nlist, geo_error, 'x', color=color)
ax2.tick_params(axis='y', labelcolor=color)
matplotlib.pyplot.xticks(Nlist)
plt.ylabel(r'Error (%)')
plt.show()