7 constexpr double air_viscosity = 1.84e-5;
8 constexpr double heat_capacity_ratio = 1.4;
9 constexpr double prandtl_number = 0.71;
11 [[nodiscard]]
bool positive_finite(
double value)
noexcept
13 return std::isfinite(value) && value > 0.0;
16 [[nodiscard]]
bool not_negative_finite(
double value)
noexcept
18 return std::isfinite(value) && value >= 0.0;
25 if (!positive_finite(radius) || !positive_finite(frequency)
26 || !positive_finite(sound_speed) || !positive_finite(air_density)) {
30 const double omega = 2.0 * std::numbers::pi * frequency;
31 const double thermal = (heat_capacity_ratio - 1.0) / std::sqrt(prandtl_number);
32 return std::sqrt(omega * air_viscosity / (2.0 * air_density)) * (1.0 + thermal) / (radius * sound_speed);
36 double radius,
double sound_speed,
double air_density,
double low_frequency,
double high_frequency)
noexcept
38 if (!positive_finite(low_frequency) || !positive_finite(high_frequency) || !(low_frequency < high_frequency)) {
44 if (!(low > 0.0) || !(high > 0.0)) {
48 const double slope = (high - low) / (high_frequency * high_frequency - low_frequency * low_frequency);
49 const double flat = low - slope * low_frequency * low_frequency;
51 const double two_pi = 2.0 * std::numbers::pi;
52 const double friction = 2.0 * sound_speed * std::max(flat, 0.0);
53 const double viscosity = slope * 2.0 * sound_speed * sound_speed * sound_speed / (two_pi * two_pi);
54 return { friction, viscosity };
73 for (
size_t l = 0; l < n; ++l) {
76 for (
size_t l = 0; l + 1 < n; ++l) {
80 const double ghost_left = 2.0 *
m_edge.front();
81 const double ghost_right = 2.0 *
m_edge.back();
83 double upper_before = 0.0;
84 for (
size_t l = 0; l < n; ++l) {
85 const double left = l > 0 ?
m_edge[l - 1] : ghost_left;
86 const double right = l + 1 < n ?
m_edge[l] : ghost_right;
87 const double diagonal =
m_mass[l] * (1.0 + k *
friction) + left + right;
89 const double pivot = diagonal - (l > 0 ? left * upper_before : 0.0);
103 const size_t n =
m_mass.size();
109 for (
size_t l = 1; l < n; ++l) {
112 for (
size_t l = n - 1; l > 0; --l) {
Wall losses of a duct as friction and viscosity on the volume velocity.
std::vector< double > m_edge
double friction() const noexcept
double viscosity() const noexcept
std::vector< double > m_inverse_pivot
std::vector< double > m_mass
bool configure(const DuctGrid &grid, double friction, double viscosity)
Factor the loss for a grid.
std::vector< double > m_upper
void apply(std::span< double > velocity) const noexcept
Apply the loss to the velocities of a sample, in place.
double viscothermal_attenuation(double radius, double frequency, double sound_speed, double air_density) noexcept
Plane wave attenuation of a circular tube from its wall boundary layers.
std::pair< double, double > viscothermal_rates(double radius, double sound_speed, double air_density, double low_frequency, double high_frequency) noexcept
Friction and viscosity that match the tube's attenuation at two frequencies.
T velocity(const Memory::HistoryBuffer< T > &history, double dt) noexcept
First difference: rate of change of position.
std::vector< double > velocity_gain
Prepared grid and update gains of one bore.