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>
25  : db::add_tag_prefix<::Tags::Analytic,
26  ::Tags::Variables<AnalyticFieldsTagList>>,
30  using return_type = typename base::type;
31  using argument_tags =
32  tmpl::list<AnalyticSolutionTag,
34  static void function(
35  const gsl::not_null<return_type*> analytic_solution,
36  const typename AnalyticSolutionTag::type& analytic_solution_computer,
37  const tnsr::I<DataVector, Dim, Frame::Inertial>& inertial_coords,
38  const double time) noexcept {
39  *analytic_solution =
40  variables_from_tagged_tuple(analytic_solution_computer.variables(
41  inertial_coords, time, AnalyticFieldsTagList{}));
42  }
43 };
44 
45 // @{
46 /*!
47  * \brief For each `Tag` in `TagsList`, compute its difference from the
48  * analytic solution.
49  */
50 template <size_t VolumeDim, typename AnalyticSolutionTag, typename TagsList>
52  : db::add_tag_prefix<::Tags::Error, ::Tags::Variables<TagsList>>,
55  using return_type = tmpl::type_from<base>;
56 
57  using argument_tags = tmpl::append<
58  tmpl::list<AnalyticSolutionTag,
60  ::Tags::Time>,
61  TagsList>;
62 
63  template <typename AnalyticSolution, typename... ErrorTags,
64  typename... FieldTypes>
65  static constexpr void function(
66  const gsl::not_null<Variables<tmpl::list<ErrorTags...>>*> errors,
67  const AnalyticSolution& analytic_solution_computer,
68  const tnsr::I<DataVector, VolumeDim, Frame::Inertial>& inertial_coords,
69  const double time, const FieldTypes&... fields) noexcept {
70  *errors = return_type{get<0>(inertial_coords).size()};
71  const auto helper = [](const auto error, const auto& field) noexcept {
72  for (size_t i = 0; i < field.size(); ++i) {
73  (*error)[i] = field[i];
74  }
75  };
77  helper(make_not_null(&get<ErrorTags>(*errors)), fields));
78 
79  const auto analytic =
80  variables_from_tagged_tuple(analytic_solution_computer.variables(
81  inertial_coords, time, TagsList{}));
82  *errors -= analytic;
83  }
84 };
85 // @}
86 } // namespace Tags
87 } // 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:797
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.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::Analytic
Prefix indicating the analytic solution value for a quantity.
Definition: Tags.hpp:84
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:51
TMPL.hpp
gsl::not_null
Require a pointer to not be a nullptr
Definition: Gsl.hpp:183