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 continue matlab code if Comsol solver did not converge?

Please login with a confirmed email address before reporting spam

Hi,

I am a student in engineer and I have to use comsol for my thesis.
To optimize the results of the model I build, I use a genetic algorithm I made in matlab.
I use Comsol 4.4 and matlab R2015a. LiveLink Comsol with Matlab too.

Here is a small description of my model :
- 1D model
- heat transfer in solids, heat flux and radiation
- Time dependent
- heat capacity and thermal conductivity are user defined and function of the temperature
- geometry : interval of 15mm

How work the algorithm for each iteration :
- It loads my model (mphload(...))
- It choose a value for the thermal conductivity (function of temerature) determined by the algorithm
- It puts the value in my model (model.param.set(...))
- It runs the solver (model.sol('sol1').runAll)
- It compares comsol results with experimental data (T = mpheval(...))
- It try again with another value for the thermal conductivity

After a lot of trial, my algorithm works good but sometimes I have an error saying "Nonlinear solver did not converge" and it returns an error in matlab and stop my algorithm.
To avoid this problem, I search a way to say T = 0 if the solver did not converge. So, my algorithm can continue and I can expect a result at the end.
I hope someone has a solution because when it runs, I can just expect that there will allways be a solution that converge...

You can find a part of the code here :
model = mphload('TestCom.mph'); % load model

% Determination of the thickness
model.geom('geom1').feature('i1').set('p2',th);
model.geom('geom1').run;

% Determination of the thermal conductivity (kf) function of temperature (TOP)
for kk = 1:1:np
name1 = sprintf('TOP%g',kk);
name2 = sprintf('kf%g',kk);
model.param.set(name1, sprintf('%g [K]',TOPTryd(kk)));
model.func('int6').setIndex('table',name1,kk-1,0);
model.param.set(name2, sprintf('%g [W/(m*K)]',kfTryd(kk)));
model.func('int6').setIndex('table',name2,kk-1, 1);
end

ModelUtil.showProgress(true); % display the progress bar
pause(eps)
model.sol('sol1').runAll; % solve
T = mpheval(model,'T','selection',2,'edim','boundary'); % extract and store data
ModelUtil.remove('model') % remove model because it will be reloaded on every loop

1 Reply Last Post 2016年6月24日 GMT-4 18:00
COMSOL Moderator

Hello Adrien Dehan

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.


Krishnaswamy Veluswamy

Please login with a confirmed email address before reporting spam

Posted: 8 years ago 2016年6月24日 GMT-4 18:00
HI
have you found the solution..?

I am currently having the same problem..

please share me if you know..

-krishnaswamy
HI have you found the solution..? I am currently having the same problem.. please share me if you know.. -krishnaswamy

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.