Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.
Automating Comsol with Matlab: While Loop and Time Dependent Solver
Posted 2016年7月11日 GMT-4 05:01 Interfacing, Results & Visualization, Studies & Solvers Version 5.1, Version 5.2, Version 5.2a 0 Replies
Please login with a confirmed email address before reporting spam
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
Hello Femi Oyedokun
Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.
If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.