Metadata-Version: 2.5
Name: magpylib-material-response
Version: 0.6.0
Summary: Python package extending the Magpylib library by providing magnetic field analysis for soft materials and demagnetization of hard magnets.
Project-URL: Homepage, https://github.com/magpylib/magpylib-material-response
Project-URL: Bug Tracker, https://github.com/magpylib/magpylib-material-response/issues
Project-URL: Discussions, https://github.com/magpylib/magpylib-material-response/discussions
Project-URL: Changelog, https://github.com/magpylib/magpylib-material-response/releases
Author-email: Alexandre Boisselet <alexabois+magpylib@gmail.com>
License-Expression: BSD-3-Clause
License-File: LICENSE
Classifier: Development Status :: 1 - Planning
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: loguru>=0.5.0
Requires-Dist: magpylib>=6.0
Requires-Dist: scipy>=1.12
Provides-Extra: tetgen
Requires-Dist: tetgen>=0.8.3; extra == 'tetgen'
Description-Content-Type: text/markdown

# magpylib-material-response

[![Actions Status][actions-badge]][actions-link]
[![Documentation Status][rtd-badge]][rtd-link]

[![PyPI version][pypi-version]][pypi-link]
[![PyPI platforms][pypi-platforms]][pypi-link]

[![Coverage][coverage-badge]][coverage-link]

<!-- SPHINX-START -->

<!-- prettier-ignore-start -->
[actions-badge]:            https://github.com/magpylib/magpylib-material-response/actions/workflows/ci.yml/badge.svg
[actions-link]:             https://github.com/magpylib/magpylib-material-response/actions
[pypi-link]:                https://pypi.org/project/magpylib-material-response/
[pypi-platforms]:           https://img.shields.io/pypi/pyversions/magpylib-material-response
[pypi-version]:             https://img.shields.io/pypi/v/magpylib-material-response
[rtd-badge]:                https://readthedocs.org/projects/magpylib-material-response/badge/?version=latest
[rtd-link]:                 https://magpylib-material-response.readthedocs.io/en/latest/?badge=latest
[coverage-badge]:           https://codecov.io/github/magpylib/magpylib-material-response/branch/main/graph/badge.svg
[coverage-link]:            https://codecov.io/github/magpylib/magpylib-material-response

<!-- prettier-ignore-end -->

> **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](https://magpylib.readthedocs.io/): the demagnetization of hard
magnets and the magnetization of soft-magnetic parts. It cuts the magnets into
cells and solves for the polarization of every cell at once with the method of
moments.

- **`apply_demag`** solves a magpylib `Collection` for a scalar or anisotropic
  susceptibility per cell, driven by remanent polarizations, a uniform applied
  field and the current sources in the collection.
- **Two solvers, two interaction rules**: a dense direct solver, or matrix-free
  GMRES with FFT products on grids of identical cuboids, for meshes too large
  for a dense matrix; the default `solver="auto"` picks one from the cells.
  Cells interact through the field at each other's centroids (default) or
  averaged over each cell (`interaction="newell"`, cuboid meshes).
- **Meshing helpers** cut cuboids, cylinders and, through TetGen, any closed
  triangular surface into cells.

## Installation

```bash
pip install magpylib-material-response
```

Tetrahedral meshing of `TriangularMesh` magnets requires the optional
[TetGen](https://tetgen.pyvista.org/) dependency:

```bash
pip install magpylib-material-response[tetgen]
```

## Minimal example

```python
import magpylib as magpy
from magpylib_material_response.demag import apply_demag
from magpylib_material_response.meshing import mesh_Cuboid

# a magnet with finite susceptibility, SI units (m, T)
magnet = magpy.magnet.Cuboid(polarization=(0, 0, 1), dimension=(1e-3, 1e-3, 1e-3))
magnet.susceptibility = 0.3  # µr = 1.3

# mesh into cells and solve; the result is a field source like any other
mesh_demag = apply_demag(mesh_Cuboid(magnet, target_elems=125))
print(magpy.getB(mesh_demag, (0, 0, 1.5e-3)))
```

See the [documentation](https://magpylib-material-response.readthedocs.io/) for
a quickstart, worked examples, and the method description.
