Skip to content
LIBRARY
Examples.WhyArrows.md

Examples.WhyArrows

Demonstrate the importance of arrow direction in Translational models.

Replicates the structure of Modelica.Mechanics.Translational.Examples.WhyArrows.

Top system (rods + sensors): Three rods (all L=1) are connected to a common Fixed reference. Position sensors measure positions at the extremities. When all arrows point in the same direction, positionSensor2.s == positionSensor3.s (both are 1 m away from Fixed in the positive direction), while positionSensor1.s differs (1 m in the negative direction).

Bottom left: fixed1(s0=-1.9) → spring1(s_rel0=2, c=11) → mass1(L=2, m=1). Bottom right: fixed2(s0=-1.9) → spring2(s_rel0=2, c=11) → mass2(L=2, m=1). Both systems are equivalent, demonstrating that sign conventions are consistent.

Usage

TranslationalComponents.Examples.WhyArrows()

Behavior

[connect(rod1+flangeb,fixed+flange)connect(rod3+flangea,fixed+flange)connect(fixed+flange,rod2+flangea)connect(rod1+flangea,positionsensor1+flange)connect(rod2+flangeb,positionsensor2+flange)connect(rod3+flangeb,positionsensor3+flange)connect(fixed1+flange,spring1+flangea)connect(spring1+flangeb,mass1+flangeb)connect(fixed2+flange,spring2+flangea)connect(spring2+flangeb,mass2+flangeb)fixed.flange.s(t)=fixed.s0rod1.flangea.s(t)=12rod1.L+rod1.s(t)rod1.flangeb.s(t)=rod1.L2+rod1.s(t)0=rod1.flangea.f(t)+rod1.flangeb.f(t)rod2.flangea.s(t)=12rod2.L+rod2.s(t)rod2.flangeb.s(t)=rod2.L2+rod2.s(t)0=rod2.flangea.f(t)+rod2.flangeb.f(t)rod3.flangea.s(t)=12rod3.L+rod3.s(t)rod3.flangeb.s(t)=rod3.L2+rod3.s(t)0=rod3.flangea.f(t)+rod3.flangeb.f(t)0=positionsensor1.flange.f(t)positionsensor1.flange.s(t)=positionsensor1.s(t)0=positionsensor2.flange.f(t)positionsensor2.flange.s(t)=positionsensor2.s(t)0=positionsensor3.flange.f(t)positionsensor3.flange.s(t)=positionsensor3.s(t)fixed1.flange.s(t)=fixed1.s0spring1.srel(t)=spring1.flangea.s(t)+spring1.flangeb.s(t)spring1.flangeb.f(t)=spring1.f(t)spring1.flangea.f(t)=spring1.f(t)spring1.f(t)=spring1.c(spring1.srel0+spring1.srel(t))mass1.flangea.s(t)=12mass1.L+mass1.s(t)mass1.flangeb.s(t)=mass1.L2+mass1.s(t)mass1.v(t)=dmass1.s(t)dtmass1.a(t)=dmass1.v(t)dt(mass1.a(t)+mass1.gsin(mass1.theta))mass1.m=mass1.flangea.f(t)+mass1.flangeb.f(t)fixed2.flange.s(t)=fixed2.s0spring2.srel(t)=spring2.flangea.s(t)+spring2.flangeb.s(t)spring2.flangeb.f(t)=spring2.f(t)spring2.flangea.f(t)=spring2.f(t)spring2.f(t)=spring2.c(spring2.srel0+spring2.srel(t))mass2.flangea.s(t)=12mass2.L+mass2.s(t)mass2.flangeb.s(t)=mass2.L2+mass2.s(t)mass2.v(t)=dmass2.s(t)dtmass2.a(t)=dmass2.v(t)dt(mass2.a(t)+mass2.gsin(mass2.theta))mass2.m=mass2.flangea.f(t)+mass2.flangeb.f(t)]

Source

dyad
"""
Demonstrate the importance of arrow direction in Translational models.

Replicates the structure of Modelica.Mechanics.Translational.Examples.WhyArrows.

**Top system (rods + sensors):** Three rods (all L=1) are connected to a
common Fixed reference. Position sensors measure positions at the extremities.
When all arrows point in the same direction, positionSensor2.s == positionSensor3.s
(both are 1 m away from Fixed in the positive direction), while
positionSensor1.s differs (1 m in the negative direction).

**Bottom left:** fixed1(s0=-1.9) → spring1(s_rel0=2, c=11) → mass1(L=2, m=1).
**Bottom right:** fixed2(s0=-1.9) → spring2(s_rel0=2, c=11) → mass2(L=2, m=1).
Both systems are equivalent, demonstrating that sign conventions are consistent.
"""
example component WhyArrows
  "Common fixed reference"
  fixed = TranslationalComponents.Components.Fixed() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 230, "x2": 550, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  "Rod 1 (L=1), extends in negative direction from fixed"
  rod1 = TranslationalComponents.Components.Rod(L = 1) {
    "Dyad": {
      "placement": {"diagram": {"iconName": "default", "x1": 210, "y1": 80, "x2": 310, "y2": 180}}
    }
  }
  "Rod 2 (L=1), extends in positive direction from fixed"
  rod2 = TranslationalComponents.Components.Rod(L = 1) {
    "Dyad": {
      "placement": {"diagram": {"iconName": "default", "x1": 620, "y1": 80, "x2": 720, "y2": 180}}
    }
  }
  "Rod 3 (L=1), extends in positive direction from fixed (flipped)"
  rod3 = TranslationalComponents.Components.Rod(L = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 220, "y1": 240, "x2": 320, "y2": 340, "rot": 180}
      },
      "tags": []
    }
  }
  "Position sensor at end of rod1 (negative side)"
  position_sensor1 = TranslationalComponents.Sensors.PositionSensor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 120, "y1": 80, "x2": 20, "y2": 180, "rot": 0}
      },
      "tags": []
    }
  }
  "Position sensor at end of rod2 (positive side)"
  position_sensor2 = TranslationalComponents.Sensors.PositionSensor() {
    "Dyad": {
      "placement": {"diagram": {"iconName": "default", "x1": 810, "y1": 80, "x2": 910, "y2": 180}}
    }
  }
  "Position sensor at end of rod3 (positive side, flipped rod)"
  position_sensor3 = TranslationalComponents.Sensors.PositionSensor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 120, "y1": 240, "x2": 20, "y2": 340, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed reference for bottom-left spring-mass"
  fixed1 = TranslationalComponents.Components.Fixed(s0 = -1.9) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 740, "x2": 120, "y2": 840, "rot": 0}
      },
      "tags": []
    }
  }
  "Spring for bottom-left system"
  spring1 = TranslationalComponents.Components.Spring(s_rel0 = 2, c = 11) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 590, "x2": 270, "y2": 690, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass for bottom-left system"
  mass1 = TranslationalComponents.Components.Mass(L = 2, m = 1, s = initial 0, v = initial 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 440, "y1": 590, "x2": 340, "y2": 690, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed reference for bottom-right system"
  fixed2 = TranslationalComponents.Components.Fixed(s0 = -1.9) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 550, "y1": 720, "x2": 650, "y2": 820, "rot": 0}
      },
      "tags": []
    }
  }
  "Spring for bottom-right system"
  spring2 = TranslationalComponents.Components.Spring(s_rel0 = 2, c = 11) {
    "Dyad": {
      "placement": {"diagram": {"iconName": "default", "x1": 690, "y1": 590, "x2": 790, "y2": 690}}
    }
  }
  "Mass for bottom-right system (connected backwards to show equivalence)"
  mass2 = TranslationalComponents.Components.Mass(L = 2, m = 1, s = initial 0, v = initial 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 860, "y1": 590, "x2": 960, "y2": 690, "rot": 180}
      },
      "tags": []
    }
  }
relations
  # Top system: rods from fixed, sensors at extremities
  connect(rod1.flange_b, fixed.flange) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(rod3.flange_a, fixed.flange) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 365, "y": 290}, {"x": 365, "y": 180}, {"x": 500, "y": 180}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(fixed.flange, rod2.flange_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(rod1.flange_a, position_sensor1.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(rod2.flange_b, position_sensor2.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(rod3.flange_b, position_sensor3.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  # Bottom-left: fixed1 → spring1 → mass1
  connect(fixed1.flange, spring1.flange_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 70, "y": 640}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(spring1.flange_b, mass1.flange_b) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  # Bottom-right: fixed2 → spring2 → mass2
  connect(fixed2.flange, spring2.flange_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 600, "y": 640}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(spring2.flange_b, mass2.flange_b) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "experiments": {},
    "tests": {
      "case1": {
        "solver": "Auto",
        "start": 0,
        "stop": 1,
        "params": {},
        "initial": {},
        "atol": {
          "position_sensor1.s": 0.001,
          "position_sensor2.s": 0.001,
          "position_sensor3.s": 0.001,
          "mass1.s": 0.001,
          "mass1.v": 0.001,
          "mass2.s": 0.001,
          "mass2.v": 0.001
        },
        "rtol": {},
        "abstol": 0.000001,
        "reltol": 0.000001,
        "automatic_discontinuity_detection": false,
        "expect": {
          "initial": {},
          "final": {
            "position_sensor1.s": -1,
            "position_sensor2.s": 1,
            "position_sensor3.s": 1,
            "mass1.s": -1.78624,
            "mass1.v": 0.5198,
            "mass2.s": -1.78624,
            "mass2.v": 0.5198
          },
          "signals": [
            "position_sensor1.s",
            "position_sensor2.s",
            "position_sensor3.s",
            "mass1.s",
            "mass1.v",
            "mass2.s",
            "mass2.v"
          ]
        }
      }
    },
    "labels": [
      {
        "label": "position_sensor2.s = position_sensor3.s",
        "x": 500,
        "y": 420,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "#0000ff",
          "font-size": "40",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      },
      {
        "label": "position_sensor3.s <> position_sensor1.s",
        "x": 500,
        "y": 470,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "#0000ff",
          "font-size": "40",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      },
      {
        "label": "Both systems are equivalent",
        "x": 490,
        "y": 890,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "#0000ff",
          "font-size": "40",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      }
    ],
    "icons": {"default": "dyad://TranslationalComponents/Example.svg"},
    "path": {},
    "doc": {"behavior": true},
    "deprecated": null
  }
}
end
Flattened Source
dyad
"""
Demonstrate the importance of arrow direction in Translational models.

Replicates the structure of Modelica.Mechanics.Translational.Examples.WhyArrows.

**Top system (rods + sensors):** Three rods (all L=1) are connected to a
common Fixed reference. Position sensors measure positions at the extremities.
When all arrows point in the same direction, positionSensor2.s == positionSensor3.s
(both are 1 m away from Fixed in the positive direction), while
positionSensor1.s differs (1 m in the negative direction).

**Bottom left:** fixed1(s0=-1.9) → spring1(s_rel0=2, c=11) → mass1(L=2, m=1).
**Bottom right:** fixed2(s0=-1.9) → spring2(s_rel0=2, c=11) → mass2(L=2, m=1).
Both systems are equivalent, demonstrating that sign conventions are consistent.
"""
example component WhyArrows
  "Common fixed reference"
  fixed = TranslationalComponents.Components.Fixed() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 450, "y1": 230, "x2": 550, "y2": 330, "rot": 0}
      },
      "tags": []
    }
  }
  "Rod 1 (L=1), extends in negative direction from fixed"
  rod1 = TranslationalComponents.Components.Rod(L = 1) {
    "Dyad": {
      "placement": {"diagram": {"iconName": "default", "x1": 210, "y1": 80, "x2": 310, "y2": 180}}
    }
  }
  "Rod 2 (L=1), extends in positive direction from fixed"
  rod2 = TranslationalComponents.Components.Rod(L = 1) {
    "Dyad": {
      "placement": {"diagram": {"iconName": "default", "x1": 620, "y1": 80, "x2": 720, "y2": 180}}
    }
  }
  "Rod 3 (L=1), extends in positive direction from fixed (flipped)"
  rod3 = TranslationalComponents.Components.Rod(L = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 220, "y1": 240, "x2": 320, "y2": 340, "rot": 180}
      },
      "tags": []
    }
  }
  "Position sensor at end of rod1 (negative side)"
  position_sensor1 = TranslationalComponents.Sensors.PositionSensor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 120, "y1": 80, "x2": 20, "y2": 180, "rot": 0}
      },
      "tags": []
    }
  }
  "Position sensor at end of rod2 (positive side)"
  position_sensor2 = TranslationalComponents.Sensors.PositionSensor() {
    "Dyad": {
      "placement": {"diagram": {"iconName": "default", "x1": 810, "y1": 80, "x2": 910, "y2": 180}}
    }
  }
  "Position sensor at end of rod3 (positive side, flipped rod)"
  position_sensor3 = TranslationalComponents.Sensors.PositionSensor() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 120, "y1": 240, "x2": 20, "y2": 340, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed reference for bottom-left spring-mass"
  fixed1 = TranslationalComponents.Components.Fixed(s0 = -1.9) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 740, "x2": 120, "y2": 840, "rot": 0}
      },
      "tags": []
    }
  }
  "Spring for bottom-left system"
  spring1 = TranslationalComponents.Components.Spring(s_rel0 = 2, c = 11) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 170, "y1": 590, "x2": 270, "y2": 690, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass for bottom-left system"
  mass1 = TranslationalComponents.Components.Mass(L = 2, m = 1, s = initial 0, v = initial 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 440, "y1": 590, "x2": 340, "y2": 690, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed reference for bottom-right system"
  fixed2 = TranslationalComponents.Components.Fixed(s0 = -1.9) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 550, "y1": 720, "x2": 650, "y2": 820, "rot": 0}
      },
      "tags": []
    }
  }
  "Spring for bottom-right system"
  spring2 = TranslationalComponents.Components.Spring(s_rel0 = 2, c = 11) {
    "Dyad": {
      "placement": {"diagram": {"iconName": "default", "x1": 690, "y1": 590, "x2": 790, "y2": 690}}
    }
  }
  "Mass for bottom-right system (connected backwards to show equivalence)"
  mass2 = TranslationalComponents.Components.Mass(L = 2, m = 1, s = initial 0, v = initial 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 860, "y1": 590, "x2": 960, "y2": 690, "rot": 180}
      },
      "tags": []
    }
  }
relations
  # Top system: rods from fixed, sensors at extremities
  connect(rod1.flange_b, fixed.flange) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(rod3.flange_a, fixed.flange) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 365, "y": 290}, {"x": 365, "y": 180}, {"x": 500, "y": 180}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(fixed.flange, rod2.flange_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 130}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(rod1.flange_a, position_sensor1.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(rod2.flange_b, position_sensor2.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(rod3.flange_b, position_sensor3.flange) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  # Bottom-left: fixed1 → spring1 → mass1
  connect(fixed1.flange, spring1.flange_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 70, "y": 640}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(spring1.flange_b, mass1.flange_b) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  # Bottom-right: fixed2 → spring2 → mass2
  connect(fixed2.flange, spring2.flange_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 600, "y": 640}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(spring2.flange_b, mass2.flange_b) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
  "Dyad": {
    "experiments": {},
    "tests": {
      "case1": {
        "solver": "Auto",
        "start": 0,
        "stop": 1,
        "params": {},
        "initial": {},
        "atol": {
          "position_sensor1.s": 0.001,
          "position_sensor2.s": 0.001,
          "position_sensor3.s": 0.001,
          "mass1.s": 0.001,
          "mass1.v": 0.001,
          "mass2.s": 0.001,
          "mass2.v": 0.001
        },
        "rtol": {},
        "abstol": 0.000001,
        "reltol": 0.000001,
        "automatic_discontinuity_detection": false,
        "expect": {
          "initial": {},
          "final": {
            "position_sensor1.s": -1,
            "position_sensor2.s": 1,
            "position_sensor3.s": 1,
            "mass1.s": -1.78624,
            "mass1.v": 0.5198,
            "mass2.s": -1.78624,
            "mass2.v": 0.5198
          },
          "signals": [
            "position_sensor1.s",
            "position_sensor2.s",
            "position_sensor3.s",
            "mass1.s",
            "mass1.v",
            "mass2.s",
            "mass2.v"
          ]
        }
      }
    },
    "labels": [
      {
        "label": "position_sensor2.s = position_sensor3.s",
        "x": 500,
        "y": 420,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "#0000ff",
          "font-size": "40",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      },
      {
        "label": "position_sensor3.s <> position_sensor1.s",
        "x": 500,
        "y": 470,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "#0000ff",
          "font-size": "40",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      },
      {
        "label": "Both systems are equivalent",
        "x": 490,
        "y": 890,
        "rot": 0,
        "layer": "diagram",
        "attrs": {
          "fill": "#0000ff",
          "font-size": "40",
          "dominant-baseline": "central",
          "text-anchor": "middle"
        }
      }
    ],
    "icons": {"default": "dyad://TranslationalComponents/Example.svg"},
    "path": {},
    "doc": {"behavior": true},
    "deprecated": null
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

  • Examples

  • Experiments

  • Analyses