OK so I'm not sure how to "directly access the CSC structure".
Anyway, for clarity, here is the method which generates my sparse matrix. In
a typical usage scenario, I need to generate and diagonalize a lot of these
matrices, which are obtained varying the *s* Function.
I guess this qualifies as a low-order method?
*function
genspmat(l::Function,r::Function,u::Function,d::Function,s::Function,
N::Int,nz::Int,α::Float64) # Preallocate I = Array(Int64,nz) J =
Array(Int64,nz) V = Array(Complex{Float64},nz) function
setnzelem(i::Int,n::Int,m::Int; pos::ASCIIString = "self") if
pos=="left" k += 1 J[k] = i-N; I[k] = i; V[k] =
l(n,m,α) elseif pos=="right" k += 1 J[k] =
i+N; I[k] = i; V[k] = r(n,m,α) elseif pos=="up" k +=
1 J[k] = i-1; I[k] = i; V[k] = u(n,m,α) elseif
pos=="down" k += 1 J[k] = i+1; I[k] = i; V[k] =
d(n,m,α) elseif pos=="self" k += 1 J[k] = i;
I[k] = i; V[k] = s(n,m,α) end end # maximum value
of m or n indices maxm = div(N-1,2) k = 0 for i in 1:N^2 m
= getm(i,N) n = getn(i,N) setnzelem(i,n,m; pos="self")
#corners #top left if n==maxm && m==-maxm
setnzelem(i,n,m; pos="right") setnzelem(i,n,m;
pos="down") #top right elseif n==maxm && m==maxm
setnzelem(i,n,m; pos="left") setnzelem(i,n,m; pos="down")
#bottom right elseif n==-maxm && m==maxm
setnzelem(i,n,m; pos="left") setnzelem(i,n,m; pos="up")
#bottom left elseif n==-maxm && m==-maxm
setnzelem(i,n,m; pos="right") setnzelem(i,n,m; pos="up")
#edges #top elseif n == maxm setnzelem(i,n,m;
pos="right") setnzelem(i,n,m; pos="left")
setnzelem(i,n,m; pos="down") #right elseif m ==
maxm setnzelem(i,n,m; pos="left") setnzelem(i,n,m;
pos="up") setnzelem(i,n,m; pos="down") #bottom
elseif n == -maxm setnzelem(i,n,m; pos="left")
setnzelem(i,n,m; pos="up") setnzelem(i,n,m; pos="right")
#left elseif m == -maxm setnzelem(i,n,m;
pos="down") setnzelem(i,n,m; pos="up")
setnzelem(i,n,m; pos="right") else #bulk setnzelem(i,n,m;
pos="down") setnzelem(i,n,m; pos="up")
setnzelem(i,n,m; pos="right") setnzelem(i,n,m;
pos="left") end end return sparse(I,J,V)end*
On Friday, April 10, 2015 at 10:15:22 PM UTC+2, Christoph Ortner wrote:
>
>
> For example, for finite elements or finite differences, the connectivity
> information gives you the sparsity pattern, which you could assemble once
> and for all and then change the entries as needed. If it is a low-order
> method, then you have few elements in each column and it would be very
> efficient (and easy to implement) to make these changes by directly
> accessing the CSC structure.
>
> Christoph
>