@@ -190,6 +190,79 @@ function DiffEqBase.ODEFunction{iip}(sys::AbstractODESystem, dvs = states(sys),
190
190
syms = Symbol .(states (sys)))
191
191
end
192
192
193
+ """
194
+ ```julia
195
+ function DiffEqBase.ODEFunctionExpr{iip}(sys::AbstractODESystem, dvs = states(sys),
196
+ ps = parameters(sys);
197
+ version = nothing, tgrad=false,
198
+ jac = false, Wfact = false,
199
+ sparse = false,
200
+ kwargs...) where {iip}
201
+ ```
202
+
203
+ Create a Julia expression for an `ODEFunction` from the [`ODESystem`](@ref).
204
+ The arguments `dvs` and `ps` are used to set the order of the dependent
205
+ variable and parameter vectors, respectively.
206
+ """
207
+ struct ODEFunctionExpr{iip} end
208
+
209
+ function ODEFunctionExpr {iip} (sys:: AbstractODESystem , dvs = states (sys),
210
+ ps = parameters (sys), u0 = nothing ;
211
+ version = nothing , tgrad= false ,
212
+ jac = false , Wfact = false ,
213
+ sparse = false ,
214
+ kwargs... ) where {iip}
215
+
216
+ idx = iip ? 2 : 1
217
+ f = generate_function (sys, dvs, ps; expression= Val{true }, kwargs... )[idx]
218
+ if tgrad
219
+ _tgrad = generate_tgrad (sys, dvs, ps; expression= Val{true }, kwargs... )[idx]
220
+ else
221
+ _tgrad = :nothing
222
+ end
223
+
224
+ if jac
225
+ _jac = generate_jacobian (sys, dvs, ps; sparse = sparse, expression= Val{true }, kwargs... )[idx]
226
+ else
227
+ _jac = :nothing
228
+ end
229
+
230
+ if Wfact
231
+ tmp_Wfact,tmp_Wfact_t = generate_factorized_W (sys, dvs, ps; expression= Val{true }, kwargs... )
232
+ _Wfact = tmp_Wfact[idx]
233
+ _Wfact_t = tmp_Wfact_t[idx]
234
+ else
235
+ _Wfact,_Wfact_t = :nothing ,:nothing
236
+ end
237
+
238
+ M = calculate_massmatrix (sys)
239
+
240
+ _M = (u0 === nothing || M == I) ? M : ArrayInterface. restructure (u0 .* u0' ,M)
241
+
242
+ quote
243
+ f = $ f
244
+ tgrad = $ _tgrad
245
+ jac = $ _jac
246
+ Wfact = $ _Wfact
247
+ Wfact_t = $ _Wfact_t
248
+ M = $ _M
249
+
250
+ ODEFunction {iip} (f,
251
+ jac = jac,
252
+ tgrad = tgrad,
253
+ Wfact = Wfact,
254
+ Wfact_t = Wfact_t,
255
+ mass_matrix = M,
256
+ syms = $ (Symbol .(states (sys))))
257
+ end
258
+ end
259
+
260
+
261
+ function ODEFunctionExpr (sys:: AbstractODESystem , args... ; kwargs... )
262
+ ODEFunctionExpr {true} (sys, args... ; kwargs... )
263
+ end
264
+
265
+
193
266
function DiffEqBase. ODEProblem (sys:: AbstractODESystem , args... ; kwargs... )
194
267
ODEProblem {true} (sys, args... ; kwargs... )
195
268
end
@@ -225,6 +298,50 @@ function DiffEqBase.ODEProblem{iip}(sys::AbstractODESystem,u0map,tspan,
225
298
ODEProblem {iip} (f,u0,tspan,p;kwargs... )
226
299
end
227
300
301
+ """
302
+ ```julia
303
+ function DiffEqBase.ODEProblemExpr{iip}(sys::AbstractODESystem,u0map,tspan,
304
+ parammap=DiffEqBase.NullParameters();
305
+ version = nothing, tgrad=false,
306
+ jac = false, Wfact = false,
307
+ checkbounds = false, sparse = false,
308
+ linenumbers = true, parallel=SerialForm(),
309
+ kwargs...) where iip
310
+ ```
311
+
312
+ Generates a Julia expression for constructing an ODEProblem from an
313
+ ODESystem and allows for automatically symbolically calculating
314
+ numerical enhancements.
315
+ """
316
+ struct ODEProblemExpr{iip} end
317
+
318
+ function ODEProblemExpr {iip} (sys:: AbstractODESystem ,u0map,tspan,
319
+ parammap= DiffEqBase. NullParameters ();
320
+ version = nothing , tgrad= false ,
321
+ jac = false , Wfact = false ,
322
+ checkbounds = false , sparse = false ,
323
+ linenumbers = true , parallel= SerialForm (),
324
+ kwargs... ) where iip
325
+ dvs = states (sys)
326
+ ps = parameters (sys)
327
+ u0 = varmap_to_vars (u0map,dvs)
328
+ p = varmap_to_vars (parammap,ps)
329
+ f = ODEFunctionExpr {iip} (sys,dvs,ps,u0;tgrad= tgrad,jac= jac,Wfact= Wfact,checkbounds= checkbounds,
330
+ linenumbers= linenumbers,parallel= parallel,
331
+ sparse= sparse)
332
+ quote
333
+ f = $ f
334
+ u0 = $ u0
335
+ tspan = $ tspan
336
+ p = $ p
337
+ ODEProblem {iip} (f,u0,tspan,p;$ (kwargs... ))
338
+ end
339
+ end
340
+
341
+ function ODEProblemExpr (sys:: AbstractODESystem , args... ; kwargs... )
342
+ ODEProblemExpr {true} (sys, args... ; kwargs... )
343
+ end
344
+
228
345
229
346
# ## Enables Steady State Problems ###
230
347
function DiffEqBase. SteadyStateProblem (sys:: AbstractODESystem , args... ; kwargs... )
0 commit comments