Merge branch 'fixf'
[wrf-fire-matlab.git] / detection / sfire_simple.m
blob3604db1448268f70f0c4d45d808452dd16c92a09
1 function t1=sfire_simple(r,dx,dy,t_init,mask,tol,rangex,rangey)
2 % t1=sfire_simple(t11,t11.dx,t11.dy,t11.tign_g,t11.mask,1e-5);
3 % in:
4 % r             structure with 2d fields f_ros11,...,f_ros33 (m/s)
5 % dx,dy         mesh spacing (m)
6 % tign_init     initial ignition times (s)
7 % tol           stopping tolerance (s)
8 % out:
9 % tign          ignition times
11 ext=0;
12 dd=sqrt(dx^2+dy^2); % diagonal length
13 if ~exist('rangex','var') || isempty(rangex),
14     rangex=1:size(r.f_ros11,1);
15 end
16 if ~exist('rangey','var') || isempty(rangey),
17     rangey=1:size(r.f_ros11,2);
18 end
19 rr.r11=dd./r.f_ros11(rangex,rangey);
20 rr.r12=dx./r.f_ros12(rangex,rangey);
21 rr.r13=dd./r.f_ros13(rangex,rangey);
22 rr.r21=dx./r.f_ros21(rangex,rangey);
23 rr.r23=dy./r.f_ros23(rangex,rangey);
24 rr.r31=dd./r.f_ros31(rangex,rangey);
25 rr.r32=dy./r.f_ros32(rangex,rangey);
26 rr.r33=dd./r.f_ros33(rangex,rangey);
27 sfire_simple_ext(rr,t_init,mask,0);
28 ncycles=100;
29 t0=ones(size(t_init))*inf;
30 t0(2:end-1,2:end-1)=t_init(2:end-1,2:end-1);
31 mint=false(size(t_init));mint(2:end-1,2:end-1)=mask(2:end-1,2:end-1);
32 % border=true(size(t_init));border(2:end-1,2:end-1)=false;
33 max_it=10*prod(size(t0))
34 for it=1:ncycles:max_it,
35     t1=sfire_simple_ext([],t0,mask,ncycles);
36     tt=abs(t1-t0);
37     err=norm(tt(~isnan(tt(:))),1);
38     count=sum(t1(:)~=t0(:));
39     fprintf('%i %g %i\n',it,err,count) 
40     t0=t1;
41     mesh(t1); drawnow
42     if err<=tol,break,end
43 end