InitializeCharacteristicEvolutionTime.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <tuple>
8 #include <utility>
9 
11 #include "DataStructures/VariablesTag.hpp"
12 #include "Evolution/Systems/Cce/OptionTags.hpp"
13 #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
14 #include "Time/Tags.hpp"
15 #include "Time/TimeSteppers/TimeStepper.hpp"
16 #include "Utilities/Rational.hpp"
17 #include "Utilities/Requires.hpp"
18 #include "Utilities/TMPL.hpp"
19 #include "Utilities/TaggedTuple.hpp"
20 
21 namespace Cce {
22 namespace Actions {
23 
24 /*!
25  * \ingroup ActionsGroup
26  * \brief Initializes the contents of the `CharacteristicEvolution` component
27  * for performing the time evolution of the system, which is the singleton that
28  * handles the main evolution system for CCE computations.
29  *
30  * \details Sets up the \ref DataBoxGroup to be ready to perform the
31  * time-stepping associated with the CCE system.
32  *
33  * \ref DataBoxGroup changes:
34  * - Modifies: nothing
35  * - Adds:
36  * - `Tags::TimeStepId`
37  * - `Tags::Next<Tags::TimeStepId>`
38  * - `Tags::TimeStep`
39  * - `Tags::Time`
40  * -
41  * ```
42  * Tags::HistoryEvolvedVariables<
43  * metavariables::evolved_coordinates_variables_tag,
44  * db::add_tag_prefix<Tags::dt,
45  * metavariables::evolved_coordinates_variables_tag>>
46  * ```
47  * -
48  * ```
49  * Tags::HistoryEvolvedVariables<
50  * ::Tags::Variables<metavariables::evolved_swsh_tag>,
51  * ::Tags::Variables<metavariables::evolved_swsh_dt_tag>>
52  * ```
53  * - Removes: nothing
54  *
55  * \note This action relies on the `SetupDataBox` aggregated initialization
56  * mechanism, so `Actions::SetupDataBox` must be present in the `Initialization`
57  * phase action list prior to this action.
58  */
59 template <typename EvolvedCoordinatesVariablesTag, typename EvolvedSwshTag>
61  using initialization_tags = tmpl::list<InitializationTags::TargetStepSize>;
62  using const_global_cache_tags =
63  tmpl::list<::Tags::TimeStepper<TimeStepper>>;
64 
67  using simple_tags = tmpl::list<
72  using compute_tags = tmpl::list<::Tags::SubstepTimeCompute>;
73 
74  template <typename DbTags, typename... InboxTags, typename Metavariables,
75  typename ArrayIndex, typename ActionList,
76  typename ParallelComponent>
77  static auto apply(db::DataBox<DbTags>& box,
78  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
79  const Parallel::GlobalCache<Metavariables>& /*cache*/,
80  const ArrayIndex& /*array_index*/,
81  const ActionList /*meta*/,
82  const ParallelComponent* const /*meta*/) noexcept {
83  const double initial_time_value = db::get<Tags::StartTime>(box);
84  const double step_size = db::get<InitializationTags::TargetStepSize>(box);
85 
86  const Slab single_step_slab{initial_time_value,
87  initial_time_value + step_size};
88  const Time initial_time = single_step_slab.start();
89  const TimeDelta fixed_time_step =
90  TimeDelta{single_step_slab, Rational{1, 1}};
91  TimeStepId initial_time_id{true, 0, initial_time};
92  const auto& time_stepper = db::get<::Tags::TimeStepper<TimeStepper>>(box);
93  TimeStepId second_time_id =
94  time_stepper.next_time_id(initial_time_id, fixed_time_step);
95 
96  const size_t starting_order =
97  time_stepper.number_of_past_steps() == 0 ? time_stepper.order() : 1;
98 
99  typename ::Tags::HistoryEvolvedVariables<EvolvedCoordinatesVariablesTag>::
100  type coordinate_history(starting_order);
101 
102  typename ::Tags::HistoryEvolvedVariables<evolved_swsh_variables_tag>::type
103  swsh_history(starting_order);
104  Initialization::mutate_assign<simple_tags>(
105  make_not_null(&box),
106  std::move(initial_time_id), // NOLINT
107  std::move(second_time_id), // NOLINT
108  fixed_time_step, fixed_time_step, initial_time_value,
109  std::move(coordinate_history), std::move(swsh_history));
110  return std::make_tuple(std::move(box));
111  }
112 };
113 
114 } // namespace Actions
115 } // namespace Cce
utility
Slab
Definition: Slab.hpp:27
Tags::TimeStepId
Tag for TimeStepId for the algorithm state.
Definition: Tags.hpp:33
Parallel::GlobalCache
Definition: ElementReceiveInterpPoints.hpp:15
Cce::Actions::InitializeCharacteristicEvolutionTime
Initializes the contents of the CharacteristicEvolution component for performing the time evolution o...
Definition: InitializeCharacteristicEvolutionTime.hpp:60
Tags::TimeStep
Tag for step size.
Definition: Tags.hpp:42
Tags::Variables
Definition: VariablesTag.hpp:21
tuple
Tags::Next
Prefix indicating the value a quantity will take on the next iteration of the algorithm.
Definition: Prefixes.hpp:118
DataBox.hpp
cstddef
TimeDelta
Definition: Time.hpp:88
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
Tags::Time
Tag for the current time as a double.
Definition: Tags.hpp:73
TimeStepId
Definition: TimeStepId.hpp:25
Cce
The set of utilities for performing Cauchy characteristic evolution and Cauchy characteristic matchin...
Definition: CharacteristicExtractFwd.hpp:6
Time
Definition: Time.hpp:29
Requires.hpp
make_not_null
gsl::not_null< T * > make_not_null(T *ptr) noexcept
Construct a not_null from a pointer. Often this will be done as an implicit conversion,...
Definition: Gsl.hpp:880
Tags::HistoryEvolvedVariables
Definition: Tags.hpp:85
TMPL.hpp
Rational
Definition: Rational.hpp:27