Skip to content

Commit dead26c

Browse files
style: pre-commit fixes
1 parent 9cbb630 commit dead26c

File tree

15 files changed

+16619
-46
lines changed

15 files changed

+16619
-46
lines changed

CHANGELOG.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
# Unreleased
22

33
# 0.3.0
4-
* improved interface for chi input
5-
* FE tests for anisotropic chi and negative chi
6-
* Improve internals
7-
* anisotropic susceptibilities are now allowed.
8-
* Improve suszeptibility input possibilities:
9-
- give susceptibility to parent collection
10-
- if susceptiblity input is scalar, isotropic susceptibility is assumed, if it is a 3-vector it can be anisotropic
11-
* Various tests included of interface and computation, isotropic and anisotropic tests confirm computaiton
4+
5+
- improved interface for chi input
6+
- FE tests for anisotropic chi and negative chi
7+
- Improve internals
8+
- anisotropic susceptibilities are now allowed.
9+
- Improve suszeptibility input possibilities:
10+
- give susceptibility to parent collection
11+
- if susceptiblity input is scalar, isotropic susceptibility is assumed, if it
12+
is a 3-vector it can be anisotropic
13+
- Various tests included of interface and computation, isotropic and anisotropic
14+
tests confirm computaiton
1215

1316
# 0.2.1a0
14-
* Fix null polarization for rotated objects ([#7](https://github.com/magpylib/magpylib-material-response/pull/7))
15-
* Fix docs not building ([#6](https://github.com/magpylib/magpylib-material-response/pull/6))
17+
18+
- Fix null polarization for rotated objects
19+
([#7](https://github.com/magpylib/magpylib-material-response/pull/7))
20+
- Fix docs not building
21+
([#6](https://github.com/magpylib/magpylib-material-response/pull/6))
1622

1723
# 0.2.0a0
18-
* renaming xi->susceptibility ([#5](https://github.com/magpylib/magpylib-material-response/pull/5))
19-
* update to magpylib v5 ([#4](https://github.com/magpylib/magpylib-material-response/pull/4))
24+
25+
- renaming xi->susceptibility
26+
([#5](https://github.com/magpylib/magpylib-material-response/pull/5))
27+
- update to magpylib v5
28+
([#4](https://github.com/magpylib/magpylib-material-response/pull/4))

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626

2727
<!-- prettier-ignore-end -->
2828

29-
> **Warning**
30-
> **This package is experimental and in development phase, breaking API changes may happen at any time.**
29+
> **Warning** > **This package is experimental and in development phase,
30+
> breaking API changes may happen at any time.**
3131
32-
Magpylib-Material-Response is an extension to the Magpylib library, providing magnetic field analysis for soft materials and demagnetization of hard magnets. Leveraging the Method of Moments, it calculates magnetic material response by meshing sources in an arbitrary number of unit elements.
32+
Magpylib-Material-Response is an extension to the Magpylib library, providing
33+
magnetic field analysis for soft materials and demagnetization of hard magnets.
34+
Leveraging the Method of Moments, it calculates magnetic material response by
35+
meshing sources in an arbitrary number of unit elements.

docs/examples/cuboids_demagnetization.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ kernelspec:
1414

1515
# Cuboids demagnetization
1616

17-
The following example demonstrates how to create magnetic sources with different susceptibilities using the Magpylib library. It defines three cuboid magnets with varying susceptibilities and positions, creates a collection of these magnets, and computes their magnetic field responses using different levels of meshing. The results are then compared to a Finite Element Method (FEM) analysis to evaluate the performance of the Magpylib-Material-Response approach. The comparison is presented in two separate plots, one showing the magnetic field values and the other showing the difference between the Magpylib results and the FEM reference data. The code demonstrates that even with a low number of mesh elements, the Magpylib results quickly approach the reference FEM values.
17+
The following example demonstrates how to create magnetic sources with different
18+
susceptibilities using the Magpylib library. It defines three cuboid magnets
19+
with varying susceptibilities and positions, creates a collection of these
20+
magnets, and computes their magnetic field responses using different levels of
21+
meshing. The results are then compared to a Finite Element Method (FEM) analysis
22+
to evaluate the performance of the Magpylib-Material-Response approach. The
23+
comparison is presented in two separate plots, one showing the magnetic field
24+
values and the other showing the difference between the Magpylib results and the
25+
FEM reference data. The code demonstrates that even with a low number of mesh
26+
elements, the Magpylib results quickly approach the reference FEM values.
1827

1928
+++
2029

@@ -164,4 +173,5 @@ fig2.update_yaxes(matches=None, showticklabels=True)
164173
display(fig1, fig2)
165174
```
166175

167-
As shown above, already with a low number of mesh elements, the result is approaching the reference FEM values and improves while refining the mesh.
176+
As shown above, already with a low number of mesh elements, the result is
177+
approaching the reference FEM values and improves while refining the mesh.

docs/examples/soft_magnets.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ kernelspec:
1818

1919
+++
2020

21-
This code demonstrates demagnetization calculations for a hard and a soft cuboid magnet using the Magpylib library.
22-
Demagnetization is applied using varying numbers of cells for the mesh and compared to the computed magnetic fields from Magpylib withoug demagnetization and with FEM analysis data obtained from an external dataset.
21+
This code demonstrates demagnetization calculations for a hard and a soft cuboid
22+
magnet using the Magpylib library. Demagnetization is applied using varying
23+
numbers of cells for the mesh and compared to the computed magnetic fields from
24+
Magpylib withoug demagnetization and with FEM analysis data obtained from an
25+
external dataset.
2326

2427
+++ {"user_expressions": []}
2528

@@ -172,4 +175,5 @@ display(fig1, fig2)
172175

173176
+++ {"user_expressions": []}
174177

175-
As shown above, the demagnetized collection outputs are approaching the reference FEM values while refining the mesh.
178+
As shown above, the demagnetized collection outputs are approaching the
179+
reference FEM values while refining the mesh.

src/magpylib_material_response/data/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Built-in datasets for demonstration, educational and test purposes.
33
"""
44

5+
from __future__ import annotations
6+
57

68
def get_dataset(name):
79
import json

src/magpylib_material_response/demag.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# +
44
# pylint: disable=invalid-name, redefined-outer-name, protected-access
5+
from __future__ import annotations
6+
57
import sys
68
from collections import Counter
79

@@ -55,25 +57,24 @@ def get_susceptibilities(sources, susceptibility):
5557
susis.append(susceptibility)
5658
else:
5759
raise ValueError("susceptibility is not scalar or array fo length 3")
60+
# susceptibilities as input to demag function
61+
elif np.isscalar(susceptibility):
62+
susis = np.ones((n, 3)) * susceptibility
63+
elif len(susceptibility) == 3:
64+
susis = np.tile(susceptibility, (n, 1))
65+
if n == 3:
66+
raise ValueError(
67+
"Apply_demag input susceptibility is ambiguous - either scalar list or vector single entry. "
68+
"Please choose different means of input or change the number of cells in the Collection."
69+
)
5870
else:
59-
# susceptibilities as input to demag function
60-
if np.isscalar(susceptibility):
61-
susis = np.ones((n, 3)) * susceptibility
62-
elif len(susceptibility) == 3:
63-
susis = np.tile(susceptibility, (n, 1))
64-
if n == 3:
65-
raise ValueError(
66-
"Apply_demag input susceptibility is ambiguous - either scalar list or vector single entry. "
67-
"Please choose different means of input or change the number of cells in the Collection."
68-
)
69-
else:
70-
if len(susceptibility) != n:
71-
raise ValueError(
72-
"Apply_demag input susceptibility must be scalar, 3-vector, or same length as input Collection."
73-
)
74-
susis = np.array(susceptibility)
75-
if susis.ndim == 1:
76-
susis = np.repeat(susis, 3).reshape(n, 3)
71+
if len(susceptibility) != n:
72+
raise ValueError(
73+
"Apply_demag input susceptibility must be scalar, 3-vector, or same length as input Collection."
74+
)
75+
susis = np.array(susceptibility)
76+
if susis.ndim == 1:
77+
susis = np.repeat(susis, 3).reshape(n, 3)
7778

7879
susis = np.reshape(susis, 3 * n, order="F")
7980
return np.array(susis)
@@ -141,7 +142,7 @@ def demag_tensor(
141142

142143
if pairs_matching and split != 1:
143144
raise ValueError("Pairs matching does not support splitting")
144-
elif max_dist != 0:
145+
if max_dist != 0:
145146
mask_inds, getH_params, pos0, rot0 = filter_distance(
146147
src_list, max_dist, return_params=False, return_base_geo=True
147148
)
@@ -179,7 +180,7 @@ def demag_tensor(
179180
H_unit_pol = []
180181
for split_ind, src_list_subset in enumerate(src_list_split):
181182
logger.info(
182-
f"Sources subset {split_ind+1}/{len(src_list_split)}"
183+
f"Sources subset {split_ind + 1}/{len(src_list_split)}"
183184
)
184185
if src_list_subset.size > 0:
185186
H_unit_pol.append(

src/magpylib_material_response/meshing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from collections import Counter
24
from itertools import product
35

src/magpylib_material_response/meshing_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from itertools import product
24

35
import numpy as np

src/magpylib_material_response/package_data/datasets/FEMdata_test_cuboids.json

Lines changed: 2310 additions & 1 deletion
Large diffs are not rendered by default.

src/magpylib_material_response/package_data/datasets/FEMdata_test_softmag.json

Lines changed: 14225 additions & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)