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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
ProcessBasedModelling.jl follows semver 2.0.
Changelog is kept with respect to v1 release.

## 1.8

- Updated to ModelingToolkit.jl v10. `type` keyword in `processes_to_mtkmodel` is now no longer used.

## 1.7

- Added an additional check when constructing the raw equations that catches
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name = "ProcessBasedModelling"
uuid = "ca969041-2cf3-4b10-bc21-86f4417093eb"
authors = ["Datseris <datseris.george@gmail.com>"]
version = "1.7.0"
version = "1.8.0"

[deps]
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
ModelingToolkit = "9.0"
ModelingToolkit = "10.0"
Reexport = "1.2"
julia = "1.9.0"
22 changes: 10 additions & 12 deletions src/make.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""
processes_to_mtkmodel(processes::Vector [, default]; kw...)

Construct a ModelingToolkit.jl model/system using the provided `processes` and `default` processes.
The model/system is _not_ structurally simplified. Use the function
[`processes_to_mtkeqs`](@ref) to obtain the raw `Vector{Equation}` before it is
passed to the MTK model/system like `ODESystem`.
Construct a ModelingToolkit.jl model using the provided `processes` and `default` processes.
The model is _not_ `mtkcompile`-d. Use the function
[`processes_to_mtkeqs`](@ref) to obtain the raw `Vector{Equation}`.

During construction, the following automations improve user experience:

Expand Down Expand Up @@ -49,9 +48,8 @@ These registered default processes are used when `default` is a `Module`.

## Keyword arguments

- `type = ODESystem`: the model type to make.
- `name = nameof(type)`: the name of the model.
- `independent = t`: the independent variable (default: `@variables t`).
- `name = :model`: the name of the model.
- `independent = t`: the independent variable (default: `@independent_variables t`).
`t` is also exported by ProcessBasedModelling.jl for convenience.
- `warn_default::Bool = true`: if `true`, throw a warning when a variable does not
have an assigned process but it has a default value so that it becomes a parameter instead.
Expand All @@ -61,10 +59,10 @@ These registered default processes are used when `default` is a `Module`.
(has happened to me many times!).
"""
function processes_to_mtkmodel(args...;
type = ODESystem, name = nameof(type), independent = t, kw...,
type = System, name = :model, independent = t, kw...,
)
eqs = processes_to_mtkeqs(args...; kw...)
sys = type(eqs, independent; name)
sys = System(eqs, independent; name)
return sys
end

Expand Down Expand Up @@ -144,17 +142,17 @@ function processes_to_mtkeqs(_processes::Vector, default::Dict{Num, Any};
end

function expand_multi_processes(procs::Vector)
etypes = Union{Vector, ODESystem, SDESystem, PDESystem}
etypes = Union{Vector, System}
!any(p -> p isa etypes, procs) && return procs
# Expand vectors of processes or ODESystems
# Expand vectors of processes or Systems
expanded = Any[procs...]
idxs = findall(p -> p isa etypes, procs)
multiprocs = expanded[idxs]
deleteat!(expanded, idxs)
for mp in multiprocs
if mp isa Vector
append!(expanded, mp)
else # then it is XDE system
else # then it is System
append!(expanded, equations(mp))
end
end
Expand Down
16 changes: 6 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ end

# First, make some default processes
@variables T(t) = 300.0 # temperature, in Kelvin
@variables α(t) = 0.3 # albedo of ice, unitless
@variables ε(t) = 0.5 # effective emissivity, unitless
@variables α(t) # albedo of ice, unitless
@variables ε(t) # effective emissivity, unitless
solar_constant = 340.25 # W/m^2, already divided by 4
σ_Stefan_Boltzman = 5.670374419e-8 # stefan boltzman constant

Expand Down Expand Up @@ -61,10 +61,8 @@ end
]

sys = processes_to_mtkmodel(processes)
@test sys isa ODESystem
@test length(unknowns(sys)) == 3

sys = structural_simplify(sys)
sys = mtkcompile(sys)
@test length(unknowns(sys)) == 1
@test has_symbolic_var(equations(sys), T)

Expand All @@ -87,13 +85,11 @@ end
]

sys = processes_to_mtkmodel(processes)
@test sys isa ODESystem
@test length(unknowns(sys)) == 3

sys = structural_simplify(sys)
sys = mtkcompile(sys)
@test length(unknowns(sys)) == 1
@test has_symbolic_var(equations(sys), T)

end

@testset "add missing processes" begin
Expand Down Expand Up @@ -192,7 +188,7 @@ end
AdditionProcess(TimeDerivative(q, x^2, 1.2), ExpRelaxation(q, x^2), q ~ y*x)
]
mtk = processes_to_mtkmodel(processes)
mtk = structural_simplify(mtk)
mtk = mtkcompile(mtk)
eqs = all_equations(mtk)
@test has_symbolic_var(eqs, x)
@test has_symbolic_var(eqs, y)
Expand All @@ -209,7 +205,7 @@ end
@test_throws ArgumentError AdditionProcess(x ~ 0.1z, y ~ x^2)
end

@testset "ODESystem as process" begin
@testset "System as process" begin
@variables z(t) = 0.0
@variables x(t) = 0.0
@variables y(t) = 0.0
Expand Down
Loading