-
-
Notifications
You must be signed in to change notification settings - Fork 271
Expand file tree
/
Copy pathOrdinaryDiffEqBDF.jl
More file actions
189 lines (169 loc) · 6.08 KB
/
Copy pathOrdinaryDiffEqBDF.jl
File metadata and controls
189 lines (169 loc) · 6.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
module OrdinaryDiffEqBDF
import OrdinaryDiffEqCore: perform_step!, unwrap_alg,
alg_extrapolates,
default_controller, IController,
OrdinaryDiffEqMutableCache, OrdinaryDiffEqConstantCache,
OrdinaryDiffEqNewtonAdaptiveAlgorithm,
OrdinaryDiffEqNewtonAlgorithm,
AbstractController,
alg_cache, @cache,
isfsal, full_cache,
constvalue, error_constant,
has_special_newton_error,
trivial_limiter!,
issplit, qmax_default, gamma_default,
qsteady_min_default, qsteady_max_default,
get_current_alg_order, get_current_adaptive_order,
stepsize_controller!,
step_accept_controller!,
step_reject_controller!, post_newton_controller!,
get_EEst,
setup_controller_cache, get_qmax, get_gamma, get_qsteady_min, get_qsteady_max,
get_failfactor, CommonControllerOptions, resolve_basic, _resolved_QT,
AbstractControllerCache,
DAEAlgorithm,
get_fsalfirstlast, generic_solver_docstring, _fixup_ad,
_ode_interpolant, _ode_interpolant!, has_stiff_interpolation,
_ode_addsteps!, DerivativeOrderNotPossibleError, set_discontinuity,
DIRK, COEFFICIENT_MULTISTEP, isnewton, set_new_W!,
find_algebraic_vars_eqs
import SciMLBase: alg_order, isadaptive, _unwrap_val
import DiffEqBase: calculate_residuals, calculate_residuals!, initialize!
using OrdinaryDiffEqSDIRK: ESDIRKIMEXConstantCache, ESDIRKIMEXCache,
ImplicitEulerESDIRKIMEXTableau
using TruncatedStacktraces: @truncate_stacktrace
using MuladdMacro: @muladd
using FastBroadcast: @..
using RecursiveArrayTools: recursivefill!
using LinearAlgebra: mul!, I, Diagonal
import ArrayInterface
import OrdinaryDiffEqCore
import OrdinaryDiffEqCore: default_controller
@static if Base.pkgversion(OrdinaryDiffEqCore) >= v"3.10"
@eval begin
import OrdinaryDiffEqCore: get_current_qmax
end
else
@eval begin
# Fallback for older OrdinaryDiffEqCore: no first-step qmax behavior
@inline get_current_qmax(integrator, qmax) = qmax
end
end
using OrdinaryDiffEqNonlinearSolve: NLNewton, du_alias_or_new, build_nlsolver,
nlsolve!, nlsolvefail, markfirststage!
import ADTypes: AutoForwardDiff
using Reexport: Reexport, @reexport
import SciMLBase
using SciMLBase: ODEProblem, ODEFunction, derivative_discontinuity!, solve
@reexport using SciMLBase
include("algorithms.jl")
include("alg_utils.jl")
include("bdf_utils.jl")
include("stald.jl")
include("nordsieck_utils.jl")
include("bdf_caches.jl")
include("dae_caches.jl")
include("controllers.jl")
include("dae_perform_step.jl")
include("bdf_perform_step.jl")
include("interp_func.jl")
include("bdf_interpolants.jl")
include("stiff_addsteps.jl")
import PrecompileTools
import Preferences
# Index-1 mass matrix DAE (Robertson). The pure-ODE problems in the workload below
# never reach the algebraic variable detection or the DAE initialization solve, so
# without this every mass matrix FBDF user pays that inference at first solve.
function precompile_mm_dae(du, u, p, t)
du[1] = -0.04u[1] + 1.0e4 * u[2] * u[3]
du[2] = 0.04u[1] - 3.0e7 * u[2]^2 - 1.0e4 * u[2] * u[3]
return du[3] = u[1] + u[2] + u[3] - 1.0
end
PrecompileTools.@compile_workload begin
lorenz = OrdinaryDiffEqCore.lorenz
lorenz_oop = OrdinaryDiffEqCore.lorenz_oop
solver_list = [FBDF(), NordsieckBDF()]
prob_list = []
if Preferences.@load_preference("PrecompileDefaultSpecialize", true)
push!(prob_list, ODEProblem(lorenz, [1.0; 0.0; 0.0], (0.0, 1.0)))
push!(prob_list, ODEProblem(lorenz, [1.0; 0.0; 0.0], (0.0, 1.0), Float64[]))
end
if Preferences.@load_preference("PrecompileMassMatrixDAE", true)
mm_dae = ODEFunction(
precompile_mm_dae, mass_matrix = Diagonal([1.0, 1.0, 0.0])
)
push!(prob_list, ODEProblem(mm_dae, [1.0, 0.0, 0.0], (0.0, 1.0)))
push!(prob_list, ODEProblem(mm_dae, [1.0, 0.0, 0.0], (0.0, 1.0), Float64[]))
end
if Preferences.@load_preference("PrecompileAutoSpecialize", false)
push!(
prob_list,
ODEProblem{true, SciMLBase.AutoSpecialize}(
lorenz, [1.0; 0.0; 0.0],
(0.0, 1.0)
)
)
push!(
prob_list,
ODEProblem{true, SciMLBase.AutoSpecialize}(
lorenz, [1.0; 0.0; 0.0],
(0.0, 1.0), Float64[]
)
)
end
if Preferences.@load_preference("PrecompileAutoDePSpecialize", false)
push!(
prob_list,
ODEProblem{true, OrdinaryDiffEqCore.AutoDePSpecialize}(
OrdinaryDiffEqCore.lorenz_p, [1.0; 0.0; 0.0],
(0.0, 1.0), OrdinaryDiffEqCore.lorenz_p_params
)
)
push!(
prob_list,
ODEProblem{true, OrdinaryDiffEqCore.AutoDePSpecialize}(
OrdinaryDiffEqCore.lorenz_pref, [1.0; 0.0; 0.0],
(0.0, 1.0), OrdinaryDiffEqCore.lorenz_pref_params
)
)
end
if Preferences.@load_preference("PrecompileFunctionWrapperSpecialize", false)
push!(
prob_list,
ODEProblem{true, SciMLBase.FunctionWrapperSpecialize}(
lorenz, [1.0; 0.0; 0.0],
(0.0, 1.0)
)
)
push!(
prob_list,
ODEProblem{true, SciMLBase.FunctionWrapperSpecialize}(
lorenz, [1.0; 0.0; 0.0],
(0.0, 1.0), Float64[]
)
)
end
if Preferences.@load_preference("PrecompileNoSpecialize", false)
push!(
prob_list,
ODEProblem{true, SciMLBase.NoSpecialize}(lorenz, [1.0; 0.0; 0.0], (0.0, 1.0))
)
push!(
prob_list,
ODEProblem{true, SciMLBase.NoSpecialize}(
lorenz, [1.0; 0.0; 0.0], (0.0, 1.0),
Float64[]
)
)
end
for prob in prob_list, solver in solver_list
solve(prob, solver)(5.0)
end
prob_list = nothing
solver_list = nothing
end
export ABDF2, QNDF1, QBDF1, QNDF2, QBDF2, QNDF, QBDF, FBDF,
SBDF, SBDF2, SBDF3, SBDF4, MEBDF2, IMEXEuler, IMEXEulerARK,
DABDF2, DImplicitEuler, DFBDF,
NordsieckBDF, DNordsieckBDF
end