Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-15 09:06:14

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/detail/InvolutePoint.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <cmath>
0010 
0011 #include "corecel/Types.hh"
0012 #include "corecel/cont/Array.hh"
0013 #include "orange/OrangeTypes.hh"
0014 
0015 namespace celeritas
0016 {
0017 namespace detail
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Find point on involute using involute equation.
0022  *
0023  *  * \f[
0024  *   x = r_b (\cos(t+a) + t \sin(t+a))
0025  * \f]
0026  * \f[
0027  *   y = r_b (\sin(t+a) - t \cos(t+a))
0028  * \f]
0029  *
0030  */
0031 class InvolutePoint
0032 {
0033   public:
0034     //!@{
0035     //! \name Type aliases
0036     using Real2 = Array<real_type, 2>;
0037     //!@}
0038 
0039   public:
0040     // Construct involute from parameters
0041     inline CELER_FUNCTION InvolutePoint(real_type r_b, real_type a);
0042 
0043     // Calculate point on an involute
0044     inline CELER_FUNCTION Real2 operator()(real_type theta) const;
0045 
0046     //// ACCESSORS ////
0047 
0048     //! Get involute parameters
0049     CELER_FUNCTION real_type r_b() const { return r_b_; }
0050     CELER_FUNCTION real_type a() const { return a_; }
0051 
0052   private:
0053     //// DATA ////
0054 
0055     // Involute parameters
0056     real_type r_b_;
0057     real_type a_;
0058 };
0059 
0060 //---------------------------------------------------------------------------//
0061 // INLINE DEFINITIONS
0062 //---------------------------------------------------------------------------//
0063 /*!
0064  * Construct from involute parameters.
0065  */
0066 CELER_FUNCTION InvolutePoint::InvolutePoint(real_type r_b, real_type a)
0067     : r_b_(r_b), a_(a)
0068 {
0069     CELER_EXPECT(r_b > 0);
0070     CELER_EXPECT(a >= 0);
0071 }
0072 
0073 /*!
0074  * Calculate the point on an involute.
0075  */
0076 CELER_FUNCTION Real2 InvolutePoint::operator()(real_type theta) const
0077 {
0078     real_type angle = theta + a_;
0079     Real2 point;
0080     // TODO: check that compiler avoids recomputing trig functions
0081     point[0] = r_b_ * (std::cos(angle) + theta * std::sin(angle));
0082     point[1] = r_b_ * (std::sin(angle) - theta * std::cos(angle));
0083 
0084     return point;
0085 }
0086 //---------------------------------------------------------------------------//
0087 }  // namespace detail
0088 }  // namespace celeritas