@@ -103,93 +103,68 @@ end
103
103
@test view (L,0.1 ,1 )[1 ] == L[0.1 ,1 ]
104
104
105
105
L = LinearSpline (0 : 2 )
106
- B1 = L[ :,1 ]
106
+ B1 = view (L, :,1 )
107
107
@test B1 isa SubQuasiArray{Float64,1 }
108
108
@test size (B1) == (ℵ₁,)
109
109
@test B1[0.1 ] == L[0.1 ,1 ]
110
110
@test_throws BoundsError B1[2.2 ]
111
111
112
- B = L[ :,1 : 2 ]
112
+ B = view (L, :,1 : 2 )
113
113
@test B isa SubQuasiArray{Float64,2 }
114
114
@test B[0.1 ,:] == L[0.1 ,1 : 2 ]
115
115
116
- B = L[:,2 : end - 1 ]
116
+ B = @view L[:,2 : end - 1 ]
117
117
@test B[0.1 ,:] == [0.1 ]
118
118
end
119
119
120
- A = randn (4 ,4 )
121
- @which lastindex (A,2 )
122
120
123
- @time begin
124
- L = LinearSpline (range (0 ,stop= 1 ,length= 10 ))[:,2 : end - 1 ]
125
- D = Derivative (axes (L,1 ))
126
-
127
- D* L
128
-
129
- Derivative (0 .. 1 )* parent (L)
130
-
131
-
132
-
133
-
134
- M = Mul (D,L)
135
- A, B = M. factors
136
- axes (A,2 ) == axes (B,1 ) || throw (DimensionMismatch ())
137
- P = parent (B)
138
- (Derivative (axes (P,1 ))* P)[parentindices (P)... ]
139
-
140
- @which axes (D,2 )
141
-
142
- axes (D,2 )
143
- D* L
144
- A = - (L' D' D* L)
145
- f = L* exp .(L. points)
146
-
147
- A \ (L' f)
148
-
149
- u = A[2 : end - 1 ,2 : end - 1 ] \ (L' f)[2 : end - 1 ]
150
-
151
- cond (A[2 : end - 1 ,2 : end - 1 ])
152
-
153
- A[2 : end - 1 ,2 : end - 1 ] * u - (L' f)[2 : end - 1 ]
154
-
155
- v = L* [0 ; u; 0 ]
156
-
157
-
158
- v[0.2 ]
159
- using Plots
160
- plot (0 : 0.01 : 1 ,getindex .(Ref (v),0 : 0.01 : 1 ))
161
- plot! (u1)
162
- ui
163
-
164
- using ApproxFun
165
-
166
- x = Fun (0 .. 1 )
167
- u1 = [Dirichlet (Chebyshev (0 .. 1 )); ApproxFun. Derivative ()^ 2 ] \ [[0 ,0 ], exp (x)]
168
-
169
- plot (u1)
170
-
171
- u_ex = L* u1 .(L. points)
172
-
173
- xx = 0 : 0.01 : 1 ;
174
- plot (xx,getindex .(Ref (D* u_ex),xx))
121
+ @testset " Subindex of splines" begin
122
+ L = LinearSpline (range (0 ,stop= 1 ,length= 10 ))
123
+ @test L[:,2 : end - 1 ] isa Mul
124
+ @test_broken L[:,2 : end - 1 ][0.1 ,1 ] == L[0.1 ,2 ]
125
+ v = randn (8 )
126
+ f = L[:,2 : end - 1 ] * v
127
+ @test f[0.1 ] ≈ (L* [0 ; v; 0 ])[0.1 ]
128
+ end
175
129
176
- getindex .(Ref (D* u_ex),xx)
177
- plot! (u1' )
130
+ @testset " Poisson" begin
131
+ L = LinearSpline (range (0 ,stop= 1 ,length= 10 ))
132
+ B = L[:,2 : end - 1 ] # Zero dirichlet by dropping first and last spline
133
+ D = Derivative (axes (L,1 ))
134
+ Δ = - (B' D' D* B) # Weak Laplacian
178
135
179
- f[0.1 ]- exp (0.1 )
136
+ f = L* exp .(L. points) # project exp(x)
137
+ u = B * (Δ \ (B' f))
180
138
181
- (D* v)' * (D* v)
139
+ @test u[0.1 ] ≈ - 0.06612902692412974
140
+ end
182
141
183
142
143
+ @testset " Helmholtz" begin
144
+ L = LinearSpline (range (0 ,stop= 1 ,length= 10 ))
145
+ B = L[:,2 : end - 1 ] # Zero dirichlet by dropping first and last spline
146
+ D = Derivative (axes (L,1 ))
147
+ A = - (B' D' D* B) + 100 ^ 2 * B' B # Weak Laplacian
184
148
185
- L' f
149
+ f = L* exp .(L. points) # project exp(x)
150
+ u = B * (A \ (B' f))
186
151
152
+ @test u[0.1 ] ≈ 0.00012678835289369413
153
+ end
187
154
188
155
156
+ L = LinearSpline (range (0 ,stop= 1 ,length= 20_000_000 ))
157
+ B = L[:,2 : end - 1 ] # Zero dirichlet by dropping first and last spline
189
158
159
+ k = 10_000
160
+ @time A = - (B' D' D* B) + k^ 2 * B' B # Weak Helmholtz, 9s
161
+ @time f = L* exp .(L. points) # project exp(x), 0.3s
162
+ @time u = B * (A \ (B' f)) # solution, 4s
190
163
191
- (L' f)
192
164
193
- (L' f)
165
+ # Compare with "exact" solution
166
+ using Plots, ApproxFun
194
167
195
- end
168
+ x = Fun (axes (L,1 ))
169
+ u_ex = [Dirichlet (Chebyshev (0 .. 1 )); ApproxFun. Derivative ()^ 2 + k^ 2 * I] \ [[0 ,0 ], exp (x)]
170
+ @test u[0.1 ] ≈ u_ex (0.1 ) rtol = 1E-3
0 commit comments