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/Tags.hpp"
19 #include "Evolution/Systems/RadiationTransport/M1Grey/Tags.hpp"
20 #include "Evolution/Systems/RadiationTransport/Tags.hpp"
21 #include "Evolution/TypeTraits.hpp"
23 #include "ParallelAlgorithms/Initialization/MergeIntoDataBox.hpp"
24 #include "PointwiseFunctions/AnalyticData/Tags.hpp"
25 #include "PointwiseFunctions/AnalyticSolutions/Tags.hpp"
26 #include "PointwiseFunctions/GeneralRelativity/IndexManipulation.hpp"
27 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
28 #include "PointwiseFunctions/Hydro/Tags.hpp"
29 #include "Utilities/Gsl.hpp"
31 #include "Utilities/TMPL.hpp"
32 
33 namespace RadiationTransport {
34 namespace M1Grey {
35 namespace Actions {
36 
38  template <typename DbTagsList, typename... InboxTags, typename Metavariables,
39  typename ArrayIndex, typename ActionList,
40  typename ParallelComponent>
41  static auto apply(db::DataBox<DbTagsList>& box,
42  const tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
44  const ArrayIndex& /*array_index*/, ActionList /*meta*/,
45  const ParallelComponent* const /*meta*/) noexcept {
46  using system = typename Metavariables::system;
47  using evolved_variables_tag = typename system::variables_tag;
48  using hydro_variables_tag = typename system::hydro_variables_tag;
49  using m1_variables_tag = typename system::primitive_variables_tag;
50  // List of variables to be created... does NOT include
51  // evolved_variables_tag because the evolved variables
52  // are created by the ConservativeSystem initialization.
53  using simple_tags =
55  using compute_tags = db::AddComputeTags<>;
56 
57  using EvolvedVars = typename evolved_variables_tag::type;
58  using HydroVars = typename hydro_variables_tag::type;
59  using M1Vars = typename m1_variables_tag::type;
60 
61  static constexpr size_t dim = system::volume_dim;
62  const double initial_time = db::get<Initialization::Tags::InitialTime>(box);
63  const size_t num_grid_points =
64  db::get<::Tags::Mesh<dim>>(box).number_of_grid_points();
65  const auto& inertial_coords =
66  db::get<::Tags::Coordinates<dim, Frame::Inertial>>(box);
67 
68  db::mutate<evolved_variables_tag>(
69  make_not_null(&box),
71  [ initial_time, &inertial_coords ](
72  const gsl::not_null<EvolvedVars*> evolved_vars,
73  std::true_type /*is_analytic_solution*/,
74  const auto& local_cache) noexcept {
75  using solution_tag = ::Tags::AnalyticSolutionBase;
76  evolved_vars->assign_subset(
77  Parallel::get<solution_tag>(local_cache)
78  .variables(inertial_coords, initial_time,
79  typename evolved_variables_tag::tags_list{}));
80  },
81  [&inertial_coords](const gsl::not_null<EvolvedVars*> evolved_vars,
82  std::false_type /*is_analytic_solution*/,
83  const auto& local_cache) noexcept {
84  using analytic_data_tag = ::Tags::AnalyticDataBase;
85  evolved_vars->assign_subset(
86  Parallel::get<analytic_data_tag>(local_cache)
87  .variables(inertial_coords,
88  typename evolved_variables_tag::tags_list{}));
89  }),
90  evolution::is_analytic_solution<typename Metavariables::initial_data>{},
91  cache);
92 
93  // Get hydro variables
94  HydroVars hydro_variables{num_grid_points};
96  [ initial_time, &inertial_coords ](
97  std::true_type /*is_analytic_solution*/,
98  const gsl::not_null<HydroVars*> hydro_vars,
99  const auto& local_cache) noexcept {
100  using solution_tag = ::Tags::AnalyticSolutionBase;
101  hydro_vars->assign_subset(
102  Parallel::get<solution_tag>(local_cache)
103  .variables(inertial_coords, initial_time,
104  typename hydro_variables_tag::tags_list{}));
105  },
106  [&inertial_coords](std::false_type /*is_analytic_solution*/,
107  const gsl::not_null<HydroVars*> hydro_vars,
108  const auto& local_cache) noexcept {
109  using analytic_data_tag = ::Tags::AnalyticDataBase;
110  hydro_vars->assign_subset(
111  Parallel::get<analytic_data_tag>(local_cache)
112  .variables(inertial_coords,
113  typename hydro_variables_tag::tags_list{}));
114  })(
115  evolution::is_analytic_solution<typename Metavariables::initial_data>{},
116  make_not_null(&hydro_variables), cache);
117 
118  M1Vars m1_variables{num_grid_points, -1.};
119 
120  return std::make_tuple(
121  db::create_from<db::RemoveTags<>, simple_tags, compute_tags>(
122  std::move(box), std::move(hydro_variables),
123  std::move(m1_variables)));
124  }
125 };
126 
127 } // namespace Actions
128 } // namespace M1Grey
129 } // namespace RadiationTransport
Overloader< Fs... > make_overloader(Fs... fs)
Create Overloader<Fs...>, see Overloader for details.
Definition: Overloader.hpp:109
Can be used to retrieve the analytic solution from the cache without having to know the template para...
Definition: Tags.hpp:40
Items related to general relativistic radiation transport.
Definition: Characteristics.hpp:20
Define prefixes for DataBox tags.
tmpl::flatten< tmpl::list< Tags... > > RemoveTags
List of Tags to remove from the DataBox.
Definition: DataBox.hpp:1215
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:273
Defines classes and functions used for manipulating DataBox&#39;s.
constexpr auto create_from(db::DataBox< TagsList > &&box, Args &&... args) noexcept
Create a new DataBox from an existing one adding or removing items and compute items.
Definition: DataBox.hpp:1423
tmpl::flatten< tmpl::list< Tags... > > AddSimpleTags
List of Tags to add to the DataBox.
Definition: DataBox.hpp:1222
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Defines class Variables.
A Charm++ chare that caches constant data once per Charm++ node.
Definition: ConstGlobalCache.hpp:135
Defines the class template Mesh.
Can be used to retrieve the analytic solution from the cache without having to know the template para...
Definition: Tags.hpp:33
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:879
Defines tags related to domain quantities.
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Defines class template ConstGlobalCache.
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:1243