Convergence Issues with Object-based Formulation

I am working on an elastodynamic simulation system (FEniCS-x, in Docker Jupyter-Lab, DOLFIN-x Real) where individual objects are Python objects, with the functions and weak form of each object contained within the object. Right now I have one elastic body contacting two rigid bodies. When I run the simulation outside of a OOP formulation, it runs fine and converges well (with tuning of the time step), but when I run the same simulation (same weak form, same contact model, same parameters) in the OOP formulation, the simulation fails to converge once where are any body forces or non-zero contact forces (RuntimeError: Newton solver did not converge because maximum number of iterations reached).

Are there particular considerations that need to be taken if you are solving FEniCS-x problems within an OOP formulation? Are there issues with the OOP formulation because of the FEniCS-x C++ backend?

I can post an example code, but because of the elastodynamics and contact mechanics, it would be a pretty lengthy example.

Any help would be greatly appreciated!

No. There should be no concerns. Many projects are built using dolfinx with an object oriented design.

I would take care with your memory management within python, avoid star imports, be careful of variable shadowing and so on.

If you happen to locate a reproducible memory leak or similar, feel free to raise an issue.

Hi @nate! Thank you for your feedback and advice. I looked through and didn’t find any memory issues. It turns out that a implementation that I thought was equivalent improperly linked some of the fem.Functions, so I think they were being improperly updated and utilized in the update steps (only realized this after reimplementing the OOP formulation). I will keep your comments in mind as I move forward, but as of now the OOP formulation is working properly!

1 Like