|
1 |
| -@muladd function perform_step!(integrator, |
2 |
| - cache::Union{ISSEMConstantCache, |
3 |
| - ISSEulerHeunConstantCache}) |
4 |
| - @unpack t,dt,uprev,u,p,f = integrator |
| 1 | +@muladd function perform_step!(integrator, cache::Union{ISSEMConstantCache, ISSEulerHeunConstantCache}) |
| 2 | + |
| 3 | + @unpack t, dt, uprev, u, p, f = integrator |
5 | 4 | @unpack nlsolver = cache
|
6 | 5 | alg = unwrap_alg(integrator, true)
|
7 | 6 | theta = alg.theta
|
8 |
| - alg.symplectic ? a = dt/2 : a = theta*dt |
| 7 | + alg.symplectic ? a = dt / 2 : a = theta * dt |
9 | 8 | OrdinaryDiffEq.markfirststage!(nlsolver)
|
10 | 9 |
|
11 | 10 | # TODO: Stochastic extrapolants?
|
12 | 11 | u = uprev
|
13 | 12 |
|
14 | 13 | repeat_step = false
|
15 | 14 |
|
16 |
| - L = integrator.g(uprev,p,t) |
17 |
| - ftmp = integrator.f(uprev,p,t) |
| 15 | + L = integrator.g(uprev, p, t) |
| 16 | + ftmp = integrator.f(uprev, p, t) |
18 | 17 |
|
19 | 18 | if alg.symplectic
|
20 | 19 | z = zero(u) # constant extrapolation, justified by ODE IM
|
21 | 20 | else
|
22 |
| - z = dt*ftmp # linear extrapolation |
| 21 | + z = dt * ftmp # linear extrapolation |
23 | 22 | end
|
24 | 23 | nlsolver.z = z
|
25 | 24 |
|
|
29 | 28 | #u = uprev + z/2
|
30 | 29 | tmp = uprev
|
31 | 30 | else
|
32 |
| - tmp = uprev + dt*(1-theta)*ftmp |
| 31 | + tmp = uprev + dt * (1 - theta) * ftmp |
33 | 32 | end
|
34 | 33 | nlsolver.tmp = tmp
|
35 | 34 |
|
|
39 | 38 | if alg.symplectic
|
40 | 39 | u = tmp + z
|
41 | 40 | else
|
42 |
| - u = tmp + theta*z |
| 41 | + u = tmp + theta * z |
43 | 42 | end
|
44 | 43 |
|
45 |
| - gtmp = L.*integrator.W.dW |
| 44 | + if !is_diagonal_noise(integrator.sol.prob) |
| 45 | + gtmp = L * integrator.W.dW |
| 46 | + else |
| 47 | + gtmp = L .* integrator.W.dW |
| 48 | + end |
46 | 49 |
|
47 | 50 | if typeof(cache) <: ISSEulerHeunConstantCache
|
48 | 51 | utilde = u + gtmp
|
49 |
| - gtmp = ((integrator.g(utilde,p,t) + L)/2)*integrator.W.dW |
| 52 | + if !is_diagonal_noise(integrator.sol.prob) |
| 53 | + gtmp = ((integrator.g(utilde, p, t) + L) / 2) * integrator.W.dW |
| 54 | + else |
| 55 | + gtmp = ((integrator.g(utilde, p, t) + L) / 2) .* integrator.W.dW |
| 56 | + end |
50 | 57 | end
|
51 | 58 |
|
52 | 59 | u += gtmp
|
53 | 60 |
|
54 | 61 | if integrator.opts.adaptive
|
55 | 62 | if has_Wfact(f)
|
56 | 63 | # This means the Jacobian was never computed!
|
57 |
| - J = f.jac(uprev,p,t) |
| 64 | + J = f.jac(uprev, p, t) |
58 | 65 | else
|
59 | 66 | J = OrdinaryDiffEq.calc_J(integrator, nlsolver.cache)
|
60 | 67 | end
|
61 |
| - Ed = dt*(dt*J*ftmp)/2 |
| 68 | + Ed = dt * (dt * J * ftmp) / 2 |
62 | 69 |
|
63 | 70 | if typeof(cache) <: ISSEMConstantCache
|
64 | 71 | K = @.. uprev + dt * ftmp
|
65 |
| - utilde = @.. K + integrator.sqdt * L |
66 |
| - ggprime = (integrator.g(utilde,p,t).-L)./(integrator.sqdt) |
67 |
| - En = ggprime .* (integrator.W.dW.^2 .- dt)./2 |
| 72 | + utilde = @.. K + integrator.sqdt * L |
| 73 | + ggprime = (integrator.g(utilde, p, t) .- L) ./ (integrator.sqdt) |
| 74 | + if !is_diagonal_noise(integrator.sol.prob) |
| 75 | + En = ggprime * (integrator.W.dW .^ 2 .- dt) ./ 2 |
| 76 | + else |
| 77 | + En = ggprime .* (integrator.W.dW .^ 2 .- dt) ./ 2 |
| 78 | + end |
68 | 79 | elseif typeof(cache) <: ISSEulerHeunConstantCache
|
69 |
| - utilde = uprev + L*integrator.sqdt |
70 |
| - ggprime = (integrator.g(utilde,p,t).-L)./(integrator.sqdt) |
71 |
| - En = ggprime.*(integrator.W.dW.^2)./2 |
| 80 | + utilde = @.. uprev + L * integrator.sqdt |
| 81 | + ggprime = (integrator.g(utilde, p, t) .- L) ./ (integrator.sqdt) |
| 82 | + if !is_diagonal_noise(integrator.sol.prob) |
| 83 | + En = ggprime * (integrator.W.dW .^ 2) ./ 2 |
| 84 | + else |
| 85 | + En = ggprime .* (integrator.W.dW .^ 2) ./ 2 |
| 86 | + end |
72 | 87 | end
|
73 | 88 |
|
74 | 89 | resids = calculate_residuals(Ed, En, uprev, u, integrator.opts.abstol,
|
75 |
| - integrator.opts.reltol, integrator.opts.delta, |
76 |
| - integrator.opts.internalnorm,t) |
77 |
| - integrator.EEst = integrator.opts.internalnorm(resids,t) |
| 90 | + integrator.opts.reltol, integrator.opts.delta, |
| 91 | + integrator.opts.internalnorm, t) |
| 92 | + integrator.EEst = integrator.opts.internalnorm(resids, t) |
78 | 93 | end
|
79 | 94 |
|
80 | 95 | integrator.u = u
|
81 | 96 | end
|
82 | 97 |
|
83 |
| -@muladd function perform_step!(integrator, cache::Union{ISSEMCache, |
84 |
| - ISSEulerHeunCache}) |
85 |
| - @unpack t,dt,uprev,u,p,f = integrator |
86 |
| - @unpack gtmp,gtmp2,dW_cache,nlsolver,k,dz = cache |
87 |
| - @unpack z,tmp = nlsolver |
| 98 | +@muladd function perform_step!(integrator, cache::Union{ISSEMCache, ISSEulerHeunCache}) |
| 99 | + @unpack t, dt, uprev, u, p, f = integrator |
| 100 | + @unpack gtmp, gtmp2, dW_cache, nlsolver, k, dz = cache |
| 101 | + @unpack z, tmp = nlsolver |
88 | 102 |
|
89 | 103 | J = (OrdinaryDiffEq.isnewton(nlsolver) ? nlsolver.cache.J : nothing)
|
90 | 104 | alg = unwrap_alg(integrator, true)
|
91 |
| - alg.symplectic ? a = dt/2 : a = alg.theta*dt |
| 105 | + alg.symplectic ? a = dt / 2 : a = alg.theta * dt |
92 | 106 | dW = integrator.W.dW
|
93 | 107 | mass_matrix = integrator.f.mass_matrix
|
94 | 108 | theta = alg.theta
|
|
97 | 111 | repeat_step = false
|
98 | 112 |
|
99 | 113 | if integrator.success_iter > 0 && !integrator.u_modified && alg.extrapolant == :interpolant
|
100 |
| - current_extrapolant!(u,t+dt,integrator) |
| 114 | + current_extrapolant!(u, t + dt, integrator) |
101 | 115 | elseif alg.extrapolant == :linear
|
102 |
| - @.. u = uprev + integrator.fsalfirst*dt |
| 116 | + @.. u = uprev + integrator.fsalfirst * dt |
103 | 117 | else # :constant
|
104 |
| - copyto!(u,uprev) |
| 118 | + copyto!(u, uprev) |
105 | 119 | end
|
106 | 120 |
|
107 |
| - integrator.f(tmp,uprev,p,t) |
| 121 | + integrator.f(tmp, uprev, p, t) |
108 | 122 | integrator.g(gtmp, uprev, p, t)
|
109 | 123 |
|
110 | 124 | if alg.symplectic
|
111 | 125 | @.. z = zero(eltype(u)) # Justified by ODE solvers, constrant extrapolation when IM
|
112 | 126 | else
|
113 |
| - @.. z = dt*tmp # linear extrapolation |
| 127 | + @.. z = dt * tmp # linear extrapolation |
| 128 | + end |
| 129 | + |
| 130 | + # Handle noise computations |
| 131 | + |
| 132 | + if is_diagonal_noise(integrator.sol.prob) |
| 133 | + @.. gtmp2 = gtmp * dW |
| 134 | + else |
| 135 | + mul!(gtmp2, gtmp, dW) |
114 | 136 | end
|
115 | 137 |
|
116 | 138 | ###
|
|
144 | 166 | if typeof(cache) <: ISSEMCache
|
145 | 167 |
|
146 | 168 | if !is_diagonal_noise(integrator.sol.prob)
|
147 |
| - integrator.g(gtmp2, z, p, t) |
148 |
| - g_sized2 = norm(gtmp2, 2) |
| 169 | + integrator.g(gtmp, z, p, t) |
| 170 | + g_sized2 = norm(gtmp, 2) |
149 | 171 | @.. dW_cache = dW .^ 2 - dt
|
150 | 172 | diff_tmp = integrator.opts.internalnorm(dW_cache, t)
|
151 | 173 | En = (g_sized2 - g_sized) / (2integrator.sqdt) * diff_tmp
|
|
191 | 213 | end
|
192 | 214 |
|
193 | 215 | ##############################################################################
|
194 |
| - |
195 |
| - # Handle noise computations |
196 |
| - |
197 |
| - if is_diagonal_noise(integrator.sol.prob) |
198 |
| - @.. gtmp2 = gtmp * dW |
199 |
| - else |
200 |
| - mul!(gtmp2, gtmp, dW) |
201 |
| - end |
202 |
| - |
203 | 216 | if typeof(cache) <: ISSEulerHeunCache
|
204 | 217 | gtmp3 = cache.gtmp3
|
205 |
| - @.. z = uprev + gtmp2 |
| 218 | + @.. z = u + gtmp2 |
206 | 219 | integrator.g(gtmp3, z, p, t)
|
207 | 220 | @.. gtmp = (gtmp3 + gtmp) / 2
|
208 | 221 | if is_diagonal_noise(integrator.sol.prob)
|
|
211 | 224 | mul!(gtmp2, gtmp, dW)
|
212 | 225 | end
|
213 | 226 | end
|
214 |
| - |
215 | 227 | @.. u += gtmp2
|
216 | 228 |
|
217 | 229 | ##############################################################################
|
|
0 commit comments