Plotting Spatial Derivatives of the Magnetic Field
Computing the spatial derivative of the magnetic field or magnetic flux density is useful in areas such as radiology, magnetophoresis, particle accelerators, and geophysics. One of the most important use cases is the design of magnetic resonance imaging (MRI) machines, where it is necessary to analyze not only the field strength but also the spatial variation of the field. Today’s blog post demonstrates how to compute and plot the gradients of the magnetic field in electromagnetic simulations in the COMSOL Multiphysics® software.
Editor’s note: This blog post was updated on 1/21/2020 to reflect new functionality and information.
Background and Objective
When you are computing magnetic fields induced by currents, computing electric fields induced by time-varying magnetic fields, or solving 3D electromagnetic wave problems, COMSOL Multiphysics uses so-called curl (vector or Nédélec edge) elements in all three cases. The curl element is also used in 2D and 2D axisymmetric magnetic field simulations that involve in-plane current distributions. Within the AC/DC Module, the curl element is typically used to compute the magnetic vector potential,
Check out the blog post What Is the Curl Element (and Why Is It Used)? for an elaborate introduction to the curl element.
The magnetic flux density
The equations show that the magnetic flux density and the magnetic field are functions of the first-order spatial derivative of the magnetic vector potential. Since the second-order spatial derivative is not defined on curl elements, the gradients of
The technique demonstrated here shows how each component of the magnetic field
Note that when solving for 2D or 2D-axisymmetric magnetic field problems involving out-of-plane currents, or static magnetic field problems without any current flow within the model, the Lagrange elements are used to solve the governing equations, which makes the second-order spatial derivative available. The method shown in this blog post applies only to cases where the curl elements are used to compute the fields.
Step-by-Step Tutorial Using a Helmholtz Coil
Let’s look at an example where we can demonstrate the technique introduced above. We will show how you can compute and plot the spatial derivatives of the magnetic field produced by a Helmholtz coil. A detailed description of this model, along with step-by-step instructions to simulate the coil, can be found in the Application Gallery.
A Helmholtz coil is a pair of parallel circular coils separated by a distance equal to one coil radius where the current through both the coils flows in the same direction. Some known uses of this kind of configuration are canceling Earth’s magnetic field and generating controlled magnetic fields for experiments.
This model uses the Magnetic Fields physics interface and the Coil feature to model the two coils. Each coil has 10 turns and a 0.25-mA current circulating through it.
The magnetic field norm and the magnetic field direction in the Helmholtz coil.
Plotting the Gradients of the Magnetic Field
We will start with the solved example from the Application Gallery and see how we can determine the derivatives of the magnetic field.
The first step is to map the magnetic field on Lagrange elements. For that, we add the Coefficient Form PDE interface with three dependent variables (one per component), which uses the Lagrange element by default. Here, we also set the appropriate units for the dependent variables.
The second step is to correctly set up the coefficients of the PDE, in order to get the appropriate expression for mapping the field components.
We set all coefficients other than “a” and “
Where a = 1,
As a consequence, when solving for this Coefficient Form PDE, the three components of the magnetic field are directly mapped onto the three scalar fields u1, u2, and u3, as follows:
u1 = mf.Hx
u2 = mf.Hy
u3 = mf.Hz
Concerning the study setup, we first compute only the magnetic fields problem in Study 1, and in the second study, we solve for the variables u1, u2, and u3. In order to take the values from the electromagnetic solution, we set the feature Values of variables not solved for using the study settings shown below.
It should be noted that the components of the magnetic field do not map perfectly onto the Lagrange elements, causing a small discrepancy between the two (even at the mesh nodes). It is a mapping, not an identity. Therefore, it is a good practice to check abs(
In order to compute the gradients of the magnetic field, we append to the variable name the spatial direction in which we want to compute the partial derivative. These suffixes for the spatial derivatives are available for all degrees of freedom, and come directly from the shape functions. For example, u1x would compute the gradient of the x-component of the magnetic field with respect to the x direction.
Download the Magnetic Field of a Helmholtz Coil model by clicking the button below, which will take you to the Application Gallery. To download the MPH-file, you need to be logged into a COMSOL Access account and have a valid software license.
Learn more about the features and functionality of COMSOL Multiphysics and the add-on AC/DC Module:
- COMSOL Now
- Today in Science