Skip to content

Instantly share code, notes, and snippets.

@KristofferC
Created April 26, 2017 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KristofferC/1660cd312d17454009644e3516c10c94 to your computer and use it in GitHub Desktop.
Save KristofferC/1660cd312d17454009644e3516c10c94 to your computer and use it in GitHub Desktop.
function getDivGrad(n1,n2,n3)
# the Divergence
D1 = kron(speye(n3),kron(speye(n2),ddx(n1)))
D2 = kron(speye(n3),kron(ddx(n2),speye(n1)))
D3 = kron(ddx(n3),kron(speye(n2),speye(n1)))
# DIV from faces to cell-centers
Div = [D1 D2 D3]
return Div*Div';
end
function ddx(n)
# generate 1D derivatives
return d = spdiagm((-ones(n),ones(n)),[0,1],n,n+1)
end
K = getDivGrad(60,60,60); b = rand(size(K,1)); c = similar(b);
@time for i in 1:1000 A_mul_B!(c,K,b) end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment