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 a quickstart, worked examples, and the method description.

Metadata

Release files for magpylib-material-response 0.9.1

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.9.1
File Size Uploaded Provenance Actions
magpylib_material_response-0.9.1.tar.gz 2.5 MB With provenance Details for magpylib_material_response-0.9.1.tar.gz

Built distribution (wheel)

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

Total release size: 2.8 MB

Release files / magpylib_material_response-0.9.1.tar.gz

Download URL magpylib_material_response-0.9.1.tar.gz
Size 2.5 MB
Tags Source
SHA-256 checksum
How to use checksums
dbf323a1ef6cad5a9a05ddb38898fb57bce5011c51a74ea97d10ab519cb93bea
BLAKE2b-256 checksum
How to use checksums
e1b1717ce94280b0ba9c456fd5b9319401d37e37ff2103bb5cc3a0fb6a640b6a
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 2, 2026.

Transparency log

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

Download URL magpylib_material_response-0.9.1-py3-none-any.whl
Size 305.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd82771b0aad9d7406e24083a4781f14204ec43e89fe2e476070b0afacc65342
BLAKE2b-256 checksum
How to use checksums
5d83c7d5ef71e9c71905e9fed304b985fa32220dec846607b0e7068bd93a7cfb
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 2, 2026.

Transparency log

Security for magpylib-material-response 0.9.1

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.

Select from 2 files

Attestation for magpylib_material_response-0.9.1.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 2, 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