Created
March 12, 2014 12:50
-
-
Save rriemann/9506293 to your computer and use it in GitHub Desktop.
latice boltzman streaming in matlab
This file contains hidden or 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
#!/usr/bin/env octave | |
% kate: hl octave; line-numbers on; space-indent on; indent-mode cstyle; | |
more off; | |
global data; | |
function move(irow, icol) | |
global data; | |
[srow,scol] = size(data); | |
vrow = 1:srow; | |
vcol = 1:scol; | |
if(icol < 0) | |
vcol = fliplr(vcol); | |
end | |
if(irow < 0) | |
vrow = fliplr(vrow); | |
end | |
% deal with corner data(srow,scol) | |
data(srow,scol) = data(mod(srow-1+irow+srow,srow)+1,mod(scol-1+icol+scol,scol)+1); | |
% deal with inner cells | |
for col=vcol # x | |
for row=vrow # y | |
nrow = mod(row-1+irow+srow,srow)+1; | |
ncol = mod(col-1+icol+scol,scol)+1; | |
if(row == 1) | |
% printf("%d->%d\n", col,ncol); | |
end | |
data(row,col) = data(nrow,ncol); | |
end | |
end | |
endfunction | |
cycles=2000; | |
N = 3; | |
runs=N*cycles | |
Nd = N + 1; | |
% a = 1:N; | |
% field = ones(3,1)*a; | |
% field = a'*a; | |
data_start = zeros(Nd,Nd); | |
%data(1:N,1:N) = field | |
%data_start(1,1) = 1 % initialize one element | |
%data_start(1,1:N) = 1; | |
data_start(1:N,1:N) = rand(N,N) | |
scol = N; srow = N; % size of the physical grid | |
irow = 1; % increment | |
icol = 1; | |
% version move % % % % % % % % % % % % % % % % % | |
data = data_start; | |
tic | |
for r=1:runs | |
% ghost cells | |
% copy edge top to bottom | |
data(Nd,1:N) = data(1,1:N); | |
% copy edge left to right | |
data(1:N,Nd) = data(1:N,1); | |
move(irow,icol); | |
for col=1:scol % x | |
for row=1:srow % y | |
% heavy grid point manipulation | |
val = data(row,col); | |
if(val ~= 0) | |
val += 1; | |
end | |
data(row,col) = mod(val,200); | |
end | |
end | |
end | |
toc | |
data(1:N,1:N) | |
% version index % % % % % % % % % % % % % % % % | |
data = data_start; | |
data_proj = data_start(1:N,1:N); | |
orow = 0; % offset row | |
ocol = 0; % offset col | |
tic | |
for r=1:runs | |
% define offset | |
orow = mod(orow+irow,srow); | |
ocol = mod(ocol+icol,scol); | |
for col=1:scol # x | |
for row=1:srow # y | |
% compute index | |
nrow = mod(row-1+orow+srow,srow)+1; | |
ncol = mod(col-1+ocol+scol,scol)+1; | |
% heavy grid point manipulation | |
val = data(nrow,ncol); | |
if(val ~= 0) | |
val += 1; | |
end | |
data(nrow,ncol) = mod(val,200); | |
% data_proj(row,col) = data(nrow,ncol); | |
end | |
end | |
end | |
toc | |
% data_proj | |
data(1:N,1:N) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment