Skip to content

MDL writer pipe connector flags may not match Vensim originals #403

Description

@bpowers

Description

In write_flow_pipe_connectors (src/simlin-engine/src/mdl/writer.rs), the pipe connector direction flag (field 4 in the pipe connector tuple) is set to 100 for cloud endpoints and 4 for stock endpoints. However, analysis of the mark2.mdl roundtrip test shows a mismatch between original and roundtripped values:

  • Original file: flags {4: 9, 100: 4} (i.e., some stock-connected pipes have flag 9, some have 4; cloud-connected pipes have 100)
  • Roundtripped file: flags {4: 11} for stock-connected pipes

The flag semantics appear to involve more than just endpoint type. They may encode additional information such as:

  • Flow direction (inflow vs. outflow)
  • Source vs. sink role of the connected stock
  • Pipe orientation or routing hints

Why It Matters

  • Correctness: Roundtripped MDL files may produce visually different pipe/flow rendering in Vensim due to incorrect direction flags.
  • MDL format fidelity: Achieving faithful MDL roundtrips is a goal of the current work on the mdl-roundtrip-fidelity branch.
  • Interoperability: Users who roundtrip models through Simlin and then open them in Vensim could see unexpected layout changes in flow arrows.

Component(s) Affected

  • simlin-engine -- specifically src/simlin-engine/src/mdl/writer.rs, function write_flow_pipe_connectors

Possible Approaches

  1. Compare multiple Vensim-generated .mdl files to catalog the full set of flag values and their correlation with flow direction, endpoint type, and pipe orientation.
  2. Check Vensim documentation or SDeverywhere/PySD for any reverse-engineered documentation of the pipe connector format.
  3. Add test cases that cover inflow-to-stock, outflow-from-stock, and cloud-terminated flows to isolate the flag semantics.

Context

Identified during development on the mdl-roundtrip-fidelity branch, specifically when analyzing differences between the original test/mdl/mark2.mdl and its roundtripped output.

Activity

  1. added
    engineIssues with the rust-based simulation engine
    compatCompatibility (XMILE, Vensim, etc) problem or enhancement
    on Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatCompatibility (XMILE, Vensim, etc) problem or enhancementengineIssues with the rust-based simulation engine

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions