neko icon indicating copy to clipboard operation
neko copied to clipboard

Open-closed factories

Open timofeymukha opened this issue 1 year ago • 0 comments

Hi! I have for some time trying to find a way to have factories that can be extended with new derived types without modifying the code of the factory. The main reason for why that would be good is the situation when people build their own module that extends Neko's capabilities (e.g. a new boundary condition, etc), including adding new runtime-selectable types. I think the ideal future scenario would be that makeneko can just pick up the new module, or, if we go the .so way, that the module is compiled into a library, and we just have a list of dynamic libraries to load at runtime in the case file, like in OpenFOAM.

The result is that one can just put one's new module online in a repo for everyone to use, without having to change anything in Neko itself, including the factory routines. This has contributed greatly to the growth of community contributions in OpenFOAM, and it would be nice if we had the same possibility.

I have already a few months ago come up with a simple design involving a named constructor type (string + procedure pointer) and a factory class, which holds an array of those. The issue is adding the constructors to the factory directly from another module. One cannot just have a statement that executes in a module. The other day, I decided to throw it out on the Fortran discourse, here. As you can see, I got this suggestion to use a C-binding as a hack, where the C file executes the bound function. This seems to work nicely, at least with gfortran, I have a repo with demo code. I don't know how to properly compile such mixed code with intel and Cray though, so couldn't test.

What do you think, is the hack reliable enough?

timofeymukha avatar Jun 27 '23 10:06 timofeymukha