Evolution.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <utility>
8 
13 #include "Domain/Mesh.hpp"
14 #include "Domain/Tags.hpp"
18 #include "Time/Slab.hpp"
20 #include "Time/Tags.hpp"
21 #include "Time/Time.hpp"
22 #include "Time/TimeId.hpp"
23 #include "Utilities/Requires.hpp"
24 #include "Utilities/TMPL.hpp"
25 
26 /// \cond
27 namespace Frame {
28 struct Inertial;
29 } // namespace Frame
30 /// \endcond
31 
32 namespace Initialization {
33 
34 /// \brief Initialize items related to time-evolution of the system
35 ///
36 /// DataBox changes:
37 /// - Adds:
38 /// * Tags::TimeId
39 /// * `Tags::Next<Tags::TimeId>`
40 /// * Tags::TimeStep
41 /// * `db::add_tag_prefix<Tags::dt, variables_tag>`
42 /// * `Tags::HistoryEvolvedVariables<variables_tag, dt_variables_tag>`
43 /// * Tags::Time
44 /// * Tags::ComputeDeriv (for non-conservative systems)
45 /// * Tags::ComputeDiv (for conservative systems)
46 /// - Removes: nothing
47 /// - Modifies: nothing
48 ///
49 /// \note HistoryEvolvedVariables is allocated, but needs to be initialized
50 template <typename System>
51 struct Evolution {
52  static constexpr size_t dim = System::volume_dim;
53  using variables_tag = typename System::variables_tag;
54  using dt_variables_tag = db::add_tag_prefix<Tags::dt, variables_tag>;
55 
56  using simple_tags = db::AddSimpleTags<
59 
60  template <typename LocalSystem, bool IsInFluxConservativeForm =
61  LocalSystem::is_in_flux_conservative_form>
62  struct ComputeTags {
63  using type = db::AddComputeTags<
64  Tags::Time,
65  Tags::DerivCompute<variables_tag,
68  typename System::gradients_tags>>;
69  };
70 
71  template <typename LocalSystem>
72  struct ComputeTags<LocalSystem, true> {
73  using type = db::AddComputeTags<
74  Tags::Time,
76  tmpl::size_t<dim>, Frame::Inertial>,
79  };
80 
81  using compute_tags = typename ComputeTags<System>::type;
82 
83  // Global time stepping
84  template <typename Metavariables,
86  static TimeDelta get_initial_time_step(
87  const Time& initial_time, const double initial_dt_value,
88  const Parallel::ConstGlobalCache<Metavariables>& /*cache*/) noexcept {
89  return (initial_dt_value > 0.0 ? 1 : -1) * initial_time.slab().duration();
90  }
91 
92  // Local time stepping
93  template <typename Metavariables,
95  static TimeDelta get_initial_time_step(
96  const Time& initial_time, const double initial_dt_value,
97  const Parallel::ConstGlobalCache<Metavariables>& cache) noexcept {
98  const auto& step_controller =
99  Parallel::get<OptionTags::StepController>(cache);
100  return step_controller.choose_step(initial_time, initial_dt_value);
101  }
102  template <typename TagsList, typename Metavariables>
103  static auto initialize(db::DataBox<TagsList>&& box,
105  const double initial_time_value,
106  const double initial_dt_value,
107  const double initial_slab_size) noexcept {
108  using DtVars = typename dt_variables_tag::type;
109 
110  const bool time_runs_forward = initial_dt_value > 0.0;
111  const Slab initial_slab =
112  time_runs_forward
113  ? Slab::with_duration_from_start(initial_time_value,
114  initial_slab_size)
115  : Slab::with_duration_to_end(initial_time_value, initial_slab_size);
116  const Time initial_time =
117  time_runs_forward ? initial_slab.start() : initial_slab.end();
118  const TimeDelta initial_dt =
119  get_initial_time_step(initial_time, initial_dt_value, cache);
120 
121  const size_t num_grid_points =
122  db::get<Tags::Mesh<dim>>(box).number_of_grid_points();
123 
124  // Will be overwritten before use
125  DtVars dt_vars{num_grid_points};
126  typename Tags::HistoryEvolvedVariables<variables_tag,
127  dt_variables_tag>::type history;
128 
129  // The slab number is increased in the self-start phase each
130  // time one order of accuracy is obtained, and the evolution
131  // proper starts with slab 0.
132  const auto& time_stepper = Parallel::get<OptionTags::TimeStepper>(cache);
133 
134  const TimeId time_id(
135  time_runs_forward,
136  -static_cast<int64_t>(time_stepper.number_of_past_steps()),
137  initial_time);
138 
139  return db::create_from<db::RemoveTags<>, simple_tags, compute_tags>(
140  std::move(box), TimeId{}, time_id, initial_dt, std::move(dt_vars),
141  std::move(history));
142  }
143 };
144 
145 } // namespace Initialization
Prefix< DataBox_detail::dispatch_add_tag_prefix_impl< Prefix, Tag, Args... >, Args... > add_tag_prefix
Wrap Tag in Prefix<_, Args...>, also wrapping variables tags if Tag is a Tags::Variables.
Definition: DataBoxTag.hpp:533
Tag for step size.
Definition: Tags.hpp:45
Items for initializing the DataBoxes of parallel components.
Definition: ConservativeSystem.hpp:21
static Slab with_duration_to_end(double end, double duration) noexcept
Construct a slab with a given end time and duration. The actual duration may differ by roundoff from ...
Definition: Slab.hpp:49
The time in a simulation. Times can be safely compared for exact equality as long as they do not belo...
Definition: Time.hpp:31
Initialize items related to time-evolution of the system.
Definition: Evolution.hpp:51
Defines base class StepController.
A unique identifier for the temporal state of an integrated system.
Definition: TimeId.hpp:25
static Slab with_duration_from_start(double start, double duration) noexcept
Construct a slab with a given start time and duration. The actual duration may differ by roundoff fro...
Definition: Slab.hpp:43
Define prefixes for DataBox tags.
A chunk of time. Every element must reach slab boundaries exactly, no matter how it actually takes ti...
Definition: Slab.hpp:29
Tag for compute item for current Time (from TimeId)
Definition: Tags.hpp:53
Defines class TimeId.
Defines the type alias Requires.
Defines Time and TimeDelta.
Computes the inverse Jacobian of the map held by MapTag at the coordinates held by SourceCoordsTag...
Definition: Tags.hpp:125
Prefix for TimeStepper history.
Definition: Tags.hpp:75
Defines classes and functions used for manipulating DataBox&#39;s.
Definition: Evolution.hpp:62
tmpl::flatten< tmpl::list< Tags... > > AddSimpleTags
List of Tags to add to the DataBox.
Definition: DataBox.hpp:1227
The logical coordinates in the Element.
Definition: LogicalCoordinates.hpp:64
Represents an interval of time within a single slab.
Definition: Time.hpp:108
Prefix indicating a flux.
Definition: Prefixes.hpp:38
Defines functions computing partial derivatives.
Defines class Slab.
Indicates the Frame that a TensorIndexType is in.
Definition: IndexType.hpp:36
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Defines class Variables.
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Defines the class template Mesh.
Compute the spatial derivatives of tags in a Variables.
Definition: PartialDerivatives.hpp:150
Wraps the template metaprogramming library used (brigand)
Prefix indicating the value a quantity will take on the next iteration of the algorithm.
Definition: Prefixes.hpp:98
Defines tags related to domain quantities.
typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters Requires
Express requirements on the template parameters of a function or class, replaces std::enable_if_t ...
Definition: Requires.hpp:67
Definition: IndexType.hpp:44
Definition: SolvePoissonProblem.hpp:38
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Defines class template ConstGlobalCache.
Compute the divergence of a Variables.
Definition: Divergence.hpp:80
Tag for TimeId for the algorithm state.
Definition: Tags.hpp:35
Defines tags related to Time quantities.
Defines functions and tags for taking a divergence.
tmpl::flatten< tmpl::list< Tags... > > AddComputeTags
List of Compute Item Tags to add to the DataBox.
Definition: DataBox.hpp:1234