forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeantGeoData.hh
151 lines (129 loc) · 4.54 KB
/
GeantGeoData.hh
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
//----------------------------------*-C++-*----------------------------------//
// Copyright 2023-2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file celeritas/ext/GeantGeoData.hh
//---------------------------------------------------------------------------//
#pragma once
#include "corecel/Macros.hh"
#include "corecel/Types.hh"
#include "corecel/cont/Array.hh"
#include "corecel/data/Collection.hh"
#include "corecel/data/CollectionBuilder.hh"
#include "corecel/sys/ThreadId.hh"
#include "celeritas/Types.hh"
#include "celeritas/UnitTypes.hh"
#include "detail/GeantGeoNavCollection.hh"
class G4VPhysicalVolume;
namespace celeritas
{
//---------------------------------------------------------------------------//
// PARAMS
//---------------------------------------------------------------------------//
/*!
* Geant4 data is all global.
*/
template<Ownership W, MemSpace M>
struct GeantGeoParamsData
{
G4VPhysicalVolume* world{nullptr};
//! Whether the interface is initialized
explicit CELER_FUNCTION operator bool() const { return world != nullptr; }
//! Assign from another set of data
template<Ownership W2, MemSpace M2>
GeantGeoParamsData& operator=(GeantGeoParamsData<W2, M2>& other)
{
world = other.world;
return *this;
}
};
//---------------------------------------------------------------------------//
// STATE
//---------------------------------------------------------------------------//
/*!
* Geant4 geometry state data.
*/
template<Ownership W, MemSpace M>
struct GeantGeoStateData
{
//// TYPES ////
using real_type = double;
using Real3 = Array<double, 3>;
template<class T>
using Items = celeritas::StateCollection<T, W, MemSpace::host>;
//// DATA ////
// Collections
Items<Real3> pos;
Items<Real3> dir;
Items<real_type> next_step;
Items<real_type> safety_radius;
// Wrapper for G4TouchableHistory and G4Navigator
detail::GeantGeoNavCollection<W, M> nav_state;
//// METHODS ////
//! True if sizes are consistent and states are assigned
explicit CELER_FUNCTION operator bool() const
{
return this->size() > 0 && dir.size() == this->size()
&& next_step.size() == this->size()
&& safety_radius.size() == this->size()
&& nav_state.size() == this->size();
}
//! State size
CELER_FUNCTION TrackSlotId::size_type size() const { return pos.size(); }
//! Assign from another set of data
template<Ownership W2, MemSpace M2>
GeantGeoStateData& operator=(GeantGeoStateData<W2, M2>& other)
{
static_assert(M2 == M && W == Ownership::reference,
"Only supported assignment is from the same memspace to "
"a reference");
CELER_EXPECT(other);
pos = other.pos;
dir = other.dir;
next_step = other.next_step;
safety_radius = other.safety_radius;
nav_state = other.nav_state;
return *this;
}
};
//---------------------------------------------------------------------------//
/*!
* Resize geometry states.
*/
inline void resize(GeantGeoStateData<Ownership::value, MemSpace::host>* data,
HostCRef<GeantGeoParamsData> const& params,
StreamId stream_id,
size_type size)
{
CELER_EXPECT(data);
CELER_EXPECT(size > 0);
resize(&data->pos, size);
resize(&data->dir, size);
resize(&data->next_step, size);
resize(&data->safety_radius, size);
data->nav_state.resize(size, params.world, stream_id);
CELER_ENSURE(data);
}
//! Resize assuming stream zero for serial tests.
inline void resize(GeantGeoStateData<Ownership::value, MemSpace::host>* data,
HostCRef<GeantGeoParamsData> const& params,
size_type size)
{
return resize(data, params, StreamId{0}, size);
}
inline void resize(GeantGeoStateData<Ownership::value, MemSpace::device>*,
HostCRef<GeantGeoParamsData> const&,
StreamId,
size_type)
{
CELER_NOT_IMPLEMENTED("Geant4 GPU");
}
inline void resize(GeantGeoStateData<Ownership::value, MemSpace::device>*,
HostCRef<GeantGeoParamsData> const&,
size_type)
{
CELER_NOT_IMPLEMENTED("Geant4 GPU");
}
//---------------------------------------------------------------------------//
} // namespace celeritas