Couple the reed to the first cell of the bore for one sample.
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.
50{
53
54 const auto wall = [&](
RootStatus status) -> std::tuple<double, double, double, RootStatus> {
55 warm_start = 0.0;
57 };
58
59 if (!channel_valid(reed) || !std::isfinite(target) || !positive_finite(gain)) {
61 }
62
64 if (target >= closing) {
66 }
67
68 const double magnitude = std::abs(target);
69 if (magnitude == 0.0) {
70 warm_start = 0.0;
72 }
73
74 const double sign = target > 0.0 ? 1.0 : -1.0;
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 {
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|.
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.
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.