MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ reed_mouth_step()

MAYAFLUX_API std::tuple< double, double, double, RootStatus > MayaFlux::Kinesis::Acoustics::reed_mouth_step ( const ReedChannel & reed,
double & warm_start,
double end_pressure_gain,
double mouth_pressure,
double end_pressure,
double downstream_flow )
nodiscardnoexcept

Couple the reed to the first cell of the bore for one sample.

Parameters
reedChannel
warm_startRoot of |d| from the previous sample, updated here; start it at zero. The search begins at the end of its bracket from which Newton steps approach the root monotonically, which is every case but a root straddling the inflection of the equation, where it begins here.
end_pressure_gainGain of the first pressure point from DuctGrid
mouth_pressureBlowing pressure at the half step
end_pressurePressure of the first point at the start of the sample
downstream_flowVolume velocity of the first half section, from the same sample
Returns
The first point's pressure after the sample, the flow into the bore at the half step, the pressure difference across the reed, and how the search ended

A reed shut by the mouth pressure acts as a wall. A channel with a field that is not positive and finite does the same and reports NOT_FINITE. The result is the one solution only while reed_coupling_is_unique holds for the coupling gain, flow_coupling_gain of end_pressure_gain.

Definition at line 43 of file Reed.cpp.

50{
51 const double gain = flow_coupling_gain(end_pressure_gain);
52 const double target = flow_coupling_target(mouth_pressure, end_pressure, gain, downstream_flow);
53
54 const auto wall = [&](RootStatus status) -> std::tuple<double, double, double, RootStatus> {
55 warm_start = 0.0;
56 return { centred_end_pressure(mouth_pressure, target, end_pressure), 0.0, target, status };
57 };
58
59 if (!channel_valid(reed) || !std::isfinite(target) || !positive_finite(gain)) {
60 return wall(RootStatus::NOT_FINITE);
61 }
62
63 const double closing = reed.closing_pressure;
64 if (target >= closing) {
65 return wall(RootStatus::CONVERGED);
66 }
67
68 const double magnitude = std::abs(target);
69 if (magnitude == 0.0) {
70 warm_start = 0.0;
71 return { centred_end_pressure(mouth_pressure, 0.0, end_pressure), 0.0, 0.0, RootStatus::CONVERGED };
72 }
73
74 const double sign = target > 0.0 ? 1.0 : -1.0;
75 const double a = gain * reed_flow_coefficient(reed);
76 const double plain_root = 2.0 * magnitude / (a + std::sqrt(a * a + 4.0 * magnitude));
77
78 const double lower = sign > 0.0 ? plain_root : 0.0;
79 const double upper = sign > 0.0 ? std::sqrt(magnitude) : plain_root;
80
81 const auto equation = [&](double s) -> RootSample {
82 const double cubic = a * s * s * s / closing;
83 return {
84 s * s + a * s - sign * cubic - magnitude,
85 2.0 * s + a - 3.0 * sign * a * s * s / closing
86 };
87 };
88
89 const double inflection = closing / (3.0 * a);
90 double start = warm_start;
91 if (sign < 0.0 || upper <= inflection) {
92 start = upper;
93 } else if (lower >= inflection) {
94 start = lower;
95 }
96
97 RootOptions options;
98 options.check_bracket = false;
99 const auto [root, status] = bracketed_newton(equation, lower, upper, start, options);
100 warm_start = root;
101
102 const double difference = sign * root * root;
103 return {
104 centred_end_pressure(mouth_pressure, difference, end_pressure),
105 reed_flow(reed, difference),
106 difference,
107 status
108 };
109}
constexpr double centred_end_pressure(double driving_pressure, double pressure_difference, double end_pressure) noexcept
Pressure of the end cell after the step, once the difference is solved.
constexpr double flow_coupling_target(double driving_pressure, double end_pressure, double gain, double downstream_flow) noexcept
Right side of the coupling equation.
double reed_flow_coefficient(const ReedChannel &reed) noexcept
w H sqrt(2 / rho), the flow per unit of (1 - d / pM) sign(d) sqrt|d|.
Definition Reed.cpp:20
constexpr double flow_coupling_gain(double end_pressure_gain) noexcept
Gain of a time centred coupling at an end cell.
double reed_flow(const ReedChannel &reed, double difference) noexcept
Volume velocity through the channel for a pressure difference.
Definition Reed.cpp:25
RootStatus
How a root search ended.
RootResult bracketed_newton(Function function, double lower, double upper, double guess, const RootOptions &options={})
Root of an increasing function by Newton steps kept inside a bracket.
std::pair< double, double > RootSample
Value and slope of a function at one point.

References MayaFlux::Kinesis::bracketed_newton(), centred_end_pressure(), MayaFlux::Kinesis::RootOptions::check_bracket, MayaFlux::Kinesis::CONVERGED, flow_coupling_gain(), flow_coupling_target(), MayaFlux::Kinesis::NOT_FINITE, reed_flow(), and reed_flow_coefficient().

Here is the call graph for this function: