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
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