Comment my code + many questions

I would suggest using class structures.
Then you can have different functions applying appropriate boundary conditions.
Also keep in mind that the only thing that should differ in the core of your variational formulation is the mesh/function space, the UFL forms should be the same in 1D/2D/3D.

Oasisx (disclaimer Im the author) GitHub - ComputationalPhysiology/oasisx: Next generation Open Source Navier Stokes solver using FEniCSx
is an example of how to re-use the variational formulation for different problems.

See for instance: Default absolute tolerance and relative tolerance - #4 by nate

I would strongly suggest you try to simplify your problem to illustrate this issue.
If you won’t simplify it, you should really be careful about the integration by parts of your problem, making sure that you are not missing a sign in the transformations. Additionally, when you say the code seem to find some “zero” voltage by itself, you should look at the equation you are now solving.

Again, using classes, and boolean inputs to either:

  1. Add terms to your variational form
  2. Add a c=dolfinx.fem.Constant(mesh, value) to your variational form (i.e. F += c*joule_heating_terms), where value is 0 or 1 depending on if you want to add the effect or not.

I do not have time to go through your code in detail, but I would strongly suggest you to start small, and take out simple parts of your code that you can re-use, and make up a general structure as you go.

1 Like