Skip to content

Commit

Permalink
Merge pull request #2955 from AayushSabharwal/as/mtkparams-public-api
Browse files Browse the repository at this point in the history
feat: document and expose `MTKParameters` as public API
  • Loading branch information
ChrisRackauckas authored Aug 17, 2024
2 parents 644f9bc + 6b87798 commit dafab96
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
9 changes: 9 additions & 0 deletions docs/src/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ The call chain typically looks like this, with the function names in the case of
3. Write actual executable code ([`generate_function`](@ref) or [`generate_custom_function`](@ref))

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`.

## Creating an `MTKParameters` object

It may be useful to create a parameter object without creating the problem. For this
purpose, the `MTKParameters` constructor is exposed as public API.

```@docs
MTKParameters
```
2 changes: 2 additions & 0 deletions src/ModelingToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,6 @@ export debug_system
export Sample, Hold, Shift, ShiftIndex, sampletime, SampleTime
export Clock, SolverStepClock, TimeDomain

export MTKParameters

end # module
16 changes: 15 additions & 1 deletion src/systems/parameter_buffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,23 @@ struct MTKParameters{T, D, C, N}
nonnumeric::N
end

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

0 comments on commit dafab96

Please sign in to comment.