-
Notifications
You must be signed in to change notification settings - Fork 70
/
timeevolution.jl
218 lines (163 loc) · 7.78 KB
/
timeevolution.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
export timeevolution, BDF2,BDF4,BDF22
## Multivariate
function RK(L,y,h)
k1=L(y)
k2=L(y+.5h*k1)
k3=L(y+.5h*k2)
k4=L(y+h*k3)
y+h*(k1+2k2+2k3+k4)/6.
end
function BDF2(B,A::BandedOperator,g::Function,bcs,u0,h,m,glp,tol=1000eps())
SBDF2 = [B,I-2.0/3.0*h*A]
u1=u0
u2=chop(RK(g,u1,h),tol)
u2,u1 = chop(SBDF2\[bcs,1/3.0*(4u2-u1)],tol),u2
push!(glp,u2)
for k=1:m
u2,u1 = chop(RK(g,u2,h),tol),u2
u2,u1 = chop(SBDF2\[bcs,1/3.0*(4u2-u1)],tol),u2
push!(glp,u2)
end
u2
end
function BDF4(B::Vector,op::BandedOperator,bcs::Vector,uin::MultivariateFun,h::Real,m::Integer,glp)
nt=size(uin,2)
d=domain(uin)
SBE = discretize([B,I-h*op],d,nt) # backward euler for first 2 time steps
SBDF2 = discretize([B,I-2.0/3.0*h*op],d,nt) # BDF formula for subsequent itme steps
SBDF3 = discretize([B,I-6.0/11.0*h*op],d,nt) # BDF formula for subsequent itme steps
SBDF4 = discretize([B,I-12.0/25.0*h*op],d,nt) # BDF formula for subsequent itme steps
u1=uin
u2=SBE\[bcs,u1]
push!(glp,pad(u2,80,80))
u3=SBDF2\[bcs,1/3.0*(4u2-u1)]
push!(glp,pad(u3,80,80))#updates window
u4=SBDF3\[bcs,1/11.0*(18u3-9u2+2u1)]
push!(glp,pad(u4,80,80))#updates window
for k=1:m
u4,u3,u2,u1 = SBDF4\[bcs,1/25.0*(48u4-36u3+16u2-3u1)],u4,u3,u2
push!(glp,pad(u4,80,80))#updates window
end
u4
end
BDF4(B::Vector,op::BandedOperator,uin::MultivariateFun,h::Real,m::Integer,glp)=BDF4(B,op,zeros(length(B)),uin,h,m,glp)
function BDF22(B::Vector,op::BandedOperator,bcs::Vector,uin::@compat(Tuple{MultivariateFun,MultivariateFun}),h::Real,m::Integer,glp)
nt=size(uin[1],2)
SBE = discretize([B,I-h^2*op],domain(uin[1]),nt) # backward euler for first 2 time steps
SBDF = discretize([B,I-4.0/9.0*h^2*op],domain(uin[1]),nt) # BDF formula for subsequent itme steps
u1,u2=uin
u3 =SBE\[bcs,2u2-u1]
push!(glp,pad(u3,80,80))
u4 =SBE\[bcs,2u3-u2]
push!(glp,pad(u4,80,80))
for k=1:m
u4,u3,u2,u1 = SBDF\[bcs,1/9.0*(24u4-22u3+8u2-u1)],u4,u3,u2
push!(glp,pad(u4,80,80)) #updates window
end
u4
end
function BDF22(B::Vector,op::BandedOperator,g::Function,bcs::Vector,uin::@compat(Tuple{MultivariateFun,MultivariateFun}),h::Real,m::Integer,glp)
nt=size(uin[1],2)
SBE = discretize([B,I-h^2*op],domain(uin[1]),nt) # backward euler for first 2 time steps
SBDF = discretize([B,I-4.0/9.0*h^2*op],domain(uin[1]),nt) # BDF formula for subsequent itme steps
u1,u2=uin
u3 =SBE\[bcs,2u2-u1]
push!(glp,pad(u3,80,80))
u4,u3,u2,u1=u3,u2,u1,u1
for k=1:m
u4,u3,u2,u1 =2u4 - u3 +h^2*g(u4),u4,u3,u2
u4,u3,u2,u1 = SBDF\[bcs,1/9.0*(24u4-22u3+8u2-u1)],u4,u3,u2
push!(glp,pad(u4,80,80))
end
u4
end
BDF22(B::Vector,op::BandedOperator,uin::MultivariateFun,h::Real,m::Integer,glp)=BDF22(B,op,zeros(length(B)),(uin,uin),h,m,glp)
BDF22(B::Vector,op::BandedOperator,g::Function,uin::MultivariateFun,h::Real,m::Integer,glp)=BDF22(B,op,g,zeros(length(B)),(uin,uin),h,m,glp)
## GLPlot routines
#u_t = op*u
function timeevolution(B::Vector,op,bcs::Vector,uin::MultivariateFun,h::Real,m::Integer,glp)
require("GLPlot")
setplotter("GLPlot")
nt=size(uin,2)
d=domain(uin)
SBE = discretize([B,I-h*op],d,nt) # backward euler for first 2 time steps
SBDF2 = discretize([B,I-2.0/3.0*h*op],d,nt) # BDF formula for subsequent itme steps
SBDF3 = discretize([B,I-6.0/11.0*h*op],d,nt) # BDF formula for subsequent itme steps
SBDF4 = discretize([B,I-12.0/25.0*h*op],d,nt) # BDF formula for subsequent itme steps
u1=chop(uin,1000eps())
u2=chop(SBE\[bcs,u1],1000eps())
plot(pad(u2,80,80),glp...)#updates window
u3=chop(SBDF2\[bcs,1/3.0*(4u2-u1)],1000eps())
plot(pad(u3,80,80),glp...)#updates window
u4=chop(SBDF3\[bcs,1/11.0*(18u3-9u2+2u1)],1000eps())
plot(pad(u4,80,80),glp...)#updates window
for k=1:m
u4,u3,u2,u1 = chop(SBDF4\[bcs,1/25.0*(48u4-36u3+16u2-3u1)],1000eps()),u4,u3,u2
plot(pad(u4,80,80),glp...)#updates window
end
u4
end
function timeevolution(B::Vector,op,bcs::Vector,uin::MultivariateFun,h::Real,m=5000)
require("GLPlot")
setplotter("GLPlot")
timeevolution(B,op,bcs,uin,h,m,plot(pad(uin,80,80)))
end
timeevolution(B::Vector,op,uin::MultivariateFun,h::Real,dat...)=timeevolution(B,op,zeros(length(B)),uin,h,dat...)
timeevolution(B::BandedOperator,dat...)=timeevolution([B],dat...)
timeevolution(B::Vector,op,bcs::Vector,uin::Fun,dat...)=timeevolution(B,op,bcs,ProductFun(uin),dat...)
timeevolution(B::Vector,op,uin::Fun,dat...)=timeevolution(B,op,ProductFun(uin),dat...)
timeevolution(B::Operator,dat...)=timeevolution([B],dat...)
#u_tt = op*u
function timeevolution2(B::Vector,op,bcs::Vector,uin::@compat(Tuple{MultivariateFun,MultivariateFun}),h::Real,m::Integer,glp)
require("GLPlot")
setplotter("GLPlot")
nt=size(uin[1],2)
SBE = discretize([B,I-h^2*op],domain(uin[1]),nt) # backward euler for first 2 time steps
SBDF = discretize([B,I-4.0/9.0*h^2*op],domain(uin[1]),nt) # BDF formula for subsequent itme steps
u1,u2=chop(uin[1],1000eps()),chop(uin[2],1000eps())
u3 =chop(SBE\[bcs,2u2-u1],1000eps())
u4 =chop(SBE\[bcs,2u3-u2],1000eps())
for k=1:m
u4,u3,u2,u1 = chop(SBDF\[bcs,1/9.0*(24u4-22u3+8u2-u1)],1000eps()),u4,u3,u2
plot(pad(u4,80,80),glp...)#updates window
end
u4
end
#u_tt = op*u
function timeevolution2(B::Vector,op,g::Function,bcs::Vector,uin::@compat(Tuple{MultivariateFun,MultivariateFun}),h::Real,m::Integer,glp)
require("GLPlot")
setplotter("GLPlot")
nt=size(uin[1],2)
SBE = discretize([B,I-h^2*op],domain(uin[1]),nt) # backward euler for first 2 time steps
SBDF = discretize([B,I-4.0/9.0*h^2*op],domain(uin[1]),nt) # BDF formula for subsequent itme steps
u1,u2=chop(uin[1],1000eps()),chop(uin[2],1000eps())
u3 =chop(SBE\[bcs,2u2-u1],1000eps())
u4 =chop(2u3 - u2 +h^2*g(u3),1000eps())
u4,u3,u2,u1 = chop(SBDF\[bcs,1/9.0*(24u4-22u3+8u2-u1)],1000eps()),u4,u3,u2
plot(pad(u4,80,80),glp...)#updates window
for k=1:m
u4,u3,u2,u1 = chop(2u4 - u3 +h^2*g(u4),1000eps()),u4,u3,u2
u4,u3,u2,u1 = chop(SBDF\[bcs,1/9.0*(24u4-22u3+8u2-u1)],1000eps()),u4,u3,u2
plot(pad(u4,80,80),glp...)#updates window
end
u4
end
function timeevolution2(B::Vector,op,uin::@compat(Tuple{MultivariateFun,MultivariateFun}),bcs::Vector,h::Real,m=5000)
require("GLPlot")
setplotter("GLPlot")
timeevolution2(B,op,bcs,uin,h,m,plot(pad(uin[end],80,80)))
end
function timeevolution2(B::Vector,op,g::Function,uin::@compat(Tuple{MultivariateFun,MultivariateFun}),bcs::Vector,h::Real,m=5000)
require("GLPlot")
setplotter("GLPlot")
timeevolution2(B,op,g,bcs,uin,h,m,plot(pad(uin[end],80,80)))
end
timeevolution2(B::Vector,op,uin::@compat(Tuple{MultivariateFun,MultivariateFun}),h::Real,dat...)=timeevolution2(B,op,uin,zeros(length(B)),h,dat...)
timeevolution2(B::Vector,op,uin::MultivariateFun,dat...)=timeevolution2(B,op,(uin,uin),dat...)
timeevolution2(B::Operator,dat...)=timeevolution2([B],dat...)
timeevolution2(B::Vector,op,g::Function,uin::@compat(Tuple{MultivariateFun,MultivariateFun}),h::Real,dat...)=timeevolution2(B,op,g,uin,zeros(length(B)),h,dat...)
timeevolution2(B::Vector,op,g::Function,uin::MultivariateFun,dat...)=timeevolution2(B,op,g,(uin,uin),dat...)
timeevolution2(B::Vector,op,g::Function,uin::@compat(Tuple{Fun,Fun}),dat...)=timeevolution2(B,op,g,(ProductFun(uin[1]),ProductFun(uin[2])),dat...)
timeevolution2(B::Vector,op,g::Function,uin::Fun,dat...)=timeevolution2(B,op,g,ProductFun(uin),dat...)
timeevolution2(B::Vector,op,uin::Fun,dat...)=timeevolution2(B,op,ProductFun(uin),dat...)
timeevolution(o::Integer,dat...)=o==2?timeevolution2(dat...):timeevolution(dat...)