Hello!
TL;DR
What is the correct way to select the correct procedures for different computational models at runtime?
Introduction
I am creating a code that will require the computation of different fluid properties. However, the code needs to support different fluid models (ideal, perfect, table, real, etc). The fluid model to be used will not be know at compile time.
Goal
It would be ideal if the rest of the application does not know about the underlying models. For example:
! Ideal scenario
enthalpy = enthalpy_from_PT(P, T)
! Not ideal
enthalpy = enthaypy_from_PT(fluid_type, P, T)
Ideally, at the beginning of the program, the generic function would be set up to “point” (one can tell I come from a C background) to the requested implementation by the user. How would this be achieved?
Issue
One of the reasons I am asking is because I know modern Fortran (in my case it is Fortran 2008) has a lot of tricks up its sleeve, and this is probably simple to do. I know that in F2003 the select type
construct exists, but it is only for objects.
I thought about making a different object for every fluid model with intrinsic functions that are then selected by select type
but that would leave the code as:
enthalpy = fluid_obj%HfPT(P, T)
which seem a bit messy: having a fluid type with no data and only procedures, and calling an object method to do a normal function call.
Any help (or pointers to blogs, papers, other code, etc) is greatly appreciated.
Regards,
Fernando