TypeList
The TypeList
struct provides utilities for dealing with
template parameter packs, and in particular is heavily used
in the dispatcher and abstractions around
the type-based packs to perform
compile time logic. Some utilities include concatenating
TypeList
s, picking out types by index and splitting into separate
lists.
TypeListArray
It can also be useful to index into a regular array using the types in
a TypeList
. This is commonly used in the hydro as a way
to abstract the size of the system used depending on runtime options
used around MHD/3T physics.
physics/hydro/riemann_solver.hpp:tl-arr
Prim2Cons<hydro_traits>(vL, UL);
Prim2Cons<hydro_traits>(vR, UR);
Prim2Flux<dir1, hydro_traits>(vR, FR);
Prim2Flux<dir1, hydro_traits>(vL, FL);
physics/hydro/primconsflux.hpp:use-idx
U(DENS()) = V(DENS());
Real emag = 0.;
Real ekin = 0.;
for (int dir = 0; dir < 3; dir++) {
U(MOMENTUM(dir)) = V(DENS()) * V(VELOCITY(dir));
ekin += V(VELOCITY(dir)) * V(VELOCITY(dir));
if constexpr (hydro_traits::MHD != Mhd::off) {
U(MAGC(dir)) = V(MAGC(dir));
emag += V(MAGC(dir)) * V(MAGC(dir));
}
}
Types in a TypeList
can also be iterated over using the type_for
interface
together with a templated lambda function.
physics/hydro/riemann_solver.hpp:type_for
type_for(typename hydro_traits::Conserved(), [&]<typename Vars>(const Vars &) {
for (int comp = 0; comp < pack.GetSize(Vars()); comp++) {
auto var = Vars(comp);
pack.flux(face, var) =
sRmsLi * (sR * FL(var) - sL * FR(var) + sR * sL * (UR(var) - UL(var)));
}
});