ComputeTags.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include "DataStructures/DataBox/PrefixHelpers.hpp"
7 #include "DataStructures/DataBox/Tag.hpp"
10 #include "DataStructures/VariablesTag.hpp"
11 #include "Domain/Tags.hpp"
12 #include "PointwiseFunctions/AnalyticSolutions/Tags.hpp"
13 #include "Time/Tags.hpp"
14 #include "Utilities/TMPL.hpp"
15 
16 namespace evolution {
17 namespace Tags {
18 /*!
19  * \brief Use the `AnalyticSolutionTag` to compute the analytic solution of the
20  * tags in `AnalyticFieldsTagList`.
21  */
22 template <size_t Dim, typename AnalyticSolutionTag,
23  typename AnalyticFieldsTagList>
24 struct AnalyticCompute : ::Tags::AnalyticSolutions<AnalyticFieldsTagList>,
27  using return_type = typename base::type;
28  using argument_tags =
29  tmpl::list<AnalyticSolutionTag,
31  static void function(
32  const gsl::not_null<return_type*> analytic_solution,
33  const typename AnalyticSolutionTag::type& analytic_solution_computer,
34  const tnsr::I<DataVector, Dim, Frame::Inertial>& inertial_coords,
35  const double time) noexcept {
36  *analytic_solution =
37  variables_from_tagged_tuple(analytic_solution_computer.variables(
38  inertial_coords, time, AnalyticFieldsTagList{}));
39  }
40 };
41 
42 // @{
43 /*!
44  * \brief For each `Tag` in `TagsList`, compute its difference from the
45  * analytic solution.
46  */
47 template <size_t VolumeDim, typename AnalyticSolutionTag, typename TagsList>
49  : db::add_tag_prefix<::Tags::Error, ::Tags::Variables<TagsList>>,
52  using return_type = tmpl::type_from<base>;
53 
54  using argument_tags = tmpl::append<
55  tmpl::list<AnalyticSolutionTag,
57  ::Tags::Time>,
58  TagsList>;
59 
60  template <typename AnalyticSolution, typename... ErrorTags,
61  typename... FieldTypes>
62  static constexpr void function(
63  const gsl::not_null<Variables<tmpl::list<ErrorTags...>>*> errors,
64  const AnalyticSolution& analytic_solution_computer,
65  const tnsr::I<DataVector, VolumeDim, Frame::Inertial>& inertial_coords,
66  const double time, const FieldTypes&... fields) noexcept {
67  *errors = return_type{get<0>(inertial_coords).size()};
68  const auto helper = [](const auto error, const auto& field) noexcept {
69  for (size_t i = 0; i < field.size(); ++i) {
70  (*error)[i] = field[i];
71  }
72  };
74  helper(make_not_null(&get<ErrorTags>(*errors)), fields));
75 
76  const auto analytic =
77  variables_from_tagged_tuple(analytic_solution_computer.variables(
78  inertial_coords, time, TagsList{}));
79  *errors -= analytic;
80  }
81 };
82 // @}
83 } // namespace Tags
84 } // namespace evolution
db::ComputeTag
Mark a struct as a compute tag by inheriting from this.
Definition: Tag.hpp:157
variables_from_tagged_tuple
Variables< tmpl::list< Tags... > > variables_from_tagged_tuple(const tuples::TaggedTuple< Tags... > &tuple) noexcept
Definition: Variables.hpp:819
EXPAND_PACK_LEFT_TO_RIGHT
#define EXPAND_PACK_LEFT_TO_RIGHT(...)
Expand a parameter pack evaluating the terms from left to right.
Definition: TMPL.hpp:563
evolution
Functionality for evolving hyperbolic partial differential equations.
Definition: AddMeshVelocityNonconservative.hpp:29
domain::Tags::Coordinates< Dim, Frame::Inertial >
Tags::AnalyticSolutions
The analytic solutions for all FieldTags
Definition: Tags.hpp:110
Tags.hpp
evolution::Tags::AnalyticCompute
Use the AnalyticSolutionTag to compute the analytic solution of the tags in AnalyticFieldsTagList.
Definition: ComputeTags.hpp:24
db::add_tag_prefix
typename detail::add_tag_prefix_impl< Prefix, Tag, Args... >::type add_tag_prefix
Definition: PrefixHelpers.hpp:51
Tags::Variables
Definition: VariablesTag.hpp:21
Tags::Time
Tag for the current time as a double.
Definition: Tags.hpp:73
Variables.hpp
Tensor.hpp
make_not_null
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,...
Definition: Gsl.hpp:880
evolution::Tags::ErrorsCompute
For each Tag in TagsList, compute its difference from the analytic solution.
Definition: ComputeTags.hpp:48
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecThirdOrderPiecewisePolynomial.hpp:13