Adding Non-Meshed Variables to FEM Formulations

I am working on a magnetostatic FEM formulation that includes a model of an electromagnetic coil. The key idea is to specify the current inside the coil as a single parameter in the simulation, and this parameter is defined through the applied voltage and induced back-emf and is added as a additional equation which is solved simultaneously in the same matrix as the finite elements.

In essence, the weak formulation of the magnetic field with a coil is given by,
\int_\Omega \frac{1}{\mu} \nabla \vec{A} \nabla \vec{u} \space d\Omega + I \int_{\Omega_c} \vec{w} \cdot \vec{u} \space d\Omega = 0
where I is an external, unknown scalar variable shared across the simulation. \vec A is the trial function and \vec u is the test function. \mu and \vec w are functions defined on the mesh.

Additionally, the voltage of the coil is expressed by
V = R\cdot I + \int_{\Omega_c} \vec w \frac{d\vec A}{dt} \cdot \vec u \space d\Omega
Where V (voltage), and R (resistance), is known.

To solve this in a FEM framework you could add the extra equation as a row at the end of the matrix. Something like this

\begin{pmatrix} \frac{1}{\mu} \nabla \vec{u}_0 \nabla \vec{v}_0 & \frac{1}{\mu} \nabla \vec{u}_1 \nabla \vec{v}_0 & \dots & \frac{1}{\mu} \nabla \vec{u}_i \nabla \vec{v}_0 & \int_{\Omega_c} \vec{w} \cdot \vec{v}_0 \\ \vdots & \vdots & \vdots \\ \frac{1}{\mu} \nabla \vec{u}_0 \nabla \vec{v}_j & \frac{1}{\mu} \nabla \vec{u}_1 \nabla \vec{v}_j & \dots & \frac{1}{\mu} \nabla \vec{u}_i \nabla \vec{v}_j & \int_{\Omega_c} \vec{w} \cdot \vec{v}_j\\ \vec w \frac{d\vec u_0}{dt} \cdot \vec v_j & \vec w \frac{d\vec u_1}{dt} \cdot \vec v_j & \dots & \vec w \frac{d\vec u_i}{dt} \cdot \vec v_j & R \\ \end{pmatrix} \cdot \begin{pmatrix} A_0 \\ A_1 \\ \vdots \\ A_j \\ I \\ \end{pmatrix} = \begin{pmatrix} 0 \\ \vdots \\ 0 \\ V \\ \end{pmatrix}

However, it fails me to see how I can implement this into the form compilation framework in Dolfinx. It is, as far as I could understand, no way to specify a variable that is not defined on a functionspace and a mesh. Alternatively, I could manually assemble the matrix afterwards, but I cannot figure out how to do that either, as I would need access to the correct rows and columns.

This should work with using the finite element of «reals», see
https://scientificcomputing.github.io/scifem/examples/real_function_space.html

Thank you, this might work. The naming is a bit confusing, but I found under the old dolfin documentation that the “Real” function space has one global degree of freedom, which is exactly what I need. Maybe we could add that bit of information to the Scifem documentation.

Feel free to contribute additional documentation to scifem.

We have considered to call it “the finite element function space over scalars” to emphasize that the space can have complex valued unknowns