Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-01 10:19:50

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/Shape.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <type_traits>
0010 
0011 #include "IntersectRegion.hh"
0012 #include "ObjectInterface.hh"
0013 
0014 namespace celeritas
0015 {
0016 namespace orangeinp
0017 {
0018 //---------------------------------------------------------------------------//
0019 /*!
0020  * A simple, intersect-only region of space.
0021  *
0022  * This is an abstract class that implements \c build for constructing a volume
0023  * by dispatching to a method \c build_interior that the daughters must
0024  * override using a intersect region.
0025  *
0026  * Use the implementation classes \c XShape where \c X is one of the
0027  * region types in IntersectRegion.hh :
0028  * - \c BoxShape
0029  * - \c ConeShape
0030  * - \c CylinderShape
0031  * - \c EllipsoidShape
0032  * - \c GenPrismShape
0033  * - \c ParallelepipedShape
0034  * - \c PrismShape
0035  * - \c SphereShape
0036  */
0037 class ShapeBase : public ObjectInterface
0038 {
0039   public:
0040     // Construct a volume from this object
0041     NodeId build(VolumeBuilder&) const final;
0042 
0043     // Write the shape to JSON
0044     void output(JsonPimpl*) const final;
0045 
0046     //! Get the user-provided label
0047     std::string_view label() const final { return label_; }
0048 
0049     //! Interior intersect region interface for construction and access
0050     virtual IntersectRegionInterface const& interior() const = 0;
0051 
0052     ~ShapeBase() override = default;
0053 
0054   protected:
0055     //!@{
0056     //! Allow construction and assignment only through daughter classes
0057     explicit ShapeBase(std::string&& label);
0058     CELER_DEFAULT_COPY_MOVE(ShapeBase);
0059     //!@}
0060 
0061   private:
0062     std::string label_;
0063 };
0064 
0065 //---------------------------------------------------------------------------//
0066 /*!
0067  * Shape that holds an intersect region and forwards construction args to it.
0068  *
0069  * Construct as: \code
0070     BoxShape s{"mybox", Real3{1, 2, 3}};
0071  * \endcode
0072  * or \code
0073  *  Shape s{"mybox", Box{{1, 2, 3}}};
0074  * \endcode
0075  *
0076  * See IntersectRegion.hh for a list of the regions and their construction
0077  * arguments.
0078  */
0079 template<class T>
0080 class Shape final : public ShapeBase
0081 {
0082     static_assert(std::is_base_of_v<IntersectRegionInterface, T>);
0083 
0084   public:
0085     //! Construct with a label and arguments of the intersect region
0086     template<class... Ts>
0087     Shape(std::string&& label, Ts... region_args)
0088         : ShapeBase{std::move(label)}
0089         , region_{std::forward<Ts>(region_args)...}
0090     {
0091     }
0092 
0093     //! Construct with a label and intersect region
0094     Shape(std::string&& label, T&& region)
0095         : ShapeBase{std::move(label)}, region_{std::move(region)}
0096     {
0097     }
0098 
0099     //! Interior intersect region
0100     IntersectRegionInterface const& interior() const final { return region_; }
0101 
0102   private:
0103     T region_;
0104 };
0105 
0106 //---------------------------------------------------------------------------//
0107 // DEDUCTION GUIDES
0108 //---------------------------------------------------------------------------//
0109 
0110 template<class T>
0111 Shape(std::string&&, T&&) -> Shape<T>;
0112 
0113 //---------------------------------------------------------------------------//
0114 /*!
0115  * Construct a shape by forwarding intersect region arguments.
0116  */
0117 template<class IR, class... Args>
0118 auto make_shape(std::string&& name, Args&&... args)
0119 {
0120     return std::make_shared<Shape<IR>>(std::move(name),
0121                                        IR(std::forward<Args>(args)...));
0122 }
0123 
0124 //---------------------------------------------------------------------------//
0125 // TYPE ALIASES
0126 //---------------------------------------------------------------------------//
0127 
0128 using BoxShape = Shape<Box>;
0129 using ConeShape = Shape<Cone>;
0130 using CylinderShape = Shape<Cylinder>;
0131 using EllipsoidShape = Shape<Ellipsoid>;
0132 using ExtrudedPolygonShape = Shape<ExtrudedPolygon>;
0133 using GenPrismShape = Shape<GenPrism>;
0134 using InvoluteShape = Shape<Involute>;
0135 using ParallelepipedShape = Shape<Parallelepiped>;
0136 using PrismShape = Shape<Prism>;
0137 using SphereShape = Shape<Sphere>;
0138 
0139 //---------------------------------------------------------------------------//
0140 // EXPLICIT INSTANTIATION
0141 //---------------------------------------------------------------------------//
0142 
0143 extern template class Shape<Box>;
0144 extern template class Shape<Cone>;
0145 extern template class Shape<Cylinder>;
0146 extern template class Shape<Ellipsoid>;
0147 extern template class Shape<ExtrudedPolygon>;
0148 extern template class Shape<GenPrism>;
0149 extern template class Shape<Involute>;
0150 extern template class Shape<Parallelepiped>;
0151 extern template class Shape<Prism>;
0152 extern template class Shape<Sphere>;
0153 
0154 //---------------------------------------------------------------------------//
0155 }  // namespace orangeinp
0156 }  // namespace celeritas