Skip to content

Commit d94d581

Browse files
committed
Novelty
1 parent 5f57f8f commit d94d581

File tree

3 files changed

+52
-22
lines changed

3 files changed

+52
-22
lines changed

sumpy/recurrence_qbx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def generate_true(i):
233233
###############
234234

235235
#slope of line y = mx
236-
m = 15000 * 1e3
236+
m = 1e5/2
237237
mask_on_axis = m*np.abs(coord[0]) >= np.abs(coord[1])
238238
mask_off_axis = m*np.abs(coord[0]) < np.abs(coord[1])
239239

test/test_recurrence.py

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,22 @@ def test_helmholtz_2d_off_axis(deriv_order, exp_order):
273273
print("RATIO(x0/x1): ", rat)
274274
#assert relerr <= prederror
275275

276-
test_helmholtz_2d_off_axis(5, 4)
277-
276+
max_deriv = 21
277+
var = _make_sympy_vec("x", 2)
278+
var_t = _make_sympy_vec("t", 2)
279+
g_x_y = sp.log(sp.sqrt((var[0]-var_t[0])**2 + (var[1]-var_t[1])**2))
280+
derivs = [sp.diff(g_x_y,
281+
var_t[0], i).subs(var_t[0], 0).subs(var_t[1], 0)
282+
for i in range(max_deriv)]
278283

279284
def test_laplace_2d_off_axis(deriv_order, exp_order):
280285
r"""
281286
Tests off-axis recurrence code for orders up to 6 laplace2d.
282287
"""
283288
s = sp.Function("s")
284-
var = _make_sympy_vec("x", 2)
285-
var_t = _make_sympy_vec("t", 2)
286-
g_x_y = sp.log(sp.sqrt((var[0]-var_t[0])**2 + (var[1]-var_t[1])**2))
287-
derivs = [sp.diff(g_x_y,
288-
var_t[0], i).subs(var_t[0], 0).subs(var_t[1], 0)
289-
for i in range(15)]
290-
x_coord = 1e-2 * np.random.rand() # noqa: NPY002
291-
y_coord = np.random.rand() # noqa: NPY002
289+
290+
x_coord = -0.0009025550989241182#1e-2 * np.random.rand() # noqa: NPY002
291+
y_coord = 0.05495017991244575#np.random.rand() # noqa: NPY002
292292
coord_dict = {var[0]: x_coord, var[1]: y_coord}
293293

294294
w = make_identity_diff_op(2)
@@ -302,17 +302,17 @@ def test_laplace_2d_off_axis(deriv_order, exp_order):
302302
ic.append(derivs[i].subs(var[0], 0).subs(var[1], coord_dict[var[1]]))
303303

304304
n = sp.symbols("n")
305-
for i in range(start_order, 15):
305+
for i in range(start_order, max_deriv):
306306
recur_eval = recur.subs(var[0], coord_dict[var[0]]).subs(var[1], coord_dict[var[1]]).subs(n, i)
307307
for j in range(i-recur_order, i):
308308
recur_eval = recur_eval.subs(s(j), ic[j])
309309
ic.append(recur_eval)
310310

311311
ic = np.array(ic)
312312

313-
true_ic = np.array([derivs[i].subs(var[0], 0).subs(var[1], coord_dict[var[1]]) for i in range(15)])
313+
#true_ic = np.array([derivs[i].subs(var[0], 0).subs(var[1], coord_dict[var[1]]) for i in range(max_deriv)])
314314

315-
assert np.max(np.abs(ic[::2]-true_ic[::2])/np.abs(true_ic[::2])) < 1e-8
315+
#assert np.max(np.abs(ic[::2]-true_ic[::2])/np.abs(true_ic[::2])) < 1e-8
316316
#print(np.max(np.abs(ic[::2]-true_ic[::2])/np.abs(true_ic[::2])))
317317

318318
# CHECK ACCURACY OF EXPRESSION FOR deriv_order
@@ -321,23 +321,53 @@ def test_laplace_2d_off_axis(deriv_order, exp_order):
321321
approx_deriv = exp.subs(n, deriv_order)
322322
for i in range(-exp_range+deriv_order, deriv_order+1):
323323
approx_deriv = approx_deriv.subs(s(i), ic[i])
324-
324+
325+
"""
325326
rat = coord_dict[var[0]]/coord_dict[var[1]]
326327
if deriv_order + exp_order % 2 == 0:
327328
prederror = abs(ic[deriv_order+exp_order+2] * coord_dict[var[0]]**(exp_order+2)/math.factorial(exp_order+2))
328329
else:
329330
prederror = abs(ic[deriv_order+exp_order+1] * coord_dict[var[0]]**(exp_order+1)/math.factorial(exp_order+1))
330331
print("PREDICTED ERROR: ", prederror)
332+
"""
333+
331334
relerr = abs((approx_deriv - derivs[deriv_order])/derivs[deriv_order]).subs(var[0], coord_dict[var[0]]).subs(var[1], coord_dict[var[1]])
332-
print("RELATIVE ERROR: ", relerr)
333-
print("RATIO(x0/x1): ", rat)
335+
#print("RELATIVE ERROR: ", relerr)
336+
#print("RATIO(x0/x1): ", rat)
337+
338+
return relerr
334339
#assert relerr <= prederror
335340

336341

337-
test_laplace_2d_off_axis(6, 4)
342+
import matplotlib.pyplot as plt
343+
344+
orders_for_plot = [5, 7, 9]
345+
exp_orders = [4, 5, 6, 7, 8]
346+
347+
X_P = []
348+
for i in exp_orders:
349+
TEMP = []
350+
for j in orders_for_plot:
351+
TEMP.append(test_laplace_2d_off_axis(j, i))
352+
X_P.append(TEMP)
353+
354+
fig, ax = plt.subplots()
355+
356+
for i in range(len(exp_orders)):
357+
ax.plot(orders_for_plot, X_P[i], label="EXP ORDER: " +str(exp_orders[i]))
358+
359+
ax.set_yscale('log')
360+
ax.set_xlabel('Deriv Order')
361+
ax.set_ylabel('Error')
362+
plt.legend()
363+
plt.show()
364+
365+
366+
367+
368+
338369

339370

340-
import matplotlib.pyplot as plt
341371
def _plot_laplace_2d(max_order_check, max_abs):
342372
w = make_identity_diff_op(2)
343373
laplace2d = laplacian(w)

test/test_recurrence_qbx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,13 @@ def _construct_laplace_axis_2d(orders, resolutions):
294294
return err
295295

296296
import matplotlib.pyplot as plt
297-
orders = [10]
297+
orders = [10, 12]
298298
#resolutions = range(200, 800, 200)
299-
resolutions = [800, 1000]
299+
resolutions = [800, 1000, 1200]
300300
err_mat = _construct_laplace_axis_2d(orders, resolutions)
301301

302302
for i in range(len(orders)):
303-
plt.plot(resolutions, err_mat[i], label="order ="+str(orders[i]))
303+
plt.plot(resolutions, err_mat[i], label="order QBX="+str(orders[i]))
304304
plt.xlabel("Number of Nodes")
305305
plt.ylabel("Error")
306306
plt.title("2D Ellipse LP Eval Error")

0 commit comments

Comments
 (0)