Back to home page

EIC code displayed by LXR

 
 

    


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

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/transform/Translation.hh
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include <algorithm>
0011 
0012 #include "corecel/cont/Span.hh"
0013 #include "corecel/math/Algorithms.hh"
0014 #include "corecel/math/ArrayOperators.hh"
0015 #include "orange/OrangeTypes.hh"
0016 
0017 namespace celeritas
0018 {
0019 //---------------------------------------------------------------------------//
0020 /*!
0021  * Apply a translation (no rotation).
0022  *
0023  * The input translation is specified by translating the daughter's coordinate
0024  * into the parent.
0025  */
0026 class Translation
0027 {
0028   public:
0029     //@{
0030     //! \name Type aliases
0031     using StorageSpan = Span<real_type const, 3>;
0032     //@}
0033 
0034     //! Transform type identifier
0035     static CELER_CONSTEXPR_FUNCTION TransformType transform_type()
0036     {
0037         return TransformType::translation;
0038     }
0039 
0040   public:
0041     //! Construct with an identity translation
0042     explicit CELER_FUNCTION Translation() : tra_{0, 0, 0} {}
0043 
0044     //! Construct with the translation vector
0045     explicit CELER_FUNCTION Translation(Real3 const& trans) : tra_(trans) {}
0046 
0047     // Construct inline from storage
0048     explicit inline CELER_FUNCTION Translation(StorageSpan s);
0049 
0050     //// ACCESSORS ////
0051 
0052     //! Translation vector
0053     CELER_FORCEINLINE_FUNCTION Real3 const& translation() const
0054     {
0055         return tra_;
0056     }
0057 
0058     //! Get a view to the data for type-deleted storage
0059     CELER_FUNCTION StorageSpan data() const { return {&tra_[0], 3}; }
0060 
0061     //// CALCULATION ////
0062 
0063     // Transform from daughter to parent
0064     inline CELER_FUNCTION Real3 transform_up(Real3 const& pos) const;
0065 
0066     // Transform from parent to daughter
0067     inline CELER_FUNCTION Real3 transform_down(Real3 const& parent_pos) const;
0068 
0069     // Rotate from daughter to parent (identity)
0070     inline CELER_FUNCTION Real3 const& rotate_up(Real3 const& d) const;
0071 
0072     // Rotate from parent to daughter (identity)
0073     inline CELER_FUNCTION Real3 const& rotate_down(Real3 const& d) const;
0074 
0075     //! Calculate the inverse during preprocessing
0076     Translation calc_inverse() const { return Translation{negate(tra_)}; }
0077 
0078   private:
0079     Real3 tra_;
0080 };
0081 
0082 //---------------------------------------------------------------------------//
0083 // FREE FUNCTIONS
0084 //---------------------------------------------------------------------------//
0085 //!@{
0086 //! Host-only comparators
0087 inline bool operator==(Translation const& a, Translation const& b)
0088 {
0089     auto a_data = a.data();
0090     return std::equal(a_data.begin(), a_data.end(), b.data().begin());
0091 }
0092 
0093 inline bool operator!=(Translation const& a, Translation const& b)
0094 {
0095     return !(a == b);
0096 }
0097 //!@}
0098 
0099 //---------------------------------------------------------------------------//
0100 // INLINE DEFINITIONS
0101 //---------------------------------------------------------------------------//
0102 /*!
0103  * Construct inline from storage.
0104  */
0105 CELER_FUNCTION Translation::Translation(StorageSpan s) : tra_{s[0], s[1], s[2]}
0106 {
0107 }
0108 
0109 //---------------------------------------------------------------------------//
0110 /*!
0111  * Transform from daughter to parent.
0112  */
0113 CELER_FORCEINLINE_FUNCTION Real3 Translation::transform_up(Real3 const& pos) const
0114 {
0115     return pos + tra_;
0116 }
0117 
0118 //---------------------------------------------------------------------------//
0119 /*!
0120  * Transform from parent to daughter.
0121  */
0122 CELER_FORCEINLINE_FUNCTION Real3
0123 Translation::transform_down(Real3 const& parent_pos) const
0124 {
0125     return parent_pos - tra_;
0126 }
0127 
0128 //---------------------------------------------------------------------------//
0129 /*!
0130  * Rotate from daughter to parent (identity).
0131  */
0132 CELER_FORCEINLINE_FUNCTION Real3 const&
0133 Translation::rotate_up(Real3 const& d) const
0134 {
0135     return d;
0136 }
0137 
0138 //---------------------------------------------------------------------------//
0139 /*!
0140  * Rotate from parent to daughter (identity).
0141  */
0142 CELER_FORCEINLINE_FUNCTION Real3 const&
0143 Translation::rotate_down(Real3 const& d) const
0144 {
0145     return d;
0146 }
0147 
0148 //---------------------------------------------------------------------------//
0149 }  // namespace celeritas