diff --git a/Project.toml b/Project.toml index e61ddfd47..37fb9fed8 100644 --- a/Project.toml +++ b/Project.toml @@ -19,7 +19,7 @@ DataInterpolations = "4" DiffEqBase = "6.103" IfElse = "0.1" LinearAlgebra = "1.10" -ModelingToolkit = "8.69" +ModelingToolkit = "9" OrdinaryDiffEq = "6.33" SafeTestsets = "0.1" Symbolics = "5.2" diff --git a/docs/Project.toml b/docs/Project.toml index 034ba981d..dffb4fce9 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -13,6 +13,6 @@ ControlSystemsBase = "1.1" DifferentialEquations = "7.6" Documenter = "1" IfElse = "0.1" -ModelingToolkit = "8.67" +ModelingToolkit = "9" OrdinaryDiffEq = "6.31" Plots = "1.36" diff --git a/docs/src/connectors/connections.md b/docs/src/connectors/connections.md index 83a43f2ca..3c18308bc 100644 --- a/docs/src/connectors/connections.md +++ b/docs/src/connectors/connections.md @@ -90,10 +90,9 @@ As can be seen, this will give a 1 equation model matching our energy dissipatio ```@example connections using ModelingToolkitStandardLibrary.Electrical, ModelingToolkit, DifferentialEquations +using ModelingToolkit: t_nounits as t using Plots -@parameters t - @named resistor = Resistor(R = 1) @named capacitor = Capacitor(C = 1) @named ground = Ground() diff --git a/docs/src/tutorials/custom_component.md b/docs/src/tutorials/custom_component.md index 4472e839f..49a3bce6a 100644 --- a/docs/src/tutorials/custom_component.md +++ b/docs/src/tutorials/custom_component.md @@ -8,6 +8,7 @@ First, we need to make some imports. ```@example components using ModelingToolkit +using ModelingToolkit: t_nounits as t using ModelingToolkitStandardLibrary.Electrical using ModelingToolkitStandardLibrary.Electrical: OnePort using OrdinaryDiffEq @@ -35,8 +36,6 @@ end NonlinearResistor; this can almost be directly translated to the syntax of `ModelingToolkit`. ```@example components -@parameters t - function NonlinearResistor(; name, Ga, Gb, Ve) @named oneport = OnePort() @unpack v, i = oneport diff --git a/docs/src/tutorials/dc_motor_pi.md b/docs/src/tutorials/dc_motor_pi.md index 874dabb06..b682a3641 100644 --- a/docs/src/tutorials/dc_motor_pi.md +++ b/docs/src/tutorials/dc_motor_pi.md @@ -14,14 +14,13 @@ First, the needed packages are imported and the parameters of the model defined. ```@example dc_motor_pi using ModelingToolkit +using ModelingToolkit: t_nounits as t using ModelingToolkitStandardLibrary.Electrical using ModelingToolkitStandardLibrary.Mechanical.Rotational using ModelingToolkitStandardLibrary.Blocks using OrdinaryDiffEq using Plots -@parameters t - R = 0.5 # [Ohm] armature resistance L = 4.5e-3 # [H] armature inductance k = 0.5 # [N.m/A] motor constant diff --git a/docs/src/tutorials/input_component.md b/docs/src/tutorials/input_component.md index 293294334..414a22eed 100644 --- a/docs/src/tutorials/input_component.md +++ b/docs/src/tutorials/input_component.md @@ -14,13 +14,11 @@ The `ModelingToolkitStandardLibrary.Blocks.TimeVaryingFunction` component is eas ```julia using ModelingToolkit +using ModelingToolkit: t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks using DataInterpolations using OrdinaryDiffEq -@parameters t -D = Differential(t) - function System(f; name) src = TimeVaryingFunction(f) diff --git a/docs/src/tutorials/rc_circuit.md b/docs/src/tutorials/rc_circuit.md index 4004d5abd..c12ccebc1 100644 --- a/docs/src/tutorials/rc_circuit.md +++ b/docs/src/tutorials/rc_circuit.md @@ -29,7 +29,7 @@ rc_eqs = [connect(constant.output, source.V) @named rc_model = ODESystem(rc_eqs, t, systems = [resistor, capacitor, constant, source, ground]) sys = structural_simplify(rc_model) -prob = ODAEProblem(sys, Pair[], (0, 10.0)) +prob = ODEProblem(sys, Pair[], (0, 10.0)) sol = solve(prob, Tsit5()) plot(sol, idxs = [capacitor.v, resistor.i], title = "RC Circuit Demonstration", diff --git a/docs/src/tutorials/thermal_model.md b/docs/src/tutorials/thermal_model.md index 233e2464d..1529ec502 100644 --- a/docs/src/tutorials/thermal_model.md +++ b/docs/src/tutorials/thermal_model.md @@ -8,8 +8,7 @@ from dividing the total initial energy in the system by the sum of the heat capa ```@example using ModelingToolkitStandardLibrary.Thermal, ModelingToolkit, OrdinaryDiffEq, Plots - -@parameters t +using ModelingToolkit: t_nounits as t C1 = 15 C2 = 15 diff --git a/src/Blocks/Blocks.jl b/src/Blocks/Blocks.jl index cc7b4cde0..35cae08fd 100644 --- a/src/Blocks/Blocks.jl +++ b/src/Blocks/Blocks.jl @@ -5,10 +5,7 @@ module Blocks using ModelingToolkit, Symbolics import IfElse: ifelse import ..@symcheck -using ModelingToolkit: getdefault - -@parameters t -D = Differential(t) +using ModelingToolkit: getdefault, t_nounits as t, D_nounits as D export RealInput, RealOutput, SISO include("utils.jl") diff --git a/src/Blocks/continuous.jl b/src/Blocks/continuous.jl index be9bdf36c..d73edb558 100644 --- a/src/Blocks/continuous.jl +++ b/src/Blocks/continuous.jl @@ -620,6 +620,7 @@ See also [`StateSpace`](@ref) which handles MIMO systems, as well as [ControlSys x = collect(x) x_scaled = collect(x_scaled) + bb = collect(bb) sts = [x; x_scaled; y; u] diff --git a/src/Blocks/sources.jl b/src/Blocks/sources.jl index 8cf6a79c9..7a64f73cd 100644 --- a/src/Blocks/sources.jl +++ b/src/Blocks/sources.jl @@ -521,7 +521,7 @@ function Base.show(io::IO, m::MIME"text/plain", p::Parameter) end get_sample_time(memory::Parameter) = memory.ref -Symbolics.@register_symbolic get_sample_time(memory) +Symbolics.@register_symbolic get_sample_time(memory::Parameter) Base.convert(::Type{T}, x::Parameter{T}) where {T <: Real} = x.ref function Base.convert(::Type{<:Parameter{T}}, x::Number) where {T <: Real} @@ -603,8 +603,9 @@ end function get_sampled_data(t, buffer) get_sampled_data(t, buffer.data, buffer.ref, buffer.circular_buffer) end -Symbolics.@register_symbolic get_sampled_data(t, buffer) -Symbolics.@register_symbolic get_sampled_data(t, buffer, dt, circular_buffer) false +Symbolics.@register_symbolic Parameter(data::Vector, ref, circular_buffer::Bool) +Symbolics.@register_symbolic get_sampled_data(t, buffer::Parameter) +Symbolics.@register_symbolic get_sampled_data(t, buffer::Vector, dt, circular_buffer) false function Symbolics.derivative(::typeof(get_sampled_data), args::NTuple{2, Any}, ::Val{1}) t = @inbounds args[1] @@ -655,21 +656,23 @@ data input component. buffer, sample_time, circular_buffer = true) + T = eltype(buffer) pars = @parameters begin - buffer = buffer #::Vector{Real} - sample_time = sample_time #::Real - circular_buffer = circular_buffer #::Bool + buffer::Vector{T} = buffer #::Vector{Real} + sample_time::T = sample_time #::Real + circular_buffer::Bool = circular_buffer #::Bool end + @parameters p::Parameter{T} = Parameter(buffer, sample_time, circular_buffer) vars = [] systems = @named begin output = RealOutput() end eqs = [ - output.u ~ get_sampled_data(t, buffer, sample_time, circular_buffer) + output.u ~ get_sampled_data(t, p) ] - return ODESystem(eqs, t, vars, pars; name, systems, + return ODESystem(eqs, t, vars, [pars; p]; name, systems, defaults = [ - output.u => get_sampled_data(0.0, buffer, sample_time, circular_buffer) + output.u => get_sampled_data(0.0, p) ]) end @@ -684,9 +687,10 @@ data input component. # Connectors: - `output` """ -@component function SampledData(::Val{SampledDataType.struct_based}; name, buffer) +@component function SampledData( + ::Val{SampledDataType.struct_based}; name, buffer::Parameter) pars = @parameters begin - buffer = buffer #::Parameter + buffer::typeof(buffer) = buffer #::Parameter end vars = [] systems = @named begin diff --git a/src/Electrical/Electrical.jl b/src/Electrical/Electrical.jl index 723182067..876858197 100644 --- a/src/Electrical/Electrical.jl +++ b/src/Electrical/Electrical.jl @@ -5,13 +5,11 @@ This library contains electrical components to build up analog circuits. module Electrical using ModelingToolkit, Symbolics, IfElse +using ModelingToolkit: t_nounits as t, D_nounits as D using ..Thermal: HeatPort using ..Mechanical.Rotational: Flange, Support using ..Blocks: RealInput, RealOutput -@parameters t -D = Differential(t) - export Pin, OnePort include("utils.jl") diff --git a/src/Hydraulic/IsothermalCompressible/IsothermalCompressible.jl b/src/Hydraulic/IsothermalCompressible/IsothermalCompressible.jl index 41236e1de..b58647d84 100644 --- a/src/Hydraulic/IsothermalCompressible/IsothermalCompressible.jl +++ b/src/Hydraulic/IsothermalCompressible/IsothermalCompressible.jl @@ -4,15 +4,13 @@ Library to model iso-thermal compressible liquid fluid flow module IsothermalCompressible using ModelingToolkit, Symbolics +using ModelingToolkit: t_nounits as t, D_nounits as D using ...Blocks: RealInput, RealOutput using ...Mechanical.Translational: MechanicalPort, Mass using IfElse: ifelse -@parameters t -D = Differential(t) - export HydraulicPort, HydraulicFluid include("utils.jl") diff --git a/src/Magnetic/FluxTubes/FluxTubes.jl b/src/Magnetic/FluxTubes/FluxTubes.jl index 07c7595fc..08dd00120 100644 --- a/src/Magnetic/FluxTubes/FluxTubes.jl +++ b/src/Magnetic/FluxTubes/FluxTubes.jl @@ -1,10 +1,8 @@ module FluxTubes using ModelingToolkit +using ModelingToolkit: t_nounits as t, D_nounits as D using ...Electrical: Pin -@parameters t -D = Differential(t) - export PositiveMagneticPort, NegativeMagneticPort, TwoPort include("utils.jl") diff --git a/src/Mechanical/MultiBody2D/MultiBody2D.jl b/src/Mechanical/MultiBody2D/MultiBody2D.jl index 102434e5a..ab0e3e6c0 100644 --- a/src/Mechanical/MultiBody2D/MultiBody2D.jl +++ b/src/Mechanical/MultiBody2D/MultiBody2D.jl @@ -1,11 +1,9 @@ module MultiBody2D using ModelingToolkit, Symbolics, IfElse +using ModelingToolkit: t_nounits as t, D_nounits as D using ..TranslationalPosition -@parameters t -D = Differential(t) - export Link include("components.jl") diff --git a/src/Mechanical/Rotational/Rotational.jl b/src/Mechanical/Rotational/Rotational.jl index 9a6fda31f..3e58410a1 100644 --- a/src/Mechanical/Rotational/Rotational.jl +++ b/src/Mechanical/Rotational/Rotational.jl @@ -4,12 +4,10 @@ Library to model 1-dimensional, rotational mechanical systems module Rotational using ModelingToolkit, Symbolics, IfElse +using ModelingToolkit: t_nounits as t, D_nounits as D using ...Blocks: RealInput, RealOutput import ...@symcheck -@parameters t -D = Differential(t) - export Flange, Support include("utils.jl") diff --git a/src/Mechanical/Translational/Translational.jl b/src/Mechanical/Translational/Translational.jl index d29231a77..4db9168ad 100644 --- a/src/Mechanical/Translational/Translational.jl +++ b/src/Mechanical/Translational/Translational.jl @@ -4,14 +4,11 @@ Library to model 1-dimensional, translational mechanical systems module Translational using ModelingToolkit, Symbolics -using ModelingToolkit: getdefault +using ModelingToolkit: getdefault, t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks: RealInput, RealOutput using IfElse: ifelse -@parameters t -D = Differential(t) - export MechanicalPort include("utils.jl") diff --git a/src/Mechanical/TranslationalModelica/TranslationalModelica.jl b/src/Mechanical/TranslationalModelica/TranslationalModelica.jl index 2aec491b1..0b685e429 100644 --- a/src/Mechanical/TranslationalModelica/TranslationalModelica.jl +++ b/src/Mechanical/TranslationalModelica/TranslationalModelica.jl @@ -4,11 +4,9 @@ Library to model 1-dimensional, translational mechanical components. module TranslationalModelica using ModelingToolkit, Symbolics, IfElse +using ModelingToolkit: t_nounits as t, D_nounits as D using ...Blocks: RealInput, RealOutput -@parameters t -D = Differential(t) - export Flange include("utils.jl") diff --git a/src/Mechanical/TranslationalPosition/TranslationalPosition.jl b/src/Mechanical/TranslationalPosition/TranslationalPosition.jl index 72c91835c..078f4fc50 100644 --- a/src/Mechanical/TranslationalPosition/TranslationalPosition.jl +++ b/src/Mechanical/TranslationalPosition/TranslationalPosition.jl @@ -4,11 +4,9 @@ Library to model 1-dimensional, translational mechanical components. module TranslationalPosition using ModelingToolkit, Symbolics, IfElse +using ModelingToolkit: t_nounits as t, D_nounits as D using ...Blocks: RealInput, RealOutput -@parameters t -D = Differential(t) - export Flange include("utils.jl") diff --git a/src/Thermal/Thermal.jl b/src/Thermal/Thermal.jl index d5d59fcf4..a7ad12c07 100644 --- a/src/Thermal/Thermal.jl +++ b/src/Thermal/Thermal.jl @@ -3,11 +3,9 @@ Library of thermal system components to model heat transfer. """ module Thermal using ModelingToolkit, Symbolics, IfElse +using ModelingToolkit: t_nounits as t, D_nounits as D using ...Blocks: RealInput, RealOutput -@parameters t -D = Differential(t) - export HeatPort, Element1D include("utils.jl") diff --git a/test/Blocks/continuous.jl b/test/Blocks/continuous.jl index 4239583cb..994944c50 100644 --- a/test/Blocks/continuous.jl +++ b/test/Blocks/continuous.jl @@ -1,10 +1,9 @@ using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEq using ModelingToolkitStandardLibrary.Blocks +using ModelingToolkit: t_nounits as t using OrdinaryDiffEq: ReturnCode.Success using Test -@parameters t - #= Testing strategy: The general strategy is to test systems using simple inputs where the solution diff --git a/test/Blocks/math.jl b/test/Blocks/math.jl index aaf7f796f..c29bba069 100644 --- a/test/Blocks/math.jl +++ b/test/Blocks/math.jl @@ -1,11 +1,9 @@ using ModelingToolkitStandardLibrary.Blocks using ModelingToolkit, OrdinaryDiffEq, Test using ModelingToolkitStandardLibrary.Blocks: _clamp, _dead_zone -using ModelingToolkit: inputs, unbound_inputs, bound_inputs +using ModelingToolkit: inputs, unbound_inputs, bound_inputs, t_nounits as t using OrdinaryDiffEq: ReturnCode.Success -@parameters t - @testset "Gain" begin @named c = Constant(; k = 1) @named gain = Gain(; k = 1) diff --git a/test/Blocks/nonlinear.jl b/test/Blocks/nonlinear.jl index 4f5bd1d08..be22fc848 100644 --- a/test/Blocks/nonlinear.jl +++ b/test/Blocks/nonlinear.jl @@ -1,10 +1,9 @@ using ModelingToolkit, OrdinaryDiffEq using ModelingToolkitStandardLibrary.Blocks +using ModelingToolkit: t_nounits as t using ModelingToolkitStandardLibrary.Blocks: _clamp, _dead_zone using OrdinaryDiffEq: ReturnCode.Success -@parameters t - @testset "Limiter" begin @testset "Constant" begin @named c = Constant(; k = 1) diff --git a/test/Blocks/sources.jl b/test/Blocks/sources.jl index 43cc5bd7b..146fe77ff 100644 --- a/test/Blocks/sources.jl +++ b/test/Blocks/sources.jl @@ -1,13 +1,11 @@ using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEq using ModelingToolkitStandardLibrary.Blocks +using ModelingToolkit: t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks: smooth_sin, smooth_cos, smooth_damped_sin, smooth_square, smooth_step, smooth_ramp, smooth_triangular, triangular, square using OrdinaryDiffEq: ReturnCode.Success -@parameters t -D = Differential(t) - @testset "Constant" begin @named src = Constant(k = 2) @named int = Integrator() diff --git a/test/Blocks/test_analysis_points.jl b/test/Blocks/test_analysis_points.jl index 8dae292a6..a58786de2 100644 --- a/test/Blocks/test_analysis_points.jl +++ b/test/Blocks/test_analysis_points.jl @@ -2,12 +2,11 @@ using Test, LinearAlgebra using ModelingToolkit using ModelingToolkitStandardLibrary.Blocks using OrdinaryDiffEq -using ModelingToolkit: get_eqs, vars, @set!, get_iv +using ModelingToolkit: get_eqs, vars, @set!, t_nounits as t using ControlSystemsBase @named P = FirstOrder(k = 1, T = 1) @named C = Gain(; k = -1) -t = ModelingToolkit.get_iv(P) @test_logs (:warn,) (:warn,) connect(P.input, :bad_connection, C.output) @@ -20,8 +19,8 @@ sys = ODESystem(eqs, t, systems = [P, C], name = :hej) ssys = structural_simplify(sys) prob = ODEProblem(ssys, [P.x => 1], (0, 10)) sol = solve(prob, Rodas5()) -@test norm(sol[1]) >= 1 -@test norm(sol[end]) < 1e-6 # This fails without the feedback through C +@test norm(sol.u[1]) >= 1 +@test norm(sol.u[end]) < 1e-6 # This fails without the feedback through C # plot(sol) matrices, _ = get_sensitivity(sys, ap) @@ -108,7 +107,6 @@ matrices2, _ = linearize(sys, :plant_input, [P.output.u]) @named P = FirstOrder(k = 1, T = 1) @named C = Gain(; k = 1) @named add = Blocks.Add(k2 = -1) -t = ModelingToolkit.get_iv(P) eqs = [connect(P.output, :plant_output, add.input2) connect(add.output, C.input) @@ -231,7 +229,6 @@ Si = ss(matrices...) @test tf(So) ≈ tf(Si) ## A simple multi-level system with loop openings -@parameters t @named P_inner = FirstOrder(k = 1, T = 1) @named feedback = Feedback() @named ref = Step() @@ -311,7 +308,6 @@ G = CS.feedback(Pss, Kss, pos_feedback = true) @named P = FirstOrder(k = 1, T = 1) @named C = Gain(; k = 1) @named add = Blocks.Add(k2 = -1) -t = ModelingToolkit.get_iv(P) eqs = [connect(P.output, :plant_output, add.input2) connect(add.output, C.input) diff --git a/test/Electrical/analog.jl b/test/Electrical/analog.jl index 01f85c8cb..f19d9a923 100644 --- a/test/Electrical/analog.jl +++ b/test/Electrical/analog.jl @@ -1,4 +1,5 @@ using ModelingToolkitStandardLibrary.Electrical, ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t using ModelingToolkitStandardLibrary.Blocks: Step, Constant, Sine, Cosine, ExpSine, Ramp, Square, Triangular @@ -7,8 +8,6 @@ using OrdinaryDiffEq: ReturnCode.Success # using Plots -@parameters t - @testset "sensors" begin @named source = Sine(offset = 1, amplitude = 10, frequency = 5) @named voltage = Voltage() @@ -43,7 +42,7 @@ using OrdinaryDiffEq: ReturnCode.Success power_sensor ]) sys = structural_simplify(model) - prob = ODAEProblem(sys, [], (0.0, 10.0)) + prob = ODEProblem(sys, [], (0.0, 10.0)) sol = solve(prob, Tsit5()) # Plots.plot(sol; vars=[capacitor.v, voltage_sensor.v]) @@ -100,7 +99,7 @@ end @named model = ODESystem(connections, t; systems = [resistor, capacitor, source, voltage, ground]) sys = structural_simplify(model) - prob = ODAEProblem(sys, Pair[], (0.0, 10.0)) + prob = ODEProblem(sys, Pair[], (0.0, 10.0)) sol = solve(prob, Tsit5()) # Plots.plot(sol; vars=[source.v, capacitor.v]) @@ -124,7 +123,7 @@ end @named model = ODESystem(connections, t; systems = [resistor, inductor, source, voltage, ground]) sys = structural_simplify(model) - prob = ODAEProblem(sys, Pair[], (0.0, 10.0)) + prob = ODEProblem(sys, Pair[], (0.0, 10.0)) sol = solve(prob, Tsit5()) # Plots.plot(sol; vars=[inductor.i, inductor.i]) @@ -159,7 +158,7 @@ end @named model = ODESystem(connections, t; systems = [resistor, capacitor, source, ground, voltage]) sys = structural_simplify(model) - prob = ODAEProblem(sys, Pair[], (0.0, 10.0)) + prob = ODEProblem(sys, Pair[], (0.0, 10.0)) sol = solve(prob, Tsit5()) @test sol.retcode == Success sol = solve(prob, Rodas4()) @@ -186,7 +185,7 @@ end @named model = ODESystem(connections, t; systems = [ground, resistor, current, capacitor, source]) sys = structural_simplify(model) - prob = ODAEProblem(sys, Pair[], (0.0, 10.0)) + prob = ODEProblem(sys, Pair[], (0.0, 10.0)) sol = solve(prob, Tsit5()) y(x, st) = (x .> st) .* abs.(collect(x) .- st) @test sol.retcode == Success @@ -296,7 +295,7 @@ _damped_sine_wave(x, f, A, st, ϕ, d) = exp((st - x) * d) * A * sin(2 * π * f * u0 = [cap.v => 0.0] - prob = ODAEProblem(vsys, u0, (0, 10.0)) + prob = ODEProblem(vsys, u0, (0, 10.0)) sol = solve(prob, dt = 0.1, Tsit5()) @test sol.retcode == Success @@ -362,7 +361,7 @@ end u0 = [cap.v => 0.0] - prob = ODAEProblem(isys, u0, (0, 10.0)) + prob = ODEProblem(isys, u0, (0, 10.0)) sol = solve(prob, dt = 0.1, Tsit5()) @test sol.retcode == Success diff --git a/test/Electrical/digital.jl b/test/Electrical/digital.jl index 849e506da..a77862430 100644 --- a/test/Electrical/digital.jl +++ b/test/Electrical/digital.jl @@ -96,8 +96,6 @@ end #= -@parameters t - @named set1 = Set() @named reset1 = Reset() @named set2 = Set() diff --git a/test/Hydraulic/isothermal_compressible.jl b/test/Hydraulic/isothermal_compressible.jl index e8d71a1c8..5ee09dff7 100644 --- a/test/Hydraulic/isothermal_compressible.jl +++ b/test/Hydraulic/isothermal_compressible.jl @@ -1,13 +1,11 @@ using ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t, D_nounits as D import ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible as IC import ModelingToolkitStandardLibrary.Blocks as B import ModelingToolkitStandardLibrary.Mechanical.Translational as T using ModelingToolkitStandardLibrary.Blocks: Parameter -@parameters t -D = Differential(t) - NEWTON = NLNewton(check_div = false, always_new = true, max_iter = 100, relax = 9 // 10) @testset "Fluid Domain and Tube" begin @@ -195,8 +193,6 @@ end @testset "Actuator System" begin function System(use_input, f; name) - @parameters t - pars = @parameters begin p_s = 200e5 p_r = 5e5 diff --git a/test/Magnetic/magnetic.jl b/test/Magnetic/magnetic.jl index 8c0d1cdf8..c81439fc1 100644 --- a/test/Magnetic/magnetic.jl +++ b/test/Magnetic/magnetic.jl @@ -4,11 +4,10 @@ import ModelingToolkitStandardLibrary.Electrical import ModelingToolkitStandardLibrary.Blocks import ModelingToolkitStandardLibrary.Magnetic using ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t using OrdinaryDiffEq: ReturnCode.Success # using Plots -@parameters t - @testset "Inductor" begin mu_air = 1 l_air = 0.0001 diff --git a/test/Mechanical/multibody.jl b/test/Mechanical/multibody.jl index 68172c57a..fde5c0cb7 100644 --- a/test/Mechanical/multibody.jl +++ b/test/Mechanical/multibody.jl @@ -1,12 +1,11 @@ using ModelingToolkit +using ModelingToolkit: t_nounits as t using ModelingToolkitStandardLibrary.Mechanical.MultiBody2D using ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition using OrdinaryDiffEq # using Setfield using Test -@parameters t - @named link1 = Link(; m = 1, l = 10, I = 84, g = -9.807) @named link2 = Link(; m = 1, l = 10, I = 84, g = -9.807, x1_0 = 10) @named cart = Mass(; m = 1, s = 0) diff --git a/test/Mechanical/rotational.jl b/test/Mechanical/rotational.jl index 08a17c6e6..041ce379d 100644 --- a/test/Mechanical/rotational.jl +++ b/test/Mechanical/rotational.jl @@ -1,14 +1,12 @@ using ModelingToolkitStandardLibrary.Mechanical.Rotational, ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t, D_nounits as D import ModelingToolkitStandardLibrary.Blocks using OrdinaryDiffEq: ReturnCode.Success # using Plots -@parameters t -D = Differential(t) - @testset "two inertias" begin @named fixed = Fixed() @named inertia1 = Inertia(J = 2) # this one is fixed @@ -28,11 +26,11 @@ D = Differential(t) sol1 = solve(prob, Rodas4()) @test SciMLBase.successful_retcode(sol1) - prob = ODAEProblem(sys, Pair[], (0, 10.0)) + prob = ODEProblem(sys, Pair[], (0, 10.0)) sol = solve(prob, Rodas4()) @test SciMLBase.successful_retcode(sol) - prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 10.0)) + prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 10.0)) sol = solve(prob, DFBDF()) @test SciMLBase.successful_retcode(sol) @test all(sol[inertia1.w] .== 0) @@ -86,12 +84,12 @@ end sine ]) sys = structural_simplify(model) - prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, - [D(D(inertia2.phi)) => 1.0; D.(states(model)) .=> 0.0], (0, 10.0)) + prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, + [D(D(inertia2.phi)) => 1.0; D.(unknowns(model)) .=> 0.0], (0, 10.0)) sol = solve(prob, DFBDF()) @test SciMLBase.successful_retcode(sol) - prob = ODAEProblem(sys, Pair[], (0, 1.0)) + prob = ODEProblem(sys, Pair[], (0, 1.0)) sol = solve(prob, Rodas4()) @test SciMLBase.successful_retcode(sol) @@ -166,7 +164,7 @@ end ]) @test_skip begin sys = structural_simplify(model) #key 7 not found - prob = ODAEProblem(sys, Pair[], (0, 1.0)) + prob = ODEProblem(sys, Pair[], (0, 1.0)) sol = solve(prob, Rodas4()) @test SciMLBase.successful_retcode(sol) end @@ -214,7 +212,7 @@ end angle_sensor ]) sys = structural_simplify(model) - prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 10.0)) + prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 10.0)) sol = solve(prob, DFBDF()) @test SciMLBase.successful_retcode(sol) @@ -261,7 +259,7 @@ end @test all(sol[rel_speed_sensor.w_rel.u] .== sol[speed_sensor.w.u]) @test all(sol[torque_sensor.tau.u] .== -sol[inertia1.flange_b.tau]) - prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 10.0)) + prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 10.0)) sol = solve(prob, DFBDF()) @test SciMLBase.successful_retcode(sol) @test all(sol[inertia1.w] .== 0) diff --git a/test/Mechanical/translational.jl b/test/Mechanical/translational.jl index ee5e93e8a..74c70e271 100644 --- a/test/Mechanical/translational.jl +++ b/test/Mechanical/translational.jl @@ -1,12 +1,10 @@ using ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks import ModelingToolkitStandardLibrary.Mechanical.Translational as TV import ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition as TP -@parameters t -D = Differential(t) - @testset "Free" begin function System(; name) systems = @named begin @@ -167,7 +165,8 @@ end connect(acc.flange, mass.flange), connect(acc_output, acc.output) ] - @named sys = ODESystem(eqs, t, [], []; systems = [force, source, mass, acc, acc_output]) + @named sys = ODESystem( + eqs, t, [], []; systems = [force, source, mass, acc, acc_output]) s = complete(structural_simplify(sys)) prob = ODEProblem(s, [], (0.0, pi)) sol = solve(prob, Tsit5()) diff --git a/test/Mechanical/translational_modelica.jl b/test/Mechanical/translational_modelica.jl index 0a9e75377..3cb6fc3d5 100644 --- a/test/Mechanical/translational_modelica.jl +++ b/test/Mechanical/translational_modelica.jl @@ -1,11 +1,9 @@ using ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks import ModelingToolkitStandardLibrary.Mechanical.TranslationalModelica as TP -@parameters t -D = Differential(t) - @testset "spring damper mass fixed" begin @named damper = TP.Damper(; d = 1) @named spring = TP.Spring(; c = 1, s_rel0 = 1) diff --git a/test/Thermal/demo.jl b/test/Thermal/demo.jl index c50227156..5403681fc 100644 --- a/test/Thermal/demo.jl +++ b/test/Thermal/demo.jl @@ -1,9 +1,7 @@ using ModelingToolkitStandardLibrary.Thermal, ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t, D_nounits as D using OrdinaryDiffEq: ReturnCode.Success -@parameters t -D = Differential(t) - # Modelica example @testset "demo" begin @named mass1 = HeatCapacitor(C = 15, T = 373.15) diff --git a/test/Thermal/thermal.jl b/test/Thermal/thermal.jl index b6319ef5c..5cea2a01b 100644 --- a/test/Thermal/thermal.jl +++ b/test/Thermal/thermal.jl @@ -1,9 +1,8 @@ using ModelingToolkitStandardLibrary.Thermal, ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t, D_nounits as D using ModelingToolkitStandardLibrary.Blocks: Constant, Step using OrdinaryDiffEq: ReturnCode.Success -@parameters t -D = Differential(t) #= # Test HeatCapacitor, TemperatureSensor, RelativeTemperatureSensor, FixedTemperature @testset "Heat systems" begin diff --git a/test/chua_circuit.jl b/test/chua_circuit.jl index 6c2a3dddc..26fa362d0 100644 --- a/test/chua_circuit.jl +++ b/test/chua_circuit.jl @@ -1,4 +1,5 @@ using ModelingToolkit +using ModelingToolkit: t_nounits as t using ModelingToolkitStandardLibrary.Electrical using ModelingToolkitStandardLibrary.Electrical: OnePort using OrdinaryDiffEq @@ -6,8 +7,6 @@ using OrdinaryDiffEq: ReturnCode.Success using IfElse: ifelse @testset "Chua Circuit" begin - @parameters t - @component function NonlinearResistor(; name, Ga, Gb, Ve) @named oneport = OnePort() @unpack v, i = oneport diff --git a/test/multi_domain.jl b/test/multi_domain.jl index 7508ec13a..7b2ef4d81 100644 --- a/test/multi_domain.jl +++ b/test/multi_domain.jl @@ -5,12 +5,10 @@ using ModelingToolkitStandardLibrary.Blocks using ModelingToolkitStandardLibrary.Thermal import ModelingToolkitStandardLibrary using ModelingToolkit, OrdinaryDiffEq, Test +using ModelingToolkit: t_nounits as t, D_nounits as D using OrdinaryDiffEq: ReturnCode.Success # using Plots -@parameters t -D = Differential(t) - @testset "DC motor" begin R = 0.5 L = 4.5e-3 @@ -72,7 +70,7 @@ D = Differential(t) @test sol[inertia.w][idx_t]≈(dc_gain * [V_step; -tau_L_step])[2] rtol=1e-3 @test sol[emf.i][idx_t]≈(dc_gain * [V_step; -tau_L_step])[1] rtol=1e-3 - prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 6.0)) + prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 6.0)) sol = solve(prob, DFBDF()) @test sol.retcode == Success # EMF equations @@ -161,7 +159,7 @@ end @test all(sol[inertia.w] .== sol[speed_sensor.w.u]) - prob = DAEProblem(sys, D.(states(sys)) .=> 0.0, Pair[], (0, 6.0)) + prob = DAEProblem(sys, D.(unknowns(sys)) .=> 0.0, Pair[], (0, 6.0)) sol = solve(prob, DFBDF()) @test sol.retcode == Success