File indexing completed on 2025-01-18 10:14:03
0001
0002
0003
0004 #ifndef VECGEOM_VOLUMES_KERNEL_SCALEDSHAPEIMPLEMENTATION_H_
0005 #define VECGEOM_VOLUMES_KERNEL_SCALEDSHAPEIMPLEMENTATION_H_
0006
0007 #include "VecGeom/volumes/kernel/GenericKernels.h"
0008 #include "VecGeom/base/Vector3D.h"
0009 #include "VecGeom/volumes/ScaledShapeStruct.h"
0010
0011 #include <cstdio>
0012
0013 namespace vecgeom {
0014
0015 VECGEOM_DEVICE_FORWARD_DECLARE(struct ScaledShapeImplementation;);
0016 VECGEOM_DEVICE_DECLARE_CONV(struct, ScaledShapeImplementation);
0017
0018 inline namespace VECGEOM_IMPL_NAMESPACE {
0019
0020 class PlacedScaledShape;
0021 class UnplacedScaledShape;
0022
0023
0024
0025
0026 struct ScaledShapeImplementation {
0027
0028 using PlacedShape_t = PlacedScaledShape;
0029 using UnplacedStruct_t = ScaledShapeStruct<Precision>;
0030 using UnplacedVolume_t = UnplacedScaledShape;
0031
0032 VECCORE_ATT_HOST_DEVICE
0033 static void PrintType()
0034 {
0035
0036 }
0037
0038 template <typename Stream>
0039 static void PrintType(Stream &s, int transCodeT = translation::kGeneric, int rotCodeT = rotation::kGeneric)
0040 {
0041 s << "SpecializedScaledShape<" << transCodeT << "," << rotCodeT << ","
0042 << ">";
0043 }
0044
0045 template <typename Stream>
0046 static void PrintImplementationType(Stream & )
0047 {
0048
0049 }
0050
0051 template <typename Stream>
0052 static void PrintUnplacedType(Stream & )
0053 {
0054
0055 }
0056
0057 template <typename Real_v, typename Bool_v>
0058 VECGEOM_FORCE_INLINE
0059 VECCORE_ATT_HOST_DEVICE
0060 static void Contains(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point, Bool_v &inside);
0061
0062 template <typename Real_v, typename Inside_t>
0063 VECGEOM_FORCE_INLINE
0064 VECCORE_ATT_HOST_DEVICE
0065 static void Inside(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point, Inside_t &inside);
0066
0067 template <typename Real_v>
0068 VECGEOM_FORCE_INLINE
0069 VECCORE_ATT_HOST_DEVICE
0070 static void DistanceToIn(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0071 Vector3D<Real_v> const &direction, Real_v const &stepMax, Real_v &distance);
0072
0073 template <typename Real_v>
0074 VECGEOM_FORCE_INLINE
0075 VECCORE_ATT_HOST_DEVICE
0076 static void DistanceToOut(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0077 Vector3D<Real_v> const &direction, Real_v const &stepMax, Real_v &distance);
0078
0079 template <typename Real_v>
0080 VECGEOM_FORCE_INLINE
0081 VECCORE_ATT_HOST_DEVICE
0082 static void SafetyToIn(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point, Real_v &safety);
0083
0084 template <typename Real_v>
0085 VECGEOM_FORCE_INLINE
0086 VECCORE_ATT_HOST_DEVICE
0087 static void SafetyToOut(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point, Real_v &safety);
0088
0089 template <typename Real_v>
0090 VECGEOM_FORCE_INLINE
0091 VECCORE_ATT_HOST_DEVICE
0092 static void NormalKernel(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point, Vector3D<Real_v> &normal,
0093 vecCore::Mask_v<Real_v> &valid);
0094
0095 };
0096
0097
0098
0099 template <typename Real_v, typename Bool_v>
0100 VECCORE_ATT_HOST_DEVICE
0101 void ScaledShapeImplementation::Contains(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0102 Bool_v &inside)
0103 {
0104
0105
0106 Vector3D<Real_v> ulocalPoint;
0107 unplaced.fScale.Transform(point, ulocalPoint);
0108
0109
0110 inside = unplaced.fPlaced->Contains(ulocalPoint);
0111 }
0112
0113 template <typename Real_v, typename Inside_t>
0114 VECCORE_ATT_HOST_DEVICE
0115 void ScaledShapeImplementation::Inside(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0116 Inside_t &inside)
0117 {
0118
0119
0120 Vector3D<Real_v> ulocalPoint;
0121 unplaced.fScale.Transform(point, ulocalPoint);
0122
0123
0124 inside = unplaced.fPlaced->Inside(ulocalPoint);
0125 }
0126
0127 template <typename Real_v>
0128 VECCORE_ATT_HOST_DEVICE
0129 void ScaledShapeImplementation::DistanceToIn(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0130 Vector3D<Real_v> const &direction, Real_v const &stepMax, Real_v &distance)
0131 {
0132
0133
0134 Vector3D<Real_v> ulocalPoint;
0135 unplaced.fScale.Transform(point, ulocalPoint);
0136
0137
0138 Vector3D<Real_v> ulocalDir;
0139 unplaced.fScale.Transform(direction, ulocalDir);
0140 ulocalDir.Normalize();
0141
0142 auto ustepMax = unplaced.fScale.TransformDistance(stepMax, direction);
0143
0144
0145 distance = unplaced.fPlaced->DistanceToIn(ulocalPoint, ulocalDir, ustepMax);
0146
0147
0148 vecCore__MaskedAssignFunc(distance, distance < InfinityLength<Real_v>(),
0149 unplaced.fScale.InverseTransformDistance(distance, ulocalDir));
0150 }
0151
0152 template <typename Real_v>
0153 VECCORE_ATT_HOST_DEVICE
0154 void ScaledShapeImplementation::DistanceToOut(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0155 Vector3D<Real_v> const &direction, Real_v const &stepMax,
0156 Real_v &distance)
0157 {
0158
0159
0160 Vector3D<Real_v> ulocalPoint;
0161 unplaced.fScale.Transform(point, ulocalPoint);
0162
0163
0164 Vector3D<Real_v> ulocalDir;
0165 unplaced.fScale.Transform(direction, ulocalDir);
0166 ulocalDir.Normalize();
0167
0168 auto ustepMax = unplaced.fScale.TransformDistance(stepMax, direction);
0169
0170
0171 distance = unplaced.fPlaced->DistanceToOut(ulocalPoint, ulocalDir, ustepMax);
0172
0173
0174 vecCore__MaskedAssignFunc(distance, distance < InfinityLength<Real_v>(),
0175 unplaced.fScale.InverseTransformDistance(distance, ulocalDir));
0176 }
0177
0178 template <typename Real_v>
0179 VECCORE_ATT_HOST_DEVICE
0180 void ScaledShapeImplementation::SafetyToIn(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0181 Real_v &safety)
0182 {
0183
0184
0185 Vector3D<Real_v> ulocalPoint;
0186 unplaced.fScale.Transform(point, ulocalPoint);
0187
0188
0189 safety = unplaced.fPlaced->SafetyToIn(ulocalPoint);
0190 safety = unplaced.fScale.InverseTransformSafety(safety);
0191 }
0192
0193 template <typename Real_v>
0194 VECCORE_ATT_HOST_DEVICE
0195 void ScaledShapeImplementation::SafetyToOut(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0196 Real_v &safety)
0197 {
0198
0199
0200 Vector3D<Real_v> ulocalPoint;
0201 unplaced.fScale.Transform(point, ulocalPoint);
0202
0203
0204 safety = unplaced.fPlaced->SafetyToOut(ulocalPoint);
0205 safety = unplaced.fScale.InverseTransformSafety(safety);
0206 }
0207
0208 template <typename Real_v>
0209 VECCORE_ATT_HOST_DEVICE
0210 void ScaledShapeImplementation::NormalKernel(UnplacedStruct_t const &unplaced, Vector3D<Real_v> const &point,
0211 Vector3D<Real_v> &normal, vecCore::Mask_v<Real_v> & )
0212 {
0213
0214
0215 Vector3D<Real_v> ulocalPoint;
0216 unplaced.fScale.Transform(point, ulocalPoint);
0217
0218
0219 Vector3D<Real_v> ulocalNorm;
0220 unplaced.fPlaced->Normal(ulocalPoint, ulocalNorm );
0221
0222
0223 unplaced.fScale.InverseTransformNormal(ulocalNorm, normal);
0224 normal.Normalize();
0225 }
0226 }
0227 }
0228
0229 #endif