Skip to content
LIBRARY
PlanarMechanics.WorldForceTest.md

PlanarMechanics.WorldForceTest

Test for WorldForceTorque: a damped pendulum with an applied sinusoidal force.

Topology: Fixed → Revolute → FixedTranslation → Body A WorldForceTorque applies a sinusoidal force in x-direction to the body. A Damper stabilizes the revolute joint.

Translated from PlanarMechanicsTest.Sources.WorldForce.

Usage

MultibodyComponents.PlanarMechanics.WorldForceTest()

Behavior

julia
using MultibodyComponents #hide
using ModelingToolkit #hide
@named sys = MultibodyComponents.PlanarMechanics.WorldForceTest() #hide
full_equations(sys) #hide
<< @example-block not executed in draft mode >>

Source

dyad
"""
Test for WorldForceTorque: a damped pendulum with an applied sinusoidal force.

Topology: Fixed → Revolute → FixedTranslation → Body
A WorldForceTorque applies a sinusoidal force in x-direction to the body.
A Damper stabilizes the revolute joint.

Translated from PlanarMechanicsTest.Sources.WorldForce.
"""
test component WorldForceTest
  world = World() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  revolute = Revolute() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 295, "y1": 20, "x2": 395, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  rod = FixedTranslation(r = [0, -1]) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 415, "y1": 20, "x2": 515, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  body = Body(m = 1, I = 0.1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 295, "y1": 150, "x2": 395, "y2": 250, "rot": 0}
      },
      "tags": []
    }
  }
  damper = MultibodyComponents.PlanarMechanics.Damper(d = 1) {
    "Dyad": {
      "placement": {
        "diagram": {
          "iconName": "default",
          "x1": 167.5,
          "y1": 150,
          "x2": 267.5,
          "y2": 250,
          "rot": 0
        }
      },
      "tags": []
    }
  }
  force = WorldForceTorque(resolve_in_frame = MultibodyComponents.ResolveInFrame.World(), scale = 0.5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 165, "y1": 270, "x2": 265, "y2": 370, "rot": 0}
      },
      "tags": []
    }
  }
  sine_x = BlockComponents.Sources.Sine(amplitude = 1, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 150, "x2": 120, "y2": 250, "rot": 0}
      },
      "tags": []
    }
  }
  zero_y = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 270, "x2": 120, "y2": 370, "rot": 0}
      },
      "tags": []
    }
  }
  zero_tau = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 390, "x2": 120, "y2": 490, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial revolute.phi = 0
  initial revolute.w = 0
  connect(world.frame_b, revolute.frame_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(revolute.frame_b, rod.frame_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(rod.frame_b, body.frame_a) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 525, "y": 70}, {"x": 525, "y": 300}], "E": -1},
        {"S": -1, "M": [], "E": -2},
        {"S": -2, "M": [], "E": 2}
      ],
      "junctions": [{"x": 285, "y": 300}, {"x": 285, "y": 200}],
      "renderStyle": "standard"
    }
  }
  connect(body.frame_a, force.frame_b) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 285, "y": 200}, {"x": 285, "y": 320}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(sine_x.y, force.force_x) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 200}, {"x": 140, "y": 285}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(zero_y.y, force.force_y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(zero_tau.y, force.torque) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 440}, {"x": 140, "y": 353}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(world.frame_b, damper.frame_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 150, "y": 200}], "E": 2}],
      "junctions": [{"x": 150, "y": 70}],
      "renderStyle": "standard"
    }
  }
  connect(body.frame_a, damper.frame_b) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {"Dyad": {"tests": {"case1": {"stop": 3}}}}
end
Flattened Source
dyad
"""
Test for WorldForceTorque: a damped pendulum with an applied sinusoidal force.

Topology: Fixed → Revolute → FixedTranslation → Body
A WorldForceTorque applies a sinusoidal force in x-direction to the body.
A Damper stabilizes the revolute joint.

Translated from PlanarMechanicsTest.Sources.WorldForce.
"""
test component WorldForceTest
  world = World() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 20, "x2": 120, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  revolute = Revolute() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 295, "y1": 20, "x2": 395, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  rod = FixedTranslation(r = [0, -1]) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 415, "y1": 20, "x2": 515, "y2": 120, "rot": 0}
      },
      "tags": []
    }
  }
  body = Body(m = 1, I = 0.1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 295, "y1": 150, "x2": 395, "y2": 250, "rot": 0}
      },
      "tags": []
    }
  }
  damper = MultibodyComponents.PlanarMechanics.Damper(d = 1) {
    "Dyad": {
      "placement": {
        "diagram": {
          "iconName": "default",
          "x1": 167.5,
          "y1": 150,
          "x2": 267.5,
          "y2": 250,
          "rot": 0
        }
      },
      "tags": []
    }
  }
  force = WorldForceTorque(resolve_in_frame = MultibodyComponents.ResolveInFrame.World(), scale = 0.5) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 165, "y1": 270, "x2": 265, "y2": 370, "rot": 0}
      },
      "tags": []
    }
  }
  sine_x = BlockComponents.Sources.Sine(amplitude = 1, frequency = 1) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 150, "x2": 120, "y2": 250, "rot": 0}
      },
      "tags": []
    }
  }
  zero_y = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 270, "x2": 120, "y2": 370, "rot": 0}
      },
      "tags": []
    }
  }
  zero_tau = BlockComponents.Sources.Constant(k = 0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 390, "x2": 120, "y2": 490, "rot": 0}
      },
      "tags": []
    }
  }
relations
  initial revolute.phi = 0
  initial revolute.w = 0
  connect(world.frame_b, revolute.frame_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(revolute.frame_b, rod.frame_a) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(rod.frame_b, body.frame_a) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [{"x": 525, "y": 70}, {"x": 525, "y": 300}], "E": -1},
        {"S": -1, "M": [], "E": -2},
        {"S": -2, "M": [], "E": 2}
      ],
      "junctions": [{"x": 285, "y": 300}, {"x": 285, "y": 200}],
      "renderStyle": "standard"
    }
  }
  connect(body.frame_a, force.frame_b) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 285, "y": 200}, {"x": 285, "y": 320}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(sine_x.y, force.force_x) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 200}, {"x": 140, "y": 285}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(zero_y.y, force.force_y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
  connect(zero_tau.y, force.torque) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 140, "y": 440}, {"x": 140, "y": 353}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(world.frame_b, damper.frame_a) {
    "Dyad": {
      "edges": [{"S": 1, "M": [], "E": -1}, {"S": -1, "M": [{"x": 150, "y": 200}], "E": 2}],
      "junctions": [{"x": 150, "y": 70}],
      "renderStyle": "standard"
    }
  }
  connect(body.frame_a, damper.frame_b) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {"Dyad": {"tests": {"case1": {"stop": 3}}}}
end


Test Cases

julia
using MultibodyComponents
using DyadInterface: TransientAnalysis, rebuild_sol, ODEAlg
using ModelingToolkit: toggle_namespacing, get_initial_conditions, @named
using CSV, DataFrames, Plots

snapshotsdir = joinpath(dirname(dirname(pathof(MultibodyComponents))), "test", "snapshots")
<< @setup-block not executed in draft mode >>

Test Case case1

julia
@named model_case1 = MultibodyComponents.PlanarMechanics.WorldForceTest()
model_case1 = toggle_namespacing(model_case1, false)

model_case1 = toggle_namespacing(model_case1, true)
result_case1 = TransientAnalysis(; model = model_case1, alg = ODEAlg.Auto(), start = 0e+0, stop = 3e+0, abstol=1e-6, reltol=1e-6)
sol_case1 = rebuild_sol(result_case1)
<< @setup-block not executed in draft mode >>