As a practice to learn MATLAB live link, I try to write a MATLAB code which is able to duplicate the results made by "Heating with a Moving Laser" model available on the COMSOL website. I am highly thankful, if someone mention where my mistake in the following code is (If you run the following code in MATLAB, there is no Bug in the code but there is also no result).
Thanks in advance for your great help
model = ModelUtil.create('Model');
model.param.set('P_in', '50[W]', 'Laser beam power');
model.param.set('r', '2[cm]', 'Radius of trajectory circle');
model.param.set('omega', '10[rad/s]', 'Angular velocity');
model.modelNode.create('mod1');
model.modelNode.create('mod2');
geom1=model.geom.create('geom1', 3);
geom1.model('mod1');
B1 = geom1.feature.create('B1', 'Block');
B1.setIndex('size', '0.1', 0);
B1.setIndex('size', '0.1', 1);
B1.setIndex('size', '0.01', 2);
C1 = geom1.feature.create('C1', 'Cylinder');
C1.set('r',0.02);
C1.set('h',0.01);
C1.setIndex('pos', '0.05', 0);
C1.setIndex('pos', '0.05', 1);
mesh1=model.mesh.create('mesh1', 'geom1');
mesh1.feature.create('swe1', 'Sweep');
mesh1.feature.create('ftet1', 'FreeTet');
mesh1.feature('swe1').selection.geom('geom1', 3);
mesh1.feature('swe1').selection.set([1 2]);
mesh1.feature('swe1').set('facemethod', 'tri');
mesh1.feature('swe1').selection('sourceface').set([4 9]);
mesh1.feature('swe1').selection('targetface').set([3 8]);
mesh1.run
geom2=model.geom.create('geom2', 1);
geom2.model('mod2');
geom2.feature.create('i1', 'Interval');
mesh2=model.mesh.create('mesh2', 'geom2');
mesh2.feature.create('size1', 'Size');
mesh2.feature.create('edg1', 'Edge');
mesh2.feature('size1').selection.geom('geom2', 0);
mesh2.feature('size1').selection.set(2);
mesh2.feature('size').set('custom', 'on');
mesh2.feature('size').set('hmax', '6.6667E-5');
mesh2.feature('size1').set('custom', 'on');
mesh2.feature('size1').set('hmaxactive', true);
mesh2.feature('size1').set('hgrad', '1.1');
mesh2.feature('size1').set('hmax', '1e-5');
mesh2.feature('size1').set('hgradactive', true);
mesh2.run
var1=model.variable.create('var1');
var1.model('mod2');
var1.set('k_abs', '8e3[1/m]-10[1/(K*m)]*(T-300[K])', 'Absorption coefficient');
var1.set('I_abs', 'k_abs*I', 'Relative absorption');
cplvar1=model.variable.create('cplvar1');
cplvar1.model('mod1');
cplvar1.set('extrcpl_source_T', 'T');
cplvar1.selection.geom('geom1', 3);
model.variable('cplvar1').selection.set([1 2]);
cplvar2=model.variable.create('cplvar2');
cplvar2.model('mod2');
cplvar2.set('T', 'mod1.genext1(extrcpl_source_T)');
cplvar2.selection.geom('geom2', 1);
cplvar2.selection.set(1);
mat1=model.material.create('mat1');
mat1.model('mod1');
mat1.propertyGroup.create('Enu', 'Young''s modulus and Poisson''s ratio');
mat1.propertyGroup.create('RefractiveIndex', 'Refractive index');
mat1.name('Silicon');
mat1.propertyGroup('def').set('heatcapacity', '703[J/(kg*K)]');
mat1.propertyGroup('def').set('thermalexpansioncoefficient', {'4.15e-6[1/K]' '0' '0' '0' '4.15e-6[1/K]' '0' '0' '0' '4.15e-6[1/K]'});
mat1.propertyGroup('def').set('relpermittivity', {'12.1' '0' '0' '0' '12.1' '0' '0' '0' '12.1'});
mat1.propertyGroup('def').set('thermalconductivity', {'163[W/(m*K)]' '0' '0' '0' '163[W/(m*K)]' '0' '0' '0' '163[W/(m*K)]'});
mat1.propertyGroup('def').set('relpermeability', {'1' '0' '0' '0' '1' '0' '0' '0' '1'});
mat1.propertyGroup('def').set('density', '2330[kg/m^3]');
mat1.propertyGroup('def').set('electricconductivity', {'1e-12[S/m]' '0' '0' '0' '1e-12[S/m]' '0' '0' '0' '1e-12[S/m]'});
mat1.propertyGroup('Enu').set('youngsmodulus', '131E9[Pa]');
mat1.propertyGroup('Enu').set('poissonsratio', '0.27');
mat1.propertyGroup('RefractiveIndex').set('n', '');
mat1.propertyGroup('RefractiveIndex').set('ki', '');
mat1.propertyGroup('RefractiveIndex').set('n', {'3.48' '0' '0' '0' '3.48' '0' '0' '0' '3.48'});
mat1.propertyGroup('RefractiveIndex').set('ki', {'0' '0' '0' '0' '0' '0' '0' '0' '0'});
ht=model.physics.create('ht', 'HeatTransfer', 'geom1');
w=model.physics.create('w', 'WeakFormPDE', 'geom2');
w.field('dimensionless').field('I');
w.field('dimensionless').component({'I'});
wfeq2=w.feature.create('wfeq2', 'WeakFormPDE', 1);
wfeq2.selection.set(1);
constr1=w.feature.create('constr1', 'PointwiseConstraint', 0);
constr1.selection.set(2);
genext1=model.cpl.create('genext1', 'GeneralExtrusion', 'geom1');
genext1.selection.set([1 2]);
genext1.set('dstmap', {'r*sin(omega*t)' 'r*cos(omega*t)' 'x'});
genext1.set('srcframe', 'material');
genext1.set('usesrcmap', 'on');
ht.prop('ShapeProperty').set('order_temperature', '1');
ht.feature('solid1').set('k_mat', 'userdef');
ht.feature('solid1').set('k', {'163'; '0'; '0'; '0'; '163'; '0'; '0'; '0'; '16'});
ht.feature('init1').set('T', '300');
w.feature('wfeq1').set('weak', '0');
w.feature('init1').set('I', '1');
w.feature('wfeq2').set('weak', '(Ix-I_abs)*test(I)+I_abs*P_in*test(T)');
w.feature('constr1').set('constraintExpression', '1-I');
model.frame('material1').sorder(1);
model.study.create('std1');
model.study('std1').feature.create('time', 'Transient');
sol1=model.sol.create('sol1');
sol1.study('std1');
sol1.attach('std1');
sol1.feature.create('st1', 'StudyStep');
sol1.feature.create('v1', 'Variables');
sol1.feature.create('t1', 'Time');
sol1.feature('t1').feature.create('fc1', 'FullyCoupled');
sol1.feature('t1').feature.create('d1', 'Direct');
sol2=model.sol.create('sol2');
sol2.study('std1');
model.study('std1').feature('time').set('initstudyhide', 'on');
model.study('std1').feature('time').set('initsolhide', 'on');
model.study('std1').feature('time').set('notstudyhide', 'on');
model.study('std1').feature('time').set('notsolhide', 'on');
model.result.dataset('dset3').selection.geom('geom1', 3);
model.result.dataset('dset3').selection.set([1 2]);
model.result.create('pg1', 'PlotGroup3D');
model.result.create('pg2', 'PlotGroup1D');
model.result('pg1').feature.create('surf1', 'Surface');
model.result('pg2').feature.create('lngr1', 'LineGraph');
model.study('std1').feature('time').set('rtolactive', true);
model.study('std1').feature('time').set('tlist', 'range(0,0.02,1)');
model.study('std1').feature('time').set('mesh', {'geom1' 'mesh1' 'geom2' 'mesh2'});
model.sol('sol1').attach('std1');
model.sol('sol1').feature('st1').name('Compile Equations: Time Dependent');
model.sol('sol1').feature('st1').set('studystep', 'time');
model.sol('sol1').feature('v1').set('solnum', 'auto');
model.sol('sol1').feature('v1').set('initsol', 'sol2');
model.sol('sol1').feature('v1').set('notsolnum', 'auto');
model.sol('sol1').feature('v1').set('notsol', 'sol2');
model.sol('sol1').feature('v1').set('control', 'time');
model.sol('sol1').feature('t1').set('storeudot', false);
model.sol('sol1').feature('t1').set('control', 'time');
model.sol('sol1').feature('t1').set('tlist', 'range(0,0.02,1)');
model.sol('sol1').feature('t1').set('bwinitstepfrac', '1.0');
model.sol('sol1').feature('t1').set('atolglobalmethod', 'unscaled');
model.sol('sol1').feature('t1').set('atolglobal', '1');
model.sol('sol1').feature('t1').set('solfile', false);
model.sol('sol1').feature('t1').feature('fc1').active(false);
model.sol('sol1').feature('t1').feature('fc1').set('damp', '1.0');
model.sol('sol1').feature('t1').feature('fc1').set('ratelimitactive', true);
model.sol('sol1').feature('t1').feature('d1').set('errorchk', 'off');
model.sol('sol2').name('COMSOL 4.3b Solution');
model.sol('sol2').runAll;
model.result('pg1').set('data', 'dset3');
model.result('pg1').set('solnum', '1');
model.result('pg1').set('solrepresentation', 'solnum');
model.result('pg1').feature('surf1').set('colortable', 'Thermal');
mphplot(model,'pg1','rangenum',1)
Thanks in advance for your great help
model = ModelUtil.create('Model');
model.param.set('P_in', '50[W]', 'Laser beam power');
model.param.set('r', '2[cm]', 'Radius of trajectory circle');
model.param.set('omega', '10[rad/s]', 'Angular velocity');
model.modelNode.create('mod1');
model.modelNode.create('mod2');
geom1=model.geom.create('geom1', 3);
geom1.model('mod1');
B1 = geom1.feature.create('B1', 'Block');
B1.setIndex('size', '0.1', 0);
B1.setIndex('size', '0.1', 1);
B1.setIndex('size', '0.01', 2);
C1 = geom1.feature.create('C1', 'Cylinder');
C1.set('r',0.02);
C1.set('h',0.01);
C1.setIndex('pos', '0.05', 0);
C1.setIndex('pos', '0.05', 1);
mesh1=model.mesh.create('mesh1', 'geom1');
mesh1.feature.create('swe1', 'Sweep');
mesh1.feature.create('ftet1', 'FreeTet');
mesh1.feature('swe1').selection.geom('geom1', 3);
mesh1.feature('swe1').selection.set([1 2]);
mesh1.feature('swe1').set('facemethod', 'tri');
mesh1.feature('swe1').selection('sourceface').set([4 9]);
mesh1.feature('swe1').selection('targetface').set([3 8]);
mesh1.run
geom2=model.geom.create('geom2', 1);
geom2.model('mod2');
geom2.feature.create('i1', 'Interval');
mesh2=model.mesh.create('mesh2', 'geom2');
mesh2.feature.create('size1', 'Size');
mesh2.feature.create('edg1', 'Edge');
mesh2.feature('size1').selection.geom('geom2', 0);
mesh2.feature('size1').selection.set(2);
mesh2.feature('size').set('custom', 'on');
mesh2.feature('size').set('hmax', '6.6667E-5');
mesh2.feature('size1').set('custom', 'on');
mesh2.feature('size1').set('hmaxactive', true);
mesh2.feature('size1').set('hgrad', '1.1');
mesh2.feature('size1').set('hmax', '1e-5');
mesh2.feature('size1').set('hgradactive', true);
mesh2.run
var1=model.variable.create('var1');
var1.model('mod2');
var1.set('k_abs', '8e3[1/m]-10[1/(K*m)]*(T-300[K])', 'Absorption coefficient');
var1.set('I_abs', 'k_abs*I', 'Relative absorption');
cplvar1=model.variable.create('cplvar1');
cplvar1.model('mod1');
cplvar1.set('extrcpl_source_T', 'T');
cplvar1.selection.geom('geom1', 3);
model.variable('cplvar1').selection.set([1 2]);
cplvar2=model.variable.create('cplvar2');
cplvar2.model('mod2');
cplvar2.set('T', 'mod1.genext1(extrcpl_source_T)');
cplvar2.selection.geom('geom2', 1);
cplvar2.selection.set(1);
mat1=model.material.create('mat1');
mat1.model('mod1');
mat1.propertyGroup.create('Enu', 'Young''s modulus and Poisson''s ratio');
mat1.propertyGroup.create('RefractiveIndex', 'Refractive index');
mat1.name('Silicon');
mat1.propertyGroup('def').set('heatcapacity', '703[J/(kg*K)]');
mat1.propertyGroup('def').set('thermalexpansioncoefficient', {'4.15e-6[1/K]' '0' '0' '0' '4.15e-6[1/K]' '0' '0' '0' '4.15e-6[1/K]'});
mat1.propertyGroup('def').set('relpermittivity', {'12.1' '0' '0' '0' '12.1' '0' '0' '0' '12.1'});
mat1.propertyGroup('def').set('thermalconductivity', {'163[W/(m*K)]' '0' '0' '0' '163[W/(m*K)]' '0' '0' '0' '163[W/(m*K)]'});
mat1.propertyGroup('def').set('relpermeability', {'1' '0' '0' '0' '1' '0' '0' '0' '1'});
mat1.propertyGroup('def').set('density', '2330[kg/m^3]');
mat1.propertyGroup('def').set('electricconductivity', {'1e-12[S/m]' '0' '0' '0' '1e-12[S/m]' '0' '0' '0' '1e-12[S/m]'});
mat1.propertyGroup('Enu').set('youngsmodulus', '131E9[Pa]');
mat1.propertyGroup('Enu').set('poissonsratio', '0.27');
mat1.propertyGroup('RefractiveIndex').set('n', '');
mat1.propertyGroup('RefractiveIndex').set('ki', '');
mat1.propertyGroup('RefractiveIndex').set('n', {'3.48' '0' '0' '0' '3.48' '0' '0' '0' '3.48'});
mat1.propertyGroup('RefractiveIndex').set('ki', {'0' '0' '0' '0' '0' '0' '0' '0' '0'});
ht=model.physics.create('ht', 'HeatTransfer', 'geom1');
w=model.physics.create('w', 'WeakFormPDE', 'geom2');
w.field('dimensionless').field('I');
w.field('dimensionless').component({'I'});
wfeq2=w.feature.create('wfeq2', 'WeakFormPDE', 1);
wfeq2.selection.set(1);
constr1=w.feature.create('constr1', 'PointwiseConstraint', 0);
constr1.selection.set(2);
genext1=model.cpl.create('genext1', 'GeneralExtrusion', 'geom1');
genext1.selection.set([1 2]);
genext1.set('dstmap', {'r*sin(omega*t)' 'r*cos(omega*t)' 'x'});
genext1.set('srcframe', 'material');
genext1.set('usesrcmap', 'on');
ht.prop('ShapeProperty').set('order_temperature', '1');
ht.feature('solid1').set('k_mat', 'userdef');
ht.feature('solid1').set('k', {'163'; '0'; '0'; '0'; '163'; '0'; '0'; '0'; '16'});
ht.feature('init1').set('T', '300');
w.feature('wfeq1').set('weak', '0');
w.feature('init1').set('I', '1');
w.feature('wfeq2').set('weak', '(Ix-I_abs)*test(I)+I_abs*P_in*test(T)');
w.feature('constr1').set('constraintExpression', '1-I');
model.frame('material1').sorder(1);
model.study.create('std1');
model.study('std1').feature.create('time', 'Transient');
sol1=model.sol.create('sol1');
sol1.study('std1');
sol1.attach('std1');
sol1.feature.create('st1', 'StudyStep');
sol1.feature.create('v1', 'Variables');
sol1.feature.create('t1', 'Time');
sol1.feature('t1').feature.create('fc1', 'FullyCoupled');
sol1.feature('t1').feature.create('d1', 'Direct');
sol2=model.sol.create('sol2');
sol2.study('std1');
model.study('std1').feature('time').set('initstudyhide', 'on');
model.study('std1').feature('time').set('initsolhide', 'on');
model.study('std1').feature('time').set('notstudyhide', 'on');
model.study('std1').feature('time').set('notsolhide', 'on');
model.result.dataset('dset3').selection.geom('geom1', 3);
model.result.dataset('dset3').selection.set([1 2]);
model.result.create('pg1', 'PlotGroup3D');
model.result.create('pg2', 'PlotGroup1D');
model.result('pg1').feature.create('surf1', 'Surface');
model.result('pg2').feature.create('lngr1', 'LineGraph');
model.study('std1').feature('time').set('rtolactive', true);
model.study('std1').feature('time').set('tlist', 'range(0,0.02,1)');
model.study('std1').feature('time').set('mesh', {'geom1' 'mesh1' 'geom2' 'mesh2'});
model.sol('sol1').attach('std1');
model.sol('sol1').feature('st1').name('Compile Equations: Time Dependent');
model.sol('sol1').feature('st1').set('studystep', 'time');
model.sol('sol1').feature('v1').set('solnum', 'auto');
model.sol('sol1').feature('v1').set('initsol', 'sol2');
model.sol('sol1').feature('v1').set('notsolnum', 'auto');
model.sol('sol1').feature('v1').set('notsol', 'sol2');
model.sol('sol1').feature('v1').set('control', 'time');
model.sol('sol1').feature('t1').set('storeudot', false);
model.sol('sol1').feature('t1').set('control', 'time');
model.sol('sol1').feature('t1').set('tlist', 'range(0,0.02,1)');
model.sol('sol1').feature('t1').set('bwinitstepfrac', '1.0');
model.sol('sol1').feature('t1').set('atolglobalmethod', 'unscaled');
model.sol('sol1').feature('t1').set('atolglobal', '1');
model.sol('sol1').feature('t1').set('solfile', false);
model.sol('sol1').feature('t1').feature('fc1').active(false);
model.sol('sol1').feature('t1').feature('fc1').set('damp', '1.0');
model.sol('sol1').feature('t1').feature('fc1').set('ratelimitactive', true);
model.sol('sol1').feature('t1').feature('d1').set('errorchk', 'off');
model.sol('sol2').name('COMSOL 4.3b Solution');
model.sol('sol2').runAll;
model.result('pg1').set('data', 'dset3');
model.result('pg1').set('solnum', '1');
model.result('pg1').set('solrepresentation', 'solnum');
model.result('pg1').feature('surf1').set('colortable', 'Thermal');
mphplot(model,'pg1','rangenum',1)