Skip to content

Commit 4cb4a17

Browse files
committed
fix test for small rho
Do a check for rho < sqrt(a**2 + z**2)
1 parent 3b1f8d5 commit 4cb4a17

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ jobs:
6464
with:
6565
path: ./dist/geoana*.whl
6666

67+
6768
distribute:
6869
name: Distribute documentation
6970
runs-on: ubuntu-latest

geoana/em/static/wholespace.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,8 @@ def vector_potential(self, xyz, coordinates="cartesian"):
597597

598598
A_cyl = np.zeros_like(r_vec)
599599

600-
# when rho is small relative to the radius and z, k_sq -> 0
601-
# this is unstable so use a small argument approximation.
602-
# check k_sq for the relative sizes
603-
small_rho = k_sq < 1E-3
600+
# when rho is small relative to the radius and z
601+
small_rho = rho**2/(a**2 + z**2) < 1E-6
604602

605603
temp = np.sqrt(a**2 + z[small_rho]**2)
606604
A_cyl[small_rho, 1] = np.pi * C * (
@@ -731,10 +729,8 @@ def magnetic_flux_density(self, xyz, coordinates="cartesian"):
731729

732730
B_cyl = np.zeros_like(r_cyl)
733731

734-
# when rho is small relative to the radius and z, k_sq -> 0
735-
# this is unstable so use a small argument approximation.
736-
# check k_sq for the relative sizes
737-
small_rho = k_sq < 1E-3
732+
# when rho is small relative to the radius and z
733+
small_rho = rho**2/(a**2 + z**2) < 1E-6
738734

739735
temp = np.sqrt(a**2 + z[small_rho]**2)
740736
B_cyl[small_rho, 0] = 3 * C * np.pi * a**2 * z[small_rho] * (

tests/em/static/test_current_loop.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def circle_loop():
2424

2525
@pytest.fixture()
2626
def xyz():
27-
nx, ny, nz = (11, 13, 9)
28-
x = np.linspace(-100, 100, nx)
29-
y = np.linspace(-90, 90, ny)
30-
z = np.linspace(-80, 80, nz)
27+
nx, ny, nz = (32, 32, 32)
28+
x = np.linspace(-50, 50, nx)
29+
y = np.linspace(-50, 50, ny)
30+
z = np.linspace(-50, 50, nz)
3131
xyz = np.meshgrid(x, y, z)
3232
return xyz
3333

@@ -87,8 +87,5 @@ def test_circular_loop(circle_loop, orient, method, xyz):
8787
test = getattr(circle_loop, method)(xyz)
8888
other = getattr(loop_approx, method)(xyz)
8989

90-
atol = 1E-16
91-
if method == 'magnetic_field':
92-
atol /= mu_0
9390

94-
npt.assert_allclose(test, other, rtol=1E-3, atol=atol)
91+
npt.assert_allclose(test, other, rtol=1E-3, atol=1E-20)

0 commit comments

Comments
 (0)