Moustache.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 
8 #include "DataStructures/DataBox/Prefixes.hpp" // IWYU pragma: keep
9 #include "DataStructures/Tensor/Tensor.hpp" // IWYU pragma: keep
10 #include "Elliptic/Systems/Poisson/Tags.hpp" // IWYU pragma: keep
11 #include "Options/Options.hpp"
12 #include "Utilities/TMPL.hpp"
14 
15 /// \cond
16 class DataVector;
17 namespace PUP {
18 class er;
19 } // namespace PUP
20 /// \endcond
21 
22 namespace Poisson {
23 namespace Solutions {
24 
25 /*!
26  * \brief A solution to the Poisson equation with a discontinuous first
27  * derivative.
28  *
29  * \details This implements the solution \f$u(x,y)=x\left(1-x\right)
30  * y\left(1-y\right)\left(\left(x-\frac{1}{2}\right)^2+\left(y-
31  * \frac{1}{2}\right)^2\right)^\frac{3}{2}\f$ to the Poisson equation
32  * in two dimensions, and
33  * \f$u(x)=x\left(1-x\right)\left|x-\frac{1}{2}\right|^3\f$ in one dimension.
34  * Their boundary conditions vanish on the square \f$[0,1]^2\f$ or interval
35  * \f$[0,1]\f$, respectively.
36  *
37  * The corresponding source \f$f=-\Delta u\f$ has a discontinuous first
38  * derivative at \f$\frac{1}{2}\f$. This accomplishes two things:
39  *
40  * - It makes it useful to test the convergence behaviour of our elliptic DG
41  * solver.
42  * - It makes it look like a moustache (at least in 1D).
43  *
44  * This solution is taken from \cite Stamm2010.
45  */
46 template <size_t Dim>
47 class Moustache {
48  public:
49  using options = tmpl::list<>;
50  static constexpr OptionString help{
51  "A solution with a discontinuous first derivative of its source at 1/2 "
52  "that also happens to look like a moustache. It vanishes at zero and one "
53  "in each dimension"};
54 
55  Moustache() = default;
56  Moustache(const Moustache&) noexcept = delete;
57  Moustache& operator=(const Moustache&) noexcept = delete;
58  Moustache(Moustache&&) noexcept = default;
59  Moustache& operator=(Moustache&&) noexcept = default;
60  ~Moustache() noexcept = default;
61 
62  // @{
63  /// Retrieve variable at coordinates `x`
64  auto variables(const tnsr::I<DataVector, Dim, Frame::Inertial>& x,
65  tmpl::list<Field> /*meta*/) const noexcept
67 
68  auto variables(const tnsr::I<DataVector, Dim, Frame::Inertial>& x,
69  tmpl::list<AuxiliaryField<Dim>> /*meta*/) const noexcept
71 
72  auto variables(const tnsr::I<DataVector, Dim, Frame::Inertial>& x,
73  tmpl::list<::Tags::Source<Field>> /*meta*/) const noexcept
75 
76  auto variables(const tnsr::I<DataVector, Dim, Frame::Inertial>& x,
77  tmpl::list<::Tags::Source<AuxiliaryField<Dim>>> /*meta*/) const
79  // @}
80 
81  /// Retrieve a collection of variables at coordinates `x`
82  template <typename... Tags>
84  const tnsr::I<DataVector, Dim, Frame::Inertial>& x,
85  tmpl::list<Tags...> /*meta*/) const noexcept {
86  static_assert(sizeof...(Tags) > 1,
87  "The generic template will recurse infinitely if only one "
88  "tag is being retrieved.");
89  return {tuples::get<Tags>(variables(x, tmpl::list<Tags>{}))...};
90  }
91 
92  // clang-tidy: no pass by reference
93  void pup(PUP::er& p) noexcept; // NOLINT
94 };
95 
96 template <size_t Dim>
97 constexpr bool operator==(const Moustache<Dim>& /*lhs*/,
98  const Moustache<Dim>& /*rhs*/) noexcept {
99  return true;
100 }
101 
102 template <size_t Dim>
103 constexpr bool operator!=(const Moustache<Dim>& lhs,
104  const Moustache<Dim>& rhs) noexcept {
105  return not(lhs == rhs);
106 }
107 
108 } // namespace Solutions
109 } // namespace Poisson
Prefix indicating a source term.
Definition: Prefixes.hpp:66
Definition: Strahlkorper.hpp:14
Defines class tuples::TaggedTuple.
The auxiliary field to formulate the first-order Poisson equation .
Definition: Tags.hpp:37
tuples::TaggedTuple< Tags... > variables(const tnsr::I< DataVector, Dim, Frame::Inertial > &x, tmpl::list< Tags... >) const noexcept
Retrieve a collection of variables at coordinates x
Definition: Moustache.hpp:83
Defines classes and functions for making classes creatable from input files.
Items related to solving a Poisson equation .
Definition: Actions.hpp:6
Define prefixes for DataBox tags.
const char *const OptionString
The string used in option structs.
Definition: Options.hpp:26
An associative container that is indexed by structs.
Definition: TaggedTuple.hpp:272
Defines DataBox tags for the Poisson system.
Definition: DataBoxTag.hpp:29
Defines classes for Tensor.
Stores a collection of function values.
Definition: DataVector.hpp:46
Wraps the template metaprogramming library used (brigand)
A solution to the Poisson equation with a discontinuous first derivative.
Definition: Moustache.hpp:47