Skip to content
LIBRARY
Sources.Tests.Position.md

Sources.Tests.Position

Test of the Position source component with all ReferenceType enum variants.

Replicates the structure of ModelicaTest.Translational.AllComponents (Position portion) and ModelicaTest.Translational.TestFrictionPosition.

Three Position instances are driven by a common Sine reference (amplitude=1, frequency=1 Hz) and each drives a Mass (m=1 kg) with support grounded to Fixed:

  • pos_filtered: default Filtered mode (f_crit=50 Hz, af=1.3617, bf=0.6180)

  • pos_exact: Exact mode — flange position equals input directly

  • pos_filtered_low: Filtered mode with low critical frequency (f_crit=5 Hz) to show visible filtering

Usage

TranslationalComponents.Sources.Tests.Position()

Behavior

[connect(sine+y,posfiltered+s_ref)connect(posfiltered+flange,massfiltered+flange_a)connect(sine+y,posexact+s_ref)connect(posexact+flange,massexact+flange_a)connect(sine+y,posfiltered_low+s_ref)connect(posfiltered_low+flange,massfiltered_low+flange_a)connect(posexact+support,ground+flange)connect(posfiltered_low+support,ground+flange)connect(posfiltered+support,ground+flange)sine.y(t)=sine.offset+sine.amplitudeifelse(tsine.starttime,sin(sine.phase+6.283185307179586sine.frequency(sine.starttime+t)),sin(sine.phase))posfiltered.s(t)=posfiltered.flange.s(t)posfiltered.support.s(t)posfiltered.support.f(t)=posfiltered.flange.f(t)posfiltered.v(t)=dposfiltered.s(t)dtposfiltered.a(t)=dposfiltered.v(t)dtposfiltered.a(t)=314.1592653589793(posfiltered.a_fposfiltered.v(t)+100.0(posfiltered.s_ref(t)posfiltered.s(t))π)posfiltered.b_fmassfiltered.flange_a.s(t)=12massfiltered.L+massfiltered.s(t)massfiltered.flange_b.s(t)=massfiltered.L2+massfiltered.s(t)massfiltered.v(t)=dmassfiltered.s(t)dtmassfiltered.a(t)=dmassfiltered.v(t)dt(massfiltered.a(t)+massfiltered.gsin(massfiltered.theta))massfiltered.m=massfiltered.flange_a.f(t)+massfiltered.flange_b.f(t)posexact.s(t)=posexact.support.s(t)+posexact.flange.s(t)posexact.support.f(t)=posexact.flange.f(t)posexact.s(t)=posexact.s_ref(t)posexact.v(t)=0posexact.a(t)=0massexact.flange_a.s(t)=12massexact.L+massexact.s(t)massexact.flange_b.s(t)=massexact.L2+massexact.s(t)massexact.v(t)=dmassexact.s(t)dtmassexact.a(t)=dmassexact.v(t)dt(massexact.a(t)+massexact.gsin(massexact.theta))massexact.m=massexact.flange_b.f(t)+massexact.flange_a.f(t)posfiltered_low.s(t)=posfiltered_low.flange.s(t)posfiltered_low.support.s(t)posfiltered_low.support.f(t)=posfiltered_low.flange.f(t)posfiltered_low.v(t)=dposfiltered_low.s(t)dtposfiltered_low.a(t)=dposfiltered_low.v(t)dtposfiltered_low.a(t)=31.41592653589793(posfiltered_low.a_fposfiltered_low.v(t)+10.0(posfiltered_low.s(t)+posfiltered_low.s_ref(t))π)posfiltered_low.b_fmassfiltered_low.flange_a.s(t)=12massfiltered_low.L+massfiltered_low.s(t)massfiltered_low.flange_b.s(t)=massfiltered_low.L2+massfiltered_low.s(t)massfiltered_low.v(t)=dmassfiltered_low.s(t)dtmassfiltered_low.a(t)=dmassfiltered_low.v(t)dt(massfiltered_low.a(t)+massfiltered_low.gsin(massfiltered_low.theta))massfiltered_low.m=massfiltered_low.flange_a.f(t)+massfiltered_low.flange_b.f(t)ground.flange.s(t)=ground.s0]

Source

dyad
"""
Test of the Position source component with all ReferenceType enum variants.

Replicates the structure of ModelicaTest.Translational.AllComponents (Position portion)
and ModelicaTest.Translational.TestFrictionPosition.

Three Position instances are driven by a common Sine reference (amplitude=1, frequency=1 Hz)
and each drives a Mass (m=1 kg) with support grounded to Fixed:

- pos_filtered: default Filtered mode (f_crit=50 Hz, af=1.3617, bf=0.6180)
- pos_exact: Exact mode — flange position equals input directly
- pos_filtered_low: Filtered mode with low critical frequency (f_crit=5 Hz) to show visible filtering
"""
test component Position
  "Sine reference position signal (amplitude=1 m, frequency=1 Hz)"
  sine = BlockComponents.Sources.Sine(amplitude = 1.0, frequency = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 30, "y1": 450, "x2": 130, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Position source — Filtered with default Bessel filter (f_crit=50 Hz)"
  pos_filtered = TranslationalComponents.Sources.Position() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 340, "y1": 640, "x2": 440, "y2": 740, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass driven by filtered position source"
  mass_filtered = TranslationalComponents.Components.Mass(m = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 590, "y1": 640, "x2": 690, "y2": 740, "rot": 0}
      },
      "tags": []
    }
  }
  "Position source — Exact (flange tracks input directly)"
  pos_exact = TranslationalComponents.Sources.Position(ref_type = TranslationalComponents.Sources.ReferenceType.Exact()) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 330, "y1": 210, "x2": 430, "y2": 310, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass driven by exact position source"
  mass_exact = TranslationalComponents.Components.Mass(m = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 590, "y1": 210, "x2": 690, "y2": 310, "rot": 0}
      },
      "tags": []
    }
  }
  "Position source — Filtered with low critical frequency (f_crit=5 Hz)"
  pos_filtered_low = TranslationalComponents.Sources.Position(ref_type = TranslationalComponents.Sources.ReferenceType.Filtered(f_crit = 5.0)) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 450, "x2": 420, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass driven by low-f_crit filtered position source"
  mass_filtered_low = TranslationalComponents.Components.Mass(m = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 600, "y1": 450, "x2": 700, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed ground for all supports"
  ground = TranslationalComponents.Components.Fixed() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 890, "y1": 450, "x2": 990, "y2": 550, "rot": 270}
      },
      "tags": []
    }
  }
relations
  # --- Filtered (default) ---
  connect(sine.y, pos_filtered.s_ref) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 500}, {"x": 140, "y": 690}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(pos_filtered.flange, mass_filtered.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  initial pos_filtered.v = 0
  # --- Exact ---
  connect(sine.y, pos_exact.s_ref) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 500}, {"x": 140, "y": 260}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(pos_exact.flange, mass_exact.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  # --- Filtered low f_crit ---
  connect(sine.y, pos_filtered_low.s_ref) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(pos_filtered_low.flange, mass_filtered_low.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  initial pos_filtered_low.v = 0
  connect(pos_exact.support, ground.flange) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 380, "y": 400}, {"x": 850, "y": 400}, {"x": 850, "y": 500}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(pos_filtered_low.support, ground.flange) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 370, "y": 600}, {"x": 850, "y": 600}, {"x": 850, "y": 500}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(pos_filtered.support, ground.flange) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 390, "y": 830}, {"x": 850, "y": 830}, {"x": 850, "y": 500}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1.1,
        "atol": {
          "mass_filtered.s": 0.001,
          "mass_filtered.v": 0.01,
          "mass_exact.s": 0.001,
          "mass_exact.v": 0.01,
          "mass_filtered_low.s": 0.01,
          "mass_filtered_low.v": 0.1
        },
        "expect": {
          "final": {
            "mass_exact.s": 0.5877852522924736,
            "mass_filtered.s": 0.565467313786633,
            "mass_filtered.v": 5.1812448946651894,
            "mass_filtered_low.s": 0.3442052973660629
          },
          "signals": [
            "mass_filtered.s",
            "mass_filtered.v",
            "mass_exact.s",
            "mass_exact.v",
            "mass_filtered_low.s",
            "mass_filtered_low.v"
          ]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
Test of the Position source component with all ReferenceType enum variants.

Replicates the structure of ModelicaTest.Translational.AllComponents (Position portion)
and ModelicaTest.Translational.TestFrictionPosition.

Three Position instances are driven by a common Sine reference (amplitude=1, frequency=1 Hz)
and each drives a Mass (m=1 kg) with support grounded to Fixed:

- pos_filtered: default Filtered mode (f_crit=50 Hz, af=1.3617, bf=0.6180)
- pos_exact: Exact mode — flange position equals input directly
- pos_filtered_low: Filtered mode with low critical frequency (f_crit=5 Hz) to show visible filtering
"""
test component Position
  "Sine reference position signal (amplitude=1 m, frequency=1 Hz)"
  sine = BlockComponents.Sources.Sine(amplitude = 1.0, frequency = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 30, "y1": 450, "x2": 130, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Position source — Filtered with default Bessel filter (f_crit=50 Hz)"
  pos_filtered = TranslationalComponents.Sources.Position() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 340, "y1": 640, "x2": 440, "y2": 740, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass driven by filtered position source"
  mass_filtered = TranslationalComponents.Components.Mass(m = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 590, "y1": 640, "x2": 690, "y2": 740, "rot": 0}
      },
      "tags": []
    }
  }
  "Position source — Exact (flange tracks input directly)"
  pos_exact = TranslationalComponents.Sources.Position(ref_type = TranslationalComponents.Sources.ReferenceType.Exact()) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 330, "y1": 210, "x2": 430, "y2": 310, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass driven by exact position source"
  mass_exact = TranslationalComponents.Components.Mass(m = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 590, "y1": 210, "x2": 690, "y2": 310, "rot": 0}
      },
      "tags": []
    }
  }
  "Position source — Filtered with low critical frequency (f_crit=5 Hz)"
  pos_filtered_low = TranslationalComponents.Sources.Position(ref_type = TranslationalComponents.Sources.ReferenceType.Filtered(f_crit = 5.0)) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 320, "y1": 450, "x2": 420, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Mass driven by low-f_crit filtered position source"
  mass_filtered_low = TranslationalComponents.Components.Mass(m = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 600, "y1": 450, "x2": 700, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Fixed ground for all supports"
  ground = TranslationalComponents.Components.Fixed() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 890, "y1": 450, "x2": 990, "y2": 550, "rot": 270}
      },
      "tags": []
    }
  }
relations
  # --- Filtered (default) ---
  connect(sine.y, pos_filtered.s_ref) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 500}, {"x": 140, "y": 690}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(pos_filtered.flange, mass_filtered.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  initial pos_filtered.v = 0
  # --- Exact ---
  connect(sine.y, pos_exact.s_ref) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 500}, {"x": 140, "y": 260}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(pos_exact.flange, mass_exact.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  # --- Filtered low f_crit ---
  connect(sine.y, pos_filtered_low.s_ref) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(pos_filtered_low.flange, mass_filtered_low.flange_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  initial pos_filtered_low.v = 0
  connect(pos_exact.support, ground.flange) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 380, "y": 400}, {"x": 850, "y": 400}, {"x": 850, "y": 500}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(pos_filtered_low.support, ground.flange) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 370, "y": 600}, {"x": 850, "y": 600}, {"x": 850, "y": 500}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(pos_filtered.support, ground.flange) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 390, "y": 830}, {"x": 850, "y": 830}, {"x": 850, "y": 500}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://TranslationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1.1,
        "atol": {
          "mass_filtered.s": 0.001,
          "mass_filtered.v": 0.01,
          "mass_exact.s": 0.001,
          "mass_exact.v": 0.01,
          "mass_filtered_low.s": 0.01,
          "mass_filtered_low.v": 0.1
        },
        "expect": {
          "final": {
            "mass_exact.s": 0.5877852522924736,
            "mass_filtered.s": 0.565467313786633,
            "mass_filtered.v": 5.1812448946651894,
            "mass_filtered_low.s": 0.3442052973660629
          },
          "signals": [
            "mass_filtered.s",
            "mass_filtered.v",
            "mass_exact.s",
            "mass_exact.v",
            "mass_filtered_low.s",
            "mass_filtered_low.v"
          ]
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt