ammarhakim / gkylzero

Lowest, compiled layer of Gkeyll infrastructure.
MIT License
22 stars 5 forks source link

[DR] Simplification of how static GK species are handled #450

Open tnbernard opened 2 months ago

tnbernard commented 2 months ago

We propose the following to handle static gk and gk_neut species (idea courtesy of @JunoRavin):

Right now, we are having to introduce if statements in a bunch of places and some of these places are not necessarily sequential (don’t allocate certain internal arrays, don’t allocate certain updaters, etc) What we should do:

  1. In gk_species.c and gk_neut_species.c make new functions:
    a) gk_species_static_new and gk_neut_species_static_new b) gk_species_static_rhs and gk_neut_species_static_rhs
  2. Check in the init method if a species is static, if it is, call the static new method and set a function pointer to the correct rhs method

This has a couple of advantages:

  1. No more if statements
  2. Allows us to use pointers to just set things like f1 = f and fnew = f (so we don’t have to do a bunch of complex logic for whether f1 and fnew are allocated, we can just keep using f)

The DR will be updated with a link to a branch once development on this task has begun.

manauref commented 1 month ago

One potential disadvantage of this approach is that there may be a lot of code duplication between gk_species_static_new and gk_species_new. But perhaps the common blocks can be canned and called equally by both functions.