PartialDerivatives.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 computing partial derivatives.
6 
7 #pragma once
8 
9 #include <array>
10 #include <cstddef>
11 #include <string>
12 
15 #include "Utilities/Requires.hpp"
16 #include "Utilities/TMPL.hpp"
17 #include "Utilities/TypeTraits.hpp"
18 
19 /// \cond
20 class DataVector;
21 template <size_t Dim>
22 class Mesh;
23 
24 namespace Tags {
25 template <size_t Dim>
26 struct Mesh;
27 template <class TagList>
28 struct Variables;
29 /// \endcond
30 
31 /*!
32  * \ingroup DataBoxTagsGroup
33  * \brief Prefix indicating spatial derivatives
34  *
35  * Prefix indicating the spatial derivatives of a Tensor or that a Variables
36  * contains spatial derivatives of Tensors.
37  *
38  * \tparam Tag The tag to wrap
39  * \tparam Dim The volume dim as a type (e.g. `tmpl::size_t<Dim>`)
40  * \tparam Frame The frame of the derivative index
41  *
42  * \see Tags::DerivCompute
43  */
44 template <typename Tag, typename Dim, typename Frame, typename = std::nullptr_t>
45 struct deriv;
46 
47 template <typename Tag, typename Dim, typename Frame>
48 struct deriv<Tag, Dim, Frame, Requires<tt::is_a_v<Tensor, db::item_type<Tag>>>>
50  using type =
52  UpLo::Lo, Frame>;
53  using tag = Tag;
54  static std::string name() noexcept { return "deriv(" + Tag::name() + ")"; }
55 };
56 template <typename Tag, typename Dim, typename Frame>
57 struct deriv<Tag, Dim, Frame,
58  Requires<tt::is_a_v<::Variables, db::item_type<Tag>>>>
60  using type = db::item_type<Tag>;
61  using tag = Tag;
62  static std::string name() noexcept { return "deriv(" + Tag::name() + ")"; }
63 };
64 
65 } // namespace Tags
66 
67 // @{
68 /// \ingroup NumericalAlgorithmsGroup
69 /// \brief Compute the partial derivatives of each variable with respect to
70 /// the logical coordinate.
71 ///
72 /// \requires `DerivativeTags` to be the head of `VariableTags`
73 ///
74 /// Returns a `Variables` with a spatial tensor index appended to the front
75 /// of each tensor within `u` and each `Tag` wrapped with a `Tags::deriv`.
76 ///
77 /// \tparam DerivativeTags the subset of `VariableTags` for which derivatives
78 /// are computed.
79 template <typename DerivativeTags, typename VariableTags, size_t Dim>
81  gsl::not_null<std::array<Variables<DerivativeTags>, Dim>*>
82  logical_partial_derivatives_of_u,
83  const Variables<VariableTags>& u, const Mesh<Dim>& mesh) noexcept;
84 
85 template <typename DerivativeTags, typename VariableTags, size_t Dim>
86 auto logical_partial_derivatives(const Variables<VariableTags>& u,
87  const Mesh<Dim>& mesh) noexcept
89 // @}
90 
91 // @{
92 /// \ingroup NumericalAlgorithmsGroup
93 /// \brief Compute the partial derivatives of each variable with respect to
94 /// the coordinates of `DerivativeFrame`.
95 ///
96 /// \requires `DerivativeTags` to be the head of `VariableTags`
97 ///
98 /// Returns a `Variables` with a spatial tensor index appended to the front
99 /// of each tensor within `u` and each `Tag` wrapped with a `Tags::deriv`.
100 ///
101 /// \tparam DerivativeTags the subset of `VariableTags` for which derivatives
102 /// are computed.
103 template <typename DerivativeTags, size_t Dim, typename DerivativeFrame>
106  Tags::deriv, DerivativeTags, tmpl::size_t<Dim>, DerivativeFrame>>*>
107  du,
108  const std::array<Variables<DerivativeTags>, Dim>&
109  logical_partial_derivatives_of_u,
110  const InverseJacobian<DataVector, Dim, Frame::Logical, DerivativeFrame>&
111  inverse_jacobian) noexcept;
112 
113 template <typename DerivativeTags, typename VariableTags, size_t Dim,
114  typename DerivativeFrame>
117  Tags::deriv, DerivativeTags, tmpl::size_t<Dim>, DerivativeFrame>>*>
118  du,
119  const Variables<VariableTags>& u, const Mesh<Dim>& mesh,
120  const InverseJacobian<DataVector, Dim, Frame::Logical, DerivativeFrame>&
121  inverse_jacobian) noexcept;
122 
123 template <typename DerivativeTags, typename VariableTags, size_t Dim,
124  typename DerivativeFrame>
126  const Variables<VariableTags>& u, const Mesh<Dim>& mesh,
127  const InverseJacobian<DataVector, Dim, Frame::Logical, DerivativeFrame>&
128  inverse_jacobian) noexcept
129  -> Variables<db::wrap_tags_in<Tags::deriv, DerivativeTags,
130  tmpl::size_t<Dim>, DerivativeFrame>>;
131 // @}
132 
133 namespace Tags {
134 
135 /*!
136  * \ingroup DataBoxTagsGroup
137  * \brief Compute the spatial derivatives of tags in a Variables
138  *
139  * Computes the spatial derivatives of the Tensors in the Variables represented
140  * by `VariablesTag` in the frame mapped to by `InverseJacobianTag`. To only
141  * take the derivatives of a subset of these Tensors you can set the
142  * `DerivTags` template parameter. It takes a `tmpl::list` of the desired
143  * tags and defaults to the full `tags_list` of the Variables.
144  *
145  * This tag may be retrieved via `db::variables_tag_with_tags_list<VariablesTag,
146  * DerivTags>` prefixed with `Tags::deriv`.
147  */
148 template <typename VariablesTag, typename InverseJacobianTag,
149  typename DerivTags = typename db::item_type<VariablesTag>::tags_list>
152  deriv, db::variables_tag_with_tags_list<VariablesTag, DerivTags>,
153  tmpl::size_t<tmpl::back<
154  typename db::item_type<InverseJacobianTag>::index_list>::dim>,
155  typename tmpl::back<
156  typename db::item_type<InverseJacobianTag>::index_list>::Frame>,
158  private:
159  using inv_jac_indices =
161  static constexpr auto Dim = tmpl::back<inv_jac_indices>::dim;
162  using deriv_frame = typename tmpl::back<inv_jac_indices>::Frame;
163 
164  public:
165  static constexpr ::Variables<db::wrap_tags_in<
166  Tags::deriv, DerivTags, tmpl::size_t<Dim>, deriv_frame>> (*function)(
167  const ::Variables<typename db::item_type<VariablesTag>::tags_list>&,
168  const ::Mesh<Dim>&,
169  const ::InverseJacobian<DataVector, Dim, Frame::Logical, deriv_frame>&) =
170  partial_derivatives<DerivTags,
172  deriv_frame>;
173  using argument_tags =
174  tmpl::list<VariablesTag, Tags::Mesh<Dim>, InverseJacobianTag>;
175 };
176 
177 } // 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
Covariant, or Lower index.
void logical_partial_derivatives(gsl::not_null< std::array< Variables< DerivativeTags >, Dim > *> logical_partial_derivatives_of_u, const Variables< VariableTags > &u, const Mesh< Dim > &mesh) noexcept
Compute the partial derivatives of each variable with respect to the logical coordinate.
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
tmpl::transform< TagList, tmpl::bind< Wrapper, tmpl::_1, tmpl::pin< Args >... > > wrap_tags_in
Create a new list of Tags by wrapping each tag in TagList using the Wrapper.
Definition: DataBoxTag.hpp:418
Defines the type alias Requires.
A collection of useful type traits.
Definition: TensorExpression.hpp:115
void partial_derivatives(gsl::not_null< Variables< db::wrap_tags_in< Tags::deriv, DerivativeTags, tmpl::size_t< Dim >, DerivativeFrame >> *> du, const std::array< Variables< DerivativeTags >, Dim > &logical_partial_derivatives_of_u, const InverseJacobian< DataVector, Dim, Frame::Logical, DerivativeFrame > &inverse_jacobian) noexcept
Compute the partial derivatives of each variable with respect to the coordinates of DerivativeFrame...
Prefix indicating spatial derivatives.
Definition: PartialDerivatives.hpp:45
constexpr bool is_a_v
Definition: TypeTraits.hpp:543
Indicates the Frame that a TensorIndexType is in.
Definition: IndexType.hpp:36
Defines class Variables.
Definition: DataBoxTag.hpp:29
Compute the spatial derivatives of tags in a Variables.
Definition: PartialDerivatives.hpp:150
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
::Tensor< typename Tensor::type, tmpl::push_front< typename Tensor::symmetry, tmpl::int32_t< 1+tmpl::fold< typename Tensor::symmetry, tmpl::int32_t< 0 >, tmpl::max< tmpl::_state, tmpl::_element > >::value > >, tmpl::push_front< typename Tensor::index_list, SpatialIndex< VolumeDim, Ul, Fr > >> prepend_spatial_index
Add a spatial index to the front of a Tensor.
Definition: Metafunctions.hpp:85
Defines classes SimpleTag, PrefixTag, ComputeTag and several functions for retrieving tag info...
Defines type traits, some of which are future STL type_traits header.
Require a pointer to not be a nullptr
Definition: ConservativeFromPrimitive.hpp:12