Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:17:12

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