Skip to content
LIBRARY
Sources.Tests.VelocitySource.md

Sources.Tests.VelocitySource

Test for VelocitySource with Filtered and Exact modes, matching MSL ModelicaTest.Rotational.TestSpeed.

Two VelocitySource instances are driven by different reference signals and each drives an Inertia (J=1):

  1. velocity_filtered: Filtered mode (f_crit=5 Hz), step input at t=0.5 The first-order filter smooths the step — w tracks the step with a time constant of 1/(2π·5) ≈ 0.0318s. At t=1.1, w should be ≈1.0 (fully settled).

  2. velocity_exact: Exact mode, sine input (f=1 Hz) w tracks sin(2πt) exactly. At t=1.1: w = sin(2π·1.1) = sin(0.2π) ≈ 0.5878.

Usage

RotationalComponents.Sources.Tests.VelocitySource()

Behavior

Source

dyad
"""
Test for VelocitySource with Filtered and Exact modes, matching MSL ModelicaTest.Rotational.TestSpeed.

Two VelocitySource instances are driven by different reference signals and each
drives an Inertia (J=1):

1. velocity_filtered: Filtered mode (f_crit=5 Hz), step input at t=0.5
   The first-order filter smooths the step — w tracks the step with a time constant
   of 1/(2π·5) ≈ 0.0318s. At t=1.1, w should be ≈1.0 (fully settled).

2. velocity_exact: Exact mode, sine input (f=1 Hz)
   w tracks sin(2πt) exactly. At t=1.1: w = sin(2π·1.1) = sin(0.2π) ≈ 0.5878.
"""
test component VelocitySource
  "Fixed ground for all supports"
  fixed = RotationalComponents.Components.Fixed() {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 230, "y2": 330}}}
  }
  "Step signal for filtered velocity source (step at t=0.5)"
  step = BlockComponents.Sources.Step(height = 1.0, start_time = 0.5) {"Dyad": {"placement": {"diagram": {"x1": 10, "x2": 110, "y1": 20, "y2": 120}}}}
  "VelocitySource — Filtered mode with low f_crit=5 Hz"
  velocity_filtered = RotationalComponents.Sources.VelocitySource(ref_type = RotationalComponents.Sources.ReferenceType.Filtered(f_crit = 5.0)) {
    "Dyad": {"placement": {"diagram": {"x1": 155, "x2": 255, "y1": 20, "y2": 120}}}
  }
  "Inertia driven by filtered velocity source"
  inertia_filtered = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 20, "y2": 120}}}
  }
  "Sine signal for exact velocity source (f=1 Hz)"
  sine = BlockComponents.Sources.Sine(amplitude = 1, frequency = 1) {
    "Dyad": {"placement": {"diagram": {"x1": 20, "x2": 120, "y1": 350, "y2": 450}}}
  }
  "VelocitySource — Exact mode"
  velocity_exact = RotationalComponents.Sources.VelocitySource(ref_type = RotationalComponents.Sources.ReferenceType.Exact()) {
    "Dyad": {"placement": {"diagram": {"x1": 155, "x2": 255, "y1": 350, "y2": 450}}}
  }
  "Inertia driven by exact velocity source"
  inertia_exact = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 350, "y2": 450}}}
  }
relations
  initial inertia_exact.phi = 0
  initial inertia_filtered.phi = 0
  connect(step.y, velocity_filtered.w_ref) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "path": {}}}
  connect(velocity_filtered.spline, inertia_filtered.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "path": {}}}
  connect(velocity_filtered.support, fixed.spline) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 205, "y": 175}, {"x": 335, "y": 175}], "E": 2}],
      "path": {}
    }
  }
  connect(sine.y, velocity_exact.w_ref) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "path": {}}}
  connect(velocity_exact.spline, inertia_exact.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "path": {}}}
  connect(velocity_exact.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 205, "y": 505}, {"x": 270, "y": 505}], "E": -1},
        {"S": -1, "M": [{"x": 335, "y": 175}], "E": 2}
      ],
      "junctions": [{"x": 270, "y": 175}],
      "path": {}
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://RotationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1.1,
        "atol": {"inertia_filtered.w": 0.01, "inertia_exact.w": 0.001},
        "expect": {
          "initial": {
            "inertia_filtered.phi": 0,
            "inertia_exact.phi": 0,
            "inertia_filtered.w": 0,
            "inertia_exact.w": 0
          },
          "final": {"inertia_exact.w": 0.5878},
          "signals": [
            "inertia_filtered.w",
            "inertia_exact.w",
            "inertia_filtered.phi",
            "inertia_exact.phi"
          ]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
Test for VelocitySource with Filtered and Exact modes, matching MSL ModelicaTest.Rotational.TestSpeed.

Two VelocitySource instances are driven by different reference signals and each
drives an Inertia (J=1):

1. velocity_filtered: Filtered mode (f_crit=5 Hz), step input at t=0.5
   The first-order filter smooths the step — w tracks the step with a time constant
   of 1/(2π·5) ≈ 0.0318s. At t=1.1, w should be ≈1.0 (fully settled).

2. velocity_exact: Exact mode, sine input (f=1 Hz)
   w tracks sin(2πt) exactly. At t=1.1: w = sin(2π·1.1) = sin(0.2π) ≈ 0.5878.
"""
test component VelocitySource
  "Fixed ground for all supports"
  fixed = RotationalComponents.Components.Fixed() {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 230, "y2": 330}}}
  }
  "Step signal for filtered velocity source (step at t=0.5)"
  step = BlockComponents.Sources.Step(height = 1.0, start_time = 0.5) {"Dyad": {"placement": {"diagram": {"x1": 10, "x2": 110, "y1": 20, "y2": 120}}}}
  "VelocitySource — Filtered mode with low f_crit=5 Hz"
  velocity_filtered = RotationalComponents.Sources.VelocitySource(ref_type = RotationalComponents.Sources.ReferenceType.Filtered(f_crit = 5.0)) {
    "Dyad": {"placement": {"diagram": {"x1": 155, "x2": 255, "y1": 20, "y2": 120}}}
  }
  "Inertia driven by filtered velocity source"
  inertia_filtered = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 20, "y2": 120}}}
  }
  "Sine signal for exact velocity source (f=1 Hz)"
  sine = BlockComponents.Sources.Sine(amplitude = 1, frequency = 1) {
    "Dyad": {"placement": {"diagram": {"x1": 20, "x2": 120, "y1": 350, "y2": 450}}}
  }
  "VelocitySource — Exact mode"
  velocity_exact = RotationalComponents.Sources.VelocitySource(ref_type = RotationalComponents.Sources.ReferenceType.Exact()) {
    "Dyad": {"placement": {"diagram": {"x1": 155, "x2": 255, "y1": 350, "y2": 450}}}
  }
  "Inertia driven by exact velocity source"
  inertia_exact = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {"placement": {"diagram": {"x1": 285, "x2": 385, "y1": 350, "y2": 450}}}
  }
relations
  initial inertia_exact.phi = 0
  initial inertia_filtered.phi = 0
  connect(step.y, velocity_filtered.w_ref) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "path": {}}}
  connect(velocity_filtered.spline, inertia_filtered.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "path": {}}}
  connect(velocity_filtered.support, fixed.spline) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 205, "y": 175}, {"x": 335, "y": 175}], "E": 2}],
      "path": {}
    }
  }
  connect(sine.y, velocity_exact.w_ref) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "path": {}}}
  connect(velocity_exact.spline, inertia_exact.spline_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "path": {}}}
  connect(velocity_exact.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 205, "y": 505}, {"x": 270, "y": 505}], "E": -1},
        {"S": -1, "M": [{"x": 335, "y": 175}], "E": 2}
      ],
      "junctions": [{"x": 270, "y": 175}],
      "path": {}
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://RotationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 1.1,
        "atol": {"inertia_filtered.w": 0.01, "inertia_exact.w": 0.001},
        "expect": {
          "initial": {
            "inertia_filtered.phi": 0,
            "inertia_exact.phi": 0,
            "inertia_filtered.w": 0,
            "inertia_exact.w": 0
          },
          "final": {"inertia_exact.w": 0.5878},
          "signals": [
            "inertia_filtered.w",
            "inertia_exact.w",
            "inertia_filtered.phi",
            "inertia_exact.phi"
          ]
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt