1
+ struct SemilinearODEFunction{iip, spec} end
2
+ struct SemilinearODEProblem{iip, spec} end
3
+
1
4
const U0_P_DOCS = """
2
5
The order of unknowns is determined by `unknowns(sys)`. If the system is split
3
6
[`is_split`](@ref) create an [`MTKParameters`](@ref) object. Otherwise, a parameter vector.
@@ -92,6 +95,15 @@ function problem_ctors(prob, istd)
92
95
end
93
96
end
94
97
98
+ function problem_ctors (prob:: Type{<:SemilinearODEProblem} , istd)
99
+ @assert istd
100
+ """
101
+ SciMLBase.$prob (sys::System, op, tspan::NTuple{2}; kwargs...)
102
+ SciMLBase.$prob {iip}(sys::System, op, tspan::NTuple{2}; kwargs...)
103
+ SciMLBase.$prob {iip, specialize}(sys::System, op, tspan::NTuple{2}; stiff_linear = true, stiff_quadratic = false, stiff_nonlinear = false, kwargs...)
104
+ """
105
+ end
106
+
95
107
function prob_fun_common_kwargs (T, istd)
96
108
return """
97
109
- `check_compatibility`: Whether to check if the given system `sys` contains all the
@@ -103,7 +115,8 @@ function prob_fun_common_kwargs(T, istd)
103
115
"""
104
116
end
105
117
106
- function problem_docstring (prob, func, istd; init = true , extra_body = " " )
118
+ function problem_docstring (prob, func, istd; init = true , extra_body = " " ,
119
+ extra_kwargs = " " , extra_kwargs_desc = " " )
107
120
if func isa DataType
108
121
func = " `$func `"
109
122
end
@@ -127,8 +140,9 @@ function problem_docstring(prob, func, istd; init = true, extra_body = "")
127
140
$PROBLEM_KWARGS
128
141
$(istd ? TIME_DEPENDENT_PROBLEM_KWARGS : " " )
129
142
$(prob_fun_common_kwargs (prob, istd))
130
-
143
+ $(extra_kwargs)
131
144
All other keyword arguments are forwarded to the $func constructor.
145
+ $(extra_kwargs_desc)
132
146
133
147
$PROBLEM_INTERNALS_HEADER
134
148
@@ -186,6 +200,32 @@ If the `System` has algebraic equations, like `x(t)^2 + y(t)^2`, the resulting
186
200
`BVProblem` must be solved using BVDAE solvers, such as Ascher.
187
201
"""
188
202
203
+ const SEMILINEAR_EXTRA_BODY = """
204
+ This is a special form of an ODE which uses a `SplitFunction` internally. The equations are
205
+ separated into linear, quadratic and general terms and phrased as matrix operations. See
206
+ [`calculate_semiquadratic_form`](@ref) for information on how the equations are split. This
207
+ formulation allows leveraging split ODE solvers such as `KenCarp4` and is useful for systems
208
+ where the stiff and non-stiff terms can be separated out in such a manner. Typically the linear
209
+ part of the equations is the stiff part, but the keywords `stiff_linear`, `stiff_quadratic` and `stiff_nonlinear` can
210
+ be used to control which parts are considered as stiff.
211
+ """
212
+
213
+ const SEMILINEAR_A_B_C_KWARGS = """
214
+ - `stiff_linear`: Whether the linear part of the equations should be part of the stiff function
215
+ in the split form. Has no effect if the equations have no linear part.
216
+ - `stiff_quadratic`: Whether the quadratic part of the equations should be part of the stiff
217
+ function in the split form. Has no effect if the equations have no quadratic part.
218
+ - `stiff_nonlinear`: Whether the non-linear non-quadratic part of the equations should be part of
219
+ the stiff function in the split form. Has no effect if the equations have no such
220
+ non-linear non-quadratic part.
221
+ """
222
+
223
+ const SEMILINEAR_A_B_C_CONSTRAINT = """
224
+ Note that all three of `stiff_linear`, `stiff_quadratic`, `stiff_nonlinear` cannot be identical, and at least
225
+ two of `A`, `B`, `C` returned from [`calculate_semiquadratic_form`](@ref) must be
226
+ non-`nothing`. In other words, both of the functions in the split form must be non-empty.
227
+ """
228
+
189
229
for (mod, prob, func, istd, kws) in [
190
230
(SciMLBase, :ODEProblem , ODEFunction, true , (;)),
191
231
(SciMLBase, :SteadyStateProblem , ODEFunction, false , (;)),
@@ -201,7 +241,13 @@ for (mod, prob, func, istd, kws) in [
201
241
(SciMLBase, :NonlinearProblem , NonlinearFunction, false , (;)),
202
242
(SciMLBase, :NonlinearLeastSquaresProblem , NonlinearFunction, false , (;)),
203
243
(SciMLBase, :SCCNonlinearProblem , NonlinearFunction, false , (; init = false )),
204
- (SciMLBase, :OptimizationProblem , OptimizationFunction, false , (; init = false ))
244
+ (SciMLBase, :OptimizationProblem , OptimizationFunction, false , (; init = false )),
245
+ (ModelingToolkit,
246
+ :SemilinearODEProblem ,
247
+ :SemilinearODEFunction ,
248
+ true ,
249
+ (; extra_body = SEMILINEAR_EXTRA_BODY, extra_kwargs = SEMILINEAR_A_B_C_KWARGS,
250
+ extra_kwargs_desc = SEMILINEAR_A_B_C_CONSTRAINT))
205
251
]
206
252
kwexpr = Expr (:parameters )
207
253
for (k, v) in pairs (kws)
@@ -210,7 +256,8 @@ for (mod, prob, func, istd, kws) in [
210
256
@eval @doc problem_docstring ($ kwexpr, $ mod.$ prob, $ func, $ istd) $ mod.$ prob
211
257
end
212
258
213
- function function_docstring (func, istd, optionals)
259
+ function function_docstring (
260
+ func, istd, optionals; extra_body = " " , extra_kwargs = " " , extra_kwargs_desc = " " )
214
261
return """
215
262
$func (sys::System; kwargs...)
216
263
$func {iip}(sys::System; kwargs...)
@@ -220,6 +267,8 @@ function function_docstring(func, istd, optionals)
220
267
function should be in-place. `specialization` is a `SciMLBase.AbstractSpecalize`
221
268
subtype indicating the level of specialization of the $func .
222
269
270
+ $(extra_body)
271
+
223
272
Beyond the arguments listed below, this constructor accepts all keyword arguments
224
273
supported by the DifferentialEquations.jl `solve` function. For a complete list
225
274
and detailed descriptions, see the [DifferentialEquations.jl solve documentation](https://docs.sciml.ai/DiffEqDocs/stable/basics/common_solver_opts/).
@@ -240,9 +289,11 @@ function function_docstring(func, istd, optionals)
240
289
sparse matrices. Also controls whether the mass matrix is sparse, wherever applicable.
241
290
$(prob_fun_common_kwargs (func, istd))
242
291
$(process_optional_function_kwargs (optionals))
292
+ $(extra_kwargs)
243
293
- `kwargs...`: Additional keyword arguments passed to the solver
244
294
245
295
All other keyword arguments are forwarded to the `$func ` struct constructor.
296
+ $(extra_kwargs_desc)
246
297
"""
247
298
end
248
299
@@ -333,20 +384,30 @@ function process_optional_function_kwargs(choices::Vector{Symbol})
333
384
join (map (Base. Fix1 (getindex, OPTIONAL_FN_KWARGS_DICT), choices), " \n " )
334
385
end
335
386
336
- for (mod, func, istd, optionals) in [
337
- (SciMLBase, :ODEFunction , true , [:jac , :tgrad ]),
338
- (SciMLBase, :ODEInputFunction , true , [:inputfn , :jac , :tgrad , :controljac ]),
339
- (SciMLBase, :DAEFunction , true , [:jac , :tgrad ]),
340
- (SciMLBase, :DDEFunction , true , Symbol[]),
341
- (SciMLBase, :SDEFunction , true , [:jac , :tgrad ]),
342
- (SciMLBase, :SDDEFunction , true , Symbol[]),
343
- (SciMLBase, :DiscreteFunction , true , Symbol[]),
344
- (SciMLBase, :ImplicitDiscreteFunction , true , Symbol[]),
345
- (SciMLBase, :NonlinearFunction , false , [:resid_prototype , :jac ]),
346
- (SciMLBase, :IntervalNonlinearFunction , false , Symbol[]),
347
- (SciMLBase, :OptimizationFunction , false , [:jac , :grad , :hess , :cons_h , :cons_j ])
387
+ for (mod, func, istd, optionals, kws) in [
388
+ (SciMLBase, :ODEFunction , true , [:jac , :tgrad ], (;)),
389
+ (SciMLBase, :ODEInputFunction , true , [:inputfn , :jac , :tgrad , :controljac ], (;)),
390
+ (SciMLBase, :DAEFunction , true , [:jac , :tgrad ], (;)),
391
+ (SciMLBase, :DDEFunction , true , Symbol[], (;)),
392
+ (SciMLBase, :SDEFunction , true , [:jac , :tgrad ], (;)),
393
+ (SciMLBase, :SDDEFunction , true , Symbol[], (;)),
394
+ (SciMLBase, :DiscreteFunction , true , Symbol[], (;)),
395
+ (SciMLBase, :ImplicitDiscreteFunction , true , Symbol[], (;)),
396
+ (SciMLBase, :NonlinearFunction , false , [:resid_prototype , :jac ], (;)),
397
+ (SciMLBase, :IntervalNonlinearFunction , false , Symbol[], (;)),
398
+ (SciMLBase, :OptimizationFunction , false , [:jac , :grad , :hess , :cons_h , :cons_j ], (;)),
399
+ (ModelingToolkit,
400
+ :SemilinearODEFunction ,
401
+ true ,
402
+ [:jac ],
403
+ (; extra_body = SEMILINEAR_EXTRA_BODY, extra_kwargs = SEMILINEAR_A_B_C_KWARGS,
404
+ extra_kwargs_desc = SEMILINEAR_A_B_C_CONSTRAINT))
348
405
]
349
- @eval @doc function_docstring ($ mod.$ func, $ istd, $ optionals) $ mod.$ func
406
+ kwexpr = Expr (:parameters )
407
+ for (k, v) in pairs (kws)
408
+ push! (kwexpr. args, Expr (:kw , k, v))
409
+ end
410
+ @eval @doc function_docstring ($ kwexpr, $ mod.$ func, $ istd, $ optionals) $ mod.$ func
350
411
end
351
412
352
413
@doc """
0 commit comments