![]() |
|
|||
File indexing completed on 2025-09-17 08:53:38
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 celeritas/field/CartMapField.covfie.hh 0006 //---------------------------------------------------------------------------// 0007 #pragma once 0008 0009 #include <type_traits> 0010 0011 #include "corecel/Macros.hh" 0012 #include "corecel/Types.hh" 0013 #include "corecel/cont/Array.hh" 0014 #include "corecel/cont/Range.hh" 0015 #include "celeritas/Types.hh" 0016 #include "celeritas/field/CartMapFieldData.hh" 0017 0018 #include "detail/CovfieFieldTraits.hh" 0019 0020 namespace celeritas 0021 { 0022 //---------------------------------------------------------------------------// 0023 /*! 0024 * Interpolate a magnetic field vector on an x/y/z grid. 0025 */ 0026 class CartMapField 0027 { 0028 public: 0029 //!@{ 0030 //! \name Type aliases 0031 using real_type = float; 0032 using Real3 = Array<celeritas::real_type, 3>; 0033 using FieldParamsRef = NativeCRef<CartMapFieldParamsData>; 0034 //!@} 0035 0036 public: 0037 // Construct with the shared map data 0038 inline CELER_FUNCTION explicit CartMapField(FieldParamsRef const& shared); 0039 0040 // Evaluate the magnetic field value for the given position 0041 CELER_FUNCTION 0042 inline Real3 operator()(Real3 const& pos) const; 0043 0044 private: 0045 using field_view_t = FieldParamsRef::view_t; 0046 field_view_t const& field_; 0047 }; 0048 0049 //---------------------------------------------------------------------------// 0050 // INLINE DEFINITIONS 0051 //---------------------------------------------------------------------------// 0052 /*! 0053 * Construct with the shared magnetic field map data. 0054 */ 0055 CELER_FUNCTION 0056 CartMapField::CartMapField(FieldParamsRef const& shared) 0057 : field_{shared.get_view()} 0058 { 0059 } 0060 0061 //---------------------------------------------------------------------------// 0062 /*! 0063 * Calculate the magnetic field vector for the given position. 0064 * 0065 * This does a 3-D interpolation on the input grid and reconstructs the 0066 * magnetic field vector from the stored X, Y, Z components of the field. 0067 * The result is in the native Celeritas unit system. 0068 */ 0069 CELER_FUNCTION auto CartMapField::operator()(Real3 const& pos) const -> Real3 0070 { 0071 return detail::CovfieFieldTraits<MemSpace::native>::to_array( 0072 field_.at(static_cast<real_type>(pos[0]), 0073 static_cast<real_type>(pos[1]), 0074 static_cast<real_type>(pos[2]))); 0075 } 0076 0077 //---------------------------------------------------------------------------// 0078 } // namespace celeritas
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |