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

B-field computation more stable than H-field computation #707

Open
OrtnerMichael opened this issue Dec 24, 2023 · 0 comments
Open

B-field computation more stable than H-field computation #707

OrtnerMichael opened this issue Dec 24, 2023 · 0 comments
Milestone

Comments

@OrtnerMichael
Copy link
Member

This test shows that B-field computation is more stable than H-field computation.
Don't really understand why - probably something to do with the digits, but cant figure this out in floating point.

# Dipole <> Sphere
def test_core_physics_dipole_sphere():
    """
    dipole and sphere field must be similar outside of sphere
    moment = magnetization * volume
    near field tests
    """
    obs = np.array([(1, 2, 3), (-2, -2, -2), (3, 5, -4), (5, 4, 0.1)])
    dia = np.array([2, 3, 0.1, 3.3])
    pol = np.array([(1, 2, 3), (0, 0, 1), (-1, -2, 0), (1, -1, 0.1)])
    mom = np.array([4 * (d / 2) ** 3 * np.pi / 3 * p / MU0 for d, p in zip(dia, pol)])

    B1 = magpy.core.magnet_sphere_field(
        field="B",
        observers=obs,
        diameter=dia,
        polarization=pol,
    )
    B2 = magpy.core.dipole_field(
        field="B",
        observers=obs,
        moment=mom,
    )
    np.testing.assert_allclose(B1, B2, rtol=0, atol=1e-16)

    H1 = magpy.core.magnet_sphere_field(
        field="H",
        observers=obs,
        diameter=dia,
        polarization=pol,
    )
    H2 = magpy.core.dipole_field(
        field="H",
        observers=obs,
        moment=mom,
    )
    np.testing.assert_allclose(H1, H2, rtol=0, atol=1e-11)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant