Skip to content

Commit

Permalink
add intermediate function to mtkeqs
Browse files Browse the repository at this point in the history
  • Loading branch information
Datseris committed Oct 1, 2024
1 parent 064254f commit 9fd1af5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ProcessBasedModelling"
uuid = "ca969041-2cf3-4b10-bc21-86f4417093eb"
authors = ["Datseris <datseris.george@gmail.com>"]
version = "1.3.0"
version = "1.3.1"

[deps]
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
Expand Down
2 changes: 1 addition & 1 deletion src/ProcessBasedModelling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include("processes_basic.jl")

export t
export Process, ParameterProcess, TimeDerivative, ExpRelaxation, AdditionProcess
export processes_to_mtkmodel
export processes_to_mtkmodel, processes_to_mtkeqs
export new_derived_named_parameter
export has_symbolic_var, default_value
export @convert_to_parameters, LiteralParameter
Expand Down
33 changes: 21 additions & 12 deletions src/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
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. During construction, the following automations
improve user experience:
The model/system is _not_ structurally simplified. Use the function
`processes_to_mtkeqs` to obtain the raw `Vector{Equation}` before it is
passed to the MTK model/system like `ODESystem`.
During construction, the following automations improve user experience:
- Variable(s) introduced in `processes` that does not itself have a process obtain
a default process from `default`.
Expand Down Expand Up @@ -51,16 +54,24 @@ These registered processes are used when `default` is a `Module`.
- `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.
"""
processes_to_mtkmodel(procs::Vector; kw...) =
processes_to_mtkmodel(procs, Dict{Num, Any}(); kw...)
processes_to_mtkmodel(procs::Vector, m::Module; kw...) =
processes_to_mtkmodel(procs, default_processes(m); kw...)
processes_to_mtkmodel(procs::Vector, v::Vector; kw...) =
processes_to_mtkmodel(procs, default_dict(v); kw...)
function processes_to_mtkmodel(args...;
type = ODESystem, name = nameof(type), independent = t, kw...,
)
eqs = processes_to_mtkeqs(args...; kw...)
sys = type(eqs, independent; name)
return sys
end

processes_to_mtkeqs(procs::Vector; kw...) =
processes_to_mtkeqs(procs, Dict{Num, Any}(); kw...)
processes_to_mtkeqs(procs::Vector, m::Module; kw...) =
processes_to_mtkeqs(procs, default_processes(m); kw...)
processes_to_mtkeqs(procs::Vector, v::Vector; kw...) =
processes_to_mtkeqs(procs, default_dict(v); kw...)

# The main implementation has the defaults to be a map from variable to process
# because this simplifies a bit the code
function processes_to_mtkmodel(_processes::Vector, default::Dict{Num, Any};
function processes_to_mtkeqs(_processes::Vector, default::Dict{Num, Any};
type = ODESystem, name = nameof(type), independent = t, warn_default::Bool = true,
)
processes = expand_multi_processes(_processes)
Expand Down Expand Up @@ -116,9 +127,7 @@ function processes_to_mtkmodel(_processes::Vector, default::Dict{Num, Any};
end
end
end
# return eqs
sys = type(eqs, independent; name)
return sys
return eqs
end

function expand_multi_processes(procs::Vector)
Expand Down

0 comments on commit 9fd1af5

Please sign in to comment.