exasim-project / NeoFOAM

WIP Prototype of a modern CFD core
19 stars 1 forks source link

Python bindings #48

Open greole opened 2 months ago

greole commented 2 months ago

I think adding python bindings early on could be very valuable. Instead of implementing all the orchestration code that is not performance critical in C++ we could do that in python. Advantages:

  1. We could keep this repository focused on only the performance critical implementations comparable to OpenFOAMs libfiniteVolume and libOpenFOAM
  2. I think python development might be a bit faster.

As a consequence, we could implement the for example the runTime in python.

However, one essential question to ask is how we want to treat the physical models. Ideally, physical models like turbulence models could be implemented comfortably in python as well and using the python bindings to the low level GPU capable data-structures. Also, physical models could then be distributed as python packages and be pip installable. Models in python could also work with a runTime and objectRegistry in python. The only hurdles would be acceptance by the community and the increasing the effort of porting models from the OpenFOAM C++ code base.

One advantage of the python route is that we could use Owls which already provides parser for OpenFOAMs dictionaries. Thus, we could with some small extra effort read existing OpenFoam cases. Of course Owls2.0 would need some more work to be merged, but the parsers are already used in the OGL integration tests.

What are your thoughts: @HenningScheufler, @MarcelKoch, @bevanwsjones

MarcelKoch commented 2 months ago

In terms of using python to define a DSL, there is the UFL to describe FEM. It's part of the fenics project, an example can be seen here: https://jsdokken.com/dolfinx-tutorial/chapter1/fundamentals_code.html#defining-the-variational-problem Basically with the UFL you can define the variational formulation of a poisson problem as:

a = dot(grad(u), grad(v)) * dx
F = f * v * dx
solve(a == F)