-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimized helper functions for divergence
altPascal is now calculated in a single loop. Both divergence helper and extensionOperatorDivergence now create their outputs without inserting into a sparse matrix(which is slow).
- Loading branch information
1 parent
81aaa9b
commit 49ecc1d
Showing
4 changed files
with
54 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
function [ A ] = alt_pascal( n ) | ||
% Calculates the alternating pascal triangle. | ||
% Will give exact values for n<56 | ||
if(n>1030); error('Argument should be less than 1031'); end | ||
% Calculates the alternating pascal triangle up to n rows. | ||
% This is the change of basis matrix from the basis {i in {0,1,...,n-1}:(e^(h*D)-1)^i} to | ||
% the standard basis. {i in {0,1,...,n-1}:(e^(i*h*D))} | ||
A=eye(n); | ||
A(:,1)=1; | ||
A(:,1)=2*rem(1:n,2) - 1; %Alternating vector [1,-1,1,-1,...] | ||
for i=2:n | ||
A(i,2:end)=A(i-1,1:end-1)+A(i-1,2:end); | ||
end | ||
for i=1:n | ||
for j=1:i | ||
A(i,j)=A(i,j)*(-1)^(i+j); | ||
end | ||
A(i,2:end)=A(i-1,1:end-1)-A(i-1,2:end); | ||
end | ||
|
||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
function D=divergencehelper(k,m) | ||
%Calculates the mimetic divergence operator of order k, | ||
% barring dividing by dx. | ||
% k=order of accuracy | ||
% | ||
r=calculateInteriorRow(k); | ||
A=sparse(m+2,m+k-1); %This matrix is just using the interior scheme.Since we've extended our vector field | ||
%beyond the boundaries it'd normally have, we don't need to use | ||
%seperate power series expansions for the stencils near the boundary. | ||
% k :order of accuracy. | ||
% m :number of cells. | ||
interior=calculateInteriorRow(k); %The interior row of our matrix | ||
numNonZeros=m*k; % The number of nonZeroElements in the interior stencil matrix | ||
rowList=zeros([1,numNonZeros]); | ||
columnList=zeros([1,numNonZeros]); | ||
valueList=zeros([1,numNonZeros]); | ||
elementsInserted=1; | ||
for i=2:(m+1) | ||
A(i,(i-1):(i+k-2))=r; | ||
for j=1:(k) | ||
rowList(elementsInserted)=i; | ||
columnList(elementsInserted)=i+j-2; | ||
valueList(elementsInserted)=interior(j); | ||
elementsInserted=elementsInserted+1; | ||
end | ||
end | ||
D=A*extensionOperatorDivergence(k,m); | ||
interiorScheme=sparse(rowList,columnList,valueList,m+2,m+k-1); | ||
% This matrix is just using the interior scheme. | ||
% Since we've extended our vector field beyond the boundaries it'd normally have, we don't need to use | ||
% seperate power series expansions for the stencils near the boundary. | ||
D=interiorScheme*extensionOperatorDivergence(k,m); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters