|
| 1 | +@fallback_iip_specialize function SciMLBase.SDDEFunction{iip, spec}( |
| 2 | + sys::System, _d = nothing, u0 = nothing, p = nothing; |
| 3 | + eval_expression = false, eval_module = @__MODULE__, checkbounds = false, |
| 4 | + initialization_data = nothing, cse = true, check_compatibility = true, |
| 5 | + sparse = false, simplify = false, analytic = nothing, kwargs...) where { |
| 6 | + iip, spec} |
| 7 | + check_complete(sys, SDDEFunction) |
| 8 | + check_compatibility && check_compatible_system(SDDEFunction, sys) |
| 9 | + |
| 10 | + dvs = unknowns(sys) |
| 11 | + ps = parameters(sys) |
| 12 | + |
| 13 | + f = generate_rhs(sys, dvs, ps; expression = Val{false}, |
| 14 | + eval_expression, eval_module, checkbounds = checkbounds, cse, |
| 15 | + kwargs...) |
| 16 | + g = generate_diffusion_function(sys, dvs, ps; expression = Val{false}, |
| 17 | + eval_expression, eval_module, checkbounds, cse, kwargs...) |
| 18 | + |
| 19 | + if spec === SciMLBase.FunctionWrapperSpecialize && iip |
| 20 | + if u0 === nothing || p === nothing || t === nothing |
| 21 | + error("u0, p, and t must be specified for FunctionWrapperSpecialize on SDDEFunction.") |
| 22 | + end |
| 23 | + f = SciMLBase.wrapfun_iip(f, (u0, u0, p, t)) |
| 24 | + end |
| 25 | + |
| 26 | + M = calculate_massmatrix(sys) |
| 27 | + _M = concrete_massmatrix(M; sparse, u0) |
| 28 | + |
| 29 | + observedfun = ObservedFunctionCache( |
| 30 | + sys; eval_expression, eval_module, checkbounds, cse) |
| 31 | + |
| 32 | + SDDEFunction{iip, spec}(f, g; |
| 33 | + sys = sys, |
| 34 | + mass_matrix = _M, |
| 35 | + observed = observedfun, |
| 36 | + analytic = analytic, |
| 37 | + initialization_data) |
| 38 | +end |
| 39 | + |
| 40 | +@fallback_iip_specialize function SciMLBase.SDDEProblem{iip, spec}( |
| 41 | + sys::System, u0map, tspan, parammap = SciMLBase.NullParameters(); |
| 42 | + callback = nothing, check_length = true, cse = true, checkbounds = false, |
| 43 | + eval_expression = false, eval_module = @__MODULE__, check_compatibility = true, |
| 44 | + u0_constructor = identity, sparse = false, sparsenoise = sparse, |
| 45 | + kwargs...) where {iip, spec} |
| 46 | + check_complete(sys, SDDEProblem) |
| 47 | + check_compatibility && check_compatible_system(SDDEProblem, sys) |
| 48 | + |
| 49 | + f, u0, p = process_SciMLProblem(SDDEFunction{iip, spec}, sys, u0map, parammap; |
| 50 | + t = tspan !== nothing ? tspan[1] : tspan, check_length, cse, checkbounds, |
| 51 | + eval_expression, eval_module, check_compatibility, sparse, symbolic_u0 = true, kwargs...) |
| 52 | + |
| 53 | + h = generate_history( |
| 54 | + sys, u0; expression = Val{false}, cse, eval_expression, eval_module, |
| 55 | + checkbounds) |
| 56 | + u0 = float.(h(p, tspan[1])) |
| 57 | + if u0 !== nothing |
| 58 | + u0 = u0_constructor(u0) |
| 59 | + end |
| 60 | + |
| 61 | + noise, noise_rate_prototype = calculate_noise_and_rate_prototype(sys, u0; sparsenoise) |
| 62 | + kwargs = process_kwargs(sys; callback, eval_expression, eval_module, kwargs...) |
| 63 | + |
| 64 | + # Call `remake` so it runs initialization if it is trivial |
| 65 | + return remake(SDDEProblem{iip}( |
| 66 | + f, f.g, u0, h, tspan, p; noise, noise_rate_prototype, kwargs...)) |
| 67 | +end |
| 68 | + |
| 69 | +function check_compatible_system( |
| 70 | + T::Union{Type{SDDEFunction}, Type{SDDEProblem}}, sys::System) |
| 71 | + check_time_dependent(sys, T) |
| 72 | + check_is_dde(sys) |
| 73 | + check_no_cost(sys, T) |
| 74 | + check_no_constraints(sys, T) |
| 75 | + check_no_jumps(sys, T) |
| 76 | + check_has_noise(sys, T) |
| 77 | +end |
0 commit comments