Last active
June 28, 2021 09:37
-
-
Save j-fu/b2bf4ae92f5619199ca51865d12c234f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module mwe | |
using RecursiveArrayTools | |
abstract type AbstractTransientSolution{T,N,A,B} <: AbstractDiffEqArray{T, N, A} end | |
mutable struct TransientSolution{T,N,A,B} <: AbstractTransientSolution{T,N,A,B} | |
u::A | |
t::B | |
end | |
TransientSolution(vec::AbstractVector{T}, ts, ::NTuple{N}) where {T, N} = TransientSolution{eltype(T), N, typeof(vec), typeof(ts)}(vec, ts) | |
TransientSolution(vec::AbstractVector,ts::AbstractVector) = TransientSolution(vec, ts, (size(vec[1])..., length(vec))) | |
Base.append!(s::TransientSolution,t::Real,sol::AbstractArray)=push!(s.t,t), push!(s.u,copy(sol)) | |
function TransientSolution(t0::Number,inival::AbstractArray{T}) where T | |
TransientSolution([copy(inival)], [t0]) | |
end | |
function make_transientsol(;nt=10,M=3,N=20) | |
makevec(k)=[ k+i*j for i=1:M,j=1:N] | |
sol=TransientSolution([makevec(0)], [0]) | |
for k=1:nt | |
append!(sol,k,makevec(k)) | |
end | |
sol | |
end | |
function main() | |
s=make_transientsol() | |
s[1,:,1] | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20-element Vector{Int64}: | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11-element Vector{Vector{Int64}}: | |
[1, 2, 3] | |
[2, 3, 4] | |
[3, 4, 5] | |
[4, 5, 6] | |
[5, 6, 7] | |
[6, 7, 8] | |
[7, 8, 9] | |
[8, 9, 10] | |
[9, 10, 11] | |
[10, 11, 12] | |
[11, 12, 13] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment