diff --git a/Project.toml b/Project.toml index 702ca90..398d23a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ProcessBasedModelling" uuid = "ca969041-2cf3-4b10-bc21-86f4417093eb" authors = ["Datseris "] -version = "1.3.0" +version = "1.3.1" [deps] ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" diff --git a/src/ProcessBasedModelling.jl b/src/ProcessBasedModelling.jl index 1c46e16..7ee3f7d 100644 --- a/src/ProcessBasedModelling.jl +++ b/src/ProcessBasedModelling.jl @@ -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 diff --git a/src/make.jl b/src/make.jl index 0275452..1389b6c 100644 --- a/src/make.jl +++ b/src/make.jl @@ -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`. @@ -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) @@ -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)