SemidiscretizedDg.hpp
2 // See LICENSE.txt for details.
3
4 #pragma once
5
6 #include <array>
7
9 #include "Evolution/Systems/ScalarWave/Tags.hpp" // IWYU pragma: keep
10 #include "Options/Options.hpp"
11 #include "PointwiseFunctions/AnalyticSolutions/AnalyticSolution.hpp"
12 #include "Utilities/TMPL.hpp"
13 #include "Utilities/TaggedTuple.hpp"
14
15 /// \cond
16 class DataVector;
17 // IWYU pragma: no_forward_declare Tensor
18 namespace PUP {
19 class er;
20 } // namespace PUP
21 /// \endcond
22
23 namespace ScalarWave {
24 namespace Solutions {
25 /*!
26  * \brief An exact solution to the semidiscretized DG ScalarWave
27  * system with an upwind flux
28  *
29  * This solution takes into account the spatial discretization error,
30  * and so should show convergence in time integration accuracy to
31  * roundoff at any resolution.
32  *
33  * \warning This is not really a pointwise function, as the solution
34  * depends on the spatial discretization. It will only work on a
35  * periodic domain of length \f$2 \pi\f$ (or an integer multiple) with
36  * equally sized linear elements.
37  */
38 class SemidiscretizedDg : public MarkAsAnalyticSolution {
39  public:
40  using tags = tmpl::list<ScalarWave::Pi, ScalarWave::Phi<1>, ScalarWave::Psi>;
41
42  struct Harmonic {
43  using type = int;
44  static constexpr Options::String help =
45  "Number of wave periods across the domain";
46  };
47
48  struct Amplitudes {
50  static constexpr Options::String help =
51  "Amplitudes of the independent modes of the harmonic";
52  };
53
54  using options = tmpl::list<Harmonic, Amplitudes>;
55
56  static constexpr Options::String help =
57  "A solution of the semidiscretized DG system on linear elements\n"
58  "with spatial period 2 pi.";
59
60  SemidiscretizedDg(int harmonic,
61  const std::array<double, 4>& amplitudes) noexcept;
62
63  SemidiscretizedDg() = default;
64
65  /// Retrieve the evolution variables at time t and spatial coordinates x
66  template <typename... Tags>
67  tuples::TaggedTuple<Tags...> variables(const tnsr::I<DataVector, 1>& x,
68  double t,
69  tmpl::list<Tags...> /*meta*/) const
70  noexcept {
71  static_assert(
72  tmpl2::flat_all_v<tmpl::list_contains_v<tags, Tags>...>,
73  "At least one of the requested tags is not supported. The requested "
74  "tags are listed as template parameters of the variables function.");
75  return {get<Tags>(variables(x, t, tmpl::list<Tags>{}))...};
76  }
77
78  /// \cond
80  const tnsr::I<DataVector, 1>& x, double t,
81  tmpl::list<ScalarWave::Pi> /*meta*/) const noexcept;
82
84  const tnsr::I<DataVector, 1>& x, double t,
85  tmpl::list<ScalarWave::Phi<1>> /*meta*/) const noexcept;
86
87  tuples::TaggedTuple<ScalarWave::Psi> variables(
88  const tnsr::I<DataVector, 1>& x, double t,
89  tmpl::list<ScalarWave::Psi> /*meta*/) const noexcept;
90  /// \endcond
91
92  void pup(PUP::er& p) noexcept; // NOLINT(google-runtime-references)
93
94  private:
95  int harmonic_;
96  std::array<double, 4> amplitudes_;
97 };
98 } // namespace Solutions
99 } // namespace ScalarWave
Options.hpp
ScalarWave::Phi
Definition: Tags.hpp:31
ScalarWave::Solutions::SemidiscretizedDg::variables
tuples::TaggedTuple< Tags... > variables(const tnsr::I< DataVector, 1 > &x, double t, tmpl::list< Tags... >) const noexcept
Retrieve the evolution variables at time t and spatial coordinates x
Definition: SemidiscretizedDg.hpp:67
Tags.hpp
tmpl2::flat_all_v
constexpr bool flat_all_v
A non-short-circuiting logical AND between bools 'B"".
Definition: TMPL.hpp:545
ScalarWave::Solutions::SemidiscretizedDg::Amplitudes
Definition: SemidiscretizedDg.hpp:48
ScalarWave::Solutions::SemidiscretizedDg::Harmonic
Definition: SemidiscretizedDg.hpp:42
array
tuples::TaggedTuple
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:271
DataVector
Stores a collection of function values.
Definition: DataVector.hpp:46
tnsr
Type aliases to construct common Tensors.
Definition: TypeAliases.hpp:31
ScalarWave::Solutions::SemidiscretizedDg
An exact solution to the semidiscretized DG ScalarWave system with an upwind flux.
Definition: SemidiscretizedDg.hpp:38
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
Tensor.hpp
ScalarWave
Items related to evolving the scalar wave equation.
Definition: BoundaryCondition.hpp:24
ScalarWave::Psi
Definition: Tags.hpp:20
TMPL.hpp