7 std::span<const double> pressure,
8 std::span<const double> velocity_gain)
noexcept
10 if (pressure.empty()) {
14 const size_t count = std::min({
velocity.size(), velocity_gain.size(), pressure.size() - 1 });
15 for (
size_t l = 0; l < count; ++l) {
16 velocity[l] -= velocity_gain[l] * (pressure[l + 1] - pressure[l]);
21 std::span<double> pressure,
23 std::span<const double> pressure_gain)
noexcept
25 const size_t end = std::min({ pressure.size(), pressure_gain.size(),
velocity.size() + 1 });
26 for (
size_t l = 1; l + 1 < end; ++l) {
32 std::span<const double> pressure,
33 std::span<const double> velocity_previous,
34 std::span<const double> velocity_current,
35 std::span<const double> pressure_gain,
36 std::span<const double> velocity_gain,
37 double time_step)
noexcept
39 double potential = 0.0;
40 const size_t points = std::min(pressure.size(), pressure_gain.size());
41 for (
size_t l = 0; l < points; ++l) {
42 if (pressure_gain[l] > 0.0) {
43 potential += pressure[l] * pressure[l] / pressure_gain[l];
48 const size_t sections = std::min({ velocity_previous.size(), velocity_current.size(), velocity_gain.size() });
49 for (
size_t l = 0; l < sections; ++l) {
50 if (velocity_gain[l] > 0.0) {
51 kinetic += velocity_previous[l] * velocity_current[l] / velocity_gain[l];
55 return 0.5 * time_step * (potential + kinetic);
60 if (pressure.empty()) {
63 if (pressure.size() == 1) {
64 return pressure.front();
67 const double x = std::clamp(position, 0.0, 1.0) *
static_cast<double>(pressure.size() - 1);
68 const auto index = std::min(
static_cast<size_t>(x), pressure.size() - 2);
69 const double fraction = x -
static_cast<double>(index);
70 return pressure[index] + fraction * (pressure[index + 1] - pressure[index]);
74 std::span<const double> source,
75 std::span<double> target,
76 double offset)
noexcept
79 std::ranges::fill(target, 0.0);
83 const double from_span =
static_cast<double>(source.size()) - 1.0 + 2.0 * offset;
84 const double to_span =
static_cast<double>(target.size()) - 1.0 + 2.0 * offset;
85 const double last =
static_cast<double>(source.size() - 1);
87 for (
size_t i = 0; i < target.size(); ++i) {
88 const double position = to_span > 0.0 ? (
static_cast<double>(i) + offset) / to_span : 0.0;
89 const double index = std::clamp(position * from_span - offset, 0.0, last);
90 const auto below =
static_cast<size_t>(index);
91 const size_t above = std::min(below + 1, source.size() - 1);
92 const double fraction = index -
static_cast<double>(below);
93 target[i] = source[below] + fraction * (source[above] - source[below]);
Interior propagation of a bore on its interleaved grid, with the discrete energy and a pickup.
void resample_line(std::span< const double > source, std::span< double > target, double offset) noexcept
Linearly interpolate a line of values onto another of a different size by relative position.
void advance_velocity(std::span< double > velocity, std::span< const double > pressure, std::span< const double > velocity_gain) noexcept
Advance the half step velocities from the pressure.
double sample_pressure(std::span< const double > pressure, double position) noexcept
Pressure at a position along the bore, linearly interpolated.
void advance_pressure(std::span< double > pressure, std::span< const double > velocity, std::span< const double > pressure_gain) noexcept
Advance the interior pressures from the new velocities.
double discrete_energy(std::span< const double > pressure, std::span< const double > velocity_previous, std::span< const double > velocity_current, std::span< const double > pressure_gain, std::span< const double > velocity_gain, double time_step) noexcept
Discrete energy of the bore in joules.
T velocity(const Memory::HistoryBuffer< T > &history, double dt) noexcept
First difference: rate of change of position.