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
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.