Engineering
Hydraulic motor
Feed a fixed-displacement motor from a 150 bar line through an inlet orifice and let it drain through another: free, it settles where the two throttles and friction use up the supply pressure, the closed-form speed of that balance. Load the brake and read the pressure difference climb as D dp / 2 pi meets brake plus friction; load it past the supply’s torque and it stalls. Drive the shaft from outside and the machine turns into a pump, lifting the outlet above the inlet; drive it faster than the inlet can feed and the inlet line drains to vapour pressure, the shortfall booked as cavitation. Supply and external work are booked against the throttling, the leaks, the heat and the stored energy.

What happens
A gear motor of 50 cm³ per turn sits between an inlet line fed from a 150 bar supply through an orifice and an outlet line draining through another. The chambers pass D·ω/2π, the ideal torque is D·Δp/2π, cross-port and case leaks bleed the lines, Coulomb friction keeps a stick state, a brake and an external torque load the shaft. A symplectic sub-step of 20 µs takes the chamber flow at the mid-step speed and the torque at the mid-step pressures, so the hydraulic and mechanical ledgers meet exactly; when an overrunning load asks for more than the inlet orifice can feed, the inlet line drains to vapour pressure and the shortfall is booked as cavitation.
Try this
Let the motor run free and compare with the closed-form speed; load the brake until it stalls; then drive the shaft from outside and watch it become a pump, and harder until the inlet cavitates.
The model and its limits
Lumped lines with a constant bulk modulus, laminar leaks, turbulent orifices, vapour at zero absolute pressure without release dynamics, a rigid shaft. Efficiencies are those of this idealized machine.
Equations used in the module
Equations Q_m = D·ω/2π, T_i = D·(p_in − p_out)/2π Q_in = C_d·A_in·√(2(p_s − p_in)/ρ), Q_out = C_d·A_out·√(2p_out/ρ) J·dω/dt = T_i + T_ext − T_f·sgn ω − T_b·sgn ω − c·ω p_s·Q_in + T_ext·ω = ΔE_k + ΔE_p + Q_in_loss + Q_out_loss + Q_leak + Q_cav + Q_heat


