ConservativeDuDt.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <tuple>
8 
13 #include "Utilities/Gsl.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 /// \ingroup ConservativeGroup
17 /// \brief Calculate \f$\partial u/\partial t\f$ for a conservative system.
18 ///
19 /// The time evolution of the variables \f$u\f$ of any conservative
20 /// system is given by \f$\partial_t u = - \partial_i F^i + S\f$,
21 /// where \f$F^i\f$ are the fluxes and \f$S\f$ are the sources.
22 ///
23 /// Source terms are only added for variables in the
24 /// `System::sourced_variables` type list.
25 template <typename System>
27  private:
28  template <typename TensorTagList, typename SourcedTagList>
29  struct apply_helper;
30 
31  template <typename... TensorTags, typename... SourcedTags>
32  struct apply_helper<tmpl::list<TensorTags...>, tmpl::list<SourcedTags...>> {
33  static void function(
35  const db::item_type<TensorTags>&... div_flux,
36  const db::item_type<SourcedTags>&... sources) noexcept {
37  const auto negate = [](const auto a, const auto& b) noexcept {
38  for (size_t i = 0; i < a->size(); ++i) {
39  (*a)[i] = -b[i];
40  }
41  return nullptr;
42  };
43  expand_pack(negate(dt_u, div_flux)...);
44  const auto add = [](const auto a, const auto& b) noexcept {
45  for (size_t i = 0; i < a->size(); ++i) {
46  (*a)[i] += b[i];
47  }
48  return nullptr;
49  };
50  (void)add;
51  expand_pack(add(
52  get<tmpl::index_of<tmpl::list<TensorTags...>, SourcedTags>::value>(
53  std::forward_as_tuple(dt_u...)),
54  sources)...);
55  }
56  };
57 
58  public:
59  static constexpr size_t volume_dim = System::volume_dim;
60  using frame = Frame::Inertial;
61 
62  using argument_tags = tmpl::append<
64  Tags::div,
65  db::add_tag_prefix<Tags::Flux, typename System::variables_tag,
66  tmpl::size_t<volume_dim>, frame>>>,
67  tmpl::transform<typename System::sourced_variables,
68  tmpl::bind<Tags::Source, tmpl::_1>>>;
69 
70  static constexpr auto apply =
71  apply_helper<db::split_tag<typename System::variables_tag>,
72  typename System::sourced_variables>::function;
73 };
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
Define prefixes for DataBox tags.
tmpl::conditional_t< tmpl::size< typename Subitems< TagList, Tag >::type >::value==0, tmpl::list< Tag >, typename Subitems< TagList, Tag >::type > split_tag
Split a tag into its subitems. Tag cannot be a base tag.
Definition: DataBoxTag.hpp:657
Calculate for a conservative system.
Definition: ConservativeDuDt.hpp:26
Prefix indicating a flux.
Definition: Prefixes.hpp:38
Defines classes for Tensor.
Wraps the template metaprogramming library used (brigand)
typename DataBox_detail::item_type_impl< TagList, Tag >::type item_type
Get the type that is returned by the Tag. If it is a base tag then a TagList must be passed as a seco...
Definition: DataBoxTag.hpp:410
Defines functions and classes from the GSL.
Definition: IndexType.hpp:44
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Defines functions and tags for taking a divergence.
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12
constexpr void expand_pack(Ts &&...) noexcept
Allows zero-cost unordered expansion of a parameter.
Definition: TMPL.hpp:545