I think Oceananigans.jl sets a pretty good example with its input deck syntax. I’m most familiar with Pyranda’s behind-the-fence parent, Miranda, which uses Lua input decks to drive a Fortran code. You can specify pretty much any IC/BC/forcing terms as a set of user-created f(x, y, z, t)
within the input deck. Those specifications don’t necessarily need to be your fixed set of primitives, either - just as you can specify range(1.0, stop=10, length=10)
or range(1.0, stop=10, step=1)
, you can specify any closed set of the state variables and let the code calculate the necessary primitives via the EOS.
One of the keys is to take advantage of Julia’s multiple dispatch with parameterized struct
s to keep track of dimensionality, which avoids this sort of nested, string-based if-else block. Generally speaking, you should always prefer structs to strings for parameter specification, since the former makes precompilation and inference a lot easier.