Skip to content

Commit

Permalink
Add keyword for warning when adding a ParameterProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
Datseris committed Mar 30, 2024
1 parent aab62c2 commit 3580c5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 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.0.4"
version = "1.0.5"

[deps]
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
Expand Down
20 changes: 12 additions & 8 deletions src/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ or provide a wrapper function for it, and add a default value for `default`.
- `name = nameof(type)`: the name of the model
- `independent = t`: the independent variable (default: `@variables t`).
`t` is also exported by ProcessBasedModelling.jl for convenience.
- `warn_defaut::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.
"""
function processes_to_mtkmodel(_processes, _default = [];
type = ODESystem, name = nameof(type), independent = t
type = ODESystem, name = nameof(type), independent = t, warn_default::Bool = true,
)
processes = expand_multi_processes(_processes)
default = default_dict(_default)
Expand Down Expand Up @@ -62,13 +64,15 @@ function processes_to_mtkmodel(_processes, _default = [];
else
def_val = default_value(added_var) # utilize default value (if possible)
if !isnothing(def_val)
@warn("""
Variable $(added_var) was introduced in process of variable $(introduced[added_var]).
However, a process for $(added_var) was not provided,
and there is no default process for it either.
Since it has a default value, we make it a parameter by adding a process:
`ParameterProcess($(ModelingToolkit.getname(added_var)))`.
""")
if warn_default == true
@warn("""
Variable $(added_var) was introduced in process of variable $(introduced[added_var]).
However, a process for $(added_var) was not provided,
and there is no default process for it either.
Since it has a default value, we make it a parameter by adding a process:
`ParameterProcess($(ModelingToolkit.getname(added_var)))`.
""")
end
parproc = ParameterProcess(added_var)
push!(eqs, lhs(parproc) ~ rhs(parproc))
push!(lhs_vars, added_var)
Expand Down

0 comments on commit 3580c5f

Please sign in to comment.