ts_readslice.R only prints variables info
[wrf-fire-matlab.git] / femwind / rb_line_gs_solve.m
blob878d59539338fc61672b9fc9324f3c0816d42abe
1 function [x,it]=rb_line_gs_solve(K,F,X)
2 % x=rb_line_gs_solve(K,F,X)
3 disp('solver red-black relaxation horizontal, lines vertical')
4 n = size(X{1});
5 nn = size(F,1);
6 if nn~=prod(n)
7     error('rb_line_gs_solve: inconsistent sizes')
8 end
10 x = zeros(nn,1);
11 maxit=1000;
12 colx=1:n(3);
13 onex=ones(1,n(3));
14 tol = 1e-5*big(F)/big(K);
15 for it=1:maxit
16     for rb1=1:2
17         for rb2=1:2
18             for i1=rb1:2:n(1)
19                 for i2=rb2:2:n(2)
20                     % solving horizontal location i1 i2 and vertical line
21                     ix = sub2ind(n,i1*onex,i2*onex,colx); 
22                     x(ix) = x(ix) - K(ix,ix)\(K(:,ix)'*x - F(ix));
23                 end
24             end
25         end
26     end
27     res= norm(K*x-F);
28     fprintf('iteration %g residual %g tolerance %g\n',it,res,tol)
29     if res<tol,
30         break
31     end
32 end