PageRenderTime 58ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/other/Matlab/perimeter/perimeter.m

http://github.com/jbeezley/wrf-fire
Objective C | 616 lines | 518 code | 98 blank | 0 comment | 72 complexity | 21e834fe54957e28d74c1963ead61865 MD5 | raw file
Possible License(s): AGPL-1.0
  1. function result=perimeter(long,lat,uf,vf,dzdxf,dzdyf,time_now,bound)
  2. % Volodymyr Kondratenko December 8 2012
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. % The function creates the initial matrix of times of ignitions
  5. % given the perimeter and time of ignition at the points of the perimeter and
  6. % is using wind and terrain gradient in its calculations
  7. % Input: We get it after reading the data using function read_file_perimeter.m
  8. %
  9. % long FXLONG*UNIT_FXLONG, longtitude coordinates of the mesh converted into meters
  10. % lat FXLAT*UNIT_FXLAT, latitude coordinates of the mesh converted into meters
  11. % uf,vf horizontal wind velocity vectors of the points of the mesh
  12. % dzdxf,dzdyf terrain gradient of the points of the mesh
  13. % time_now time of ignition on the fireline (fire perimeter)
  14. % bound set of ordered points of the fire perimeter 1st=last
  15. % bound(i,1)-horisontal; bound(i,1)-vertical coordinate
  16. %
  17. % Output: Matrix of time of ignition
  18. %
  19. % Code:
  20. %addpath('../../other/Matlab/util1_jan');
  21. %addpath('../../other/Matlab/netcdf');
  22. tic
  23. fuels % This function is needed to create fuel variable, that contains all the characteristics
  24. % types of fuel, this function lies in the same folder where you run the main_function.m
  25. % (where is it originally located/can be created?)
  26. format long
  27. bnd_size=size(bound);
  28. n=size(long,1);
  29. m=size(long,2);
  30. %tign=zeros(n,m); % "time of ignition matrix" of the nodes
  31. %A=zeros(n,m); % flag matrix of the nodes, A(i,j)=1 if the time of ignition of the
  32. % point (i,j) was updated at least once
  33. 'started'
  34. % IN - matrix, that shows, whether the point is inside (IN(x,y)>0) the burning region
  35. % or outside (IN(x,y)<0)
  36. % ON - matrix that, shows whether the point is on the boundary or not
  37. % Both matrices evaluated using "polygon", coefficients are multiplied by
  38. % 10^6, because the function looses acuracy when it deals with decimals
  39. xv=bound(:,1);
  40. yv=bound(:,2);
  41. xv=xv*100000;
  42. yv=yv*100000;
  43. lat1=lat*100000;
  44. long1=long*100000;
  45. [IN,ON] = inpolygon(long1,lat1,xv,yv);
  46. % Code
  47. [ichap,bbb,phiwc,betafl,r_0]=fire_ros_new(fuel);
  48. delta_tign=delta_tign_calculation(long,lat,vf,uf,dzdxf,dzdyf,ichap,bbb,phiwc,betafl,r_0);
  49. % Calculates needed variables for rate of fire spread calculation
  50. %%%%%%% First part %%%%%%%
  51. % Set everything inside to time_now and update the tign of the points outside
  52. % Initializing flag matrix A and time of ignition (tign)
  53. % Extending the boundaries, in order to speed up the algorythm
  54. A=[];
  55. C=zeros(n+2,m+2);
  56. % A contains coordinates of the points that were updated during the last
  57. % step
  58. IN_ext=(2)*ones(n+2,m+2);
  59. IN_ext(2:n+1,2:m+1)=IN(:,:,1);
  60. for i=2:n+1
  61. for j=2:m+1
  62. if IN_ext(i,j)==1
  63. if sum(sum(IN_ext(i-1:i+1,j-1:j+1)))<9
  64. A=[A;[i,j]];
  65. end
  66. end
  67. end
  68. end
  69. tign=ones(n+2,m+2)*1000*time_now;
  70. tign(2:n+1,2:m+1)=IN(:,:,1)*time_now+(1-IN(:,:,1))*1000*time_now; % and their time of ignition is set to time_now
  71. toc
  72. changed=1;
  73. % The algorithm stops when the matrix converges (tign_old-tign==0) or if
  74. % the amount of iterations
  75. % reaches the max(size()) of the mesh
  76. for istep=1:max(2*size(tign)),
  77. if changed==0,
  78. % The matrix coverged
  79. 'first part done'
  80. break
  81. end
  82. tign_last=tign;
  83. time_toc=toc;
  84. str=sprintf('%f -- How long does it take to run step %i',time_toc,istep-1);
  85. % tign_update - updates the time of ignition of the points
  86. [tign,A,C]=tign_update(tign,A,IN_ext,delta_tign,time_now,0);
  87. % tign_update - updates the time of ignition of the points
  88. changed=sum(tign(:)~=tign_last(:));
  89. sprintf('%s \n step %i outside tign changed at %i points \n %f -- norm of the difference',str,istep,changed,norm(tign-tign_last))
  90. end
  91. if changed~=0,
  92. 'did not find fixed point'
  93. end
  94. %%%%%%% Second part %%%%%%%
  95. % Set all the points outside to time_now and update the points inside
  96. % Initializing flag matrix A and time of ignition (tign)
  97. % Extending the boundaries, in order to speed up the algorythm
  98. A=[];
  99. C=zeros(n+2,m+2);
  100. for i=2:n+1
  101. for j=2:m+1
  102. if IN_ext(i,j)==0
  103. if sum(sum(IN_ext(i-1:i+1,j-1:j+1)))>0
  104. A=[A;[i,j]];
  105. end
  106. end
  107. end
  108. end
  109. tign_in=zeros(n+2,m+2);
  110. tign_in(2:n+1,2:m+1)=(1-IN(:,:,1)).*tign(2:n+1,2:m+1);
  111. changed=1;
  112. % The algorithm stops when the matrix converges (tign_old-tign==0) or if the amount of iterations
  113. % % reaches the max(size()) of the mesh
  114. for istep=1:max(size(tign)),
  115. if changed==0,
  116. % The matrix of tign converged
  117. 'printed'
  118. break
  119. end
  120. tign_last=tign_in;
  121. time_toc=toc;
  122. str= sprintf('%f -- How long does it take to run step %i',time_toc,istep-1);
  123. % tign_update - updates the tign of the points
  124. [tign_in,A,C]=tign_update(tign_in,A,IN_ext,delta_tign,time_now,1);
  125. % hwen it is outside the last parameter is 0, inside 1
  126. changed=sum(tign_in(:)~=tign_last(:));
  127. sprintf('%s \n step %i inside tign changed at %i points \n %f -- norm of the difference',str,istep,changed,norm(tign_in-tign_last))
  128. end
  129. final_tign=zeros(n+2,m+2);
  130. final_tign(2:n+1,2:m+1)=(IN(:,:,1)>0).*tign_in(2:n+1,2:m+1)+(IN(:,:,1)==0).*tign(2:n+1,2:m+1);
  131. result=final_tign(2:n+1,2:m+1);
  132. fid = fopen('output_tign.txt', 'w');
  133. dlmwrite('output_tign.txt', result, 'delimiter', '\t','precision', '%.4f');
  134. fclose(fid);
  135. if changed~=0,
  136. 'did not find fixed point inside'
  137. end
  138. end
  139. function [tign,A,C]=tign_update(tign,A,IN,delta_tign,time_now,where)
  140. % Does one iteration of the algorythm and updates the tign of the points of
  141. % the mesh that are next to the previously updated neighbors
  142. %B=A(end,:);
  143. C=zeros(size(tign,1),size(tign,2));
  144. for i=1:size(A,1)
  145. for dx=-1:1
  146. for dy=-1:1
  147. if where*IN(A(i,1)+dx,A(i,2)+dy)==1
  148. tign_new=tign(A(i,1),A(i,2))-0.5*(delta_tign(A(i,1)+dx,A(i,2)+dy,dx+2,dy+2)+delta_tign(A(i,1),A(i,2),2-dx,2-dy));
  149. if (tign(A(i,1)+dx,A(i,2)+dy)<tign_new)&&(tign_new<=time_now)
  150. % Looking for the max tign, which
  151. % should be <= than time_now, since the
  152. % point is inside of the preimeter
  153. % if (B(end,1)~=A(i,1)+dx)||(B(end,2)~=A(i,2)+dy)
  154. % B=[B;[A(i,1)+dx,A(i,2)+dy]];
  155. tign(A(i,1)+dx,A(i,2)+dy)=tign_new;
  156. C(A(i,1)+dx,A(i,2)+dy)=1;
  157. % end
  158. end
  159. elseif (1-where)*(1-IN(A(i,1)+dx,A(i,2)+dy))==1
  160. tign_new=tign(A(i,1),A(i,2))+0.5*(delta_tign(A(i,1)+dx,A(i,2)+dy,dx+2,dy+2)+delta_tign(A(i,1),A(i,2),2-dx,2-dy));
  161. if (A(i,1)+dx==2)&&(A(i,2)+dy==2)
  162. display('**********************************************************')
  163. display('i=1,j=1, (2,2) in extended array')
  164. display('we calculate it from the point')
  165. A(i,1)
  166. A(i,2)
  167. display('tign_new that was calculated')
  168. tign_new
  169. display('tign(A(i,1),A(i,2))')
  170. tign(A(i,1),A(i,2))
  171. display('delta_tign(A(i,1)+dx,A(i,2)+dy,dx+2,dy+2) ')
  172. delta_tign(A(i,1)+dx,A(i,2)+dy,dx+2,dy+2)
  173. display('delta_tign(A(i,1),A(i,2),2-dx,2-dy)')
  174. delta_tign(A(i,1),A(i,2),2-dx,2-dy)
  175. display('tign(A(i,1)+dx,A(i,2)+dy')
  176. tign(A(i,1)+dx,A(i,2)+dy)
  177. display('time_now')
  178. time_now
  179. display('check (tign(A(i,1)+dx,A(i,2)+dy)>tign_new)&&(tign_new>=time_now)')
  180. (tign(A(i,1)+dx,A(i,2)+dy)>tign_new)&&(tign_new>=time_now)
  181. end
  182. if (tign(A(i,1)+dx,A(i,2)+dy)>tign_new)&&(tign_new>=time_now);
  183. % Looking for the min tign, which
  184. % should be >= than time_now, since the
  185. % point is outside of the preimeter
  186. % if (B(end,1)~=A(i,1)+dx+1)||(B(end,2)~=A(i,2)+dy)
  187. % B=[B;[A(i,1)+dx,A(i,2)+dy]];
  188. tign(A(i,1)+dx,A(i,2)+dy)=tign_new;
  189. C(A(i,1)+dx,A(i,2)+dy)=1;
  190. % end
  191. end
  192. end
  193. end
  194. end
  195. end
  196. A=[];
  197. [A(:,1),A(:,2)]=find(C>0);
  198. end
  199. function [ichap,bbb,phiwc,betafl,r_0]=fire_ros_new(fuel,fmc_g)
  200. % ros=fire_ros(fuel,speed,tanphi)
  201. % ros=fire_ros(fuel,speed,tanphi,fmc_g)
  202. % in
  203. % fuel fuel description structure
  204. % speed wind speed
  205. % tanphi slope
  206. % fmc_g optional, overrides fuelmc_g from the fuel description
  207. % out
  208. % ros rate of spread
  209. % given fuel params
  210. windrf=fuel.windrf; % WIND REDUCTION FACTOR
  211. fgi=fuel.fgi; % INITIAL TOTAL MASS OF SURFACE FUEL (KG/M**2)
  212. fueldepthm=fuel.fueldepthm; % FUEL DEPTH (M)
  213. savr=fuel.savr; % FUEL PARTICLE SURFACE-AREA-TO-VOLUME RATIO, 1/FT
  214. fuelmce=fuel.fuelmce; % MOISTURE CONTENT OF EXTINCTION
  215. fueldens=fuel.fueldens; % OVENDRY PARTICLE DENSITY, LB/FT^3
  216. st=fuel.st; % FUEL PARTICLE TOTAL MINERAL CONTENT
  217. se=fuel.se; % FUEL PARTICLE EFFECTIVE MINERAL CONTENT
  218. weight=fuel.weight; % WEIGHTING PARAMETER THAT DETERMINES THE SLOPE OF THE MASS LOSS CURVE
  219. fci_d=fuel.fci_d; % INITIAL DRY MASS OF CANOPY FUEL
  220. fct=fuel.fct; % BURN OUT TIME FOR CANOPY FUEL, AFTER DRY (S)
  221. ichap=fuel.ichap; % 1 if chaparral, 0 if not
  222. fci=fuel.fci; % INITIAL TOTAL MASS OF CANOPY FUEL
  223. fcbr=fuel.fcbr; % FUEL CANOPY BURN RATE (KG/M**2/S)
  224. hfgl=fuel.hfgl; % SURFACE FIRE HEAT FLUX THRESHOLD TO IGNITE CANOPY (W/m^2)
  225. cmbcnst=fuel.cmbcnst; % JOULES PER KG OF DRY FUEL
  226. fuelheat=fuel.fuelheat; % FUEL PARTICLE LOW HEAT CONTENT, BTU/LB
  227. fuelmc_g=fuel.fuelmc_g; % FUEL PARTICLE (SURFACE) MOISTURE CONTENT, jm: 1 by weight?
  228. fuelmc_c=fuel.fuelmc_c; % FUEL PARTICLE (CANOPY) MOISTURE CONTENT, 1
  229. if exist('fmc_g','var') % override moisture content by given
  230. fuelmc_g = fmc_g;
  231. end
  232. % computations from CAWFE code: wf2_janice/fire_startup.m4
  233. bmst = fuelmc_g/(1+fuelmc_g); % jm: 1
  234. fuelheat = cmbcnst * 4.30e-04; % convert J/kg to BTU/lb
  235. fci = (1.+fuelmc_c)*fci_d;
  236. fuelloadm= (1.-bmst) * fgi; % fuelload without moisture
  237. % jm: 1.-bmst = 1/(1+fuelmc_g) so fgi includes moisture?
  238. fuelload = fuelloadm * (.3048)^2 * 2.205; % to lb/ft^2
  239. fueldepth= fueldepthm/0.3048; % to ft
  240. betafl = fuelload/(fueldepth * fueldens);% packing ratio jm: lb/ft^2/(ft * lb*ft^3) = 1
  241. betaop = 3.348 * savr^(-0.8189); % optimum packing ratio jm: units??
  242. qig = 250. + 1116.*fuelmc_g; % heat of preignition, btu/lb
  243. epsilon = exp(-138./savr ); % effective heating number
  244. rhob = fuelload/fueldepth; % ovendry bulk density, lb/ft^3
  245. c = 7.47 * exp(-0.133 * savr^0.55); % const in wind coef
  246. bbb = 0.02526 * savr^0.54; % const in wind coef
  247. c = c * windrf^bbb; % jm: wind reduction from 20ft per Baughman&Albini(1980)
  248. e = 0.715 * exp( -3.59e-4 * savr); % const in wind coef
  249. phiwc = c * (betafl/betaop)^(-e);
  250. rtemp2 = savr^1.5;
  251. gammax = rtemp2/(495. + 0.0594*rtemp2); % maximum rxn vel, 1/min
  252. a = 1./(4.774 * savr^0.1 - 7.27); % coef for optimum rxn vel
  253. ratio = betafl/betaop;
  254. gamma = gammax*(ratio^a)*exp(a*(1.-ratio)); % optimum rxn vel, 1/min
  255. wn = fuelload/(1 + st); % net fuel loading, lb/ft^2
  256. rtemp1 = fuelmc_g/fuelmce;
  257. etam = 1.-2.59*rtemp1 +5.11*rtemp1^2 -3.52*rtemp1^3; % moist damp coef
  258. etas = 0.174* se^(-0.19); % mineral damping coef
  259. ir = gamma * wn * fuelheat * etam * etas; % rxn intensity,btu/ft^2 min
  260. irm = ir * 1055./( 0.3048^2 * 60.) * 1.e-6;% for mw/m^2 (set but not used)
  261. xifr = exp( (0.792 + 0.681*savr^0.5)...
  262. * (betafl+0.1)) /(192. + 0.2595*savr); % propagating flux ratio
  263. % ... r_0 is the spread rate for a fire on flat ground with no wind.
  264. r_0 = ir*xifr/(rhob * epsilon *qig); % default spread rate in ft/min
  265. % computations from CAWFE code: wf2_janice/fire_ros.m4
  266. end
  267. function delta_tign=delta_tign_calculation(long,lat,vf,uf,dzdxf,dzdyf,ichap,bbb,phiwc,betafl,r_0)
  268. %Extend the boundaries to speed up the algorithm, the values of the
  269. %extended boundaries would be set to zeros and are never used in the
  270. %code
  271. result=1;
  272. 'hello'
  273. delta_tign=zeros(size(long,1)+2,size(long,2)+2,3,3);
  274. rate_of_spread=zeros(size(long,1)+2,size(long,2)+2,3,3);
  275. long2=zeros(size(long,1)+2,size(long,2)+2);
  276. long2(2:size(long,1)+1,2:size(long,2)+1)=long;
  277. long=long2;
  278. lat2=zeros(size(lat,1)+2,size(lat,2)+2);
  279. lat2(2:size(lat,1)+1,2:size(lat,2)+1)=lat;
  280. lat=lat2;
  281. vf2=zeros(size(vf,1)+2,size(vf,2)+2);
  282. vf2(2:size(vf,1)+1,2:size(vf,2)+1)=vf;
  283. vf=vf2;
  284. uf2=zeros(size(uf,1)+2,size(uf,2)+2);
  285. uf2(2:size(uf,1)+1,2:size(uf,2)+1)=uf;
  286. uf=uf2;
  287. dzdxf2=zeros(size(dzdxf,1)+2,size(dzdxf,2)+2);
  288. dzdxf2(2:size(dzdxf,1)+1,2:size(dzdxf,2)+1)=dzdxf;
  289. dzdxf=dzdxf2;
  290. dzdyf2=zeros(size(dzdyf,1)+2,size(dzdyf,2)+2);
  291. dzdyf2(2:size(dzdyf,1)+1,2:size(dzdyf,2)+1)=dzdyf;
  292. dzdyf=dzdyf2;
  293. for i=2:size(long,1)-1
  294. for j=2:size(long,2)-1
  295. for a=-1:1
  296. for b=-1:1
  297. wind=0.5*((long(i,j,1)-long(i+a,j+b,1))*vf(i,j,1)+ ...
  298. (lat(i,j,1)-lat(i+a,j+b,1))*uf(i,j,1));
  299. angle=0.5*((long(i,j,1)-long(i+a,j+b,1))*dzdxf(i,j,1)+ ...
  300. (lat(i,j,1)-lat(i+a,j+b,1))*dzdyf(i,j,1));
  301. if ~ichap,
  302. % ... if wind is 0 or into fireline, phiw = 0, &this reduces to backing ros.
  303. spdms = max(wind,0.);
  304. umidm = min(spdms,30.); % max input wind spd is 30 m/s !param!
  305. umid = umidm * 196.850; % m/s to ft/min
  306. % eqn.: phiw = c * umid**bbb * (betafl/betaop)**(-e) ! wind coef
  307. phiw = umid^bbb * phiwc; % wind coef
  308. phis = 5.275 * betafl^(-0.3) *max(0,angle)^2; % slope factor
  309. ros = r_0*(1. + phiw + phis) * .00508; % spread rate, m/s
  310. else % chapparal
  311. % .... spread rate has no dependency on fuel character, only windspeed.
  312. spdms = max(wind,0.);
  313. ros = max(.03333,1.2974 * spdms^1.41); % spread rate, m/s
  314. end
  315. rate_of_spread(i,j,a+2,b+2)=min(ros,6);
  316. % DEscribe the coefficient below
  317. delta_tign(i,j,a+2,b+2)=sqrt((long(i+a,j+b,1)-long(i,j,1))^2+ ...
  318. (lat(i+a,j+b,1)-lat(i,j,1))^2)/rate_of_spread(i,j,a+2,b+2);
  319. end
  320. end
  321. end
  322. end
  323. end
  324. function [tign,A]=point_update(i,j,tign,delta_tign,inside)
  325. for dx=-1:+1
  326. for dy=-1:+1
  327. % loop over all neighbors
  328. if (A(i+dx,j+dy)==1) % the neighbor was already updated
  329. % All the vectors are split in half-intervals
  330. % to get better calculation
  331. %%% Make a picture of what is happening %%%
  332. tign_new=tign(i+dx,j+dy)-delta_tign(i,j,dx+2,dy+2)-delta_tign(i+dx,j+dy,2-dx,2-dy);
  333. if (tign(i,j)<tign_new)&&(tign_new<=time_now);
  334. % Looking for the max tign, which
  335. % should be <= than time_now, since the
  336. % point is inside of the preimeter
  337. tign(i,j)=tign_new;
  338. A(i,j)=1;
  339. end
  340. end
  341. end
  342. end
  343. end
  344. % function result=print_matrix(tign,fid)
  345. %
  346. %
  347. % fprintf(fid,'%s\n','j=1740:1744, i=2750:2754');
  348. %
  349. % for ii = 2750:2754
  350. % fprintf(fid,'%g\t',tign(ii,1740:1744));
  351. % fprintf(fid,'\n');
  352. % end
  353. % fprintf(fid,'%s\n','i=100');
  354. %
  355. % for ii = 98:102
  356. % fprintf(fid,'%g\t',tign(ii,98:102));
  357. % fprintf(fid,'\n');
  358. % end
  359. % fprintf(fid,'%s\n','i=1000');
  360. %
  361. % for ii = 998:1002
  362. % fprintf(fid,'%g\t',tign(ii,998:1002));
  363. % fprintf(fid,'\n');
  364. % end
  365. % result=0;
  366. % end
  367. % for i=2:size(tign,1)-1
  368. % for j=2:size(tign,2)-1
  369. % % sum_A is needed to know what is the amount of points that surrounds (i,j)
  370. % sum_A=sum(sum(A(i-1:i+1,j-1:j+1)));
  371. %
  372. % if (sum_A~=0)
  373. %
  374. % % sum_A>0 then at least on eneighbor was previously updated and its
  375. % % tign can be used to update the tign of the point (i,j)
  376. %
  377. % % I subtract 1 in all IN, long, lat, uf, vf, dzdxf, dzdyf
  378. % % matrices, because their boundaries were not updated, unlike
  379. % %%% tign (do the loop 1:n, 1:m and change the indexes in tign) %%%
  380. %
  381. %
  382. % for dx=-1:1
  383. % for dy=-1:1
  384. % % loop over all neighbors
  385. % if (A(i+dx,j+dy)==1) % the neighbor was already updated
  386. % % All the vectors are split in half-intervals
  387. % % to get better calculation
  388. % %%% Make a picture of what is happening %%%
  389. % % I do multiplication by 0.5 here 0.5-(IN(i-1,j-1)>0
  390. %
  391. % tign_new=tign(i+dx,j+dy)+(0.5-(IN(i-1,j-1)>0))*(delta_tign(i,j,dx+2,dy+2)+delta_tign(i+dx,j+dy,2-dx,2-dy));
  392. %
  393. % if (IN(i-1,j-1)>0)
  394. %
  395. % if (tign(i,j)<tign_new)&&(tign_new<=time_now)
  396. % % Looking for the max tign, which
  397. % % should be <= than time_now, since the
  398. % % point is inside of the preimeter
  399. % tign(i,j)=tign_new;
  400. % A(i,j)=1;
  401. % end
  402. % elseif (tign(i,j)>tign_new)&&(tign_new>=time_now);
  403. % % Looking for the min tign, which
  404. % % should be >= than time_now, since the
  405. % % point is outside of the preimeter
  406. % tign(i,j)=tign_new;
  407. % A(i,j)=1;
  408. % end
  409. % end
  410. % end
  411. % end
  412. % end
  413. % end
  414. % end
  415. % Old Code -- tign_update
  416. % % wind1 = vect.*(uf,vf)
  417. % wind1=0.5*((long(a-1,b-1,1)-long(i-1,j-1, 1))*vf(i-1,j-1,1)+ ...
  418. % (lat(a-1,b-1,1)-lat(i-1,j-1,1))*uf(i-1,j-1,1));
  419. % angle1=0.5*((long(a-1,b-1,1)-long(i-1,j-1,1))*dzdxf(i-1,j-1,1)+ ...
  420. % (lat(a-1,b-1,1)-lat(i-1,j-1,1))*dzdyf(i-1,j-1,1));
  421. %
  422. % % This is needed to calculate the ros(i,j)
  423. % if ~ichap,
  424. % % ... if wind is 0 or into fireline, phiw = 0, &this reduces to backing ros.
  425. % spdms = max(wind1,0.);
  426. % umidm = min(spdms,30.); % max input wind spd is 30 m/s !param!
  427. % umid = umidm * 196.850; % m/s to ft/min
  428. % % eqn.: phiw = c * umid**bbb * (betafl/betaop)**(-e) ! wind coef
  429. % phiw = umid^bbb * phiwc; % wind coef
  430. % phis = 5.275 * betafl^(-0.3) *max(0,angle1)^2; % slope factor
  431. % ros = r_0*(1. + phiw + phis) * .00508; % spread rate, m/s
  432. % else % chapparal
  433. % % .... spread rate has no dependency on fuel character, only windspeed.
  434. % spdms = max(wind1,0.);
  435. % ros = max(.03333,1.2974 * spdms^1.41); % spread rate, m/s
  436. % end
  437. % ros=min(ros,6);
  438. %
  439. % % tign_new=tign(a,b)-delta(t);
  440. % tign_new1=tign(a,b)-0.5*sqrt((long(a-1,b-1,1)-long(i-1,j-1,1))^2+ ...
  441. % (lat(a-1,b-1,1)-lat(i-1,j-1,1))^2)/ros; ...
  442. %
  443. % % Same calculation for the second half of the
  444. % % interval
  445. %
  446. % wind2=0.5*((long(a-1,b-1,1)-long(i-1,j-1, 1))*vf(a-1,b-1,1)+ ...
  447. % (lat(a-1,b-1,1)-lat(i-1,j-1,1))*uf(a-1,b-1,1));
  448. % angle2=0.5*((long(a-1,b-1,1)-long(i-1,j-1,1))*dzdxf(a-1,b-1,1)+ ...
  449. % (lat(a-1,b-1,1)-lat(i-1,j-1,1))*dzdyf(a-1,b-1,1));
  450. % if ~ichap,
  451. % % ... if wind is 0 or into fireline, phiw = 0, &this reduces to backing ros.
  452. % spdms = max(wind2,0.);
  453. % umidm = min(spdms,30.); % max input wind spd is 30 m/s !param!
  454. % umid = umidm * 196.850; % m/s to ft/min
  455. % % eqn.: phiw = c * umid**bbb * (betafl/betaop)**(-e) ! wind coef
  456. % phiw = umid^bbb * phiwc; % wind coef
  457. % phis = 5.275 * betafl^(-0.3) *max(0,angle2)^2; % slope factor
  458. % ros = r_0*(1. + phiw + phis) * .00508; % spread rate, m/s
  459. % else % chapparal
  460. % % .... spread rate has no dependency on fuel character, only windspeed.
  461. % spdms = max(wind2,0.);
  462. % ros = max(.03333,1.2974 * spdms^1.41); % spread rate, m/s
  463. % end
  464. % ros=min(ros,6);
  465. % tign_new2=-0.5*sqrt((long(a-1,b-1,1)-long(i-1,j-1,1))^2+ ...
  466. % (lat(a-1,b-1,1)-lat(i-1,j-1,1))^2)/ros;
  467. % tign_new=tign_new1+tign_new2;
  468. % OUTSIDE
  469. % wind1=0.5*((long(i-1,j-1,1)-long(a-1,b-1,1))*vf(i-1,j-1,1)+ ...
  470. % (lat(i-1,j-1,1)-lat(a-1,b-1,1))*uf(i-1,j-1,1));
  471. % angle1=0.5*((long(i-1,j-1,1)-long(a-1,b-1,1))*dzdxf(i-1,j-1,1)+ ...
  472. % (lat(i-1,j-1,1)-lat(a-1,b-1,1))*dzdyf(i-1,j-1,1));
  473. % if ~ichap,
  474. % % ... if wind is 0 or into fireline, phiw = 0, &this reduces to backing ros.
  475. % spdms = max(wind1,0.);
  476. % umidm = min(spdms,30.); % max input wind spd is 30 m/s !param!
  477. % umid = umidm * 196.850; % m/s to ft/min
  478. % % eqn.: phiw = c * umid**bbb * (betafl/betaop)**(-e) ! wind coef
  479. % phiw = umid^bbb * phiwc; % wind coef
  480. % phis = 5.275 * betafl^(-0.3) *max(0,angle1)^2; % slope factor
  481. % ros = r_0*(1. + phiw + phis) * .00508; % spread rate, m/s
  482. % else % chapparal
  483. % % .... spread rate has no dependency on fuel character, only windspeed.
  484. % spdms = max(wind1,0.);
  485. % ros = max(.03333,1.2974 * spdms^1.41); % spread rate, m/s
  486. % end
  487. % ros=min(ros,6);
  488. % % tign_new=tign(a,b)-delta(t);
  489. % tign_new1=tign(a,b)+0.5*sqrt((long(a-1,b-1,1)-long(i-1,j-1,1))^2+ ...
  490. % (lat(a-1,b-1,1)-lat(i-1,j-1,1))^2)/r
  491. % os;s
  492. %
  493. % wind2=0.5*((long(i-1,j-1,1)-long(a-1,b-1,1))*vf(a-1,b-1,1)+ ...
  494. % (lat(i-1,j-1,1)-lat(a-1,b-1,1))*uf(a-1,b-1,1));
  495. % angle2=0.5*((long(i-1,j-1,1)-long(a-1,b-1,1))*dzdxf(a-1,b-1,1)+ ...
  496. % (lat(i-1,j-1,1)-lat(a-1,b-1,1))*dzdyf(a-1,b-1,1));
  497. % if ~ichap,
  498. % % ... if wind is 0 or into fireline, phiw = 0, &this reduces to backing ros.
  499. % spdms = max(wind2,0.);
  500. % umidm = min(spdms,30.); % max input wind spd is 30 m/s !param!
  501. % umid = umidm * 196.850; % m/s to ft/min
  502. % % eqn.: phiw = c * umid**bbb * (betafl/betaop)**(-e) ! wind coef
  503. % phiw = umid^bbb * phiwc; % wind coef
  504. % phis = 5.275 * betafl^(-0.3) *max(0,angle2)^2; % slope factor
  505. % ros = r_0*(1. + phiw + phis) * .00508; % spread rate, m/s
  506. % else % chapparal
  507. % % .... spread rate has no dependency on fuel character, only windspeed.
  508. % spdms = max(wind2,0.);
  509. % ros = max(.03333,1.2974 * spdms^1.41); % spread rate, m/s
  510. % end
  511. % ros=min(ros,6);
  512. % tign_new2=0.5*sqrt((long(a-1,b-1,1)-long(i-1,j-1,1))^2+ ...
  513. % (lat(a-1,b-1,1)-lat(i-1,j-1,1))^2)/ros;
  514. % tign_new=tign_new1+tign_new2; ...
  515. % % Here the direction of the vector is
  516. % % opposite, since fire is going from the
  517. % % inside point towards the point that was
  518. % % already computed