Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/celeritas/phys/PhysicsData.hh was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 celeritas/phys/PhysicsData.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/data/Collection.hh"
0010 #include "corecel/data/CollectionBuilder.hh"
0011 #include "corecel/data/StackAllocatorData.hh"
0012 #include "celeritas/Quantities.hh"
0013 #include "celeritas/Types.hh"
0014 #include "celeritas/em/data/AtomicRelaxationData.hh"
0015 #include "celeritas/em/data/EPlusGGData.hh"
0016 #include "celeritas/em/data/ElectroNuclearData.hh"
0017 #include "celeritas/em/data/GammaNuclearData.hh"
0018 #include "celeritas/em/data/LivermorePEData.hh"
0019 #include "celeritas/grid/XsGridData.hh"
0020 #include "celeritas/neutron/data/NeutronElasticData.hh"
0021 
0022 #include "Interaction.hh"
0023 #include "Secondary.hh"
0024 
0025 namespace celeritas
0026 {
0027 //---------------------------------------------------------------------------//
0028 // PARAMS
0029 //---------------------------------------------------------------------------//
0030 /*!
0031  * Set of value grids for all elements or materials.
0032  *
0033  * It is allowable for this to be "false" (i.e. no materials assigned)
0034  * indicating that the value table doesn't apply in the context -- for
0035  * example, an empty ValueTable macro_xs means that the process doesn't have a
0036  * discrete interaction.
0037  */
0038 template<class GridId>
0039 struct ValueTable
0040 {
0041     ItemRange<GridId> grids;  //!< Value grid by element or material index
0042 
0043     //! True if assigned
0044     explicit CELER_FUNCTION operator bool() const { return !grids.empty(); }
0045 };
0046 
0047 using UniformTable = ValueTable<UniformGridId>;
0048 
0049 //---------------------------------------------------------------------------//
0050 /*!
0051  * Set of cross section CDF tables for a model.
0052  *
0053  * Each material has a set of value grids for its constituent elements; these
0054  * are used to sample an element from a material when required by a discrete
0055  * interaction. A null \c ValueTableId means the material only has a single
0056  * element, so no cross sections need to be stored. An empty \c ModelCdfTable
0057  * means no element selection is required for the model.
0058  */
0059 struct ModelCdfTable
0060 {
0061     ItemRange<UniformTable> tables;  //!< Value table by material
0062 
0063     //! True if assigned
0064     explicit CELER_FUNCTION operator bool() const { return !tables.empty(); }
0065 };
0066 
0067 //---------------------------------------------------------------------------//
0068 /*!
0069  * Energy-dependent model IDs for a single process and particle type.
0070  *
0071  * For a given particle type, a single process should be divided into multiple
0072  * models as a function of energy. The \c ModelGroup represents this with an
0073  * energy grid, and each cell of the grid corresponding to a particular
0074  * \c ParticleModelId.
0075  */
0076 struct ModelGroup
0077 {
0078     using Energy = units::MevEnergy;
0079 
0080     ItemRange<real_type> energy;  //!< Energy grid bounds [MeV]
0081     ItemRange<ParticleModelId> model;  //!< Corresponding models
0082 
0083     //! True if assigned
0084     explicit CELER_FUNCTION operator bool() const
0085     {
0086         return (energy.size() >= 2) && (model.size() + 1 == energy.size());
0087     }
0088 };
0089 
0090 //---------------------------------------------------------------------------//
0091 /*!
0092  * Particle-process that uses MC integration to sample interaction length.
0093  *
0094  * This is needed for the integral approach for correctly sampling the discrete
0095  * interaction length after a particle loses energy along a step. An \c
0096  * IntegralXsProcess is stored for each particle-process. This will be "false"
0097  * (i.e. no energy_max assigned) if the particle associated with the process
0098  * does not have energy loss processes or if \c use_integral_xs is false.
0099  */
0100 struct IntegralXsProcess
0101 {
0102     ItemRange<real_type> energy_max_xs;  //!< Energy of the largest xs [mat]
0103 
0104     //! True if assigned
0105     explicit CELER_FUNCTION operator bool() const
0106     {
0107         return !energy_max_xs.empty();
0108     }
0109 };
0110 
0111 //---------------------------------------------------------------------------//
0112 /*!
0113  * Processes for a single particle type.
0114  *
0115  * Each index should be accessed with type ParticleProcessId. \c macro_xs
0116  * stores the cross section tables for each process, while \c energy_loss and
0117  * \c range are the process-integrated dE/dx and range for the particle.  \c
0118  * integral_xs will only be assigned if the integral approach is used and the
0119  * particle has continuous-discrete processes.
0120  *
0121  * \todo If it's possible for a particle to have multiple at-rest processes, \c
0122  * at_rest should be the process with the smallest lifetime. This is used in \c
0123  * select_discrete_interaction to choose the at-rest process with the smallest
0124  * time to interaction if the particle is stopped and has a process that
0125  * applies at rest.
0126  */
0127 struct ProcessGroup
0128 {
0129     ItemRange<ProcessId> processes;  //!< Processes that apply [ppid]
0130     ItemRange<ModelGroup> models;  //!< Model applicability [ppid]
0131     ItemRange<IntegralXsProcess> integral_xs;  //!< [ppid]
0132     ItemRange<ValueTable<XsGridId>> macro_xs;  //!< [ppid]
0133     UniformTable energy_loss;  //!< Process-integrated energy loss
0134     UniformTable range;  //!< Process-integrated range
0135     UniformTable inverse_range;  //!< Inverse process-integrated range
0136     ParticleProcessId at_rest;  //!< ID of the particle's at-rest process
0137 
0138     //! True if assigned and valid
0139     explicit CELER_FUNCTION operator bool() const
0140     {
0141         return !processes.empty() && models.size() == processes.size();
0142     }
0143 
0144     //! Number of processes that apply
0145     CELER_FUNCTION ParticleProcessId::size_type size() const
0146     {
0147         return processes.size();
0148     }
0149 };
0150 
0151 //---------------------------------------------------------------------------//
0152 /*!
0153  * IDs for models that do on-the-fly cross section calculation.
0154  */
0155 struct HardwiredIds
0156 {
0157     ProcessId annihilation;
0158     ModelId eplusgg;
0159 
0160     ProcessId electro_nuclear;
0161     ModelId electro_vd;
0162 
0163     ProcessId gamma_nuclear;
0164     ModelId bertini_qgs;
0165 
0166     ProcessId photoelectric;
0167     ModelId livermore_pe;
0168 
0169     ProcessId neutron_elastic;
0170     ModelId chips;
0171 };
0172 
0173 //---------------------------------------------------------------------------//
0174 /*!
0175  * Model data for special hardwired cases (on-the-fly xs calculations).
0176  */
0177 template<Ownership W, MemSpace M>
0178 struct HardwiredModels
0179 {
0180     // Process and model IDs
0181     HardwiredIds ids;
0182 
0183     // Model data
0184     EPlusGGData eplusgg;
0185     ElectroNuclearData<W, M> electro_vd;
0186     GammaNuclearData<W, M> bertini_qgs;
0187     LivermorePEData<W, M> livermore_pe;
0188     AtomicRelaxParamsData<W, M> relaxation;
0189     NeutronElasticData<W, M> chips;
0190 
0191     //! Assign from another set of data
0192     template<Ownership W2, MemSpace M2>
0193     HardwiredModels& operator=(HardwiredModels<W2, M2> const& other)
0194     {
0195         // Don't assign the references to model data
0196         ids = other.ids;
0197         eplusgg = other.eplusgg;
0198 
0199         return *this;
0200     }
0201 };
0202 
0203 //---------------------------------------------------------------------------//
0204 /*!
0205  * User-configurable particle-dependent physics constants.
0206  *
0207  * These scalar quantities can have different values for electrons/positrons
0208  * and muons/hadrons. They are described in \c PhysicsParams .
0209  */
0210 struct ParticleScalars
0211 {
0212     using Energy = units::MevEnergy;
0213 
0214     // Energy loss/range options
0215     real_type min_range{};  //!< rho [len]
0216     real_type max_step_over_range{};  //!< alpha [unitless]
0217     Energy lowest_energy{};  //!< Lowest kinetic energy
0218 
0219     // Multiple scattering options
0220     bool displaced{};  //!< Whether lateral displacement is enabled
0221     real_type range_factor{};
0222     MscStepLimitAlgorithm step_limit_algorithm{MscStepLimitAlgorithm::size_};
0223 
0224     //! True if assigned
0225     explicit CELER_FUNCTION operator bool() const
0226     {
0227         return min_range > 0 && max_step_over_range > 0
0228                && lowest_energy > zero_quantity() && range_factor > 0
0229                && range_factor < 1
0230                && step_limit_algorithm != MscStepLimitAlgorithm::size_;
0231     }
0232 };
0233 
0234 //---------------------------------------------------------------------------//
0235 /*!
0236  * Scalar (no template needed) quantities used by physics.
0237  *
0238  * The user-configurable constants and multiple scattering options are
0239  * described in \c PhysicsParams .
0240  *
0241  * The \c first_model_action is the \c ActionId for the first \c
0242  * ModelId . Additionally it implies (by construction in physics_params) the
0243  * action IDs of several other physics actions.
0244  */
0245 struct PhysicsParamsScalars
0246 {
0247     using Energy = units::MevEnergy;
0248 
0249     //! Highest number of processes for any particle type
0250     ProcessId::size_type max_particle_processes{};
0251     //! Offset to create an ActionId from a ModelId
0252     ActionId first_model_action{};
0253     //! Number of physics models
0254     ModelId::size_type num_models{};
0255 
0256     // User-configurable constants
0257     real_type min_eprime_over_e{};  //!< xi [unitless]
0258     real_type linear_loss_limit{};  //!< For scaled range calculation
0259     real_type fixed_step_limiter{};  //!< Global charged step size limit [len]
0260 
0261     // User-configurable multiple scattering options
0262     real_type lambda_limit{};  //!< lambda limit
0263     real_type safety_factor{};  //!< safety factor
0264 
0265     // Particle-dependent user-configurable constants
0266     ParticleScalars light;
0267     ParticleScalars heavy;
0268 
0269     real_type secondary_stack_factor = 3;  //!< Secondary storage per state
0270                                            //!< size
0271     // When fixed step limiter is used, this is the corresponding action ID
0272     ActionId fixed_step_action{};
0273 
0274     //! True if assigned
0275     explicit CELER_FUNCTION operator bool() const
0276     {
0277         return max_particle_processes > 0 && first_model_action >= ActionId{4}
0278                && num_models > 0 && min_eprime_over_e > 0
0279                && linear_loss_limit > 0 && secondary_stack_factor > 0
0280                && ((fixed_step_limiter > 0)
0281                    == static_cast<bool>(fixed_step_action))
0282                && lambda_limit > 0 && safety_factor >= 0.1 && light && heavy;
0283     }
0284 
0285     //! Stop early due to MSC limitation
0286     CELER_FORCEINLINE_FUNCTION ActionId msc_action() const
0287     {
0288         return first_model_action - 4;
0289     }
0290 
0291     //! Stop early due to range limitation
0292     CELER_FORCEINLINE_FUNCTION ActionId range_action() const
0293     {
0294         return first_model_action - 3;
0295     }
0296 
0297     //! Undergo a discrete interaction
0298     CELER_FORCEINLINE_FUNCTION ActionId discrete_action() const
0299     {
0300         return first_model_action - 2;
0301     }
0302 
0303     //! Indicate a discrete interaction was rejected by the integral method
0304     CELER_FORCEINLINE_FUNCTION ActionId integral_rejection_action() const
0305     {
0306         return first_model_action - 1;
0307     }
0308 
0309     //! Indicate an interaction failed to allocate memory
0310     CELER_FORCEINLINE_FUNCTION ActionId failure_action() const
0311     {
0312         return first_model_action + num_models;
0313     }
0314 };
0315 
0316 //---------------------------------------------------------------------------//
0317 /*!
0318  * Persistent shared physics data.
0319  *
0320  * This includes macroscopic cross section tables ordered by
0321  * [particle][process][material][energy] and process-integrated energy loss and
0322  * range tables ordered by [particle][material][energy].
0323  */
0324 template<Ownership W, MemSpace M>
0325 struct PhysicsParamsData
0326 {
0327     //// TYPES ////
0328 
0329     template<class T>
0330     using Items = Collection<T, W, M>;
0331     template<class T>
0332     using ParticleItems = Collection<T, W, M, ParticleId>;
0333     template<class T>
0334     using ParticleModelItems = Collection<T, W, M, ParticleModelId>;
0335 
0336     //// DATA ////
0337 
0338     // Non-templated data
0339     PhysicsParamsScalars scalars;
0340 
0341     // Models that calculate cross sections on the fly
0342     HardwiredModels<Ownership::const_reference, M> hardwired;
0343 
0344     // Grid and table storage
0345     Items<XsGridId> xs_grid_ids;
0346     Items<XsGridRecord> xs_grids;
0347     Items<ValueTable<XsGridId>> xs_tables;
0348     Items<UniformGridId> uniform_grid_ids;
0349     Items<UniformGridRecord> uniform_grids;
0350     Items<UniformTable> uniform_tables;
0351     ParticleModelItems<ModelCdfTable> model_cdf;
0352 
0353     // Process and model storage
0354     Items<ModelGroup> model_groups;
0355     Items<IntegralXsProcess> integral_xs;
0356     ParticleItems<ProcessGroup> process_groups;
0357     ParticleModelItems<ModelId> model_ids;
0358     Items<ParticleModelId> pmodel_ids;
0359     Items<ProcessId> process_ids;
0360 
0361     // Backend storage
0362     Items<real_type> reals;
0363 
0364     //// METHODS ////
0365 
0366     //! True if assigned
0367     explicit CELER_FUNCTION operator bool() const
0368     {
0369         return !process_groups.empty() && !model_ids.empty() && scalars;
0370     }
0371 
0372     //! Assign from another set of data
0373     template<Ownership W2, MemSpace M2>
0374     PhysicsParamsData& operator=(PhysicsParamsData<W2, M2> const& other)
0375     {
0376         CELER_EXPECT(other);
0377 
0378         scalars = other.scalars;
0379 
0380         hardwired = other.hardwired;
0381 
0382         xs_grids = other.xs_grids;
0383         xs_grid_ids = other.xs_grid_ids;
0384         xs_tables = other.xs_tables;
0385         uniform_grids = other.uniform_grids;
0386         uniform_grid_ids = other.uniform_grid_ids;
0387         uniform_tables = other.uniform_tables;
0388         model_cdf = other.model_cdf;
0389 
0390         model_groups = other.model_groups;
0391         integral_xs = other.integral_xs;
0392         process_groups = other.process_groups;
0393         model_ids = other.model_ids;
0394         pmodel_ids = other.pmodel_ids;
0395         process_ids = other.process_ids;
0396 
0397         reals = other.reals;
0398 
0399         return *this;
0400     }
0401 };
0402 
0403 //---------------------------------------------------------------------------//
0404 // STATE
0405 //---------------------------------------------------------------------------//
0406 /*!
0407  * Physics state data for a single track.
0408  *
0409  * State that's persistent across steps:
0410  * - Remaining number of mean free paths to the next discrete interaction
0411  *
0412  * State that is reset at every step:
0413  * - Current macroscopic cross section
0414  * - Within-step energy deposition
0415  * - Within-step energy loss range
0416  * - Secondaries emitted from an interaction
0417  * - Discrete process element selection
0418  */
0419 struct PhysicsTrackState
0420 {
0421     real_type interaction_mfp;  //!< Remaining MFP to interaction
0422 
0423     // TEMPORARY STATE
0424     real_type macro_xs;  //!< Total cross section for discrete interactions
0425     real_type energy_deposition;  //!< Local energy deposition in a step [MeV]
0426     real_type dedx_range;  //!< Local energy loss range [len]
0427     MscRange msc_range;  //!< Range properties for multiple scattering
0428     Span<Secondary> secondaries;  //!< Emitted secondaries
0429     ElementComponentId element;  //!< Element sampled for interaction
0430 };
0431 
0432 //---------------------------------------------------------------------------//
0433 /*!
0434  * Initialize a physics track state.
0435  *
0436  * Currently no data is required at initialization -- it all must be evaluated
0437  * by the physics kernels itself.
0438  */
0439 struct PhysicsTrackInitializer
0440 {
0441 };
0442 
0443 //---------------------------------------------------------------------------//
0444 /*!
0445  * Dynamic physics (models, processes) state data.
0446  *
0447  * The "xs scratch space" is a 2D array of reals, indexed with
0448  * [track_id][el_component_id], where the fast-moving dimension has the
0449  * greatest number of element components of any material in the problem. This
0450  * can be used for the physics to calculate microscopic cross sections.
0451  */
0452 template<Ownership W, MemSpace M>
0453 struct PhysicsStateData
0454 {
0455     //// TYPES ////
0456 
0457     template<class T>
0458     using StateItems = celeritas::StateCollection<T, W, M>;
0459     template<class T>
0460     using Items = celeritas::Collection<T, W, M>;
0461 
0462     //// DATA ////
0463 
0464     StateItems<PhysicsTrackState> state;  //!< Track state [track]
0465     StateItems<MscStep> msc_step;  //!< Internal MSC data [track]
0466 
0467     Items<real_type> per_process_xs;  //!< XS [track][particle process]
0468 
0469     AtomicRelaxStateData<W, M> relaxation;  //!< Scratch data
0470     StackAllocatorData<Secondary, W, M> secondaries;  //!< Secondary stack
0471 
0472     //// METHODS ////
0473 
0474     //! True if assigned
0475     explicit CELER_FUNCTION operator bool() const
0476     {
0477         return !state.empty() && secondaries;
0478     }
0479 
0480     //! State size
0481     CELER_FUNCTION size_type size() const { return state.size(); }
0482 
0483     //! Assign from another set of states
0484     template<Ownership W2, MemSpace M2>
0485     PhysicsStateData& operator=(PhysicsStateData<W2, M2>& other)
0486     {
0487         CELER_EXPECT(other);
0488         state = other.state;
0489         msc_step = other.msc_step;
0490 
0491         per_process_xs = other.per_process_xs;
0492 
0493         relaxation = other.relaxation;
0494         secondaries = other.secondaries;
0495 
0496         return *this;
0497     }
0498 };
0499 
0500 //---------------------------------------------------------------------------//
0501 /*!
0502  * Resize the state in host code.
0503  */
0504 template<MemSpace M>
0505 inline void resize(PhysicsStateData<Ownership::value, M>* state,
0506                    HostCRef<PhysicsParamsData> const& params,
0507                    size_type size)
0508 {
0509     CELER_EXPECT(size > 0);
0510     CELER_EXPECT(params.scalars.max_particle_processes > 0);
0511     resize(&state->state, size);
0512     resize(&state->msc_step, size);
0513     resize(&state->per_process_xs,
0514            size * params.scalars.max_particle_processes);
0515     resize(&state->relaxation, params.hardwired.relaxation, size);
0516     resize(
0517         &state->secondaries,
0518         static_cast<size_type>(size * params.scalars.secondary_stack_factor));
0519 }
0520 
0521 //---------------------------------------------------------------------------//
0522 }  // namespace celeritas