Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <cstddef>
7 : #include <optional>
8 : #include <tuple>
9 : #include <utility>
10 :
11 : #include "DataStructures/DataBox/DataBox.hpp"
12 : #include "Evolution/Particles/MonteCarlo/Actions/Labels.hpp"
13 : #include "Parallel/AlgorithmExecution.hpp"
14 : #include "ParallelAlgorithms/Actions/Goto.hpp"
15 : #include "Time/Tags/TimeStepId.hpp"
16 : #include "Time/Time.hpp"
17 : #include "Time/TimeStepId.hpp"
18 : #include "Utilities/TMPL.hpp"
19 :
20 : /// \cond
21 : namespace Parallel {
22 : template <typename Metavariables>
23 : class GlobalCache;
24 : } // namespace Parallel
25 : namespace tuples {
26 : template <typename...>
27 : class TaggedTuple;
28 : } // namespace tuples
29 : /// \endcond
30 :
31 : namespace Particles::MonteCarlo::Actions {
32 : /*!
33 : * \brief Goes to `Labels::BeginMonteCarlo` or `Labels::EndMonteCarlo` depending
34 : * on whether we are at the end of a full time step or at an intermediate step
35 : * of the timestepping algorithm.
36 : *
37 : * GlobalCache: nothing
38 : *
39 : * DataBox:
40 : * - Uses:
41 : * - Tags::Next<::Tags::TimeStepId>
42 : */
43 1 : struct TriggerMonteCarloEvolution {
44 : template <typename DbTagsList, typename... InboxTags, typename Metavariables,
45 : typename ArrayIndex, typename ActionList,
46 : typename ParallelComponent>
47 0 : static Parallel::iterable_action_return_t apply(
48 : db::DataBox<DbTagsList>& box,
49 : const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
50 : const Parallel::GlobalCache<Metavariables>& /*cache*/,
51 : const ArrayIndex& /*array_index*/, ActionList /*meta*/,
52 : const ParallelComponent* const /*meta*/) {
53 : const auto& next_time_id = db::get<::Tags::Next<::Tags::TimeStepId>>(box);
54 : // We only run MC if we are at the beginning of a full time step
55 : const bool trigger_mc = (next_time_id.substep() == 0);
56 : // Note: we jump to the `Label+1` because the label actions don't do
57 : // anything anyway
58 : if (trigger_mc) {
59 : const size_t mc_index =
60 : tmpl::index_of<ActionList,
61 : ::Actions::Label<Labels::BeginMonteCarlo>>::value +
62 : 1;
63 : return {Parallel::AlgorithmExecution::Continue, mc_index};
64 : } else {
65 : const size_t post_mc_index =
66 : tmpl::index_of<ActionList,
67 : ::Actions::Label<Labels::EndMonteCarlo>>::value +
68 : 1;
69 : return {Parallel::AlgorithmExecution::Continue, post_mc_index};
70 : }
71 : }
72 : };
73 : } // namespace Particles::MonteCarlo::Actions
|