Magnetic Field Modeling
Magnetic-Field-Modeling
Collections of MATLAB scripts and functions for the design of systems comprising cylindrically magnetized objects.
Capability of the functions present in the repository:
- Computation of Magnetic Field and Magnetic Field Gradient for cylindrical and ring permanent magnets with arbitrary and uniform magnetization (e.g., Axially and Diametrically magnetized cylinders as special cases), or equivalently of axial solenoids. These functions can be used for the computation of the Torques and Forces (Field and Field Gradient, respectively) applied by a permanent magnet cylinder to a magnetic dipole.
- Computation of Forces and Torques between coaxial permanent magnets cylinders with axial or diametric magnetization.
- Visualization functions for the magnetic field and field gradient.
Notes: The expressions implemented in this library are based on the fundamental assumption of uniform magnetization, that is an excellent approximations for magnets made up of modern, high-grade magnetic materials, like SmCo, NdFeB or ferrites with susceptibilities <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\chi &lt; 0.1$</math-renderer> . The main advantage over common numerical methods such as finite element (FE) approaches or direct numerical integration is the fast computation times of the order of microseconds, which enables highly efficient multivariate parameter space analysis and solving global optimization problems for permanent magnet arrangements.
Repo description at a glance:
- directory "00 - Older Versions": contains functions of the first repo version. They can compute the field of axial magnets and rings
- directory "01 - Permanent Magnet Cylinders and Rings": contains functions for force and torque between coaxial cylinders (having same magnetization direction)
- directory "04 - Graphics": contains functions to visualize field components of cylindrical magnets with arbitrary magnetization
- directory "05 - Numerical Recipes": is a convenient folder containing useful functions from Elfun18 library for numerical computation of special functions
- directory "11 - Parallel Library": contains functions to compute field and gradient using vector operations only (for speed up).
Magnetic Field and Gradient of cylindrical magnets
The present code computes of the magnetic field <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{H}$</math-renderer>, as well as its gradient <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\nabla\mathbf{H}$</math-renderer>, at a generic point <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{P}$</math-renderer> either outside or within the magnet. These quantities are computed analytically solving the governing equations for magnetostatics in the absence of free currents, namely <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$$\nabla \times \mathbf{H} = 0\mbox{ }, \quad \nabla \cdot \mathbf{B} = 0\mbox{ },$$</math-renderer> with <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{B}$</math-renderer> representing magnetic induction, which is related to <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{H}$</math-renderer> and to the (local medium) magnetization <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{M}$</math-renderer> by <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{B} = \mu_0(\mathbf{H} + \mathbf{M} )$</math-renderer>, where <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mu_0 = 4\pi \cdot 10^{-7} \mbox{ T m A}^{-1}$</math-renderer> denotes vacuum magnetic permeability. Once introduced the magnetostatic scalar potential <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\varphi$</math-renderer>, such that, <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{H} = -\nabla \varphi$</math-renderer>, whence <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\Delta\varphi = -\nabla\cdot\mathbf{H}$</math-renderer>, the remaining governing equation reads: <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$$\nabla^2\varphi = \nabla \cdot \mathbf{M}\mbox{ }.$$</math-renderer> Its solution, based on the assumed uniform magnetization <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{M}_{\star}$</math-renderer>, formally reads: <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$$\varphi(\mathbf{P}) = \frac{1}{4\pi}\int_{\mathrm{S}} \frac{\mathbf{M}_{\star} \cdot \hat{\mathbf{n}}}{\lVert\mathbf{P}-\mathbf{P}'\rVert}\mbox{ } \mathrm{d} \mathrm{S}^\prime,$$</math-renderer> where <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathrm{S}=\mathrm{S_t}\cup\mathrm{S_b}\cup\mathrm{S_l}$</math-renderer> denotes the surface of the cylindrical magnet (union of top, bottom and lateral surfaces, respectively) and <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\hat{\mathbf{n}}$</math-renderer> denotes the (outer) normal at the running point <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{P}'$</math-renderer> on the cylinder surface.
Last equation and its derivatives (up to second order) were solved to obtain all the components of <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{H}$</math-renderer> and <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\nabla\mathbf{H}$</math-renderer> in cylindrical coordinates, recasting them in terms of the Bulirsch integral <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mbox{cel}$</math-renderer> and the Normalized Heuman Lambda function <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\Lambda$</math-renderer>, <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$$\mbox{cel}(k_c,p,a,b) = \int_0^{\pi/2} \frac{a \cos^2(\psi) + b \sin^2(\psi)}{\left(\cos^2(\psi) + p \sin^2(\psi)\right) \mbox{ } \sqrt{\cos^2(\psi)+k_c^2 \sin^2(\psi)}}\mbox{ } \mathrm{d}\psi$$</math-renderer> <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$$\Lambda(\sigma^2,k) = \sqrt{\tilde{p}\sigma^2} \mbox{ } \mbox{cel}(k_c,\tilde{p},1,k_c^2)\mbox{ }, \quad \tilde{p} = \frac{1 - \sigma^2 k_c^2}{1 - \sigma^2}\mbox{ }.$$</math-renderer> The use of these two functions allow to achieve a fast computation without encurring into representation singularities. These expressions could be used also in the computation of the magnetic force <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{F}$</math-renderer> and torque <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{T}$</math-renderer> exerted by a cylindrical magnet on a dipole, with magnetic moment <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{m}$</math-renderer>, according to the expressions: <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$$\mathbf{F}=\mu_0\left(\nabla\mathbf{H}\cdot\mathbf{m}\right)\mbox{ }, \quad \mathbf{T}=\mu_0\left(\mathbf{m}\times \mathbf{H}\right)$$</math-renderer>.
Magnetic Force and Torque between coaxial cylindrical magnets
The code provides also analytical models for force and torque between two coaxial cylinders, namely C1 (radius <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathrm{R}_1$</math-renderer>, height <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$2\mathrm{L}_1$</math-renderer>, magnetization <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{M}_1$</math-renderer>) and C2 (radius <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathrm{R}_2$</math-renderer>, height <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$2\mathrm{L}_2$</math-renderer>, magnetization <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{M}_2$</math-renderer>), at a relative distance (between magnets centers) <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathrm{d} \ge \mathrm{L}_1 + \mathrm{L}_2$</math-renderer>. Force and torque exerted by C1 on C2 can be respectively computed as follows: <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$$\mathbf{F}_{1\to 2}=\mu_0\int_{V_2} \nabla\mathbf{H}_1 \cdot \mathbf{M}_2\mbox{ } \mathrm{d}V\mbox{ },$$</math-renderer> <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$$\mathbf{T}_{1\to 2}=\mu_0\int_{V_2} \Big( (\mathbf{P} - \mathbf{O}_1) \times (\nabla\mathbf{H}_1 \cdot \mathbf{M}_2)+ \mathbf{M}_2\times\mathbf{H}_1 \Big)\mbox{ }\mathrm{d}V\mbox{ } ,$$</math-renderer> where (subscripts are understood and) <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$V_2$</math-renderer> denotes the volume occupied by C2. The code implements the solutions of the two above-mentioned equations in case of axial magnetizations: <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{M}_1 = \mathbf{M}_{\parallel1}$</math-renderer> and <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{M}_2 = \mathbf{M}_{\parallel2}$</math-renderer>, thus computing only the corresponding force <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{F}^\parallel_{1\to2}$</math-renderer> (torque being null, by symmetry), and in the case of diametric magnetizations: <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{M}_1 = \mathbf{M}_{\bot1}$</math-renderer>, <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{M}_2 = \mathbf{M}_{\bot2}$</math-renderer>, having a generic relative angular shift <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\theta$</math-renderer>, thus computing the related force <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{F}^\bot_{1\to2}$</math-renderer> and torque <math-renderer class="js-inline-math" style="display: inline" data-static-url="https://github.githubassets.com/static" data-run-id="29dff8e969de6d61458c3def0e94f07f">$\mathbf{T}^\bot_{1\to2}$</math-renderer>.
Additional information on the models will be provided soon ...
Cite As
Federico Masiero (2024). Magnetic Field Modeling (https://github.com/ApeParrot/Magnetic-Field-Modeling), GitHub. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Mathematics and Optimization > Mapping Toolbox > Map Display >
- Radar > Mapping Toolbox > Map Display >
Tags
Acknowledgements
Inspired by: elfun18, Magnetic fields of solenoids and magnets
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
00 - Older Versions/Demos
00 - Older Versions/Functions and Scripts
01 - Permanent Magnet Cylinders and Rings/Forces and Torque
04 - Graphics
05 - Numerical Recipes
11 - Parallel Library
Versions that use the GitHub default branch cannot be downloaded
Version | Published | Release Notes | |
---|---|---|---|
2.0.0 | Robust implementation of the field computation that avoid some elliptic integral singularities. Gradient, Force and Torque added. |
|
|
1.0.0 |
|