You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* bump version of MTK
* rename states to unknowns
* make default choices more fitting for dynsys
* increase test coverage
* increase coverage more
* more informative make new parameter
* correct exponential relaxation
* explcitily display errors and warnings
* state value
* name, not symbol
* massive improvement on parameter macro
* typo
* don't use (t) in the wranings
* add LiteralParameter
* fix literal value
* fix wrong test in derived
* fix omitted x
* restore warnonly setting
* fix timescale reference
* use canonical MTK t and derivative as requested
* fix typo in docs
* bump version to 1.0
* add addition process and test for all processes
Copy file name to clipboardExpand all lines: docs/src/index.md
+47-20Lines changed: 47 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -5,12 +5,17 @@ ProcessBasedModelling
5
5
!!! note "Basic familiarity with ModelingToolkit.jl"
6
6
These docs assume that you have some basic familiarity with ModelingToolkit.jl. If you don't going through the introductory tutorial of [ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/) should be enough to get you started!
7
7
8
+
!!! note "Default `t` is unitless"
9
+
Like ModelingToolkit.jl, ProcessBasedModelling.jl also exports `t` as the independent variable representing time.
10
+
However, instead of the default `t` of ModelingToolkit.jl, here `t` is unitless.
11
+
Do `t = ModelingToolkit.t` to obtain the unitful version of `t`.
8
12
9
13
## Usage
10
14
11
15
In ProcessBasedModelling.jl, each variable is governed by a "process".
12
16
Conceptually this is just an equation that _defines_ the given variable.
13
-
To couple the variable with the process it is governed by, a user either defines simple equations of the form "variable = expression", or creates an instance of [`Process`](@ref) if the left-hand-side of the equation needs to be anything more complex. In either case, the variable and the expression are both _symbolic expressions_ created via ModellingToolkit.jl (more specifically, via Symbolics.jl).
17
+
To couple the variable with the process it is governed by, a user either defines simple equations of the form "variable = expression", or creates an instance of [`Process`](@ref) if the left-hand-side of the equation needs to be anything more complex (or, simply if you want to utilize the conveniences of predefined processes).
18
+
In either case, the variable and the expression are both _symbolic expressions_ created via ModellingToolkit.jl (more specifically, via Symbolics.jl).
14
19
15
20
Once all the processes about the physical system are collected, they are given as a `Vector` to the [`processes_to_mtkmodel`](@ref) central function, similarly to how one gives a `Vector` of `Equation`s to e.g., `ModelingToolkit.ODESystem`. This function also defines what quantifies as a "process" in more specificity.
16
21
@@ -30,13 +35,17 @@ symbolically using ModelingToolkit.jl (**MTK**). We define
30
35
using ModelingToolkit
31
36
using OrdinaryDiffEq: Tsit5
32
37
33
-
@variables t # independent variable
38
+
@variables t # independent variable _without_ units
34
39
@variables z(t) = 0.0
35
40
@variables x(t) # no default value
36
41
@variables y(t) = 0.0
37
42
```
38
43
ProcessBasedModelling.jl (**PBM**) strongly recommends that all defined variables have a default value at definition point. Here we didn't do this for ``x`` to illustrate what how such an "omission" will be treated by **PBM**.
39
44
45
+
!!! note "ModelingToolkit.jl is re-exported"
46
+
ProcessBasedModelling.jl re-exports the whole `ModelingToolkit` package,
47
+
so you don't need to be `using` both of them, just `using ProcessBasedModelling`.
48
+
40
49
To make the equations we want, we can use MTK directly, and call
41
50
```@example MAIN
42
51
eqs = [
@@ -52,20 +61,23 @@ equations(model)
52
61
53
62
All good. Now, if we missed the process for one variable (because of our own error/sloppyness/very-large-codebase), MTK will throw an error when we try to _structurally simplify_ the model (a step necessary before solving the ODE problem):
54
63
55
-
```@example MAIN
64
+
```julia
56
65
model =ODESystem(eqs[1:2], t; name =:example)
57
-
try
58
-
model = structural_simplify(model)
59
-
catch e
60
-
return e.msg
61
-
end
66
+
model =structural_simplify(model)
67
+
```
68
+
```
69
+
ERROR: ExtraVariablesSystemException: The system is unbalanced.
70
+
There are 3 highest order derivative variables and 2 equations.
71
+
More variables than equations, here are the potential extra variable(s):
72
+
z(t)
73
+
x(t)
74
+
y(t)
62
75
```
63
76
64
-
As you can see, the error message is unhelpful even with such a trivial system of equations,
65
-
as all variables are reported as "potentially missing".
77
+
The error message is unhelpful as all variables are reported as "potentially missing".
66
78
At least on the basis of our scientific reasoning however, both ``x, z`` have an equation.
67
79
It is ``y`` that ``x`` introduced that does not have an equation.
68
-
Moreover, in our experience these errors messages become increasingly less useful when a model has many equations and/or variables, as many variables get cited as "missing" from the variable map even when only one should be.
80
+
Moreover, in our experience these error messages become increasingly less useful when a model has many equations and/or variables, as many variables get cited as "missing" from the variable map even when only one should be.
69
81
70
82
**PBM** resolves these problems and always gives accurate error messages when it comes to
71
83
the construction of the system of equations.
@@ -95,15 +107,17 @@ Notice that the resulting **MTK** model is not `structural_simplify`-ed, to allo
95
107
Now, in contrast to before, if we "forgot" a process, **PBM** will react accordingly.
96
108
For example, if we forgot the 2nd process, then the construction will error informatively,
97
109
telling us exactly which variable is missing, and because of which processes it is missing:
98
-
```@example MAIN
99
-
try
100
-
model = processes_to_mtkmodel(processes[[1, 3]])
101
-
catch e
102
-
return e.msg
103
-
end
110
+
```julia
111
+
model =processes_to_mtkmodel(processes[[1, 3]])
112
+
```
113
+
```
114
+
ERROR: ArgumentError: Variable x was introduced in process of variable z(t).
115
+
However, a process for x was not provided,
116
+
there is no default process for x, and x doesn't have a default value.
117
+
Please provide a process for variable x.
104
118
```
105
119
106
-
If instead we "forgot" the ``y`` process, **PBM** will not error, but instead warn, and make ``y`` equal to a named parameter:
120
+
If instead we "forgot" the ``y`` process, **PBM** will not error, but warn, and make ``y`` equal to a named parameter, since ``y`` has a default value:
107
121
```@example MAIN
108
122
model = processes_to_mtkmodel(processes[1:2])
109
123
equations(model)
@@ -113,8 +127,18 @@ equations(model)
113
127
parameters(model)
114
128
```
115
129
130
+
and the warning thrown was:
131
+
```julia
132
+
┌ Warning: Variable y was introduced in process of variable x(t).
133
+
│ However, a process for y was not provided,
134
+
│ and there is no default process for it either.
135
+
│ Since it has a default value, we make it a parameter by adding a process:
Lastly, [`processes_to_mtkmodel`](@ref) also allows the concept of "default" processes, that can be used for introduced "process-less" variables.
117
-
Default processes are like `processes` and given as a 2nd argument to [`process_to_mtkmodel`](@ref).
141
+
Default processes are like `processes` and given as a 2nd argument to [`processes_to_mtkmodel`](@ref).
118
142
For example,
119
143
120
144
```@example MAIN
@@ -143,7 +167,8 @@ equations(model)
143
167
parameters(model)
144
168
```
145
169
146
-
This special handling is also why each process explicitly declares a timescale via the [`timescale`](@ref) function that one can optionally extend.
170
+
This special handling is also why each process can declare a timescale via the [`ProcessBasedModelling.timescale`](@ref) function that one can optionally extend
171
+
(although in our experience the default behaviour covers almost all cases).
0 commit comments