Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test for small rho #81

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
with:
path: ./dist/geoana*.whl


distribute:
name: Distribute documentation
runs-on: ubuntu-latest
Expand Down
12 changes: 4 additions & 8 deletions geoana/em/static/wholespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,8 @@ def vector_potential(self, xyz, coordinates="cartesian"):

A_cyl = np.zeros_like(r_vec)

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

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

B_cyl = np.zeros_like(r_cyl)

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

temp = np.sqrt(a**2 + z[small_rho]**2)
B_cyl[small_rho, 0] = 3 * C * np.pi * a**2 * z[small_rho] * (
Expand Down
13 changes: 5 additions & 8 deletions tests/em/static/test_current_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def circle_loop():

@pytest.fixture()
def xyz():
nx, ny, nz = (11, 13, 9)
x = np.linspace(-100, 100, nx)
y = np.linspace(-90, 90, ny)
z = np.linspace(-80, 80, nz)
nx, ny, nz = (32, 32, 32)
x = np.linspace(-50, 50, nx)
y = np.linspace(-50, 50, ny)
z = np.linspace(-50, 50, nz)
xyz = np.meshgrid(x, y, z)
return xyz

Expand Down Expand Up @@ -87,8 +87,5 @@ def test_circular_loop(circle_loop, orient, method, xyz):
test = getattr(circle_loop, method)(xyz)
other = getattr(loop_approx, method)(xyz)

atol = 1E-16
if method == 'magnetic_field':
atol /= mu_0

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