-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add translational library #85
Changes from 2 commits
f43ff5e
28bbdb8
9b58673
f48821d
d4020e1
2f6bb42
68a81ab
4fbee98
c8c29a2
ae11458
6f4bd5a
02e3a6b
9476eba
af6e08f
f7f188e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"type": "julia", | ||
"request": "launch", | ||
"name": "Run active Julia file", | ||
"program": "${file}", | ||
"stopOnEntry": false, | ||
"cwd": "${workspaceFolder}", | ||
"juliaEnv": "${command:activeJuliaEnvironment}" | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,19 @@ | ||||||
module Translational | ||||||
|
||||||
using ModelingToolkit, Symbolics, IfElse, OrdinaryDiffEq | ||||||
using OffsetArrays | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove not needed packages |
||||||
using ...Blocks: RealInput, RealOutput | ||||||
|
||||||
@parameters t | ||||||
D = Differential(t) | ||||||
|
||||||
export Flange | ||||||
include("utils.jl") | ||||||
|
||||||
export Fixed, Inertia, Spring, Damper, IdealGear | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
include("components.jl") | ||||||
|
||||||
export Force | ||||||
include("sources.jl") | ||||||
|
||||||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
function Fixed(; name, s0=0.0) | ||
@named flange = Flange() | ||
@parameters s0 = s0 | ||
eqs = [flange.s ~ s0] | ||
return compose(ODESystem(eqs, t, [], [s0]; name=name), flange) | ||
end | ||
|
||
function Mass(; name, m, s_start=0.0, v_start=0.0, a_start=0.0) | ||
@named flange_a = Flange() | ||
@named flange_b = Flange() | ||
@parameters m = m | ||
sts = @variables begin | ||
s(t) = s_start | ||
v(t) = v_start | ||
a(t) = a_start | ||
end | ||
eqs = [ | ||
s ~ flange_a.s | ||
s ~ flange_b.s | ||
D(s) ~ v | ||
D(v) ~ a | ||
m * a ~ flange_a.f + flange_b.f | ||
] | ||
return compose(ODESystem(eqs, t, sts, [m]; name=name), flange_a, flange_b) | ||
end | ||
|
||
function Spring(; name, c, s_rel0=0.0) | ||
@named partial_comp = PartialCompliant() | ||
@unpack s_rel, f = partial_comp | ||
pars = @parameters begin | ||
c = c | ||
s_rel0 = s_rel0 | ||
end | ||
eqs = [f ~ c * (s_rel - s_rel0)] | ||
extend(ODESystem(eqs, t, [], pars; name=name), partial_comp) | ||
end | ||
|
||
function Damper(; name, d) | ||
@named partial_comp = PartialCompliantWithRelativeStates() | ||
@unpack v_rel, f = partial_comp | ||
pars = @parameters d = d | ||
eqs = [f ~ d * v_rel] | ||
extend(ODESystem(eqs, t, [], pars; name=name), partial_comp) | ||
end | ||
|
||
function IdealGear(; name, ratio, use_support=false) | ||
@named partial_element = PartialElementaryTwoFlangesAndSupport2(use_support=use_support) | ||
@unpack s_support, flange_a, flange_b = partial_element | ||
@parameters ratio = ratio | ||
sts = @variables s_a(t) = 0.0 s_b(t) = 0.0 | ||
eqs = [ | ||
s_a ~ flange_a.s - s_support | ||
s_b ~ flange_b.s - s_support | ||
s_a ~ ratio * s_b | ||
0 ~ ratio * flange_a.f + flange_b.f | ||
] | ||
extend(ODESystem(eqs, t, sts, [ratio]; name=name), partial_element) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function Force(; name, use_support=false) | ||
@named partial_element = PartialElementaryOneFlangeAndSupport2(use_support=use_support) | ||
@unpack flange = partial_element | ||
@named f = RealInput() # Accelerating torque acting at flange (= -flange.tau) | ||
eqs = [flange.f ~ -f.u] | ||
return extend(ODESystem(eqs, t, [], []; name=name, systems=[f]), partial_element) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
@connector function Flange(; name) | ||
sts = @variables begin | ||
s(t) | ||
f(t), [connect = Flow] | ||
end | ||
ODESystem(Equation[], t, sts, [], name=name, defaults=Dict(s => 0.0, f => 0.0)) | ||
end | ||
|
||
@connector function Support(; name) | ||
sts = @variables begin | ||
s(t) | ||
f(t), [connect = Flow] | ||
end | ||
ODESystem(Equation[], t, sts, [], name=name, defaults=Dict(s => 0.0, f => 0.0)) | ||
end | ||
|
||
function PartialCompliant(; name, s_rel_start=0.0, f_start=0.0) | ||
@named flange_a = Flange() | ||
@named flange_b = Flange() | ||
sts = @variables begin | ||
s_rel(t) = s_rel_start | ||
f(t) = f_start | ||
end | ||
eqs = [ | ||
s_rel ~ flange_b.s - flange_a.s | ||
flange_b.f ~ f | ||
flange_a.f ~ -f | ||
] | ||
return compose(ODESystem(eqs, t, sts, []; name=name), flange_a, flange_b) | ||
end | ||
|
||
function PartialCompliantWithRelativeStates(; name, s_rel_start=0.0, v_start=0.0, a_start=0.0, f_start=0.0) | ||
@named flange_a = Flange() | ||
@named flange_b = Flange() | ||
sts = @variables begin | ||
s_rel(t) = s_rel_start | ||
v_rel(t) = v_start | ||
a_rel(t) = a_start | ||
f(t) = f_start | ||
end | ||
eqs = [ | ||
s_rel ~ flange_b.s - flange_a.s | ||
D(s_rel) ~ v_rel | ||
D(v_rel) ~ a_rel | ||
flange_b.f ~ f | ||
flange_a.f ~ -f | ||
] | ||
return compose(ODESystem(eqs, t, sts, []; name=name), flange_a, flange_b) | ||
end | ||
|
||
function PartialElementaryOneFlangeAndSupport2(; name, use_support=false) | ||
@named flange = Flange() | ||
sys = [flange] | ||
@variables s_support(t) | ||
if use_support | ||
@named support = Support() | ||
eqs = [ | ||
support.s ~ s_support | ||
support.f ~ -flange.f | ||
] | ||
push!(sys, support) | ||
else | ||
eqs = [s_support ~ 0] | ||
end | ||
return compose(ODESystem(eqs, t, [s_support], []; name=name), sys) | ||
end | ||
|
||
function PartialElementaryTwoFlangesAndSupport2(; name, use_support=false) | ||
@named flange_a = Flange() | ||
@named flange_b = Flange() | ||
sys = [flange_a, flange_b] | ||
@variables s_support(t) = 0.0 | ||
if use_support | ||
@named support = Support() | ||
eqs = [ | ||
support.s ~ s_support | ||
support.f ~ -flange_a.f - flange_b.f | ||
] | ||
push!(sys, support) | ||
else | ||
eqs = [s_support ~ 0] | ||
end | ||
return compose(ODESystem(eqs, t, [s_support], []; name=name), sys) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import ModelingToolkitStandardLibrary.Blocks | ||
include("/Users/kianmolani/Documents/Project Files/Codebases/ModelingToolkitStandardLibrary.jl/src/Mechanical/Translational/Translational.jl") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should be removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can I add the Translational module to the package and be able to import it using |
||
using ModelingToolkit, OrdinaryDiffEq, Test | ||
using Plots | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't import Plots in test. CI cannot actually see plots. |
||
|
||
@parameters t | ||
D = Differential(t) | ||
|
||
function fixed_mass_damper_system() | ||
m = 1 # mass of sliding mass | ||
L = 1 # length of mass, from left flange to right flange (undefined) | ||
s_start = 3 # absolute position of sliding mass (ought to be of component center, if L were defined) | ||
v_start = 10 # absolute velocity of sliding mass | ||
d = 25 # damping constant of damper (expressed here in units of N*s/m) | ||
s0 = 4.5 # fixed offset position of housing | ||
|
||
@named fixed = Main.Translational.Fixed(s0=s0) | ||
@named mass = Main.Translational.Mass(m=m, s_start=s_start, v_start=v_start) | ||
@named damper = Main.Translational.Damper(d=d) | ||
|
||
connections = [ | ||
connect(mass.flange_b, damper.flange_a) | ||
connect(damper.flange_b, fixed.flange) | ||
] | ||
|
||
@named model = ODESystem(connections, t, systems=[fixed, mass, damper]) | ||
sys = structural_simplify(model) | ||
prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, [D(D(mass.s)) => 1.0], (0, 1.0)) | ||
sol = solve(prob, DFBDF()) | ||
|
||
display(Plots.plot(sol; vars=[mass.s])) | ||
display(Plots.plot(sol; vars=[mass.v])) | ||
display(Plots.plot(sol; vars=[mass.a])) | ||
end | ||
|
||
fixed_mass_damper_system() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can add
.vscode
and.DS_Store
in global git ignore setting. Check out https://sebastiandedeyne.com/setting-up-a-global-gitignore-file/