Skip to content
LIBRARY
Sources.Tests.TestBraking.md

Sources.Tests.TestBraking

Test for braking torque sources, matching MSL ModelicaTest.Rotational.TestBraking.

Five inertias (J=1) each start at w=100 rad/s and are braked by a different source. EddyCurrentTorque is omitted (depends on ThermalComponents).

Expected behavior (all with TorqueDirection=true, the default):

  1. LinearSpeedDependentTorque: tau = -|w| → w(t) = 100·exp(-t) → w(2) ≈ 13.534

  2. QuadraticSpeedDependentTorque: tau = -w²/100 → w = 100/(1+t) → w(2) ≈ 33.333

  3. ConstantTorque: tau = -100 → w = 100-100t → w(2) = -100

  4. SignTorque (Exp): tau ≈ -100·sign(w) → brakes to 0, then regularizes near w=0

  5. InverseSpeedDependentTorque: tau = -10000/|w| → w = 100·√(1-2t) → w hits 0 at t=0.5

Usage

RotationalComponents.Sources.Tests.TestBraking()

Behavior

[connect(inertia1+splineb,linearspeed+spline)connect(linearspeed+support,fixed+spline)connect(inertia2+splineb,quadraticspeed+spline)connect(quadraticspeed+support,fixed+spline)connect(inertia3+splineb,constanttorque+spline)connect(constanttorque+support,fixed+spline)connect(inertia4+splineb,signtorque+spline)connect(signtorque+support,fixed+spline)connect(inertia5+splineb,inversespeed+spline)connect(inversespeed+support,fixed+spline)fixed.spline.phi(t)=fixed.phi0inertia1.phi(t)=inertia1.splinea.phi(t)inertia1.phi(t)=inertia1.splineb.phi(t)dinertia1.phi(t)dt=inertia1.w(t)dinertia1.w(t)dt=inertia1.a(t)inertia1.Jinertia1.a(t)=inertia1.splinea.tau(t)+inertia1.splineb.tau(t)linearspeed.support.phi(t)=linearspeed.phi_support(t)linearspeed.support.tau(t)=linearspeed.spline.tau(t)linearspeed.phi(t)=linearspeed.phi_support(t)+linearspeed.spline.phi(t)linearspeed.w(t)=dlinearspeed.phi(t)dtlinearspeed.tau(t)=linearspeed.spline.tau(t)linearspeed.tau(t)=linearspeed.tau_nominal|linearspeed.w(t)linearspeed.w_nominal|inertia2.phi(t)=inertia2.splinea.phi(t)inertia2.phi(t)=inertia2.splineb.phi(t)dinertia2.phi(t)dt=inertia2.w(t)dinertia2.w(t)dt=inertia2.a(t)inertia2.Jinertia2.a(t)=inertia2.splinea.tau(t)+inertia2.splineb.tau(t)quadraticspeed.support.phi(t)=quadraticspeed.phi_support(t)quadraticspeed.support.tau(t)=quadraticspeed.spline.tau(t)quadraticspeed.phi(t)=quadraticspeed.spline.phi(t)quadraticspeed.phi_support(t)quadraticspeed.w(t)=dquadraticspeed.phi(t)dtquadraticspeed.tau(t)=quadraticspeed.spline.tau(t)quadraticspeed.tau(t)=(quadraticspeed.w(t)quadraticspeed.w_nominal)2quadraticspeed.tau_nominalinertia3.phi(t)=inertia3.splinea.phi(t)inertia3.phi(t)=inertia3.splineb.phi(t)dinertia3.phi(t)dt=inertia3.w(t)dinertia3.w(t)dt=inertia3.a(t)inertia3.Jinertia3.a(t)=inertia3.splinea.tau(t)+inertia3.splineb.tau(t)constanttorque.support.phi(t)=constanttorque.phi_support(t)constanttorque.support.tau(t)=constanttorque.spline.tau(t)constanttorque.phi(t)=constanttorque.spline.phi(t)constanttorque.phi_support(t)constanttorque.w(t)=dconstanttorque.phi(t)dtconstanttorque.tau(t)=constanttorque.spline.tau(t)constanttorque.tau(t)=constanttorque.tau_constantinertia4.phi(t)=inertia4.splinea.phi(t)inertia4.phi(t)=inertia4.splineb.phi(t)dinertia4.phi(t)dt=inertia4.w(t)dinertia4.w(t)dt=inertia4.a(t)inertia4.Jinertia4.a(t)=inertia4.splineb.tau(t)+inertia4.splinea.tau(t)signtorque.support.phi(t)=signtorque.phi_support(t)signtorque.support.tau(t)=signtorque.spline.tau(t)signtorque.phi(t)=signtorque.spline.phi(t)signtorque.phi_support(t)signtorque.w(t)=dsigntorque.phi(t)dtsigntorque.tau(t)=signtorque.spline.tau(t)signtorque.tau(t)=signtorque.tau_nominal(1.0+2.01.0+esigntorque.w(t)0.01signtorque.w0)inertia5.phi(t)=inertia5.splinea.phi(t)inertia5.phi(t)=inertia5.splineb.phi(t)dinertia5.phi(t)dt=inertia5.w(t)dinertia5.w(t)dt=inertia5.a(t)inertia5.Jinertia5.a(t)=inertia5.splinea.tau(t)+inertia5.splineb.tau(t)inversespeed.support.phi(t)=inversespeed.phi_support(t)inversespeed.support.tau(t)=inversespeed.spline.tau(t)inversespeed.phi(t)=inversespeed.spline.phi(t)inversespeed.phi_support(t)inversespeed.w(t)=dinversespeed.phi(t)dtinversespeed.tau(t)=inversespeed.spline.tau(t)inversespeed.tau(t)=ifelse(|inversespeed.w(t)|<inversespeed.w0,inversespeed.tau_nominalinversespeed.w_nominalinversespeed.w0,inversespeed.tau_nominalinversespeed.w_nominal|inversespeed.w(t)|)]

Source

dyad
"""
Test for braking torque sources, matching MSL ModelicaTest.Rotational.TestBraking.

Five inertias (J=1) each start at w=100 rad/s and are braked by a different
source. EddyCurrentTorque is omitted (depends on ThermalComponents).

Expected behavior (all with TorqueDirection=true, the default):
  1. LinearSpeedDependentTorque: tau = -|w| → w(t) = 100·exp(-t) → w(2) ≈ 13.534
  2. QuadraticSpeedDependentTorque: tau = -w²/100 → w = 100/(1+t) → w(2) ≈ 33.333
  3. ConstantTorque: tau = -100 → w = 100-100t → w(2) = -100
  4. SignTorque (Exp): tau ≈ -100·sign(w) → brakes to 0, then regularizes near w=0
  5. InverseSpeedDependentTorque: tau = -10000/|w| → w = 100·√(1-2t) → w hits 0 at t=0.5
"""
test component TestBraking
  "Fixed ground for all source supports"
  fixed = RotationalComponents.Components.Fixed() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -90, "y1": 760, "x2": 10, "y2": 860, "rot": 90}
      },
      "tags": []
    }
  }
  "Inertia 1 for linear speed dependent braking"
  inertia1 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 560, "y1": 720, "x2": 660, "y2": 820, "rot": 0}
      },
      "tags": []
    }
  }
  "Linear speed dependent torque (tau_nominal=-100, w_nominal=100)"
  linear_speed = RotationalComponents.Sources.LinearSpeedDependentTorque(tau_nominal = -100, w_nominal = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 190, "y1": 720, "x2": 290, "y2": 820, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 2 for quadratic speed dependent braking"
  inertia2 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 570, "y1": 450, "x2": 670, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Quadratic speed dependent torque (tau_nominal=-100, w_nominal=100)"
  quadratic_speed = RotationalComponents.Sources.QuadraticSpeedDependentTorque(tau_nominal = -100, w_nominal = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 450, "x2": 280, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 3 for constant torque braking"
  inertia3 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 560, "y1": 950, "x2": 660, "y2": 1050, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant torque (tau_constant=-100)"
  constant_torque = RotationalComponents.Sources.ConstantTorque(tau_constant = -100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 190, "y1": 950, "x2": 290, "y2": 1050, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 4 for sign torque braking"
  inertia4 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 560, "y1": 200, "x2": 660, "y2": 300, "rot": 0}
      },
      "tags": []
    }
  }
  "Sign torque with Exp regularization (tau_nominal=-100, w0=1)"
  sign_torque = RotationalComponents.Sources.SignTorque(tau_nominal = -100, w0 = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 200, "x2": 280, "y2": 300, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 5 for inverse speed dependent braking"
  inertia5 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 550, "y1": 0, "x2": 650, "y2": 100, "rot": 0}
      },
      "tags": []
    }
  }
  "Inverse speed dependent torque (tau_nominal=-100, w_nominal=100, w0=1)"
  inverse_speed = RotationalComponents.Sources.InverseSpeedDependentTorque(tau_nominal = -100, w_nominal = 100, w0 = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 0, "x2": 280, "y2": 100, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial inertia1.phi = 0
  initial inertia1.w = 100
  initial inertia2.phi = 0
  initial inertia2.w = 100
  initial inertia3.phi = 0
  initial inertia3.w = 100
  initial inertia4.phi = 0
  initial inertia4.w = 100
  initial inertia5.phi = 0
  initial inertia5.w = 100
  connect(inertia1.spline_b, linear_speed.spline) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(linear_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 240, "y": 870}, {"x": 50, "y": 870}], "E": -1},
        {"S": -1, "M": [{"x": 50, "y": 810}], "E": 2}
      ],
      "junctions": [{"x": 50, "y": 750}],
      "renderStyle": "standard"
    }
  }
  connect(inertia2.spline_b, quadratic_speed.spline) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(quadratic_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 230, "y": 670}, {"x": 50, "y": 670}, {"x": 50, "y": 810}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(inertia3.spline_b, constant_torque.spline) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(constant_torque.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 240, "y": 1120}, {"x": 50, "y": 1120}, {"x": 50, "y": 810}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(inertia4.spline_b, sign_torque.spline) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sign_torque.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 230, "y": 380}, {"x": 50, "y": 380}], "E": -1},
        {"S": -1, "M": [{"x": 50, "y": 810}], "E": 2}
      ],
      "junctions": [{"x": 50, "y": 500}],
      "renderStyle": "standard"
    }
  }
  connect(inertia5.spline_b, inverse_speed.spline) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(inverse_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 230, "y": 160}, {"x": 50, "y": 160}, {"x": 50, "y": 810}],
          "E": -1
        },
        {"S": -1, "M": [], "E": 2}
      ],
      "junctions": [{"x": 20, "y": 810}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://RotationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 2,
        "abstol": 1e-8,
        "reltol": 1e-8,
        "atol": {"inertia1.w": 0.01, "inertia2.w": 0.01, "inertia3.w": 0.01},
        "expect": {
          "initial": {
            "inertia1.w": 100,
            "inertia2.w": 100,
            "inertia3.w": 100,
            "inertia4.w": 100,
            "inertia5.w": 100,
            "inertia1.phi": 0,
            "inertia2.phi": 0,
            "inertia3.phi": 0,
            "inertia4.phi": 0,
            "inertia5.phi": 0
          },
          "final": {"inertia1.w": 13.534, "inertia2.w": 33.333, "inertia3.w": -100},
          "signals": ["inertia1.w", "inertia2.w", "inertia3.w", "inertia4.w", "inertia5.w"]
        }
      }
    }
  }
}
end
Flattened Source
dyad
"""
Test for braking torque sources, matching MSL ModelicaTest.Rotational.TestBraking.

Five inertias (J=1) each start at w=100 rad/s and are braked by a different
source. EddyCurrentTorque is omitted (depends on ThermalComponents).

Expected behavior (all with TorqueDirection=true, the default):
  1. LinearSpeedDependentTorque: tau = -|w| → w(t) = 100·exp(-t) → w(2) ≈ 13.534
  2. QuadraticSpeedDependentTorque: tau = -w²/100 → w = 100/(1+t) → w(2) ≈ 33.333
  3. ConstantTorque: tau = -100 → w = 100-100t → w(2) = -100
  4. SignTorque (Exp): tau ≈ -100·sign(w) → brakes to 0, then regularizes near w=0
  5. InverseSpeedDependentTorque: tau = -10000/|w| → w = 100·√(1-2t) → w hits 0 at t=0.5
"""
test component TestBraking
  "Fixed ground for all source supports"
  fixed = RotationalComponents.Components.Fixed() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": -90, "y1": 760, "x2": 10, "y2": 860, "rot": 90}
      },
      "tags": []
    }
  }
  "Inertia 1 for linear speed dependent braking"
  inertia1 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 560, "y1": 720, "x2": 660, "y2": 820, "rot": 0}
      },
      "tags": []
    }
  }
  "Linear speed dependent torque (tau_nominal=-100, w_nominal=100)"
  linear_speed = RotationalComponents.Sources.LinearSpeedDependentTorque(tau_nominal = -100, w_nominal = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 190, "y1": 720, "x2": 290, "y2": 820, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 2 for quadratic speed dependent braking"
  inertia2 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 570, "y1": 450, "x2": 670, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Quadratic speed dependent torque (tau_nominal=-100, w_nominal=100)"
  quadratic_speed = RotationalComponents.Sources.QuadraticSpeedDependentTorque(tau_nominal = -100, w_nominal = 100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 450, "x2": 280, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 3 for constant torque braking"
  inertia3 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 560, "y1": 950, "x2": 660, "y2": 1050, "rot": 0}
      },
      "tags": []
    }
  }
  "Constant torque (tau_constant=-100)"
  constant_torque = RotationalComponents.Sources.ConstantTorque(tau_constant = -100) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 190, "y1": 950, "x2": 290, "y2": 1050, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 4 for sign torque braking"
  inertia4 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 560, "y1": 200, "x2": 660, "y2": 300, "rot": 0}
      },
      "tags": []
    }
  }
  "Sign torque with Exp regularization (tau_nominal=-100, w0=1)"
  sign_torque = RotationalComponents.Sources.SignTorque(tau_nominal = -100, w0 = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 200, "x2": 280, "y2": 300, "rot": 0}
      },
      "tags": []
    }
  }
  "Inertia 5 for inverse speed dependent braking"
  inertia5 = RotationalComponents.Components.Inertia(J = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 550, "y1": 0, "x2": 650, "y2": 100, "rot": 0}
      },
      "tags": []
    }
  }
  "Inverse speed dependent torque (tau_nominal=-100, w_nominal=100, w0=1)"
  inverse_speed = RotationalComponents.Sources.InverseSpeedDependentTorque(tau_nominal = -100, w_nominal = 100, w0 = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 180, "y1": 0, "x2": 280, "y2": 100, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial inertia1.phi = 0
  initial inertia1.w = 100
  initial inertia2.phi = 0
  initial inertia2.w = 100
  initial inertia3.phi = 0
  initial inertia3.w = 100
  initial inertia4.phi = 0
  initial inertia4.w = 100
  initial inertia5.phi = 0
  initial inertia5.w = 100
  connect(inertia1.spline_b, linear_speed.spline) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(linear_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 240, "y": 870}, {"x": 50, "y": 870}], "E": -1},
        {"S": -1, "M": [{"x": 50, "y": 810}], "E": 2}
      ],
      "junctions": [{"x": 50, "y": 750}],
      "renderStyle": "standard"
    }
  }
  connect(inertia2.spline_b, quadratic_speed.spline) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(quadratic_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 230, "y": 670}, {"x": 50, "y": 670}, {"x": 50, "y": 810}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(inertia3.spline_b, constant_torque.spline) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(constant_torque.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 240, "y": 1120}, {"x": 50, "y": 1120}, {"x": 50, "y": 810}],
          "E": 2
        }
      ],
      "renderStyle": "standard"
    }
  }
  connect(inertia4.spline_b, sign_torque.spline) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(sign_torque.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 230, "y": 380}, {"x": 50, "y": 380}], "E": -1},
        {"S": -1, "M": [{"x": 50, "y": 810}], "E": 2}
      ],
      "junctions": [{"x": 50, "y": 500}],
      "renderStyle": "standard"
    }
  }
  connect(inertia5.spline_b, inverse_speed.spline) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(inverse_speed.support, fixed.spline) {
    "Dyad": {
      "edges": [
        {
          "S": 1,
          "M": [{"x": 230, "y": 160}, {"x": 50, "y": 160}, {"x": 50, "y": 810}],
          "E": -1
        },
        {"S": -1, "M": [], "E": 2}
      ],
      "junctions": [{"x": 20, "y": 810}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://RotationalComponents/Example.svg"},
    "tests": {
      "case1": {
        "stop": 2,
        "abstol": 1e-8,
        "reltol": 1e-8,
        "atol": {"inertia1.w": 0.01, "inertia2.w": 0.01, "inertia3.w": 0.01},
        "expect": {
          "initial": {
            "inertia1.w": 100,
            "inertia2.w": 100,
            "inertia3.w": 100,
            "inertia4.w": 100,
            "inertia5.w": 100,
            "inertia1.phi": 0,
            "inertia2.phi": 0,
            "inertia3.phi": 0,
            "inertia4.phi": 0,
            "inertia5.phi": 0
          },
          "final": {"inertia1.w": 13.534, "inertia2.w": 33.333, "inertia3.w": -100},
          "signals": ["inertia1.w", "inertia2.w", "inertia3.w", "inertia4.w", "inertia5.w"]
        }
      }
    }
  }
}
end


Test Cases

Test Case case1

julia
plt

julia
plt

julia
plt

julia
plt

julia
plt