Back to home page

EIC code displayed by LXR

 
 

    


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

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/phys/ProcessBuilder.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <functional>
0011 #include <memory>
0012 #include <set>
0013 #include <unordered_map>
0014 #include <vector>
0015 
0016 #include "celeritas/ext/GeantPhysicsOptions.hh"
0017 #include "celeritas/io/ImportProcess.hh"
0018 #include "celeritas/io/ImportSBTable.hh"
0019 
0020 #include "AtomicNumber.hh"
0021 #include "Process.hh"
0022 
0023 namespace celeritas
0024 {
0025 //---------------------------------------------------------------------------//
0026 class ImportedProcesses;
0027 class MaterialParams;
0028 class ParticleParams;
0029 struct ImportData;
0030 struct ImportLivermorePE;
0031 
0032 //---------------------------------------------------------------------------//
0033 //! Options used for constructing built-in Celeritas processes
0034 struct ProcessBuilderOptions
0035 {
0036     bool brem_combined{false};
0037     BremsModelSelection brems_selection{BremsModelSelection::all};
0038 };
0039 
0040 //---------------------------------------------------------------------------//
0041 /*!
0042  * Construct Celeritas EM processes from imported data.
0043  *
0044  * This factory class has a hardcoded map that takes a \c ImportProcessClass
0045  * and constructs a built-in EM process (which will then build corresponding
0046  * models). This map can be overridden or extended by the \c user_build
0047  * constructor argument, which is a mapping of process class to user-supplied
0048  * factory functions.
0049  *
0050  * The function can return a null process pointer (in which case the caller
0051  * *must* ignore it) to indicate that a process should be deliberately omitted
0052  * from Celeritas. This can be used to (for example) skip very-high-energy
0053  * processes if Celeritas offloads only tracks below some energy cutoff. See \c
0054  * WarnAndIgnoreProcess below for a helper function for this purpose.
0055  *
0056  * \note Imported data may have multiple duplicate "process" entries, one
0057  * per particle type, because that's how Geant4 manages processes.
0058  */
0059 class ProcessBuilder
0060 {
0061   public:
0062     //!@{
0063     //! \name Type aliases
0064     using IPC = ImportProcessClass;
0065     using Options = ProcessBuilderOptions;
0066     using SPProcess = std::shared_ptr<Process>;
0067     using SPConstParticle = std::shared_ptr<ParticleParams const>;
0068     using SPConstMaterial = std::shared_ptr<MaterialParams const>;
0069     using SPConstImported = std::shared_ptr<ImportedProcesses const>;
0070     //!@}
0071 
0072     //! Input argument for user-provided process construction
0073     struct UserBuildInput
0074     {
0075         SPConstMaterial material;
0076         SPConstParticle particle;
0077         SPConstImported imported;
0078     };
0079 
0080     //!@{
0081     //! \name User builder type aliases
0082     using UserBuildFunction = std::function<SPProcess(UserBuildInput const&)>;
0083     using UserBuildMap = std::unordered_map<IPC, UserBuildFunction>;
0084     //!@}
0085 
0086   public:
0087     // Get an ordered set of all available processes
0088     static std::set<IPC>
0089     get_all_process_classes(std::vector<ImportProcess> const& processes);
0090 
0091     // Construct from imported and shared data and user construction
0092     ProcessBuilder(ImportData const& data,
0093                    SPConstParticle particle,
0094                    SPConstMaterial material,
0095                    UserBuildMap user_build,
0096                    Options options);
0097 
0098     // Construct without custom user builders
0099     ProcessBuilder(ImportData const& data,
0100                    SPConstParticle particle,
0101                    SPConstMaterial material,
0102                    Options options);
0103 
0104     // Default destructor
0105     ~ProcessBuilder();
0106 
0107     // Create a process from the data
0108     SPProcess operator()(IPC ipc);
0109 
0110   private:
0111     //// DATA ////
0112 
0113     UserBuildInput input_;
0114     UserBuildMap user_build_map_;
0115     std::function<ImportSBTable(AtomicNumber)> read_sb_;
0116     std::function<ImportLivermorePE(AtomicNumber)> read_livermore_;
0117     std::function<ImportPhysicsVector(AtomicNumber)> read_neutron_elastic_;
0118 
0119     BremsModelSelection selection_;
0120     bool brem_combined_;
0121     bool enable_lpm_;
0122     bool use_integral_xs_;
0123 
0124     //// HELPER FUNCTIONS ////
0125 
0126     SPConstMaterial const material() const { return input_.material; }
0127     SPConstParticle const particle() const { return input_.particle; }
0128     SPConstImported const imported() const { return input_.imported; }
0129 
0130     auto build_annihilation() -> SPProcess;
0131     auto build_compton() -> SPProcess;
0132     auto build_conversion() -> SPProcess;
0133     auto build_coulomb() -> SPProcess;
0134     auto build_ebrems() -> SPProcess;
0135     auto build_eioni() -> SPProcess;
0136     auto build_mubrems() -> SPProcess;
0137     auto build_muioni() -> SPProcess;
0138     auto build_msc() -> SPProcess;
0139     auto build_neutron_elastic() -> SPProcess;
0140     auto build_photoelectric() -> SPProcess;
0141     auto build_rayleigh() -> SPProcess;
0142 };
0143 
0144 //---------------------------------------------------------------------------//
0145 /*!
0146  * Warn about a missing process and deliberately skip it.
0147  *
0148  * Example:
0149  * \code
0150   ProcessBuilder::UserBuildMap ubm;
0151   ubm.emplace(ImportProcessClass::coulomb_scat,
0152               WarnAndIgnoreProcess{ImportProcessClass::coulomb_scat});
0153  * \endcode
0154  */
0155 struct WarnAndIgnoreProcess
0156 {
0157     //// TYPES ////
0158     using argument_type = ProcessBuilder::UserBuildInput const&;
0159     using result_type = ProcessBuilder::SPProcess;
0160 
0161     //// DATA ////
0162 
0163     ImportProcessClass process;
0164 
0165     //// METHODS ////
0166 
0167     result_type operator()(argument_type) const;
0168 };
0169 
0170 //---------------------------------------------------------------------------//
0171 }  // namespace celeritas