Line data Source code
1 : """
2 : y = advect(problem, t0, t1, y0)
3 :
4 : Solve `problem` for given initial conditions and return the final position of a
5 : particle at time `t1`.
6 :
7 : !!! note
8 : This method is a convenience wrapper to [`solve!`](@ref).
9 :
10 : !!! note
11 : `advect(p, t0, t1, y0)` silently returns `y0` *without warning* if `t0==t1`.
12 :
13 : !!! warning
14 : `advect` returns a (near) boundary position for [`state`](@Ref) `OutOfDomain`
15 : and raises an **error** for any failure state!
16 :
17 : See also [`problem`](@ref), [`solve!`](@ref)
18 : """
19 5577 : function advect(p::Problem{N, T, S, Dy, Out},
20 : t0::T, t1::T, y0::SVector{N, T}) where {N, T, S, Dy, Out}
21 5577 : (t0 == t1) && return y0
22 :
23 5319 : s = solve!(p, t0, t1, y0)
24 5436 : issuccess(s) || (s == OutOfDomain) || error("invalid state ", s)
25 5319 : pos(p)[2]
26 : end
27 :
28 1048 : function pathline(p::Problem{N, T, S, Dy, Out},
29 : t0::T, t1, y0::SVector{N, T}) where {N, T, S, Dy, Out}
30 1048 : sol = emptysolution(p)
31 1165 : pathline!(p, sol, t0, t1, y0)
32 1048 : sol
33 : end
34 :
35 2215 : function pathline!(p::Problem{N, T, S, Dy, Out},
36 : sol::Sol,
37 : t0::T, t1::T, y0::SVector{N, T};
38 : empty::Bool=true) where {N, T, S, Dy, Out, Sol}
39 1049 : empty && empty!(sol)
40 1049 : st = solve!(p, t0, t1, y0, pushinto(sol))
41 :
42 1049 : if st == OutOfDomain
43 117 : t, y, dy = pos(p)
44 234 : ismonotone(sol, t) && push!(sol, (t, y, dy))
45 : end
46 :
47 1049 : sol
48 : end
49 :
50 1 : function pathline!(p::Problem{N, T, S, Dy, Out},
51 : sol::Sol,
52 : t0::T, t12::Tuple{T, T},
53 : y0::SVector{N, T}) where {N, T, S, Dy, Out, Sol}
54 1 : tbackward, tforward = t12
55 1 : @assert tbackward <= t0 <= tforward
56 :
57 1 : pathline!(p, sol, t0, tbackward, y0)
58 2 : reverse!(sol)
59 1 : pathline!(p, sol, t0, tforward, y0; empty=false)
60 :
61 1 : sol
62 : end
63 :
64 : """
65 : solution = pathline(problem, t0, t1, y0)
66 :
67 : Generate pathline by [`solve!`](@ref)ing `problem` for povided
68 : initial conditions.
69 :
70 : solution = pathline(problem, t0, (t1, t2), y0)
71 :
72 : Generate pathline from *forward and backward* integration for
73 : `t1 < t0 < t2`.
74 :
75 : If the integration is stopped due to an `OutOfDomain` event,
76 : the stopping position is added to the solution at `t1` (and `t2`,
77 : respectively).
78 :
79 : !!! note
80 : `pathline` does not return the solver [`State`](@ref). Use
81 : `state(problem)`.
82 :
83 : See also [`pathline`](@Ref), [`problem`](@ref), [`solve!`](@ref)
84 :
85 : """ pathline
86 :
87 : """
88 : solution = emptysolution(problem)
89 : pathline!(problem, solution, t0, t1, y0[;empty=true])
90 : pathline!(problem, solution, t0, (t1, t2), y0[; empty=true])
91 :
92 : In-place version of [`pathline`](@ref) that mutates `solution`.
93 :
94 : If `!empty` the `solution` is used as is, and the integration appends
95 : data.
96 :
97 : See also [`pathline`](@Ref), [`problem`](@ref), [`solve!`](@ref)
98 : """ pathline!
|