Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //----------------------------------*-C++-*----------------------------------//
0002 // Copyright 2023-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/FaceNamer.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <string>
0011 #include <utility>
0012 
0013 #include "orange/OrangeTypes.hh"
0014 
0015 #include "SurfaceFwd.hh"
0016 #include "VariantSurface.hh"
0017 
0018 namespace celeritas
0019 {
0020 //---------------------------------------------------------------------------//
0021 /*!
0022  * Return a "name" for a face.
0023  *
0024  * This is generally a very short string to be used as an extension for a
0025  * volume comprised of several intersecting surface half-spaces. Because
0026  * successive surfaces should have separate names, this has a small internal
0027  * state.
0028  */
0029 class FaceNamer
0030 {
0031   public:
0032     // Construct with no prefix
0033     FaceNamer() = default;
0034 
0035     // Construct with prefix
0036     explicit inline FaceNamer(std::string&& prefix);
0037 
0038     // Apply to a surface with known type
0039     template<class S>
0040     inline std::string operator()(Sense s, S const& surf);
0041 
0042     // Apply to a surface with unknown type
0043     std::string operator()(Sense s, VariantSurface const& surf);
0044 
0045     // Apply with an explicit name
0046     inline std::string operator()(std::string const& s) const;
0047 
0048   private:
0049     struct State
0050     {
0051         int num_plane{0};
0052         int num_gq{0};
0053     };
0054 
0055     // String prefix
0056     std::string prefix_;
0057 
0058     // Persistent state
0059     State state_;
0060 
0061     // Nested implementation class
0062     struct Impl
0063     {
0064         State* state_;
0065         Sense sense_;
0066 
0067         //// OPERATORS ////
0068 
0069         template<Axis T>
0070         std::string operator()(PlaneAligned<T> const&) const;
0071 
0072         template<Axis T>
0073         std::string operator()(CylCentered<T> const&) const;
0074 
0075         std::string operator()(SphereCentered const&) const;
0076 
0077         template<Axis T>
0078         std::string operator()(CylAligned<T> const&) const;
0079 
0080         std::string operator()(Plane const&) const;
0081 
0082         std::string operator()(Sphere const&) const;
0083 
0084         template<Axis T>
0085         std::string operator()(ConeAligned<T> const&) const;
0086 
0087         std::string operator()(SimpleQuadric const&) const;
0088 
0089         std::string operator()(GeneralQuadric const&) const;
0090 
0091         std::string operator()(Involute const&) const;
0092     };
0093 };
0094 
0095 //---------------------------------------------------------------------------//
0096 /*!
0097  * Construct with prefix.
0098  */
0099 FaceNamer::FaceNamer(std::string&& prefix) : prefix_{std::move(prefix)}
0100 {
0101     if (!prefix_.empty() && prefix_.back() != '.')
0102     {
0103         prefix_.push_back('.');
0104     }
0105 }
0106 
0107 //---------------------------------------------------------------------------//
0108 /*!
0109  * Apply to a surface with known type.
0110  */
0111 template<class S>
0112 std::string FaceNamer::operator()(Sense s, S const& surf)
0113 {
0114     std::string result = prefix_;
0115     result += Impl{&state_, s}(surf);
0116     return result;
0117 }
0118 
0119 //---------------------------------------------------------------------------//
0120 /*!
0121  * Apply with an explicit face name.
0122  *
0123  * This can be useful for instances such as "generic trapezoid" where the
0124  * surface type can change based on whether the face is planar or twisted.
0125  */
0126 std::string FaceNamer::operator()(std::string const& s) const
0127 {
0128     std::string result = prefix_;
0129     result += s;
0130     return result;
0131 }
0132 
0133 //---------------------------------------------------------------------------//
0134 }  // namespace celeritas