Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d55b447

Browse files
committed
Merge branch 'main' of https://github.com/magpylib/magpylib into show-sensor-pixel-field
2 parents f5d62f3 + 0647b66 commit d55b447

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+550
-106
lines changed

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 0 additions & 51 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/feature_request.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/question_magnetics.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
# Related Issues
2-
3-
# Notes
4-

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.6.0
3+
rev: v5.0.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
@@ -25,7 +25,7 @@ repos:
2525

2626

2727
- repo: https://github.com/psf/black
28-
rev: "24.8.0"
28+
rev: "24.10.0"
2929
hooks:
3030
- id: black
3131

CHANGELOG.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
# Changelog
22

33
## [Unreleased] - YYYY-MM-DD
4+
5+
## [5.1.1] - 2024-10-31
6+
- Included magpylib-force version 0.3.1 in documentation
7+
- Removed unused issue templates and improved PR template
8+
9+
## [5.1.0] - 2024-10-09
10+
- Fixed a bug where the magnetization arrow graphical representation would be anchored badly after rotation ([#805](https://github.com/magpylib/magpylib/issues/805))
411
- Added `units_length` input to the `show` function to allow displaying axes with different length units. This parameter can be set individually for each subplot. ([#786](https://github.com/magpylib/magpylib/pull/786))
512
- Small documentation and Readme improvement. Change naming from "explicit expression" to "analytical expression" as described in ([#794](https://github.com/magpylib/magpylib/issues/794)).
613
- Fixed Pvyvista plot bounds not fitting on animation. Also enables `zoom` feature which was not working until now. ([#798](https://github.com/magpylib/magpylib/pull/798))
714
- Fixed canvas layout being modified even when user-provided. Also added a new `canvas_update` parameter to choose the layout behavior (by default `"auto"`) ([#799](https://github.com/magpylib/magpylib/pull/799))
8-
- Improved documentation ([#766](https://github.com/magpylib/magpylib/issues/766))
15+
- Improved documentation ([#766](https://github.com/magpylib/magpylib/issues/766), [#802](https://github.com/magpylib/magpylib/issues/802))
16+
- Documentation now includes force computation, which is still in a separate package "magpylib-force", but which will be integrated into Magplyib in the coming months. ([#787](https://github.com/magpylib/magpylib/issues/787))
917

1018
## [5.0.4] - 2024-06-18
1119
- Added support for Numpy 2.0 ([#795](https://github.com/magpylib/magpylib/pull/789))
@@ -476,7 +484,9 @@ The first official release of the Magpylib library.
476484

477485
---
478486

479-
[Unreleased]:https://github.com/magpylib/magpylib/compare/5.0.4...HEAD
487+
[Unreleased]:https://github.com/magpylib/magpylib/compare/5.1.1...HEAD
488+
[5.1.1]:https://github.com/magpylib/magpylib/compare/5.1.0...5.1.1
489+
[5.1.0]:https://github.com/magpylib/magpylib/compare/5.0.4...5.1.0
480490
[5.0.4]:https://github.com/magpylib/magpylib/compare/5.0.3...5.0.4
481491
[5.0.3]:https://github.com/magpylib/magpylib/compare/5.0.2...5.0.3
482492
[5.0.2]:https://github.com/magpylib/magpylib/compare/5.0.1...5.0.2

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</a>
2121
<a href="https://anaconda.org/conda-forge/magpylib"> <img src="https://anaconda.org/conda-forge/magpylib/badges/version.svg" alt="Conda Cloud" height="18">
2222
</a>
23-
<a href="https://mybinder.org/v2/gh/magpylib/magpylib/5.1.0dev?filepath=docs%2Fexamples"> <img src="https://mybinder.org/badge_logo.svg" alt="MyBinder link" height="18">
23+
<a href="https://mybinder.org/v2/gh/magpylib/magpylib/5.1.1?filepath=docs%2Fexamples"> <img src="https://mybinder.org/badge_logo.svg" alt="MyBinder link" height="18">
2424
</a>
2525
<a href="https://github.com/psf/black"> <img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="black" height="18">
2626
</a>
@@ -42,7 +42,7 @@ Magpylib supports _Python3.10+_ and relies on common scientific computation libr
4242

4343
# Resources
4444

45-
- Check out our **[Documentation](https://magpylib.readthedocs.io/en/latest)** for detailed information.
45+
- Check out our **[Documentation](https://magpylib.readthedocs.io/en/stable)** for detailed information about the last stable release, or the **[Dev Docs](https://magpylib.readthedocs.io/en/latest)** to see the unreleased development version features.
4646
- Please abide by our **[Code of Conduct](https://github.com/magpylib/magpylib/blob/main/CODE_OF_CONDUCT.md)**.
4747
- Contribute through **[Discussions](https://github.com/magpylib/magpylib/discussions)** and coding by following the **[Contribution Guide](https://github.com/magpylib/magpylib/blob/main/CONTRIBUTING.md)**. The Git project **[Issues](https://github.com/magpylib/magpylib/issues)** give an up-to-date list of potential enhancements and planned milestones. Propose new ones.
4848
- A **[Youtube video](https://www.youtube.com/watch?v=LeUx6cM1vcs)** introduction to Magpylib v4.0.0 within the **[GSC network](https://www.internationalcollaboration.org/).**
@@ -105,7 +105,7 @@ print(B.round(2)) # --> [[-0.12 -0.04 -0.02]
105105
magpy.show(cube, sensor, backend="pyvista")
106106
```
107107

108-
More details and other important features are described in detail in the **[Documentation](https://magpylib.readthedocs.io/en/latest)**. Key features are:
108+
More details and other important features are described in detail in the **[Documentation](https://magpylib.readthedocs.io/en/stable)**. Key features are:
109109

110110
- **Collections**: Group multiple objects for common manipulation
111111
- **Complex shapes**: Create magnets with arbitrary shapes
@@ -136,7 +136,7 @@ A valid software citation could be
136136
author = {{Michael-Ortner et al.}},
137137
title = {magpylib},
138138
url = {https://magpylib.readthedocs.io/en/latest/},
139-
version = {5.1.0dev},
139+
version = {5.1.1},
140140
date = {2023-06-25},
141141
}
142142
```
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
orphan: true
3+
jupytext:
4+
text_representation:
5+
extension: .md
6+
format_name: myst
7+
format_version: 0.13
8+
jupytext_version: 1.13.7
9+
kernelspec:
10+
display_name: Python 3
11+
language: python
12+
name: python3
13+
---
14+
15+
(docs-magpylib-force)=
16+
# Magpylib Force v0.3.1
17+
18+
The package `magpylib-force` provides an addon for magnetic force and torque computation between magpylib source objects.
19+
20+
## Installation
21+
22+
Install `magpylib-force` with pip:
23+
24+
```console
25+
pip install magpylib-force
26+
```
27+
28+
## API
29+
30+
The package provides only a single top-level function <span style="color: orange">**getFT()**</span> for computing force and torque.
31+
32+
```python
33+
import magpylib_force as mforce
34+
mforce.getFT(sources, targets, anchor, eps=1e-5, squeeze=True)
35+
```
36+
37+
Here `sources` are Magpylib source objects that generate the magnetic field. The `targets` are the objects on which the magnetic field of the sources acts to generate force and torque. With current version 0.3.1 only `Cuboid`, `Cylinder`, `CylinderSegment`, `Polyline`, and `Circle` objects can be targets. The `anchor` denotes an anchor point which is the barycenter of the target. If no barycenter is given, homogeneous mass density is assumed and the geometric center of the target is chose as it's barycenter. `eps` refers to the finite difference length when computing the magnetic field gradient and should be adjusted to be much smaller than size of the system. `squeeze` can be used to squeeze the output array dimensions as in Magpylib's `getB`, `getH`, `getJ`, and `getM`.
38+
39+
The computation is based on numerically integrating the magnetic field generated by the `sources` over the `targets`, see [here](docs-force-computation) for more details. This requires that each target has a <span style="color: orange">**meshing**</span> directive, which must be provided via an attribute to the object. How `meshing` is defined:
40+
41+
For all objects as an integer, which defines the target number of mesh-points. In some cases an algorithm will attempt to come close to this number by splitting up magnets into quasi-cubical cells. Exceptions are:
42+
43+
- `Cuboid`: takes also a 3-vector that defines the number of equidistant splits along each axis resulting in a rectangular regular grid. Keep in mind that the accuracy is increased by cubical aspect ratios.
44+
- `PolyLine`: defines the number of equidistant splits of each PolyLine segment, not of the whole multi-segmented object. The total number of mesh-points will be number of segments times meshing.
45+
46+
The function `getFT()` returns force and torque as `np.ndarray` of shape (2,3), or (t,2,3) when t targets are given.
47+
48+
The following example code computes the force acting on a cuboid magnet, generated by a current loop.
49+
50+
```python
51+
import magpylib as magpy
52+
import magpylib_force as mforce
53+
54+
# create source and target objects
55+
loop = magpy.current.Circle(diameter=2e-3, current=10, position=(0,0,-1e-3))
56+
cube = magpy.magnet.Cuboid(dimension=(1e-3,1e-3,1e-3), polarization=(1,0,0))
57+
58+
# provide meshing for target object
59+
cube.meshing = (5,5,5)
60+
61+
# compute force and torque
62+
FT = mforce.getFT(loop, cube)
63+
print(FT)
64+
# [[ 1.36304272e-03 6.35274710e-22 6.18334051e-20] # force in N
65+
# [-0.00000000e+00 -1.77583097e-06 1.69572026e-23]] # torque in Nm
66+
```
67+
68+
```{warning}
69+
[Scaling invariance](guide-docs-io-scale-invariance) does not hold for force computations! Be careful to provide the inputs in the correct units!
70+
```
71+
72+
(docs-force-computation)=
73+
## Computation details
74+
75+
The force $\vec{F}_m$ acting on a magnetization distribution $\vec{M}$ in a magnetic field $\vec{B}$ is given by
76+
77+
$$\vec{F}_m = \int \nabla (\vec{M}\cdot\vec{B}) \ dV.$$
78+
79+
The torque $\vec{T}_m$ which acts on the magnetization distribution is
80+
81+
$$\vec{T}_m = \int \vec{M} \times \vec{B} \ dV.$$
82+
83+
The force $\vec{F}_c$ which acts on a current distribution $\vec{j}$ in a magnetic field is
84+
85+
$$\vec{F}_c = \int \vec{j}\times \vec{B} \ dV.$$
86+
87+
And there is no torque. However, one must not forget that a force, when applied off-center, adds to the torque as
88+
89+
$$\vec{T}' = \int \vec{r} \times \vec{F} \ dV,$$
90+
91+
where $\vec{r}$ points from the body barycenter to the position where the force is applied.
92+
93+
The idea behind `magplyib-force` is to compute the above integrals by discretization. For this purpose, the target body is split up into small cells using the object `meshing` attribute. The force and torque computation is performed for all cells in a vectorized form, and the sum is returned.

0 commit comments

Comments
 (0)