Skip to content

Commit

Permalink
bug fix in test_biotsavart.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mbkumar committed Oct 28, 2023
1 parent a4acab6 commit a72392c
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions tests/field/test_biotsavart.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,21 @@ def test_biotsavart_both_interfaces_give_same_result(self):
assert np.allclose(B1, B2)

def test_biotsavart_exponential_convergence(self):
coil = BiotSavart([Coil(get_curve(), Current(1e4))])
from time import time
# points = np.asarray(17 * [[-1.41513202e-03, 8.99999382e-01, -3.14473221e-04 ]])
points = np.asarray(10 * [[-1.41513202e-03, 8.99999382e-01, -3.14473221e-04]])
tic = time()
btrue = BiotSavart([Coil(get_curve(1000), Current(1e4))]).set_points(points).B()
# print(btrue)
bcoarse = BiotSavart([Coil(get_curve(10), Current(1e4))]).set_points(points).B()
bfine = BiotSavart([Coil(get_curve(20), Current(1e4))]).set_points(points).B()
assert np.linalg.norm(btrue-bfine) < 1e-4 * np.linalg.norm(bcoarse-bfine)
# print(time()-tic)

tic = time()
dbtrue = BiotSavart([Coil(get_curve(1000), Current(1e4))]).set_points(points).dB_by_dX()
# print(dbtrue)
dbcoarse = BiotSavart([Coil(get_curve(10), Current(1e4))]).set_points(points).dB_by_dX()
dbfine = BiotSavart([Coil(get_curve(20), Current(1e4))]).set_points(points).dB_by_dX()
assert np.linalg.norm(btrue-bfine) < 1e-4 * np.linalg.norm(bcoarse-bfine)
# print(time()-tic)
assert np.linalg.norm(dbtrue-dbfine) < 1e-4 * np.linalg.norm(dbcoarse-dbfine)

tic = time()
dbtrue = BiotSavart([Coil(get_curve(1000), Current(1e4))]).set_points(points).d2B_by_dXdX()
# print("dbtrue", dbtrue)
dbcoarse = BiotSavart([Coil(get_curve(10), Current(1e4))]).set_points(points).d2B_by_dXdX()
dbfine = BiotSavart([Coil(get_curve(20), Current(1e4))]).set_points(points).d2B_by_dXdX()
assert np.linalg.norm(btrue-bfine) < 1e-4 * np.linalg.norm(bcoarse-bfine)
# print(time()-tic)
assert np.linalg.norm(dbtrue-dbfine) < 1e-4 * np.linalg.norm(dbcoarse-dbfine)

def test_dB_by_dcoilcoeff_reverse_taylortest(self):
np.random.seed(1)
Expand Down Expand Up @@ -180,7 +168,7 @@ def subtest_biotsavart_d2B_by_dXdX_taylortest(self, idx):
bs = BiotSavart([coil])
points = np.asarray(17 * [[-1.41513202e-03, 8.99999382e-01, -3.14473221e-04]])
bs.set_points(points)
dB_by_dX, d2B_by_dXdX = bs.dB_by_dX(), bs.d2B_by_dXdX()
d2B_by_dXdX = bs.d2B_by_dXdX()
for d1 in range(3):
for d2 in range(3):
second_deriv = d2B_by_dXdX[idx, d1, d2]
Expand Down Expand Up @@ -255,7 +243,7 @@ def subtest_biotsavart_d2A_by_dXdX_taylortest(self, idx):
bs = BiotSavart([coil])
points = np.asarray(17 * [[-1.41513202e-03, 8.99999382e-01, -3.14473221e-04]])
bs.set_points(points)
dA_by_dX, d2A_by_dXdX = bs.dA_by_dX(), bs.d2A_by_dXdX()
d2A_by_dXdX = bs.d2A_by_dXdX()
for d1 in range(3):
for d2 in range(3):
second_deriv = d2A_by_dXdX[idx, d1, d2]
Expand Down

0 comments on commit a72392c

Please sign in to comment.