Skip to content

Commit

Permalink
refactor: use default t and D from MTKv9
Browse files Browse the repository at this point in the history
  • Loading branch information
AayushSabharwal committed Feb 22, 2024
1 parent 3fcf939 commit 645278c
Show file tree
Hide file tree
Showing 33 changed files with 38 additions and 90 deletions.
3 changes: 1 addition & 2 deletions docs/src/connectors/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, D
using Plots
@parameters t
@named resistor = Resistor(R = 1)
@named capacitor = Capacitor(C = 1)
@named ground = Ground()
Expand Down
3 changes: 1 addition & 2 deletions docs/src/tutorials/custom_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions docs/src/tutorials/dc_motor_pi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Expand Down
4 changes: 1 addition & 3 deletions docs/src/tutorials/input_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ The `ModelingToolkitStandardLibrary.Blocks.TimeVaryingFunction` component is eas

```julia
using ModelingToolkit
using ModelingToolkit: t, D
using ModelingToolkitStandardLibrary.Blocks
using DataInterpolations
using OrdinaryDiffEq

@parameters t
D = Differential(t)

function System(f; name)
src = TimeVaryingFunction(f)

Expand Down
3 changes: 1 addition & 2 deletions docs/src/tutorials/thermal_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
C1 = 15
C2 = 15
Expand Down
5 changes: 1 addition & 4 deletions src/Blocks/Blocks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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, D

export RealInput, RealOutput, SISO
include("utils.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/Blocks/continuous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ linearized around the operating point `x₀, u₀`, we have `y0, u0 = h(x₀, u
]
# pars = @parameters A=A B=B C=C D=D # This is buggy
eqs = [ # FIXME: if array equations work
[Differential(t)(x[i]) ~ sum(A[i, k] * x[k] for k in 1:nx) +
[D(x[i]) ~ sum(A[i, k] * x[k] for k in 1:nx) +
sum(B[i, j] * (input.u[j] - u0[j]) for j in 1:nu)
for i in 1:nx]..., # cannot use D here
[output.u[j] ~ sum(C[j, i] * x[i] for i in 1:nx) +
Expand Down
4 changes: 1 addition & 3 deletions src/Electrical/Electrical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ This library contains electrical components to build up analog circuits.
module Electrical

using ModelingToolkit, Symbolics, IfElse
using ModelingToolkit: t, D
using ..Thermal: HeatPort
using ..Mechanical.Rotational: Flange, Support
using ..Blocks: RealInput, RealOutput

@parameters t
D = Differential(t)

export Pin, OnePort
include("utils.jl")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ Library to model iso-thermal compressible liquid fluid flow
module IsothermalCompressible

using ModelingToolkit, Symbolics
using ModelingToolkit: t, D

using ...Blocks: RealInput, RealOutput
using ...Mechanical.Translational: MechanicalPort, Mass

using IfElse: ifelse

@parameters t
D = Differential(t)

export HydraulicPort, HydraulicFluid
include("utils.jl")

Expand Down
4 changes: 1 addition & 3 deletions src/Magnetic/FluxTubes/FluxTubes.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module FluxTubes
using ModelingToolkit
using ModelingToolkit: t, D
using ...Electrical: Pin

@parameters t
D = Differential(t)

export PositiveMagneticPort, NegativeMagneticPort, TwoPort
include("utils.jl")

Expand Down
5 changes: 2 additions & 3 deletions src/Mechanical/MultiBody2D/MultiBody2D.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module MultiBody2D

using ModelingToolkit, Symbolics, IfElse
using ..TranslationalPosition
using ModelingToolkit: t, D

@parameters t
D = Differential(t)
using ..TranslationalPosition

export Link
include("components.jl")
Expand Down
5 changes: 2 additions & 3 deletions src/Mechanical/Rotational/Rotational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ Library to model 1-dimensional, rotational mechanical systems
module Rotational

using ModelingToolkit, Symbolics, IfElse
using ModelingToolkit: t, D

using ...Blocks: RealInput, RealOutput
import ...@symcheck

@parameters t
D = Differential(t)

export Flange, Support
include("utils.jl")

Expand Down
5 changes: 1 addition & 4 deletions src/Mechanical/Translational/Translational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ Library to model 1-dimensional, translational mechanical systems
module Translational

using ModelingToolkit, Symbolics
using ModelingToolkit: getdefault
using ModelingToolkit: getdefault, t, D

using ModelingToolkitStandardLibrary.Blocks: RealInput, RealOutput
using IfElse: ifelse

@parameters t
D = Differential(t)

export MechanicalPort
include("utils.jl")

Expand Down
5 changes: 2 additions & 3 deletions src/Mechanical/TranslationalModelica/TranslationalModelica.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ Library to model 1-dimensional, translational mechanical components.
module TranslationalModelica

using ModelingToolkit, Symbolics, IfElse
using ...Blocks: RealInput, RealOutput
using ModelingToolkit: t, D

@parameters t
D = Differential(t)
using ...Blocks: RealInput, RealOutput

export Flange
include("utils.jl")
Expand Down
5 changes: 2 additions & 3 deletions src/Mechanical/TranslationalPosition/TranslationalPosition.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ Library to model 1-dimensional, translational mechanical components.
module TranslationalPosition

using ModelingToolkit, Symbolics, IfElse
using ...Blocks: RealInput, RealOutput
using ModelingToolkit: t, D

@parameters t
D = Differential(t)
using ...Blocks: RealInput, RealOutput

export Flange
include("utils.jl")
Expand Down
5 changes: 2 additions & 3 deletions src/Thermal/Thermal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ Library of thermal system components to model heat transfer.
"""
module Thermal
using ModelingToolkit, Symbolics, IfElse
using ...Blocks: RealInput, RealOutput
using ModelingToolkit: t, D

@parameters t
D = Differential(t)
using ...Blocks: RealInput, RealOutput

export HeatPort, Element1D
include("utils.jl")
Expand Down
4 changes: 1 addition & 3 deletions test/Blocks/continuous.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEq
using ModelingToolkit: t
using ModelingToolkitStandardLibrary.Blocks
using OrdinaryDiffEq: ReturnCode.Success
using Test

@parameters t

#=
Testing strategy:
The general strategy is to test systems using simple inputs where the solution
Expand Down Expand Up @@ -138,7 +137,6 @@ Second order demo plant
@component function Plant(; name, x = zeros(2))
@named input = RealInput()
@named output = RealOutput()
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
Expand Down
4 changes: 1 addition & 3 deletions test/Blocks/math.jl
Original file line number Diff line number Diff line change
@@ -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
using OrdinaryDiffEq: ReturnCode.Success

@parameters t

@testset "Gain" begin
@named c = Constant(; k = 1)
@named gain = Gain(; k = 1)
Expand Down
3 changes: 1 addition & 2 deletions test/Blocks/nonlinear.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using ModelingToolkit, OrdinaryDiffEq
using ModelingToolkit: t
using ModelingToolkitStandardLibrary.Blocks
using ModelingToolkitStandardLibrary.Blocks: _clamp, _dead_zone
using OrdinaryDiffEq: ReturnCode.Success

@parameters t

@testset "Limiter" begin
@testset "Constant" begin
@named c = Constant(; k = 1)
Expand Down
4 changes: 1 addition & 3 deletions test/Blocks/sources.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using ModelingToolkit, ModelingToolkitStandardLibrary, OrdinaryDiffEq
using ModelingToolkit: t, D
using ModelingToolkitStandardLibrary.Blocks
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()
Expand Down
3 changes: 1 addition & 2 deletions test/Blocks/test_analysis_points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using Test, LinearAlgebra
using ModelingToolkit
using ModelingToolkitStandardLibrary.Blocks
using OrdinaryDiffEq
using ModelingToolkit: get_eqs, vars, @set!, get_iv
using ModelingToolkit: get_eqs, vars, @set!, get_iv, t
using ControlSystemsBase

@named P = FirstOrder(k = 1, T = 1)
Expand Down Expand Up @@ -231,7 +231,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()
Expand Down
3 changes: 1 addition & 2 deletions test/Electrical/analog.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ModelingToolkitStandardLibrary.Electrical, ModelingToolkit, OrdinaryDiffEq, Test
using ModelingToolkit: t
using ModelingToolkitStandardLibrary.Blocks: Step,
Constant, Sine, Cosine, ExpSine, Ramp,
Square, Triangular
Expand All @@ -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()
Expand Down
4 changes: 1 addition & 3 deletions test/Electrical/digital.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using ModelingToolkitStandardLibrary.Electrical: U, X, F0, F1, Z, W, L, H, DC, U
using ModelingToolkitStandardLibrary.Electrical: AndTable, OrTable, NotTable, XorTable
using ModelingToolkitStandardLibrary.Electrical: get_logic_level
using OrdinaryDiffEq: ReturnCode.Success

# using ModelingToolkit: t, D
# using ModelingToolkitStandardLibrary.Electrical: Set, Reset

@testset "Logic, logic-vectors and helpers" begin
Expand Down Expand Up @@ -96,8 +96,6 @@ end

#=
@parameters t
@named set1 = Set()
@named reset1 = Reset()
@named set2 = Set()
Expand Down
6 changes: 1 addition & 5 deletions test/Hydraulic/isothermal_compressible.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using ModelingToolkit, OrdinaryDiffEq, Test
using ModelingToolkit: t, 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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions test/Magnetic/magnetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import ModelingToolkitStandardLibrary.Electrical
import ModelingToolkitStandardLibrary.Blocks
import ModelingToolkitStandardLibrary.Magnetic
using ModelingToolkit, OrdinaryDiffEq, Test
using ModelingToolkit: t, D
using OrdinaryDiffEq: ReturnCode.Success
# using Plots

@parameters t

@testset "Inductor" begin
mu_air = 1
l_air = 0.0001
Expand Down
3 changes: 1 addition & 2 deletions test/Mechanical/multibody.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using ModelingToolkit
using ModelingToolkit: 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)
Expand Down
4 changes: 1 addition & 3 deletions test/Mechanical/rotational.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using ModelingToolkitStandardLibrary.Mechanical.Rotational,
ModelingToolkit, OrdinaryDiffEq,
Test
using ModelingToolkit: t, 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
Expand Down
Loading

0 comments on commit 645278c

Please sign in to comment.