Divergence.hpp
Go to the documentation of this file.
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 /// \file
5 /// Defines functions and tags for taking a divergence.
6 
7 #pragma once
8 
9 #include <cstddef>
10 #include <string>
11 
14 #include "Utilities/Requires.hpp"
15 #include "Utilities/TMPL.hpp"
16 #include "Utilities/TypeTraits.hpp" // IWYU pragma: keep
17 
18 /// \cond
19 class DataVector;
20 template <size_t Dim>
21 class Mesh;
22 template <typename TagsList>
23 class Variables;
24 
25 namespace Tags {
26 template <size_t Dim>
27 struct Mesh;
28 /// \endcond
29 
30 /// \ingroup DataBoxTagsGroup
31 /// \brief Prefix indicating the divergence
32 ///
33 /// Prefix indicating the divergence of a Tensor or that a Variables
34 /// contains divergences of Tensors.
35 ///
36 /// \snippet Test_Divergence.cpp divergence_name
37 ///
38 /// \see Tags::DivCompute
39 template <typename Tag, typename = std::nullptr_t>
40 struct div;
41 
42 /// \cond
43 template <typename Tag>
44 struct div<Tag, Requires<tt::is_a_v<Tensor, db::item_type<Tag>>>>
46  static std::string name() noexcept { return "div(" + Tag::name() + ")"; }
47  using tag = Tag;
49 };
50 
51 template <typename Tag>
52 struct div<Tag, Requires<tt::is_a_v<::Variables, db::item_type<Tag>>>>
54  static std::string name() noexcept { return "div(" + Tag::name() + ")"; }
55  using tag = Tag;
56  using type = db::item_type<Tag>;
57 };
58 /// \endcond
59 } // namespace Tags
60 
61 /// \ingroup NumericalAlgorithmsGroup
62 /// \brief Compute the (Euclidean) divergence of fluxes
63 template <typename FluxTags, size_t Dim, typename DerivativeFrame>
64 auto divergence(
65  const Variables<FluxTags>& F, const Mesh<Dim>& mesh,
66  const InverseJacobian<DataVector, Dim, Frame::Logical, DerivativeFrame>&
67  inverse_jacobian) noexcept
68  -> Variables<db::wrap_tags_in<Tags::div, FluxTags>>;
69 
70 namespace Tags {
71 /// \ingroup DataBoxTagsGroup
72 /// \brief Compute the divergence of a Variables
73 ///
74 /// Computes the divergence of the Tensors in the Variables
75 /// represented by `Tag` in the frame mapped to by
76 /// `InverseJacobianTag`. The map must map from the logical frame.
77 ///
78 /// This tag inherits from `db::add_prefix_tag<Tags::div, Tag>`.
79 template <typename Tag, typename InverseJacobianTag>
81  private:
82  using inv_jac_indices =
84  static constexpr auto dim = tmpl::back<inv_jac_indices>::dim;
85  static_assert(cpp17::is_same_v<typename tmpl::front<inv_jac_indices>::Frame,
87  "Must map from the logical frame.");
88 
89  public:
90  static constexpr auto function =
91  divergence<typename db::item_type<Tag>::tags_list, dim,
92  typename tmpl::back<inv_jac_indices>::Frame>;
93  using argument_tags = tmpl::list<Tag, Tags::Mesh<dim>, InverseJacobianTag>;
94 };
95 } // namespace Tags
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
Marks a DataBoxTag as being a compute item that executes a function.
Definition: DataBoxTag.hpp:155
Holds the number of grid points, basis, and quadrature in each direction of the computational grid...
Definition: Mesh.hpp:49
Tags for the DataBox inherit from this type.
Definition: DataBoxTag.hpp:65
Prefix indicating the divergence.
Definition: Divergence.hpp:40
Defines the type alias Requires.
A collection of useful type traits.
Definition: TensorExpression.hpp:115
constexpr bool is_same_v
Variable template for is_same.
Definition: TypeTraits.hpp:221
constexpr bool is_a_v
Definition: TypeTraits.hpp:543
auto divergence(const Variables< FluxTags > &F, const Mesh< Dim > &mesh, const InverseJacobian< DataVector, Dim, Frame::Logical, DerivativeFrame > &inverse_jacobian) noexcept -> Variables< db::wrap_tags_in< Tags::div, FluxTags >>
Compute the (Euclidean) divergence of fluxes.
Definition: DataBoxTag.hpp:29
Definition: IndexType.hpp:42
Defines classes for Tensor.
::Tensor< typename Tensor::type, tmpl::pop_front< typename Tensor::symmetry >, tmpl::pop_front< typename Tensor::index_list > > remove_first_index
remove the first index of a tensor
Definition: Metafunctions.hpp:113
Stores a collection of function values.
Definition: DataVector.hpp:46
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
Marks an item as being a prefix to another tag.
Definition: DataBoxTag.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
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Compute the divergence of a Variables.
Definition: Divergence.hpp:80
Defines type traits, some of which are future STL type_traits header.