AMReX-Astro / Microphysics

common astrophysical microphysics routines with interfaces for the different AMReX codes
https://amrex-astro.github.io/Microphysics
Other
35 stars 34 forks source link

templating integrator functions on NumSpec, actual_rhs #1657

Open BenWibking opened 2 weeks ago

BenWibking commented 2 weeks ago

There is somewhat of a design "impedance mismatch" between Quokka and Microphysics.

I think this can be solved with two straightforward API changes:

Then it should be possible to call any integrator (either BackwardEuler or VODE) with something like: integrate<NumSpec, F>(F actual_rhs, ...) from the application code, or from the existing burner. Note that since the type of F is known at compile time, the compiler can inline the function call to actual_rhs() and there is no performance loss (it is not equivalent to a function pointer).

The functor could look like this:

struct QuokkaActualRhsFunctor {
        constexpr int num_groups = 1;
        amrex::Real my_runtime_parameter = 1.5;
    AMREX_GPU_DEVICE void operator()(amrex::GpuArray<num_groups> &rhs) const
    {
        // compute rhs here
        rhs(0) = M_PI * my_runtime_parameter;
    }
};

Calling the integrator could look like this:

QuokkaActualRhsFunctor my_actual_rhs;
my_actual_rhs.my_runtime_parameter = 42.0;
integrate<NumGroups>(my_actual_rhs, dt);

where the template parameter F is deduced by the compiler from the type of my_actual_rhs.

For existing Microphysics networks, I think this could be accomplished with code changes only trivial syntactic changes to the generic burner code (although potentially changing a significant number of lines of code). But it would be good to hear from other Microphysics developers on this point.

Background information

cc @chongchonghe @markkrumholz @psharda @zingale

BenWibking commented 2 weeks ago

Since everything is now templated on BurnT, we should be able to just add an operator() to the state object and call it inside rhs: https://github.com/AMReX-Astro/Microphysics/blob/533f712d2d217ea4f4063f3a809eb16a839c9ef6/integration/integrator_rhs_strang.H#L25