File: UnplacedScaledShape.h

package info (click to toggle)
vecgeom 1.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 23,928 kB
  • sloc: cpp: 88,717; ansic: 6,894; python: 1,035; sh: 582; sql: 538; makefile: 29
file content (237 lines) | stat: -rw-r--r-- 8,322 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/// @file UnplacedScaledShape.h
/// @author Mihaela Gheata (mihaela.gheata@cern.ch)

#ifndef VECGEOM_VOLUMES_UNPLACEDSCALEDSHAPE_H_
#define VECGEOM_VOLUMES_UNPLACEDSCALEDSHAPE_H_

#include "VecGeom/base/Cuda.h"
#include "VecGeom/base/Global.h"
#include "VecGeom/base/AlignedBase.h"
#include "VecGeom/base/Vector3D.h"
#include "VecGeom/base/Scale3D.h"
#include "ScaledShapeStruct.h"
#include "VecGeom/volumes/UnplacedVolume.h"
#include "VecGeom/volumes/PlacedVolume.h"
#include "VecGeom/volumes/LogicalVolume.h"
#include "VecGeom/volumes/kernel/ScaledShapeImplementation.h"
#include "VecGeom/volumes/UnplacedVolumeImplHelper.h"

namespace vecgeom {

VECGEOM_DEVICE_FORWARD_DECLARE(class UnplacedScaledShape;);
VECGEOM_DEVICE_DECLARE_CONV(class, UnplacedScaledShape);

inline namespace VECGEOM_IMPL_NAMESPACE {

#ifdef GOT_AROUND_TO_SPECIALIZE_SCALED_SHAPE
template <typename Specialized_t>
class SUnplacedScaledShape {
};

return ScaledShape::MakeInstance<BaseShape_t>(scale, Argtypes... args);

template <typename Shape_t>
Scale(Shape_t vol, ... Scale)
{
  return SUnplacedScaleShabe<Shape_t>(scale, vol);
}

UnplacedScaledScale(UnplacedTube, scale)
{
  if (dynamic_cast<...>()) }

template <typename BaseShape_t, Argtypes... Args>
static UnplacedScaledShape *MakeScaledInstance(Scale3D scale, Argtypes... args)
{
  auto svol = BaseShape_t::MakeInstance(args...);
  return Scale(svol, scale);
}
#endif

/**
 * The unplaced scaled shape class.
 */
class UnplacedScaledShape : public SIMDUnplacedVolumeImplHelper<ScaledShapeImplementation>, public AlignedBase {

public:
  ScaledShapeStruct<Precision> fScaled; /* The scaled shape structure */

public:
  /// Dummy ctor
  VECCORE_ATT_HOST_DEVICE
  UnplacedScaledShape() : fScaled()
  {
    fGlobalConvexity = fScaled.fPlaced->GetUnplacedVolume()->IsConvex();
    ComputeBBox();
  }

  /// Constructor based on placed volume
  VECCORE_ATT_HOST_DEVICE
  UnplacedScaledShape(VPlacedVolume const *placed, Precision sx, Precision sy, Precision sz)
      : fScaled(placed, sx, sy, sz)
  {
    fGlobalConvexity = fScaled.fPlaced->GetUnplacedVolume()->IsConvex();
    ComputeBBox();
  }

#if defined(VECCORE_CUDA)
  /// Constructor based on placed volume
  VECCORE_ATT_HOST_DEVICE
  UnplacedScaledShape(VPlacedVolume const *placed, Precision sx, Precision sy, Precision sz, bool globalConvexity)
      : fScaled(placed, sx, sy, sz)
  {
    /* assert(placed->GetTransformation()->IsIdentity());*/
    fGlobalConvexity = globalConvexity;
    /* We must have
         assert(globalConvexity == fPlaced->GetUnplacedVolume()->IsConvex())
       However due to the order we create the geometry on the GPU (i.e. all Unplaced *then* all
       Placed volume, we can not use this information (i.e. 'placed' points to uninitialized memory
       at time this constructor is callled.
    */
  }
#endif

/// Constructor based on unplaced volume
#if !defined(VECCORE_CUDA)
  UnplacedScaledShape(VUnplacedVolume const *shape, Precision sx, Precision sy, Precision sz)
      : fScaled(nullptr, sx, sy, sz)
  {
    // We need to create a placement with identity transformation from the unplaced version
    // Hopefully we don't need to create a logical volume
    LogicalVolume *lvol = new LogicalVolume("", shape);
    fScaled.fPlaced     = lvol->Place();
    fGlobalConvexity    = fScaled.fPlaced->GetUnplacedVolume()->IsConvex();
    ComputeBBox();
  }
#endif

  /// Copy constructor
  //  VECCORE_ATT_HOST_DEVICE
  UnplacedScaledShape(UnplacedScaledShape const &other) : fScaled()
  {
    fScaled.fPlaced  = other.fScaled.fPlaced->GetLogicalVolume()->Place();
    fScaled.fScale   = other.fScaled.fScale;
    fGlobalConvexity = other.fGlobalConvexity;
    ComputeBBox();
  }

  /// Assignment operator
  //  VECCORE_ATT_HOST_DEVICE
  UnplacedScaledShape &operator=(UnplacedScaledShape const &other)
  {
    if (&other != this) {
      fScaled.fPlaced  = other.fScaled.fPlaced->GetLogicalVolume()->Place();
      fScaled.fScale   = other.fScaled.fScale;
      fGlobalConvexity = other.fGlobalConvexity;
    }
    return *this;
  }

  /// Destructor
  VECCORE_ATT_HOST_DEVICE
  virtual ~UnplacedScaledShape()
  {
    // The fPlaced was owned by the class, but now it gets deleted before
    // the destructor by GeoManager. The class will be restructured to use
    // the VUnplaceVolume new navigation interfaces after migration of all
    // shapes to VecCore, so this data member will dissapear.

    // delete fScaled.fPlaced;
  }

  /// Getter for the generic scaled shape structure
  VECCORE_ATT_HOST_DEVICE
  ScaledShapeStruct<Precision> const &GetStruct() const { return fScaled; }

  virtual int MemorySize() const final { return (sizeof(*this) + fScaled.fPlaced->MemorySize()); }

#ifdef VECGEOM_CUDA_INTERFACE
  virtual size_t DeviceSizeOf() const override { return DevicePtr<cuda::UnplacedScaledShape>::SizeOf(); }
  virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu() const override;
  virtual DevicePtr<cuda::VUnplacedVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const gpu_ptr) const override;
#endif

  VECGEOM_FORCE_INLINE
  const VUnplacedVolume *UnscaledShape() const { return fScaled.fPlaced->GetLogicalVolume()->GetUnplacedVolume(); }

  VECGEOM_FORCE_INLINE
  VPlacedVolume const *GetPlaced() const { return fScaled.fPlaced; }

  VECGEOM_FORCE_INLINE
  Scale3D const &GetScale() const { return fScaled.fScale; }

  Precision Volume() const
  {
    Precision capacity             = ((VPlacedVolume *)fScaled.fPlaced)->Capacity();
    const Vector3D<Precision> &scl = fScaled.fScale.Scale();
    capacity *= scl[0] * scl[1] * scl[2];
    return capacity;
  }

  Precision Capacity() const override { return Volume(); }

  // VECGEOM_FORCE_INLINE
  Precision SurfaceArea() const override
  {
    /// Not so easy as for the capacity...
    Precision area = VUnplacedVolume::EstimateSurfaceArea(1000000);
    return area;
  }

  VECCORE_ATT_HOST_DEVICE
  bool Normal(Vector3D<Precision> const &point, Vector3D<Precision> &normal) const override;

  VECCORE_ATT_HOST_DEVICE
  void Extent(Vector3D<Precision> &min, Vector3D<Precision> &max) const override;

  Vector3D<Precision> SamplePointOnSurface() const override;

  virtual std::string GetEntityType() const { return "ScaledShape"; }

  VECCORE_ATT_HOST_DEVICE
  virtual void Print() const final;

  virtual void Print(std::ostream &os) const final;

  template <TranslationCode trans_code, RotationCode rot_code>
  VECCORE_ATT_DEVICE
  static VPlacedVolume *Create(LogicalVolume const *const logical_volume, Transformation3D const *const transformation,
#ifdef VECCORE_CUDA
                               const int id, const int copy_no, const int child_id,
#endif // !VECCORE_CUDA
                               VPlacedVolume *const placement = NULL);

  VECCORE_ATT_DEVICE
  static VPlacedVolume *CreateSpecializedVolume(LogicalVolume const *const volume,
                                                Transformation3D const *const transformation,
                                                const TranslationCode trans_code, const RotationCode rot_code,
#ifdef VECCORE_CUDA
                                                const int id, const int copy_no, const int child_id,
#endif // !VECCORE_CUDA
                                                VPlacedVolume *const placement = NULL);

private:
  VECCORE_ATT_DEVICE
  virtual VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume,
                                           Transformation3D const *const transformation,
                                           const TranslationCode trans_code, const RotationCode rot_code,
#ifdef VECCORE_CUDA
                                           const int id, const int copy_no, const int child_id,
#endif
                                           VPlacedVolume *const placement = NULL) const final
  {
    return CreateSpecializedVolume(volume, transformation, trans_code, rot_code,
#ifdef VECCORE_CUDA
                                   id, copy_no, child_id,
#endif
                                   placement);
  }
  void SetPlaced(VPlacedVolume const *pvol) { fScaled.fPlaced = pvol; }
  void SetScale(Scale3D const &scale) { fScaled.fScale = scale; }

  friend class GeoManager;
};
} // namespace VECGEOM_IMPL_NAMESPACE
} // namespace vecgeom

#endif // VECGEOM_VOLUMES_UNPLACESCALEDSHAPE_H_