/
BondiHoyleAccretion.cpp
255 lines (221 loc) · 10.1 KB
/
BondiHoyleAccretion.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
// Distributed under the MIT License.
// See LICENSE.txt for details.
#include "PointwiseFunctions/AnalyticData/GrMhd/BondiHoyleAccretion.hpp"
#include <cmath>
#include <pup.h>
#include "DataStructures/DataBox/DataBoxTag.hpp"
#include "DataStructures/DataVector.hpp" // IWYU pragma: keep
#include "DataStructures/Tensor/Tensor.hpp" // IWYU pragma: keep
#include "PointwiseFunctions/Hydro/EquationsOfState/EquationOfState.hpp"
#include "PointwiseFunctions/Hydro/EquationsOfState/PolytropicFluid.hpp" // IWYU pragma: keep
#include "Utilities/ConstantExpressions.hpp"
#include "Utilities/GenerateInstantiations.hpp"
#include "Utilities/MakeWithValue.hpp"
// IWYU pragma: no_include "DataStructures/Tensor/TypeAliases.hpp"
/// \cond
namespace grmhd {
namespace AnalyticData {
BondiHoyleAccretion::BondiHoyleAccretion(
const double bh_mass, const double bh_dimless_spin,
const double rest_mass_density, const double flow_speed,
const double magnetic_field_strength, const double polytropic_constant,
const double polytropic_exponent) noexcept
: bh_mass_(bh_mass),
bh_spin_a_(bh_mass * bh_dimless_spin),
rest_mass_density_(rest_mass_density),
flow_speed_(flow_speed),
magnetic_field_strength_(magnetic_field_strength),
polytropic_constant_(polytropic_constant),
polytropic_exponent_(polytropic_exponent),
equation_of_state_{polytropic_constant_, polytropic_exponent_},
background_spacetime_{
bh_mass, {{0.0, 0.0, bh_dimless_spin}}, {{0.0, 0.0, 0.0}}},
kerr_schild_coords_{bh_mass, bh_dimless_spin} {}
void BondiHoyleAccretion::pup(PUP::er& p) noexcept {
p | bh_mass_;
p | bh_spin_a_;
p | rest_mass_density_;
p | flow_speed_;
p | magnetic_field_strength_;
p | polytropic_constant_;
p | polytropic_exponent_;
p | equation_of_state_;
p | background_spacetime_;
p | kerr_schild_coords_;
}
template <typename DataType>
typename hydro::Tags::SpatialVelocity<DataType, 3, Frame::NoFrame>::type
BondiHoyleAccretion::spatial_velocity(const DataType& r_squared,
const DataType& cos_theta,
const DataType& sin_theta) const
noexcept {
auto result = make_with_value<
typename hydro::Tags::SpatialVelocity<DataType, 3, Frame::NoFrame>::type>(
r_squared, 0.0);
const DataType sigma = r_squared + square(bh_spin_a_) * square(cos_theta);
get<0>(result) = flow_speed_ * cos_theta /
sqrt(1.0 + 2.0 * bh_mass_ * sqrt(r_squared) / sigma);
get<1>(result) = -flow_speed_ * sin_theta / sqrt(sigma);
// get<2>(result) is identically zero
return result;
}
template <typename DataType>
typename hydro::Tags::MagneticField<DataType, 3, Frame::NoFrame>::type
BondiHoyleAccretion::magnetic_field(const DataType& r_squared,
const DataType& cos_theta,
const DataType& sin_theta) const noexcept {
const double a_squared = bh_spin_a_ * bh_spin_a_;
const DataType cos_theta_squared = square(cos_theta);
const DataType two_m_r = 2.0 * bh_mass_ * sqrt(r_squared);
// The square root of the determinant of the spatial metric is proportional to
// sin(theta) squared. That factor cancels out after multiplying by Faraday.
DataType sigma = r_squared + a_squared * cos_theta_squared;
const DataType prefactor =
magnetic_field_strength_ / sqrt(sigma * (sigma + two_m_r));
auto result = make_with_value<
typename hydro::Tags::MagneticField<DataType, 3, Frame::NoFrame>::type>(
r_squared, 0.0);
// Redefine sigma to save an allocation.
sigma = 1.0 / square(sigma);
get<0>(result) = prefactor *
(r_squared - two_m_r + a_squared +
sigma * two_m_r * (square(r_squared) - square(a_squared))) *
cos_theta;
get<1>(result) = -prefactor *
(sqrt(r_squared) +
bh_mass_ * a_squared * sigma *
(r_squared - a_squared * cos_theta_squared) *
(1.0 + cos_theta_squared)) *
sin_theta;
get<2>(result) = bh_spin_a_ * prefactor *
(1.0 + sigma * two_m_r * (r_squared - a_squared)) *
cos_theta;
return result;
}
template <typename DataType>
tuples::TaggedTuple<hydro::Tags::RestMassDensity<DataType>>
BondiHoyleAccretion::variables(
const tnsr::I<DataType, 3, Frame::Inertial>& x,
tmpl::list<hydro::Tags::RestMassDensity<DataType>> /*meta*/) const
noexcept {
return {
make_with_value<db::item_type<hydro::Tags::RestMassDensity<DataType>>>(
x, rest_mass_density_)};
}
template <typename DataType>
tuples::TaggedTuple<hydro::Tags::SpatialVelocity<DataType, 3>>
BondiHoyleAccretion::variables(
const tnsr::I<DataType, 3, Frame::Inertial>& x,
tmpl::list<hydro::Tags::SpatialVelocity<DataType, 3>> /*meta*/) const
noexcept {
const DataType r_squared = get(kerr_schild_coords_.r_coord_squared(x));
return kerr_schild_coords_.cartesian_from_spherical_ks(
spatial_velocity(r_squared, DataType{get<2>(x) / sqrt(r_squared)},
DataType{sqrt((square(get<0>(x)) + square(get<1>(x))) /
(r_squared + square(bh_spin_a_)))}),
x);
}
template <typename DataType>
tuples::TaggedTuple<hydro::Tags::SpecificInternalEnergy<DataType>>
BondiHoyleAccretion::variables(
const tnsr::I<DataType, 3, Frame::Inertial>& x,
tmpl::list<hydro::Tags::SpecificInternalEnergy<DataType>> /*meta*/) const
noexcept {
return equation_of_state_.specific_internal_energy_from_density(
get<hydro::Tags::RestMassDensity<DataType>>(
variables(x, tmpl::list<hydro::Tags::RestMassDensity<DataType>>{})));
}
template <typename DataType>
tuples::TaggedTuple<hydro::Tags::Pressure<DataType>>
BondiHoyleAccretion::variables(
const tnsr::I<DataType, 3, Frame::Inertial>& x,
tmpl::list<hydro::Tags::Pressure<DataType>> /*meta*/) const noexcept {
return equation_of_state_.pressure_from_density(
get<hydro::Tags::RestMassDensity<DataType>>(
variables(x, tmpl::list<hydro::Tags::RestMassDensity<DataType>>{})));
}
template <typename DataType>
tuples::TaggedTuple<hydro::Tags::MagneticField<DataType, 3>>
BondiHoyleAccretion::variables(
const tnsr::I<DataType, 3, Frame::Inertial>& x,
tmpl::list<hydro::Tags::MagneticField<DataType, 3>> /*meta*/) const
noexcept {
const DataType r_squared = get(kerr_schild_coords_.r_coord_squared(x));
return kerr_schild_coords_.cartesian_from_spherical_ks(
magnetic_field(r_squared, DataType{get<2>(x) / sqrt(r_squared)},
DataType{sqrt((square(get<0>(x)) + square(get<1>(x))) /
(r_squared + square(bh_spin_a_)))}),
x);
}
template <typename DataType>
tuples::TaggedTuple<hydro::Tags::DivergenceCleaningField<DataType>>
BondiHoyleAccretion::variables(
const tnsr::I<DataType, 3, Frame::Inertial>& x,
tmpl::list<hydro::Tags::DivergenceCleaningField<DataType>> /*meta*/) const
noexcept {
return {make_with_value<
db::item_type<hydro::Tags::DivergenceCleaningField<DataType>>>(x, 0.0)};
}
template <typename DataType>
tuples::TaggedTuple<hydro::Tags::LorentzFactor<DataType>>
BondiHoyleAccretion::variables(
const tnsr::I<DataType, 3, Frame::Inertial>& x,
tmpl::list<hydro::Tags::LorentzFactor<DataType>> /*meta*/) const noexcept {
return {make_with_value<db::item_type<hydro::Tags::LorentzFactor<DataType>>>(
x, 1.0 / sqrt(1.0 - square(flow_speed_)))};
}
template <typename DataType>
tuples::TaggedTuple<hydro::Tags::SpecificEnthalpy<DataType>>
BondiHoyleAccretion::variables(
const tnsr::I<DataType, 3, Frame::Inertial>& x,
tmpl::list<hydro::Tags::SpecificEnthalpy<DataType>> /*meta*/) const
noexcept {
return equation_of_state_.specific_enthalpy_from_density(
get<hydro::Tags::RestMassDensity<DataType>>(
variables(x, tmpl::list<hydro::Tags::RestMassDensity<DataType>>{})));
}
bool operator==(const BondiHoyleAccretion& lhs,
const BondiHoyleAccretion& rhs) noexcept {
// There is no comparison operator for the `equation_of_state` and the
// `background_spacetime`, but should be okay as the `bh_mass`s,
// `bh_dimless_spin`s, `polytropic_exponent`s and `polytropic_constant`s are
// compared.
return lhs.bh_mass_ == rhs.bh_mass_ and lhs.bh_spin_a_ == rhs.bh_spin_a_ and
lhs.rest_mass_density_ == rhs.rest_mass_density_ and
lhs.flow_speed_ == rhs.flow_speed_ and
lhs.magnetic_field_strength_ == rhs.magnetic_field_strength_ and
lhs.polytropic_constant_ == rhs.polytropic_constant_ and
lhs.polytropic_exponent_ == rhs.polytropic_exponent_;
}
bool operator!=(const BondiHoyleAccretion& lhs,
const BondiHoyleAccretion& rhs) noexcept {
return not(lhs == rhs);
}
#define DTYPE(data) BOOST_PP_TUPLE_ELEM(0, data)
#define TAG(data) BOOST_PP_TUPLE_ELEM(1, data)
#define INSTANTIATE_SCALARS(_, data) \
template tuples::TaggedTuple<TAG(data) < DTYPE(data)>> \
BondiHoyleAccretion::variables( \
const tnsr::I<DTYPE(data), 3, Frame::Inertial>& x, \
tmpl::list<TAG(data) < DTYPE(data)>> /*meta*/) const noexcept;
GENERATE_INSTANTIATIONS(
INSTANTIATE_SCALARS, (double, DataVector),
(hydro::Tags::RestMassDensity, hydro::Tags::SpecificInternalEnergy,
hydro::Tags::Pressure, hydro::Tags::DivergenceCleaningField,
hydro::Tags::LorentzFactor, hydro::Tags::SpecificEnthalpy))
#define INSTANTIATE_VECTORS(_, data) \
template tuples::TaggedTuple<TAG(data) < DTYPE(data), 3>> \
BondiHoyleAccretion::variables( \
const tnsr::I<DTYPE(data), 3, Frame::Inertial>& x, \
tmpl::list<TAG(data) < DTYPE(data), 3, Frame::Inertial>> /*meta*/) \
const noexcept;
GENERATE_INSTANTIATIONS(INSTANTIATE_VECTORS, (double, DataVector),
(hydro::Tags::SpatialVelocity,
hydro::Tags::MagneticField))
#undef DTYPE
#undef TAG
#undef INSTANTIATE_SCALARS
#undef INSTANTIATE_VECTORS
} // namespace AnalyticData
} // namespace grmhd
/// \endcond