DirichletAnalytic.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <memory>
7 #include <optional>
8 #include <pup.h>
9 #include <string>
10 #include <type_traits>
11 
13 #include "DataStructures/DataVector.hpp"
16 #include "Evolution/BoundaryConditions/Type.hpp"
17 #include "Evolution/Systems/GeneralizedHarmonic/BoundaryConditions/BoundaryCondition.hpp"
18 #include "Evolution/Systems/GeneralizedHarmonic/ConstraintDamping/Tags.hpp"
19 #include "Evolution/Systems/GeneralizedHarmonic/Tags.hpp"
20 #include "Options/Options.hpp"
22 #include "PointwiseFunctions/AnalyticData/Tags.hpp"
23 #include "PointwiseFunctions/AnalyticSolutions/AnalyticSolution.hpp"
24 #include "PointwiseFunctions/GeneralRelativity/Tags.hpp"
25 #include "Time/Tags.hpp"
26 #include "Utilities/Gsl.hpp"
27 #include "Utilities/TMPL.hpp"
28 
29 /// \cond
30 namespace domain::Tags {
31 template <size_t Dim, typename Frame>
32 struct Coordinates;
33 } // namespace domain::Tags
34 /// \endcond
35 
37 /*!
38  * \brief Sets Dirichlet boundary conditions using the analytic solution or
39  * analytic data.
40  */
41 template <size_t Dim>
42 class DirichletAnalytic final : public BoundaryCondition<Dim> {
43  public:
44  using options = tmpl::list<>;
45  static constexpr Options::String help{
46  "DirichletAnalytic boundary conditions setting the value of the "
47  "spacetime metric and its derivatives Phi and Pi to the analytic "
48  "solution or analytic data."};
49 
50  DirichletAnalytic() = default;
51  DirichletAnalytic(DirichletAnalytic&&) noexcept = default;
52  DirichletAnalytic& operator=(DirichletAnalytic&&) noexcept = default;
53  DirichletAnalytic(const DirichletAnalytic&) = default;
54  DirichletAnalytic& operator=(const DirichletAnalytic&) = default;
55  ~DirichletAnalytic() override = default;
56 
57  explicit DirichletAnalytic(CkMigrateMessage* msg) noexcept;
58 
59  WRAPPED_PUPable_decl_base_template(
61 
62  auto get_clone() const noexcept -> std::unique_ptr<
64 
65  static constexpr evolution::BoundaryConditions::Type bc_type =
66  evolution::BoundaryConditions::Type::Ghost;
67 
68  void pup(PUP::er& p) override;
69 
70  using dg_interior_evolved_variables_tags = tmpl::list<>;
71  using dg_interior_temporary_tags = tmpl::list<
75  using dg_gridless_tags =
76  tmpl::list<::Tags::Time, ::Tags::AnalyticSolutionOrData>;
77 
78  template <typename AnalyticSolutionOrData>
80  const gsl::not_null<tnsr::aa<DataVector, Dim, Frame::Inertial>*>
82  const gsl::not_null<tnsr::aa<DataVector, Dim, Frame::Inertial>*> pi,
83  const gsl::not_null<tnsr::iaa<DataVector, Dim, Frame::Inertial>*> phi,
84  const gsl::not_null<Scalar<DataVector>*> gamma1,
85  const gsl::not_null<Scalar<DataVector>*> gamma2,
87  const gsl::not_null<tnsr::I<DataVector, Dim, Frame::Inertial>*> shift,
88  const gsl::not_null<tnsr::II<DataVector, Dim, Frame::Inertial>*>
89  inv_spatial_metric,
90  const std::optional<
91  tnsr::I<DataVector, Dim, Frame::Inertial>>& /*face_mesh_velocity*/,
92  const tnsr::i<DataVector, Dim, Frame::Inertial>& /*normal_covector*/,
93  const tnsr::I<DataVector, Dim, Frame::Inertial>& /*normal_vector*/,
94  const tnsr::I<DataVector, Dim, Frame::Inertial>& coords,
95  const Scalar<DataVector>& interior_gamma1,
96  const Scalar<DataVector>& interior_gamma2, const double time,
97  const AnalyticSolutionOrData& analytic_solution_or_data) const noexcept {
98  *gamma1 = interior_gamma1;
99  *gamma2 = interior_gamma2;
100  auto boundary_values = [&analytic_solution_or_data, &coords,
101  &time]() noexcept {
102  if constexpr (std::is_base_of_v<MarkAsAnalyticSolution,
103  AnalyticSolutionOrData>) {
104  return analytic_solution_or_data.variables(
105  coords, time,
106  tmpl::list<
110 
111  } else {
112  (void)time;
113  return analytic_solution_or_data.variables(
114  coords,
115  tmpl::list<
119  }
120  }();
121 
123  get<gr::Tags::SpacetimeMetric<Dim, Frame::Inertial, DataVector>>(
124  boundary_values);
125  *pi = get<GeneralizedHarmonic::Tags::Pi<Dim, Frame::Inertial>>(
126  boundary_values);
127  *phi = get<GeneralizedHarmonic::Tags::Phi<Dim, Frame::Inertial>>(
128  boundary_values);
129 
130  // Now compute lapse and shift...
131  lapse_shift_and_inv_spatial_metric(lapse, shift, inv_spatial_metric,
133  return {};
134  }
135 
136  private:
137  void lapse_shift_and_inv_spatial_metric(
139  gsl::not_null<tnsr::I<DataVector, Dim, Frame::Inertial>*> shift,
140  gsl::not_null<tnsr::II<DataVector, Dim, Frame::Inertial>*>
141  inv_spatial_metric,
142  const tnsr::aa<DataVector, Dim, Frame::Inertial>& spacetime_metric)
143  const noexcept;
144 };
145 } // namespace GeneralizedHarmonic::BoundaryConditions
GeneralizedHarmonic::pi
void pi(gsl::not_null< tnsr::aa< DataType, SpatialDim, Frame > * > pi, const Scalar< DataType > &lapse, const Scalar< DataType > &dt_lapse, const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::I< DataType, SpatialDim, Frame > &dt_shift, const tnsr::ii< DataType, SpatialDim, Frame > &spatial_metric, const tnsr::ii< DataType, SpatialDim, Frame > &dt_spatial_metric, const tnsr::iaa< DataType, SpatialDim, Frame > &phi) noexcept
Computes the conjugate momentum of the spacetime metric .
CharmPupable.hpp
domain::BoundaryConditions::BoundaryCondition
Base class from which all system-specific base classes must inherit.
Definition: BoundaryCondition.hpp:18
domain::Tags::Coordinates< Dim, Frame::Inertial >
Options.hpp
GeneralizedHarmonic::BoundaryConditions
Boundary conditions for the generalized harmonic system.
Definition: Bjorhus.hpp:38
gr::lapse
Scalar< DataType > lapse(const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::aa< DataType, SpatialDim, Frame > &spacetime_metric) noexcept
Compute lapse from shift and spacetime metric.
GeneralizedHarmonic::Tags::Pi
Conjugate momentum to the spacetime metric.
Definition: Tags.hpp:29
gr::Tags::SpacetimeMetric
Definition: Tags.hpp:17
GeneralizedHarmonic::phi
void phi(gsl::not_null< tnsr::iaa< DataType, SpatialDim, Frame > * > phi, const Scalar< DataType > &lapse, const tnsr::i< DataType, SpatialDim, Frame > &deriv_lapse, const tnsr::I< DataType, SpatialDim, Frame > &shift, const tnsr::iJ< DataType, SpatialDim, Frame > &deriv_shift, const tnsr::ii< DataType, SpatialDim, Frame > &spatial_metric, const tnsr::ijj< DataType, SpatialDim, Frame > &deriv_spatial_metric) noexcept
Computes the auxiliary variable used by the generalized harmonic formulation of Einstein's equations...
memory
GeneralizedHarmonic::ConstraintDamping::Tags::ConstraintGamma2
Constraint dammping parameter for the generalized harmonic system (cf. ).
Definition: Tags.hpp:70
Variables.hpp
gr::shift
tnsr::I< DataType, SpatialDim, Frame > shift(const tnsr::aa< DataType, SpatialDim, Frame > &spacetime_metric, const tnsr::II< DataType, SpatialDim, Frame > &inverse_spatial_metric) noexcept
Compute shift from spacetime metric and inverse spatial metric.
GeneralizedHarmonic::Tags::Phi
Auxiliary variable which is analytically the spatial derivative of the spacetime metric.
Definition: Tags.hpp:40
Scalar
Tensor< T, Symmetry<>, index_list<> > Scalar
Definition: TypeAliases.hpp:21
Gsl.hpp
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
GeneralizedHarmonic::BoundaryConditions::DirichletAnalytic
Sets Dirichlet boundary conditions using the analytic solution or analytic data.
Definition: DirichletAnalytic.hpp:42
gr::spacetime_metric
void spacetime_metric(gsl::not_null< tnsr::aa< DataType, Dim, Frame > * > spacetime_metric, const Scalar< DataType > &lapse, const tnsr::I< DataType, Dim, Frame > &shift, const tnsr::ii< DataType, Dim, Frame > &spatial_metric) noexcept
Computes the spacetime metric from the spatial metric, lapse, and shift.
Tensor.hpp
GeneralizedHarmonic::BoundaryConditions::BoundaryCondition
The base class off of which all boundary conditions must inherit.
Definition: BoundaryCondition.hpp:27
optional
GeneralizedHarmonic::ConstraintDamping::Tags::ConstraintGamma1
Constraint dammping parameter for the generalized harmonic system (cf. ).
Definition: Tags.hpp:62
std::unique_ptr
Prefixes.hpp
type_traits
TMPL.hpp
domain::Tags
Tags for the domain.
Definition: FaceNormal.hpp:107
gsl::not_null
Require a pointer to not be a nullptr
Definition: ReadSpecPiecewisePolynomial.hpp:13
string