Skip to content

Commit

Permalink
fix #703
Browse files Browse the repository at this point in the history
  • Loading branch information
Boisselet Alexandre (IFAT DC ATV SC D TE2) authored and Boisselet Alexandre (IFAT DC ATV SC D TE2) committed Dec 22, 2023
1 parent 9413f22 commit a182438
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion magpylib/_src/fields/field_BH_cylinder.py
Expand Up @@ -386,7 +386,7 @@ def magnet_cylinder_field(
return np.concatenate(((Bx,), (By,), (Bz,)), axis=0).T

if any(mask_ax): # ax computes B-field
Bz[mask_tv * mask_inside] -= magz[mask_tv * mask_inside]
Bz[mask_ax * mask_inside] -= magz[mask_ax * mask_inside]
return np.concatenate(((Bx,), (By,), (Bz,)), axis=0).T * 10 / 4 / np.pi


Expand Down
23 changes: 23 additions & 0 deletions tests/test_field_cylinder.py
Expand Up @@ -461,3 +461,26 @@ def test_cylinder_diametral_small_r():
ddB = abs(ddB - np.mean(ddB, axis=0))

assert np.all(ddB < 0.001)


def test_cyl_vs_cylseg_axial_H_inside_mask():
"""see https://github.com/magpylib/magpylib/issues/703"""
field = "H"
obs = np.array([(0.1, 0.2, 0.3)])
pols = np.array([(0, 0, 1)])
dims = np.array([(1, 1)])
dims_cs = np.array([(0,0.5,1,0,360)])

Bc = magpy.core.magnet_cylinder_field(
field=field,
observers=obs,
dimension=dims,
magnetization=pols,
)
Bcs = magpy.core.magnet_cylinder_segment_field(
field=field,
observers=obs,
dimension=dims_cs,
magnetization=pols,
)
np.testing.assert_allclose(Bc, Bcs)

0 comments on commit a182438

Please sign in to comment.