magpylib-material-response
Warning This package is experimental and in development phase, breaking API changes may happen at any time.
Magpylib-Material-Response adds the response of magnetic materials to Magpylib: the magnetization of soft-magnetic parts and the demagnetization of hard magnets. A solved model is a magpylib source like any other.
solve_face_chargesolves linear, uniform parts on their surface, with no volume mesh: cuboids, cylinders, cylinder segments, spheres and closed triangle meshes, such as CAD exports. It gets within 1 % of a finite-element reference faster than finite elements on every validation case where both get there.solve_cellscuts the parts into cells and solves for the polarization of every cell at once with the method of moments: for a part that saturates on aBHCurve, an anisotropic susceptibility, or one that varies inside a part. A dense direct solver, or matrix-free GMRES with FFT products on grids of identical cells; meshing helpers cut cuboids, cylinders and, through TetGen, any closed triangular surface into cells.solve_fem(thefemextra, NGSolve) solves the same model by finite elements, to check the other two, a saturating part too;study_cells,study_femandcomparegive error bars by refining the mesh or the element order.
What drives a part is any other source in the model: magnets, currents and a
UniformField. All of these are importable from the package itself.
Installation
pip install magpylib-material-response
Tetrahedral meshing of TriangularMesh magnets needs the optional
TetGen, finite elements
NGSolve:
pip install "magpylib-material-response[tetgen]"
pip install "magpylib-material-response[fem]"
Minimal examples
import magpylib as magpy
from magpylib_material_response import solve_face_charge
# a magnet on an iron plate, SI units (m, T)
magnet = magpy.magnet.Cuboid(polarization=(0, 0, 1.2), dimension=(0.01, 0.01, 0.005))
magnet.position = (0, 0, 0.0055)
plate = magpy.magnet.Cuboid(polarization=(0, 0, 0), dimension=(0.04, 0.04, 0.006))
plate.susceptibility = 1000 # soft iron; the magnet, with none, keeps its polarization
solved = solve_face_charge(magpy.Collection(magnet, plate))
print(
magpy.getB(solved, (0, 0, 0.012))
) # 205 mT above the magnet, 160 without the plate
import magpylib as magpy
from magpylib_material_response import solve_cells
from magpylib_material_response.meshing import mesh_Cuboid
# a magnet with finite susceptibility, demagnetizing itself
magnet = magpy.magnet.Cuboid(polarization=(0, 0, 1), dimension=(1e-3, 1e-3, 1e-3))
magnet.susceptibility = 0.3 # µr = 1.3
mesh_demag = solve_cells(mesh_Cuboid(magnet, target_elems=125))
print(magpy.getB(mesh_demag, (0, 0, 1.5e-3)))
import magpylib as magpy
import numpy as np
from magpylib_material_response import BHCurve, UniformField, solve_cells
from magpylib_material_response.meshing import mesh_Cuboid
# an iron cube saturating in an applied field, with a B-H curve in A/m and T
H = np.r_[0.0, np.geomspace(1e-2, 1e6, 200)]
mu0H = magpy.mu_0 * H
cube = magpy.magnet.Cuboid(polarization=(0, 0, 0), dimension=(0.01, 0.01, 0.01))
cube.susceptibility = BHCurve(H=H, B=1000 * mu0H / (1 + 1000 * mu0H / 1.6) + mu0H)
model = magpy.Collection(mesh_Cuboid(cube, (4, 4, 4)), UniformField(B=(0, 0, 1)))
solved = solve_cells(model)
print(magpy.getB(solved, (0, 0, 0.02))) # the applied 1 T included
AI coding assistants: the package ships an Agent Skill, which
uvx library-skills adds to a project.
See the documentation for a quickstart, worked examples, and the method description.
Metadata
Release files for magpylib-material-response 0.9.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| magpylib_material_response-0.9.2.tar.gz | 2.5 MB | With provenance | Details for magpylib_material_response-0.9.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| magpylib_material_response-0.9.2-py3-none-any.whl | Python 3 | none | any | Details for magpylib_material_response-0.9.2-py3-none-any.whl |
Total release size: 2.8 MB
Release files / magpylib_material_response-0.9.2.tar.gz
| Download URL | magpylib_material_response-0.9.2.tar.gz |
|---|---|
| Size | 2.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c40f39b27917e5515041e0c18714600a9c4cf7f9e0376d7b31661156b123e903
|
|
BLAKE2b-256 checksum How to use checksums |
9a65087399b923fe07055101c583da74c936fe8640f964f60d26f34edf08d73c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logRelease files / magpylib_material_response-0.9.2-py3-none-any.whl
| Download URL | magpylib_material_response-0.9.2-py3-none-any.whl |
|---|---|
| Size | 305.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af123e044d10582aa9717ba4145d661cba960fbfe7e807098971436ca8afea1e
|
|
BLAKE2b-256 checksum How to use checksums |
88040179d32aba339d96bace44d613cde0f40b55cc09470bb3de097bcc28e372
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logSecurity for magpylib-material-response 0.9.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for magpylib_material_response-0.9.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.