Skip to content

Commit af56da8

Browse files
YingboMaChrisRackauckas
authored andcommitted
More getters
1 parent 1d7ddff commit af56da8

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

docs/src/systems/AbstractSystem.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,29 @@ The values which are common to all `AbstractSystem`s are:
2020
- `equations(sys)`: All equations that define the system and its subsystems.
2121
- `states(sys)`: All the states in the system and its subsystems.
2222
- `parameters(sys)`: All parameters of the system and its subsystems.
23+
- `nameof(sys)`: The name of the current-level system.
2324
- `get_equations(sys)`: Equations that define the current-level system.
2425
- `get_states(sys)`: States that are in the current-level system.
2526
- `get_ps(sys)`: Parameters that are in the current-level system.
2627
- `get_systems(sys)`: Subsystems of the current-level system.
27-
- `get_name(sys)` or `nameof(sys)`: The name of the current-level system.
2828

29-
Optionally, a system could have
29+
Optionally, a system could have:
3030

31-
- `get_default_u0`: A `Dict` that maps states into their default initial
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
3234
condition.
33-
- `get_default_p`: A `Dict` that maps parameters into their default value.
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+
38+
Note that there's `get_iv(sys)`, but it is not advised to use, since it errors
39+
when the system has no field `iv`. `independent_variable(sys)` returns `nothing`
40+
for `NonlinearSystem`s.
41+
42+
A system could also have caches:
43+
44+
- `get_jac(sys)`: The Jacobian of a system.
45+
- `get_tgrad(sys)`: The gradient with respect to time of a system.
3446

3547
## Transformations
3648

src/systems/abstractsystem.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ 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)

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)