@@ -153,15 +153,15 @@ generate_custom_function(sys::AbstractSystem, exprs, dvs = unknowns(sys),
153
153
154
154
Generate a function to evaluate `exprs`. `exprs` is a symbolic expression or
155
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),
156
+ may be subsetted using `dvs` and `ps`. All `kwargs` are passed to the internal
157
+ [`build_function`](@ref) call. The returned function can be called as `f(u, p, t)` or
158
+ `f(du, u, p, t)` for time-dependent systems and `f(u, p)` or `f(du, u, p)` for
159
+ time-independent systems. If `split=true` (the default) was passed to [`complete`](@ref),
160
160
[`structural_simplify`](@ref) or [`@mtkbuild`](@ref), `p` is expected to be an `MTKParameters`
161
161
object.
162
162
"""
163
163
function generate_custom_function (sys:: AbstractSystem , exprs, dvs = unknowns (sys),
164
- ps = parameters (sys); wrap_code = nothing , kwargs... )
164
+ ps = parameters (sys); wrap_code = nothing , postprocess_fbody = nothing , states = nothing , kwargs... )
165
165
if ! iscomplete (sys)
166
166
error (" A completed system is required. Call `complete` or `structural_simplify` on the system." )
167
167
end
@@ -171,15 +171,20 @@ function generate_custom_function(sys::AbstractSystem, exprs, dvs = unknowns(sys
171
171
wrap_code = isscalar ? identity : (identity, identity)
172
172
end
173
173
pre, sol_states = get_substitutions_and_solved_unknowns (sys)
174
-
174
+ if postprocess_fbody === nothing
175
+ postprocess_fbody = pre
176
+ end
177
+ if states === nothing
178
+ states = sol_states
179
+ end
175
180
if is_time_dependent (sys)
176
181
return build_function (exprs,
177
182
dvs,
178
183
p... ,
179
184
get_iv (sys);
180
185
kwargs... ,
181
- postprocess_fbody = pre ,
182
- states = sol_states ,
186
+ postprocess_fbody,
187
+ states,
183
188
wrap_code = wrap_code .∘ wrap_mtkparameters (sys, isscalar) .∘
184
189
wrap_array_vars (sys, exprs; dvs)
185
190
)
@@ -188,8 +193,8 @@ function generate_custom_function(sys::AbstractSystem, exprs, dvs = unknowns(sys
188
193
dvs,
189
194
p... ;
190
195
kwargs... ,
191
- postprocess_fbody = pre ,
192
- states = sol_states ,
196
+ postprocess_fbody,
197
+ states,
193
198
wrap_code = wrap_code .∘ wrap_mtkparameters (sys, isscalar) .∘
194
199
wrap_array_vars (sys, exprs; dvs)
195
200
)
0 commit comments