diff --git a/README.md b/README.md index 973f252a4..94dd89676 100644 --- a/README.md +++ b/README.md @@ -60,9 +60,9 @@ 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]) diff --git a/docs/pages.jl b/docs/pages.jl index af2de24f3..35cf400cb 100644 --- a/docs/pages.jl +++ b/docs/pages.jl @@ -5,7 +5,7 @@ pages = [ "Custom Components" => "tutorials/custom_component.md", "Thermal Conduction Model" => "tutorials/thermal_model.md", "DC Motor with Speed Controller" => "tutorials/dc_motor_pi.md", - "SampledData Component" => "tutorials/input_component.md", + "SampledData Component" => "tutorials/input_component.md" ], "About Acausal Connections" => "connectors/connections.md", "API" => [ @@ -15,6 +15,6 @@ pages = [ "Mechanical Components" => "API/mechanical.md", "Thermal Components" => "API/thermal.md", "Hydraulic Components" => "API/hydraulic.md", - "Linear Analysis" => "API/linear_analysis.md", - ], + "Linear Analysis" => "API/linear_analysis.md" + ] ] diff --git a/docs/src/API/linear_analysis.md b/docs/src/API/linear_analysis.md index 0028defb8..98d265371 100644 --- a/docs/src/API/linear_analysis.md +++ b/docs/src/API/linear_analysis.md @@ -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. diff --git a/docs/src/connectors/connections.md b/docs/src/connectors/connections.md index 28ec45c92..83a43f2ca 100644 --- a/docs/src/connectors/connections.md +++ b/docs/src/connectors/connections.md @@ -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]) @@ -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]) @@ -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]) @@ -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]) diff --git a/docs/src/tutorials/custom_component.md b/docs/src/tutorials/custom_component.md index a0274179f..4472e839f 100644 --- a/docs/src/tutorials/custom_component.md +++ b/docs/src/tutorials/custom_component.md @@ -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 @@ -102,14 +102,14 @@ The final model can now be created with the components from the library and the @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 diff --git a/docs/src/tutorials/dc_motor_pi.md b/docs/src/tutorials/dc_motor_pi.md index ae711ed0d..874dabb06 100644 --- a/docs/src/tutorials/dc_motor_pi.md +++ b/docs/src/tutorials/dc_motor_pi.md @@ -50,18 +50,18 @@ 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 = [ @@ -78,7 +78,7 @@ connections = [connect(fixed.flange, emf.support, friction.flange_b) load_step, inertia, friction, - speed_sensor, + speed_sensor ]) nothing # hide ``` diff --git a/docs/src/tutorials/input_component.md b/docs/src/tutorials/input_component.md index 7347c1213..293294334 100644 --- a/docs/src/tutorials/input_component.md +++ b/docs/src/tutorials/input_component.md @@ -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 @@ -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 @@ -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 diff --git a/docs/src/tutorials/rc_circuit.md b/docs/src/tutorials/rc_circuit.md index a33a89ca1..4004d5abd 100644 --- a/docs/src/tutorials/rc_circuit.md +++ b/docs/src/tutorials/rc_circuit.md @@ -22,9 +22,9 @@ 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]) diff --git a/docs/src/tutorials/thermal_model.md b/docs/src/tutorials/thermal_model.md index b83a064bb..233e2464d 100644 --- a/docs/src/tutorials/thermal_model.md +++ b/docs/src/tutorials/thermal_model.md @@ -23,7 +23,7 @@ connections = [ connect(mass1.port, conduction.port_a), connect(conduction.port_b, mass2.port), connect(mass1.port, Tsensor1.port), - connect(mass2.port, Tsensor2.port), + connect(mass2.port, Tsensor2.port) ] @named model = ODESystem(connections, t, diff --git a/src/Blocks/Blocks.jl b/src/Blocks/Blocks.jl index cf0679a37..cc7b4cde0 100644 --- a/src/Blocks/Blocks.jl +++ b/src/Blocks/Blocks.jl @@ -19,7 +19,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 @@ -30,7 +30,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 diff --git a/src/Blocks/analysis_points.jl b/src/Blocks/analysis_points.jl index b7690692d..99cf216a8 100644 --- a/src/Blocks/analysis_points.jl +++ b/src/Blocks/analysis_points.jl @@ -5,8 +5,18 @@ Base.@kwdef mutable struct AnalysisPoint out = nothing name::Symbol = :nothing end +Base.broadcastable(x::AnalysisPoint) = Ref(x) +if Base.isdefined(ModelingToolkit, :isconnection) + ModelingToolkit.isconnection(::AnalysisPoint) = true +end Base.nameof(ap::AnalysisPoint) = ap.name +function Base.hash(ap::AnalysisPoint, seed::UInt) + h1 = hash(ap.in, seed) + h2 = hash(ap.out, h1) + h3 = hash(ap.name, h2) + h3 ⊻ (0xd29cdc51aa6562d4 % UInt) +end function ap_var(sys) if hasproperty(sys, :u) @@ -255,7 +265,7 @@ end const SymOrVec = Union{Symbol, Vector{Symbol}} function get_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = nothing, - kwargs...) + kwargs...) find = namespaced_ap_match(ap_name, loop_openings) t = get_iv(sys) aps = [] @@ -284,7 +294,7 @@ function get_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = nothin end function get_comp_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = nothing, - kwargs...) + kwargs...) find = namespaced_ap_match(ap_name, loop_openings) t = get_iv(sys) aps = [] @@ -313,7 +323,7 @@ function get_comp_sensitivity_function(sys, ap_name::SymOrVec; loop_openings = n end function get_looptransfer_function(sys, ap_name::SymOrVec; loop_openings = nothing, - kwargs...) + kwargs...) find = namespaced_ap_match(ap_name, loop_openings) t = get_iv(sys) aps = [] @@ -380,9 +390,9 @@ function open_loop(sys, ap_name::Symbol; ground_input = false, kwargs...) end function ModelingToolkit.linearization_function(sys::ModelingToolkit.AbstractSystem, - input_name::SymOrVec, output_name; - loop_openings = nothing, - kwargs...) + input_name::SymOrVec, output_name; + loop_openings = nothing, + kwargs...) t = get_iv(sys) @variables u(t)=0 [input = true] names = [input_name;] @@ -417,7 +427,7 @@ function ModelingToolkit.linearization_function(sys::ModelingToolkit.AbstractSys push!(multiplicities_y, length(yi)) append!(y, yi) [ap_var(ap.in) .~ yi; - ap_var(ap.out) .~ ap_var(ap.in)], yi + ap_var(ap.out) .~ ap_var(ap.in)], yi else # loop opening [ap_var(ap.out) .~ 0;], [] end @@ -444,19 +454,19 @@ for f in [:get_sensitivity, :get_comp_sensitivity, :get_looptransfer, :open_loop end function ModelingToolkit.linearize(sys, input::AnalysisPoint, output::AnalysisPoint; - kwargs...) + kwargs...) ModelingToolkit.linearize(sys, nameof(input), nameof(output); kwargs...) end # Methods above are implemented in terms of linearization_function, the method below creates wrappers for linearize for f in [:get_sensitivity, :get_comp_sensitivity, :get_looptransfer] @eval function $f(sys, - ap, - args...; - loop_openings = nothing, - op = Dict(), - p = DiffEqBase.NullParameters(), - kwargs...) + ap, + args...; + loop_openings = nothing, + op = Dict(), + p = DiffEqBase.NullParameters(), + kwargs...) lin_fun, ssys = $(Symbol(string(f) * "_function"))(sys, ap, args...; op, p, loop_openings, kwargs...) @@ -472,7 +482,7 @@ Linearize a system between two analysis points. To get a loop-transfer function, The output is allowed to be either an analysis-point name, or a vector of symbolic variables like the standard interface to `linearize`. The input must be an analysis-point name. """ function ModelingToolkit.linearize(sys, input_name::SymOrVec, output_name; - loop_openings = nothing, kwargs...) + loop_openings = nothing, kwargs...) lin_fun, ssys = linearization_function(sys, input_name, output_name; loop_openings, kwargs...) ModelingToolkit.linearize(ssys, lin_fun; kwargs...), ssys diff --git a/src/Blocks/continuous.jl b/src/Blocks/continuous.jl index 2661c7124..7b6fa47ed 100644 --- a/src/Blocks/continuous.jl +++ b/src/Blocks/continuous.jl @@ -245,7 +245,7 @@ Text-book version of a PID-controller without actuator saturation and anti-windu See also [`LimPID`](@ref) """ @component function PID(; name, k = 1, Ti = false, Td = false, Nd = 10, int__x = 0, - der__x = 0) + der__x = 0) with_I = !isequal(Ti, false) with_D = !isequal(Td, false) @named err_input = RealInput() # control error @@ -282,7 +282,7 @@ See also [`LimPID`](@ref) eqs = [ connect(err_input, addPID.input1), connect(addPID.output, gainPID.input), - connect(gainPID.output, ctr_output), + connect(gainPID.output, ctr_output) ] if with_I push!(eqs, connect(err_input, int.input)) @@ -347,7 +347,7 @@ The simplified expression above is given without the anti-windup protection. connect(err_input, addTrack.input1), connect(gainTrack.output, addTrack.input2), connect(addTrack.output, int.input), - connect(int.output, addPI.input2), + connect(int.output, addPI.input2) ] ODESystem(eqs, t, [], []; name = name, systems = sys) end @@ -386,13 +386,13 @@ where the transfer function for the derivative includes additional filtering, se - `ctr_output` """ @component function LimPID(; name, k = 1, Ti = false, Td = false, wp = 1, wd = 1, - Ni = Ti == 0 ? Inf : √(max(Td / Ti, 1e-6)), - Nd = 10, - u_max = Inf, - u_min = u_max > 0 ? -u_max : -Inf, - gains = false, - int__x = 0.0, - der__x = 0.0) + Ni = Ti == 0 ? Inf : √(max(Td / Ti, 1e-6)), + Nd = 10, + u_max = Inf, + u_min = u_max > 0 ? -u_max : -Inf, + gains = false, + int__x = 0.0, + der__x = 0.0) with_I = !isequal(Ti, false) with_D = !isequal(Td, false) with_AWM = Ni != Inf @@ -459,7 +459,7 @@ where the transfer function for the derivative includes additional filtering, se connect(addP.output, addPID.input1), connect(addPID.output, gainPID.input), connect(gainPID.output, limiter.input), - connect(limiter.output, ctr_output), + connect(limiter.output, ctr_output) ] if with_I push!(eqs, connect(reference, addI.input1)) @@ -522,7 +522,7 @@ y &= h(x, u) linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u₀), u₀`. """ @component function StateSpace(; A, B, C, D = nothing, x = zeros(size(A, 1)), name, - u0 = zeros(size(B, 2)), y0 = zeros(size(C, 1))) + u0 = zeros(size(B, 2)), y0 = zeros(size(C, 1))) nx, nu, ny = size(A, 1), size(B, 2), size(C, 1) size(A, 2) == nx || error("`A` has to be a square matrix.") size(B, 1) == nx || error("`B` has to be of dimension ($nx x $nu).") @@ -538,7 +538,7 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u @named input = RealInput(nin = nu) @named output = RealOutput(nout = ny) @variables x(t)[1:nx]=x [ - description = "State variables of StateSpace system $name", + description = "State variables of StateSpace system $name" ] # pars = @parameters A=A B=B C=C D=D # This is buggy eqs = [ # FIXME: if array equations work @@ -547,7 +547,7 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u for i in 1:nx]..., # cannot use D here [output.u[j] ~ sum(C[j, i] * x[i] for i in 1:nx) + sum(D[j, k] * (input.u[k] - u0[k]) for k in 1:nu) + y0[j] - for j in 1:ny]..., + for j in 1:ny]... ] compose(ODESystem(eqs, t, vcat(x...), [], name = name), [input, output]) end @@ -596,11 +596,11 @@ See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSys @parameters begin b[1:nb] = b, [ - description = "Numerator coefficients of transfer function (e.g., 2s + 3 is specified as [2,3])", + description = "Numerator coefficients of transfer function (e.g., 2s + 3 is specified as [2,3])" ] a[1:na] = a, [ - description = "Denominator coefficients of transfer function (e.g., `s² + 2ωs + ω^2` is specified as [1, 2ω, ω^2])", + description = "Denominator coefficients of transfer function (e.g., `s² + 2ωs + ω^2` is specified as [1, 2ω, ω^2])" ] bb[1:(nbb + nb)] = [zeros(nbb); b] d = bb[1] / a[1], [description = "Direct feedthrough gain"] @@ -627,9 +627,9 @@ See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSys eqs = [y ~ d * u] else eqs = [D(x_scaled[1]) ~ (-a[2:na]'x_scaled + a_end * u) / a[1] - D.(x_scaled[2:nx]) .~ x_scaled[1:(nx - 1)] - y ~ ((bb[2:na] - d * a[2:na])'x_scaled) / a_end + d * u - x .~ x_scaled ./ a_end] + D.(x_scaled[2:nx]) .~ x_scaled[1:(nx - 1)] + y ~ ((bb[2:na] - d * a[2:na])'x_scaled) / a_end + d * u + x .~ x_scaled ./ a_end] end push!(eqs, input.u ~ u) push!(eqs, output.u ~ y) diff --git a/src/Blocks/nonlinear.jl b/src/Blocks/nonlinear.jl index 847c11190..8f2466f72 100644 --- a/src/Blocks/nonlinear.jl +++ b/src/Blocks/nonlinear.jl @@ -22,10 +22,10 @@ Limit the range of a signal. @named siso = SISO(u_start = m, y_start = m) # Default signals to center of saturation to minimize risk of saturation while linearizing etc. @unpack u, y = siso pars = @parameters y_max=y_max [description = "Maximum allowed output of Limiter $name"] y_min=y_min [ - description = "Minimum allowed output of Limiter $name", + description = "Minimum allowed output of Limiter $name" ] eqs = [ - y ~ _clamp(u, y_min, y_max), + y ~ _clamp(u, y_min, y_max) ] extend(ODESystem(eqs, t, [], pars; name = name), siso) end diff --git a/src/Blocks/sources.jl b/src/Blocks/sources.jl index a3020cbdb..8cf6a79c9 100644 --- a/src/Blocks/sources.jl +++ b/src/Blocks/sources.jl @@ -130,12 +130,12 @@ Generate sine signal. - `output` """ @component function Sine(; name, - frequency, - amplitude = 1, - phase = 0, - offset = 0, - start_time = 0, - smooth = false) + frequency, + amplitude = 1, + phase = 0, + offset = 0, + start_time = 0, + smooth = false) @named output = RealOutput() pars = @parameters offset=offset start_time=start_time amplitude=amplitude frequency=frequency phase=phase equation = if smooth == false @@ -147,7 +147,7 @@ Generate sine signal. end eqs = [ - output.u ~ equation, + output.u ~ equation ] compose(ODESystem(eqs, t, [], pars; name = name), [output]) @@ -173,12 +173,12 @@ Cosine signal. """ @component function Cosine(; name, - frequency, - amplitude = 1, - phase = 0, - offset = 0, - start_time = 0, - smooth = false) + frequency, + amplitude = 1, + phase = 0, + offset = 0, + start_time = 0, + smooth = false) @named output = RealOutput() pars = @parameters offset=offset start_time=start_time amplitude=amplitude frequency=frequency phase=phase equation = if smooth == false @@ -189,7 +189,7 @@ Cosine signal. smooth_cos(t, smooth, frequency, amplitude, phase, offset, start_time) end eqs = [ - output.u ~ equation, + output.u ~ equation ] compose(ODESystem(eqs, t, [], pars; name = name), [output]) @@ -213,7 +213,7 @@ Generate current time signal. @named output = RealOutput() pars = @parameters offset=offset start_time=start_time eqs = [ - output.u ~ offset + ifelse(t < start_time, zero(t), t - start_time), + output.u ~ offset + ifelse(t < start_time, zero(t), t - start_time) ] compose(ODESystem(eqs, t, [], pars; name = name), [output]) @@ -238,11 +238,11 @@ Generate ramp signal. - `output` """ @component function Ramp(; name, - height = 1, - duration = 1, - offset = 0, - start_time = 0, - smooth = false) + height = 1, + duration = 1, + offset = 0, + start_time = 0, + smooth = false) @named output = RealOutput() pars = @parameters offset=offset start_time=start_time height=height duration=duration equation = if smooth == false @@ -255,7 +255,7 @@ Generate ramp signal. end eqs = [ - output.u ~ equation, + output.u ~ equation ] compose(ODESystem(eqs, t, [], pars; name = name), [output]) @@ -280,7 +280,7 @@ Generate smooth square signal. - `output` """ @component function Square(; name, frequency = 1.0, amplitude = 1.0, - offset = 0.0, start_time = 0.0, smooth = false) + offset = 0.0, start_time = 0.0, smooth = false) @named output = RealOutput() pars = @parameters begin frequency = frequency @@ -297,7 +297,7 @@ Generate smooth square signal. end eqs = [ - output.u ~ equation, + output.u ~ equation ] compose(ODESystem(eqs, t, [], pars; name = name), [output]) @@ -322,7 +322,7 @@ Generate step signal. - `output` """ @component function Step(; name, height = 1, offset = 0, start_time = 0, duration = Inf, - smooth = 1e-5) + smooth = 1e-5) @named output = RealOutput() duration_numeric = duration pars = @parameters offset=offset start_time=start_time height=height duration=duration @@ -339,7 +339,7 @@ Generate step signal. end eqs = [ - output.u ~ equation, + output.u ~ equation ] compose(ODESystem(eqs, t, [], pars; name = name), [output]) @@ -366,13 +366,13 @@ Exponentially damped sine signal. - `output` """ @component function ExpSine(; name, - frequency, - amplitude = 1, - damping = 0.1, - phase = 0, - offset = 0, - start_time = 0, - smooth = false) + frequency, + amplitude = 1, + damping = 0.1, + phase = 0, + offset = 0, + start_time = 0, + smooth = false) @named output = RealOutput() pars = @parameters offset=offset start_time=start_time amplitude=amplitude frequency=frequency phase=phase damping=damping @@ -387,7 +387,7 @@ Exponentially damped sine signal. end eqs = [ - output.u ~ equation, + output.u ~ equation ] compose(ODESystem(eqs, t, [], pars; name = name), [output]) @@ -413,7 +413,7 @@ Generate smooth triangular signal for frequencies less than or equal to 25 Hz - `output` """ @component function Triangular(; name, amplitude = 1.0, frequency = 1.0, - offset = 0.0, start_time = 0.0, smooth = false) + offset = 0.0, start_time = 0.0, smooth = false) @named output = RealOutput() pars = @parameters begin amplitude = amplitude @@ -430,7 +430,7 @@ Generate smooth triangular signal for frequencies less than or equal to 25 Hz end eqs = [ - output.u ~ equation, + output.u ~ equation ] compose(ODESystem(eqs, t, [], pars; name = name), [output]) @@ -559,9 +559,9 @@ function first_order_backwards_difference(t, buffer, Δt, circular_buffer) end function get_sampled_data(t, - buffer::Vector{T}, - dt::T, - circular_buffer = true) where {T <: Real} + buffer::Vector{T}, + dt::T, + circular_buffer = true) where {T <: Real} if t < 0 t = zero(t) end @@ -623,11 +623,11 @@ function Symbolics.derivative(::typeof(get_sampled_data), args::NTuple{4, Any}, first_order_backwards_difference(t, buffer, sample_time, circular_buffer) end function ChainRulesCore.frule((_, ẋ, _), - ::typeof(get_sampled_data), - t, - buffer, - sample_time, - circular_buffer) + ::typeof(get_sampled_data), + t, + buffer, + sample_time, + circular_buffer) first_order_backwards_difference(t, buffer, sample_time, circular_buffer) * ẋ end @@ -651,10 +651,10 @@ data input component. - `output` """ @component function SampledData(::Val{SampledDataType.vector_based}; - name, - buffer, - sample_time, - circular_buffer = true) + name, + buffer, + sample_time, + circular_buffer = true) pars = @parameters begin buffer = buffer #::Vector{Real} sample_time = sample_time #::Real @@ -665,11 +665,11 @@ data input component. output = RealOutput() end eqs = [ - output.u ~ get_sampled_data(t, buffer, sample_time, circular_buffer), + output.u ~ get_sampled_data(t, buffer, sample_time, circular_buffer) ] return ODESystem(eqs, t, vars, pars; name, systems, defaults = [ - output.u => get_sampled_data(0.0, buffer, sample_time, circular_buffer), + output.u => get_sampled_data(0.0, buffer, sample_time, circular_buffer) ]) end @@ -693,7 +693,7 @@ data input component. output = RealOutput() end eqs = [ - output.u ~ get_sampled_data(t, buffer), + output.u ~ get_sampled_data(t, buffer) ] return ODESystem(eqs, t, vars, pars; name, systems, defaults = [output.u => get_sampled_data(0.0, buffer)]) @@ -717,9 +717,9 @@ function SampledData(sample_time::T, circular_buffer = true; name) where {T <: R circular_buffer) end function SampledData(buffer::Vector{<:Real}, - sample_time::Real, - circular_buffer = true; - name) + sample_time::Real, + circular_buffer = true; + name) SampledData(SampledDataType.vector_based; name, buffer, sample_time, circular_buffer) end function SampledData(; name, buffer, sample_time, circular_buffer) diff --git a/src/Blocks/utils.jl b/src/Blocks/utils.jl index d6200d85b..ec61db769 100644 --- a/src/Blocks/utils.jl +++ b/src/Blocks/utils.jl @@ -2,12 +2,12 @@ if nin == 1 @variables u(t)=u_start [ input = true, - description = "Inner variable in RealInput $name", + description = "Inner variable in RealInput $name" ] else @variables u(t)[1:nin]=u_start [ input = true, - description = "Inner variable in RealInput $name", + description = "Inner variable in RealInput $name" ] u = collect(u) end @@ -30,12 +30,12 @@ Connector with one input signal of type Real. if nout == 1 @variables u(t)=u_start [ output = true, - description = "Inner variable in RealOutput $name", + description = "Inner variable in RealOutput $name" ] else @variables u(t)[1:nout]=u_start [ output = true, - description = "Inner variable in RealOutput $name", + description = "Inner variable in RealOutput $name" ] u = collect(u) end @@ -96,14 +96,14 @@ Base class for a multiple input multiple output (MIMO) continuous system block. - `y_start`: Initial value for the output """ @component function MIMO(; name, nin = 1, nout = 1, u_start = zeros(nin), - y_start = zeros(nout)) + y_start = zeros(nout)) @named input = RealInput(nin = nin, u_start = u_start) @named output = RealOutput(nout = nout, u_start = y_start) @variables(u(t)[1:nin]=u_start, [description = "Input of MIMO system $name"], y(t)[1:nout]=y_start, [description = "Output of MIMO system $name"],) eqs = [ [u[i] ~ input.u[i] for i in 1:nin]..., - [y[i] ~ output.u[i] for i in 1:nout]..., + [y[i] ~ output.u[i] for i in 1:nout]... ] return ODESystem(eqs, t, vcat(u..., y...), []; name = name, systems = [input, output]) end diff --git a/src/Electrical/Digital/components.jl b/src/Electrical/Digital/components.jl index ce9f31211..c3252f57d 100644 --- a/src/Electrical/Digital/components.jl +++ b/src/Electrical/Digital/components.jl @@ -30,9 +30,9 @@ Takes two bits as input, and outputs the sum and the carry @variables sum(t), carry(t) eqs = [y1.val ~ _xor(x1.val, x2.val) - y2.val ~ _and(x1.val, x2.val) - sum ~ y1.val - carry ~ y2.val] + y2.val ~ _and(x1.val, x2.val) + sum ~ y1.val + carry ~ y2.val] ODESystem(eqs, t, [sum, carry], [], systems = [x1, x2, y1, y2], name = name) end @@ -68,9 +68,9 @@ Takes three bits as input, and outputs the sum and the carry @variables sum(t), carry(t) eqs = [y1.val ~ _xor(x1.val, x2.val, x3.val) - y2.val ~ _or(_and(x3.val, _xor(x1.val, x2.val)), _and(x1.val, x2.val)) - sum ~ y1.val - carry ~ y2.val] + y2.val ~ _or(_and(x3.val, _xor(x1.val, x2.val)), _and(x1.val, x2.val)) + sum ~ y1.val + carry ~ y2.val] ODESystem(eqs, t, [sum, carry], [], systems = [x1, x2, x3, y1, y2], name = name) end diff --git a/src/Electrical/Digital/gates.jl b/src/Electrical/Digital/gates.jl index e7cdd73f5..0940e4cfc 100644 --- a/src/Electrical/Digital/gates.jl +++ b/src/Electrical/Digital/gates.jl @@ -17,7 +17,7 @@ function Not(; name) @named y = DigitalPin() eqs = [x.i ~ y.i - y.val ~ _not(x.val)] + y.val ~ _not(x.val)] ODESystem(eqs, t, [], [], systems = [x, y], name = name) end @@ -43,7 +43,7 @@ function And(; name, N = 2) vals = [k.val for k in x] eqs = [y.val ~ _and(vals...) - y.i ~ sum(k -> k.i, x)] + y.i ~ sum(k -> k.i, x)] ODESystem(eqs, t, [], [], systems = [x..., y], name = name) end @@ -69,7 +69,7 @@ function Nand(; name, N = 2) vlist = [k.val for k in x] eqs = [y.val ~ _not(_and(vlist...)) - y.i ~ sum(k -> k.i, x)] + y.i ~ sum(k -> k.i, x)] ODESystem(eqs, t, [], [], systems = [x..., y], name = name) end @@ -95,7 +95,7 @@ function Or(; name, N = 2) vals = [k.val for k in x] eqs = [y.val ~ _or(vals...) - y.i ~ sum(k -> k.i, x)] + y.i ~ sum(k -> k.i, x)] ODESystem(eqs, t, [], [], systems = [x..., y], name = name) end @@ -121,7 +121,7 @@ function Nor(; name, N = 2) vlist = [k.val for k in x] eqs = [y.val ~ _not(_or(vlist...)) - y.i ~ sum(k -> k.i, x)] + y.i ~ sum(k -> k.i, x)] ODESystem(eqs, t, [], [], systems = [x..., y], name = name) end @@ -147,7 +147,7 @@ function Xor(; name, N = 2) vals = [k.val for k in x] eqs = [y.val ~ _xor(vals...) - y.i ~ sum(k -> k.i, x)] + y.i ~ sum(k -> k.i, x)] ODESystem(eqs, t, [], [], systems = [x..., y], name = name) end @@ -173,6 +173,6 @@ function Xnor(; name, N = 2) vlist = [k.val for k in x] eqs = [y.val ~ _not(_xor(vlist...)) - y.i ~ sum(k -> k.i, x)] + y.i ~ sum(k -> k.i, x)] ODESystem(eqs, t, [], [], systems = [x..., y], name = name) end diff --git a/src/Electrical/Digital/logic_vectors.jl b/src/Electrical/Digital/logic_vectors.jl index 8f048249a..590621cd1 100644 --- a/src/Electrical/Digital/logic_vectors.jl +++ b/src/Electrical/Digital/logic_vectors.jl @@ -24,7 +24,7 @@ axes(l::LogicVector) = axes(l.logic) getindex(s::LogicVector, i::Int) = getindex(s.logic, i) function Base.getindex(s::LogicVector, i1::Int, i2::Int, - I::Int...) + I::Int...) getindex(s.logic, i1, i2, I...) end diff --git a/src/Electrical/Digital/sources.jl b/src/Electrical/Digital/sources.jl index 17537c088..b2a41a8e8 100644 --- a/src/Electrical/Digital/sources.jl +++ b/src/Electrical/Digital/sources.jl @@ -19,7 +19,7 @@ function PulseDiff(; name, Val = 1, dt = 0.1) D = ModelingToolkit.Difference(t; dt = dt) eqs = [D(val) ~ Val - val ~ d.val] + val ~ d.val] ODESystem(eqs, t, [val], [], systems = [d], defaults = Dict(Val => 0), name = name) end @@ -40,7 +40,7 @@ function Set(; name) @named d = DigitalPin() eqs = [ - d.val ~ 1, + d.val ~ 1 ] ODESystem(eqs, t, [], [], systems = [d], name = name) end @@ -61,7 +61,7 @@ function Reset(; name) @named d = DigitalPin() eqs = [ - d.val ~ 0, + d.val ~ 0 ] ODESystem(eqs, t, [], [], systems = [d], name = name) end @@ -82,7 +82,7 @@ function Pulse(; name, duty_cycle = 0.5, T = 1.0) @named d = DigitalPin() eqs = [ - d.val ~ IfElse.ifelse(t % T > duty_cycle * T, 1, 0), + d.val ~ IfElse.ifelse(t % T > duty_cycle * T, 1, 0) ] ODESystem(eqs, t, [], [], systems = [d], name = name) end diff --git a/src/Electrical/Digital/tables.jl b/src/Electrical/Digital/tables.jl index b2d7b8983..beb171730 100644 --- a/src/Electrical/Digital/tables.jl +++ b/src/Electrical/Digital/tables.jl @@ -17,7 +17,7 @@ function Base.getindex(s::LogicTable, i1::Logic, i2::Logic) getindex(s.logic, get_logic_level(i1), get_logic_level(i2)) end function Base.getindex(s::LogicTable, i1::Logic, i2::Logic, - I::Logic...) + I::Logic...) getindex(s.logic, get_logic_level(i1), get_logic_level(i2), get_logic_level(I...)...) end @@ -37,16 +37,16 @@ get_logic_level(l::LogicTable) = Int.(l.logic) # AND gate const AndTable = LogicTable([ -# U X F0 F1 Z W L H DC - U U F0 U U U F0 U U # U - U X F0 X X X F0 X X # X - F0 F0 F0 F0 F0 F0 F0 F0 F0 # F0 - U X F0 F1 X X F0 F1 X # F1 - U X F0 X X X F0 X X # Z - U X F0 X X X F0 X X # W - F0 F0 F0 F0 F0 F0 F0 F0 F0 # L - U X F0 F1 X X F0 F1 X # H - U X F0 X X X F0 X X]) # DC + # U X F0 F1 Z W L H DC + U U F0 U U U F0 U U # U + U X F0 X X X F0 X X # X + F0 F0 F0 F0 F0 F0 F0 F0 F0 # F0 + U X F0 F1 X X F0 F1 X # F1 + U X F0 X X X F0 X X # Z + U X F0 X X X F0 X X # W + F0 F0 F0 F0 F0 F0 F0 F0 F0 # L + U X F0 F1 X X F0 F1 X # H + U X F0 X X X F0 X X]) # DC function _and2(a::Logic, b::Logic) AndTable[a, b] @@ -75,16 +75,16 @@ _not(x::Number) = _not(convert(Logic, x)) # OR gate const OrTable = LogicTable([ -# U X F0 F1 Z W L H DC - U U U F1 U U U F1 U # U - U X X F1 X X X F1 X # X - U X F0 F1 X X F0 F1 X # F0 - F1 F1 F1 F1 F1 F1 F1 F1 F1 # F1 - U X X F1 X X X F1 X # Z - U X X F1 X X X F1 X # W - U X F0 F1 X X F0 F1 X # L - F1 F1 F1 F1 F1 F1 F1 F1 F1 # H - U X X F1 X X X F1 X]) # DC + # U X F0 F1 Z W L H DC + U U U F1 U U U F1 U # U + U X X F1 X X X F1 X # X + U X F0 F1 X X F0 F1 X # F0 + F1 F1 F1 F1 F1 F1 F1 F1 F1 # F1 + U X X F1 X X X F1 X # Z + U X X F1 X X X F1 X # W + U X F0 F1 X X F0 F1 X # L + F1 F1 F1 F1 F1 F1 F1 F1 F1 # H + U X X F1 X X X F1 X]) # DC function _or2(a::Logic, b::Logic) OrTable[a, b] @@ -105,16 +105,16 @@ end # XOR gate const XorTable = LogicTable([ -# U X F0 F1 Z W L H DC - U U U U U U U U U # U - U X X X X X X X X # X - U X F0 F1 X X F0 F1 X # F0 - U X F1 F0 X X F1 F0 X # F1 - U X X X X X X X X # Z - U X X X X X X X X # W - U X F0 F1 X X F0 F1 X # L - U X F1 F0 X X F1 F0 X # H - U X X X X X X X X]) # DC + # U X F0 F1 Z W L H DC + U U U U U U U U U # U + U X X X X X X X X # X + U X F0 F1 X X F0 F1 X # F0 + U X F1 F0 X X F1 F0 X # F1 + U X X X X X X X X # Z + U X X X X X X X X # W + U X F0 F1 X X F0 F1 X # L + U X F1 F0 X X F1 F0 X # H + U X X X X X X X X]) # DC function _xor2(a::Logic, b::Logic) XorTable[a, b] diff --git a/src/Electrical/Electrical.jl b/src/Electrical/Electrical.jl index 687f92b20..723182067 100644 --- a/src/Electrical/Electrical.jl +++ b/src/Electrical/Electrical.jl @@ -16,8 +16,8 @@ export Pin, OnePort include("utils.jl") export Capacitor, - Ground, Inductor, Resistor, Conductor, Short, IdealOpAmp, EMF, - HeatingResistor + Ground, Inductor, Resistor, Conductor, Short, IdealOpAmp, EMF, + HeatingResistor include("Analog/ideal_components.jl") export CurrentSensor, PotentialSensor, VoltageSensor, PowerSensor, MultiSensor @@ -38,12 +38,12 @@ export Logic include("Digital/logic.jl") export StdLogicVector, StdULogicVector, - std_ulogic, UX01, UX01Z, X01, X01Z, - get_logic_level + std_ulogic, UX01, UX01Z, X01, X01Z, + get_logic_level include("Digital/logic_vectors.jl") export LogicTable, - AndTable, OrTable, NotTable, XorTable + AndTable, OrTable, NotTable, XorTable include("Digital/tables.jl") end diff --git a/src/Electrical/utils.jl b/src/Electrical/utils.jl index ba7d0f541..e3a8c9a7f 100644 --- a/src/Electrical/utils.jl +++ b/src/Electrical/utils.jl @@ -89,7 +89,7 @@ end @variables val(t) v(t) i(t) eqs = [ val ~ IfElse.ifelse((0.0 <= v) & (v <= 0.8) | (2.0 <= v) & (v <= 5.0), - IfElse.ifelse(v > 2.0, 1, 0), X), + IfElse.ifelse(v > 2.0, 1, 0), X) ] ODESystem(Equation[], t, [val, v, i], [], defaults = Dict(val => 0, i => 0), name = name) diff --git a/src/Hydraulic/IsothermalCompressible/components.jl b/src/Hydraulic/IsothermalCompressible/components.jl index 91f6bd54c..8e41b39fb 100644 --- a/src/Hydraulic/IsothermalCompressible/components.jl +++ b/src/Hydraulic/IsothermalCompressible/components.jl @@ -20,7 +20,7 @@ Caps a hydraulic port to prevent mass flow in or out. end eqs = [port.p ~ p - port.dm ~ 0] + port.dm ~ 0] ODESystem(eqs, t, vars, pars; name, systems) end @@ -38,7 +38,7 @@ end end eqs = [port.p ~ p - port.dm ~ dm] + port.dm ~ dm] ODESystem(eqs, t, vars, pars; name, systems) end @@ -65,9 +65,9 @@ Variable length internal flow model of the fully developed incompressible flow f - `port_b`: hydraulic port """ @component function TubeBase(add_inertia = true, variable_length = true; p_int, area, - length_int, head_factor = 1, - perimeter = 2 * sqrt(area * pi), - shape_factor = 64, name) + length_int, head_factor = 1, + perimeter = 2 * sqrt(area * pi), + shape_factor = 64, name) pars = @parameters begin p_int = p_int area = area @@ -117,7 +117,7 @@ Variable length internal flow model of the fully developed incompressible flow f end eqs = [0 ~ port_a.dm + port_b.dm - domain_connect(port_a, port_b)] + domain_connect(port_a, port_b)] if variable_length push!(eqs, Δp ~ ifelse(c > 0, shear + inertia, zero(c))) @@ -150,8 +150,8 @@ Constant length internal flow model discretized by `N` (`FixedVolume`: `N`, `Tub - `port_b`: hydraulic port """ @component function Tube(N, add_inertia = true; p_int, area, length, head_factor = 1, - perimeter = 2 * sqrt(area * pi), - shape_factor = 64, name) + perimeter = 2 * sqrt(area * pi), + shape_factor = 64, name) @assert(N>0, "the Tube component must be defined with at least 1 segment (i.e. N>0), found N=$N") @@ -204,7 +204,7 @@ Constant length internal flow model discretized by `N` (`FixedVolume`: `N`, `Tub end eqs = [connect(volumes[1].port, pipe_bases[1].port_a, port_a) - connect(volumes[end].port, pipe_bases[end].port_b, port_b)] + connect(volumes[end].port, pipe_bases[end].port_b, port_b)] for i in 2:(N - 1) push!(eqs, @@ -253,17 +253,17 @@ Reduces the flow from `port_a` to `port_b` by `n`. Useful for modeling parallel end eqs = [connect(port_a, port_b, open.port) - dm_a ~ port_a.dm - dm_b ~ dm_a / n - open.dm ~ dm_a - dm_b # extra flow dumps into an open port - # port_b.dm ~ dm_b # divided flow goes to port_b - ] + dm_a ~ port_a.dm + dm_b ~ dm_a / n + open.dm ~ dm_a - dm_b # extra flow dumps into an open port + # port_b.dm ~ dm_b # divided flow goes to port_b + ] ODESystem(eqs, t, vars, pars; name, systems) end @component function ValveBase(reversible = false; p_a_int, p_b_int, minimum_area = 0, - area_int, Cd, Cd_reverse = Cd, name) + area_int, Cd, Cd_reverse = Cd, name) pars = @parameters begin p_a_int = p_a_int p_b_int = p_b_int @@ -303,9 +303,9 @@ end end eqs = [0 ~ port_a.dm + port_b.dm - domain_connect(port_a, port_b) - dm ~ regRoot(2 * Δp * ρ / c) * x - y ~ x] + domain_connect(port_a, port_b) + dm ~ regRoot(2 * Δp * ρ / c) * x + y ~ x] ODESystem(eqs, t, vars, pars; name, systems) end @@ -329,9 +329,9 @@ Valve with `area` input and discharge coefficient `Cd` defined by https://en.wik - `area`: real input setting the valve `area`. When `reversible = true`, negative input reverses flow direction, otherwise a floor of `minimum_area` is enforced. """ @component function Valve(reversible = false; p_a_int, p_b_int, - area_int, Cd, Cd_reverse = Cd, - minimum_area = 0, - name) + area_int, Cd, Cd_reverse = Cd, + minimum_area = 0, + name) pars = @parameters begin p_a_int = p_a_int p_b_int = p_b_int @@ -352,14 +352,14 @@ Valve with `area` input and discharge coefficient `Cd` defined by https://en.wik vars = [] eqs = [connect(base.port_a, port_a) - connect(base.port_b, port_b) - base.area ~ area.u] + connect(base.port_b, port_b) + base.area ~ area.u] ODESystem(eqs, t, vars, pars; name, systems, defaults = [area.u => area_int]) end @component function VolumeBase(; p_int, x_int = 0, area, dead_volume = 0, Χ1 = 1, Χ2 = 1, - name) + name) pars = @parameters begin p_int = p_int x_int = x_int @@ -384,10 +384,10 @@ end p = port.p eqs = [vol ~ dead_volume + area * x - D(x) ~ dx - D(rho) ~ drho - rho ~ full_density(port, p) - dm ~ drho * vol * Χ1 + rho * area * dx * Χ2] + D(x) ~ dx + D(rho) ~ drho + rho ~ full_density(port, p) + dm ~ drho * vol * Χ1 + rho * area * dx * Χ2] ODESystem(eqs, t, vars, pars; name, systems) end @@ -424,8 +424,8 @@ Fixed fluid volume. p = port.p eqs = [D(rho) ~ drho - rho ~ full_density(port, p) - dm ~ drho * vol] + rho ~ full_density(port, p) + dm ~ drho * vol] ODESystem(eqs, t, vars, pars; name, systems) end @@ -477,24 +477,24 @@ dm ────► │ │ area - `flange`: mechanical translational port """ @component function DynamicVolume(N, add_inertia = true, reversible = false; - p_int, - area, - x_int = 0, - x_max, - x_min = 0, - x_damp = x_min, - direction = +1, - - # Tube - perimeter = 2 * sqrt(area * pi), - shape_factor = 64, - head_factor = 1, - - # Valve - Cd = 1e2, - Cd_reverse = Cd, - minimum_area = 0, - name) + p_int, + area, + x_int = 0, + x_max, + x_min = 0, + x_damp = x_min, + direction = +1, + + # Tube + perimeter = 2 * sqrt(area * pi), + shape_factor = 64, + head_factor = 1, + + # Valve + Cd = 1e2, + Cd_reverse = Cd, + minimum_area = 0, + name) @assert(N>=0, "the Tube component must be defined with 0 or more segments (i.e. N>=0), found N=$N") @assert (direction == +1)||(direction == -1) "direction argument must be +/-1, found $direction" @@ -564,9 +564,9 @@ dm ────► │ │ area end eqs = [vol ~ x * area - D(x) ~ flange.v * direction - damper.area ~ damper_area - connect(port, damper.port_b)] + D(x) ~ flange.v * direction + damper.area ~ damper_area + connect(port, damper.port_b)] volumes = [] if N > 0 @@ -597,8 +597,9 @@ dm ────► │ │ area for i in 1:N push!(eqs, - volumes[i].dx ~ ifelse((vol >= (i - 1) * (x_max / N) * area) & - (vol < (i) * (x_max / N) * area), + volumes[i].dx ~ ifelse( + (vol >= (i - 1) * (x_max / N) * area) & + (vol < (i) * (x_max / N) * area), flange.v * direction, 0)) push!(eqs, pipe_bases[i].x ~ volumes[i].vol / volumes[i].area) end @@ -637,17 +638,17 @@ end end eqs = [D(x) ~ dx - flange.v ~ dx - flange.f ~ 0 #TODO: model flow force - connect(valve.port_a, port_a) - connect(valve.port_b, port_b) - valve.area ~ x * 2π * d] + flange.v ~ dx + flange.f ~ 0 #TODO: model flow force + connect(valve.port_a, port_a) + connect(valve.port_b, port_b) + valve.area ~ x * 2π * d] ODESystem(eqs, t, vars, pars; name, systems, defaults = [flange.v => 0]) end @component function SpoolValve2Way(reversible = false; p_s_int, p_a_int, p_b_int, p_r_int, - m, g, x_int, Cd, d, name) + m, g, x_int, Cd, d, name) pars = @parameters begin p_s_int = p_s_int p_a_int = p_a_int @@ -681,37 +682,37 @@ end end eqs = [connect(vSA.port_a, port_s) - connect(vSA.port_b, port_a) - connect(vBR.port_a, port_b) - connect(vBR.port_b, port_r) - connect(vSA.flange, vBR.flange, mass.flange, flange)] + connect(vSA.port_b, port_a) + connect(vBR.port_a, port_b) + connect(vBR.port_b, port_r) + connect(vSA.flange, vBR.flange, mass.flange, flange)] ODESystem(eqs, t, vars, pars; name, systems, defaults = [flange.v => 0]) end @component function Actuator(N, add_inertia = true, reversible = false; - p_a_int, - p_b_int, - area_a, - area_b, - perimeter_a = 2 * sqrt(area_a * pi), - perimeter_b = 2 * sqrt(area_b * pi), - length_a_int, - length_b_int, - shape_factor_a = 64, - shape_factor_b = 64, - head_factor_a = 1, - head_factor_b = 1, - m, - g, - x_int = 0, - minimum_volume_a = 0, - minimum_volume_b = 0, - damping_volume_a = minimum_volume_a, - damping_volume_b = minimum_volume_b, - Cd = 1e4, - Cd_reverse = Cd, - name) + p_a_int, + p_b_int, + area_a, + area_b, + perimeter_a = 2 * sqrt(area_a * pi), + perimeter_b = 2 * sqrt(area_b * pi), + length_a_int, + length_b_int, + shape_factor_a = 64, + shape_factor_b = 64, + head_factor_a = 1, + head_factor_b = 1, + m, + g, + x_int = 0, + minimum_volume_a = 0, + minimum_volume_b = 0, + damping_volume_a = minimum_volume_a, + damping_volume_b = minimum_volume_b, + Cd = 1e4, + Cd_reverse = Cd, + name) pars = @parameters begin p_a_int = p_a_int p_b_int = p_b_int @@ -777,10 +778,10 @@ end end eqs = [connect(vol_a.port, port_a) - connect(vol_b.port, port_b) - connect(vol_a.flange, vol_b.flange, mass.flange, flange) - D(x) ~ dx - dx ~ vol_a.flange.v] + connect(vol_b.port, port_b) + connect(vol_a.flange, vol_b.flange, mass.flange, flange) + D(x) ~ dx + dx ~ vol_a.flange.v] ODESystem(eqs, t, vars, pars; name, systems, defaults = [flange.v => 0]) end diff --git a/src/Hydraulic/IsothermalCompressible/sources.jl b/src/Hydraulic/IsothermalCompressible/sources.jl index 237962489..4f7f53b68 100644 --- a/src/Hydraulic/IsothermalCompressible/sources.jl +++ b/src/Hydraulic/IsothermalCompressible/sources.jl @@ -18,7 +18,7 @@ Hydraulic mass flow input source vars = [] eqs = [ - port.dm ~ -dm.u, + port.dm ~ -dm.u ] ODESystem(eqs, t, vars, pars; name, systems) @@ -47,7 +47,7 @@ Fixed pressure source end eqs = [ - port.p ~ p, + port.p ~ p ] ODESystem(eqs, t, vars, pars; name, systems) @@ -79,7 +79,7 @@ input pressure source end eqs = [ - port.p ~ p.u, + port.p ~ p.u ] ODESystem(eqs, t, vars, pars; name, systems) diff --git a/src/Hydraulic/IsothermalCompressible/utils.jl b/src/Hydraulic/IsothermalCompressible/utils.jl index cc937bbf2..bd09012a5 100644 --- a/src/Hydraulic/IsothermalCompressible/utils.jl +++ b/src/Hydraulic/IsothermalCompressible/utils.jl @@ -51,8 +51,8 @@ Fluid parameter setter for isothermal compressible fluid domain. Defaults given - `p_gas`: [Pa] reference pressure (set by `gas_pressure` argument) """ @connector function HydraulicFluid(; density = 997, bulk_modulus = 2.09e9, - viscosity = 0.0010016, gas_density = 0.0073955, - gas_pressure = -1000, n = 1, let_gas = 1, name) + viscosity = 0.0010016, gas_density = 0.0073955, + gas_pressure = -1000, n = 1, let_gas = 1, name) pars = @parameters begin ρ = density β = bulk_modulus @@ -68,7 +68,7 @@ Fluid parameter setter for isothermal compressible fluid domain. Defaults given end eqs = [ - dm ~ 0, + dm ~ 0 ] ODESystem(eqs, t, vars, pars; name, defaults = [dm => 0]) diff --git a/src/Magnetic/FluxTubes/FluxTubes.jl b/src/Magnetic/FluxTubes/FluxTubes.jl index c082b5f0a..07c7595fc 100644 --- a/src/Magnetic/FluxTubes/FluxTubes.jl +++ b/src/Magnetic/FluxTubes/FluxTubes.jl @@ -9,7 +9,7 @@ export PositiveMagneticPort, NegativeMagneticPort, TwoPort include("utils.jl") export Ground, Idle, Short, Crossing, ConstantPermeance, ConstantReluctance, EddyCurrent, - ElectroMagneticConverter + ElectroMagneticConverter include("basic.jl") export ConstantMagneticPotentialDifference, ConstantMagneticFlux diff --git a/src/Mechanical/Rotational/sources.jl b/src/Mechanical/Rotational/sources.jl index 72f89fbc9..f1c158c0c 100644 --- a/src/Mechanical/Rotational/sources.jl +++ b/src/Mechanical/Rotational/sources.jl @@ -4,7 +4,7 @@ @variables begin phi(t), [ - description = "Angle of flange with respect to support (= flange.phi - support.phi)", + description = "Angle of flange with respect to support (= flange.phi - support.phi)" ] end @equations begin @@ -63,7 +63,7 @@ Constant torque source @parameters begin tau_constant, [ - description = "Constant torque (if negative, torque is acting as load in positive direction of rotation)", + description = "Constant torque (if negative, torque is acting as load in positive direction of rotation)" ] end @extend flange, phi = partial_element = PartialTorque(; use_support = false) @@ -105,7 +105,7 @@ Forced movement of a flange according to a reference angular velocity signal @named w_ref = RealInput() @variables phi(t)=0.0 w(t)=0.0 a(t)=0.0 eqs = [phi ~ flange.phi - phi_support - D(phi) ~ w] + D(phi) ~ w] if exact pars = [] push!(eqs, w ~ w_ref.u) diff --git a/src/Mechanical/Rotational/utils.jl b/src/Mechanical/Rotational/utils.jl index b54bfd06d..4ce2e3380 100644 --- a/src/Mechanical/Rotational/utils.jl +++ b/src/Mechanical/Rotational/utils.jl @@ -142,7 +142,7 @@ Partial model for a component with one rotational 1-dim. shaft flange and a supp if use_support @named support = Support() eqs = [support.phi ~ phi_support - support.tau ~ -flange.tau] + support.tau ~ -flange.tau] push!(sys, support) else eqs = [phi_support ~ 0] @@ -177,7 +177,7 @@ Partial model for a component with two rotational 1-dim. shaft flanges and a sup if use_support @named support = Support() eqs = [support.phi ~ phi_support - support.tau ~ -flange_a.tau - flange_b.tau] + support.tau ~ -flange_a.tau - flange_b.tau] push!(sys, support) else eqs = [phi_support ~ 0] diff --git a/src/Mechanical/Translational/components.jl b/src/Mechanical/Translational/components.jl index a7cb9d130..42bb517cc 100644 --- a/src/Mechanical/Translational/components.jl +++ b/src/Mechanical/Translational/components.jl @@ -70,7 +70,7 @@ Sliding mass with inertia end eqs = [flange.v ~ v - flange.f ~ f] + flange.f ~ f] # gravity option if g !== nothing @@ -117,7 +117,7 @@ Linear 1D translational spring end # default @component function Spring(::Val{:relative}; name, k, delta_s = 0.0, flange_a__v = 0.0, - flange_b__v = 0.0) + flange_b__v = 0.0) pars = @parameters begin k = k end @@ -130,9 +130,9 @@ end # default @named flange_b = MechanicalPort(; v = flange_b__v) eqs = [D(delta_s) ~ flange_a.v - flange_b.v - f ~ k * delta_s - flange_a.f ~ +f - flange_b.f ~ -f] + f ~ k * delta_s + flange_a.f ~ +f + flange_b.f ~ -f] return compose(ODESystem(eqs, t, vars, pars; name = name), flange_a, flange_b) #flange_a.f => +k*delta_s, flange_b.f => -k*delta_s @@ -140,7 +140,7 @@ end const ABS = Val(:absolute) @component function Spring(::Val{:absolute}; name, k, sa = 0, sb = 0, flange_a__v = 0.0, - flange_b__v = 0.0, l = 0) + flange_b__v = 0.0, l = 0) pars = @parameters begin k = k l = l @@ -155,10 +155,10 @@ const ABS = Val(:absolute) @named flange_b = MechanicalPort(; v = flange_b__v) eqs = [D(sa) ~ flange_a.v - D(sb) ~ flange_b.v - f ~ k * (sa - sb - l) #delta_s - flange_a.f ~ +f - flange_b.f ~ -f] + D(sb) ~ flange_b.v + f ~ k * (sa - sb - l) #delta_s + flange_a.f ~ +f + flange_b.f ~ -f] return compose(ODESystem(eqs, t, vars, pars; name = name), flange_a, flange_b) #, flange_a.f => k * (flange_a__s - flange_b__s - l) diff --git a/src/Mechanical/Translational/sources.jl b/src/Mechanical/Translational/sources.jl index 71d4f62f4..7c135ad51 100644 --- a/src/Mechanical/Translational/sources.jl +++ b/src/Mechanical/Translational/sources.jl @@ -38,7 +38,7 @@ Linear 1D position input source. Set `solves_force=false` to force input force end eqs = [ - D(s.u) ~ flange.v, + D(s.u) ~ flange.v ] !solves_force && push!(eqs, 0 ~ flange.f) @@ -64,7 +64,7 @@ Linear 1D position input source. Set `solves_force=false` to force input force end eqs = [ - v.u ~ flange.v, + v.u ~ flange.v ] !solves_force && push!(eqs, 0 ~ flange.f) @@ -91,7 +91,7 @@ Linear 1D position input source. Set `solves_force=false` to force input force vars = @variables v(t) = 0 eqs = [v ~ flange.v - D(v) ~ a.u] + D(v) ~ a.u] !solves_force && push!(eqs, 0 ~ flange.f) diff --git a/src/Mechanical/TranslationalModelica/utils.jl b/src/Mechanical/TranslationalModelica/utils.jl index a12016087..02c3099a3 100644 --- a/src/Mechanical/TranslationalModelica/utils.jl +++ b/src/Mechanical/TranslationalModelica/utils.jl @@ -101,7 +101,7 @@ function PartialElementaryOneFlangeAndSupport2(; name, use_support = false) @named flange = Flange() @variables s_support(t) [description = "Absolute position of support flange"] @variables s(t) [ - description = "Distance between flange and support (= flange.s - support.s)", + description = "Distance between flange and support (= flange.s - support.s)" ] eqs = [s ~ flange.s - s_support] if use_support @@ -135,7 +135,7 @@ function PartialElementaryTwoFlangesAndSupport2(; name, use_support = false) @variables s_support(t) [description = "Absolute position of support flange"] eqs = [s_a ~ flange_a.s - s_support - s_b ~ flange_b.s - s_support] + s_b ~ flange_b.s - s_support] if use_support @named support = Support() push!(eqs, support.f ~ -flange_a.f - flange_b.f) diff --git a/src/Mechanical/TranslationalPosition/components.jl b/src/Mechanical/TranslationalPosition/components.jl index 427738e3c..c6f2aeb24 100644 --- a/src/Mechanical/TranslationalPosition/components.jl +++ b/src/Mechanical/TranslationalPosition/components.jl @@ -65,7 +65,7 @@ end const REL = Val(:relative) @component function Spring(::Val{:relative}; name, k, va = 0.0, vb = 0.0, - delta_s = 0, flange_a__s = 0, flange_b__s = 0) + delta_s = 0, flange_a__s = 0, flange_b__s = 0) pars = @parameters begin k = k end @@ -80,19 +80,22 @@ const REL = Val(:relative) @named flange_b = Flange() eqs = [D(flange_a.s) ~ va - D(flange_b.s) ~ vb - D(delta_s) ~ va - vb - f ~ k * delta_s - flange_a.f ~ +f - flange_b.f ~ -f] - - return compose(ODESystem(eqs, t, vars, pars; name = name, + D(flange_b.s) ~ vb + D(delta_s) ~ va - vb + f ~ k * delta_s + flange_a.f ~ +f + flange_b.f ~ -f] + + return compose( + ODESystem(eqs, t, vars, pars; name = name, defaults = [ flange_a.s => flange_a__s, flange_b.s => flange_b__s, flange_a.f => +delta_s * k, - flange_b.f => -delta_s * k, - ]), flange_a, flange_b) + flange_b.f => -delta_s * k + ]), + flange_a, + flange_b) end const ABS = Val(:absolute) @@ -119,8 +122,8 @@ function Spring(; name, k, flange_a__s = 0, flange_b__s = 0, l = 0) end #default function @component function Spring(::Val{:absolute}; - name, k, flange_a__s = 0, - flange_b__s = 0, l = 0) + name, k, flange_a__s = 0, + flange_b__s = 0, l = 0) pars = @parameters begin k = k l = l @@ -133,10 +136,10 @@ end #default function @named flange_b = Flange(; s = flange_a__s, f = -k * (flange_a__s - flange_b__s - l)) eqs = [ - # delta_s ~ flange_a.s - flange_b.s - f ~ k * (flange_a.s - flange_b.s - l) #delta_s - flange_a.f ~ +f - flange_b.f ~ -f] + # delta_s ~ flange_a.s - flange_b.s + f ~ k * (flange_a.s - flange_b.s - l) #delta_s + flange_a.f ~ +f + flange_b.f ~ -f] return compose(ODESystem(eqs, t, vars, pars; name = name), flange_a, flange_b) end diff --git a/src/Mechanical/TranslationalPosition/utils.jl b/src/Mechanical/TranslationalPosition/utils.jl index b242f2047..3a8f20c09 100644 --- a/src/Mechanical/TranslationalPosition/utils.jl +++ b/src/Mechanical/TranslationalPosition/utils.jl @@ -111,7 +111,7 @@ Partial model for a component with one translational 1-dim. shaft flange and a s if use_support @named support = Support() eqs = [support.s ~ s_support - support.f ~ -flange.f] + support.f ~ -flange.f] push!(sys, support) else eqs = [s_support ~ 0] @@ -140,7 +140,7 @@ Partial model for a component with two translational 1-dim. flanges and a suppor if use_support @named support = Support() eqs = [support.s ~ s_support - support.f ~ -flange_a.f - flange_b.f] + support.f ~ -flange_a.f - flange_b.f] push!(sys, support) else eqs = [s_support ~ 0] diff --git a/src/Thermal/HeatTransfer/ideal_components.jl b/src/Thermal/HeatTransfer/ideal_components.jl index f4e0e19c0..bbb3bf256 100644 --- a/src/Thermal/HeatTransfer/ideal_components.jl +++ b/src/Thermal/HeatTransfer/ideal_components.jl @@ -205,7 +205,7 @@ This is a model to collect the heat flows from `m` heatports to one single heatp port_a = [HeatPort(name = Symbol(:port_a, i)) for i in 1:m] @named port_b = HeatPort() eqs = [port_b.Q_flow + sum(k -> k.Q_flow, port_a) ~ 0 - port_b.T ~ port_a[1].T] + port_b.T ~ port_a[1].T] for i in 1:(m - 1) push!(eqs, port_a[i].T ~ port_a[i + 1].T) end diff --git a/src/Thermal/Thermal.jl b/src/Thermal/Thermal.jl index 1a2958fd9..d5d59fcf4 100644 --- a/src/Thermal/Thermal.jl +++ b/src/Thermal/Thermal.jl @@ -12,8 +12,8 @@ export HeatPort, Element1D include("utils.jl") export BodyRadiation, ConvectiveConductor, ConvectiveResistor, HeatCapacitor, - ThermalConductor, - ThermalResistor, ThermalCollector + ThermalConductor, + ThermalResistor, ThermalCollector include("HeatTransfer/ideal_components.jl") export RelativeTemperatureSensor, HeatFlowSensor, TemperatureSensor diff --git a/test/Blocks/continuous.jl b/test/Blocks/continuous.jl index 8b28fbea5..4239583cb 100644 --- a/test/Blocks/continuous.jl +++ b/test/Blocks/continuous.jl @@ -28,9 +28,10 @@ end @named source = Sine(; frequency = 1) @named int = Integrator(; k = 1) @named der = Derivative(; k = 1, T = 0.001) - @named iosys = ODESystem([ + @named iosys = ODESystem( + [ connect(source.output, der.input), - connect(der.output, int.input), + connect(der.output, int.input) ], t, systems = [int, source, der]) @@ -96,7 +97,7 @@ end @named ss = StateSpace(; A, B, C, D, x = zeros(2)) @named c = Constant(; k = 1) @named model = ODESystem([ - connect(c.output, ss.input), + connect(c.output, ss.input) ], t, systems = [ss, c]) @@ -116,7 +117,7 @@ end y0 = [2] @named ss = StateSpace(; A, B, C, D, x = zeros(2), u0, y0) @named model = ODESystem([ - connect(c.output, ss.input), + connect(c.output, ss.input) ], t, systems = [ss, c]) @@ -140,8 +141,8 @@ Second order demo plant D = Differential(t) sts = @variables x1(t)=x[1] x2(t)=x[2] eqs = [D(x1) ~ x2 - D(x2) ~ -x1 - 0.5 * x2 + input.u - output.u ~ 0.9 * x1 + x2] + D(x2) ~ -x1 - 0.5 * x2 + input.u + output.u ~ 0.9 * x1 + x2] compose(ODESystem(eqs, t, sts, []; name), [input, output]) end @@ -151,11 +152,12 @@ end @named pi_controller = PI(k = 1, T = 1) @named plant = Plant() @named fb = Feedback() - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, fb.input1), connect(plant.output, fb.input2), connect(fb.output, pi_controller.err_input), - connect(pi_controller.ctr_output, plant.input), + connect(pi_controller.ctr_output, plant.input) ], t, systems = [pi_controller, plant, ref, fb]) @@ -173,11 +175,12 @@ end @named pid_controller = PID(k = 3, Ti = 0.5, Td = 1 / 100) @named plant = Plant() @named fb = Feedback() - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, fb.input1), connect(plant.output, fb.input2), connect(fb.output, pid_controller.err_input), - connect(pid_controller.ctr_output, plant.input), + connect(pid_controller.ctr_output, plant.input) ], t, systems = [pid_controller, plant, ref, fb]) @@ -190,11 +193,12 @@ end @testset "PI" begin @named pid_controller = PID(k = 3, Ti = 0.5, Td = false) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, fb.input1), connect(plant.output, fb.input2), connect(fb.output, pid_controller.err_input), - connect(pid_controller.ctr_output, plant.input), + connect(pid_controller.ctr_output, plant.input) ], t, systems = [pid_controller, plant, ref, fb]) @@ -208,11 +212,12 @@ end @testset "PD" begin @named pid_controller = PID(k = 10, Ti = false, Td = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, fb.input1), connect(plant.output, fb.input2), connect(fb.output, pid_controller.err_input), - connect(pid_controller.ctr_output, plant.input), + connect(pid_controller.ctr_output, plant.input) ], t, systems = [pid_controller, plant, ref, fb]) @@ -240,12 +245,13 @@ end # without anti-windup measure sol = let - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, fb.input1), connect(plant.output, fb.input2), connect(fb.output, pi_controller.err_input), connect(pi_controller.ctr_output, sat.input), - connect(sat.output, plant.input), + connect(sat.output, plant.input) ], t, systems = [pi_controller, plant, ref, fb, sat]) @@ -256,12 +262,13 @@ end # with anti-windup measure sol_lim = let - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, fb.input1), connect(plant.output, fb.input2), connect(fb.output, pi_controller_lim.err_input), connect(pi_controller_lim.ctr_output, sat.input), - connect(sat.output, plant.input), + connect(sat.output, plant.input) ], t, systems = [pi_controller_lim, plant, ref, fb, sat]) @@ -285,13 +292,15 @@ end @testset "LimPID" begin re_val = 1 @named ref = Constant(; k = re_val) - @named pid_controller = LimPID(k = 3, Ti = 0.5, Td = 1 / 100, u_max = 1.5, u_min = -1.5, + @named pid_controller = LimPID( + k = 3, Ti = 0.5, Td = 1 / 100, u_max = 1.5, u_min = -1.5, Ni = 0.1 / 0.5) @named plant = Plant() - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, pid_controller.reference), connect(plant.output, pid_controller.measurement), - connect(pid_controller.ctr_output, plant.input), + connect(pid_controller.ctr_output, plant.input) ], t, systems = [pid_controller, plant, ref]) @@ -308,10 +317,11 @@ end @testset "PI" begin @named pid_controller = LimPID(k = 3, Ti = 0.5, Td = false, u_max = 1.5, u_min = -1.5, Ni = 0.1 / 0.5) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, pid_controller.reference), connect(plant.output, pid_controller.measurement), - connect(pid_controller.ctr_output, plant.input), + connect(pid_controller.ctr_output, plant.input) ], t, systems = [pid_controller, plant, ref]) @@ -328,10 +338,11 @@ end @testset "PD" begin @named pid_controller = LimPID(k = 10, Ti = false, Td = 1, u_max = 1.5, u_min = -1.5) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, pid_controller.reference), connect(plant.output, pid_controller.measurement), - connect(pid_controller.ctr_output, plant.input), + connect(pid_controller.ctr_output, plant.input) ], t, systems = [pid_controller, plant, ref]) @@ -349,10 +360,11 @@ end @testset "wp" begin @named pid_controller = LimPID(k = 3, Ti = 0.5, Td = 1 / 100, u_max = 1.5, u_min = -1.5, Ni = 0.1 / 0.5, wp = 0, wd = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, pid_controller.reference), connect(plant.output, pid_controller.measurement), - connect(pid_controller.ctr_output, plant.input), + connect(pid_controller.ctr_output, plant.input) ], t, systems = [pid_controller, plant, ref]) @@ -370,10 +382,11 @@ end @testset "wd" begin @named pid_controller = LimPID(k = 3, Ti = 0.5, Td = 1 / 100, u_max = 1.5, u_min = -1.5, Ni = 0.1 / 0.5, wp = 1, wd = 0) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, pid_controller.reference), connect(plant.output, pid_controller.measurement), - connect(pid_controller.ctr_output, plant.input), + connect(pid_controller.ctr_output, plant.input) ], t, systems = [pid_controller, plant, ref]) @@ -392,10 +405,11 @@ end @testset "PI without AWM" begin @named pid_controller = LimPID(k = 3, Ti = 0.5, Td = false, u_max = 1.5, u_min = -1.5, Ni = Inf) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(ref.output, pid_controller.reference), connect(plant.output, pid_controller.measurement), - connect(pid_controller.ctr_output, plant.input), + connect(pid_controller.ctr_output, plant.input) ], t, systems = [pid_controller, plant, ref]) diff --git a/test/Blocks/math.jl b/test/Blocks/math.jl index 1ad2317fc..aaf7f796f 100644 --- a/test/Blocks/math.jl +++ b/test/Blocks/math.jl @@ -10,10 +10,12 @@ using OrdinaryDiffEq: ReturnCode.Success @named c = Constant(; k = 1) @named gain = Gain(; k = 1) @named int = Integrator(; k = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c.output, gain.input), - connect(gain.output, int.input), - ], t, systems = [int, gain, c]) + connect(gain.output, int.input) + ], + t, systems = [int, gain, c]) sys = structural_simplify(model) prob = ODEProblem(sys, Pair[int.x => 1.0], (0.0, 1.0)) @@ -30,11 +32,12 @@ end @named gain = Gain(; k = 1) @named int = Integrator(; k = 1) @named fb = Feedback(;) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c.output, fb.input1), connect(fb.input2, int.output), connect(fb.output, gain.input), - connect(gain.output, int.input), + connect(gain.output, int.input) ], t, systems = [int, gain, c, fb]) @@ -53,10 +56,11 @@ end @named c2 = Sine(; frequency = 1) @named add = Add(;) @named int = Integrator(; k = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c1.output, add.input1), connect(c2.output, add.input2), - connect(add.output, int.input), + connect(add.output, int.input) ], t, systems = [int, add, c1, c2]) @@ -71,10 +75,11 @@ end k1 = -1 k2 = 2 @named add = Add(; k1 = k1, k2 = k2) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c1.output, add.input1), connect(c2.output, add.input2), - connect(add.output, int.input), + connect(add.output, int.input) ], t, systems = [int, add, c1, c2]) @@ -93,11 +98,12 @@ end @named c3 = Sine(; frequency = 2) @named add = Add3(;) @named int = Integrator(; k = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c1.output, add.input1), connect(c2.output, add.input2), connect(c3.output, add.input3), - connect(add.output, int.input), + connect(add.output, int.input) ], t, systems = [int, add, c1, c2, c3]) @@ -113,11 +119,12 @@ end k2 = 2 k3 = -pi @named add = Add3(; k1 = k1, k2 = k2, k3 = k3) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c1.output, add.input1), connect(c2.output, add.input2), connect(c3.output, add.input3), - connect(add.output, int.input), + connect(add.output, int.input) ], t, systems = [int, add, c1, c2, c3]) @@ -136,10 +143,11 @@ end @named c2 = Sine(; frequency = 1) @named prod = Product(;) @named int = Integrator(; k = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c1.output, prod.input1), connect(c2.output, prod.input2), - connect(prod.output, int.input), + connect(prod.output, int.input) ], t, systems = [int, prod, c1, c2]) @@ -156,10 +164,11 @@ end @named c2 = Constant(; k = 2) @named div = Division(;) @named int = Integrator(; k = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c1.output, div.input1), connect(c2.output, div.input2), - connect(div.output, int.input), + connect(div.output, int.input) ], t, systems = [int, div, c1, c2]) @@ -175,9 +184,10 @@ end @named c = Sine(; frequency = 1) @named absb = Abs(;) @named int = Integrator(; k = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c.output, absb.input), - connect(absb.output, int.input), + connect(absb.output, int.input) ], t, systems = [int, absb, c]) @@ -215,16 +225,18 @@ end (Sinh, sinh), (Cosh, cosh), (Tanh, tanh), - (Exp, exp), + (Exp, exp) ] @info "testing $block" @named source = Sine(frequency = 1, amplitude = 0.5) @named b = block() @named int = Integrator() - @named model = ODESystem([ + @named model = ODESystem( + [ connect(source.output, b.input), - connect(b.output, int.input), - ], t, systems = [int, b, source]) + connect(b.output, int.input) + ], + t, systems = [int, b, source]) sys = structural_simplify(model) prob = ODEProblem(sys, Pair[int.x => 0.0], (0.0, 1.0)) sol = solve(prob, Rodas4()) @@ -239,10 +251,12 @@ end @named source = Sine(; frequency = 1, offset = 2, amplitude = 0.5) @named b = block() @named int = Integrator() - @named model = ODESystem([ + @named model = ODESystem( + [ connect(source.output, b.input), - connect(b.output, int.input), - ], t, systems = [int, b, source]) + connect(b.output, int.input) + ], + t, systems = [int, b, source]) sys = structural_simplify(model) prob = ODEProblem(sys, Pair[int.x => 0.0, b.input.u => 2.0], (0.0, 1.0)) sol = solve(prob, Rodas4()) @@ -257,10 +271,11 @@ end @named c2 = Sine(; frequency = 1, offset = 1) @named b = Atan2(;) @named int = Integrator(; k = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c1.output, b.input1), connect(c2.output, b.input2), - connect(b.output, int.input), + connect(b.output, int.input) ], t, systems = [int, b, c1, c2]) diff --git a/test/Blocks/nonlinear.jl b/test/Blocks/nonlinear.jl index e13a45047..4f5bd1d08 100644 --- a/test/Blocks/nonlinear.jl +++ b/test/Blocks/nonlinear.jl @@ -10,9 +10,10 @@ using OrdinaryDiffEq: ReturnCode.Success @named c = Constant(; k = 1) @named int = Integrator(; k = 1) @named sat = Limiter(; y_min = -0.6, y_max = 0.8) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c.output, int.input), - connect(int.output, sat.input), + connect(int.output, sat.input) ], t, systems = [int, c, sat]) @@ -30,9 +31,10 @@ using OrdinaryDiffEq: ReturnCode.Success @named source = Sine(; frequency = 1 / 2) @named lim = Limiter(; y_max = y_max, y_min = y_min) @named int = Integrator(; k = 1) - @named iosys = ODESystem([ + @named iosys = ODESystem( + [ connect(source.output, lim.input), - connect(lim.output, int.input), + connect(lim.output, int.input) ], t, systems = [source, lim, int]) @@ -57,9 +59,10 @@ end @named c = Constant(; k = 1) @named int = Integrator(; k = 1) @named dz = DeadZone(; u_min = -2, u_max = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(c.output, int.input), - connect(int.output, dz.input), + connect(int.output, dz.input) ], t, systems = [int, c, dz]) @@ -76,9 +79,10 @@ end @named source = Sine(; amplitude = 3, frequency = 1 / 2) @named dz = DeadZone(; u_min = u_min, u_max = u_max) @named int = Integrator(; k = 1) - @named model = ODESystem([ + @named model = ODESystem( + [ connect(source.output, dz.input), - connect(dz.output, int.input), + connect(dz.output, int.input) ], t, systems = [int, source, dz]) @@ -102,7 +106,7 @@ end @named source = Sine(; frequency = 1 / 2) @named rl = SlewRateLimiter(; rising = 1, falling = -1, Td = 0.001, y_start = -1 / 3) @named iosys = ODESystem([ - connect(source.output, rl.input), + connect(source.output, rl.input) ], t, systems = [source, rl]) diff --git a/test/Blocks/sources.jl b/test/Blocks/sources.jl index b1df8f21b..43cc5bd7b 100644 --- a/test/Blocks/sources.jl +++ b/test/Blocks/sources.jl @@ -1,8 +1,8 @@ using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEq using ModelingToolkitStandardLibrary.Blocks using ModelingToolkitStandardLibrary.Blocks: smooth_sin, smooth_cos, smooth_damped_sin, - smooth_square, smooth_step, smooth_ramp, - smooth_triangular, triangular, square + smooth_square, smooth_step, smooth_ramp, + smooth_triangular, triangular, square using OrdinaryDiffEq: ReturnCode.Success @parameters t @@ -12,7 +12,7 @@ D = Differential(t) @named src = Constant(k = 2) @named int = Integrator() @named iosys = ODESystem([ - connect(src.output, int.input), + connect(src.output, int.input) ], t, systems = [int, src]) @@ -30,10 +30,11 @@ end vars = @variables y(t)=1 dy(t)=0 ddy(t)=0 @named src = TimeVaryingFunction(f) @named int = Integrator() - @named iosys = ODESystem([y ~ src.output.u - D(y) ~ dy - D(dy) ~ ddy - connect(src.output, int.input)], + @named iosys = ODESystem( + [y ~ src.output.u + D(y) ~ dy + D(dy) ~ ddy + connect(src.output, int.input)], t, systems = [int, src]) sys = structural_simplify(iosys) @@ -63,7 +64,7 @@ end @named src = Sine(frequency = frequency, amplitude = amplitude, phase = phase, offset = offset, start_time = start_time) @named iosys = ODESystem([ - connect(src.output, int.input), + connect(src.output, int.input) ], t, systems = [int, src]) @@ -82,7 +83,7 @@ end start_time = start_time, smooth = true) @named smooth_iosys = ODESystem([ - connect(smooth_src.output, int.input), + connect(smooth_src.output, int.input) ], t, systems = [int, smooth_src]) @@ -92,7 +93,8 @@ end smooth_sol = solve(smooth_prob, Rodas4()) @test sol.retcode == Success - @test smooth_sol[smooth_src.output.u]≈smooth_sin.(smooth_sol.t, δ, frequency, amplitude, + @test smooth_sol[smooth_src.output.u]≈smooth_sin.( + smooth_sol.t, δ, frequency, amplitude, phase, offset, start_time) atol=1e-3 end @@ -117,7 +119,7 @@ end start_time = start_time, smooth = false) @named iosys = ODESystem([ - connect(src.output, int.input), + connect(src.output, int.input) ], t, systems = [int, src]) @@ -135,7 +137,7 @@ end start_time = start_time, smooth = true) @named smooth_iosys = ODESystem([ - connect(smooth_src.output, int.input), + connect(smooth_src.output, int.input) ], t, systems = [int, smooth_src]) @@ -145,7 +147,8 @@ end smooth_sol = solve(smooth_prob, Rodas4()) @test smooth_sol.retcode == Success - @test smooth_sol[smooth_src.output.u]≈smooth_cos.(smooth_sol.t, δ, frequency, amplitude, + @test smooth_sol[smooth_src.output.u]≈smooth_cos.( + smooth_sol.t, δ, frequency, amplitude, phase, offset, start_time) atol=1e-3 end @@ -157,7 +160,7 @@ end @named src = ContinuousClock(offset = offset, start_time = start_time) @named int = Integrator() @named iosys = ODESystem([ - connect(src.output, int.input), + connect(src.output, int.input) ], t, systems = [int, src]) @@ -183,7 +186,7 @@ end @named src = Ramp(offset = offset, height = height, duration = duration, start_time = start_time) @named iosys = ODESystem([ - connect(src.output, int.input), + connect(src.output, int.input) ], t, systems = [int, src]) @@ -198,7 +201,7 @@ end @named smooth_src = Ramp(offset = offset, height = height, duration = duration, start_time = start_time, smooth = true) @named smooth_iosys = ODESystem([ - connect(smooth_src.output, int.input), + connect(smooth_src.output, int.input) ], t, systems = [int, smooth_src]) @@ -221,7 +224,7 @@ end @named src = Step(offset = offset, height = height, start_time = start_time, smooth = false) @named iosys = ODESystem([ - connect(src.output, int.input), + connect(src.output, int.input) ], t, systems = [int, src]) @@ -238,7 +241,7 @@ end @named src = Step(offset = offset, height = height, start_time = start_time, duration = duration, smooth = false) @named iosys = ODESystem([ - connect(src.output, int.input), + connect(src.output, int.input) ], t, systems = [int, src]) @@ -254,7 +257,7 @@ end @named smooth_src = Step(offset = offset, height = height, start_time = start_time, smooth = true) @named smooth_iosys = ODESystem([ - connect(smooth_src.output, int.input), + connect(smooth_src.output, int.input) ], t, systems = [int, smooth_src]) @@ -271,7 +274,7 @@ end @named smooth_src = Step(offset = offset, height = height, start_time = start_time, smooth = true, duration = duration) @named smooth_iosys = ODESystem([ - connect(smooth_src.output, int.input), + connect(smooth_src.output, int.input) ], t, systems = [int, smooth_src]) @@ -297,7 +300,7 @@ end @named src = Square(frequency = frequency, amplitude = amplitude, offset = offset, start_time = start_time) @named iosys = ODESystem([ - connect(src.output, int.input), + connect(src.output, int.input) ], t, systems = [int, src]) @@ -312,7 +315,7 @@ end @named smooth_src = Square(frequency = frequency, amplitude = amplitude, offset = offset, start_time = start_time, smooth = true) @named smooth_iosys = ODESystem([ - connect(smooth_src.output, int.input), + connect(smooth_src.output, int.input) ], t, systems = [int, smooth_src]) @@ -337,7 +340,7 @@ end @named src = Triangular(frequency = frequency, amplitude = amplitude, offset = offset, start_time = start_time) @named iosys = ODESystem([ - connect(src.output, int.input), + connect(src.output, int.input) ], t, systems = [int, src]) @@ -352,7 +355,7 @@ end @named smooth_src = Triangular(frequency = frequency, amplitude = amplitude, offset = offset, start_time = start_time, smooth = true) @named smooth_iosys = ODESystem([ - connect(smooth_src.output, int.input), + connect(smooth_src.output, int.input) ], t, systems = [int, smooth_src]) @@ -379,7 +382,7 @@ end phase = phase, offset = offset, start_time = start_time) @named int = Integrator() @named iosys = ODESystem([ - connect(src.output, int.input), + connect(src.output, int.input) ], t, systems = [int, src]) @@ -395,7 +398,7 @@ end damping = damping, phase = phase, offset = offset, start_time = start_time, smooth = true) @named smooth_iosys = ODESystem([ - connect(smooth_src.output, int.input), + connect(smooth_src.output, int.input) ], t, systems = [int, smooth_src]) @@ -421,10 +424,11 @@ end vars = @variables y(t)=1 dy(t)=0 ddy(t)=0 @named src = SampledData(Float64) @named int = Integrator() - @named iosys = ODESystem([y ~ src.output.u - D(y) ~ dy - D(dy) ~ ddy - connect(src.output, int.input)], + @named iosys = ODESystem( + [y ~ src.output.u + D(y) ~ dy + D(dy) ~ ddy + connect(src.output, int.input)], t, systems = [int, src]) sys = structural_simplify(iosys) @@ -450,10 +454,11 @@ end vars = @variables y(t)=1 dy(t)=0 ddy(t)=0 @named src = SampledData(dt) @named int = Integrator() - @named iosys = ODESystem([y ~ src.output.u - D(y) ~ dy - D(dy) ~ ddy - connect(src.output, int.input)], + @named iosys = ODESystem( + [y ~ src.output.u + D(y) ~ dy + D(dy) ~ ddy + connect(src.output, int.input)], t, systems = [int, src]) sys = structural_simplify(iosys) diff --git a/test/Blocks/test_analysis_points.jl b/test/Blocks/test_analysis_points.jl index 533265a5e..b6468e203 100644 --- a/test/Blocks/test_analysis_points.jl +++ b/test/Blocks/test_analysis_points.jl @@ -14,7 +14,7 @@ t = ModelingToolkit.get_iv(P) # Test with explicitly created AnalysisPoint ap = AnalysisPoint(:plant_input) eqs = [connect(P.output, C.input) - connect(C.output, ap, P.input)] + connect(C.output, ap, P.input)] sys = ODESystem(eqs, t, systems = [P, C], name = :hej) ssys = structural_simplify(sys) @@ -45,7 +45,7 @@ T = comp_sensitivity(P, C) # or feedback(P*C) # Test with automatically created analysis point eqs = [connect(P.output, C.input) - connect(C.output, :plant_input, P.input)] + connect(C.output, :plant_input, P.input)] sys = ODESystem(eqs, t, systems = [P, C], name = :hej) matrices, _ = get_sensitivity(sys, :plant_input) @@ -84,7 +84,7 @@ matrices, _ = linearize(open_sys, [u], [y]) # Test with more than one AnalysisPoint eqs = [connect(P.output, :plant_output, C.input) - connect(C.output, :plant_input, P.input)] + connect(C.output, :plant_input, P.input)] sys = ODESystem(eqs, t, systems = [P, C], name = :hej) matrices, _ = get_sensitivity(sys, :plant_input) @@ -111,8 +111,8 @@ matrices2, _ = linearize(sys, :plant_input, [P.output.u]) t = ModelingToolkit.get_iv(P) eqs = [connect(P.output, :plant_output, add.input2) - connect(add.output, C.input) - connect(C.output, :plant_input, P.input)] + connect(add.output, C.input) + connect(C.output, :plant_input, P.input)] # eqs = [connect(P.output, add.input2) # connect(add.output, C.input) @@ -124,7 +124,7 @@ sys_inner = ODESystem(eqs, t, systems = [P, C, add], name = :inner) @named F = FirstOrder(k = 1, T = 3) eqs = [connect(r.output, F.input) - connect(F.output, sys_inner.add.input1)] + connect(F.output, sys_inner.add.input1)] sys_outer = ODESystem(eqs, t, systems = [F, sys_inner, r], name = :outer) # test first that the structural_simplify works correctly @@ -163,8 +163,8 @@ c = 10 # Damping coefficient function SystemModel(u = nothing; name = :model) eqs = [connect(torque.flange, inertia1.flange_a) - connect(inertia1.flange_b, spring.flange_a, damper.flange_a) - connect(inertia2.flange_a, spring.flange_b, damper.flange_b)] + connect(inertia1.flange_b, spring.flange_a, damper.flange_a) + connect(inertia2.flange_a, spring.flange_b, damper.flange_b)] if u !== nothing push!(eqs, connect(torque.tau, u.output)) return @named model = ODESystem(eqs, t; @@ -174,7 +174,7 @@ function SystemModel(u = nothing; name = :model) inertia2, spring, damper, - u, + u ]) end ODESystem(eqs, t; systems = [torque, inertia1, inertia2, spring, damper], name) @@ -183,7 +183,7 @@ function AngleSensor(; name) @named flange = Flange() @named phi = RealOutput() eqs = [phi.u ~ flange.phi - flange.tau ~ 0] + flange.tau ~ 0] return ODESystem(eqs, t, [], []; name = name, systems = [flange, phi]) end @@ -195,11 +195,11 @@ model = SystemModel() @named er = Add(k2 = -1) connections = [connect(r.output, :r, filt.input) - connect(filt.output, er.input1) - connect(pid.ctr_output, :u, model.torque.tau) - connect(model.inertia2.flange_b, sensor.flange) - connect(sensor.phi, :y, er.input2) - connect(er.output, :e, pid.err_input)] + connect(filt.output, er.input1) + connect(pid.ctr_output, :u, model.torque.tau) + connect(model.inertia2.flange_b, sensor.flange) + connect(sensor.phi, :y, er.input2) + connect(er.output, :e, pid.err_input)] closed_loop = ODESystem(connections, t, systems = [model, pid, filt, sensor, r, er], name = :closed_loop) @@ -235,21 +235,27 @@ Si = ss(matrices...) @named P_inner = FirstOrder(k = 1, T = 1) @named feedback = Feedback() @named ref = Step() -@named sys_inner = ODESystem([connect(P_inner.output, :y, feedback.input2) - connect(feedback.output, :u, P_inner.input) - connect(ref.output, :r, feedback.input1)], t, +@named sys_inner = ODESystem( + [connect(P_inner.output, :y, feedback.input2) + connect(feedback.output, :u, P_inner.input) + connect(ref.output, :r, feedback.input1)], + t, systems = [P_inner, feedback, ref]) Sinner = sminreal(ss(get_sensitivity(sys_inner, :u)[1]...)) -@named sys_inner = ODESystem([connect(P_inner.output, :y, feedback.input2) - connect(feedback.output, :u, P_inner.input)], t, +@named sys_inner = ODESystem( + [connect(P_inner.output, :y, feedback.input2) + connect(feedback.output, :u, P_inner.input)], + t, systems = [P_inner, feedback]) @named P_outer = FirstOrder(k = rand(), T = rand()) -@named sys_outer = ODESystem([connect(sys_inner.P_inner.output, :y2, P_outer.input) - connect(P_outer.output, :u2, sys_inner.feedback.input1)], t, +@named sys_outer = ODESystem( + [connect(sys_inner.P_inner.output, :y2, P_outer.input) + connect(P_outer.output, :u2, sys_inner.feedback.input1)], + t, systems = [P_outer, sys_inner]) Souter = sminreal(ss(get_sensitivity(sys_outer, :sys_inner_u)[1]...)) @@ -278,7 +284,7 @@ D = [0.0 0.0; 0.0 0.0] Kss = CS.ss(A, B, C, D) eqs = [connect(P.output, :plant_output, K.input) - connect(K.output, :plant_input, P.input)] + connect(K.output, :plant_input, P.input)] sys = ODESystem(eqs, t, systems = [P, K], name = :hej) matrices, _ = Blocks.get_sensitivity(sys, :plant_input) @@ -308,8 +314,8 @@ G = CS.feedback(Pss, Kss, pos_feedback = true) t = ModelingToolkit.get_iv(P) eqs = [connect(P.output, :plant_output, add.input2) - connect(add.output, C.input) - connect(C.output, :plant_input, P.input)] + connect(add.output, C.input) + connect(C.output, :plant_input, P.input)] sys_inner = ODESystem(eqs, t, systems = [P, C, add], name = :inner) @@ -317,7 +323,7 @@ sys_inner = ODESystem(eqs, t, systems = [P, C, add], name = :inner) @named F = FirstOrder(k = 1, T = 3) eqs = [connect(r.output, F.input) - connect(F.output, sys_inner.add.input1)] + connect(F.output, sys_inner.add.input1)] sys_outer = ODESystem(eqs, t, systems = [F, sys_inner, r], name = :outer) matrices, _ = get_sensitivity(sys_outer, [:inner_plant_input, :inner_plant_output]) diff --git a/test/Electrical/analog.jl b/test/Electrical/analog.jl index 35fce60d5..01f85c8cb 100644 --- a/test/Electrical/analog.jl +++ b/test/Electrical/analog.jl @@ -1,7 +1,7 @@ using ModelingToolkitStandardLibrary.Electrical, ModelingToolkit, OrdinaryDiffEq, Test using ModelingToolkitStandardLibrary.Blocks: Step, - Constant, Sine, Cosine, ExpSine, Ramp, - Square, Triangular + Constant, Sine, Cosine, ExpSine, Ramp, + Square, Triangular using ModelingToolkitStandardLibrary.Blocks: square, triangular using OrdinaryDiffEq: ReturnCode.Success @@ -21,15 +21,15 @@ using OrdinaryDiffEq: ReturnCode.Success @named power_sensor = PowerSensor() connections = [connect(source.output, voltage.V) - connect(voltage.p, resistor.p) - connect(resistor.n, current_sensor.p) - connect(current_sensor.n, power_sensor.pc) - connect(power_sensor.nc, capacitor.p) - connect(capacitor.n, voltage.n, ground.g) - connect(capacitor.p, voltage_sensor.p) - connect(capacitor.n, voltage_sensor.n) - connect(capacitor.p, power_sensor.pv) - connect(capacitor.n, power_sensor.nv)] + connect(voltage.p, resistor.p) + connect(resistor.n, current_sensor.p) + connect(current_sensor.n, power_sensor.pc) + connect(power_sensor.nc, capacitor.p) + connect(capacitor.n, voltage.n, ground.g) + connect(capacitor.p, voltage_sensor.p) + connect(capacitor.n, voltage_sensor.n) + connect(capacitor.p, power_sensor.pv) + connect(capacitor.n, power_sensor.nv)] @named model = ODESystem(connections, t; systems = [ @@ -40,7 +40,7 @@ using OrdinaryDiffEq: ReturnCode.Success ground, voltage_sensor, current_sensor, - power_sensor, + power_sensor ]) sys = structural_simplify(model) prob = ODAEProblem(sys, [], (0.0, 10.0)) @@ -66,10 +66,10 @@ end @named short = Short() connections = [connect(source.output, voltage.V) - connect(voltage.p, R1.p) - connect(R1.n, short.p, R0.p) - connect(short.n, R0.n, R2.p) - connect(R2.n, voltage.n, ground.g)] + connect(voltage.p, R1.p) + connect(R1.n, short.p, R0.p) + connect(short.n, R0.n, R2.p) + connect(R2.n, voltage.n, ground.g)] @named model = ODESystem(connections, t, systems = [R0, R1, R2, source, short, voltage, ground]) @@ -93,9 +93,9 @@ end @named ground = Ground() connections = [connect(source.output, voltage.V) - connect(voltage.p, resistor.p) - connect(resistor.n, capacitor.p) - connect(capacitor.n, voltage.n, ground.g)] + connect(voltage.p, resistor.p) + connect(resistor.n, capacitor.p) + connect(capacitor.n, voltage.n, ground.g)] @named model = ODESystem(connections, t; systems = [resistor, capacitor, source, voltage, ground]) @@ -117,9 +117,9 @@ end @named ground = Ground() connections = [connect(source.output, voltage.V) - connect(voltage.p, resistor.p) - connect(resistor.n, inductor.p) - connect(inductor.n, voltage.n, ground.g)] + connect(voltage.p, resistor.p) + connect(resistor.n, inductor.p) + connect(inductor.n, voltage.n, ground.g)] @named model = ODESystem(connections, t; systems = [resistor, inductor, source, voltage, ground]) @@ -152,9 +152,9 @@ end for source in sources connections = [connect(source.output, voltage.V) - connect(voltage.p, resistor.p) - connect(resistor.n, capacitor.p) - connect(capacitor.n, voltage.n, ground.g)] + connect(voltage.p, resistor.p) + connect(resistor.n, capacitor.p) + connect(capacitor.n, voltage.n, ground.g)] @named model = ODESystem(connections, t; systems = [resistor, capacitor, source, ground, voltage]) @@ -179,9 +179,9 @@ end @named ground = Ground() connections = [connect(source.output, current.I) - connect(current.p, resistor.n) - connect(capacitor.n, resistor.p) - connect(capacitor.p, current.n, ground.g)] + connect(current.p, resistor.n) + connect(capacitor.n, resistor.p) + connect(capacitor.p, current.n, ground.g)] @named model = ODESystem(connections, t; systems = [ground, resistor, current, capacitor, source]) @@ -207,12 +207,12 @@ end @named sensor = VoltageSensor() connections = [connect(square_source.output, voltage.V) - connect(voltage.p, R1.p) - connect(R1.n, C1.n, R2.p, opamp.n1) - connect(opamp.p2, C1.p, R2.n) - connect(opamp.p1, ground.g, opamp.n2, voltage.n) - connect(opamp.p2, sensor.p) - connect(sensor.n, ground.g)] + connect(voltage.p, R1.p) + connect(R1.n, C1.n, R2.p, opamp.n1) + connect(opamp.p2, C1.p, R2.n) + connect(opamp.p1, ground.g, opamp.n2, voltage.n) + connect(opamp.p2, sensor.p) + connect(sensor.n, ground.g)] @named model = ODESystem(connections, t, systems = [ R1, @@ -222,11 +222,11 @@ end voltage, C1, ground, - sensor, + sensor ]) sys = structural_simplify(model) u0 = [C1.v => 0.0 - R1.v => 0.0] + R1.v => 0.0] prob = ODEProblem(sys, u0, (0, 100.0)) sol = solve(prob, Rodas4()) @test sol.retcode == Success @@ -264,13 +264,15 @@ _damped_sine_wave(x, f, A, st, ϕ, d) = exp((st - x) * d) * A * sin(2 * π * f * sources = [step, cosine, sine, damped_sine, ramp, tri, vsquare] #, vsawtooth] function waveforms(i, x) - getindex([o .+ _step.(x, h, st), + getindex( + [o .+ _step.(x, h, st), o .+ (x .> st) .* _cos_wave.(x, f, A, st, ϕ), o .+ (x .> st) .* _sine_wave.(x, f, A, st, ϕ), o .+ (x .> st) .* _damped_sine_wave.(x, f, A, st, ϕ, d), o .+ _ramp.(x, st, (et - st), h), triangular.(x, f, A, o, st), - square.(x, f, A, o, st)], i) + square.(x, f, A, o, st)], + i) end # o .+ (x .> st). * _sawtooth_wave.(x, δ, f, A, st), @@ -278,9 +280,9 @@ _damped_sine_wave(x, f, A, st, ϕ, d) = exp((st - x) * d) * A * sin(2 * π * f * source = sources[i] @info "Testing Voltage with $(source.name) source" eqs = [connect(source.output, voltage.V) - connect(voltage.p, voltage_sensor.p, res.p) - connect(res.n, cap.p) - connect(ground.g, voltage_sensor.n, voltage.n, cap.n)] + connect(voltage.p, voltage_sensor.p, res.p) + connect(res.n, cap.p) + connect(ground.g, voltage_sensor.n, voltage.n, cap.n)] @named vmodel = ODESystem(eqs, t, systems = [ voltage_sensor, @@ -288,7 +290,7 @@ _damped_sine_wave(x, f, A, st, ϕ, d) = exp((st - x) * d) * A * sin(2 * π * f * cap, source, voltage, - ground, + ground ]) vsys = structural_simplify(vmodel) @@ -327,13 +329,15 @@ end sources = [step, cosine, sine, damped_sine, ramp, tri, vsquare] #, idamped_sine] function waveforms(i, x) - getindex([o .+ _step.(x, h, st), + getindex( + [o .+ _step.(x, h, st), o .+ (x .> st) .* _cos_wave.(x, f, A, st, ϕ), o .+ (x .> st) .* _sine_wave.(x, f, A, st, ϕ), o .+ (x .> st) .* _damped_sine_wave.(x, f, A, st, ϕ, d), o .+ _ramp.(x, st, (et - st), h), triangular.(x, f, A, o, st), - square.(x, f, A, o, st)], i) + square.(x, f, A, o, st)], + i) end # # o .+ (x .> st). * _sawtooth_wave.(x, δ, f, A, st) @@ -341,10 +345,10 @@ end source = sources[i] @info "Testing Current with $(source.name) source" eqs = [connect(source.output, current.I) - connect(current.p, current_sensor.n) - connect(current_sensor.p, res.p) - connect(res.n, cap.p) - connect(current.n, ground.g, cap.n)] + connect(current.p, current_sensor.n) + connect(current_sensor.p, res.p) + connect(res.n, cap.p) + connect(current.n, ground.g, cap.n)] @named model = ODESystem(eqs, t, systems = [ current_sensor, @@ -352,7 +356,7 @@ end current, res, cap, - ground, + ground ]) isys = structural_simplify(model) diff --git a/test/Electrical/digital.jl b/test/Electrical/digital.jl index b4264031c..849e506da 100644 --- a/test/Electrical/digital.jl +++ b/test/Electrical/digital.jl @@ -21,7 +21,7 @@ using OrdinaryDiffEq: ReturnCode.Success @test zero(Logic) == zero(U) == F0 @test one(Logic) == one(U) == F1 @test ones(Logic, 2, 2) == [F1 F1 - F1 F1] + F1 F1] # Logic vectors u_logic = StdULogicVector([U, W, X, 1]) @@ -41,7 +41,7 @@ using OrdinaryDiffEq: ReturnCode.Success # Logic vector helpers test_logic_matrix = StdULogicVector([U F0 - F1 X]) + F1 X]) test_logic_vector = StdLogicVector([U, F0, F1, X]) size(test_logic_matrix) == (2, 2) diff --git a/test/Hydraulic/isothermal_compressible.jl b/test/Hydraulic/isothermal_compressible.jl index 2e2e0c836..e8d71a1c8 100644 --- a/test/Hydraulic/isothermal_compressible.jl +++ b/test/Hydraulic/isothermal_compressible.jl @@ -26,9 +26,9 @@ NEWTON = NLNewton(check_div = false, always_new = true, max_iter = 100, relax = end eqs = [connect(stp.output, src.p) - connect(fluid, src.port) - connect(src.port, res.port_a) - connect(res.port_b, vol.port)] + connect(fluid, src.port) + connect(src.port, res.port_a) + connect(res.port_b, vol.port)] ODESystem(eqs, t, [], pars; name, systems) end @@ -41,7 +41,7 @@ NEWTON = NLNewton(check_div = false, always_new = true, max_iter = 100, relax = probs = [ODEProblem(sys, ModelingToolkit.missing_variable_defaults(sys), (0, 0.05)) for sys in syss] # sols = [solve(prob, ImplicitEuler(nlsolve = NEWTON); initializealg = NoInit(), - dt = 1e-4, adaptive = false) + dt = 1e-4, adaptive = false) for prob in probs] s1_2 = complete(sys1_2) @@ -79,9 +79,9 @@ end end eqs = [connect(fluid, sink.port) - connect(sink.port, valve.port_a) - connect(valve.port_b, vol.port) - connect(valve.area, ramp.output)] + connect(sink.port, valve.port_a) + connect(valve.port_b, vol.port) + connect(valve.area, ramp.output)] ODESystem(eqs, t, [], pars; name, systems) end @@ -127,12 +127,12 @@ end end eqs = [connect(fluid, src1.port) - connect(fluid, src2.port) - connect(src1.port, vol1.port) - connect(src2.port, vol2.port) - connect(vol1.flange, mass.flange, vol2.flange) - connect(src1.p, sin1.output) - connect(src2.p, sin2.output)] + connect(fluid, src2.port) + connect(src1.port, vol1.port) + connect(src2.port, vol2.port) + connect(vol1.flange, mass.flange, vol2.flange) + connect(src1.p, sin1.output) + connect(src2.p, sin2.output)] ODESystem(eqs, t, [], pars; name, systems) end @@ -261,17 +261,17 @@ end push!(systems, input) eqs = [connect(input.output, pos.s) - connect(valve.flange, pos.flange) - connect(valve.port_a, piston.port_a) - connect(piston.flange, body.flange) - connect(piston.port_b, m1.port_a) - connect(m1.port_b, pipe.port_b) - connect(pipe.port_a, m2.port_b) - connect(m2.port_a, valve.port_b) - connect(src.port, valve.port_s) - connect(snk.port, valve.port_r) - connect(fluid, src.port, snk.port) - D(body.v) ~ ddx] + connect(valve.flange, pos.flange) + connect(valve.port_a, piston.port_a) + connect(piston.flange, body.flange) + connect(piston.port_b, m1.port_a) + connect(m1.port_b, pipe.port_b) + connect(pipe.port_a, m2.port_b) + connect(m2.port_a, valve.port_b) + connect(src.port, valve.port_s) + connect(snk.port, valve.port_r) + connect(fluid, src.port, snk.port) + D(body.v) ~ ddx] ODESystem(eqs, t, vars, pars; name, systems) end @@ -322,7 +322,7 @@ end end eqs = [connect(fluid, cap.port, vol.port) - connect(vol.flange, mass.flange)] + connect(vol.flange, mass.flange)] ODESystem(eqs, t, [], pars; name, systems) end diff --git a/test/Magnetic/magnetic.jl b/test/Magnetic/magnetic.jl index e378c32f4..8c0d1cdf8 100644 --- a/test/Magnetic/magnetic.jl +++ b/test/Magnetic/magnetic.jl @@ -26,16 +26,16 @@ using OrdinaryDiffEq: ReturnCode.Success @named r_mFe = Magnetic.FluxTubes.ConstantReluctance(R_m = a * b * l_Fe * mu_Fe) @named r_mLeak = Magnetic.FluxTubes.ConstantReluctance(R_m = 1.2e6) connections = [connect(source.output, voltage.V) - connect(voltage.p, r.p) - connect(r.n, coil.p) - connect(voltage.n, coil.n) - connect(coil.port_p, r_mLeak.port_p) - connect(r_mLeak.port_p, r_mAirPar.port_p) - connect(r_mAirPar.port_n, r_mFe.port_p) - connect(r_mFe.port_n, r_mLeak.port_n) - connect(r_mFe.port_n, coil.port_n) - connect(ground.g, voltage.n) - connect(ground_m.port, r_mFe.port_n)] + connect(voltage.p, r.p) + connect(r.n, coil.p) + connect(voltage.n, coil.n) + connect(coil.port_p, r_mLeak.port_p) + connect(r_mLeak.port_p, r_mAirPar.port_p) + connect(r_mAirPar.port_n, r_mFe.port_p) + connect(r_mFe.port_n, r_mLeak.port_n) + connect(r_mFe.port_n, coil.port_n) + connect(ground.g, voltage.n) + connect(ground_m.port, r_mFe.port_n)] @named model = ODESystem(connections, t, systems = [ source, @@ -46,7 +46,7 @@ using OrdinaryDiffEq: ReturnCode.Success r_mAirPar, r_mFe, r_mLeak, - voltage, + voltage ]) sys = structural_simplify(model) prob = ODEProblem(sys, Pair[], (0, 0.1)) diff --git a/test/Mechanical/multibody.jl b/test/Mechanical/multibody.jl index 92a07407a..68172c57a 100644 --- a/test/Mechanical/multibody.jl +++ b/test/Mechanical/multibody.jl @@ -16,9 +16,9 @@ using Test # @named m2 = Mass(;m=0.5) eqs = [connect(link1.TX1, cart.flange) #, force.flange) - connect(link1.TY1, fixed.flange) - connect(link1.TX2, link2.TX1) - connect(link1.TY2, link2.TY1)] + connect(link1.TY1, fixed.flange) + connect(link1.TX2, link2.TX1) + connect(link1.TY2, link2.TY1)] @named model = ODESystem(eqs, t, [], []; systems = [link1, link2, cart, fixed]) diff --git a/test/Mechanical/rotational.jl b/test/Mechanical/rotational.jl index cbbc35887..08a17c6e6 100644 --- a/test/Mechanical/rotational.jl +++ b/test/Mechanical/rotational.jl @@ -1,6 +1,6 @@ using ModelingToolkitStandardLibrary.Mechanical.Rotational, - ModelingToolkit, OrdinaryDiffEq, - Test + ModelingToolkit, OrdinaryDiffEq, + Test import ModelingToolkitStandardLibrary.Blocks using OrdinaryDiffEq: ReturnCode.Success @@ -17,8 +17,8 @@ D = Differential(t) @named inertia2 = Inertia(J = 2, phi = pi / 2) connections = [connect(fixed.flange, inertia1.flange_b) - connect(inertia1.flange_b, spring.flange_a, damper.flange_a) - connect(spring.flange_b, damper.flange_b, inertia2.flange_a)] + connect(inertia1.flange_b, spring.flange_a, damper.flange_a) + connect(spring.flange_b, damper.flange_b, inertia2.flange_a)] @named model = ODESystem(connections, t, systems = [fixed, inertia1, inertia2, spring, damper]) @@ -40,8 +40,8 @@ D = Differential(t) @named springdamper = SpringDamper(; c = 1e4, d = 10) connections = [connect(fixed.flange, inertia1.flange_b) - connect(inertia1.flange_b, springdamper.flange_a) - connect(springdamper.flange_b, inertia2.flange_a)] + connect(inertia1.flange_b, springdamper.flange_a) + connect(springdamper.flange_b, inertia2.flange_a)] @named model = ODESystem(connections, t, systems = [fixed, inertia1, inertia2, springdamper]) @@ -70,10 +70,10 @@ end @named sine = Blocks.Sine(amplitude = amplitude, frequency = frequency) connections = [connect(sine.output, torque.tau) - connect(torque.support, fixed.flange) - connect(torque.flange, inertia1.flange_a) - connect(inertia1.flange_b, spring.flange_a, damper.flange_a) - connect(spring.flange_b, damper.flange_b, inertia2.flange_a)] + connect(torque.support, fixed.flange) + connect(torque.flange, inertia1.flange_a) + connect(inertia1.flange_b, spring.flange_a, damper.flange_a) + connect(spring.flange_b, damper.flange_b, inertia2.flange_a)] @named model = ODESystem(connections, t, systems = [ @@ -83,7 +83,7 @@ end inertia2, spring, damper, - sine, + sine ]) sys = structural_simplify(model) prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, @@ -101,9 +101,9 @@ end ## Test with constant torque source @named torque = ConstantTorque(use_support = true, tau_constant = 1) connections = [connect(torque.support, fixed.flange) - connect(torque.flange, inertia1.flange_a) - connect(inertia1.flange_b, spring.flange_a, damper.flange_a) - connect(spring.flange_b, damper.flange_b, inertia2.flange_a)] + connect(torque.flange, inertia1.flange_a) + connect(inertia1.flange_b, spring.flange_a, damper.flange_a) + connect(spring.flange_b, damper.flange_b, inertia2.flange_a)] @named model = ODESystem(connections, t, systems = [ @@ -112,7 +112,7 @@ end inertia1, inertia2, spring, - damper, + damper ]) sys = structural_simplify(model) @@ -142,15 +142,15 @@ end @named sine = Blocks.Sine(amplitude = amplitude, frequency = frequency) connections = [connect(inertia1.flange_b, idealGear.flange_a) - connect(idealGear.flange_b, inertia2.flange_a) - connect(inertia2.flange_b, spring.flange_a) - connect(spring.flange_b, inertia3.flange_a) - connect(damper.flange_a, inertia2.flange_b) - connect(damper.flange_b, fixed.flange) - connect(sine.output, torque.tau) - connect(torque.support, fixed.flange) - connect(idealGear.support, fixed.flange) - connect(torque.flange, inertia1.flange_a)] + connect(idealGear.flange_b, inertia2.flange_a) + connect(inertia2.flange_b, spring.flange_a) + connect(spring.flange_b, inertia3.flange_a) + connect(damper.flange_a, inertia2.flange_b) + connect(damper.flange_b, fixed.flange) + connect(sine.output, torque.tau) + connect(torque.support, fixed.flange) + connect(idealGear.support, fixed.flange) + connect(torque.flange, inertia1.flange_a)] @named model = ODESystem(connections, t, systems = [ @@ -162,7 +162,7 @@ end spring, inertia3, damper, - sine, + sine ]) @test_skip begin sys = structural_simplify(model) #key 7 not found @@ -180,8 +180,8 @@ end @named lim = Blocks.Limiter(y_max = 6) @named output = Blocks.RealOutput() connections = [connect(sine.output, dz.input) - connect(dz.output, lim.input) - connect(lim.output, output)] + connect(dz.output, lim.input) + connect(lim.output, output)] ODESystem(connections, t, [], []; name = name, systems = [sine, dz, lim, output]) end @@ -196,11 +196,11 @@ end @named angle_sensor = AngleSensor() connections = [connect(vel_profile.output, source.w_ref) - connect(source.flange, friction.flange_a) - connect(friction.flange_b, inertia.flange_a) - connect(inertia.flange_b, spring.flange_a, damper.flange_a) - connect(spring.flange_b, damper.flange_b, fixed.flange) - connect(angle_sensor.flange, inertia.flange_a)] + connect(source.flange, friction.flange_a) + connect(friction.flange_b, inertia.flange_a) + connect(inertia.flange_b, spring.flange_a, damper.flange_a) + connect(spring.flange_b, damper.flange_b, fixed.flange) + connect(angle_sensor.flange, inertia.flange_a)] @named model = ODESystem(connections, t, systems = [ @@ -211,7 +211,7 @@ end vel_profile, source, friction, - angle_sensor, + angle_sensor ]) sys = structural_simplify(model) prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 10.0)) @@ -239,16 +239,16 @@ end @named rel_speed_sensor = RelSpeedSensor() connections = [connect(fixed.flange, inertia1.flange_b, rel_speed_sensor.flange_b) - connect(inertia1.flange_b, torque_sensor.flange_a) - connect(torque_sensor.flange_b, spring.flange_a, damper.flange_a, - speed_sensor.flange, rel_speed_sensor.flange_a) - connect(spring.flange_b, damper.flange_b, inertia2.flange_a)] + connect(inertia1.flange_b, torque_sensor.flange_a) + connect(torque_sensor.flange_b, spring.flange_a, damper.flange_a, + speed_sensor.flange, rel_speed_sensor.flange_a) + connect(spring.flange_b, damper.flange_b, inertia2.flange_a)] @named model = ODESystem(connections, t, systems = [ fixed, inertia1, inertia2, spring, damper, speed_sensor, - rel_speed_sensor, torque_sensor, + rel_speed_sensor, torque_sensor ]) sys = structural_simplify(model) diff --git a/test/Mechanical/translational.jl b/test/Mechanical/translational.jl index 15d27621e..c78e0e047 100644 --- a/test/Mechanical/translational.jl +++ b/test/Mechanical/translational.jl @@ -17,7 +17,7 @@ D = Differential(t) end eqs = [connect(a.output, acc.a) - connect(mass.flange, acc.flange, free.flange)] + connect(mass.flange, acc.flange, free.flange)] ODESystem(eqs, t, [], []; name, systems) end @@ -47,7 +47,7 @@ end 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]) @@ -89,9 +89,9 @@ end function System(damping, spring, body, ground, f, source) eqs = [connect(f.f, source.output) - connect(f.flange, body.flange) - connect(spring.flange_a, body.flange, damping.flange_a) - connect(spring.flange_b, damping.flange_b, ground.flange)] + connect(f.flange, body.flange) + connect(spring.flange_a, body.flange, damping.flange_a) + connect(spring.flange_b, damping.flange_b, ground.flange)] @named model = ODESystem(eqs, t; systems = [ground, body, spring, damping, f, source]) @@ -134,11 +134,11 @@ end end eqs = [connect(pos.s, src1.output) - connect(force.f, src2.output) - connect(spring.flange_a, pos.flange, force_sensor.flange) - connect(spring.flange_b, force.flange, pos_sensor.flange) - connect(pos_value, pos_sensor.output) - connect(force_output, force_sensor.output)] + connect(force.f, src2.output) + connect(spring.flange_a, pos.flange, force_sensor.flange) + connect(spring.flange_b, force.flange, pos_sensor.flange) + connect(pos_value, pos_sensor.output) + connect(force_output, force_sensor.output)] ODESystem(eqs, t, [], []; name, systems) end diff --git a/test/Mechanical/translational_modelica.jl b/test/Mechanical/translational_modelica.jl index a35adf490..0a9e75377 100644 --- a/test/Mechanical/translational_modelica.jl +++ b/test/Mechanical/translational_modelica.jl @@ -13,7 +13,7 @@ D = Differential(t) @named fixed = TP.Fixed(s0 = 1) eqs = [connect(spring.flange_a, mass.flange_a, damper.flange_a) - connect(spring.flange_b, damper.flange_b, fixed.flange)] + connect(spring.flange_b, damper.flange_b, fixed.flange)] @named model = ODESystem(eqs, t; systems = [fixed, mass, spring, damper]) @@ -37,9 +37,9 @@ end @named source = Sine(frequency = 3, amplitude = 2) eqs = [connect(force.f, source.output) - connect(force.flange, mass.flange_a) - connect(spring.flange_a, mass.flange_b, damper.flange_a) - connect(spring.flange_b, damper.flange_b, fixed.flange)] + connect(force.flange, mass.flange_a) + connect(spring.flange_a, mass.flange_b, damper.flange_a) + connect(spring.flange_b, damper.flange_b, fixed.flange)] @named model = ODESystem(eqs, t; systems = [fixed, mass, spring, damper, force, source]) diff --git a/test/Thermal/demo.jl b/test/Thermal/demo.jl index 0cc950c56..c50227156 100644 --- a/test/Thermal/demo.jl +++ b/test/Thermal/demo.jl @@ -16,7 +16,7 @@ D = Differential(t) connect(mass1.port, conduction.port_a), connect(conduction.port_b, mass2.port), connect(mass1.port, Tsensor1.port), - connect(mass2.port, Tsensor2.port), + connect(mass2.port, Tsensor2.port) ] @named model = ODESystem(connections, t, diff --git a/test/Thermal/thermal.jl b/test/Thermal/thermal.jl index bf8b39383..b6319ef5c 100644 --- a/test/Thermal/thermal.jl +++ b/test/Thermal/thermal.jl @@ -215,16 +215,16 @@ end @named winding_losses = Step(height = 900, offset = 100, start_time = 360, duration = Inf, smooth = false) connections = [connect(windingLosses.port, winding.port) - connect(coreLosses.port, core.port) - connect(winding.port, winding2core.port_a) - connect(winding2core.port_b, core.port) - connect(winding.port, T_winding.port) - connect(core.port, T_core.port) - connect(winding2core.port_b, convection.solid) - connect(convection.fluid, environment.port) - connect(amb.output, environment.T) - connect(winding_losses.output, windingLosses.Q_flow) - connect(core_losses_const.output, coreLosses.Q_flow)] + connect(coreLosses.port, core.port) + connect(winding.port, winding2core.port_a) + connect(winding2core.port_b, core.port) + connect(winding.port, T_winding.port) + connect(core.port, T_core.port) + connect(winding2core.port_b, convection.solid) + connect(convection.fluid, environment.port) + connect(amb.output, environment.T) + connect(winding_losses.output, windingLosses.Q_flow) + connect(core_losses_const.output, coreLosses.Q_flow)] @named model = ODESystem(connections, t, systems = [ diff --git a/test/chua_circuit.jl b/test/chua_circuit.jl index c12896d3c..6c2a3dddc 100644 --- a/test/chua_circuit.jl +++ b/test/chua_circuit.jl @@ -14,10 +14,10 @@ using IfElse: ifelse 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 @@ -33,14 +33,14 @@ using IfElse: ifelse @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]) sys = structural_simplify(model) diff --git a/test/multi_domain.jl b/test/multi_domain.jl index a20cdf76f..7508ec13a 100644 --- a/test/multi_domain.jl +++ b/test/multi_domain.jl @@ -32,14 +32,14 @@ D = Differential(t) @named friction = Damper(d = f) 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(load_step.output, load.tau) - connect(voltage_step.output, 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(load_step.output, load.tau) + connect(voltage_step.output, 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 = [ @@ -53,7 +53,7 @@ D = Differential(t) load, load_step, inertia, - friction, + friction ]) sys = structural_simplify(model) @@ -115,15 +115,15 @@ end @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(voltage_step.output, 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(voltage_step.output, 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 = [ @@ -138,7 +138,7 @@ end load_step, inertia, friction, - speed_sensor, + speed_sensor ]) sys = structural_simplify(model) @@ -188,10 +188,10 @@ end @named thermal_conductor = ThermalConductor(G = 50) @named env = FixedTemperature(T = 273.15 + 20) connections = [connect(source.n, ground.g, heating_resistor.n) - connect(source.p, heating_resistor.p) - connect(voltage_sine.output, source.V) - connect(heating_resistor.heat_port, thermal_conductor.port_a) - connect(thermal_conductor.port_b, env.port)] + connect(source.p, heating_resistor.p) + connect(voltage_sine.output, source.V) + connect(heating_resistor.heat_port, thermal_conductor.port_a) + connect(thermal_conductor.port_b, env.port)] @named model = ODESystem(connections, t, systems = [ @@ -200,7 +200,7 @@ end source, heating_resistor, thermal_conductor, - env, + env ]) sys = structural_simplify(model)