Skip to content

Commit dafab96

Browse files
Merge pull request #2955 from AayushSabharwal/as/mtkparams-public-api
feat: document and expose `MTKParameters` as public API
2 parents 644f9bc + 6b87798 commit dafab96

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

docs/src/internals.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ The call chain typically looks like this, with the function names in the case of
3535
3. Write actual executable code ([`generate_function`](@ref) or [`generate_custom_function`](@ref))
3636

3737
Apart from [`generate_function`](@ref), which generates the dynamics function, `ODEFunction` also builds functions for observed equations (`build_explicit_observed_function`) and Jacobians (`generate_jacobian`) etc. These are all stored in the `ODEFunction`.
38+
39+
## Creating an `MTKParameters` object
40+
41+
It may be useful to create a parameter object without creating the problem. For this
42+
purpose, the `MTKParameters` constructor is exposed as public API.
43+
44+
```@docs
45+
MTKParameters
46+
```

src/ModelingToolkit.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,6 @@ export debug_system
275275
export Sample, Hold, Shift, ShiftIndex, sampletime, SampleTime
276276
export Clock, SolverStepClock, TimeDomain
277277

278+
export MTKParameters
279+
278280
end # module

src/systems/parameter_buffer.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,23 @@ struct MTKParameters{T, D, C, N}
1010
nonnumeric::N
1111
end
1212

13+
"""
14+
function MTKParameters(sys::AbstractSystem, p, u0 = Dict(); t0 = nothing)
15+
16+
Create an `MTKParameters` object for the system `sys`. `p` (`u0`) are symbolic maps from
17+
parameters (unknowns) to their values. The values can also be symbolic expressions, which
18+
are evaluated given the values of other parameters/unknowns. `u0` is only required if
19+
the values of parameters depend on the unknowns. `t0` is the initial time, for time-
20+
dependent systems. It is only required if the symbolic expressions also use the independent
21+
variable of the system.
22+
23+
This requires that `complete` has been called on the system (usually via
24+
`structural_simplify` or `@mtkbuild`) and the keyword `split = true` was passed (which is
25+
the default behavior).
26+
"""
1327
function MTKParameters(
1428
sys::AbstractSystem, p, u0 = Dict(); tofloat = false, use_union = false,
15-
t0 = nothing, eval_expression = false, eval_module = @__MODULE__)
29+
t0 = nothing)
1630
ic = if has_index_cache(sys) && get_index_cache(sys) !== nothing
1731
get_index_cache(sys)
1832
else

0 commit comments

Comments
 (0)