Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
ModelingToolkitBase = "7771a370-6774-4173-bd38-47e70ca0b839"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b"
Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7"
Expand All @@ -23,6 +24,7 @@ ForwardDiff = "0.10, 1"
LinearAlgebra = "1.10"
ModelingToolkit = "11.28"
ModelingToolkitBase = "1.49"
PrecompileTools = "1.2.1"
OrdinaryDiffEq = "7"
OrdinaryDiffEqBDF = "2"
OrdinaryDiffEqDefault = "2"
Expand Down
12 changes: 12 additions & 0 deletions src/ModelingToolkitStandardLibrary.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module ModelingToolkitStandardLibrary
import SymbolicUtils: unwrap
using ModelingToolkitBase: System, connect, t_nounits as t
using PrecompileTools: @compile_workload, @setup_workload

"""
@symcheck J > 0 || throw(ArgumentError("Expected `J` to be positive"))
Expand All @@ -23,4 +25,14 @@ include("Electrical/Electrical.jl")
include("Magnetic/Magnetic.jl")
include("Hydraulic/Hydraulic.jl")

@setup_workload begin
constant = Blocks.Constant(; name = :constant, k = 1.0)
integrator = Blocks.Integrator(; name = :integrator, x = 0.0)
connections = [connect(constant.output, integrator.input)]

@compile_workload begin
System(connections, t; name = :model, systems = [integrator, constant])
end
end

end
17 changes: 17 additions & 0 deletions test/precompile_workload.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using ModelingToolkitStandardLibrary.Blocks
using ModelingToolkitBase: System, connect, equations, t_nounits as t
using Test

@testset "Precompile workload" begin
constant = Constant(; name = :constant, k = 1.0)
integrator = Integrator(; name = :integrator, x = 0.0)
model = System(
[connect(constant.output, integrator.input)],
t;
name = :model,
systems = [integrator, constant]
)

@test model isa System
@test !isempty(equations(model))
end
Loading