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.

How to write several physics in a loop using LiveLink for Matlab?

Please login with a confirmed email address before reporting spam

Hi everyone,

I have a question related to the use of the LiveLink for Matlab. I am using COMSOL version 4.2a

In my problem I have to perform N models one after another. Each model uses two modules: heat transfer and pde. For each model, I run it and I save the results. In the next model, I add a geometric entity to which I need to assign another pde module, and the initial values for the other domains will be the results of the previous model. And so on until I reach the last domain.

I am trying to do this using the LiveLink for Matlab by performing a loop. At each loop the COMSOL model is run and results are saved. At each loop, a geometric entity is added as well as a new PDE node. This PDE node will be called 'cN', being N the loop number.

For adding geometric entities I have no problems and it works. However, I am having trouble to add new PDE nodes to assing to different domains... I am trying something like this:

for j = 1:N
c_j = ['c',num2str(j)];
model.physics.create('c_j', 'CoefficientFormPDE', 'geom1');
(...)
end

But I think this is not working... Plus, inside each PDE I will have the same equation. However, the variables need to be different. For example, I need to have variable 'V1' for PDE 'c', variable 'V2' for PDE 'c2', and so on... I have thought about defining a variable node for each domain. I would then have to write a group of variables 'varN' at each loop. I am trying something like this:

for j = 1:N
var_j = ['var',num2str(j)];
model.variable.create('var_j');
(...)
end

I have also tried something like: model.variable.create(num2str(var_j));
or even
model.variable.create('',num2str(var_j),'');

Does anyone have some ideas about how I can solve this?
Any help would be appreciated, thank you!
Hope I was clear about my question...

Ana Gaspar


0 Replies Last Post Mar 13, 2012, 9:04 a.m. EDT
COMSOL Moderator

Hello Ana Gaspar

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.