ConservativeSystem.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 
15 /// \cond
16 namespace Frame {
17 struct Inertial;
18 } // namespace Frame
19 /// \endcond
20 
21 namespace Initialization {
22 
23 /// \brief Allocate variables needed for evolution of conservative systems
24 ///
25 /// Uses:
26 /// - DataBox:
27 /// * `Tags::Mesh<Dim>`
28 ///
29 /// DataBox changes:
30 /// - Adds:
31 /// * System::variables_tag
32 /// * db::add_tag_prefix<Tags::Flux, System::variables_tag>
33 /// * db::add_tag_prefix<Tags::Source, System::variables_tag>
34 ///
35 /// - Removes: nothing
36 /// - Modifies: nothing
37 ///
38 /// \note This only allocates storage as all variables are initialized to
39 /// `signaling_NaN()`. The `Flux` and `Source` will be computed during the
40 /// evolution, but the conservative variables themselves should be initialized
41 /// with a call to Initialization::ConservativeVars after the primitive
42 /// variables are initialized.
43 template <typename System>
45  static_assert(System::is_in_flux_conservative_form,
46  "System is not in flux conservative form");
47  static constexpr size_t dim = System::volume_dim;
48  using variables_tag = typename System::variables_tag;
49  using fluxes_tag = db::add_tag_prefix<Tags::Flux, variables_tag,
50  tmpl::size_t<dim>, Frame::Inertial>;
53  using compute_tags = db::AddComputeTags<>;
54 
55  template <typename TagsList>
56  static auto initialize(db::DataBox<TagsList>&& box) noexcept {
57  const size_t num_grid_points =
58  db::get<Tags::Mesh<dim>>(box).number_of_grid_points();
59  typename variables_tag::type vars(num_grid_points);
60  typename fluxes_tag::type fluxes(num_grid_points);
61  typename sources_tag::type sources(num_grid_points);
62 
63  return db::create_from<db::RemoveTags<>, simple_tags, compute_tags>(
64  std::move(box), std::move(vars), std::move(fluxes), std::move(sources));
65  }
66 };
67 
68 /// \brief Initialize the conservative variables from the primitive variables
69 ///
70 /// Uses:
71 /// - DataBox:
72 /// * System::conservative_from_primitive::argument_tags
73 ///
74 /// DataBox changes:
75 /// - Adds: nothing
76 /// - Removes: nothing
77 /// - Modifies:
78 /// * System::conservative_from_primitive::return_tags
79 template <typename System>
81  template <typename TagsList>
82  static auto initialize(db::DataBox<TagsList>&& box) noexcept {
84  typename System::conservative_from_primitive::return_tags,
85  typename System::conservative_from_primitive::argument_tags>(
86  typename System::conservative_from_primitive{}, make_not_null(&box));
87  return std::move(box);
88  }
89 };
90 } // 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
constexpr auto mutate_apply(F f, const gsl::not_null< DataBox< BoxTags > *> box, Args &&... args) noexcept(DataBox_detail::check_mutate_apply_mutate_tags(BoxTags{}, MutateTags{}) and DataBox_detail::check_mutate_apply_argument_tags(BoxTags{}, ArgumentTags{}) and noexcept(DataBox_detail::mutate_apply(f, box, MutateTags{}, ArgumentTags{}, std::forward< Args >(args)...)))
Apply the function f mutating items MutateTags and taking as additional arguments ArgumentTags and ar...
Definition: DataBox.hpp:1773
Items for initializing the DataBoxes of parallel components.
Definition: ConservativeSystem.hpp:21
Define prefixes for DataBox tags.
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
Prefix indicating a flux.
Definition: Prefixes.hpp:38
Indicates the Frame that a TensorIndexType is in.
Definition: IndexType.hpp:36
Definition: InterpolationTargetWedgeSectionTorus.hpp:24
Defines class Variables.
Defines the class template Mesh.
Allocate variables needed for evolution of conservative systems.
Definition: ConservativeSystem.hpp:44
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
Definition: IndexType.hpp:44
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Initialize the conservative variables from the primitive variables.
Definition: ConservativeSystem.hpp:80
tmpl::flatten< tmpl::list< Tags... > > AddComputeTags
List of Compute Item Tags to add to the DataBox.
Definition: DataBox.hpp:1234