Skip to content

Commit 1acbf88

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 408dd58 commit 1acbf88

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

magpylib_material_response/demag.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def get_susceptibilities(*sources, susceptibility=None):
5151
raise ValueError("susceptibility is not scalar or array fo length 3")
5252
return susceptibilities
5353

54+
5455
def get_H_ext(*sources, H_ext=None):
5556
"""Return a list of length (len(sources)) with H_ext values
5657
Priority is given at the source level, hovever if value is not found, it is searched up the
@@ -61,8 +62,8 @@ def get_H_ext(*sources, H_ext=None):
6162
H_ext = getattr(src, "H_ext", None)
6263
if H_ext is None:
6364
if src.parent is None:
64-
#print("Warning: No value for H_ext defined in any parent collection. H_ext set to zero.")
65-
H_exts.append((0.0,0.0,0.0))
65+
# print("Warning: No value for H_ext defined in any parent collection. H_ext set to zero.")
66+
H_exts.append((0.0, 0.0, 0.0))
6667
else:
6768
H_exts.extend(get_H_ext(src.parent))
6869
else:
@@ -370,19 +371,17 @@ def apply_demag(
370371
raise ValueError(
371372
"Apply_demag input collection and susceptibility must have same length."
372373
)
373-
susceptibility = np.reshape(
374-
susceptibility, 3 * n, order="F"
375-
)
374+
susceptibility = np.reshape(susceptibility, 3 * n, order="F")
376375
S = np.diag(susceptibility) # shape ii, jj
377376

378377
# set up H_ext
379378
H_ext = get_H_ext(*magnets_list)
380379
H_ext = np.array(H_ext)
381380
if len(H_ext) != n:
382-
raise ValueError("Apply_demag input collection and H_ext must have same length.")
383-
H_ext = np.reshape(
384-
H_ext, (3 * n, 1), order="F"
385-
)
381+
raise ValueError(
382+
"Apply_demag input collection and H_ext must have same length."
383+
)
384+
H_ext = np.reshape(H_ext, (3 * n, 1), order="F")
386385

387386
# set up T (3 pol unit, n cells, n positions, 3 Bxyz)
388387
with timelog("Demagnetization tensor calculation", min_log_time=min_log_time):

tests/test_demag.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
import magpylib as magpy
2+
23
import magpylib_material_response
4+
35
print(magpylib_material_response.__version__)
4-
from magpylib_material_response.meshing import mesh_Cuboid
5-
from magpylib_material_response.demag import apply_demag
6-
import numpy as np
76
import matplotlib.pyplot as plt
7+
import numpy as np
8+
9+
from magpylib_material_response.demag import apply_demag
10+
from magpylib_material_response.meshing import mesh_Cuboid
811

912
elements = 4
1013

11-
#hollow cylinder magnet
12-
cuboid = magpy.magnet.Cuboid(polarization=(1,2,3), dimension=(2,2,2))
14+
# hollow cylinder magnet
15+
cuboid = magpy.magnet.Cuboid(polarization=(1, 2, 3), dimension=(2, 2, 2))
1316
coll = mesh_Cuboid(cuboid, elements)
14-
#coll.susceptibility = (1,2,3,4)
17+
# coll.susceptibility = (1,2,3,4)
1518
for i in range(len(coll)):
16-
coll[i].susceptibility = (i,i,i*10)
17-
#coll[i].susceptibility = i
18-
#coll.H_ext = (-10,-10,-10)
19+
coll[i].susceptibility = (i, i, i * 10)
20+
# coll[i].susceptibility = i
21+
# coll.H_ext = (-10,-10,-10)
1922
coll = apply_demag(coll)
2023

2124
fig, ax = plt.subplots()
@@ -27,12 +30,7 @@
2730

2831
# Display the B-field with streamplot using log10-scaled
2932
# color function and linewidth
30-
splt = ax.quiver(
31-
grid[:, :, 0],
32-
grid[:, :, 2],
33-
B[:, :, 0],
34-
B[:, :, 2]
35-
)
33+
splt = ax.quiver(grid[:, :, 0], grid[:, :, 2], B[:, :, 0], B[:, :, 2])
3634

3735
print(B)
3836

@@ -44,4 +42,4 @@
4442
)
4543

4644
plt.tight_layout()
47-
plt.show()
45+
plt.show()

0 commit comments

Comments
 (0)