|
1 | 1 | function Φ!(residual, cache::FIRKCacheExpand, y, u, trait, constraint) |
2 | 2 | return Φ!( |
3 | 3 | residual, cache.fᵢ_cache, cache.k_discrete, cache.f, cache.TU, y, u, cache.p, |
4 | | - cache.mesh, cache.mesh_dt, cache.stage, cache.f_prototype, trait, constraint |
| 4 | + cache.mesh, cache.mesh_dt, cache.stage, cache.f_prototype, cache.singular_term, trait, constraint |
5 | 5 | ) |
6 | 6 | end |
7 | 7 |
|
|
14 | 14 |
|
15 | 15 | @views function Φ!( |
16 | 16 | residual, fᵢ_cache, k_discrete, f!, TU::FIRKTableau{false}, y, u, p, |
17 | | - mesh, mesh_dt, stage::Int, f_prototype, ::DiffCacheNeeded, ::Val{true} |
| 17 | + mesh, mesh_dt, stage::Int, f_prototype, singular_term, ::DiffCacheNeeded, ::Val{true} |
18 | 18 | ) |
19 | 19 | (; c, a, b) = TU |
20 | 20 | L_f_prototype = length(f_prototype) |
|
59 | 59 |
|
60 | 60 | @views function Φ!( |
61 | 61 | residual, fᵢ_cache, k_discrete, f!, TU::FIRKTableau{false}, y, u, p, |
62 | | - mesh, mesh_dt, stage::Int, f_prototype, ::DiffCacheNeeded, ::Val{false} |
| 62 | + mesh, mesh_dt, stage::Int, _, singular_term, ::DiffCacheNeeded, ::Val{false} |
63 | 63 | ) |
64 | 64 | (; c, a, b) = TU |
65 | 65 | tmp1 = get_tmp(fᵢ_cache, u) |
|
81 | 81 | for r in 1:stage |
82 | 82 | @. tmp1 = yᵢ |
83 | 83 | __maybe_matmul!(tmp1, K, a[:, r], h, T(1)) |
84 | | - f!(residual[ctr + r], tmp1, p, mesh[i] + c[r] * h) |
| 84 | + t = mesh[i] + c[r] * h |
| 85 | + f!(residual[ctr + r], tmp1, p, t) |
| 86 | + __add_singular_term!(residual[ctr + r], singular_term, tmp1, t) |
85 | 87 | residual[ctr + r] .-= K[:, r] |
86 | 88 | end |
87 | 89 |
|
|
95 | 97 |
|
96 | 98 | @views function Φ!( |
97 | 99 | residual, fᵢ_cache, k_discrete, f!, TU::FIRKTableau{false}, y, u, p, mesh, |
98 | | - mesh_dt, stage::Int, f_prototype, ::NoDiffCacheNeeded, ::Val{false} |
| 100 | + mesh_dt, stage::Int, _, singular_term, ::NoDiffCacheNeeded, ::Val{false} |
99 | 101 | ) |
100 | 102 | (; c, a, b) = TU |
101 | 103 | tmp1 = similar(fᵢ_cache) |
|
117 | 119 | for r in 1:stage |
118 | 120 | @. tmp1 = yᵢ |
119 | 121 | __maybe_matmul!(tmp1, K, a[:, r], h, T(1)) |
120 | | - f!(residual[ctr + r], tmp1, p, mesh[i] + c[r] * h) |
| 122 | + t = mesh[i] + c[r] * h |
| 123 | + f!(residual[ctr + r], tmp1, p, t) |
| 124 | + __add_singular_term!(residual[ctr + r], singular_term, tmp1, t) |
121 | 125 | residual[ctr + r] .-= K[:, r] |
122 | 126 | end |
123 | 127 |
|
|
266 | 270 | function Φ(cache::FIRKCacheExpand, y, u, trait) |
267 | 271 | return Φ( |
268 | 272 | cache.fᵢ_cache, cache.k_discrete, cache.f, cache.TU, y, u, |
269 | | - cache.p, cache.mesh, cache.mesh_dt, cache.stage, trait |
| 273 | + cache.p, cache.mesh, cache.mesh_dt, cache.stage, cache.singular_term, trait |
270 | 274 | ) |
271 | 275 | end |
272 | 276 |
|
|
279 | 283 |
|
280 | 284 | @views function Φ( |
281 | 285 | fᵢ_cache, k_discrete, f, TU::FIRKTableau{false}, y, |
282 | | - u, p, mesh, mesh_dt, stage::Int, ::DiffCacheNeeded |
| 286 | + u, p, mesh, mesh_dt, stage::Int, singular_term, ::DiffCacheNeeded |
283 | 287 | ) |
284 | 288 | (; c, a, b) = TU |
285 | 289 | residuals = [safe_similar(yᵢ) for yᵢ in y[1:(end - 1)]] |
|
302 | 306 | for r in 1:stage |
303 | 307 | @. tmp1 = yᵢ |
304 | 308 | __maybe_matmul!(tmp1, K, a[:, r], h, T(1)) |
305 | | - residuals[ctr + r] = f(tmp1, p, mesh[i] + c[r] * h) |
| 309 | + t = mesh[i] + c[r] * h |
| 310 | + residuals[ctr + r] = f(tmp1, p, t) |
| 311 | + __add_singular_term!(residuals[ctr + r], singular_term, tmp1, t) |
306 | 312 | residuals[ctr + r] .-= K[:, r] |
307 | 313 | end |
308 | 314 |
|
|
317 | 323 |
|
318 | 324 | @views function Φ( |
319 | 325 | fᵢ_cache, k_discrete, f, TU::FIRKTableau{false}, y, |
320 | | - u, p, mesh, mesh_dt, stage::Int, ::NoDiffCacheNeeded |
| 326 | + u, p, mesh, mesh_dt, stage::Int, singular_term, ::NoDiffCacheNeeded |
321 | 327 | ) |
322 | 328 | (; c, a, b) = TU |
323 | 329 | residuals = [safe_similar(yᵢ) for yᵢ in y[1:(end - 1)]] |
|
340 | 346 | for r in 1:stage |
341 | 347 | @. tmp1 = yᵢ |
342 | 348 | __maybe_matmul!(tmp1, K, a[:, r], h, T(1)) |
343 | | - residuals[ctr + r] = f(tmp1, p, mesh[i] + c[r] * h) |
| 349 | + t = mesh[i] + c[r] * h |
| 350 | + residuals[ctr + r] = f(tmp1, p, t) |
| 351 | + __add_singular_term!(residuals[ctr + r], singular_term, tmp1, t) |
344 | 352 | residuals[ctr + r] .-= K[:, r] |
345 | 353 | end |
346 | 354 |
|
|
0 commit comments