Skip to content

Commit 96ad879

Browse files
committed
Add more documentation (based on #1822)
1 parent 421e41e commit 96ad879

File tree

5 files changed

+81
-7
lines changed

5 files changed

+81
-7
lines changed

src/constants.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ toconstant(s::Num) = wrap(toconstant(value(s)))
2727
$(SIGNATURES)
2828
2929
Define one or more constants.
30+
31+
See also [`@independent_variables`](@ref), [`@parameters`](@ref) and [`@variables`](@ref).
3032
"""
3133
macro constants(xs...)
3234
Symbolics._parse_vars(:constants,

src/parameters.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ tovar(s::Num) = Num(tovar(value(s)))
5454
$(SIGNATURES)
5555
5656
Define one or more known parameters.
57+
58+
See also [`@independent_variables`](@ref), [`@variables`](@ref) and [`@constants`](@ref).
5759
"""
5860
macro parameters(xs...)
5961
Symbolics._parse_vars(:parameters,

src/structural_transformation/StructuralTransformations.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ using SparseArrays
5050

5151
using SimpleNonlinearSolve
5252

53+
using DocStringExtensions
54+
5355
export tearing, partial_state_selection, dae_index_lowering, check_consistency
5456
export dummy_derivative
5557
export build_torn_function, build_observed_function, ODAEProblem

src/structural_transformation/symbolics_tearing.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ function tearing_sub(expr, dict, s)
8686
s ? simplify(expr) : expr
8787
end
8888

89+
"""
90+
$(TYPEDSIGNATURES)
91+
92+
Like `equations(sys)`, but includes substitutions done by the tearing process.
93+
These equations matches generated numerical code.
94+
95+
See also [`equations`](@ref) and [`ModelingToolkit.get_eqs`](@ref).
96+
"""
8997
function full_equations(sys::AbstractSystem; simplify = false)
9098
empty_substitutions(sys) && return equations(sys)
9199
substitutions = get_substitutions(sys)

src/systems/abstractsystem.jl

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ function independent_variables(sys::AbstractMultivariateSystem)
355355
return getfield(sys, :ivs)
356356
end
357357

358+
"""
359+
$(TYPEDSIGNATURES)
360+
361+
Get the independent variable(s) of the system `sys`.
362+
363+
See also [`@independent_variables`](@ref) and [`ModelingToolkit.get_iv`](@ref).
364+
"""
358365
function independent_variables(sys::AbstractSystem)
359366
@warn "Please declare ($(typeof(sys))) as a subtype of `AbstractTimeDependentSystem`, `AbstractTimeIndependentSystem` or `AbstractMultivariateSystem`."
360367
if isdefined(sys, :iv)
@@ -649,11 +656,29 @@ for prop in [:eqs
649656
:split_idxs
650657
:parent
651658
:index_cache]
652-
fname1 = Symbol(:get_, prop)
653-
fname2 = Symbol(:has_, prop)
659+
fname_get = Symbol(:get_, prop)
660+
fname_has = Symbol(:has_, prop)
654661
@eval begin
655-
$fname1(sys::AbstractSystem) = getfield(sys, $(QuoteNode(prop)))
656-
$fname2(sys::AbstractSystem) = isdefined(sys, $(QuoteNode(prop)))
662+
"""
663+
$(TYPEDSIGNATURES)
664+
665+
Get the internal field `$($(QuoteNode(prop)))` of a system `sys`.
666+
It only includes `$($(QuoteNode(prop)))` local to `sys`; not those of its subsystems,
667+
like `unknowns(sys)`, `parameters(sys)` and `equations(sys)` does.
668+
This is equivalent to, but preferred over `sys.$($(QuoteNode(prop)))`.
669+
670+
See also [`has_$($(QuoteNode(prop)))`](@ref).
671+
"""
672+
$fname_get(sys::AbstractSystem) = getfield(sys, $(QuoteNode(prop)))
673+
674+
"""
675+
$(TYPEDSIGNATURES)
676+
677+
Returns whether the system `sys` has the internal field `$($(QuoteNode(prop)))`.
678+
679+
See also [`get_$($(QuoteNode(prop)))`](@ref).
680+
"""
681+
$fname_has(sys::AbstractSystem) = isdefined(sys, $(QuoteNode(prop)))
657682
end
658683
end
659684

@@ -1003,6 +1028,14 @@ function namespace_expr(
10031028
end
10041029
end
10051030
_nonum(@nospecialize x) = x isa Num ? x.val : x
1031+
1032+
"""
1033+
$(TYPEDSIGNATURES)
1034+
1035+
Get the unknown variables of the system `sys` and its subsystems.
1036+
1037+
See also [`ModelingToolkit.get_unknowns`](@ref).
1038+
"""
10061039
function unknowns(sys::AbstractSystem)
10071040
sts = get_unknowns(sys)
10081041
systems = get_systems(sys)
@@ -1023,6 +1056,13 @@ function unknowns(sys::AbstractSystem)
10231056
unique(nonunique_unknowns)
10241057
end
10251058

1059+
"""
1060+
$(TYPEDSIGNATURES)
1061+
1062+
Get the parameters of the system `sys` and its subsystems.
1063+
1064+
See also [`@parameters`](@ref) and [`ModelingToolkit.get_ps`](@ref).
1065+
"""
10261066
function parameters(sys::AbstractSystem)
10271067
ps = get_ps(sys)
10281068
if ps == SciMLBase.NullParameters()
@@ -1131,6 +1171,15 @@ end
11311171

11321172
flatten(sys::AbstractSystem, args...) = sys
11331173

1174+
"""
1175+
$(TYPEDSIGNATURES)
1176+
1177+
Get the flattened equations of the system `sys` and its subsystems.
1178+
It may include some abbreviations and aliases of observables.
1179+
It is often the most useful way to inspect the equations of a system.
1180+
1181+
See also [`full_equations`](@ref) and [`ModelingToolkit.get_eqs`](@ref).
1182+
"""
11341183
function equations(sys::AbstractSystem)
11351184
eqs = get_eqs(sys)
11361185
systems = get_systems(sys)
@@ -1145,6 +1194,13 @@ function equations(sys::AbstractSystem)
11451194
end
11461195
end
11471196

1197+
"""
1198+
$(TYPEDSIGNATURES)
1199+
1200+
Get the initialization equations of the system `sys` and its subsystems.
1201+
1202+
See also [`ModelingToolkit.get_initialization_eqs`](@ref).
1203+
"""
11481204
function initialization_equations(sys::AbstractSystem)
11491205
eqs = get_initialization_eqs(sys)
11501206
systems = get_systems(sys)
@@ -2500,8 +2556,10 @@ end
25002556
"""
25012557
$(TYPEDSIGNATURES)
25022558
2503-
extend the `basesys` with `sys`, the resulting system would inherit `sys`'s name
2559+
Extend the `basesys` with `sys`, the resulting system would inherit `sys`'s name
25042560
by default.
2561+
2562+
See also [`compose`](@ref).
25052563
"""
25062564
function extend(sys::AbstractSystem, basesys::AbstractSystem; name::Symbol = nameof(sys),
25072565
gui_metadata = get_gui_metadata(sys))
@@ -2550,8 +2608,10 @@ end
25502608
"""
25512609
$(SIGNATURES)
25522610
2553-
compose multiple systems together. The resulting system would inherit the first
2611+
Compose multiple systems together. The resulting system would inherit the first
25542612
system's name.
2613+
2614+
See also [`extend`](@ref).
25552615
"""
25562616
function compose(sys::AbstractSystem, systems::AbstractArray; name = nameof(sys))
25572617
nsys = length(systems)
@@ -2572,7 +2632,7 @@ end
25722632
"""
25732633
missing_variable_defaults(sys::AbstractSystem, default = 0.0; subset = unknowns(sys))
25742634
2575-
returns a `Vector{Pair}` of variables set to `default` which are missing from `get_defaults(sys)`. The `default` argument can be a single value or vector to set the missing defaults respectively.
2635+
Returns a `Vector{Pair}` of variables set to `default` which are missing from `get_defaults(sys)`. The `default` argument can be a single value or vector to set the missing defaults respectively.
25762636
"""
25772637
function missing_variable_defaults(
25782638
sys::AbstractSystem, default = 0.0; subset = unknowns(sys))

0 commit comments

Comments
 (0)