TwoInertiasWithDrivingTorque
A mechanical system of two rotational inertias coupled by a spring and damper, driven by a sinusoidal torque.
This model represents a dynamic system where a primary rotational inertia (inertia1) is subjected to an external torque generated by a sinusoidal source. This first inertia is mechanically coupled to a second rotational inertia (inertia2) through a torsional spring and a torsional damper, which are arranged in parallel. The torque source is referenced to a fixed ground. Initial conditions for angular positions, and implicitly angular velocities through the initial acceleration constraint, define the starting state of the system.
Usage
TwoInertiasWithDrivingTorque()
Behavior
Source
dyad
# A mechanical system of two rotational inertias coupled by a spring and damper, driven by a sinusoidal torque.
#
# This model represents a dynamic system where a primary rotational inertia
# (inertia1) is subjected to an external torque generated by a sinusoidal source.
# This first inertia is mechanically coupled to a second rotational inertia
# (inertia2) through a torsional spring and a torsional damper, which are arranged
# in parallel. The torque source is referenced to a fixed ground.
# Initial conditions for angular positions, and implicitly angular velocities
# through the initial acceleration constraint, define the starting state of the system.
test component TwoInertiasWithDrivingTorque
# Represents a fixed mechanical ground or reference frame.
fixed = Fixed()
# Source that applies a torque to the system, driven by an external signal.
torque = TorqueSource()
# First rotational inertia with moment of inertia J=2 kg.m^2.
inertia1 = Inertia(J=2)
# Second rotational inertia with moment of inertia J=4 kg.m^2.
inertia2 = Inertia(J=4)
# Torsional spring connecting the two inertias, with spring constant c=1e4 N.m/rad.
spring = Spring(c=1e4)
# Torsional damper in parallel with the spring, with damping coefficient d=10 N.m.s/rad.
damper = Damper(d=10)
# Generates a sinusoidal signal for the driving torque, with amplitude=10 and frequency=5 Hz.
sine = BlockComponents.Sine(amplitude=10, frequency=5)
relations
initial inertia1.phi = 1
initial inertia2.phi = 0.5
initial inertia2.a = 0
connect(sine.y, torque.tau)
connect(torque.support, fixed.spline)
connect(torque.spline, inertia1.spline_a)
connect(inertia1.spline_b, spring.spline_a, damper.spline_a)
connect(spring.spline_b, damper.spline_b, inertia2.spline_a)
metadata {
"Dyad": {
"tests": {
"case1": {
"stop": 1,
"expect": {
"initial": {"inertia1.phi": 1, "inertia2.phi": 0.5, "inertia1.w": -500, "inertia2.w ": 0}
}
}
}
}
}
end
Flattened Source
dyad
# A mechanical system of two rotational inertias coupled by a spring and damper, driven by a sinusoidal torque.
#
# This model represents a dynamic system where a primary rotational inertia
# (inertia1) is subjected to an external torque generated by a sinusoidal source.
# This first inertia is mechanically coupled to a second rotational inertia
# (inertia2) through a torsional spring and a torsional damper, which are arranged
# in parallel. The torque source is referenced to a fixed ground.
# Initial conditions for angular positions, and implicitly angular velocities
# through the initial acceleration constraint, define the starting state of the system.
test component TwoInertiasWithDrivingTorque
# Represents a fixed mechanical ground or reference frame.
fixed = Fixed()
# Source that applies a torque to the system, driven by an external signal.
torque = TorqueSource()
# First rotational inertia with moment of inertia J=2 kg.m^2.
inertia1 = Inertia(J=2)
# Second rotational inertia with moment of inertia J=4 kg.m^2.
inertia2 = Inertia(J=4)
# Torsional spring connecting the two inertias, with spring constant c=1e4 N.m/rad.
spring = Spring(c=1e4)
# Torsional damper in parallel with the spring, with damping coefficient d=10 N.m.s/rad.
damper = Damper(d=10)
# Generates a sinusoidal signal for the driving torque, with amplitude=10 and frequency=5 Hz.
sine = BlockComponents.Sine(amplitude=10, frequency=5)
relations
initial inertia1.phi = 1
initial inertia2.phi = 0.5
initial inertia2.a = 0
connect(sine.y, torque.tau)
connect(torque.support, fixed.spline)
connect(torque.spline, inertia1.spline_a)
connect(inertia1.spline_b, spring.spline_a, damper.spline_a)
connect(spring.spline_b, damper.spline_b, inertia2.spline_a)
metadata {
"Dyad": {
"tests": {
"case1": {
"stop": 1,
"expect": {
"initial": {"inertia1.phi": 1, "inertia2.phi": 0.5, "inertia1.w": -500, "inertia2.w ": 0}
}
}
}
}
}
end
Test Cases
This is setup code, that must be run before each test case.
julia
using RotationalComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames
snapshotsdir = joinpath(dirname(dirname(pathof(RotationalComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/RotationalComponents/0VPxm/test/snapshots"
Test Case case1
julia
@mtkbuild model_case1 = TwoInertiasWithDrivingTorque()
u0_case1 = []
prob_case1 = ODEProblem(model_case1, u0_case1, (0, 1))
sol_case1 = solve(prob_case1)
retcode: Success
Interpolation: 3rd order Hermite
t: 85-element Vector{Float64}:
0.0
0.001741101126589462
0.004219151423183404
0.007390864690109434
0.011322960645592586
0.015896047994834458
0.020955577415067525
0.02747487111254223
0.033626680113946
0.04109101569458323
⋮
0.9304547216375303
0.9396185689845381
0.9496806215701978
0.9595166735894302
0.9671742935600001
0.9762955183064588
0.9861108909071538
0.9962774736550695
1.0
u: 85-element Vector{Vector{Float64}}:
[0.5, 1.0, -0.0, -500.0]
[0.4989052349941844, 0.1316391048747763, -1.8828569522820653, -496.2340480665899]
[0.4845789392409978, -1.0787316255265904, -10.887648273020629, -478.2233073936973]
[0.4187186117814805, -2.5328590275740974, -32.39365247078328, -435.2084240704959]
[0.2176930137676368, -4.096828584375997, -71.89733672908721, -356.1953627306581]
[-0.23955971781536456, -5.46880070877337, -129.49468675523957, -240.99118973836]
[-1.0667244288415147, -6.344104100049989, -197.14929701800887, -105.66814410899657]
[-2.6057053121857585, -6.52550183337916, -270.66772021991585, 41.39113700716393]
[-4.405446612131925, -6.001505473451473, -308.16480553726495, 116.41046213612312]
[-6.711992508605791, -5.11985191790964, -299.9408977757787, 99.99698487088443]
⋮
[-154.42544770878945, -154.2242290591094, -165.1518846818742, -169.44496370176682]
[-155.92212534071598, -155.81067983722372, -161.70706560013207, -176.3754510247057]
[-157.54545452781116, -157.59317912706567, -161.30098852090114, -177.23720639613833]
[-159.14569489408223, -159.30938308379544, -164.28919189745494, -171.30946755480207]
[-160.41670649649814, -160.59544627877116, -167.6680191357831, -164.58678505084706]
[-161.96114351739865, -162.06664538585008, -170.8046956163836, -158.34881309421922]
[-163.64202034800542, -163.61230733249562, -171.40596090840387, -157.1736081145332]
[-165.37291602040156, -165.23373775280427, -168.89554858495282, -162.20831664129014]
[-165.99900204853537, -165.8428290590023, -167.472359729937, -165.0557820733616]