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