Skip to content

Commit 2431138

Browse files
refactor: use default t and D from MTKv9
1 parent d27d372 commit 2431138

File tree

33 files changed

+38
-90
lines changed

33 files changed

+38
-90
lines changed

docs/src/connectors/connections.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ As can be seen, this will give a 1 equation model matching our energy dissipatio
9090

9191
```@example connections
9292
using ModelingToolkitStandardLibrary.Electrical, ModelingToolkit, DifferentialEquations
93+
using ModelingToolkit: t, D
9394
using Plots
9495
95-
@parameters t
96-
9796
@named resistor = Resistor(R = 1)
9897
@named capacitor = Capacitor(C = 1)
9998
@named ground = Ground()

docs/src/tutorials/custom_component.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ First, we need to make some imports.
88

99
```@example components
1010
using ModelingToolkit
11+
using ModelingToolkit: t_nounits as t
1112
using ModelingToolkitStandardLibrary.Electrical
1213
using ModelingToolkitStandardLibrary.Electrical: OnePort
1314
using OrdinaryDiffEq
@@ -35,8 +36,6 @@ end NonlinearResistor;
3536
this can almost be directly translated to the syntax of `ModelingToolkit`.
3637

3738
```@example components
38-
@parameters t
39-
4039
function NonlinearResistor(; name, Ga, Gb, Ve)
4140
@named oneport = OnePort()
4241
@unpack v, i = oneport

docs/src/tutorials/dc_motor_pi.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ First, the needed packages are imported and the parameters of the model defined.
1414

1515
```@example dc_motor_pi
1616
using ModelingToolkit
17+
using ModelingToolkit: t
1718
using ModelingToolkitStandardLibrary.Electrical
1819
using ModelingToolkitStandardLibrary.Mechanical.Rotational
1920
using ModelingToolkitStandardLibrary.Blocks
2021
using OrdinaryDiffEq
2122
using Plots
2223
23-
@parameters t
24-
2524
R = 0.5 # [Ohm] armature resistance
2625
L = 4.5e-3 # [H] armature inductance
2726
k = 0.5 # [N.m/A] motor constant

docs/src/tutorials/input_component.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ The `ModelingToolkitStandardLibrary.Blocks.TimeVaryingFunction` component is eas
1414

1515
```julia
1616
using ModelingToolkit
17+
using ModelingToolkit: t, D
1718
using ModelingToolkitStandardLibrary.Blocks
1819
using DataInterpolations
1920
using OrdinaryDiffEq
2021

21-
@parameters t
22-
D = Differential(t)
23-
2422
function System(f; name)
2523
src = TimeVaryingFunction(f)
2624

docs/src/tutorials/thermal_model.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ from dividing the total initial energy in the system by the sum of the heat capa
88

99
```@example
1010
using ModelingToolkitStandardLibrary.Thermal, ModelingToolkit, OrdinaryDiffEq, Plots
11-
12-
@parameters t
11+
using ModelingToolkit: t
1312
1413
C1 = 15
1514
C2 = 15

src/Blocks/Blocks.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ module Blocks
55
using ModelingToolkit, Symbolics
66
import IfElse: ifelse
77
import ..@symcheck
8-
using ModelingToolkit: getdefault
9-
10-
@parameters t
11-
D = Differential(t)
8+
using ModelingToolkit: getdefault, t, D
129

1310
export RealInput, RealOutput, SISO
1411
include("utils.jl")

src/Blocks/continuous.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u
542542
]
543543
# pars = @parameters A=A B=B C=C D=D # This is buggy
544544
eqs = [ # FIXME: if array equations work
545-
[Differential(t)(x[i]) ~ sum(A[i, k] * x[k] for k in 1:nx) +
545+
[D(x[i]) ~ sum(A[i, k] * x[k] for k in 1:nx) +
546546
sum(B[i, j] * (input.u[j] - u0[j]) for j in 1:nu)
547547
for i in 1:nx]..., # cannot use D here
548548
[output.u[j] ~ sum(C[j, i] * x[i] for i in 1:nx) +

src/Electrical/Electrical.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ This library contains electrical components to build up analog circuits.
55
module Electrical
66

77
using ModelingToolkit, Symbolics, IfElse
8+
using ModelingToolkit: t, D
89
using ..Thermal: HeatPort
910
using ..Mechanical.Rotational: Flange, Support
1011
using ..Blocks: RealInput, RealOutput
1112

12-
@parameters t
13-
D = Differential(t)
14-
1513
export Pin, OnePort
1614
include("utils.jl")
1715

src/Hydraulic/IsothermalCompressible/IsothermalCompressible.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ Library to model iso-thermal compressible liquid fluid flow
44
module IsothermalCompressible
55

66
using ModelingToolkit, Symbolics
7+
using ModelingToolkit: t, D
78

89
using ...Blocks: RealInput, RealOutput
910
using ...Mechanical.Translational: MechanicalPort, Mass
1011

1112
using IfElse: ifelse
1213

13-
@parameters t
14-
D = Differential(t)
15-
1614
export HydraulicPort, HydraulicFluid
1715
include("utils.jl")
1816

src/Magnetic/FluxTubes/FluxTubes.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
module FluxTubes
22
using ModelingToolkit
3+
using ModelingToolkit: t, D
34
using ...Electrical: Pin
45

5-
@parameters t
6-
D = Differential(t)
7-
86
export PositiveMagneticPort, NegativeMagneticPort, TwoPort
97
include("utils.jl")
108

src/Mechanical/MultiBody2D/MultiBody2D.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
module MultiBody2D
22

33
using ModelingToolkit, Symbolics, IfElse
4-
using ..TranslationalPosition
4+
using ModelingToolkit: t, D
55

6-
@parameters t
7-
D = Differential(t)
6+
using ..TranslationalPosition
87

98
export Link
109
include("components.jl")

src/Mechanical/Rotational/Rotational.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ Library to model 1-dimensional, rotational mechanical systems
44
module Rotational
55

66
using ModelingToolkit, Symbolics, IfElse
7+
using ModelingToolkit: t, D
8+
79
using ...Blocks: RealInput, RealOutput
810
import ...@symcheck
911

10-
@parameters t
11-
D = Differential(t)
12-
1312
export Flange, Support
1413
include("utils.jl")
1514

src/Mechanical/Translational/Translational.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ Library to model 1-dimensional, translational mechanical systems
44
module Translational
55

66
using ModelingToolkit, Symbolics
7-
using ModelingToolkit: getdefault
7+
using ModelingToolkit: getdefault, t, D
88

99
using ModelingToolkitStandardLibrary.Blocks: RealInput, RealOutput
1010
using IfElse: ifelse
1111

12-
@parameters t
13-
D = Differential(t)
14-
1512
export MechanicalPort
1613
include("utils.jl")
1714

src/Mechanical/TranslationalModelica/TranslationalModelica.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ Library to model 1-dimensional, translational mechanical components.
44
module TranslationalModelica
55

66
using ModelingToolkit, Symbolics, IfElse
7-
using ...Blocks: RealInput, RealOutput
7+
using ModelingToolkit: t, D
88

9-
@parameters t
10-
D = Differential(t)
9+
using ...Blocks: RealInput, RealOutput
1110

1211
export Flange
1312
include("utils.jl")

src/Mechanical/TranslationalPosition/TranslationalPosition.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ Library to model 1-dimensional, translational mechanical components.
44
module TranslationalPosition
55

66
using ModelingToolkit, Symbolics, IfElse
7-
using ...Blocks: RealInput, RealOutput
7+
using ModelingToolkit: t, D
88

9-
@parameters t
10-
D = Differential(t)
9+
using ...Blocks: RealInput, RealOutput
1110

1211
export Flange
1312
include("utils.jl")

src/Thermal/Thermal.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ Library of thermal system components to model heat transfer.
33
"""
44
module Thermal
55
using ModelingToolkit, Symbolics, IfElse
6-
using ...Blocks: RealInput, RealOutput
6+
using ModelingToolkit: t, D
77

8-
@parameters t
9-
D = Differential(t)
8+
using ...Blocks: RealInput, RealOutput
109

1110
export HeatPort, Element1D
1211
include("utils.jl")

test/Blocks/continuous.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEq
2+
using ModelingToolkit: t
23
using ModelingToolkitStandardLibrary.Blocks
34
using OrdinaryDiffEq: ReturnCode.Success
45
using Test
56

6-
@parameters t
7-
87
#=
98
Testing strategy:
109
The general strategy is to test systems using simple inputs where the solution
@@ -137,7 +136,6 @@ Second order demo plant
137136
@component function Plant(; name, x = zeros(2))
138137
@named input = RealInput()
139138
@named output = RealOutput()
140-
D = Differential(t)
141139
sts = @variables x1(t)=x[1] x2(t)=x[2]
142140
eqs = [D(x1) ~ x2
143141
D(x2) ~ -x1 - 0.5 * x2 + input.u

test/Blocks/math.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using ModelingToolkitStandardLibrary.Blocks
22
using ModelingToolkit, OrdinaryDiffEq, Test
33
using ModelingToolkitStandardLibrary.Blocks: _clamp, _dead_zone
4-
using ModelingToolkit: inputs, unbound_inputs, bound_inputs
4+
using ModelingToolkit: inputs, unbound_inputs, bound_inputs, t
55
using OrdinaryDiffEq: ReturnCode.Success
66

7-
@parameters t
8-
97
@testset "Gain" begin
108
@named c = Constant(; k = 1)
119
@named gain = Gain(; k = 1)

test/Blocks/nonlinear.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using ModelingToolkit, OrdinaryDiffEq
2+
using ModelingToolkit: t
23
using ModelingToolkitStandardLibrary.Blocks
34
using ModelingToolkitStandardLibrary.Blocks: _clamp, _dead_zone
45
using OrdinaryDiffEq: ReturnCode.Success
56

6-
@parameters t
7-
87
@testset "Limiter" begin
98
@testset "Constant" begin
109
@named c = Constant(; k = 1)

test/Blocks/sources.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEq
2+
using ModelingToolkit: t, D
23
using ModelingToolkitStandardLibrary.Blocks
34
using ModelingToolkitStandardLibrary.Blocks: smooth_sin, smooth_cos, smooth_damped_sin,
45
smooth_square, smooth_step, smooth_ramp,
56
smooth_triangular, triangular, square
67
using OrdinaryDiffEq: ReturnCode.Success
78

8-
@parameters t
9-
D = Differential(t)
10-
119
@testset "Constant" begin
1210
@named src = Constant(k = 2)
1311
@named int = Integrator()

test/Blocks/test_analysis_points.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using Test, LinearAlgebra
22
using ModelingToolkit
33
using ModelingToolkitStandardLibrary.Blocks
44
using OrdinaryDiffEq
5-
using ModelingToolkit: get_eqs, vars, @set!, get_iv
5+
using ModelingToolkit: get_eqs, vars, @set!, get_iv, t
66
using ControlSystemsBase
77

88
@named P = FirstOrder(k = 1, T = 1)
@@ -231,7 +231,6 @@ Si = ss(matrices...)
231231
@test tf(So) tf(Si)
232232

233233
## A simple multi-level system with loop openings
234-
@parameters t
235234
@named P_inner = FirstOrder(k = 1, T = 1)
236235
@named feedback = Feedback()
237236
@named ref = Step()

test/Electrical/analog.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ModelingToolkitStandardLibrary.Electrical, ModelingToolkit, OrdinaryDiffEq, Test
2+
using ModelingToolkit: t
23
using ModelingToolkitStandardLibrary.Blocks: Step,
34
Constant, Sine, Cosine, ExpSine, Ramp,
45
Square, Triangular
@@ -7,8 +8,6 @@ using OrdinaryDiffEq: ReturnCode.Success
78

89
# using Plots
910

10-
@parameters t
11-
1211
@testset "sensors" begin
1312
@named source = Sine(offset = 1, amplitude = 10, frequency = 5)
1413
@named voltage = Voltage()

test/Electrical/digital.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using ModelingToolkitStandardLibrary.Electrical: U, X, F0, F1, Z, W, L, H, DC, U
44
using ModelingToolkitStandardLibrary.Electrical: AndTable, OrTable, NotTable, XorTable
55
using ModelingToolkitStandardLibrary.Electrical: get_logic_level
66
using OrdinaryDiffEq: ReturnCode.Success
7-
7+
# using ModelingToolkit: t, D
88
# using ModelingToolkitStandardLibrary.Electrical: Set, Reset
99

1010
@testset "Logic, logic-vectors and helpers" begin
@@ -96,8 +96,6 @@ end
9696

9797
#=
9898
99-
@parameters t
100-
10199
@named set1 = Set()
102100
@named reset1 = Reset()
103101
@named set2 = Set()

test/Hydraulic/isothermal_compressible.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
using ModelingToolkit, OrdinaryDiffEq, Test
2+
using ModelingToolkit: t, D
23
import ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible as IC
34
import ModelingToolkitStandardLibrary.Blocks as B
45
import ModelingToolkitStandardLibrary.Mechanical.Translational as T
56

67
using ModelingToolkitStandardLibrary.Blocks: Parameter
78

8-
@parameters t
9-
D = Differential(t)
10-
119
NEWTON = NLNewton(check_div = false, always_new = true, max_iter = 100, relax = 9 // 10)
1210

1311
@testset "Fluid Domain and Tube" begin
@@ -195,8 +193,6 @@ end
195193

196194
@testset "Actuator System" begin
197195
function System(use_input, f; name)
198-
@parameters t
199-
200196
pars = @parameters begin
201197
p_s = 200e5
202198
p_r = 5e5

test/Magnetic/magnetic.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import ModelingToolkitStandardLibrary.Electrical
44
import ModelingToolkitStandardLibrary.Blocks
55
import ModelingToolkitStandardLibrary.Magnetic
66
using ModelingToolkit, OrdinaryDiffEq, Test
7+
using ModelingToolkit: t, D
78
using OrdinaryDiffEq: ReturnCode.Success
89
# using Plots
910

10-
@parameters t
11-
1211
@testset "Inductor" begin
1312
mu_air = 1
1413
l_air = 0.0001

test/Mechanical/multibody.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using ModelingToolkit
2+
using ModelingToolkit: t
23
using ModelingToolkitStandardLibrary.Mechanical.MultiBody2D
34
using ModelingToolkitStandardLibrary.Mechanical.TranslationalPosition
45
using OrdinaryDiffEq
56
# using Setfield
67
using Test
78

8-
@parameters t
9-
109
@named link1 = Link(; m = 1, l = 10, I = 84, g = -9.807)
1110
@named link2 = Link(; m = 1, l = 10, I = 84, g = -9.807, x1_0 = 10)
1211
@named cart = Mass(; m = 1, s = 0)

test/Mechanical/rotational.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using ModelingToolkitStandardLibrary.Mechanical.Rotational,
22
ModelingToolkit, OrdinaryDiffEq,
33
Test
4+
using ModelingToolkit: t, D
45
import ModelingToolkitStandardLibrary.Blocks
56
using OrdinaryDiffEq: ReturnCode.Success
67

78
# using Plots
89

9-
@parameters t
10-
D = Differential(t)
11-
1210
@testset "two inertias" begin
1311
@named fixed = Fixed()
1412
@named inertia1 = Inertia(J = 2) # this one is fixed

0 commit comments

Comments
 (0)