Commit Graph

24 Commits

Author SHA1 Message Date
Rene De Ren
9916527790 optimalControl: dispatch setpoint to non-operational pumps too
Previously the dispatch loop only fired flowmovement for pumps in
'operational' or transitioned 'idle' pumps via execsequence-startup-then-flowmovement.
Pumps mid-startup (starting/warmingup) were silently skipped. With PS
sending demand every tick, intermediate setpoints during the startup
window never reached the pump — it locked onto the very first
snapshot's flowmovement and froze there.

Now flowmovement is sent regardless of state and rotatingMachine's
state.moveTo handles the queueing (delayedMove for transients, unpark
for residue, immediate for operational). Crucially, flowmovement runs
BEFORE execsequence-startup so the FIRST call's stale setpoint can't
land on an already-operational pump and overwrite the latest
delayedMove that fires at end of startup.

Adds three integration tests:
- demand-cycle-walkthrough: 0..100% sweep with clean per-step table
- idle-startup-deadlock: four scenarios that pin the dispatch behaviour
  including the regression guard for varying-demand-during-startup
- optimizer-combination-choice: physical-validity invariants

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 11:19:47 +02:00
znetsixe
9c79dac4e3 Fix stale flow cache on MGC shutdown; correct NCog physics tests
### Bug fix — stale flow cache on shutdown (specificClass.js)

When turnOffAllMachines() fires (negative demand, zero flow demand, or
safety trip), the MGC was only shutting pumps down. The pumps' last
emitted predicted flow / power stayed in the MeasurementContainer,
so the parent pumpingStation kept computing net flow from cached
non-zero values — reading the MGC as "still draining" when it wasn't.
Net: net-flow direction and safety triggers misfired during and
shortly after an MGC shutdown.

Fix: after shutting down all machines, write 0 to the predicted
flow (downstream + atEquipment) and predicted power (atEquipment)
slots so the cache reflects reality immediately.

### Correctness — async/await on shutdown (specificClass.js)

Two call sites invoked turnOffAllMachines() without awaiting it, so
the subsequent `return` raced the shutdown promises. Now awaited.
Also DRY'd one inline shutdown loop into a call to
turnOffAllMachines().

### Physics correction — NCog for centrifugal pumps (integration tests)

The previous tests asserted NCog > 0 for centrifugal pumps. That's
physically wrong: for variable-speed centrifugal pumps P ∝ n³ and
Q ∝ n, so Q/P ∝ 1/n² is monotonically decreasing with speed. Peak
efficiency (peak Q/P) is always at minimum speed → cogIndex = 0 →
NCog = 0 by the current formula.

Tests now:
- Assert NCog == 0 for all centrifugal configurations
- Assert distributeByNCog() falls back to equal distribution when
  NCog == 0 (confirmed by the existing tests 4-6 that slope-based
  redistribution is what actually differentiates pumps with different
  BEPs — not NCog)

This matches the actual implementation; the previous tests were
asserting an idealised COG model that doesn't apply here.

### Editor hygiene (mgc.html, nodeClass.js)

- mgc.html: add missing asset-menu defaults (uuid, supplier, category,
  assetType, model, unit) — brings MGC in line with rotatingMachine
  and pumpingStation editor shapes.
- nodeClass.js: clear node status badge on close.

All 13 tests (basic + integration) pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-22 17:51:10 +02:00
znetsixe
d55f401ab3 fix: production hardening — unit mismatch, safety guards, marginal-cost refinement
- Fix flowmovement unit mismatch: MGC computed flow in canonical (m³/s)
  but rotatingMachine expects output units (m³/h). All flowmovement calls
  now convert via _canonicalToOutputFlow(). Without this fix, every pump
  stayed at minimum flow regardless of demand.
- Fix absolute scaling: demandQout vs demandQ comparison bug, reorder
  conditions so <= 0 is checked first, add else branch for valid demand.
- Fix empty Qd <= 0 block: now calls turnOffAllMachines().
- Add empty-machines guards on optimalControl and equalizePressure.
- Add null fallback (|| 0) on pressure measurement reads.
- Fix division-by-zero in calcRelativeDistanceFromPeak.
- Fix missing flowmovement after startup in equalFlowControl.
- Add marginal-cost refinement loop in BEP-Gravitation: after slope-based
  redistribution, iteratively shifts flow from highest actual dP/dQ to
  lowest using real power evaluations. Closes gap to brute-force optimum
  from 2.1% to <0.1% without affecting combination selection stability.
- Add NCog distribution comparison tests and brute-force power table test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 13:40:45 +02:00
znetsixe
ffb2072baa Merge commit '85797b5' into HEAD
# Conflicts:
#	src/nodeClass.js
#	src/specificClass.js
2026-03-31 18:17:41 +02:00
Rene De Ren
85797b5b8b Align machineGroupControl with current architecture 2026-03-12 16:43:29 +01:00
znetsixe
b337bf9eb7 updates 2026-03-11 11:12:52 +01:00
znetsixe
f8012c8bad update 2026-02-23 13:17:39 +01:00
znetsixe
f4cb329597 updates 2025-11-25 15:10:36 +01:00
znetsixe
b49f0c3ed2 attempt to fix flow distribution 2025-11-22 21:09:38 +01:00
znetsixe
edcffade75 Added edge case for when 1 pump cant handle the scope 2025-11-20 22:28:49 +01:00
znetsixe
b6ffefc92b Lots of minor bug fixes to update on architecture choices 2025-11-13 19:39:32 +01:00
znetsixe
ed2cf4c23d fixed outputformats 2025-11-06 11:18:38 +01:00
znetsixe
e0526250c2 changed colours, description based on s88 2025-10-14 13:52:18 +02:00
Rene De ren
15501e8b1d updates from laptop 2025-10-03 15:33:37 +02:00
znetsixe
b4364094c6 Stable version of machinegroup control 2025-10-02 17:08:41 +02:00
znetsixe
a55c6bdbea fixed pressure updates from machines. Everything seems to be working again. 2025-09-23 15:50:40 +02:00
znetsixe
ac9d1b4fdd added test file 2025-09-23 15:12:01 +02:00
znetsixe
cbc0840f0c added testfile fixing bugs 2025-09-23 15:03:57 +02:00
znetsixe
c62071992d working on a stable version 2025-09-23 11:19:22 +02:00
znetsixe
078a0d80dc updated function for registration of machines 2025-09-04 17:07:18 +02:00
znetsixe
dc1fb500c0 license update 2025-08-07 13:52:56 +02:00
znetsixe
de5652b73d small bug fixes 2025-07-31 09:10:34 +02:00
znetsixe
2aeb876c0d bug fixes 2025-07-02 10:52:37 +02:00
znetsixe
35eb965609 not working yet need to fix child registration? 2025-07-01 17:03:36 +02:00