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

H-field inside for Cylinder and Cylinder Segment does not match #703

Closed
Alexboiboi opened this issue Dec 22, 2023 · 2 comments · Fixed by #706
Closed

H-field inside for Cylinder and Cylinder Segment does not match #703

Alexboiboi opened this issue Dec 22, 2023 · 2 comments · Fixed by #706
Assignees
Labels
bug needs attention critical needs to be fixed immediately with new release

Comments

@Alexboiboi
Copy link
Member

Alexboiboi commented Dec 22, 2023

Magpylib version

4.x (Latest)

What happened?

When computing the H-field inside a cylinder, the values do not match the values obtained with an equivalent cylinder segment.

@OrtnerMichael Shall we wait for the v5 release or make a hotfix for v4 already now?

Code example

import magpylib as magpy
import numpy as np

field = "H"
obs = np.array([(0.1, 0.2, 0.3)])
pols = np.array([(0, 0, 1)] * len(obs))
d,h = 1,1
dims = np.array([(d, h)]*len(obs))
dims_cs = np.array([(0, d/2, h, 0, 360)]*len(obs))

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,
)
print(Bc, Bcs)
# ->output :
#(array([[0.02672707, 0.05345415, 0.50743767]]),
# array([[ 0.02672707,  0.05345415, -0.28833704]]))

Additional context

Cylinder field function axial vs transversal mask. seems to be the issue

      if any(mask_ax):  # ax computes B-field
        Bz[mask_tv * mask_inside] -= magz[mask_tv * mask_inside]
    return np.concatenate(((Bx,), (By,), (Bz,)), axis=0).T * 10 / 4 / np.pi
    ```
    ([permalink](https://github.com/magpylib/magpylib/blob/e35b724a8154903d2c6710edb1d254105d884f88/magpylib/_src/fields/field_BH_cylinder.py#L388C5-L389C65))
@Alexboiboi Alexboiboi added critical needs to be fixed immediately with new release bug needs attention labels Dec 22, 2023
@OrtnerMichael
Copy link
Member

let me check this

@OrtnerMichael
Copy link
Member

A bug in the magnetic field computation

getH gives this

image

lets make a hotfix!!!

Alexboiboi pushed a commit that referenced this issue Dec 22, 2023
OrtnerMichael pushed a commit that referenced this issue Dec 27, 2023
* fix #703

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Boisselet Alexandre (IFAT DC ATV SC D TE2) <Alexandre.Boisselet@infineon.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs attention critical needs to be fixed immediately with new release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants