File indexing completed on 2025-01-18 10:14:16
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef VECGEOM_VOLUMES_UNPLACEDVOLUME_H_
0010 #define VECGEOM_VOLUMES_UNPLACEDVOLUME_H_
0011
0012 #include "VecGeom/base/Cuda.h"
0013 #include "VecGeom/base/Global.h"
0014 #include "VecGeom/base/Transformation3D.h"
0015 #include "VecGeom/base/SOA3D.h"
0016 #include "VecGeom/volumes/kernel/BoxImplementation.h"
0017 #include <string>
0018 #include <ostream>
0019
0020 #ifndef VECCORE_CUDA
0021 #include "VecGeom/volumes/SolidMesh.h"
0022 #endif
0023
0024 namespace vecgeom {
0025
0026 VECGEOM_DEVICE_FORWARD_DECLARE(class VUnplacedVolume;);
0027 VECGEOM_DEVICE_DECLARE_CONV(class, VUnplacedVolume);
0028
0029 inline namespace VECGEOM_IMPL_NAMESPACE {
0030
0031 class LogicalVolume;
0032 class VPlacedVolume;
0033
0034
0035
0036
0037
0038
0039
0040
0041 class VUnplacedVolume {
0042
0043 private:
0044 friend class CudaManager;
0045 Vector3D<Precision> fBBox[2];
0046
0047 protected:
0048 bool fGlobalConvexity;
0049 bool fIsAssembly = false;
0050
0051 public:
0052
0053 using Real_v = vecgeom::VectorBackend::Real_v;
0054
0055 VECCORE_ATT_HOST_DEVICE
0056 virtual ~VUnplacedVolume() {}
0057
0058 VECGEOM_FORCE_INLINE
0059 VECCORE_ATT_HOST_DEVICE
0060 void SetBBox(Vector3D<Precision> const &amin, Vector3D<Precision> const &amax)
0061 {
0062 fBBox[0] = amin;
0063 fBBox[1] = amax;
0064 }
0065
0066 VECGEOM_FORCE_INLINE
0067 VECCORE_ATT_HOST_DEVICE
0068 void GetBBox(Vector3D<Precision> &amin, Vector3D<Precision> &amax) const
0069 {
0070 amin = fBBox[0];
0071 amax = fBBox[1];
0072 }
0073
0074 VECGEOM_FORCE_INLINE
0075 VECCORE_ATT_HOST_DEVICE
0076 void ComputeBBox()
0077 {
0078 #ifndef VECCORE_CUDA_DEVICE_COMPILATION
0079 Extent(fBBox[0], fBBox[1]);
0080 #endif
0081 }
0082
0083
0084
0085
0086
0087
0088 VECCORE_ATT_HOST_DEVICE
0089 virtual bool Contains(Vector3D<Precision> const &pos) const = 0;
0090
0091
0092
0093
0094
0095 VECCORE_ATT_HOST_DEVICE
0096 virtual EnumInside Inside(Vector3D<Precision> const &pos) const = 0;
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108 VECCORE_ATT_HOST_DEVICE
0109 virtual Precision DistanceToOut(Vector3D<Precision> const &pos, Vector3D<Precision> const &dir,
0110 Precision step_max = kInfLength) const = 0;
0111
0112
0113
0114
0115
0116
0117 VECCORE_ATT_HOST_DEVICE
0118 virtual Precision DistanceToOut(Vector3D<Precision> const &pos, Vector3D<Precision> const &dir,
0119 Vector3D<Precision> &normal, bool &convex, Precision step_max = kInfLength) const;
0120
0121
0122
0123
0124
0125 VECCORE_ATT_HOST_DEVICE
0126 virtual Real_v DistanceToOutVec(Vector3D<Real_v> const &pos, Vector3D<Real_v> const &dir,
0127 Real_v const &step_max) const;
0128
0129
0130
0131
0132 template <typename T>
0133 VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE T DistanceToOut(Vector3D<T> const &p, Vector3D<T> const &d,
0134 T const &step_max) const
0135 {
0136 return DistanceToOutVec(p, d, step_max);
0137 }
0138
0139
0140
0141
0142
0143 virtual void DistanceToOut(SOA3D<Precision> const &points, SOA3D<Precision> const &directions,
0144 Precision const *const step_max, Precision *const output) const;
0145
0146
0147
0148
0149
0150
0151
0152
0153 VECCORE_ATT_HOST_DEVICE
0154 virtual Precision SafetyToOut(Vector3D<Precision> const &pos) const = 0;
0155
0156
0157
0158
0159
0160 VECCORE_ATT_HOST_DEVICE
0161 virtual Real_v SafetyToOutVec(Vector3D<Real_v> const &p) const;
0162
0163
0164
0165
0166 template <typename T>
0167 VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE T SafetyToOut(Vector3D<T> const &p) const
0168 {
0169 return SafetyToOutVec(p);
0170 }
0171
0172
0173
0174
0175
0176 virtual void SafetyToOut(SOA3D<Precision> const &points, Precision *const output) const ;
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 VECCORE_ATT_HOST_DEVICE
0189 virtual Precision DistanceToIn(Vector3D<Precision> const &position, Vector3D<Precision> const &direction,
0190 const Precision step_max = kInfLength) const = 0;
0191
0192
0193
0194
0195
0196 VECCORE_ATT_HOST_DEVICE
0197 virtual Real_v DistanceToInVec(Vector3D<Real_v> const &position, Vector3D<Real_v> const &direction,
0198 const Real_v &step_max = Real_v(kInfLength)) const ;
0199
0200
0201
0202
0203
0204 template <typename T>
0205 VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE T DistanceToIn(Vector3D<T> const &p, Vector3D<T> const &d,
0206 T const &step_max) const
0207 {
0208 return DistanceToInVec(p, d, step_max);
0209 }
0210
0211
0212
0213
0214
0215
0216
0217
0218 VECCORE_ATT_HOST_DEVICE
0219 virtual Precision SafetyToIn(Vector3D<Precision> const &pos) const = 0;
0220
0221
0222
0223
0224
0225 VECCORE_ATT_HOST_DEVICE
0226 virtual Real_v SafetyToInVec(Vector3D<Real_v> const &p) const;
0227
0228
0229
0230
0231 template <typename T>
0232 VECGEOM_FORCE_INLINE VECCORE_ATT_HOST_DEVICE T SafetyToIn(Vector3D<T> const &p) const
0233 {
0234 return SafetyToInVec(p);
0235 }
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245 VECCORE_ATT_HOST_DEVICE
0246 virtual bool Normal(Vector3D<Precision> const &pos, Vector3D<Precision> &normal) const ;
0247
0248
0249
0250
0251
0252
0253 virtual Vector3D<Precision> SamplePointOnSurface() const ;
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263 VECCORE_ATT_HOST_DEVICE
0264 virtual void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const ;
0265
0266 VECGEOM_FORCE_INLINE
0267 VECCORE_ATT_HOST_DEVICE
0268 Precision ApproachSolid(Vector3D<Precision> const &point, Vector3D<Precision> const &invDir) const
0269 {
0270 Precision distance = BoxImplementation::IntersectCachedKernel2<Precision, Precision>(
0271 fBBox, point, invDir, invDir.x() < 0, invDir.y() < 0, invDir.z() < 0, 0, kInfLength);
0272 return vecCore::math::Max(distance, Precision(0));
0273 }
0274
0275
0276
0277
0278
0279 VECCORE_ATT_HOST_DEVICE
0280 bool IsConvex() const { return fGlobalConvexity; }
0281
0282
0283
0284
0285 VECCORE_ATT_HOST_DEVICE
0286 bool IsAssembly() const { return fIsAssembly; }
0287
0288
0289
0290
0291
0292 virtual Precision Capacity() const = 0;
0293
0294
0295
0296
0297
0298 Precision EstimateCapacity(int nStat = 100000) const;
0299
0300
0301
0302
0303
0304 virtual Precision SurfaceArea() const = 0;
0305
0306
0307
0308
0309
0310 Precision EstimateSurfaceArea(int nStat = 100000) const;
0311
0312
0313
0314
0315
0316 friend std::ostream &operator<<(std::ostream &os, VUnplacedVolume const &vol);
0317
0318
0319
0320
0321
0322 virtual int MemorySize() const = 0;
0323
0324 #ifdef VECGEOM_CUDA_INTERFACE
0325 virtual size_t DeviceSizeOf() const = 0;
0326
0327
0328
0329
0330
0331 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const = 0;
0332 virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const = 0;
0333
0334 template <typename Derived, typename... ArgsTypes>
0335 DevicePtr<cuda::VUnplacedVolume> CopyToGpuImpl(DevicePtr<cuda::VUnplacedVolume> const in_gpu_ptr,
0336 ArgsTypes... params) const
0337 {
0338 DevicePtr<CudaType_t<Derived>> gpu_ptr(in_gpu_ptr);
0339 gpu_ptr.Construct(params...);
0340 CudaAssertError();
0341
0342
0343
0344 return DevicePtr<cuda::VUnplacedVolume>((void *)gpu_ptr);
0345 }
0346 template <typename Derived>
0347 DevicePtr<cuda::VUnplacedVolume> CopyToGpuImpl() const
0348 {
0349 DevicePtr<CudaType_t<Derived>> gpu_ptr;
0350 gpu_ptr.Allocate();
0351 return this->CopyToGpu(DevicePtr<cuda::VUnplacedVolume>((void *)gpu_ptr));
0352 }
0353
0354 static void CopyBBoxesToGpu(const std::vector<VUnplacedVolume const *> &volumes,
0355 const std::vector<DevicePtr<cuda::VUnplacedVolume>> &gpu_ptrs);
0356
0357 #endif
0358
0359
0360
0361
0362
0363 virtual void Print(std::ostream &os) const = 0;
0364
0365
0366
0367
0368
0369 VECCORE_ATT_HOST_DEVICE
0370 virtual void Print() const = 0;
0371
0372
0373 #ifndef VECCORE_CUDA
0374 virtual SolidMesh *CreateMesh3D(Transformation3D const & , const size_t ) const
0375 {
0376 return nullptr;
0377 };
0378 #endif
0379
0380
0381
0382
0383 VPlacedVolume *PlaceVolume(char const *const label, LogicalVolume const *const volume,
0384 Transformation3D const *const transformation, VPlacedVolume *const placement = NULL) const;
0385
0386 VPlacedVolume *PlaceVolume(LogicalVolume const *const volume, Transformation3D const *const transformation,
0387 VPlacedVolume *const placement = NULL) const;
0388
0389 private:
0390 #ifndef VECCORE_CUDA
0391
0392 virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0393 Transformation3D const *const transformation,
0394 const TranslationCode trans_code, const RotationCode rot_code,
0395 VPlacedVolume *const placement = NULL) const = 0;
0396
0397 #else
0398 VECCORE_ATT_DEVICE
0399 virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
0400 Transformation3D const *const transformation,
0401 const TranslationCode trans_code, const RotationCode rot_code, const int id,
0402 const int copy_no, const int child_id,
0403 VPlacedVolume *const placement = NULL) const = 0;
0404
0405 #endif
0406 };
0407
0408
0409
0410
0411
0412 template <typename Shape_t>
0413 struct Maker {
0414 template <typename... ArgTypes>
0415 static Shape_t *MakeInstance(ArgTypes... args)
0416 {
0417
0418 return new Shape_t(args...);
0419 }
0420 };
0421
0422 std::ostream &operator<<(std::ostream &os, VUnplacedVolume const &vol);
0423
0424 }
0425
0426 }
0427
0428 #endif