Lagrange multiplier-y learning time

After the immensely-practical torque calculation series, let’s do something completely different: intricacies of numerical analysis. Yay!

Are you familiar with Lagrange multipliers? Besides their obvious use in optimization, they are also quite handy in finite element analysis. Like in optimization, their purpose in FEA is enforcing boundary conditions and other constraints. However, to get correct results, it’s kinda important that you don’t just blindly throw them into the mix.

Unfortunately, the mix often ends up looking like this.

Sliding interface

I first came across them in an electric motor simulation. They were used to enforce continuity between separate stator and rotor meshes, across a so-called sliding interface. The continuity was defined based on something called the polynomial interpolation method, but that’s not important right now. What is important is that the continuity condition looked like something as simple as

\mathbf{I} \mathbf{a}_\mathrm{r} = \mathbf{P} \mathbf{a}_\mathrm{s}.

In other words, the potential on rotor-side of airgap was set to equal to stator-side.

In addition, the basic FEA equation of

\begin{bmatrix} \mathbf{S}_\mathrm{s} & \mathbf{0} \\ \mathbf{0} & \mathbf{S}_\mathrm{r} \end{bmatrix} \begin{bmatrix} \mathbf{a}_\mathrm{s} \\ \mathbf{a}_\mathrm{r} \end{bmatrix} = \begin{bmatrix} f_\mathrm{s} \\ f_\mathrm{r} \end{bmatrix}

of course had to be satisfied.

Now, I was in a hurry to get things done, so I dug only a little deeper. I found out that I could simply introduce new variables (let’s call them \gamma), and solve the following system instead

\begin{bmatrix} \mathbf{S}_\mathrm{s} & \mathbf{0} & \mathbf{P}^\mathrm{T} \\ \mathbf{0} & \mathbf{S}_\mathrm{r} & -\mathbf{I}^\mathrm{T} \\ \mathbf{P} & -\mathbf{I} & \mathbf{0} \end{bmatrix} \begin{bmatrix} \mathbf{a}_\mathrm{s} \\ \mathbf{a}_\mathrm{r} \\ \mathbf{\gamma} \end{bmatrix} = \begin{bmatrix} \mathbf{f}_\mathrm{s} \\ \mathbf{f}_\mathrm{r} \\ \mathbf{0} \end{bmatrix}.

That worked, so I mentally filed it under ‘Matrix Magic’ and never thought about it until much, much later.

By the way, that’s exactly the very same sliding interface condition that I mentioned in the numerical torque computation post.

Things occasionally go wrong with the sliding interface, by the way.
3D analysis

That time came when I was considering some 3D analysis, using the vector potential (\mathbf{A}) formulation. To get a unique solution, the following gauge condition should be satisfied

\nabla \cdot \mathbf{A} = 0.

I happened to know that an easy way to achieve this would be with Lagrange multipliers, again. So, it’d make sense that the final matrix equation would look like

\begin{bmatrix} \mathbf{S} & \mathbf{C}^\mathrm{T} \\ \mathbf{C} & \mathbf{0} \end{bmatrix} \begin{bmatrix} \mathbf{a} \\ \mathbf{\gamma}\end{bmatrix} = \begin{bmatrix} \mathbf{f} \\ \mathbf{0} \end{bmatrix}.

In other words, simply add the constraint equation \nabla \cdot \mathbf{A} = 0 in matrix form, and then some matrix \mathbf{C} to couple them together. This is how it would work, right?


Except it wouldn’t.


Now that’s the question.

Physical meaning of lil-L

And to understand that, we have dig deeper into the physical meaning of, well, everything. So not simply Matrix Magic anymore – yuck!

Let’s begin with the gauge condition \nabla \cdot \mathbf{A} = 0.

It’s there because the vector potential isn’t unique in 3D. We can add any gradient of a scalar potential u to it

\mathbf{A} \leftarrow \mathbf{A} + \nabla u

and still get the same field solution \mathbf{B} = \nabla \times \mathbf{A}.

It other words, \mathbf{A} can be thought to contain an unknown gradient field.

Now, the correct approach is to include this gradient field as an unknown – to solve both \mathbf{A} and uand then require that their sum satisfies the gauge condition

\nabla \cdot ( \mathbf{A} + \nabla u)= 0.

By looking at the two equations, it’s quite easy to guess that the resulting matrix equation will look like

\begin{bmatrix} \mathbf{S} & \mathbf{C}^\mathrm{T} \\ \mathbf{C} & \mathbf{G} \end{bmatrix} \begin{bmatrix} \mathbf{a} \\ \mathbf{u}\end{bmatrix} = \begin{bmatrix} \mathbf{f} \\ \mathbf{0} \end{bmatrix}.

So, we have an extra block \mathbf{G} in the lower right corner.

Furthermore, now we understand why everything is as it is. The Lagrance multipliers (now called \mathbf{u}!) aren’t an artificial constraint anymore. Instead, they directly define a potential u, in effect cancelling out the gradient part hidden inside A.

Original example

So, how does this relate to out original example

\begin{bmatrix} \mathbf{S}_\mathrm{s} & \mathbf{0} & \mathbf{P}^\mathrm{T} \\ \mathbf{0} & \mathbf{S}_\mathrm{r} & -\mathbf{I}^\mathrm{T} \\ \mathbf{P} & -\mathbf{I} & \mathbf{0} \end{bmatrix} \begin{bmatrix} \mathbf{a}_\mathrm{s} \\ \mathbf{a}_\mathrm{r} \\ \mathbf{\gamma} \end{bmatrix} = \begin{bmatrix} \mathbf{f}_\mathrm{s} \\ \mathbf{f}_\mathrm{r} \\ \mathbf{0} \end{bmatrix}?

Well, it turns out the multipliers \gamma have a clear physical meaning there as well. Specifically, they add an additional H_\mathrm{t} – tangential component of the magnetic field on the airgap boundaries of the stator and rotor. Hence the appearance of the matrices \mathbf{P} and \mathbf{I} on the first two rows of the linear system.

Moreover, the tangential field is defined to be such that the solution is then continuous over the airgap interface. Thus the third, extra row.

Wondering why get the relatively weird tangential field? That’s simply a peculiarity of the vector potential. For many other problems, we’d see a normal component – such as a heat flux for thermal problems, or a boundary force (Łukasz might have a word or two to say about my choice of term – sorry!) for mechanics.

Another case

Analysing an electric machine with circuit connections? Whether you know it or not (still using black-box commercial software?), some voltages are being solved along with the field quantities. And know what, these voltages are are in fact nothing more than Lagrange multipliers for the field problem.


  • Lagrange multipliers are a handy way of adding constraints to an FEA problem.
  • Despite their misleading name, the multipliers do indeed have a physical meaning, too.
  • Blindly adding constraints (ignoring the point above) can lead to an incorrect solution.

Need help with electric motor design or design software? Let's get in touch - satisfaction guaranteed!
Lagrange multipliers and their physical meaning

5 thoughts on “Lagrange multipliers and their physical meaning

  • Hi,

    Interesting post. I am curious is it the same way periodic boundary conditions can be enforced.
    For eg. In machines antiperiodic boundary conditions are let say a1=p* a2 . Here for anti periodicity p=-1. (provided node positions are similar). However in case of a random mesh at boundaries it can p will be some matrix. Will it be used as langrange multiplier?

    1. Hi Ravi, periodicity conditions can indeed also be enforced with Lagrange multipliers.

      And yes, P will indeed be a matrix if the nodes on the two boundaries won’t match 1-on-1. Or, to be precise, it will be a matrix in any case – but with matching nodes it will simply be a permuted identity matrix with zero columns. It’s probably easiest to understand with Matlab notation:

      Let n_periodic_1 and n_periodic_2 be the indices of the nodes on the two periodic boundaries (ordered so that they match 1-on-1), and n = numel(n_periodic_1), and N = number of total nodes. Then, following the notation in the Sliding interface paragrap, the matrices are as follows:

      I = sparse(1:n, n_periodic_1, ones(1, n), n, N)
      P = sparse(1:n, n_periodic_2, periodicity_coeff*ones(1,n), n, N)

      Now, in case the nodes don’t match, I will still be the same, but P will be a more complex interpolation or mortar matrix.

      Hope that clarified something 😀

    2. Ravi, you can have a look at this paper:
      M. Aubertin et al. “Periodic and Anti-Periodic Boundary Conditions With the Lagrange Multipliers in the FEM”, IEEE Trans. Magn., v. 46, no. 8

      They describe the use of Lagrange multiplier approach to periodic boundary conditions quite detailed.

Leave a Reply

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