Skip to content

Commit 87df269

Browse files
docs: add doc for generate_custom_function
1 parent f584815 commit 87df269

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

docs/src/internals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ The call chain typically looks like this, with the function names in the case of
3232

3333
1. Problem constructor ([`ODEProblem`](@ref))
3434
2. Build an `DEFunction` ([`process_DEProblem`](@ref) -> [`ODEFunction`](@ref)
35-
3. Write actual executable code ([`generate_function`](@ref))
35+
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`.

src/systems/abstractsystem.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,26 @@ Generate a function to evaluate the system's equations.
145145
"""
146146
function generate_function end
147147

148+
"""
149+
```julia
150+
generate_custom_function(sys::AbstractSystem, exprs, dvs = unknowns(sys),
151+
ps = full_parameters(sys); kwargs...)
152+
```
153+
154+
Generate a function to evaluate `exprs`. `exprs` is a symbolic expression or
155+
array of symbolic expression involving symbolic variables in `sys`. The symbolic variables
156+
may be subsetted using `dvs` and `ps`. All `kwargs` except `postprocess_fbody` and `states`
157+
are passed to the internal [`build_function`](@ref) call. The returned function can be called
158+
as `f(u, p, t)` or `f(du, u, p, t)` for time-dependent systems and `f(u, p)` or `f(du, u, p)`
159+
for time-independent systems. If `split=true` (the default) was passed to [`complete`](@ref),
160+
[`structural_simplify`](@ref) or [`@mtkbuild`](@ref), `p` is expected to be an `MTKParameters`
161+
object.
162+
"""
148163
function generate_custom_function(sys::AbstractSystem, exprs, dvs = unknowns(sys),
149164
ps = parameters(sys); wrap_code = nothing, kwargs...)
165+
if !iscomplete(sys)
166+
error("A completed system is required. Call `complete` or `structural_simplify` on the system.")
167+
end
150168
p = reorder_parameters(sys, ps)
151169
isscalar = !(exprs isa AbstractArray)
152170
if wrap_code === nothing

0 commit comments

Comments
 (0)