forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlobalTestBase.hh
210 lines (185 loc) · 7.36 KB
/
GlobalTestBase.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
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
//----------------------------------*-C++-*----------------------------------//
// Copyright 2022-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/GlobalTestBase.hh
//---------------------------------------------------------------------------//
#pragma once
#include <iosfwd>
#include <memory>
#include <string>
#include "corecel/Assert.hh"
#include "celeritas/geo/GeoFwd.hh"
#include "celeritas/random/RngParamsFwd.hh"
#include "Test.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
class ActionRegistry;
class AtomicRelaxationParams;
class CutoffParams;
class ExplicitCoreActionInterface;
class GeoMaterialParams;
class MaterialParams;
class ParticleParams;
class PhysicsParams;
class SimParams;
class TrackInitParams;
class CoreParams;
class OutputRegistry;
class CerenkovParams;
class OpticalPropertyParams;
class ScintillationParams;
namespace test
{
//---------------------------------------------------------------------------//
/*!
* Lazily construct core parameters, individually or together.
*
* \note Inherit from this class (or \c GlobalGeoTestBase) using \c
* virtual \c public so that tests can create mixins (see e.g. \c
* SimpleStepperTest).
*/
class GlobalTestBase : public Test
{
public:
//!@{
//! \name Type aliases
template<class T>
using SP = std::shared_ptr<T>;
using SPConstGeo = SP<GeoParams const>;
using SPConstMaterial = SP<MaterialParams const>;
using SPConstGeoMaterial = SP<GeoMaterialParams const>;
using SPConstParticle = SP<ParticleParams const>;
using SPConstCutoff = SP<CutoffParams const>;
using SPConstPhysics = SP<PhysicsParams const>;
using SPConstAction = SP<ExplicitCoreActionInterface const>;
using SPConstRng = SP<RngParams const>;
using SPConstSim = SP<SimParams const>;
using SPConstTrackInit = SP<TrackInitParams const>;
using SPConstCore = SP<CoreParams const>;
using SPActionRegistry = SP<ActionRegistry>;
using SPOutputRegistry = SP<OutputRegistry>;
using SPConstCerenkov = SP<CerenkovParams const>;
using SPConstProperties = SP<OpticalPropertyParams const>;
using SPConstScintillation = SP<ScintillationParams const>;
//!@}
public:
// Create output manager on construction
GlobalTestBase();
// Print output on failure if available
virtual ~GlobalTestBase();
//// ACCESSORS ////
//!@{
//! Access lazily constructed objects.
inline SPConstGeo const& geometry();
inline SPConstMaterial const& material();
inline SPConstGeoMaterial const& geomaterial();
inline SPConstParticle const& particle();
inline SPConstCutoff const& cutoff();
inline SPConstPhysics const& physics();
inline SPConstAction const& along_step();
inline SPConstRng const& rng();
inline SPConstSim const& sim();
inline SPConstTrackInit const& init();
inline SPActionRegistry const& action_reg();
inline SPConstCore const& core();
inline SPConstCerenkov const& cerenkov();
inline SPConstProperties const& properties();
inline SPConstScintillation const& scintillation();
inline SPConstGeo const& geometry() const;
inline SPConstMaterial const& material() const;
inline SPConstGeoMaterial const& geomaterial() const;
inline SPConstParticle const& particle() const;
inline SPConstCutoff const& cutoff() const;
inline SPConstPhysics const& physics() const;
inline SPConstAction const& along_step() const;
inline SPConstRng const& rng() const;
inline SPConstSim const& sim() const;
inline SPConstTrackInit const& init() const;
inline SPActionRegistry const& action_reg() const;
inline SPConstCore const& core() const;
inline SPConstCerenkov const& cerenkov() const;
inline SPConstProperties const& properties() const;
inline SPConstScintillation const& scintillation() const;
//!@}
//// OUTPUT ////
//! Access output manager
SPOutputRegistry const& output_reg() const { return output_reg_; }
//! Write output to a debug text file
void write_output();
//! Write output to a stream
void write_output(std::ostream& os) const;
protected:
[[nodiscard]] virtual SPConstGeo build_geometry() = 0;
[[nodiscard]] virtual SPConstMaterial build_material() = 0;
[[nodiscard]] virtual SPConstGeoMaterial build_geomaterial() = 0;
[[nodiscard]] virtual SPConstParticle build_particle() = 0;
[[nodiscard]] virtual SPConstCutoff build_cutoff() = 0;
[[nodiscard]] virtual SPConstPhysics build_physics() = 0;
[[nodiscard]] virtual SPConstSim build_sim() = 0;
[[nodiscard]] virtual SPConstTrackInit build_init() = 0;
[[nodiscard]] virtual SPConstAction build_along_step() = 0;
[[nodiscard]] virtual SPConstCerenkov build_cerenkov() = 0;
[[nodiscard]] virtual SPConstProperties build_properties() = 0;
[[nodiscard]] virtual SPConstScintillation build_scintillation() = 0;
private:
SPConstRng build_rng() const;
SPActionRegistry build_action_reg() const;
SPConstCore build_core();
private:
SPConstGeo geometry_;
SPConstMaterial material_;
SPConstGeoMaterial geomaterial_;
SPConstParticle particle_;
SPConstCutoff cutoff_;
SPConstPhysics physics_;
SPActionRegistry action_reg_;
SPConstAction along_step_;
SPConstRng rng_;
SPConstSim sim_;
SPConstTrackInit init_;
SPConstCore core_;
SPOutputRegistry output_reg_;
SPConstCerenkov cerenkov_;
SPConstProperties properties_;
SPConstScintillation scintillation_;
};
//---------------------------------------------------------------------------//
// INLINE DEFINITIONS
//---------------------------------------------------------------------------//
#define DEF_GTB_ACCESSORS(CLS, NAME) \
auto GlobalTestBase::NAME() -> CLS const& \
{ \
if (!this->NAME##_) \
{ \
this->NAME##_ = this->build_##NAME(); \
CELER_ASSERT(this->NAME##_); \
} \
return this->NAME##_; \
} \
auto GlobalTestBase::NAME() const -> CLS const& \
{ \
CELER_ASSERT(this->NAME##_); \
return this->NAME##_; \
}
DEF_GTB_ACCESSORS(SPConstGeo, geometry)
DEF_GTB_ACCESSORS(SPConstMaterial, material)
DEF_GTB_ACCESSORS(SPConstGeoMaterial, geomaterial)
DEF_GTB_ACCESSORS(SPConstParticle, particle)
DEF_GTB_ACCESSORS(SPConstCutoff, cutoff)
DEF_GTB_ACCESSORS(SPConstPhysics, physics)
DEF_GTB_ACCESSORS(SPConstAction, along_step)
DEF_GTB_ACCESSORS(SPConstRng, rng)
DEF_GTB_ACCESSORS(SPConstSim, sim)
DEF_GTB_ACCESSORS(SPConstTrackInit, init)
DEF_GTB_ACCESSORS(SPActionRegistry, action_reg)
DEF_GTB_ACCESSORS(SPConstCore, core)
DEF_GTB_ACCESSORS(SPConstCerenkov, cerenkov)
DEF_GTB_ACCESSORS(SPConstProperties, properties)
DEF_GTB_ACCESSORS(SPConstScintillation, scintillation)
#undef DEF_GTB_ACCESSORS
//---------------------------------------------------------------------------//
} // namespace test
} // namespace celeritas