Commit e2b9a52d authored by Stephan Lachnit's avatar Stephan Lachnit
Browse files

Merge branch 'perf_powfast' into 'master'

Super-Charged Pow() for Faster Mobility

See merge request allpix-squared/allpix-squared!1012
parents f6618bc2 b872fe7f
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -65,6 +65,38 @@ parameter value, especially at very high values of the electric field.

This model can be selected in the configuration file via the parameter `mobility_model = "canali"`.

## CanaliFast Model

The CanaliFast model is an alternative implementation of the Canali model described above. Instead of calculating the powers
$`x^\beta`$ and $`y^{1 / \beta}`$ directly for every requested mobility value, it uses pre-calculated lookup tables with
fixed binning and interpolates between the nearest bins. Depending on the simulation settings, this can provide a speed-up
of more than 30%.

The boundary values and the binning are chosen according to the expected range of the base. For the Canali model, values from
zero up to a field strength of 1000kV/cm are tabulated in 1000 bins. Separate lookup tables are built for the two power
calculations for electrons and holes, respectively.

For the calculation of $`x^\beta`$, the lower boundary is set to 0 since the electric field strength is positive. The upper
boundary is set to the argument of the Canali model formula, i.e. the maximum field strength divided by the
critical field strength provided by the model.

For the calculation of $`y^{1 / \beta}`$, the lower boundary is set to 1 owing to the offset present in the Canali formula.
The upper boundary is again set to the formula argument, i.e. $`1 + (E / E_C)^\beta`$ with $`E`$ being the maximum tabulated
field strength.

For field strengths outside the range, the first and last bin are extrapolated linearly, respectively.

The following plots show a comparison of the mobility and velocity of electrons and holes as calculated from the Canali and
the CanaliFast models. The maximum relative difference occurs at very low electric field strengths and is less than 0.004.

![](./canali_fast_mobility.png)\
*Comparison of the electron and hole mobilities calculated using the Canali and CanaliFast models as a function of the
electric field strength.*

![](./canali_fast_velocity.png)\
*Comparison of the electron and hole velocities calculated using the Canali and CanaliFast models as a function of the
electric field strength.*

## Hamburg Model

The Hamburg model \[[@hamburg]\] presents an empirical parametrization of electron and hole mobility as a function of the
+31.1 KiB
Loading image diff...
+30.9 KiB
Loading image diff...
+28 −0
Original line number Diff line number Diff line
# SPDX-FileCopyrightText: 2021-2023 CERN and the Allpix Squared authors
# SPDX-License-Identifier: MIT

#DESC tests selection of mobility model "canali"
[Allpix]
detectors_file = "detector.conf"
number_of_events = 1
random_seed = 0
multithreading = true
workers = 3

[DepositionPointCharge]
model = "fixed"
source_type = "point"
position = 0,0,0

[GenericPropagation]
temperature = 293K
charge_per_step = 100
mobility_model = "canali_fast"
log_level = INFO
propagate_electrons = true
propagate_holes = true

#PASS (INFO) [I:GenericPropagation:mydetector] Selected mobility model "canali_fast"
#LABEL coverage
#FAIL ERROR
#FAIL FATAL
+49 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@
#include "core/utils/log.h"
#include "core/utils/unit.h"
#include "objects/SensorCharge.hpp"
#include "tools/tabulated_pow.h"

namespace allpix {

@@ -87,7 +88,6 @@ namespace allpix {
        double hole_Vm_;
        double hole_Beta_;

    private:
        double electron_Ec_;
        double hole_Ec_;
    };
@@ -106,6 +106,52 @@ namespace allpix {
        }
    };

    /**
     * @ingroup Models
     * @brief Fast implementation of the Canali mobility model
     *
     * This model uses a pre-calculated lookup table for the required power calculations in the range relevant for
     * the simulation. This provides a significant speedup while having a good accuracy.
     */
    class CanaliFast : virtual public Canali {
    public:
        explicit CanaliFast(SensorMaterial material, double temperature)
            : JacoboniCanali(material, temperature), Canali(material, temperature),
              pow_e_beta(0., Units::get(1000., "kV/cm") / electron_Ec_, electron_Beta_),
              pow_e_inv_beta(
                  1., 1. + std::pow(Units::get(1000., "kV/cm") / electron_Ec_, electron_Beta_), 1.0 / electron_Beta_),
              pow_h_beta(0., Units::get(1000., "kV/cm") / hole_Ec_, hole_Beta_),
              pow_h_inv_beta(1., 1 + std::pow(Units::get(1000., "kV/cm") / hole_Ec_, hole_Beta_), 1.0 / hole_Beta_) {

            LOG(INFO) << "This mobility model uses a tabulated pow implementation and might be less accurate";

            // The boundary values and binning are chosen according to the expected range of the base.
            // Values are tabulated up to field values of 1000kV/cm

            // The pow-beta lower boundary is 0 since we are looking at electric field magnitudes which are >= 0
            // The pow-beta upper boundary is set to the pow function argument: maximum field divided by critical field

            // The pow-inverse-beta lower boundary is 1 due to the offset present in the Canali formula
            // The pow-inverse-beta upper boundary is set to the pow function argument: 1 plus pow from max / critical field
        }

        double operator()(const CarrierType& type, double efield_mag, double) const override {
            // Compute carrier mobility from constants and electric field magnitude
            if(type == CarrierType::ELECTRON) {
                return electron_Vm_ / electron_Ec_ / pow_e_inv_beta(1. + pow_e_beta(efield_mag / electron_Ec_));
            } else {
                return hole_Vm_ / hole_Ec_ / pow_h_inv_beta(1. + pow_h_beta(efield_mag / hole_Ec_));
            }
        };

    private:
        TabulatedPow<1000> pow_e_beta;
        TabulatedPow<1000> pow_e_inv_beta;

        TabulatedPow<1000> pow_h_beta;
        TabulatedPow<1000> pow_h_inv_beta;
    };

    /**
     * @ingroup Models
     * @brief Hamburg (Klanner-Scharf) parametrization for <100> silicon
@@ -557,6 +603,8 @@ namespace allpix {
                    model_ = std::make_unique<JacoboniCanali>(material, temperature);
                } else if(model == "canali") {
                    model_ = std::make_unique<Canali>(material, temperature);
                } else if(model == "canali_fast") {
                    model_ = std::make_unique<CanaliFast>(material, temperature);
                } else if(model == "hamburg") {
                    model_ = std::make_unique<Hamburg>(material, temperature);
                } else if(model == "hamburg_highfield") {
Loading