I am running a comsol model with matlab; and I have a while loop in which the pressure values extracted from comsol at a time tmax corresponding to the iteration parameter, k of the while loop, is used to compute a variable. Since MATLAB and COMSOL do not run at the same sequence, how can t and k be synchronized so that my computation will not run out of results or solutions.
In other words, suppose I have the code below, and pwmid is to extracted from Comsol destop. The final value of k is not known until the end of the iteration. For a time dependent problem in Comsol, I need to specify the computing time, t (i.e 0:1:tmax), where tmax is the max time. How can I synchronize tmax and k, so that I do not run out of values in MATLAB; if a specify a value tmax=1000, and at the end of while loop k=1001, I will run out of values at the last iteration step. But if I update the value of tmax with k and recompute, I am guessing this should synchronize the two values; will it despite the difference in the computing speed of matlab and comsol?
clear all
clc
Lh=15*ones(1,5);
for j=1:5
k=1;
%Lh=15;
Lo(k,j)=0.2;
k2(k,j)=Lo(k,j)./sqrt(Lh(j));
ud(k,j)=(k2(k,j)).^2.*Lh(j);
p(k,j)=Lh(j).^3*Lo(k,j);
pq(k,j)=k2(k,j).*Lh(j).^3;
if pq(k,j)<p(k,j)
while Lo(k,j)<Lh
Lo(k+1,j)=Lo(k,j)+ud(k,j);
k2(k+1,j)=Lo(k+1,j)./Lh(j);
ud(k+1,j)=(k2(k+1,j)).^2./Lh(j);
pq(k+1,j)=k2(k+1,j).*Lh(j).^3;
p(k+1,j)=Lh(j).^3*Lo(k+1,j);
Pm=[p k2 ud pq];
pwmid(k)=(mphinterp(model,'p','coord',coord10a,'t',k)
Pm2(k+1,j)=Pm(k+1,j)-pwmid(k);
k=k+1;
if k>1000
break;
end
model.param.set('tmax',k)
model.study('std1').run;
end
end
end
In other words, suppose I have the code below, and pwmid is to extracted from Comsol destop. The final value of k is not known until the end of the iteration. For a time dependent problem in Comsol, I need to specify the computing time, t (i.e 0:1:tmax), where tmax is the max time. How can I synchronize tmax and k, so that I do not run out of values in MATLAB; if a specify a value tmax=1000, and at the end of while loop k=1001, I will run out of values at the last iteration step. But if I update the value of tmax with k and recompute, I am guessing this should synchronize the two values; will it despite the difference in the computing speed of matlab and comsol?
clear all
clc
Lh=15*ones(1,5);
for j=1:5
k=1;
%Lh=15;
Lo(k,j)=0.2;
k2(k,j)=Lo(k,j)./sqrt(Lh(j));
ud(k,j)=(k2(k,j)).^2.*Lh(j);
p(k,j)=Lh(j).^3*Lo(k,j);
pq(k,j)=k2(k,j).*Lh(j).^3;
if pq(k,j)<p(k,j)
while Lo(k,j)<Lh
Lo(k+1,j)=Lo(k,j)+ud(k,j);
k2(k+1,j)=Lo(k+1,j)./Lh(j);
ud(k+1,j)=(k2(k+1,j)).^2./Lh(j);
pq(k+1,j)=k2(k+1,j).*Lh(j).^3;
p(k+1,j)=Lh(j).^3*Lo(k+1,j);
Pm=[p k2 ud pq];
pwmid(k)=(mphinterp(model,'p','coord',coord10a,'t',k)
Pm2(k+1,j)=Pm(k+1,j)-pwmid(k);
k=k+1;
if k>1000
break;
end
model.param.set('tmax',k)
model.study('std1').run;
end
end
end