Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:31:21

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2022-2024 UT-Battelle, LLC, and other Celeritas developers.
0003 // See the top-level COPYRIGHT file for details.
0004 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0005 //---------------------------------------------------------------------------//
0006 //! \file celeritas/field/MakeMagFieldPropagator.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "corecel/Assert.hh"
0011 #include "corecel/Macros.hh"
0012 #include "corecel/math/Algorithms.hh"
0013 #include "celeritas/Quantities.hh"
0014 #include "celeritas/geo/GeoTrackView.hh"
0015 #include "celeritas/phys/ParticleTrackView.hh"
0016 
0017 #include "FieldDriver.hh"
0018 #include "FieldDriverOptions.hh"
0019 #include "FieldPropagator.hh"
0020 #include "MagFieldEquation.hh"
0021 
0022 namespace celeritas
0023 {
0024 //---------------------------------------------------------------------------//
0025 /*!
0026  * Create a stepper for a charge in a magnetic field.
0027  *
0028  * Example:
0029  * \code
0030  * auto step = make_stepper<DormandPrinceStepper>(
0031  *    UniformField{{1, 2, 3}},
0032  *    particle.charge());
0033  * \endcode
0034  */
0035 template<template<class EquationT> class StepperT, class FieldT>
0036 CELER_FUNCTION decltype(auto)
0037 make_mag_field_stepper(FieldT&& field, units::ElementaryCharge charge)
0038 {
0039     using Equation_t = MagFieldEquation<FieldT>;
0040     return StepperT<Equation_t>{
0041         Equation_t{::celeritas::forward<FieldT>(field), charge}};
0042 }
0043 
0044 //---------------------------------------------------------------------------//
0045 /*!
0046  * Create a field propagator from an existing stepper.
0047  *
0048  * Example:
0049  * \code
0050  * FieldDriverOptions driver_options,
0051  * auto propagate = make_field_propagator(
0052  *    stepper,
0053  *    driver_options,
0054  *    particle,
0055  *    &geo);
0056  * propagate(0.123);
0057  * \endcode
0058  */
0059 template<class StepperT, class GTV>
0060 CELER_FUNCTION decltype(auto)
0061 make_field_propagator(StepperT&& stepper,
0062                       FieldDriverOptions const& options,
0063                       ParticleTrackView const& particle,
0064                       GTV&& geometry)
0065 {
0066     return FieldPropagator{
0067         FieldDriver{options, ::celeritas::forward<StepperT>(stepper)},
0068         particle,
0069         ::celeritas::forward<GTV>(geometry)};
0070 }
0071 
0072 //---------------------------------------------------------------------------//
0073 /*!
0074  * Create a magnetic field propagator.
0075  *
0076  * Example:
0077  * \code
0078  * FieldDriverOptions driver_options,
0079  * auto propagate = make_mag_field_propagator<DormandPrinceStepper>(
0080  *    UniformField{{1, 2, 3}},
0081  *    driver_options,
0082  *    particle,
0083  *    &geo);
0084  * propagate(0.123);
0085  * \endcode
0086  */
0087 template<template<class EquationT> class StepperT, class FieldT, class GTV>
0088 CELER_FUNCTION decltype(auto)
0089 make_mag_field_propagator(FieldT&& field,
0090                           FieldDriverOptions const& options,
0091                           ParticleTrackView const& particle,
0092                           GTV&& geometry)
0093 {
0094     return make_field_propagator(
0095         make_mag_field_stepper<StepperT>(::celeritas::forward<FieldT>(field),
0096                                          particle.charge()),
0097         options,
0098         particle,
0099         ::celeritas::forward<GTV>(geometry));
0100 }
0101 
0102 //---------------------------------------------------------------------------//
0103 }  // namespace celeritas