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/Initialization/Tags.hpp"
13 #include "Evolution/Systems/Cce/OptionTags.hpp"
14 #include "ParallelAlgorithms/Initialization/MutateAssign.hpp"
15 #include "Time/StepChoosers/ErrorControl.hpp"
16 #include "Time/Tags.hpp"
17 #include "Time/TimeSteppers/TimeStepper.hpp"
18 #include "Utilities/Rational.hpp"
19 #include "Utilities/Requires.hpp"
20 #include "Utilities/TMPL.hpp"
21 #include "Utilities/TaggedTuple.hpp"
22 
23 namespace Cce {
24 namespace Actions {
25 
26 /*!
27  * \ingroup ActionsGroup
28  * \brief Initializes the contents of the `CharacteristicEvolution` component
29  * for performing the time evolution of the system, which is the singleton that
30  * handles the main evolution system for CCE computations.
31  *
32  * \details Sets up the \ref DataBoxGroup to be ready to perform the
33  * time-stepping associated with the CCE system.
34  *
35  * \ref DataBoxGroup changes:
36  * - Modifies: nothing
37  * - Adds:
38  * - `Tags::TimeStepId`
39  * - `Tags::Next<Tags::TimeStepId>`
40  * - `Tags::TimeStep`
41  * - `Tags::Time`
42  * -
43  * ```
44  * Tags::HistoryEvolvedVariables<
45  * metavariables::evolved_coordinates_variables_tag,
46  * db::add_tag_prefix<Tags::dt,
47  * metavariables::evolved_coordinates_variables_tag>>
48  * ```
49  * -
50  * ```
51  * Tags::HistoryEvolvedVariables<
52  * ::Tags::Variables<metavariables::evolved_swsh_tag>,
53  * ::Tags::Variables<metavariables::evolved_swsh_dt_tag>>
54  * ```
55  * - Removes: nothing
56  *
57  * \note This action relies on the `SetupDataBox` aggregated initialization
58  * mechanism, so `Actions::SetupDataBox` must be present in the `Initialization`
59  * phase action list prior to this action.
60  */
61 template <typename EvolvedCoordinatesVariablesTag, typename EvolvedSwshTag,
62  bool local_time_stepping>
64  using initialization_tags_to_keep =
65  tmpl::flatten<tmpl::list<tmpl::conditional_t<
66  local_time_stepping,
67  tmpl::list<
74  tmpl::list<
77 
78  using initialization_tags = tmpl::push_front<
79  initialization_tags_to_keep,
82 
83  using const_global_cache_tags = tmpl::list<>;
84 
87  using simple_tags = tmpl::list<
93  using compute_tags = tmpl::list<::Tags::SubstepTimeCompute>;
94 
95  template <typename DbTags, typename... InboxTags, typename Metavariables,
96  typename ArrayIndex, typename ActionList,
97  typename ParallelComponent>
98  static auto apply(db::DataBox<DbTags>& box,
99  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
100  const Parallel::GlobalCache<Metavariables>& /*cache*/,
101  const ArrayIndex& /*array_index*/,
102  const ActionList /*meta*/,
103  const ParallelComponent* const /*meta*/) noexcept {
104  const double initial_time_value = db::get<Tags::StartTime>(box);
105  const double slab_size =
106  db::get<::Initialization::Tags::InitialSlabSize<local_time_stepping>>(
107  box);
108 
109  const Slab single_step_slab{initial_time_value,
110  initial_time_value + slab_size};
111  const Time initial_time = single_step_slab.start();
112  TimeDelta initial_time_step;
113  if constexpr (local_time_stepping) {
114  const double initial_time_delta =
115  db::get<Initialization::Tags::InitialTimeDelta>(box);
116  initial_time_step =
117  db::get<Tags::CceEvolutionPrefix<::Tags::StepController>>(box)
118  .choose_step(initial_time, initial_time_delta);
119  } else {
120  initial_time_step = TimeDelta{initial_time.slab().duration()};
121  }
122 
123  const auto& time_stepper = db::get<::Tags::TimeStepper<>>(box);
124 
125  const size_t starting_order =
126  time_stepper.number_of_past_steps() == 0 ? time_stepper.order() : 1;
127 
128  typename ::Tags::HistoryEvolvedVariables<EvolvedCoordinatesVariablesTag>::
129  type coordinate_history(starting_order);
130 
131  typename ::Tags::HistoryEvolvedVariables<evolved_swsh_variables_tag>::type
132  swsh_history(starting_order);
133  Initialization::mutate_assign<simple_tags>(
134  make_not_null(&box), TimeStepId{},
135  TimeStepId{true,
136  -static_cast<int64_t>(time_stepper.number_of_past_steps()),
137  initial_time},
138  initial_time_step, initial_time_step, initial_time_value,
139  std::move(coordinate_history), std::move(swsh_history), false);
140  return std::make_tuple(std::move(box));
141  }
142 };
143 
144 } // namespace Actions
145 } // namespace Cce
domain::push_front
CoordinateMap< SourceFrame, TargetFrame, NewMap, Maps... > push_front(CoordinateMap< SourceFrame, TargetFrame, Maps... > old_map, NewMap new_map) noexcept
Creates a CoordinateMap by prepending the new map to the beginning of the old maps.
Tags::NeverUsingTimeSteppingErrorControl
Tag indicating that the ErrorControl step chooser will not be used.
Definition: ErrorControl.hpp:353
Cce::Tags::CceEvolutionPrefix
Tag for duplicating functionality of another tag, but allows creation from options in the Cce::Evolut...
Definition: OptionTags.hpp:250
Cce::OptionTags::CceEvolutionPrefix
A prefix for common tags (e.g. from Time/Tags.hpp) that are specific to CCE, so should be in the Cce:...
Definition: OptionTags.hpp:48
Initialization::Tags::InitialTimeDelta
Definition: Tags.hpp:28
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:63
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
Tags::StepperErrorUpdated
Tag indicating whether the stepper error has been updated on the current step.
Definition: Tags.hpp:129
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::IsUsingTimeSteppingErrorControl
A tag that is true if the ErrorControl step chooser is one of the option-created Events.
Definition: ErrorControl.hpp:307
Initialization::Tags::InitialSlabSize
Definition: Tags.hpp:39
Tags::HistoryEvolvedVariables
Definition: Tags.hpp:85
TMPL.hpp