Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/orange/orangeinp/detail/ProtoBuilder.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 orange/orangeinp/detail/ProtoBuilder.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <functional>
0010 
0011 #include "orange/OrangeInput.hh"
0012 #include "orange/OrangeTypes.hh"
0013 
0014 #include "ProtoMap.hh"
0015 
0016 namespace celeritas
0017 {
0018 struct JsonPimpl;
0019 namespace orangeinp
0020 {
0021 class ProtoInterface;
0022 
0023 namespace detail
0024 {
0025 //---------------------------------------------------------------------------//
0026 /*!
0027  * Manage data and state during the universe construction.
0028  *
0029  * This is a helper class passed to UnitProto::build which manages data for the
0030  * UnitProto -> OrangeInput build process. It also maintains the universe ID
0031  * of the current universe being constructed.
0032  */
0033 class ProtoBuilder
0034 {
0035   public:
0036     //!@{
0037     //! \name Type aliases
0038     using Tol = Tolerance<>;
0039     using SaveUnivJson = std::function<void(UnivId, JsonPimpl&&)>;
0040     //!@}
0041 
0042     //! Input options for construction
0043     struct Options
0044     {
0045         //! Save metadata during construction for each universe
0046         SaveUnivJson save_json;
0047 
0048         //! Remove bounding surfaces from lower-level universes
0049         bool implicit_parent_boundary{};
0050     };
0051 
0052   public:
0053     // Construct with output pointer, geometry construction options, and protos
0054     ProtoBuilder(OrangeInput* inp, ProtoMap const& protos, Options const& opts);
0055 
0056     //! Get the tolerance to use when constructing geometry
0057     Tol const& tol() const { return inp_->tol; }
0058 
0059     //! Whether output should be saved for each
0060     bool save_json() const { return static_cast<bool>(save_json_); }
0061 
0062     // Find a universe ID
0063     inline UnivId find_universe_id(ProtoInterface const*) const;
0064 
0065     // Get the UniverseId of the universe currently being built
0066     inline UnivId current_uid() const;
0067 
0068     //! Number of universes
0069     UnivId::size_type num_universes() const { return inp_->universes.size(); }
0070 
0071     //! Whether the current universe is the global universe
0072     bool is_global_universe() const
0073     {
0074         return this->current_uid() == orange_global_univ;
0075     }
0076 
0077     //! Whether to delete exterior boundaries of the current universe
0078     bool assume_inside() const
0079     {
0080         return implicit_parent_boundary_ && !this->is_global_universe();
0081     }
0082 
0083     //! Logic notation being constructed
0084     LogicNotation logic() const { return inp_->logic; }
0085 
0086     // Save debugging data for a universe
0087     void save_json(JsonPimpl&&) const;
0088 
0089     // Construct a universe (to be called *once* per proto)
0090     void insert(VariantUniverseInput&& unit);
0091 
0092   private:
0093     OrangeInput* inp_{};
0094     ProtoMap const& protos_;
0095     SaveUnivJson save_json_;
0096     bool implicit_parent_boundary_{};
0097 
0098     // State variables
0099     size_type num_univs_inserted_{0};
0100 };
0101 
0102 //---------------------------------------------------------------------------//
0103 // INLINE DEFINITIONS
0104 //---------------------------------------------------------------------------//
0105 /*!
0106  * Find a universe ID.
0107  */
0108 UnivId ProtoBuilder::find_universe_id(ProtoInterface const* p) const
0109 {
0110     return protos_.find(p);
0111 }
0112 
0113 //---------------------------------------------------------------------------//
0114 /*!
0115  * Get the UniverseId of the universe currently being built.
0116  */
0117 UnivId ProtoBuilder::current_uid() const
0118 {
0119     CELER_EXPECT(num_univs_inserted_ < this->num_universes());
0120     return UnivId{this->num_universes() - num_univs_inserted_ - 1};
0121 }
0122 
0123 //---------------------------------------------------------------------------//
0124 }  // namespace detail
0125 }  // namespace orangeinp
0126 }  // namespace celeritas