|
56 | 56 | backward_sync_subintegrator!(parent, child, idxs, sync) |
57 | 57 | end |
58 | 58 | end |
| 59 | + |
| 60 | +# --------------------------------------------------------------------------- |
| 61 | +# Strang-Marchuk operator splitting |
| 62 | +# --------------------------------------------------------------------------- |
| 63 | +""" |
| 64 | + StrangMarchuk <: AbstractOperatorSplittingAlgorithm |
| 65 | +
|
| 66 | +Second-order symmetric (palindromic) operator splitting algorithm attributed to |
| 67 | +[Str:1968:ccd,Mar:1971:tsm](@cite). |
| 68 | +
|
| 69 | +For ``N`` operators the scheme performs |
| 70 | +
|
| 71 | +``A_1(\\Delta t/2) \\to \\cdots \\to A_{N-1}(\\Delta t/2) \\to A_N(\\Delta t) \\to A_{N-1}(\\Delta t/2) \\to \\cdots \\to A_1(\\Delta t/2)`` |
| 72 | +
|
| 73 | +achieving second-order accuracy through symmetry. |
| 74 | +""" |
| 75 | +struct StrangMarchuk{AlgTupleType} <: AbstractOperatorSplittingAlgorithm |
| 76 | + inner_algs::AlgTupleType # Tuple of timesteppers for inner problems |
| 77 | +end |
| 78 | + |
| 79 | +function Base.show(io::IO, alg::StrangMarchuk) |
| 80 | + print(io, "SM (") |
| 81 | + for inner_alg in alg.inner_algs[1:(end - 1)] |
| 82 | + Base.show(io, inner_alg) |
| 83 | + print(io, " -> ") |
| 84 | + end |
| 85 | + length(alg.inner_algs) > 0 && Base.show(io, alg.inner_algs[end]) |
| 86 | + return print(io, ")") |
| 87 | +end |
| 88 | + |
| 89 | +struct StrangMarchukCache{uType, uprevType} <: AbstractOperatorSplittingCache |
| 90 | + u::uType |
| 91 | + uprev::uprevType |
| 92 | +end |
| 93 | + |
| 94 | +function init_cache( |
| 95 | + f::GenericSplitFunction, alg::StrangMarchuk; |
| 96 | + uprev::AbstractArray, u::AbstractVector, |
| 97 | + ) |
| 98 | + return StrangMarchukCache(u, uprev) |
| 99 | +end |
| 100 | + |
| 101 | +# Forward pass: A₁(dt/2) → … → Aₙ₋₁(dt/2) → Aₙ(dt) |
| 102 | +@unroll function _sm_forward_pass!(parent, children::Tuple, half_dt, dt) |
| 103 | + N = length(children) |
| 104 | + i = 0 |
| 105 | + @unroll for child in children |
| 106 | + i += 1 |
| 107 | + step_dt = i < N ? half_dt : dt |
| 108 | + |
| 109 | + idxs = parent.child_solution_indices[i] |
| 110 | + sync = parent.child_synchronizers[i] |
| 111 | + |
| 112 | + @timeit_debug "sync ->" forward_sync_subintegrator!(parent, child, idxs, sync) |
| 113 | + @timeit_debug "time solve" advance_solution_by!(parent, child, step_dt) |
| 114 | + if _child_failed(child) |
| 115 | + parent.force_stepfail = true |
| 116 | + return |
| 117 | + end |
| 118 | + |
| 119 | + backward_sync_subintegrator!(parent, child, idxs, sync) |
| 120 | + end |
| 121 | +end |
| 122 | + |
| 123 | +# Reverse pass: Aₙ₋₁(dt/2) → … → A₁(dt/2) |
| 124 | +@unroll function _sm_reverse_pass!(parent, rev_front::Tuple, half_dt, N) |
| 125 | + j = 0 |
| 126 | + @unroll for child in rev_front |
| 127 | + j += 1 |
| 128 | + i = N - j |
| 129 | + |
| 130 | + idxs = parent.child_solution_indices[i] |
| 131 | + sync = parent.child_synchronizers[i] |
| 132 | + |
| 133 | + @timeit_debug "sync ->" forward_sync_subintegrator!(parent, child, idxs, sync) |
| 134 | + @timeit_debug "time solve" advance_solution_by!(parent, child, half_dt) |
| 135 | + if _child_failed(child) |
| 136 | + parent.force_stepfail = true |
| 137 | + return |
| 138 | + end |
| 139 | + |
| 140 | + backward_sync_subintegrator!(parent, child, idxs, sync) |
| 141 | + end |
| 142 | +end |
| 143 | + |
| 144 | +function _perform_step!( |
| 145 | + parent, |
| 146 | + children::Tuple, |
| 147 | + cache::StrangMarchukCache, |
| 148 | + dt |
| 149 | + ) |
| 150 | + half_dt = dt / 2 |
| 151 | + |
| 152 | + _sm_forward_pass!(parent, children, half_dt, dt) |
| 153 | + parent.force_stepfail && return |
| 154 | + |
| 155 | + _sm_reverse_pass!(parent, reverse(children[1:(end - 1)]), half_dt, length(children)) |
| 156 | + parent.force_stepfail && return |
| 157 | + |
| 158 | + return |
| 159 | +end |
0 commit comments