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

Please login with a confirmed email address before reporting spam

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

0 Replies Last Post 2016年7月11日 GMT-4 05:01
COMSOL Moderator

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.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.