1 function core_test(exe)
\r
5 if ~exist('exe','var'), exe='core_test_prog.exe';end
\r
11 %m=111 % domain mesh
\r
20 case {'circlespin','c'}
\r
23 case {'gostraight','g'}
\r
26 case {'windmill','w'}
\r
30 case {'spinstardemo','s'},
\r
31 % same as spinStarDemo('low',1)
\r
36 % normal propagation speed
\r
46 phi=zeros(m,n); % allocate level function
\r
54 case {'straight','s'}
\r
57 vx=speed*cos(alpha)*ones(m,n);
\r
58 vy=speed*sin(alpha)*ones(m,n);
\r
59 case {'circular','c'}
\r
60 [xx,yy]=ndgrid(x-xs/2,y-ys/2);
\r
61 rotation=-0.75 * pi;
\r
74 [xx,yy]=ndgrid(x-xs/2,y-ys/2);
\r
75 [ theta, rad ] = cart2pol(xx, yy);
\r
76 phi = rad - scale * (cos(points * theta) + shift);
\r
78 c=[0.3*xs,0.5*ys]; % center
\r
82 % phi(i,j)=sign(norm([i*dx,j*dy]-c)-d);
\r
83 phi(i,j)=(norm([i*dx,j*dy]-c)-d);
\r
86 case {'widmill','w'}
\r
88 phi(floor(m*0.20):ceil(m*0.45),floor(n*0.49):ceil(n*0.51))=-1;
\r
89 phi(floor(m*0.55):ceil(m*0.80),floor(n*0.49):ceil(n*0.51))=-1;
\r
90 phi(floor(m*0.49):ceil(m*0.51),floor(n*0.20):ceil(n*0.45))=-1;
\r
91 phi(floor(m*0.49):ceil(m*0.51),floor(n*0.55):ceil(n*0.80))=-1;
\r
93 error('no ignition')
\r
96 plotSteps = 10; % How many intermediate plots to produce?
\r
97 t0 = time0; % Start time.
\r
99 % Period at which intermediate plots should be produced.
\r
100 tPlot = (time1 - time0) / (plotSteps - 1);
\r
102 %r=ones(m,n).*r + 0.04*sqrt(vx.*vx+vy.*vy); % shrinkage correction
\r
103 r=ones(m,n).*r; % make sure it is array
\r
104 tign=-1e10*ones(m,n);
\r
105 fuel_time=20*ones(m-1,n-1);
\r
106 tign(phi<=0)=time0;
\r
107 frac_end=ones(m-1,n-1);
\r
108 frac_lost=zeros(m-1,n-1);
\r
111 vis(phi,frac_lost,vx,vy,dx,dy,tNow);
\r
114 tNext=min(time1, tNow + tPlot);
\r
116 % write the input file for the fortran code
\r
118 fid = fopen('core_test_in.txt','wt');
\r
119 if(fid<0), error('cannot open file core_test_in.txt'),end
\r
120 fprintf(fid,fmt,1,m,1,n,tNow,tNext,dx,dy);
\r
121 fprintf(fid,fmt,phi,tign,fuel_time,r,vx,vy);
\r
124 % call the fortran implementation
\r
127 % read the output file from the fortran code
\r
128 fid = fopen('core_test_out.txt','rt');
\r
129 if(fid<0), error('cannot open file core_test_out.txt'),end
\r
130 [in,c]=fscanf(fid,'%g');
\r
133 % parse the file read into a single array
\r
134 count=2*m*n+2*(m-1)*(n-1);
\r
135 if(c~=count), error(sprintf('read %g terms should be %g\n',c,count)),end
\r
137 terms=m*n;phi=reshape(in(1+last:terms+last),size(phi));last=terms+last;
\r
138 terms=m*n;tign=reshape(in(1+last:terms+last),size(tign));last=terms+last;
\r
139 tign_d=tign;tign_d(tign<0)=NaN;
\r
140 terms=(m-1)*(n-1);frac_lost=reshape(in(1+last:terms+last),size(frac_lost));last=terms+last;
\r
141 terms=(m-1)*(n-1);frac_end=reshape(in(1+last:terms+last),size(frac_end));last=terms+last;
\r
142 if(last~=count),error('bad count'),end
\r
143 frac_tend=frac_lost/(tNext-tNow);
\r
147 vis(phi,-frac_tend,vx,vy,dx,dy,tNow)
\r
148 %subplot(1,3,1);vis(phi,frac_tend,vx,vy,dx,dy,tNow)
\r
149 %subplot(1,3,2);mesh(tign_d);title('tign')
\r
150 %subplot(1,3,3);mesh(phi);title('phi')
\r
152 pause(0.3); % for ctrl-c
\r
158 %-------------------------------------------
\r
160 function vis(u,f,vx,vy,dx,dy,tNow)
\r
171 set(h,'edgecolor','none')
\r
174 contour3(y,x,u,[0 0],'k')
\r
179 h=pcolor(xh,yh,-f');
\r
180 set(h,'edgecolor','none')
\r
188 h=pcolor(xh,yh,-f');
\r
189 set(h,'edgecolor','none')
\r
192 contour(y,x,u',[0 0],'k')
\r
196 [xx,yy]=ndgrid(x,y);
\r
197 quiver(xx(ix,iy),yy(ix,iy),vx(ix,iy),vy(ix,iy))
\r
200 disp('no visualization selected, set vis=type to 2d or 3d')
\r
204 title(sprintf('t=%g',tNow));
\r