IAP GITLAB

Skip to content

WIP: Support for uniform magnetic fields in environment.

Remy Prechelt requested to merge rprechelt-magnetic-field into master

Please disregard this MR and see !211 (merged) for an updated version.

This is a WIP MR containing an concept for adding magnetic field support into the C8 environment hierarchy. However, the included solution is more general than just magnetic fields. This MR succesfully compiles the vertical_EAS example and can query the magnetic fields at the current particle location in the cascade loop.

The current Environment<template IMediumModel> only supports query density and grammage. Furthermore, most of the C8 codebase is explicitly templated on Environment<IMediumModel> which does not allow for any flexibility. There are several optional components users may want to include in the environment (magnetic fields, refractive index) and there are applications where allowing users to add their own extensions to the environment would be extremely interesting (such as birefringence modeling or ice absorption/attenuation).

This MR makes Environment a Variadic CRTP derived class template <typename IMediumModel, typename... Extensions>. This allows users to optionally plug-in different environment extension models at compile-time. These extensions can be used to implement mSome examples of constructing custom environments are below:

Environment env; // the default - just a density model (this is how the code is used now)
Environment<AtmModel> env; // the same as the above - just an atmospheric density model.
Environment<AtmModel, UniformMagneticField> env; // a density model with a uniform (constant) magnetic field
Environment<AtmModel, UniformMagneticField, RefractiveIndexModel> env; // density + B-field + refractive index model
Environment<AtmModel, RefractiveIndexModel> env; // just density + refractive index
Environment<AtmModel, CustomUserProvidedBirefringenceModel, IceAbsorption> env; // custom user provided modules

In detail, this MR contains:

  • Environment is now a variadic CRTP class that supports an unlimited number of optional CRTP environment plugins. By default, this is the standard environment type already available in C8 with a zero magnetic field everywhere. The current interface has not changed - i.e. instantiating a Environment<IMediumModel> (which the master branch does right now) still works!
  • Some classes were templated on Environment<template IMediumModel> (which is overly specialized). These have been changed to be templated on TEnvironment directly so they can work arbitrary environment specializations/combinations.
  • Since some of these methods are now templates, they had to be moved to their corresponding header files (Augusto has apparently already done this in his refactoring branch but that is not available to me)
  • Implementation of a CRTP magnetic field interface type, MagneticField, and two concrete instances, NoMagneticField (which returns zero everywhere), and UniformMagneticField that returns a fixed 3D magnetic field vector everywhere. The interface function definition is GetMagneticField(Point const&) -> MagneticFieldVector

I'd appreciate comments and discussions on this design. I personally think this is an incredibly flexible way to allow for custom environments to be constructed by us or the user (and is done completely at compile time) with very minimal changes to the codebase (most of which have already been done by Augusto). If there is a general consensus that this is a good direction, I will finish off porting the other examples and finalize this MR.

Edited by Remy Prechelt

Merge request reports