forked from celeritas-project/celeritas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActionSequence.hh
103 lines (85 loc) · 3.31 KB
/
ActionSequence.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
//----------------------------------*-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/global/detail/ActionSequence.hh
//---------------------------------------------------------------------------//
#pragma once
#include <memory>
#include <type_traits>
#include <vector>
#include "corecel/Types.hh"
#include "ParamsTraits.hh"
#include "../ActionInterface.hh"
#include "../CoreTrackDataFwd.hh"
namespace celeritas
{
//---------------------------------------------------------------------------//
class ActionRegistry;
class CoreParams;
namespace detail
{
//---------------------------------------------------------------------------//
/*!
* Sequence of explicit actions to invoke as part of a single step.
*
* TODO accessors here are used by diagnostic output from celer-sim etc.;
* perhaps make this public or add a diagnostic output for it?
*/
template<class Params>
class ActionSequence
{
public:
//!@{
//! \name Type aliases
template<MemSpace M>
using State = typename ParamsTraits<Params>::template State<M>;
using SpecializedExplicitAction =
typename ParamsTraits<Params>::ExplicitAction;
using SPBegin = std::shared_ptr<BeginRunActionInterface>;
using SPConstSpecializedExplicit
= std::shared_ptr<SpecializedExplicitAction const>;
using VecBeginAction = std::vector<SPBegin>;
using VecSpecializedExplicitAction
= std::vector<SPConstSpecializedExplicit>;
using VecDouble = std::vector<double>;
//!@}
// Verify that we have a valid explicit action type for the given Params
static_assert(
std::is_base_of_v<ExplicitActionInterface, SpecializedExplicitAction>,
"ParamTraits<Params> explicit action must be derived from "
"ExplicitActionInterface");
//! Construction/execution options
struct Options
{
bool sync{false}; //!< Call DeviceSynchronize and add timer
};
public:
// Construct from an action registry and sequence options
ActionSequence(ActionRegistry const&, Options options);
//// INVOCATION ////
// Launch all actions with the given memory space.
template<MemSpace M>
void begin_run(Params const& params, State<M>& state);
// Launch all actions with the given memory space.
template<MemSpace M>
void execute(Params const&, State<M>& state);
//// ACCESSORS ////
//! Whether synchronization is taking place
bool sync() const { return options_.sync; }
//! Get the set of beginning-of-run actions
VecBeginAction const& begin_run_actions() const { return begin_run_; }
//! Get the ordered vector of actions in the sequence
VecSpecializedExplicitAction const& actions() const { return actions_; }
//! Get the corresponding accumulated time, if 'sync' or host called
VecDouble const& accum_time() const { return accum_time_; }
private:
Options options_;
VecBeginAction begin_run_;
VecSpecializedExplicitAction actions_;
VecDouble accum_time_;
};
//---------------------------------------------------------------------------//
} // namespace detail
} // namespace celeritas