Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:21:12

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file accel/AlongStepFactory.hh
0006 //! \brief Along-step factory interface and definitions
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <functional>
0011 #include <memory>
0012 #include <G4ThreeVector.hh>
0013 
0014 #include "celeritas/geo/GeoFwd.hh"
0015 #include "celeritas/global/ActionInterface.hh"
0016 
0017 class G4LogicalVolume;
0018 
0019 namespace celeritas
0020 {
0021 struct ImportData;
0022 struct RZMapFieldInput;
0023 struct CartMapFieldInput;
0024 struct CylMapFieldInput;
0025 class CutoffParams;
0026 class FluctuationParams;
0027 class GeoMaterialParams;
0028 class MaterialParams;
0029 class ParticleParams;
0030 class PhysicsParams;
0031 
0032 namespace inp
0033 {
0034 struct UniformField;
0035 }
0036 
0037 //---------------------------------------------------------------------------//
0038 /*!
0039  * Input argument to the AlongStepFactory interface.
0040  *
0041  * When passed to a factory instance, all member data will be set (so the
0042  * instance will be 'true').
0043  *
0044  * Most of these classes have been forward-declared because they simply need to
0045  * be passed along to another class's constructor.
0046  */
0047 struct AlongStepFactoryInput
0048 {
0049     ActionId action_id;
0050 
0051     std::shared_ptr<GeoParams const> geometry;
0052     std::shared_ptr<MaterialParams const> material;
0053     std::shared_ptr<GeoMaterialParams const> geomaterial;
0054     std::shared_ptr<ParticleParams const> particle;
0055     std::shared_ptr<CutoffParams const> cutoff;
0056     std::shared_ptr<PhysicsParams const> physics;
0057     std::shared_ptr<ImportData const> imported;
0058 
0059     //! True if all data is assigned
0060     explicit operator bool() const
0061     {
0062         return action_id && geometry && material && geomaterial && particle
0063                && cutoff && physics && imported;
0064     }
0065 };
0066 
0067 //---------------------------------------------------------------------------//
0068 /*!
0069  * Helper class for emitting an AlongStep action.
0070  *
0071  * Currently Celeritas accepts a single along-step action (i.e., the same
0072  * stepper is used for both neutral and charged particles, across all energies
0073  * and regions of the problem). The along-step action is a single GPU
0074  * kernel that combines the field stepper selection, the magnetic field,
0075  * slowing-down calculation, multiple scattering, and energy loss fluctuations.
0076  *
0077  * The factory will be called from the thread that initializes \c SharedParams.
0078  * Instead of a daughter class, you can provide any function-like object that
0079  * has the same interface.
0080  *
0081  * Celeritas provides a few "default" configurations of along-step actions in
0082  * `celeritas/alongstep`.
0083  */
0084 class AlongStepFactoryInterface
0085 {
0086   public:
0087     //!@{
0088     //! \name Type aliases
0089     using argument_type = AlongStepFactoryInput const&;
0090     using result_type = std::shared_ptr<CoreStepActionInterface const>;
0091     //!@}
0092 
0093   public:
0094     virtual ~AlongStepFactoryInterface() = default;
0095 
0096     // Emit an along-step action
0097     virtual result_type operator()(argument_type input) const = 0;
0098 
0099   protected:
0100     AlongStepFactoryInterface() = default;
0101     CELER_DEFAULT_COPY_MOVE(AlongStepFactoryInterface);
0102 };
0103 
0104 //---------------------------------------------------------------------------//
0105 /*!
0106  * Create an along-step method for a uniform (or zero) field.
0107  *
0108  * The constructor is a lazily evaluated function that must return the field
0109  * definition and driver configuration. If unspecified, the field is zero.
0110  *
0111  * \todo Add a helper function to build from a Geant4 field manager or the new
0112  * \c G4FieldSetup
0113  */
0114 class UniformAlongStepFactory final : public AlongStepFactoryInterface
0115 {
0116   public:
0117     //!@{
0118     //! \name Type aliases
0119     using FieldInput = inp::UniformField;
0120     using FieldFunction = std::function<FieldInput()>;
0121     using VecVolume = std::vector<G4LogicalVolume const*>;
0122     using VecVolumeFunction = std::function<VecVolume()>;
0123     //!@}
0124 
0125   public:
0126     //! Construct with no field (linear propagation)
0127     UniformAlongStepFactory() = default;
0128 
0129     // Construct with a function to return the field strength
0130     explicit UniformAlongStepFactory(FieldFunction f);
0131 
0132     // Construct with field strength and volumes where field is present
0133     UniformAlongStepFactory(FieldFunction f, VecVolumeFunction volumes);
0134 
0135     // Emit an along-step action
0136     result_type operator()(argument_type input) const final;
0137 
0138     // Get the field params (used for converting to celeritas::inp)
0139     FieldInput get_field() const;
0140 
0141     // Get the volumes where field is present
0142     VecVolume get_volumes() const;
0143 
0144   private:
0145     FieldFunction get_field_;
0146     VecVolumeFunction get_volumes_;
0147 };
0148 
0149 //---------------------------------------------------------------------------//
0150 /*!
0151  * Create an along-step method for a two-dimensional (r-z in the cylindical
0152  * coordinate system) map field (RZMapField).
0153  */
0154 class RZMapFieldAlongStepFactory final : public AlongStepFactoryInterface
0155 {
0156   public:
0157     //!@{
0158     //! \name Type aliases
0159     using RZMapFieldFunction = std::function<RZMapFieldInput()>;
0160     //!@}
0161 
0162   public:
0163     // Construct with a function to return RZMapFieldInput
0164     explicit RZMapFieldAlongStepFactory(RZMapFieldFunction f);
0165 
0166     // Emit an along-step action
0167     result_type operator()(argument_type input) const final;
0168 
0169     // Get the field params (used for converting to celeritas::inp)
0170     RZMapFieldInput get_field() const;
0171 
0172   private:
0173     RZMapFieldFunction get_fieldmap_;
0174 };
0175 
0176 //---------------------------------------------------------------------------//
0177 /*!
0178  * Create an along-step method for a three-dimensional (r-phi-z in the
0179  * cylindical coordinate system) map field (CylMapField).
0180  */
0181 class CylMapFieldAlongStepFactory final : public AlongStepFactoryInterface
0182 {
0183   public:
0184     //!@{
0185     //! \name Type aliases
0186     using CylMapFieldFunction = std::function<CylMapFieldInput()>;
0187     //!@}
0188 
0189   public:
0190     // Construct with a function to return CylMapFieldInput
0191     explicit CylMapFieldAlongStepFactory(CylMapFieldFunction f);
0192 
0193     // Emit an along-step action
0194     result_type operator()(argument_type input) const final;
0195 
0196     // Get the field params (used for converting to celeritas::inp)
0197     CylMapFieldInput get_field() const;
0198 
0199   private:
0200     CylMapFieldFunction get_fieldmap_;
0201 };
0202 
0203 //---------------------------------------------------------------------------//
0204 /*!
0205  * Create an along-step method for a three-dimensional (x-y-z in the
0206  * cartesian coordinate system) map field (CartMapField).
0207  */
0208 class CartMapFieldAlongStepFactory final : public AlongStepFactoryInterface
0209 {
0210   public:
0211     //!@{
0212     //! \name Type aliases
0213     using CartMapFieldFunction = std::function<CartMapFieldInput()>;
0214     //!@}
0215 
0216   public:
0217     // Construct with a function to return CartMapFieldInput
0218     explicit CartMapFieldAlongStepFactory(CartMapFieldFunction f);
0219 
0220     // Emit an along-step action
0221     result_type operator()(argument_type input) const final;
0222 
0223     // Get the field params (used for converting to celeritas::inp)
0224     CartMapFieldInput get_field() const;
0225 
0226   private:
0227     CartMapFieldFunction get_fieldmap_;
0228 };
0229 
0230 //---------------------------------------------------------------------------//
0231 }  // namespace celeritas