Repository navigation
Description
Problem
When a Vensim stock is defined piecewise over subranges of a shared parent dimension, the MDL importer widens the STOCK's dimensions to the parent dimension, but the synthesized <stock>_net_flow variable keeps the FIRST piecewise arm's subrange dimensions -- while its per-element Equation::Arrayed entries are generated over the full parent range. The entries for the parent-only elements then name no declared element combination of the (too-narrow) flow dimensions, and the compiler silently drops them (the exact silent-drop hazard tracked in #905). The net flow for those elements is missing (implicit 0), so the simulation is wrong for those elements -- with no diagnostic on released builds.
Concrete repro
test/metasd/beer-game/RealBeer4-Sterman13.mdl declares:
Lower Levels: Retailer,Wholesaler,Distributor -> Upper LevelsLevel: Retailer,Wholesaler,Distributor,Factory
and defines the stock piecewise:
Supply Line[Games,Lower Levels] = INTEG(...)Supply Line[Games,Factory] = INTEG(...)
After open_vensim:
- stock
supply_linecorrectly gets dims["Games", "Level"]with entries for all four levels (the subrange-widening logic works for the stock); - synthesized
supply_line_net_flowgets dims["Games", "Lower_Levels"](3 elements) while carrying 13 entries forGameN,Factory(one per game) that name no element ofLower_Levels.
Those 13 entries are silently dropped by the compiler, so the Factory column's net flow is 0.
With the new UnknownElementSubscript Warning (GH #905 work on branch conveyor-engine), this now surfaces as 13 warnings on that model, one per GameN,Factory entry. The diagnostic is correct; the importer output is what is wrong.
Why it matters
Correctness: the imported model simulates plausible-looking but wrong results for every element outside the first arm's subrange, with no signal at all before the #905 diagnostic lands. Any Vensim model using the common subrange -> parent piecewise-INTEG idiom is affected.
Components affected
src/simlin-engine/src/mdl/convert/stocks.rs--build_synthetic_flow_equation(line ~384) and the dims selection at its call sites (~261, ~319): the synthetic flow inherits the first arm's dims.src/simlin-engine/src/mdl/convert/variables.rs(~line 381) -- the stock path already has the right logic: when normalized dims match but raw dims differ, it promotes to the parent viaresolve_subrange_to_parent.
Possible approach
Resolve the synthetic net-flow variable's dimensions the same way the stock's are resolved: when the piecewise arms span different subranges of the same parent, widen the flow dims to the common parent (reuse or share the resolve_subrange_to_parent promotion in variables.rs ~381) so the flow's declared dimensions cover every generated per-element entry.
Context
Identified on branch conveyor-engine while implementing the #905 unknown-element-subscript diagnostic, which flagged the dropped GameN,Factory entries on RealBeer4-Sterman13.mdl.
Activity
engine: warn on unresolvable arrayed element subscripts
engine: warn on unresolvable arrayed element subscripts