Initialize.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <array>
7 #include <cstddef>
8 #include <tuple>
9 #include <utility> // IWYU pragma: keep
10 #include <vector>
11 
15 #include "DataStructures/Variables.hpp" // IWYU pragma: keep
16 #include "Domain/Mesh.hpp"
17 #include "Domain/Tags.hpp"
18 #include "Evolution/Initialization/ConservativeSystem.hpp"
19 #include "Evolution/Initialization/DiscontinuousGalerkin.hpp"
20 #include "Evolution/Initialization/Domain.hpp"
21 #include "Evolution/Initialization/Evolution.hpp"
22 #include "Evolution/Initialization/Interface.hpp"
23 #include "Evolution/Initialization/Limiter.hpp"
24 #include "Evolution/Systems/GrMhd/ValenciaDivClean/Tags.hpp"
25 #include "Evolution/VariableFixing/FixToAtmosphere.hpp"
26 #include "NumericalAlgorithms/LinearOperators/Divergence.tpp"
28 #include "PointwiseFunctions/AnalyticData/Tags.hpp"
29 #include "PointwiseFunctions/AnalyticSolutions/Tags.hpp"
30 #include "PointwiseFunctions/GeneralRelativity/IndexManipulation.hpp"
31 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
32 #include "PointwiseFunctions/Hydro/LorentzFactor.hpp"
33 #include "PointwiseFunctions/Hydro/SpecificEnthalpy.hpp"
34 #include "PointwiseFunctions/Hydro/Tags.hpp"
35 #include "Utilities/Gsl.hpp"
37 #include "Utilities/TMPL.hpp"
38 
39 namespace grmhd {
40 namespace ValenciaDivClean {
41 namespace Actions {
42 namespace detail {
43 template <class T, class = cpp17::void_t<>>
44 struct has_analytic_solution_alias : std::false_type {};
45 template <class T>
46 struct has_analytic_solution_alias<T,
47  cpp17::void_t<typename T::analytic_solution>>
48  : std::true_type {};
49 } // namespace detail
50 
51 // Note: I've left the Dim and System template parameters until it is clear
52 // whether or not what remains is specific to this system, and what might be
53 // applicable to more than one system
54 template <size_t Dim>
55 struct Initialize {
56  template <typename Metavariables>
57  struct PrimitiveTags {
58  using system = typename Metavariables::system;
59  using primitives_tag = typename system::primitive_variables_tag;
60  using simple_tags = db::AddSimpleTags<
61  primitives_tag, typename Metavariables::equation_of_state_tag,
63  using compute_tags = db::AddComputeTags<>;
64 
65  template <typename TagsList>
66  static auto initialize(
69  const double initial_time) noexcept {
70  using PrimitiveVars = typename primitives_tag::type;
71 
72  const size_t num_grid_points =
73  db::get<::Tags::Mesh<Dim>>(box).number_of_grid_points();
74 
75  const auto& inertial_coords =
76  db::get<::Tags::Coordinates<Dim, Frame::Inertial>>(box);
77 
78  // Set initial data from analytic solution
79  PrimitiveVars primitive_vars{num_grid_points};
80  auto equation_of_state = make_overloader(
81  [ initial_time, &inertial_coords ](
82  std::true_type /*is_analytic_solution*/,
83  const gsl::not_null<PrimitiveVars*> prim_vars,
84  const auto& local_cache) noexcept {
85  using solution_tag = OptionTags::AnalyticSolutionBase;
86  prim_vars->assign_subset(
87  Parallel::get<solution_tag>(local_cache)
88  .variables(
89  inertial_coords, initial_time,
90  typename Metavariables::analytic_variables_tags{}));
91  return Parallel::get<solution_tag>(local_cache).equation_of_state();
92  },
93  [&inertial_coords](std::false_type /*is_analytic_solution*/,
94  const gsl::not_null<PrimitiveVars*> prim_vars,
95  const auto& local_cache) noexcept {
96  using analytic_data_tag = OptionTags::AnalyticDataBase;
97  prim_vars->assign_subset(
98  Parallel::get<analytic_data_tag>(local_cache)
99  .variables(
100  inertial_coords,
101  typename Metavariables::analytic_variables_tags{}));
102  return Parallel::get<analytic_data_tag>(local_cache)
103  .equation_of_state();
104  })(detail::has_analytic_solution_alias<Metavariables>{},
105  make_not_null(&primitive_vars), cache);
106 
108  equation_of_state)::thermodynamic_dim>
109  fixer{1.e-12, 1.e-12};
110  fixer(
111  &get<hydro::Tags::RestMassDensity<DataVector>>(primitive_vars),
113  &get<hydro::Tags::SpatialVelocity<DataVector, 3>>(primitive_vars),
114  &get<hydro::Tags::LorentzFactor<DataVector>>(primitive_vars),
115  &get<hydro::Tags::Pressure<DataVector>>(primitive_vars),
116  &get<hydro::Tags::SpecificEnthalpy<DataVector>>(primitive_vars),
117  equation_of_state);
118 
119  return db::create_from<db::RemoveTags<>, simple_tags, compute_tags>(
120  std::move(box), std::move(primitive_vars),
121  std::move(equation_of_state),
122  Parallel::get<OptionTags::DampingParameter>(cache));
123  }
124  };
125 
126  template <typename System>
127  struct GrTags {
128  using gr_tag = typename System::spacetime_variables_tag;
129  using simple_tags = db::AddSimpleTags<gr_tag>;
130  using compute_tags = db::AddComputeTags<>;
131 
132  template <typename TagsList, typename Metavariables>
133  static auto initialize(
134  db::DataBox<TagsList>&& box,
136  const double initial_time) noexcept {
137  using GrVars = typename gr_tag::type;
138 
139  const size_t num_grid_points =
140  db::get<::Tags::Mesh<Dim>>(box).number_of_grid_points();
141  const auto& inertial_coords =
142  db::get<::Tags::Coordinates<Dim, Frame::Inertial>>(box);
143 
144  // Set initial data from analytic solution
145  GrVars gr_vars{num_grid_points};
147  [ initial_time, &inertial_coords ](
148  std::true_type /*is_analytic_solution*/,
149  const gsl::not_null<GrVars*> local_gr_vars,
150  const auto& local_cache) noexcept {
151  using solution_tag = OptionTags::AnalyticSolutionBase;
152  local_gr_vars->assign_subset(
153  Parallel::get<solution_tag>(local_cache)
154  .variables(inertial_coords, initial_time,
155  typename GrVars::tags_list{}));
156  },
157  [&inertial_coords](std::false_type /*is_analytic_solution*/,
158  const gsl::not_null<GrVars*> local_gr_vars,
159  const auto& local_cache) noexcept {
160  using analytic_data_tag = OptionTags::AnalyticDataBase;
161  local_gr_vars->assign_subset(
162  Parallel::get<analytic_data_tag>(local_cache)
163  .variables(inertial_coords, typename GrVars::tags_list{}));
164  })(detail::has_analytic_solution_alias<Metavariables>{},
165  make_not_null(&gr_vars), cache);
166 
167  return db::create_from<db::RemoveTags<>, simple_tags, compute_tags>(
168  std::move(box), std::move(gr_vars));
169  }
170  };
171 
172  template <class Metavariables>
173  using return_tag_list = tmpl::append<
174  typename Initialization::Domain<Dim>::simple_tags,
175  typename GrTags<typename Metavariables::system>::simple_tags,
176  typename PrimitiveTags<Metavariables>::simple_tags,
178  typename Metavariables::system>::simple_tags,
179  typename Initialization::Interface<
180  typename Metavariables::system>::simple_tags,
181  typename Initialization::Evolution<
182  typename Metavariables::system>::simple_tags,
184  Metavariables>::simple_tags,
185  typename Initialization::MinMod<Dim>::simple_tags,
186  typename Initialization::Domain<Dim>::compute_tags,
187  typename GrTags<typename Metavariables::system>::compute_tags,
188  typename PrimitiveTags<Metavariables>::compute_tags,
190  typename Metavariables::system>::compute_tags,
191  typename Initialization::Interface<
192  typename Metavariables::system>::compute_tags,
193  typename Initialization::Evolution<
194  typename Metavariables::system>::compute_tags,
196  Metavariables>::compute_tags,
197  typename Initialization::MinMod<Dim>::compute_tags>;
198 
199  template <typename... InboxTags, typename Metavariables, typename ActionList,
200  typename ParallelComponent>
201  static auto apply(const db::DataBox<tmpl::list<>>& /*box*/,
202  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
204  const ElementIndex<Dim>& array_index,
205  const ActionList /*meta*/,
206  const ParallelComponent* const /*meta*/,
207  std::vector<std::array<size_t, Dim>> initial_extents,
209  const double initial_time, const double initial_dt,
210  const double initial_slab_size) noexcept {
211  using system = typename Metavariables::system;
212  auto domain_box = Initialization::Domain<Dim>::initialize(
213  db::DataBox<tmpl::list<>>{}, array_index, initial_extents, domain);
214  auto gr_box = GrTags<system>::initialize(std::move(domain_box), cache,
215  initial_time);
216  auto primitive_box = PrimitiveTags<Metavariables>::initialize(
217  std::move(gr_box), cache, initial_time);
219  std::move(primitive_box));
220  auto conservative_box =
222  std::move(system_box));
223  auto domain_interface_box = Initialization::Interface<system>::initialize(
224  std::move(conservative_box));
226  std::move(domain_interface_box), cache, initial_time, initial_dt,
227  initial_slab_size);
228  auto dg_box =
230  std::move(evolution_box), initial_extents);
231  auto limiter_box =
232  Initialization::MinMod<Dim>::initialize(std::move(dg_box));
233  return std::make_tuple(std::move(limiter_box));
234  }
235 };
236 } // namespace Actions
237 } // namespace ValenciaDivClean
238 } // namespace grmhd
Definition: Variables.hpp:46
The spatial velocity .
Definition: Tags.hpp:144
Allocate items for minmod limiter.
Definition: Limiter.hpp:24
Fix the primitive variables to an atmosphere in low density regions.
Definition: FixToAtmosphere.hpp:47
Overloader< Fs... > make_overloader(Fs... fs)
Create Overloader<Fs...>, see Overloader for details.
Definition: Overloader.hpp:109
Initialize items related to the basic structure of the Domain.
Definition: Domain.hpp:48
The fluid pressure .
Definition: Tags.hpp:123
Definition: BlockId.hpp:16
void void_t
Given a set of types, returns void
Definition: TypeTraits.hpp:214
The specific internal energy .
Definition: Tags.hpp:176
Initialize items related to time-evolution of the system.
Definition: Evolution.hpp:51
Can be used to retrieve the analytic data from the cache without having to know the template paramete...
Definition: Tags.hpp:12
Define prefixes for DataBox tags.
constexpr auto apply(F &&f, const DataBox< BoxTags > &box, Args &&... args)
Apply the function f with argument Tags TagsList from DataBox box
Definition: DataBox.hpp:1595
Definition: Determinant.hpp:11
Initialize items related to the discontinuous Galerkin method.
Definition: DiscontinuousGalerkin.hpp:57
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
Defines classes and functions used for manipulating DataBox&#39;s.
tmpl::flatten< tmpl::list< Tags... > > AddSimpleTags
List of Tags to add to the DataBox.
Definition: DataBox.hpp:1227
Initialize items related to the interfaces between Elements and on external boundaries.
Definition: Interface.hpp:39
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Defines class Variables.
The Lorentz factor .
Definition: Tags.hpp:64
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:76
Defines the class template Mesh.
Allocate variables needed for evolution of conservative systems.
Definition: ConservativeSystem.hpp:44
Can be used to retrieve the analytic solution from the cache without having to know the template para...
Definition: Tags.hpp:12
A wrapper around a vector of Blocks that represent the computational domain.
Definition: Domain.hpp:36
The Poisson equation formulated as a set of coupled first-order PDEs.
Definition: FirstOrderSystem.hpp:55
Wraps the template metaprogramming library used (brigand)
Defines functions and classes from the GSL.
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, but it may be necessary to perform the conversion explicitly when type deduction is desired.
Definition: Gsl.hpp:863
Defines tags related to domain quantities.
The rest-mass density .
Definition: Tags.hpp:130
C++ STL code present in C++17.
Definition: Array.hpp:16
Definition: SolvePoissonProblem.hpp:38
A class for indexing a Charm array by Element.
Definition: ElementIndex.hpp:53
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Defines class template ConstGlobalCache.
The specific enthalpy .
Definition: Tags.hpp:169
Items related to general relativistic magnetohydrodynamics (GRMHD)
Definition: Characteristics.hpp:34
The constraint damping parameter for divergence cleaning.
Definition: Tags.hpp:38
Initialize the conservative variables from the primitive variables.
Definition: ConservativeSystem.hpp:80
Definition: ComputeTimeDerivative.hpp:28
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12
Defines make_with_value.
tmpl::flatten< tmpl::list< Tags... > > AddComputeTags
List of Compute Item Tags to add to the DataBox.
Definition: DataBox.hpp:1234