Note: This discussion is about an older version of the COMSOL Multiphysics® software. The information provided may be out of date.

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.

model.param.set

Please login with a confirmed email address before reporting spam

Hi,

Are there someone would like to give me some help about 'model.para.set'?

I have three variables in comsol model, which are p_1, p_2, p_3.

So in my matlab function, I worte

model.para.set ('p_1',x(:,1));
model.para.set ('p_2',x(:,2));
model.para.set ('p_1',x(:,3));

Is there some way to write them somehow in one sentence, like
model.param.set(p(j),x(k,j));
this is totally wrong, but I want to find a way to call 'model.param.set' only once and deal with a matrix rather than several times deal with an element each time.

Thanks for the help in advance.

Best regards
Yanrui

1 Reply Last Post Dec 30, 2014, 7:32 p.m. EST

Please login with a confirmed email address before reporting spam

Posted: 10 years ago Dec 30, 2014, 7:32 p.m. EST
more explanation of the problem

I use genetic algorithm to optimize a design which is simulated in comsol

I ran profile in matlab and since I can't reduce the time costed by comsol built in function, I am trying to reduce the time that comsol functions being called. Let the functions do more work each time by vectorization.

now my code is like

parfor k=1:size(x,1);

model.para.set ('p_1',x(k,1));
model.para.set ('p_2',x(k,2));
model.para.set ('p_1',x(k,3));
...
end
This code will call 'model.para.set' amount of time during running.
if it is able to write like

parfor k=1:size(x,1);
model.para.set ({'p_1' 'p_2' 'p_3'},{x(k,1) x(k,2) x(k,3)});
...
end

which is wrong but could reduce the calling time to almost 1/3.

Further more, the code is somehow like

j=1:3; %three variables need to optimized
k=1:size(x,1);
model.para.set (p(k,j),x(k,j));

which apparently wrong but may reduce the calling time to very few times. besides I may even could use some matlab function like 'arrayfun' later on.

I check use manual and found assign 'pname' could change parameter set to variable in comsol. However I think it is only possible for some special case, such as parameter swept or some comsol built in optimization.
And even 'pname' is not the way I want.

Any ideas about this problem?

Thanks.
more explanation of the problem I use genetic algorithm to optimize a design which is simulated in comsol I ran profile in matlab and since I can't reduce the time costed by comsol built in function, I am trying to reduce the time that comsol functions being called. Let the functions do more work each time by vectorization. now my code is like parfor k=1:size(x,1); model.para.set ('p_1',x(k,1)); model.para.set ('p_2',x(k,2)); model.para.set ('p_1',x(k,3)); ... end This code will call 'model.para.set' amount of time during running. if it is able to write like parfor k=1:size(x,1); model.para.set ({'p_1' 'p_2' 'p_3'},{x(k,1) x(k,2) x(k,3)}); ... end which is wrong but could reduce the calling time to almost 1/3. Further more, the code is somehow like j=1:3; %three variables need to optimized k=1:size(x,1); model.para.set (p(k,j),x(k,j)); which apparently wrong but may reduce the calling time to very few times. besides I may even could use some matlab function like 'arrayfun' later on. I check use manual and found assign 'pname' could change parameter set to variable in comsol. However I think it is only possible for some special case, such as parameter swept or some comsol built in optimization. And even 'pname' is not the way I want. Any ideas about this problem? Thanks.

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.