Skip to content

Commit 74812c4

Browse files
Merge pull request #785 from SciML/myb/docs
Document getters
2 parents ae029d0 + fb10f6d commit 74812c4

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

docs/src/systems/AbstractSystem.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,33 @@ total set, which includes that of all systems held inside.
1717

1818
The values which are common to all `AbstractSystem`s are:
1919

20-
- `sys.eqs` or `equations(sys)`: The equations that define the system.
21-
- `sys.states` or `states(sys)`: The set of states in the system.
22-
- `sys.parameters` or `parameters(sys)`: The parameters of the system.
23-
- `sys.systems`: The subsystems of the system.
20+
- `equations(sys)`: All equations that define the system and its subsystems.
21+
- `states(sys)`: All the states in the system and its subsystems.
22+
- `parameters(sys)`: All parameters of the system and its subsystems.
23+
- `nameof(sys)`: The name of the current-level system.
24+
- `get_equations(sys)`: Equations that define the current-level system.
25+
- `get_states(sys)`: States that are in the current-level system.
26+
- `get_ps(sys)`: Parameters that are in the current-level system.
27+
- `get_systems(sys)`: Subsystems of the current-level system.
28+
29+
Optionally, a system could have:
30+
31+
- `observed(sys)`: All observed equations of the system and its subsystems.
32+
- `get_observed(sys)`: Observed equations of the current-level system.
33+
- `get_default_u0(sys)`: A `Dict` that maps states into their default initial
34+
condition.
35+
- `get_default_p(sys)`: A `Dict` that maps parameters into their default value.
36+
- `independent_variable(sys)`: The independent variable of a system.
37+
- `get_noiseeqs(sys)`: Noise equations of the current-level system.
38+
39+
Note that there's `get_iv(sys)`, but it is not advised to use, since it errors
40+
when the system has no field `iv`. `independent_variable(sys)` returns `nothing`
41+
for `NonlinearSystem`s.
42+
43+
A system could also have caches:
44+
45+
- `get_jac(sys)`: The Jacobian of a system.
46+
- `get_tgrad(sys)`: The gradient with respect to time of a system.
2447

2548
## Transformations
2649

src/systems/abstractsystem.jl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,29 @@ function getname(t)
127127
end
128128
end
129129

130-
independent_variable(sys::AbstractSystem) = getfield(sys, :iv)
130+
independent_variable(sys::AbstractSystem) = isdefined(sys, :iv) ? getfield(sys, :iv) : nothing
131131

132132
function structure(sys::AbstractSystem)
133133
s = get_structure(sys)
134134
s isa SystemStructure || throw(ArgumentError("SystemStructure is not yet initialized, please run `sys = initialize_system_structure(sys)` or `sys = alias_elimination(sys)`."))
135135
return s
136136
end
137-
for prop in [:eqs, :iv, :states, :ps, :default_p, :default_u0, :observed, :tgrad, :jac, :Wfact, :Wfact_t, :systems, :structure]
137+
for prop in [
138+
:eqs
139+
:noiseeqs
140+
:iv
141+
:states
142+
:ps
143+
:default_p
144+
:default_u0
145+
:observed
146+
:tgrad
147+
:jac
148+
:Wfact
149+
:Wfact_t
150+
:systems
151+
:structure
152+
]
138153
fname1 = Symbol(:get_, prop)
139154
fname2 = Symbol(:has_, prop)
140155
@eval begin

src/systems/nonlinear/nonlinearsystem.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ function NonlinearSystem(eqs, states, ps;
6363
NonlinearSystem(eqs, value.(states), value.(ps), observed, name, systems, default_u0, default_p, nothing)
6464
end
6565

66-
independent_variable(::NonlinearSystem) = nothing
67-
6866
function calculate_jacobian(sys::NonlinearSystem;sparse=false,simplify=false)
6967
rhs = [eq.rhs for eq equations(sys)]
7068
vals = [dv for dv in states(sys)]

0 commit comments

Comments
 (0)