Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:53:44

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/optical/ModelImporter.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <functional>
0010 #include <memory>
0011 #include <optional>
0012 #include <unordered_map>
0013 #include <vector>
0014 
0015 #include "celeritas/io/ImportOpticalModel.hh"
0016 
0017 #include "Model.hh"
0018 #include "Types.hh"
0019 
0020 namespace celeritas
0021 {
0022 class MaterialParams;
0023 struct ImportData;
0024 struct ImportOpticalRayleigh;
0025 struct ImportWavelengthShift;
0026 
0027 namespace optical
0028 {
0029 class MaterialParams;
0030 class ImportedModels;
0031 class ImportedMaterials;
0032 //---------------------------------------------------------------------------//
0033 /*!
0034  * Construct Celeritas optical model builders from imported data.
0035  */
0036 class ModelImporter
0037 {
0038   public:
0039     //!@{
0040     //! \name Type aliases
0041     using IMC = ImportModelClass;
0042     using SPConstImported = std::shared_ptr<ImportedModels const>;
0043     using SPConstMaterial = std::shared_ptr<MaterialParams const>;
0044     using SPConstImportedMaterial = std::shared_ptr<ImportedMaterials const>;
0045     using SPConstCoreMaterial
0046         = std::shared_ptr<::celeritas::MaterialParams const>;
0047     //!@}
0048 
0049     //! Input argument for user-provided process construction
0050     struct UserBuildInput
0051     {
0052         SPConstImported imported;
0053         SPConstMaterial material;
0054         SPConstImportedMaterial import_material;
0055         SPConstCoreMaterial core_material;
0056     };
0057 
0058     //!@{
0059     //! \name User builder type aliases
0060     using ModelBuilder = Model::ModelBuilder;
0061     using UserBuildFunction
0062         = std::function<std::optional<ModelBuilder>(UserBuildInput const&)>;
0063     using UserBuildMap = std::unordered_map<IMC, UserBuildFunction>;
0064     //!@}
0065 
0066   public:
0067     // Construct from imported and shared data with user construction
0068     ModelImporter(ImportData const& data,
0069                   SPConstMaterial material,
0070                   SPConstCoreMaterial core_material,
0071                   UserBuildMap user_build);
0072 
0073     // Construct without custom user builders
0074     ModelImporter(ImportData const& data,
0075                   SPConstMaterial material,
0076                   SPConstCoreMaterial core_material);
0077 
0078     // Create a model builder from the data
0079     std::optional<ModelBuilder> operator()(IMC imc) const;
0080 
0081   private:
0082     UserBuildInput input_;
0083     UserBuildMap user_build_map_;
0084 
0085     SPConstImported const& imported() const { return input_.imported; }
0086     SPConstMaterial const& material() const { return input_.material; }
0087     SPConstImportedMaterial const& import_material() const
0088     {
0089         return input_.import_material;
0090     }
0091     SPConstCoreMaterial const& core_material() const
0092     {
0093         return input_.core_material;
0094     }
0095 
0096     ModelBuilder build_absorption() const;
0097     ModelBuilder build_rayleigh() const;
0098 };
0099 
0100 //---------------------------------------------------------------------------//
0101 /*!
0102  * Warn about a missing optical model and deliberately skip it.
0103  *
0104  * May be provided as a custom user build function to \c ModelImporter to
0105  * skip the construction of an optical model builder.
0106  */
0107 struct WarnAndIgnoreModel
0108 {
0109     //!@{
0110     //! \name Type aliases
0111     using UserBuildInput = ModelImporter::UserBuildInput;
0112     using ModelBuilder = ModelImporter::ModelBuilder;
0113     //!@}
0114 
0115     // Warn about a missing optical model and ignore it
0116     std::optional<ModelBuilder> operator()(UserBuildInput const&) const;
0117 
0118     //! Missing optical model to warn about
0119     ImportModelClass model;
0120 };
0121 
0122 //---------------------------------------------------------------------------//
0123 }  // namespace optical
0124 }  // namespace celeritas