DgElementArray.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cmath>
7 #include <cstddef>
8 #include <memory>
9 #include <vector>
10 
11 #include "AlgorithmArray.hpp"
13 #include "Domain/Creators/DomainCreator.hpp" // IWYU pragma: keep
14 #include "Domain/ElementId.hpp" // IWYU pragma: keep
15 #include "Domain/ElementIndex.hpp"
16 #include "Domain/InitialElementIds.hpp"
17 #include "ErrorHandling/Error.hpp"
18 #include "IO/Observer/TypeOfObservation.hpp"
20 #include "Parallel/Info.hpp"
21 #include "Parallel/Invoke.hpp"
22 #include "Parallel/ParallelComponentHelpers.hpp"
23 #include "Time/Tags.hpp" // IWYU pragma: keep
24 #include "Utilities/TMPL.hpp"
25 
26 /// \cond
27 namespace Frame {
28 struct Inertial;
29 } // namespace Frame
30 namespace observers {
31 namespace Actions {
32 template <observers::TypeOfObservation TypeOfObservation>
33 struct RegisterWithObservers;
34 } // namespace Actions
35 } // namespace observers
36 /// \endcond
37 
38 template <class Metavariables, class InitializeAction, class ActionList>
40  static constexpr size_t volume_dim = Metavariables::system::volume_dim;
41 
42  using chare_type = Parallel::Algorithms::Array;
44  using action_list = ActionList;
46 
47  using const_global_cache_tag_list =
49 
50  using initial_databox = db::compute_databox_type<
51  typename InitializeAction::template return_tag_list<Metavariables>>;
52 
53  using options = tmpl::flatten<tmpl::list<
56  tmpl::conditional_t<tmpl::list_contains_v<const_global_cache_tag_list,
58  OptionTags::InitialSlabSize, tmpl::list<>>>>;
59 
60  static void initialize(
61  Parallel::CProxy_ConstGlobalCache<Metavariables>& global_cache,
63  domain_creator,
64  double initial_time, double initial_dt) noexcept;
65 
66  static void initialize(
67  Parallel::CProxy_ConstGlobalCache<Metavariables>& global_cache,
69  domain_creator,
70  double initial_time, double initial_dt,
71  double initial_slab_size) noexcept;
72 
73  static void execute_next_phase(
74  const typename Metavariables::Phase next_phase,
75  Parallel::CProxy_ConstGlobalCache<Metavariables>& global_cache) noexcept {
76  auto& local_cache = *(global_cache.ckLocalBranch());
77  if (next_phase == Metavariables::Phase::Evolve) {
78  Parallel::get_parallel_component<DgElementArray>(local_cache)
79  .perform_algorithm();
80  } else {
81  try_register_with_observers(next_phase, global_cache);
82  }
83  }
84 
85  private:
86  template <typename PhaseType,
88  nullptr>
89  static void try_register_with_observers(
90  const PhaseType /*next_phase*/,
91  Parallel::CProxy_ConstGlobalCache<
92  Metavariables>& /*global_cache*/) noexcept {}
93 
94  template <
95  typename PhaseType,
97  static void try_register_with_observers(
98  const PhaseType next_phase,
99  Parallel::CProxy_ConstGlobalCache<Metavariables>& global_cache) noexcept {
100  if (next_phase == Metavariables::Phase::RegisterWithObserver) {
101  auto& local_cache = *(global_cache.ckLocalBranch());
102  // We currently use a fake temporal id when registering observers but in
103  // the future when we start doing load balancing and elements migrate
104  // around the system they will need to register and unregister themselves
105  // at specific times.
106  const size_t fake_temporal_id = 0;
109  Parallel::get_parallel_component<DgElementArray>(local_cache),
110  fake_temporal_id);
111  }
112  }
113 };
114 
115 template <class Metavariables, class InitializeAction, class ActionList>
117  Parallel::CProxy_ConstGlobalCache<Metavariables>& global_cache,
119  const double initial_time, const double initial_dt) noexcept {
120  initialize(global_cache, std::move(domain_creator), initial_time, initial_dt,
121  std::abs(initial_dt));
122 }
123 
124 template <class Metavariables, class InitializeAction, class ActionList>
126  Parallel::CProxy_ConstGlobalCache<Metavariables>& global_cache,
128  domain_creator,
129  const double initial_time, const double initial_dt,
130  const double initial_slab_size) noexcept {
131  auto& cache = *global_cache.ckLocalBranch();
132  auto& dg_element_array =
133  Parallel::get_parallel_component<DgElementArray>(cache);
134 
135  if (not Metavariables::local_time_stepping and
136  std::abs(initial_dt) != initial_slab_size) {
137  ERROR("Step and slab size must agree for global time-stepping.");
138  }
139 
140  auto domain = domain_creator->create_domain();
141  for (const auto& block : domain.blocks()) {
142  const auto initial_ref_levs =
143  domain_creator->initial_refinement_levels()[block.id()];
144  const std::vector<ElementId<volume_dim>> element_ids =
145  initial_element_ids(block.id(), initial_ref_levs);
146  int which_proc = 0;
148  for (size_t i = 0; i < element_ids.size(); ++i) {
149  dg_element_array(ElementIndex<volume_dim>(element_ids[i]))
150  .insert(global_cache, which_proc);
151  which_proc = which_proc + 1 == number_of_procs ? 0 : which_proc + 1;
152  }
153  }
154  dg_element_array.doneInserting();
155 
156  Parallel::simple_action<InitializeAction>(
157  dg_element_array, domain_creator->initial_extents(), std::move(domain),
158  initial_time, initial_dt, initial_slab_size);
159 }
Definition: Actions.hpp:20
Definition: Tags.hpp:130
Definition: DgElementArray.hpp:39
#define ERROR(m)
prints an error message to the standard error stream and aborts the program.
Definition: Error.hpp:35
Defines functions for interfacing with the parallelization framework.
The sender will perform both reduction and volume observations.
The initial time step taken by the time stepper. This may be overridden by an adaptive stepper...
Definition: Tags.hpp:153
Definition: BlockId.hpp:16
Registers itself with the local observer parallel component so the observer knows to expect data from...
Definition: Actions.hpp:97
int number_of_procs()
Number of processing elements.
Definition: Info.hpp:16
Defines class ElementId.
Base class for creating Domains from an option string.
Definition: DomainCreator.hpp:87
tmpl::remove_duplicates< tmpl::join< tmpl::transform< ActionsList, Parallel_detail::get_const_global_cache_tags_from_action< tmpl::_1 > >> > get_const_global_cache_tags
Given a list of Actions, get a list of the unique tags specified in the actions&#39; const_global_cache_t...
Definition: ParallelComponentHelpers.hpp:72
Defines classes and functions used for manipulating DataBox&#39;s.
std::vector< ElementId< VolumeDim > > initial_element_ids(const std::vector< std::array< size_t, VolumeDim >> &initial_refinement_levels) noexcept
Create the ElementIds of the initial computational domain.
Definition: InitialElementIds.cpp:67
Indicates the Frame that a TensorIndexType is in.
Definition: IndexType.hpp:36
The initial slab size.
Definition: Tags.hpp:162
The time at which to start the simulation.
Definition: Tags.hpp:142
Defines class ElementIndex.
Wraps the template metaprogramming library used (brigand)
void simple_action(Proxy &&proxy) noexcept
Invoke a simple action on proxy
Definition: Invoke.hpp:112
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
typename DataBox_detail::compute_dbox_type< get_items< TagList >, get_compute_items< TagList > >::type compute_databox_type
Returns the type of the DataBox that would be constructed from the TagList of tags.
Definition: DataBox.hpp:1827
Definition: SolvePoissonProblem.hpp:38
A class for indexing a Charm array by Element.
Definition: ElementIndex.hpp:53
Defines class template ConstGlobalCache.
Defines macro ERROR.
The input file tag for the DomainCreator to use.
Definition: Tags.hpp:44
Defines tags related to Time quantities.
Definition: ComputeTimeDerivative.hpp:28
Defines class DomainCreator.