Skip to main content

magpylib-material-response

Actions Status Documentation Status

PyPI version PyPI platforms

Coverage

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_charge solves 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_cells cuts 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 a BHCurve, 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 (the fem extra, NGSolve) solves the same model by finite elements, to check the other two, a saturating part too; study_cells, study_fem and compare give 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 getting started, a guide to choosing a solver, how each solver works, and worked examples against finite elements.

Metadata

Release files for magpylib-material-response 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for magpylib-material-response 0.12.0
File Size Uploaded Provenance Actions
magpylib_material_response-0.12.0.tar.gz 3.6 MB With provenance Details for magpylib_material_response-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for magpylib-material-response 0.12.0
File Interpreter ABI Platform Actions
magpylib_material_response-0.12.0-py3-none-any.whl Python 3 none any Details for magpylib_material_response-0.12.0-py3-none-any.whl

Total release size: 3.9 MB

Release files / magpylib_material_response-0.12.0.tar.gz

Download URL magpylib_material_response-0.12.0.tar.gz
Size 3.6 MB
Tags Source
SHA-256 checksum
How to use checksums
9b0ff0a6ee5e216fa2e0ea3e9d0d31418bd28f48331eb0df4a53b2f87730d57c
BLAKE2b-256 checksum
How to use checksums
434d67290f2c6d2ae283242a5bab211a92f41d705cc03bd96ccb4597384d363e
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 8, 2026.

Transparency log

Release files / magpylib_material_response-0.12.0-py3-none-any.whl

Download URL magpylib_material_response-0.12.0-py3-none-any.whl
Size 321.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15ac62a5784823efbbccc3a3766cfa6ecd1cbd98bfcf1589a710d69e94c5ad3f
BLAKE2b-256 checksum
How to use checksums
793e1266c807d3f69b6bbbf739e6e9c6c612f790a52e7724c1f4cb31f90241e7
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 8, 2026.

Transparency log

Security for magpylib-material-response 0.12.0

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for magpylib_material_response-0.12.0.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 8, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page