How Do I Use Gauge Fixing in COMSOL Multiphysics®?

In the previous blog post, What Is Gauge Fixing? A Theoretical Introduction, we gave a theoretical background to gauge fixing; that is, why and when it is required. Here, we continue to discuss its implementation and how to use it in the context of the COMSOL Multiphysics® software.

The Short Guide to Gauge Fixing: Generally Not Necessary

In our previous blog post, we introduced three potentials that are used to formulate some of the physics interfaces in the AC/DC Module; i.e., the electric scalar potential , the magnetic scalar potential , and the magnetic vector potential .

We have shown that unless reference levels for and are defined and is specified, the potentials are not uniquely determined. When the solution is not unique, the numerical problem to be solved is singular. In that case, COMSOL Multiphysics defaults to using an iterative solver that will converge to a solution; which one does not matter as all yield the same physical fields (, , , or — depending on context).

Check out this Knowledge Base entry to understand the difference between the iterative and direct solvers.

In the AC/DC Module, an add-on to COMSOL Multiphysics, there are three physics interfaces that solve for the field:

  1. Magnetic Fields (mf), which is based on the formulation and where is the only dependent variable. In statics, this solution is not unique without gauge fixing, whereas in dynamics, additional terms of inductive origin make the solution unique, provided those terms are numerically significant.
  2. Magnetic and Electric Fields (mef), which solves the fully coupled and fields. Due to the gauge transformation, there is no unique solution unless is specified.
  3. Rotating Machinery, Magnetic (rmm), a combination of the formulation and formulation. The formulation is used to model conductive (current-carrying) domains, and the formulation is used for the air gap and other nonconducting domains. The two formulations are coupled on their common interfacing boundaries. Since the rmm interface is a mixed formulation, the comments on gauge fixing for the Magnetic Fields (mf) interface apply.

As a summary, the table below lists the properties of the solution and required numerical solver for the mf, mef, and rmm interfaces and for different study types without gauge fixing. Due to the default iterative solvers for these three interfaces, gauge fixing is generally not necessary.

Interface, Attribute Stationary Time Dependent, Time Dependent, Frequency Domain,
mf, rmm
Nonunique Nonunique Unique Unique
mf, rmm
Iterative only Iterative only Iterative or direct Iterative or direct
Nonunique Covered by the usage of the mf interface Covered by the usage of the mf interface Nonunique
Iterative only Covered by the usage of the mf interface Covered by the usage of the mf interface Iterative only

It is worth mentioning that even in the case when the potentials lack unique solutions, the physical fields and are always unique. The potentials are not directly measurable and have no direct physical meaning, so for the potentials, any solution fulfilling the equations will do.

As an illustration, take the Inductance of a Power Inductor model available in the Application Library. The model is built with the mef interface and solved in the frequency domain; first without gauge fixing and then with gauge fixing.

As shown in the figure below, the field differs significantly, while the norm of the field is invariant as expected. The top-right figure shows a field that varies smoothly in the domain when gauge fixing is applied. This is quite different from the field without gauge fixing, as shown in the top-left figure. It is interesting to notice that we call this gauge () the “Coulomb gauge” because it enforces a field that behaves like the Coulomb potential, which results from a static electric charge density. As the physical fields and are the same, the computed reactance values also agree.

An image of the electric potential in a power inductor.
Simulation results for electric potential in a power inductor with gauge fixing applied.
COMSOL Multiphysics results for the electric field norm of a power inductor.
An plot of the electric field norm in a power inductor when gauge fixing is used in the simulation.

Figure 1: Comparison of the computed field and field norm in the coil domain solved without gauge fixing (left) and with gauge fixing (right).

Gauge Fixing in the AC/DC Module

Gauge fixing is usually required when the solution of the field is not unique and you want to use a direct solver. Using a direct solver may be required or beneficial in cases involving multiphysics couplings, as iterative solvers and preconditioners typically are tuned for one specific type of physics only. Also, when solving 2D models, direct solvers are used as default.

In the mf, mef, and rmm interfaces, there is a domain feature called Gauge Fixing for A-field. The feature is available except when solving for the out-of-plane vector potential only in 2D and 2D axisymmetry. The Coulomb gauge is then trivially fulfilled as the vector potential is assumed constant in the out-of-plane direction.

The Gauge Fixing for A-field feature introduces a Lagrange multiplier to enforce the Coulomb gauge, resulting in two coupled equations. Let’s use magnetostatics as an example. The first equation (static Ampère’s law) is for and is expressed as


nabla times (frac 1mu nabla times textbfA )= textbfJ + nabla psi

The second equation is for and expresses the Coulomb gauge


nabla cdot textbfA = 0

In Eq. 1, the variable acts similarly to the pressure in the incompressible Navier–Stokes equations, where the pressure enforces the constraint of a divergence-free flow field.

As Eq. 1 shows, the magnitude of does not have particular significance; only its gradient enters the equations (it acts like a potential). The “current-like” term in Eq. 1 closes the set of equations by providing a mechanism for letting affect . To ensure a nonsingular model, it is important to constrain the value of in at least one point. By default, the feature constrains the value of on magnetic insulation boundaries to a value that can be set in the interface by entering the divergence condition variable scaling (default value 1 A/m). The figure below shows the field and the magnitude of the electric field for the power inductor model using different values. As can be seen, the magnitude of does not affect the field.

A plot of the divergence condition variable in a power inductor model with 1 A/m.
Simulation results for the divergence condition variable with the A/m set to 1000.
A plot of the electric field norm for a power inductor with 1 A/m.
COMSOL Multiphysics results for the electric field norm of a power inductor at 1000 A/m.

Figure 2: Comparison of the computed field and field norm in the coil and core domain solved with different scaling; = 1 A/m (left) and = 1000 A/m (right).

It is recommended not to use gauge fixing unless necessary, since it increases the total number of unknowns, requiring more memory and time to solve. Depending on different models, the computation time could increase by 30–60% if gauge fixing is used. It is also worth mentioning that the gauge fixing will result in the system matrix having zeros on the diagonal. The latter is not a problem when using a direct solver, but an iterative solver has to use more expensive methods in the preconditioner (e.g., the Vanka algorithm). Please refer to the COMSOL Reference Manual for details on the solvers. Thanks to the solver defaults normally accounting for the above situations, it is generally not necessary to worry about the change of the structure of the system matrix.

Imposing Current Conservation: Another Role of Gauge Fixing

Current conservation is inherent in Ampère’s law, meaning that the sum of applied source current densities and the induced current density must be solenoidal. This has important consequences when solving Maxwell’s equations. For the static case in the mf interface, the equation to be solved is expressed as


nabla times (frac 1mu nabla times textbfA )= textbfJ

Taking the divergence of both the left- and right-hand side of Eq. 3 yields


nabla cdot (nabla times (frac 1mu nabla times textbfA ))= nabla cdot textbfJ

Notice that the left-hand side of Eq. 4 is zero per definition as for any . Thus, the right-hand side, the divergence of the external source current density, should also be zero, since otherwise the equation has no solution (at all). This causes the variable introduced in Eq. 1 to effectively serve two purposes. Apart from the obvious purpose of enforcing Eq. 2, it also enforces the condition , which is inherent in Eq. 1. In other words, the added term in Eq. 1 will eliminate any divergence from the externally applied current density, making the modified right-hand side comply with the required current conservation. For this reason, unexpected solutions can be produced if gauge fixing is used in combination with an externally applied current density that is not divergence free in the analytical sense. Then the gauge fixing will introduce a nonphysical, large compensational current density in the term and the model will produce unexpected results. This might lead to a misconception and to detect such cases, it is suggested to visualize the field after solving with gauge fixing. The field should only have extremely small variations in the domain where gauge fixing is applied, as shown in the top row of Figure 2. If not, the supplied source current density is most likely not solenoidal as required by Ampère’s law. Here, it is appropriate to add that the default iterative solvers for the stationary solution of the Magnetic Fields (mf) interface perform a similar correction of the supplied source currents so the gauged and ungauged solutions will not be different when it comes to the physical field .

For the dynamic cases in the mf interface (), the solution is unique and constraining is usually not necessary. The mf interface provides an option to switch the gauge fixing from Stationary () to Study controlled, so let’s elaborate more on what that means. In the time-dependent study, the mf interface solves the equation:


sigma frac partial textbfA partial t + nabla times (frac 1mu nabla times textbfA )= textbfJ

It considers the induced conduction current density but ignores the induced displacement current density (so-called quasistatic approximation). In this case, instead of constraining , the study-controlled gauge fixing reduces to help imposing current conservation by enforcing , which is consistent with taking the divergence of Eq. 5. Similarly, for the frequency domain study, which includes both types of induced current densities and is a “full Maxwell formulation”, instead of constraining , the study-controlled gauge fixing enforces . The main benefit of using this kind of divergence constraint is improved numerical stability, especially when approaching the static limit.

Try It Yourself: Experiment with Gauge Fixing

To get a better understanding of gauge fixing, it is helpful to do some experiments by yourself. The table below lists some models in the Application Library that you can solve without and with gauge fixing and then compare the results and computation times. For example, in the E-Core Transformer model, it is solved with gauge fixing with a direct solver and the electrical conductivity is set to zero. You can also solve it with the same direct solver without gauge fixing by setting S/m in all domains and also in the stabilization electrical conductivity for coil domains. You will notice that the model can be solved within about half of the computation time when gauge fixing is used.

Physics Interface Study Type Model in Application Gallery
mf Stationary Helmholtz Coil
Time-Dependent E-core Transformer
Frequency Domain Eddy Currents
mef Frequency Domain Power Inductor
rmm Time Dependent Permanent Magnet Motor


In this blog post, we started by emphasizing that gauge fixing is not necessary in electromagnetics simulations with the AC/DC Module unless you need to use a direct solver. Then we showed how gauge fixing is implemented and used in three related physics interfaces, followed by discussing benefits and drawbacks of gauge fixing. At the end, we provided a list of interesting models that you might want to experiment with.

Leave a Reply

Your email address will not be published. Required fields are marked *