File: AssemblyTest.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 (142 lines) | stat: -rw-r--r-- 4,715 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
#include "VecGeom/volumes/UnplacedAssembly.h"
#include "VecGeom/volumes/PlacedAssembly.h"
#include "VecGeom/navigation/NavigationState.h"
#include "VecGeom/volumes/Box.h"
#include "test/unit_tests/ApproxEqual.h"

// make sure that assert are included even in Release mode
#ifdef NDEBUG
#undef NDEBUG
#endif
#include <cassert>

using namespace vecgeom;

int main()
{

  // make a simple assembly of 2 boxes
  UnplacedBox *b    = new UnplacedBox(10., 10., 10.);
  LogicalVolume *lb = new LogicalVolume("boxlv", b);

  UnplacedAssembly *ass = new UnplacedAssembly();
  assert(ass->GetLogicalVolume() == nullptr);

  // this statement makes lv an assembly
  LogicalVolume *lv = new LogicalVolume("assemblylv", ass);
  assert(ass->GetLogicalVolume() == lv);

  // make simple assembly out of 2 placed boxes
  ass->AddVolume(lb->Place(new Transformation3D(-20., 0., 0.)));
  ass->AddVolume(lb->Place(new Transformation3D(20., 0., 0.)));
  assert(ass->GetNVolumes() == 2);

  // check that the bounding box is initialized
  assert(ass->GetLowerCorner().x() > -kInfLength);

  VPlacedVolume *const pv = lv->Place();

  // check the assembly property
  assert(pv->GetUnplacedVolume()->IsAssembly());
  assert(ass->IsAssembly());
  assert(!b->IsAssembly());

  GeoManager::Instance().SetWorld(pv);
  GeoManager::Instance().CloseGeometry();

  // verify correct conversion of Unplaced to Placed type
  PlacedAssembly const *pa = dynamic_cast<PlacedAssembly const *>(pv);
  assert(pa != nullptr);

  // some checks on Contains, Safety and DistanceToIn
  {
    Vector3D<Precision> p(0., 0., 0.);
    Vector3D<Precision> p2(20., 0., 0.);
    Vector3D<Precision> lp(0., 0., 0.);
    NavigationState *state = NavigationState::MakeInstance(10);
    // State must point to assembly parent (none in this case)
    state->Clear();
    std::cerr << pa->Contains(p, lp, *state) << "\n";
    state->Clear();
    assert(!pa->Contains(p, lp, *state));
    state->Clear();
    std::cerr << pa->Contains(p2, lp, *state) << "\n";
    state->Clear();
    assert(pa->Contains(p2, lp, *state));
    state->Clear();
    std::cerr << pa->Contains(p) << "\n";
    state->Clear();
    assert(!pa->Contains(p));
    state->Clear();
    std::cerr << pa->Contains(p2) << "\n";
    state->Clear();
    assert(pa->Contains(p2));

    assert(pa->SafetyToIn(Vector3D<Precision>(-10, 0, 0)) == 0.);
    assert(pa->SafetyToIn(Vector3D<Precision>(0, 0, 0)) == 10.);

    assert(pa->DistanceToIn(Vector3D<Precision>(-40, 0, 0), Vector3D<Precision>(1., 0, 0)) == 10);
    assert(pa->DistanceToIn(Vector3D<Precision>(0, -40, 0), Vector3D<Precision>(0, 1, 0)) == kInfLength);
    assert(pa->DistanceToIn(Vector3D<Precision>(0, 0, 0), Vector3D<Precision>(1., 0, 0)) == 10);
    assert(pa->DistanceToIn(Vector3D<Precision>(0, 0, 0), Vector3D<Precision>(-1., 0, 0)) == 10);
  }

  if (pv->GetUnplacedVolume()->IsAssembly()) {
    Vector3D<Precision> p(20., 0., 0.);
    Vector3D<Precision> lp(0., 0., 0.);
    NavigationState *state = NavigationState::MakeInstance(10);
    state->Clear();
    static_cast<PlacedAssembly const *>(pv)->Contains(p, lp, *state);
    state->Print();
  }

  // check Capacity and Surface Area
  assert(ass->Capacity() == 2. * b->Capacity());
  assert(ass->SurfaceArea() == 2. * b->SurfaceArea());
  assert(((PlacedAssembly *)pa)->Capacity() == 2. * b->Capacity());
  assert(((PlacedAssembly *)pa)->SurfaceArea() == 2. * b->SurfaceArea());

  // check Extent
  Vector3D<Precision> emin;
  Vector3D<Precision> emax;
  ass->Extent(emin, emax);
  assert(emin.x() <= -30);
  assert(emin.y() <= -10);
  assert(emin.z() <= -10);
  assert(emax.x() >= 30);
  assert(emax.y() >= 10);
  assert(emax.z() >= 10);

  assert(emin == ass->GetLowerCorner());
  assert(emax == ass->GetUpperCorner());

  // test bounding box
  Vector3D<Precision> minExtent, maxExtent;
  Vector3D<Precision> minBBox, maxBBox;
  ass->Extent(minExtent, maxExtent);
  ass->GetBBox(minBBox, maxBBox);
  assert(ApproxEqual<Precision>(minExtent, minBBox));
  assert(ApproxEqual<Precision>(maxExtent, maxBBox));

  // check Normal
  // TBD

  // check some properties of BoxImplementation
  BoxStruct<Precision> bs(kInfLength, kInfLength, kInfLength);
  Vector3D<Precision> p(0., 0., 0.);
  Vector3D<Precision> d(1., 0., 0.);
  Precision dist;
  BoxImplementation::DistanceToIn(bs, p, d, kInfLength, dist);
  assert(dist < kInfLength);
  bool cont;
  BoxImplementation::Contains(bs, p, cont);
  assert(cont);
  std::cerr << "dist " << dist << "\n";

  Vector3D<Precision> corners[2];
  corners[0].Set(-kInfLength, -kInfLength, -kInfLength);
  corners[1].Set(kInfLength, kInfLength, kInfLength);
  assert(BoxImplementation::Intersect(corners, p, d, 0, kInfLength));

  return 0;
}