Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:29:26

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-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 accel/AlongStepFactory.hh
0007 //! \brief Along-step factory interface and definitions
0008 //---------------------------------------------------------------------------//
0009 #pragma once
0010 
0011 #include <functional>
0012 #include <memory>
0013 #include <G4ThreeVector.hh>
0014 
0015 #include "celeritas/geo/GeoFwd.hh"
0016 #include "celeritas/global/ActionInterface.hh"
0017 
0018 namespace celeritas
0019 {
0020 struct ImportData;
0021 struct RZMapFieldInput;
0022 struct UniformFieldParams;
0023 class CutoffParams;
0024 class FluctuationParams;
0025 class GeoMaterialParams;
0026 class MaterialParams;
0027 class ParticleParams;
0028 class PhysicsParams;
0029 
0030 //---------------------------------------------------------------------------//
0031 /*!
0032  * Input argument to the AlongStepFactory interface.
0033  *
0034  * When passed to a factory instance, all member data will be set (so the
0035  * instance will be 'true').
0036  *
0037  * Most of these classes have been forward-declared because they simply need to
0038  * be passed along to another class's constructor.
0039  */
0040 struct AlongStepFactoryInput
0041 {
0042     ActionId action_id;
0043 
0044     std::shared_ptr<GeoParams const> geometry;
0045     std::shared_ptr<MaterialParams const> material;
0046     std::shared_ptr<GeoMaterialParams const> geomaterial;
0047     std::shared_ptr<ParticleParams const> particle;
0048     std::shared_ptr<CutoffParams const> cutoff;
0049     std::shared_ptr<PhysicsParams const> physics;
0050     std::shared_ptr<ImportData const> imported;
0051 
0052     //! True if all data is assigned
0053     explicit operator bool() const
0054     {
0055         return action_id && geometry && material && geomaterial && particle
0056                && cutoff && physics && imported;
0057     }
0058 };
0059 
0060 //---------------------------------------------------------------------------//
0061 /*!
0062  * Helper class for emitting an AlongStep action.
0063  *
0064  * Currently Celeritas accepts a single along-step action (i.e., the same
0065  * stepper is used for both neutral and charged particles, across all energies
0066  * and regions of the problem). The along-step action is a single GPU
0067  * kernel that combines the field stepper selection, the magnetic field,
0068  * slowing-down calculation, multiple scattering, and energy loss fluctuations.
0069  *
0070  * The factory will be called from the thread that initializes \c SharedParams.
0071  * Instead of a daughter class, you can provide any function-like object that
0072  * has the same interface.
0073  *
0074  * Celeritas provides a few "default" configurations of along-step actions in
0075  * `celeritas/global/alongstep`.
0076  */
0077 class AlongStepFactoryInterface
0078 {
0079   public:
0080     //!@{
0081     //! \name Type aliases
0082     using argument_type = AlongStepFactoryInput const&;
0083     using result_type = std::shared_ptr<CoreStepActionInterface const>;
0084     //!@}
0085 
0086   public:
0087     virtual ~AlongStepFactoryInterface() = default;
0088 
0089     // Emit an along-step action
0090     virtual result_type operator()(argument_type input) const = 0;
0091 
0092   protected:
0093     AlongStepFactoryInterface() = default;
0094     CELER_DEFAULT_COPY_MOVE(AlongStepFactoryInterface);
0095 };
0096 
0097 //---------------------------------------------------------------------------//
0098 /*!
0099  * Create an along-step method for a uniform (or zero) field.
0100  *
0101  * The constructor is a lazily evaluated function that must return the field
0102  * definition and driver configuration. If unspecified, the field is zero.
0103  */
0104 class UniformAlongStepFactory final : public AlongStepFactoryInterface
0105 {
0106   public:
0107     //!@{
0108     //! \name Type aliases
0109     using FieldFunction = std::function<UniformFieldParams()>;
0110     //!@}
0111 
0112   public:
0113     //! Construct with no field (linear propagation)
0114     UniformAlongStepFactory() = default;
0115 
0116     // Construct with a function to return the field strength
0117     explicit UniformAlongStepFactory(FieldFunction f);
0118 
0119     // Emit an along-step action
0120     result_type operator()(argument_type input) const final;
0121 
0122   private:
0123     FieldFunction get_field_;
0124 };
0125 
0126 //---------------------------------------------------------------------------//
0127 /*!
0128  * Create an along-step method for a two-dimensional (r-z in the cylindical
0129  * coordinate system) map field (RZMapField).
0130  */
0131 class RZMapFieldAlongStepFactory final : public AlongStepFactoryInterface
0132 {
0133   public:
0134     //!@{
0135     //! \name Type aliases
0136     using RZMapFieldFunction = std::function<RZMapFieldInput()>;
0137     //!@}
0138 
0139   public:
0140     // Construct with a function to return RZMapFieldInput
0141     explicit RZMapFieldAlongStepFactory(RZMapFieldFunction f);
0142 
0143     // Emit an along-step action
0144     result_type operator()(argument_type input) const final;
0145 
0146   private:
0147     RZMapFieldFunction get_fieldmap_;
0148 };
0149 //---------------------------------------------------------------------------//
0150 }  // namespace celeritas