Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:05:58

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 orange/OrangeInput.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <algorithm>
0011 #include <iosfwd>
0012 #include <map>
0013 #include <variant>
0014 #include <vector>
0015 
0016 #include "corecel/io/Label.hh"
0017 #include "geocel/BoundingBox.hh"
0018 
0019 #include "OrangeData.hh"
0020 #include "OrangeTypes.hh"
0021 #include "surf/VariantSurface.hh"
0022 #include "transform/VariantTransform.hh"
0023 
0024 namespace celeritas
0025 {
0026 //---------------------------------------------------------------------------//
0027 /*!
0028  * Input definition for a single oriented bounding zone.
0029  */
0030 struct OrientedBoundingZoneInput
0031 {
0032     //! Inner bounding box
0033     BBox inner;
0034     //! Outer bounding box
0035     BBox outer;
0036     //! Local to global transformation
0037     TransformId transform_id;
0038 
0039     //! Whether the obz definition is valid
0040     explicit operator bool() const { return inner && outer && transform_id; }
0041 };
0042 
0043 //---------------------------------------------------------------------------//
0044 /*!
0045  * Input definition for a single volume.
0046  */
0047 struct VolumeInput
0048 {
0049     using Flags = VolumeRecord::Flags;
0050 
0051     //! Volume label
0052     Label label{};
0053 
0054     //! Sorted list of surface IDs in this volume
0055     std::vector<LocalSurfaceId> faces{};
0056     //! RPN region definition for this volume, using local surface index
0057     std::vector<logic_int> logic{};
0058     //! Axis-aligned bounding box
0059     BBox bbox{};
0060     //! OrientedBoundingZone
0061     OrientedBoundingZoneInput obz;
0062 
0063     //! Special flags
0064     logic_int flags{0};
0065     //! Masking priority
0066     ZOrder zorder{};
0067 
0068     //! Whether the volume definition is valid
0069     explicit operator bool() const
0070     {
0071         return (!logic.empty() || (flags & Flags::implicit_vol))
0072                && zorder != ZOrder::invalid;
0073     }
0074 };
0075 
0076 //---------------------------------------------------------------------------//
0077 /*!
0078  * Input definition a daughter universe embedded in a parent cell.
0079  */
0080 struct DaughterInput
0081 {
0082     UniverseId universe_id;
0083     VariantTransform transform;
0084 };
0085 
0086 //---------------------------------------------------------------------------//
0087 /*!
0088  * Input definition for a unit.
0089  *
0090  * \todo Add a CsgTree object and \c vector<NodeId> volumes;
0091  */
0092 struct UnitInput
0093 {
0094     using MapVolumeDaughter = std::map<LocalVolumeId, DaughterInput>;
0095 
0096     std::vector<VariantSurface> surfaces;
0097     std::vector<VolumeInput> volumes;
0098     BBox bbox;  //!< Outer bounding box
0099     MapVolumeDaughter daughter_map;
0100 
0101     // Unit metadata
0102     std::vector<Label> surface_labels;
0103     Label label;
0104 
0105     //! Whether the unit definition is valid
0106     explicit operator bool() const { return !volumes.empty(); }
0107 };
0108 
0109 //---------------------------------------------------------------------------//
0110 /*!
0111  * Input definition for a rectangular array universe.
0112  */
0113 struct RectArrayInput
0114 {
0115     // Grid boundaries in x, y, and z
0116     Array<std::vector<double>, 3> grid;
0117 
0118     // Daughters in each cell [x][y][z]
0119     std::vector<DaughterInput> daughters;
0120 
0121     // Unit metadata
0122     Label label;
0123 
0124     //! Whether the universe definition is valid
0125     explicit operator bool() const
0126     {
0127         return !daughters.empty()
0128                && std::all_of(grid.begin(), grid.end(), [](auto& v) {
0129                       return v.size() >= 2;
0130                   });
0131     }
0132 };
0133 
0134 //---------------------------------------------------------------------------//
0135 //! Possible types of universe inputs
0136 using VariantUniverseInput = std::variant<UnitInput, RectArrayInput>;
0137 
0138 //---------------------------------------------------------------------------//
0139 /*!
0140  * Construction definition for a full ORANGE geometry.
0141  */
0142 struct OrangeInput
0143 {
0144     std::vector<VariantUniverseInput> universes;
0145 
0146     //! Relative and absolute error for construction and transport
0147     Tolerance<> tol;
0148 
0149     //! Whether the unit definition is valid
0150     explicit operator bool() const { return !universes.empty() && tol; }
0151 };
0152 
0153 //---------------------------------------------------------------------------//
0154 // Helper to read the input from a file or stream
0155 std::istream& operator>>(std::istream& is, OrangeInput&);
0156 
0157 //---------------------------------------------------------------------------//
0158 // Helper to write the input to a file or stream
0159 std::ostream& operator<<(std::ostream& os, OrangeInput const&);
0160 
0161 //---------------------------------------------------------------------------//
0162 }  // namespace celeritas