Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:07: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/surf/SurfaceTypeTraits.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include "corecel/cont/EnumClassUtils.hh"
0010 #include "corecel/math/Algorithms.hh"
0011 #include "orange/OrangeTypes.hh"
0012 
0013 #include "SurfaceFwd.hh"
0014 
0015 namespace celeritas
0016 {
0017 //---------------------------------------------------------------------------//
0018 /*!
0019  * Map surface enumeration to surface type.
0020  *
0021  * This class can be passed as a "tag" to functors that can then retrieve its
0022  * value or the associated class. It can be implicitly converted into a
0023  * SurfaceType enum for use in template parameters.
0024  */
0025 template<SurfaceType S>
0026 struct SurfaceTypeTraits;
0027 
0028 #define ORANGE_SURFACE_TRAITS(ENUM_VALUE, CLS)                          \
0029     template<>                                                          \
0030     struct SurfaceTypeTraits<SurfaceType::ENUM_VALUE>                   \
0031         : public EnumToClass<SurfaceType, SurfaceType::ENUM_VALUE, CLS> \
0032     {                                                                   \
0033     }
0034 
0035 // clang-format off
0036 ORANGE_SURFACE_TRAITS(px,  PlaneAligned<Axis::x>);
0037 ORANGE_SURFACE_TRAITS(py,  PlaneAligned<Axis::y>);
0038 ORANGE_SURFACE_TRAITS(pz,  PlaneAligned<Axis::z>);
0039 ORANGE_SURFACE_TRAITS(cxc, CylCentered<Axis::x>);
0040 ORANGE_SURFACE_TRAITS(cyc, CylCentered<Axis::y>);
0041 ORANGE_SURFACE_TRAITS(czc, CylCentered<Axis::z>);
0042 ORANGE_SURFACE_TRAITS(sc,  SphereCentered);
0043 ORANGE_SURFACE_TRAITS(cx,  CylAligned<Axis::x>);
0044 ORANGE_SURFACE_TRAITS(cy,  CylAligned<Axis::y>);
0045 ORANGE_SURFACE_TRAITS(cz,  CylAligned<Axis::z>);
0046 ORANGE_SURFACE_TRAITS(p,   Plane);
0047 ORANGE_SURFACE_TRAITS(s,   Sphere);
0048 ORANGE_SURFACE_TRAITS(kx,  ConeAligned<Axis::x>);
0049 ORANGE_SURFACE_TRAITS(ky,  ConeAligned<Axis::y>);
0050 ORANGE_SURFACE_TRAITS(kz,  ConeAligned<Axis::z>);
0051 ORANGE_SURFACE_TRAITS(sq,  SimpleQuadric);
0052 ORANGE_SURFACE_TRAITS(gq,  GeneralQuadric);
0053 ORANGE_SURFACE_TRAITS(inv, Involute);
0054 // clang-format on
0055 
0056 #undef ORANGE_SURFACE_TRAITS
0057 
0058 //---------------------------------------------------------------------------//
0059 /*!
0060  * Expand a macro to a switch statement over all possible surface types.
0061  *
0062  * The \c func argument should be a functor that takes a single argument which
0063  * is a SurfaceTypeTraits instance.
0064  */
0065 template<class F>
0066 CELER_CONSTEXPR_FUNCTION decltype(auto)
0067 visit_surface_type(F&& func, SurfaceType st)
0068 {
0069 #define ORANGE_ST_VISIT_CASE(TYPE)          \
0070     case SurfaceType::TYPE:                 \
0071         return celeritas::forward<F>(func)( \
0072             SurfaceTypeTraits<SurfaceType::TYPE>{})
0073 
0074     switch (st)
0075     {
0076         ORANGE_ST_VISIT_CASE(px);
0077         ORANGE_ST_VISIT_CASE(py);
0078         ORANGE_ST_VISIT_CASE(pz);
0079         ORANGE_ST_VISIT_CASE(cxc);
0080         ORANGE_ST_VISIT_CASE(cyc);
0081         ORANGE_ST_VISIT_CASE(czc);
0082         ORANGE_ST_VISIT_CASE(sc);
0083         ORANGE_ST_VISIT_CASE(cx);
0084         ORANGE_ST_VISIT_CASE(cy);
0085         ORANGE_ST_VISIT_CASE(cz);
0086         ORANGE_ST_VISIT_CASE(p);
0087         ORANGE_ST_VISIT_CASE(s);
0088         ORANGE_ST_VISIT_CASE(kx);
0089         ORANGE_ST_VISIT_CASE(ky);
0090         ORANGE_ST_VISIT_CASE(kz);
0091         ORANGE_ST_VISIT_CASE(sq);
0092         ORANGE_ST_VISIT_CASE(gq);
0093         case SurfaceType::inv:
0094             // Prevented by input reader: see
0095             // orange/detail/SurfacesRecordBuilder.cc
0096             CELER_ASSERT_UNREACHABLE();
0097         default:
0098             CELER_ASSERT_UNREACHABLE();
0099     }
0100 #undef ORANGE_ST_VISIT_CASE
0101 }
0102 
0103 //---------------------------------------------------------------------------//
0104 }  // namespace celeritas