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

◆ discrete_energy()

MAYAFLUX_API double MayaFlux::Kinesis::Acoustics::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 )
nodiscardnoexcept

Discrete energy of the bore in joules.

Parameters
pressureN + 1 pressures at step n
velocity_previousN velocities at step n - 1/2
velocity_currentN velocities at step n + 1/2
pressure_gainN + 1 gains from DuctGrid
velocity_gainN gains from DuctGrid
time_stepTime step in seconds

The sum of cell compliance times pressure squared and section inertance times the product of the velocities at the two time levels, each halved. With sealed ends it is constant to rounding from sample to sample, and with lossy ends it only falls. It is not negative while the Courant number is at most one.

Definition at line 31 of file StaggeredLine.cpp.

38{
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];
44 }
45 }
46
47 double kinetic = 0.0;
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];
52 }
53 }
54
55 return 0.5 * time_step * (potential + kinetic);
56}