@@ -17,9 +17,6 @@ checkbounds(A::AbstractDerivativeOperator, k::Colon, j::Integer) =
1717checkbounds (A:: AbstractDerivativeOperator , k:: Integer , j:: Colon ) =
1818 (0 < k ≤ size (A, 1 ) || throw (BoundsError (A, (k,size (A,2 )))))
1919
20-
21- # BandedMatrix{A,B,C,D}(A::DerivativeOperator{A,B,C,D}) = BandedMatrix(convert(Array, A, A.stencil_length), A.stencil_length, div(A.stencil_length,2), div(A.stencil_length,2))
22-
2320# ~~ getindex ~~
2421@inline function getindex (A:: AbstractDerivativeOperator , i:: Int , j:: Int )
2522 @boundscheck checkbounds (A, i, j)
113110 end
114111end
115112
116- #=
117- This the basic mul! function which is broken up into 3 parts ie. handling the left
118- boundary, handling the interior and handling the right boundary. Finally the vector is
119- scaled appropriately according to the derivative order and the degree of discretizaiton.
120- We also update the time stamp of the DerivativeOperator inside to manage time dependent
121- boundary conditions.
122- =#
123- function LinearAlgebra. mul! (x_temp:: AbstractVector{T} , A:: Union{DerivativeOperator{T},UpwindOperator{T}} , x:: AbstractVector{T} ) where T<: Real
124- convolve_BC_left! (x_temp, x, A)
125- convolve_interior! (x_temp, x, A)
126- convolve_BC_right! (x_temp, x, A)
127- rmul! (x_temp, @. (1 / (A. dx^ A. derivative_order)))
128- A. t[] += 1 # incrementing the internal time stamp
129- end
130-
131113#=
132114 This definition of the mul! function makes it possible to apply the LinearOperator on
133115 a matrix and not just a vector. It basically transforms the rows one at a time.
@@ -159,58 +141,6 @@ Base.transpose(A::Union{DerivativeOperator,UpwindOperator}) = A
159141Base. adjoint (A:: Union{DerivativeOperator,UpwindOperator} ) = A
160142LinearAlgebra. issymmetric (:: Union{DerivativeOperator,UpwindOperator} ) = true
161143
162- #=
163- This function ideally should give us a matrix which when multiplied with the input vector
164- returns the derivative. But the presence of different boundary conditons complicates the
165- situation. It is not possible to incorporate the full information of the boundary conditions
166- in the matrix as they are additive in nature. So in this implementation we will just
167- return the inner stencil of the matrix transformation. The user will have to manually
168- incorporate the BCs at the ends.
169- =#
170- function Base. convert (:: Type{Array} , A:: AbstractDerivativeOperator{T} , N:: Int = A. dimension) where T
171- @assert N >= A. stencil_length # stencil must be able to fit in the matrix
172- mat = zeros (T, (N, N))
173- v = zeros (T, N)
174- for i= 1 : N
175- v[i] = one (T)
176- #=
177- calculating the effect on a unit vector to get the matrix of transformation
178- to get the vector in the new vector space.
179- =#
180- mul! (view (mat,:,i), A, v)
181- v[i] = zero (T)
182- end
183- return mat
184- end
185-
186-
187- #=
188- This function ideally should give us a matrix which when multiplied with the input vector
189- returns the derivative. But the presence of different boundary conditons complicates the
190- situation. It is not possible to incorporate the full information of the boundary conditions
191- in the matrix as they are additive in nature. So in this implementation we will just
192- return the inner stencil of the matrix transformation. The user will have to manually
193- incorporate the BCs at the ends.
194- =#
195- function SparseArrays. sparse (A:: AbstractDerivativeOperator{T} ) where T
196- N = A. dimension
197- mat = spzeros (T, N, N)
198- v = zeros (T, N)
199- row = zeros (T, N)
200- for i= 1 : N
201- v[i] = one (T)
202- #=
203- calculating the effect on a unit vector to get the matrix of transformation
204- to get the vector in the new vector space.
205- =#
206- mul! (row, A, v)
207- copyto! (view (mat,:,i), row)
208- @. row = 0 * row;
209- v[i] = zero (T)
210- end
211- return mat
212- end
213-
214144#=
215145 Fallback methods that use the full representation of the operator
216146=#
@@ -219,3 +149,51 @@ Base.:\(A::AbstractVecOrMat, B::AbstractDerivativeOperator) = A \ convert(Array,
219149Base.:\ (A:: AbstractDerivativeOperator , B:: AbstractVecOrMat ) = convert (Array,A) \ B
220150Base.:/ (A:: AbstractVecOrMat , B:: AbstractDerivativeOperator ) = A / convert (Array,B)
221151Base.:/ (A:: AbstractDerivativeOperator , B:: AbstractVecOrMat ) = convert (Array,A) / B
152+
153+ # #######################################################################
154+
155+ # Are these necessary?
156+
157+ get_type (:: AbstractDerivativeOperator{T} ) where {T} = T
158+
159+ function * (A:: AbstractDerivativeOperator ,x:: AbstractVector )
160+ #=
161+ We will output a vector which is a supertype of the types of A and x
162+ to ensure numerical stability
163+ =#
164+ get_type (A) != eltype (x) ? error (" DiffEqOperator and array are not of same type!" ) : nothing
165+ y = zeros (promote_type (eltype (A),eltype (x)), length (x))
166+ LinearAlgebra. mul! (y, A:: AbstractDerivativeOperator , x:: AbstractVector )
167+ return y
168+ end
169+
170+
171+ function * (A:: AbstractDerivativeOperator ,M:: AbstractMatrix )
172+ #=
173+ We will output a vector which is a supertype of the types of A and x
174+ to ensure numerical stability
175+ =#
176+ get_type (A) != eltype (M) ? error (" DiffEqOperator and array are not of same type!" ) : nothing
177+ y = zeros (promote_type (eltype (A),eltype (M)), size (M))
178+ LinearAlgebra. mul! (y, A:: AbstractDerivativeOperator , M:: AbstractMatrix )
179+ return y
180+ end
181+
182+
183+ function * (M:: AbstractMatrix ,A:: AbstractDerivativeOperator )
184+ #=
185+ We will output a vector which is a supertype of the types of A and x
186+ to ensure numerical stability
187+ =#
188+ get_type (A) != eltype (M) ? error (" DiffEqOperator and array are not of same type!" ) : nothing
189+ y = zeros (promote_type (eltype (A),eltype (M)), size (M))
190+ LinearAlgebra. mul! (y, A:: AbstractDerivativeOperator , M:: AbstractMatrix )
191+ return y
192+ end
193+
194+
195+ function * (A:: AbstractDerivativeOperator ,B:: AbstractDerivativeOperator )
196+ # TODO : it will result in an operator which calculates
197+ # the derivative of order A.dorder + B.dorder of
198+ # approximation_order = min(approx_A, approx_B)
199+ end
0 commit comments