Skip to content

new format rules #184

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

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ V = 1.0
@named ground = Ground()

rc_eqs = [connect(constant.output, source.V)
connect(source.p, resistor.p)
connect(resistor.n, capacitor.p)
connect(capacitor.n, source.n, ground.g)]
connect(source.p, resistor.p)
connect(resistor.n, capacitor.p)
connect(capacitor.n, source.n, ground.g)]

@named rc_model = ODESystem(rc_eqs, t,
systems = [resistor, capacitor, constant, source, ground])
systems = [resistor, capacitor, constant, source, ground])
sys = structural_simplify(rc_model)
prob = ODEProblem(sys, Pair[], (0, 10.0))
sol = solve(prob, Tsit5())
plot(sol, idxs = [capacitor.v, resistor.i],
title = "RC Circuit Demonstration",
labels = ["Capacitor Voltage" "Resistor Current"])
title = "RC Circuit Demonstration",
labels = ["Capacitor Voltage" "Resistor Current"])
savefig("plot.png")
```

Expand Down
48 changes: 24 additions & 24 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ ENV["GKSwstype"] = "100"
include("pages.jl")

makedocs(sitename = "ModelingToolkitStandardLibrary.jl",
authors = "Julia Computing",
clean = true,
doctest = false,
linkcheck = true,
strict = [
:linkcheck,
:doctest,
:example_block,
],
modules = [ModelingToolkit,
ModelingToolkitStandardLibrary,
ModelingToolkitStandardLibrary.Blocks,
ModelingToolkitStandardLibrary.Mechanical,
ModelingToolkitStandardLibrary.Mechanical.Rotational,
ModelingToolkitStandardLibrary.Magnetic,
ModelingToolkitStandardLibrary.Magnetic.FluxTubes,
ModelingToolkitStandardLibrary.Electrical,
ModelingToolkitStandardLibrary.Thermal,
ModelingToolkitStandardLibrary.Hydraulic,
ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible],
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/"),
pages = pages)
authors = "Julia Computing",
clean = true,
doctest = false,
linkcheck = true,
strict = [
:linkcheck,
:doctest,
:example_block,
],
modules = [ModelingToolkit,
ModelingToolkitStandardLibrary,
ModelingToolkitStandardLibrary.Blocks,
ModelingToolkitStandardLibrary.Mechanical,
ModelingToolkitStandardLibrary.Mechanical.Rotational,
ModelingToolkitStandardLibrary.Magnetic,
ModelingToolkitStandardLibrary.Magnetic.FluxTubes,
ModelingToolkitStandardLibrary.Electrical,
ModelingToolkitStandardLibrary.Thermal,
ModelingToolkitStandardLibrary.Hydraulic,
ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible],
format = Documenter.HTML(assets = ["assets/favicon.ico"],
canonical = "https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/"),
pages = pages)

deploydocs(repo = "github.com/SciML/ModelingToolkitStandardLibrary.jl";
push_preview = true)
push_preview = true)
4 changes: 2 additions & 2 deletions docs/src/API/linear_analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ using ModelingToolkitStandardLibrary.Blocks, ModelingToolkit
@named C = Gain(-1) # A P controller
t = ModelingToolkit.get_iv(P)
eqs = [connect(P.output, :plant_output, C.input) # Connect with an automatically created analysis point called :plant_output
connect(C.output, :plant_input, P.input)]
connect(C.output, :plant_input, P.input)]
sys = ODESystem(eqs, t, systems = [P, C], name = :feedback_system)

matrices_S = get_sensitivity(sys, :plant_input)[1] # Compute the matrices of a state-space representation of the (input)sensitivity function.
Expand All @@ -75,7 +75,7 @@ using ControlSystemsBase, Plots
S = ss(matrices_S...)
T = ss(matrices_T...)
bodeplot([S, T], lab = ["S" "" "T" ""], plot_title = "Bode plot of sensitivity functions",
margin = 5Plots.mm)
margin = 5Plots.mm)
```

The sensitivity functions obtained this way should be equivalent to the ones obtained with the code below
Expand Down
10 changes: 5 additions & 5 deletions docs/src/connectors/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ using Plots
@named ground = Ground()

eqs = [connect(capacitor.p, resistor.p)
connect(resistor.n, ground.g, capacitor.n)]
connect(resistor.n, ground.g, capacitor.n)]

@named model = ODESystem(eqs, t; systems = [resistor, capacitor, ground])

Expand Down Expand Up @@ -139,7 +139,7 @@ const TV = ModelingToolkitStandardLibrary.Mechanical.Translational
@named ground = TV.Fixed()

eqs = [connect(damping.flange_a, body.flange)
connect(ground.flange, damping.flange_b)]
connect(ground.flange, damping.flange_b)]

@named model = ODESystem(eqs, t; systems = [damping, body, ground])

Expand Down Expand Up @@ -172,7 +172,7 @@ const TP = ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition
@named ground = TP.Fixed(s_0 = 0)

eqs = [connect(damping.flange_a, body.flange)
connect(ground.flange, damping.flange_b)]
connect(ground.flange, damping.flange_b)]

@named model = ODESystem(eqs, t; systems = [damping, body, ground])

Expand Down Expand Up @@ -267,7 +267,7 @@ Let's define a quick function to simplify and solve the 2 different systems. Not
```@example connections
function simplify_and_solve(damping, spring, body, ground)
eqs = [connect(spring.flange_a, body.flange, damping.flange_a)
connect(spring.flange_b, damping.flange_b, ground.flange)]
connect(spring.flange_b, damping.flange_b, ground.flange)]

@named model = ODESystem(eqs, t; systems = [ground, body, spring, damping])

Expand Down Expand Up @@ -345,7 +345,7 @@ Which means both systems are actually solving the same exact system. We can plo

```@example connections
plot(title = "numerical difference: vel. vs. pos. domain", xlabel = "time [s]",
ylabel = "solv[bv.v] .- solp[bp.v]")
ylabel = "solv[bv.v] .- solp[bp.v]")
time = 0:0.1:10
plot!(time, (solv(time)[bv.v] .- solp(time)[bp.v]), label = "")
Plots.ylims!(-1e-15, 1e-15)
Expand Down
32 changes: 16 additions & 16 deletions docs/src/tutorials/custom_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ function NonlinearResistor(; name, Ga, Gb, Ve)
pars = @parameters Ga=Ga Gb=Gb Ve=Ve
eqs = [
i ~ ifelse(v < -Ve,
Gb * (v + Ve) - Ga * Ve,
ifelse(v > Ve,
Gb * (v - Ve) + Ga * Ve,
Ga * v)),
Gb * (v + Ve) - Ga * Ve,
ifelse(v > Ve,
Gb * (v - Ve) + Ga * Ve,
Ga * v)),
]
extend(ODESystem(eqs, t, [], pars; name = name), oneport)
end
Expand Down Expand Up @@ -97,19 +97,19 @@ The final model can now be created with the components from the library and the
@named C1 = Capacitor(C = 10, v_start = 4)
@named C2 = Capacitor(C = 100)
@named Nr = NonlinearResistor(Ga = -0.757576,
Gb = -0.409091,
Ve = 1)
Gb = -0.409091,
Ve = 1)
@named Gnd = Ground()

connections = [connect(L.p, G.p)
connect(G.n, Nr.p)
connect(Nr.n, Gnd.g)
connect(C1.p, G.n)
connect(L.n, Ro.p)
connect(G.p, C2.p)
connect(C1.n, Gnd.g)
connect(C2.n, Gnd.g)
connect(Ro.n, Gnd.g)]
connect(G.n, Nr.p)
connect(Nr.n, Gnd.g)
connect(C1.p, G.n)
connect(L.n, Ro.p)
connect(G.p, C2.p)
connect(C1.n, Gnd.g)
connect(C2.n, Gnd.g)
connect(Ro.n, Gnd.g)]

@named model = ODESystem(connections, t, systems = [L, Ro, G, C1, C2, Nr, Gnd])
nothing # hide
Expand All @@ -127,12 +127,12 @@ prob = ODEProblem(sys, Pair[], (0, 5e4), saveat = 0.01)
sol = solve(prob, Rodas4())

Plots.plot(sol[C1.v], sol[C2.v], title = "Chaotic Attractor", label = "",
ylabel = "C1 Voltage in V", xlabel = "C2 Voltage in V")
ylabel = "C1 Voltage in V", xlabel = "C2 Voltage in V")
Plots.savefig("chua_phase_plane.png")
nothing # hide

Plots.plot(sol; vars = [C1.v, C2.v, L.i],
labels = ["C1 Voltage in V" "C1 Voltage in V" "Inductor Current in A"])
labels = ["C1 Voltage in V" "C1 Voltage in V" "Inductor Current in A"])
Plots.savefig("chua.png")
nothing # hide
```
Expand Down
62 changes: 31 additions & 31 deletions docs/src/tutorials/dc_motor_pi.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,36 @@ The actual model can now be composed.
@named speed_sensor = SpeedSensor()

connections = [connect(fixed.flange, emf.support, friction.flange_b)
connect(emf.flange, friction.flange_a, inertia.flange_a)
connect(inertia.flange_b, load.flange)
connect(inertia.flange_b, speed_sensor.flange)
connect(load_step.output, load.tau)
connect(ref.output, feedback.input1)
connect(speed_sensor.w, :y, feedback.input2)
connect(feedback.output, pi_controller.err_input)
connect(pi_controller.ctr_output, :u, source.V)
connect(source.p, R1.p)
connect(R1.n, L1.p)
connect(L1.n, emf.p)
connect(emf.n, source.n, ground.g)]
connect(emf.flange, friction.flange_a, inertia.flange_a)
connect(inertia.flange_b, load.flange)
connect(inertia.flange_b, speed_sensor.flange)
connect(load_step.output, load.tau)
connect(ref.output, feedback.input1)
connect(speed_sensor.w, :y, feedback.input2)
connect(feedback.output, pi_controller.err_input)
connect(pi_controller.ctr_output, :u, source.V)
connect(source.p, R1.p)
connect(R1.n, L1.p)
connect(L1.n, emf.p)
connect(emf.n, source.n, ground.g)]

@named model = ODESystem(connections, t,
systems = [
ground,
ref,
pi_controller,
feedback,
source,
R1,
L1,
emf,
fixed,
load,
load_step,
inertia,
friction,
speed_sensor,
])
systems = [
ground,
ref,
pi_controller,
feedback,
source,
R1,
L1,
emf,
fixed,
load,
load_step,
inertia,
friction,
speed_sensor,
])
nothing # hide
```

Expand All @@ -93,7 +93,7 @@ prob = ODEProblem(sys, [], (0, 6.0))
sol = solve(prob, Rodas4())

p1 = Plots.plot(sol.t, sol[inertia.w], ylabel = "Angular Vel. in rad/s",
label = "Measurement", title = "DC Motor with Speed Controller")
label = "Measurement", title = "DC Motor with Speed Controller")
Plots.plot!(sol.t, sol[ref.output.u], label = "Reference")
p2 = Plots.plot(sol.t, sol[load.tau.u], ylabel = "Disturbance in Nm", label = "")
Plots.plot(p1, p2, layout = (2, 1))
Expand Down Expand Up @@ -124,7 +124,7 @@ So = ss(matrices_S...) |> minreal # The output-sensitivity function as a StateSp
matrices_T, simplified_sys = Blocks.get_comp_sensitivity(model, :y)
To = ss(matrices_T...)# The output complementary sensitivity function as a StateSpace system
bodeplot([So, To], label = ["S" "T"], plot_title = "Sensitivity functions",
plotphase = false)
plotphase = false)
```

Similarly, we may compute the loop-transfer function and plot its Nyquist curve
Expand All @@ -134,5 +134,5 @@ matrices_L, simplified_sys = Blocks.get_looptransfer(model, :y)
L = -ss(matrices_L...) # The loop-transfer function as a StateSpace system. The negative sign is to negate the built-in negative feedback
Ms, ωMs = hinfnorm(So) # Compute the peak of the sensitivity function to draw a circle in the Nyquist plot
nyquistplot(L, label = "\$L(s)\$", ylims = (-2.5, 0.5), xlims = (-1.2, 0.1),
Ms_circles = Ms)
Ms_circles = Ms)
```
18 changes: 9 additions & 9 deletions docs/src/tutorials/input_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function System(f; name)
pars = @parameters m=10 k=1000 d=1

eqs = [f ~ src.output.u
ddx * 10 ~ k * x + d * dx + f
D(x) ~ dx
D(dx) ~ ddx]
ddx * 10 ~ k * x + d * dx + f
D(x) ~ dx
D(dx) ~ ddx]

ODESystem(eqs, t, vars, pars; systems = [src], name)
end
Expand Down Expand Up @@ -74,9 +74,9 @@ function System(; name)
pars = @parameters m=10 k=1000 d=1

eqs = [f ~ get_sampled_data(t)
ddx * 10 ~ k * x + d * dx + f
D(x) ~ dx
D(dx) ~ ddx]
ddx * 10 ~ k * x + d * dx + f
D(x) ~ dx
D(dx) ~ ddx]

ODESystem(eqs, t, vars, pars; name)
end
Expand Down Expand Up @@ -115,9 +115,9 @@ function System(; name)
pars = @parameters m=10 k=1000 d=1

eqs = [f ~ src.output.u
ddx * 10 ~ k * x + d * dx + f
D(x) ~ dx
D(dx) ~ ddx]
ddx * 10 ~ k * x + d * dx + f
D(x) ~ dx
D(dx) ~ ddx]

ODESystem(eqs, t, vars, pars; systems = [src], name)
end
Expand Down
12 changes: 6 additions & 6 deletions docs/src/tutorials/rc_circuit.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ V = 1.0
@named ground = Ground()

rc_eqs = [connect(constant.output, source.V)
connect(source.p, resistor.p)
connect(resistor.n, capacitor.p)
connect(capacitor.n, source.n, ground.g)]
connect(source.p, resistor.p)
connect(resistor.n, capacitor.p)
connect(capacitor.n, source.n, ground.g)]

@named rc_model = ODESystem(rc_eqs, t,
systems = [resistor, capacitor, constant, source, ground])
systems = [resistor, capacitor, constant, source, ground])
sys = structural_simplify(rc_model)
prob = ODAEProblem(sys, Pair[], (0, 10.0))
sol = solve(prob, Tsit5())
plot(sol, vars = [capacitor.v, resistor.i],
title = "RC Circuit Demonstration",
labels = ["Capacitor Voltage" "Resistor Current"])
title = "RC Circuit Demonstration",
labels = ["Capacitor Voltage" "Resistor Current"])
savefig("plot.png");
nothing; # hide
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/thermal_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ connections = [
]

@named model = ODESystem(connections, t,
systems = [mass1, mass2, conduction, Tsensor1, Tsensor2])
systems = [mass1, mass2, conduction, Tsensor1, Tsensor2])
sys = structural_simplify(model)
prob = ODEProblem(sys, Pair[], (0, 5.0))
sol = solve(prob, Tsit5())
Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/Blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export Log, Log10
include("math.jl")

export Constant, TimeVaryingFunction, Sine, Cosine, ContinuousClock, Ramp, Step, ExpSine,
Square, Triangular, Parameter, SampledData
Square, Triangular, Parameter, SampledData
include("sources.jl")

export Limiter, DeadZone, SlewRateLimiter
Expand All @@ -29,7 +29,7 @@ export PI, LimPI, PID, LimPID
include("continuous.jl")

export AnalysisPoint, get_sensitivity, get_comp_sensitivity,
get_looptransfer, open_loop
get_looptransfer, open_loop
include("analysis_points.jl")

end
Loading