function out = model % % induced_voltage_moving_magnet.m % % Model exported on Apr 2 2017, 17:31 by COMSOL 5.1.0.234. import com.comsol.model.* import com.comsol.model.util.* model = ModelUtil.create('Model'); model.modelPath('C:\Users\AMEY SUNIL KULKARNI\Desktop\academia\prosthetics\my work\comsol'); model.comments(['Untitled\n\n']); model.modelNode.create('comp1'); model.geom.create('geom1', 2); model.geom('geom1').axisymmetric(true); model.mesh.create('mesh1', 'geom1'); model.physics.create('mf', 'InductionCurrents', 'geom1'); model.physics.create('ale', 'MovingMesh', 'geom1'); model.study.create('std1'); model.study('std1').create('stat', 'Stationary'); model.study('std1').feature('stat').activate('mf', true); model.study('std1').feature('stat').activate('ale', true); model.param.set('f0', '4[Hz]'); model.param.descr('f0', 'Frequency of an oscillating magnet'); model.param.set('T0', '1/f0'); model.param.descr('T0', 'Time period of an oscillating magnet'); model.geom('geom1').lengthUnit('cm'); model.geom('geom1').create('r1', 'Rectangle'); model.geom('geom1').feature('r1').set('size', {'1' '2'}); model.geom('geom1').feature('r1').set('pos', {'0' '-1'}); model.geom('geom1').run('r1'); model.geom('geom1').run('r1'); model.geom('geom1').create('r2', 'Rectangle'); model.geom('geom1').feature('r2').set('size', {'1' '8'}); model.geom('geom1').feature('r2').set('pos', {'1.1' '-4'}); model.geom('geom1').run('r2'); model.geom('geom1').run('r2'); model.geom('geom1').create('r3', 'Rectangle'); model.geom('geom1').feature('r3').set('size', {'1' '12'}); model.geom('geom1').feature('r3').set('pos', {'0' '-6'}); model.geom('geom1').run('r3'); model.geom('geom1').run('r3'); model.geom('geom1').create('r4', 'Rectangle'); model.geom('geom1').feature('r4').set('size', {'3' '12'}); model.geom('geom1').feature('r4').set('pos', {'1' '-6'}); model.geom('geom1').run('r4'); model.geom('geom1').run('r4'); model.geom('geom1').create('uni1', 'Union'); model.geom('geom1').feature('uni1').selection('input').set({'r1' 'r3'}); model.geom('geom1').run('uni1'); model.geom('geom1').run('uni1'); model.geom('geom1').create('uni2', 'Union'); model.geom('geom1').feature('uni2').selection('input').set({'r2' 'r4'}); model.geom('geom1').run('uni2'); model.geom('geom1').feature('fin').set('repairtol', '1e-6'); model.geom('geom1').feature('fin').set('action', 'assembly'); model.geom('geom1').run('fin'); model.selection.create('sel1', 'Explicit'); model.selection('sel1').geom(1); model.selection('sel1').set([3 4 6 9]); model.selection('sel1').label('Magnet Boundaries'); model.selection.create('sel2', 'Explicit'); model.selection('sel2').geom(1); model.selection('sel2').set([8 9 10]); model.selection('sel2').label('Continuity Boundaries'); model.material.create('mat1', 'Common', 'comp1'); model.material('mat1').label('Air'); model.material('mat1').set('family', 'air'); model.material('mat1').propertyGroup('def').set('relpermeability', '1'); model.material('mat1').propertyGroup('def').set('relpermittivity', '1'); model.material('mat1').propertyGroup('def').set('dynamicviscosity', 'eta(T[1/K])[Pa*s]'); model.material('mat1').propertyGroup('def').set('ratioofspecificheat', '1.4'); model.material('mat1').propertyGroup('def').set('electricconductivity', '0[S/m]'); model.material('mat1').propertyGroup('def').set('heatcapacity', 'Cp(T[1/K])[J/(kg*K)]'); model.material('mat1').propertyGroup('def').set('density', 'rho(pA[1/Pa],T[1/K])[kg/m^3]'); model.material('mat1').propertyGroup('def').set('thermalconductivity', 'k(T[1/K])[W/(m*K)]'); model.material('mat1').propertyGroup('def').set('soundspeed', 'cs(T[1/K])[m/s]'); model.material('mat1').propertyGroup('def').func.create('eta', 'Piecewise'); model.material('mat1').propertyGroup('def').func('eta').set('funcname', 'eta'); model.material('mat1').propertyGroup('def').func('eta').set('arg', 'T'); model.material('mat1').propertyGroup('def').func('eta').set('extrap', 'constant'); model.material('mat1').propertyGroup('def').func('eta').set('pieces', {'200.0' '1600.0' '-8.38278E-7+8.35717342E-8*T^1-7.69429583E-11*T^2+4.6437266E-14*T^3-1.06585607E-17*T^4'}); model.material('mat1').propertyGroup('def').func.create('Cp', 'Piecewise'); model.material('mat1').propertyGroup('def').func('Cp').set('funcname', 'Cp'); model.material('mat1').propertyGroup('def').func('Cp').set('arg', 'T'); model.material('mat1').propertyGroup('def').func('Cp').set('extrap', 'constant'); model.material('mat1').propertyGroup('def').func('Cp').set('pieces', {'200.0' '1600.0' '1047.63657-0.372589265*T^1+9.45304214E-4*T^2-6.02409443E-7*T^3+1.2858961E-10*T^4'}); model.material('mat1').propertyGroup('def').func.create('rho', 'Analytic'); model.material('mat1').propertyGroup('def').func('rho').set('funcname', 'rho'); model.material('mat1').propertyGroup('def').func('rho').set('args', {'pA' 'T'}); model.material('mat1').propertyGroup('def').func('rho').set('expr', 'pA*0.02897/8.314/T'); model.material('mat1').propertyGroup('def').func('rho').set('dermethod', 'manual'); model.material('mat1').propertyGroup('def').func('rho').set('argders', {'pA' 'd(pA*0.02897/8.314/T,pA)'; 'T' 'd(pA*0.02897/8.314/T,T)'}); model.material('mat1').propertyGroup('def').func.create('k', 'Piecewise'); model.material('mat1').propertyGroup('def').func('k').set('funcname', 'k'); model.material('mat1').propertyGroup('def').func('k').set('arg', 'T'); model.material('mat1').propertyGroup('def').func('k').set('extrap', 'constant'); model.material('mat1').propertyGroup('def').func('k').set('pieces', {'200.0' '1600.0' '-0.00227583562+1.15480022E-4*T^1-7.90252856E-8*T^2+4.11702505E-11*T^3-7.43864331E-15*T^4'}); model.material('mat1').propertyGroup('def').func.create('cs', 'Analytic'); model.material('mat1').propertyGroup('def').func('cs').set('funcname', 'cs'); model.material('mat1').propertyGroup('def').func('cs').set('args', {'T'}); model.material('mat1').propertyGroup('def').func('cs').set('expr', 'sqrt(1.4*287*T)'); model.material('mat1').propertyGroup('def').func('cs').set('dermethod', 'manual'); model.material('mat1').propertyGroup('def').func('cs').set('argders', {'T' 'd(sqrt(1.4*287*T),T)'}); model.material('mat1').propertyGroup('def').addInput('temperature'); model.material('mat1').propertyGroup('def').addInput('pressure'); model.material('mat1').propertyGroup.create('RefractiveIndex', 'Refractive index'); model.material('mat1').propertyGroup('RefractiveIndex').set('n', '1'); model.material('mat1').set('family', 'air'); model.physics('mf').feature.create('al2', 'AmperesLaw', 2); model.physics('mf').feature('al2').selection.set([2]); model.physics('mf').feature('al2').set('ConstitutiveRelationH', 'RemanentFluxDensity'); model.physics('mf').feature('al2').set('Br', {'0' '0' '1.2'}); model.physics('mf').feature.create('mtcd1', 'MultiTurnCoilDomain', 2); model.physics('mf').feature('mtcd1').selection.set([5]); model.physics('mf').feature('mtcd1').set('N', '800'); model.physics('mf').feature('mtcd1').set('coilWindArea', 'pi*(0.5[mm])^2'); model.physics('mf').feature('mtcd1').set('ICoil', '0'); model.physics('mf').feature.create('cont1', 'Continuity', 1); model.physics('mf').feature('cont1').setIndex('pairs', 'ap1', 0); model.physics('mf').feature('cont1').set('weakConstraints', true); model.physics('mf').feature('cont1').feature('mi1').set('weakConstraints', true); model.physics('ale').selection.set([1 2 3]); model.physics('ale').feature.create('free1', 'FreeDeformation', 2); model.physics('ale').feature('free1').selection.set([1 2 3]); model.physics('ale').feature.create('disp2', 'PrescribedMeshDisplacement', 1); model.physics('ale').feature('disp2').selection.named('sel1'); model.physics('ale').feature('disp2').setIndex('dx', '30[mm]*sin(2*pi*f0*t)', 1); model.physics('ale').feature.create('disp3', 'PrescribedMeshDisplacement', 1); model.physics('ale').feature('disp3').selection.set([1 5 8 10]); model.physics('ale').feature('disp3').setIndex('useDx', '0', 1); model.mesh('mesh1').autoMeshSize(4); model.mesh('mesh1').create('size1', 'Size'); model.mesh('mesh1').feature('size1').selection.geom('geom1', 1); model.mesh('mesh1').feature('size1').selection.named('sel2'); model.mesh('mesh1').feature('size1').set('custom', 'on'); model.mesh('mesh1').feature('size1').set('hmaxactive', 'on'); model.mesh('mesh1').feature('size1').set('hmax', '3[mm]'); model.mesh('mesh1').create('ftri1', 'FreeTri'); model.mesh('mesh1').run; model.study('std1').feature('stat').set('physselection', 'mf'); model.study('std1').feature('stat').set('activate', {'mf' 'on' 'ale' 'off'}); model.study('std1').create('time', 'Transient'); model.study('std1').feature('time').set('tlist', 'range(0,T0/100,T0)'); model.study('std1').feature('time').set('rtolactive', 'on'); model.study('std1').feature('time').set('rtol', '0.0001'); model.sol.create('sol1'); model.sol('sol1').study('std1'); model.study('std1').feature('stat').set('notlistsolnum', 1); model.study('std1').feature('stat').set('notsolnum', '1'); model.study('std1').feature('stat').set('listsolnum', 1); model.study('std1').feature('stat').set('solnum', '1'); model.study('std1').feature('time').set('notlistsolnum', 1); model.study('std1').feature('time').set('notsolnum', 'auto'); model.study('std1').feature('time').set('listsolnum', 1); model.study('std1').feature('time').set('solnum', 'auto'); model.sol('sol1').create('st1', 'StudyStep'); model.sol('sol1').feature('st1').set('study', 'std1'); model.sol('sol1').feature('st1').set('studystep', 'stat'); model.sol('sol1').create('v1', 'Variables'); model.sol('sol1').feature('v1').set('control', 'stat'); model.sol('sol1').create('s1', 'Stationary'); model.sol('sol1').feature('s1').create('fc1', 'FullyCoupled'); model.sol('sol1').feature('s1').feature('fc1').set('linsolver', 'dDef'); model.sol('sol1').feature('s1').feature.remove('fcDef'); model.sol('sol1').create('su1', 'StoreSolution'); model.sol('sol1').create('st2', 'StudyStep'); model.sol('sol1').feature('st2').set('study', 'std1'); model.sol('sol1').feature('st2').set('studystep', 'time'); model.sol('sol1').create('v2', 'Variables'); model.sol('sol1').feature('v2').set('initmethod', 'sol'); model.sol('sol1').feature('v2').set('initsol', 'sol1'); model.sol('sol1').feature('v2').set('initsoluse', 'su1'); model.sol('sol1').feature('v2').set('notsolmethod', 'sol'); model.sol('sol1').feature('v2').set('notsol', 'sol1'); model.sol('sol1').feature('v2').set('notsoluse', 'su1'); model.sol('sol1').feature('v2').set('control', 'time'); model.sol('sol1').create('t1', 'Time'); model.sol('sol1').feature('t1').set('tlist', 'range(0,T0/100,T0)'); model.sol('sol1').feature('t1').set('plot', 'off'); model.sol('sol1').feature('t1').set('plotgroup', 'Default'); model.sol('sol1').feature('t1').set('plotfreq', 'tout'); model.sol('sol1').feature('t1').set('probesel', 'all'); model.sol('sol1').feature('t1').set('probes', {}); model.sol('sol1').feature('t1').set('probefreq', 'tsteps'); model.sol('sol1').feature('t1').set('control', 'time'); model.sol('sol1').feature('t1').create('seDef', 'Segregated'); model.sol('sol1').feature('t1').create('fc1', 'FullyCoupled'); model.sol('sol1').feature('t1').feature('fc1').set('linsolver', 'dDef'); model.sol('sol1').feature('t1').feature.remove('fcDef'); model.sol('sol1').feature('t1').feature.remove('seDef'); model.sol('sol1').attach('std1'); model.result.create('pg1', 'PlotGroup2D'); model.result('pg1').label('Magnetic Flux Density Norm (mf)'); model.result('pg1').set('oldanalysistype', 'noneavailable'); model.result('pg1').set('data', 'dset1'); model.result('pg1').feature.create('surf1', 'Surface'); model.result('pg1').feature('surf1').set('oldanalysistype', 'noneavailable'); model.result('pg1').feature('surf1').set('data', 'parent'); model.result.dataset.create('rev1', 'Revolve2D'); model.result.dataset('rev1').set('startangle', -90); model.result.dataset('rev1').set('revangle', 225); model.result.dataset('rev1').set('data', 'dset1'); model.result.create('pg2', 'PlotGroup3D'); model.result('pg2').label('Magnetic Flux Density Norm (mf) 1'); model.result('pg2').set('oldanalysistype', 'noneavailable'); model.result('pg2').set('data', 'rev1'); model.result('pg2').feature.create('surf1', 'Surface'); model.result('pg2').feature('surf1').set('oldanalysistype', 'noneavailable'); model.result('pg2').feature('surf1').set('data', 'parent'); model.sol('sol1').runAll; model.result('pg1').run; model.result('pg1').setIndex('looplevel', '81', 0); model.result('pg1').create('mesh1', 'Mesh'); model.result('pg1').feature('mesh1').set('elemcolor', 'none'); model.result('pg1').feature('mesh1').set('wireframecolor', 'white'); model.result('pg1').run; model.result.create('pg3', 'PlotGroup1D'); model.result('pg3').run; model.result('pg3').create('glob1', 'Global'); model.result('pg3').feature('glob1').set('expr', {'mf.VCoil_1'}); model.result('pg3').feature('glob1').set('descr', {'Coil voltage'}); model.result('pg3').feature('glob1').set('unit', {'V'}); model.result('pg3').run; model.result('pg3').run; model.result('pg3').label('Coil Induced Voltage'); model.comments(['Voltage Induced in a Coil by a Moving Magnet\n\nA magnet moving axially through the center of a coil will induce a voltage across the coil terminals. A practical application of this phenomenon is in shaker flashlights, where the flashlight is vigorously shaken back and forth, thereby causing a magnet to move through a multi-turn coil, which provides charge to the battery. This example models the motion of a magnet through a coil and computes the induced voltages. The displacement of the magnet is significant, so the example uses a moving and sliding mesh.']); model.label('induced_voltage_moving_magnet.mph'); model.result('pg3').run; out = model;