File: UnplacedParaboloid.cpp

package info (click to toggle)
vecgeom 1.2.8%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 24,016 kB
  • sloc: cpp: 88,803; ansic: 6,888; python: 1,035; sh: 582; sql: 538; makefile: 23
file content (287 lines) | stat: -rw-r--r-- 10,028 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// This file is part of VecGeom and is distributed under the
// conditions in the file LICENSE.txt in the top directory.
// For the full list of authors see CONTRIBUTORS.txt and `git log`.

/// @file source/UnplacedParaboloid.cpp
/// @author Marilena Bandieramonte (marilena.bandieramonte@cern.ch)

#include "VecGeom/volumes/UnplacedParaboloid.h"
#include "VecGeom/management/VolumeFactory.h"
#include "VecGeom/volumes/SpecializedParaboloid.h"
#include "VecGeom/base/RNG.h"
#include <stdio.h>

namespace vecgeom {
inline namespace VECGEOM_IMPL_NAMESPACE {

VECCORE_ATT_HOST_DEVICE
UnplacedParaboloid::UnplacedParaboloid() : fCubicVolume(0), fSurfaceArea(0)
{
  // default constructor
  fGlobalConvexity = true;
  ComputeBBox();
}

VECCORE_ATT_HOST_DEVICE
UnplacedParaboloid::UnplacedParaboloid(const Precision rlo, const Precision rhi, const Precision dz)
    : fParaboloid(rlo, rhi, dz)
{
  CalcCapacity();
  CalcSurfaceArea();
  fGlobalConvexity = true;
  ComputeBBox();
}

VECCORE_ATT_HOST_DEVICE
void UnplacedParaboloid::CalcCapacity()
{
  fCubicVolume = kPi * fParaboloid.fDz * (fParaboloid.fRlo * fParaboloid.fRlo + fParaboloid.fRhi * fParaboloid.fRhi);
}

VECCORE_ATT_HOST_DEVICE
void UnplacedParaboloid::CalcSurfaceArea()
{

  Precision h1, h2, A1, A2;
  h1 = -fParaboloid.fB + fParaboloid.fDz;
  h2 = -fParaboloid.fB - fParaboloid.fDz;

  // Calculate surface area for the paraboloid full paraboloid
  // cutoff at z = dz (not the cutoff area though).
  A1 = fParaboloid.fRhi2 + 4 * h1 * h1;
  A1 *= (A1 * A1); // Sets A1 = A1^3
  A1 = kPi * fParaboloid.fRhi / 6 / (h1 * h1) * (sqrt(A1) - fParaboloid.fRhi2 * fParaboloid.fRhi);

  // Calculate surface area for the paraboloid full paraboloid
  // cutoff at z = -dz (not the cutoff area though).
  A2 = fParaboloid.fRlo2 + 4 * (h2 * h2);
  A2 *= (A2 * A2); // Sets A2 = A2^3

  if (h2 != 0)
    A2 = kPi * fParaboloid.fRlo / 6 / (h2 * h2) * (Sqrt(A2) - fParaboloid.fRlo2 * fParaboloid.fRlo);
  else
    A2 = 0.;
  fSurfaceArea = (A1 - A2 + (fParaboloid.fRlo2 + fParaboloid.fRhi2) * kPi);
}

VECCORE_ATT_HOST_DEVICE
void UnplacedParaboloid::Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const
{
  aMin.x() = -fParaboloid.fDx;
  aMax.x() = fParaboloid.fDx;
  aMin.y() = -fParaboloid.fDy;
  aMax.y() = fParaboloid.fDy;
  aMin.z() = -fParaboloid.fDz;
  aMax.z() = fParaboloid.fDz;
}

Vector3D<Precision> UnplacedParaboloid::SamplePointOnSurface() const
{
  // G4 implementation
  Precision A   = SurfaceArea();
  Precision z   = RNG::Instance().uniform(0., 1.);
  Precision phi = RNG::Instance().uniform(0., 2 * kPi);
  if (kPi * (fParaboloid.fRlo2 + fParaboloid.fRhi2) / A >= z) {
    Precision rho;
    // points on the cutting circle surface at -dZ
    if (kPi * fParaboloid.fRlo2 / A > z) {
      rho = fParaboloid.fRlo * Sqrt(RNG::Instance().uniform(0., 1.));
      return Vector3D<Precision>(rho * cos(phi), rho * sin(phi), -fParaboloid.fDz);
    }
    // points on the cutting circle surface at dZ
    else {
      rho = fParaboloid.fRhi * Sqrt(RNG::Instance().uniform(0., 1.));
      return Vector3D<Precision>(rho * cos(phi), rho * sin(phi), fParaboloid.fDz);
    }
  }
  // points on the paraboloid surface
  else {
    z = RNG::Instance().uniform(0., 1.) * 2 * fParaboloid.fDz - fParaboloid.fDz;
    return Vector3D<Precision>(Sqrt(z * fParaboloid.fInvA - fParaboloid.fB * fParaboloid.fInvA) * cos(phi),
                               Sqrt(z * fParaboloid.fInvA - fParaboloid.fB * fParaboloid.fInvA) * sin(phi), z);
  }
}

std::string UnplacedParaboloid::GetEntityType() const
{
  return "Paraboloid\n";
}

/*
VECCORE_ATT_HOST_DEVICE
void UnplacedParaboloid::GetParametersList(int, Precision *aArray) const
{
  aArray[0] = GetRadius();
}
*/

VECCORE_ATT_HOST_DEVICE
UnplacedParaboloid *UnplacedParaboloid::Clone() const
{
  return new UnplacedParaboloid(fParaboloid.fRlo, fParaboloid.fRhi, fParaboloid.fDz);
}

// VECCORE_ATT_HOST_DEVICE
std::ostream &UnplacedParaboloid::StreamInfo(std::ostream &os) const
// Definition taken from UParaboloid
{
  int oldprc = os.precision(16);
  os << "-----------------------------------------------------------\n"
     << "     *** Dump for solid - " << GetEntityType() << " ***\n"
     << "     ===================================================\n"
     << " Solid type: Paraboloid\n"
     << " Parameters: \n"
     << "     Paraboloid Radii Rlo=" << fParaboloid.fRlo << "mm, Rhi" << fParaboloid.fRhi << "mm \n"
     << "     Half-length Dz = " << fParaboloid.fDz << "mm\n";
  os << "-----------------------------------------------------------\n";
  os.precision(oldprc);
  return os;
}

VECCORE_ATT_HOST_DEVICE
void UnplacedParaboloid::Print() const
{
  // printf("UnplacedParaboloid {%.2f}", GetRadius());
  printf("UnplacedParaboloid {%.2f, %.2f, %.2f, %.2f, %.2f}", GetRlo(), GetRhi(), GetDz(), GetA(), GetB());
}

void UnplacedParaboloid::Print(std::ostream &os) const
{
  // os << "UnplacedParaboloid {" << GetRadius() << "}";
  os << "UnplacedParaboloid {" << GetRlo() << ", " << GetRhi() << ", " << GetDz() << ", " << GetA() << ", " << GetB();
}

#ifndef VECCORE_CUDA
SolidMesh *UnplacedParaboloid::CreateMesh3D(Transformation3D const &trans, size_t nSegments) const
{
  typedef Vector3D<Precision> Vec_t;
  SolidMesh *sm = new SolidMesh();

  size_t nMeshVertices = (nSegments + 1) * (nSegments + 1);
  Vec_t *vertices      = new Vec_t[nMeshVertices];

  sm->ResetMesh(nMeshVertices, nSegments * nSegments + 2);

  Precision phi_step = 2 * M_PI / nSegments;
  Precision phi      = 0.;

  Precision z_step = 2 * GetDz() / nSegments;
  Precision z      = -GetDz();

  size_t idx = 0;
  for (size_t i = 0; i <= nSegments; ++i, z += z_step, phi = 0.) {
    Precision intermediate = std::sqrt(std::abs((z - GetB()) / GetA()));
    for (size_t j = 0; j <= nSegments; ++j, phi += phi_step) {
      vertices[idx++] = Vec_t(intermediate * std::cos(phi), intermediate * std::sin(phi), z);
    }
  }
  sm->SetVertices(vertices, nMeshVertices);
  delete[] vertices;
  sm->TransformVertices(trans);

  for (size_t j = 0, k = 0; j < nSegments; j++, k++) {
    for (size_t i = 0, l = k + nSegments + 1; i < nSegments; i++, k++, l++) {
      sm->AddPolygon(4, {l + 1, l, k, k + 1}, true);
    }
  }

  Utils3D::vector_t<size_t> indices;
  indices.reserve(nSegments);

  if (GetRlo() != 0.) {
    // lower surface
    for (size_t i = nSegments; i > 0; i--) {
      indices.push_back(i - 1);
    }
    sm->AddPolygon(nSegments, indices, true);
  }

  if (GetRhi() != 0.) {
    // upper surface
    indices.clear();
    for (size_t i = 0, k = (nSegments + 1) * (nSegments); i < nSegments; i++, k++) {
      indices.push_back(k);
    }
    sm->AddPolygon(nSegments, indices, true);
  }

  return sm;
}
#endif

#ifndef VECCORE_CUDA
template <TranslationCode trans_code, RotationCode rot_code>
VPlacedVolume *UnplacedParaboloid::Create(LogicalVolume const *const logical_volume,
                                          Transformation3D const *const transformation, VPlacedVolume *const placement)
{
  if (placement) {
    new (placement) SpecializedParaboloid<trans_code, rot_code>(logical_volume, transformation);
    return placement;
  }
  return new SpecializedParaboloid<trans_code, rot_code>(logical_volume, transformation);
}

VPlacedVolume *UnplacedParaboloid::SpecializedVolume(LogicalVolume const *const volume,
                                                     Transformation3D const *const transformation,
                                                     const TranslationCode trans_code, const RotationCode rot_code,
                                                     VPlacedVolume *const placement) const
{
  return VolumeFactory::CreateByTransformation<UnplacedParaboloid>(volume, transformation, trans_code, rot_code,
                                                                   placement);
}
#else

template <TranslationCode trans_code, RotationCode rot_code>
VECCORE_ATT_DEVICE
VPlacedVolume *UnplacedParaboloid::Create(LogicalVolume const *const logical_volume,
                                          Transformation3D const *const transformation, const int id, const int copy_no,
                                          const int child_id, VPlacedVolume *const placement)
{
  if (placement) {
    new (placement) SpecializedParaboloid<trans_code, rot_code>(logical_volume, transformation, id, copy_no, child_id);
    return placement;
  }
  return new SpecializedParaboloid<trans_code, rot_code>(logical_volume, transformation, id, copy_no, child_id);
}

VECCORE_ATT_DEVICE
VPlacedVolume *UnplacedParaboloid::SpecializedVolume(LogicalVolume const *const volume,
                                                     Transformation3D const *const transformation,
                                                     const TranslationCode trans_code, const RotationCode rot_code,
                                                     const int id, const int copy_no, const int child_id,
                                                     VPlacedVolume *const placement) const
{
  return VolumeFactory::CreateByTransformation<UnplacedParaboloid>(volume, transformation, trans_code, rot_code, id,
                                                                   copy_no, child_id, placement);
}

#endif

#ifdef VECGEOM_CUDA_INTERFACE

DevicePtr<cuda::VUnplacedVolume> UnplacedParaboloid::CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const in_gpu_ptr) const
{
  return CopyToGpuImpl<UnplacedParaboloid>(in_gpu_ptr, GetRlo(), GetRhi(), GetDz());
}

DevicePtr<cuda::VUnplacedVolume> UnplacedParaboloid::CopyToGpu() const
{
  return CopyToGpuImpl<UnplacedParaboloid>();
}

#endif // VECGEOM_CUDA_INTERFACE

} // namespace VECGEOM_IMPL_NAMESPACE

#ifdef VECCORE_CUDA

namespace cxx {

template size_t DevicePtr<cuda::UnplacedParaboloid>::SizeOf();
template void DevicePtr<cuda::UnplacedParaboloid>::Construct(const Precision rlo, const Precision rhi,
                                                             const Precision dz) const;

} // namespace cxx

#endif
} // namespace vecgeom