import com.comsol.model.* import com.comsol.model.util.* %imports necessary libraries model= ModelUtil.create('Model'); %creates model object geometry = model.geom.create('geometry',2); %creates geometry object, 2 defines it as 2 Dimensional model.param.set('BoxWidth','2[nm]'); model.param.set('SlitWidth','0.1[nm]'); model.param.set('ScreenHeight','0.1[nm]'); model.param.set('ScreenWidth','(BoxWidth-SlitWidth)/2'); %defines parameters that are used for any part of the script BoxWidth=mphevaluate(model,'BoxWidth'); SlitWidth=mphevaluate(model,'SlitWidth'); ScreenWidth=mphevaluate(model,'ScreenWidth'); ScreenHeight=mphevaluate(model,'ScreenHeight'); %outputs the parameters we defined sq1 = geometry.feature.create('sq1','Square'); sq1.set('size',BoxWidth); sq1.set('base','corner'); %sets up largest square LeftScreen = geometry.feature.create('LeftScreen','Rectangle'); LeftScreen.set('size',[ScreenWidth ScreenHeight]); LeftScreen.set('pos',[BoxWidth /2-ScreenWidth/2-SlitWidth/2 BoxWidth/2]); LeftScreen.set('base','center'); %creates separation to the left of the slit RightScreen = geometry.feature.create('RightScreen','Rectangle'); RightScreen.set('size',[ScreenWidth ScreenHeight]); RightScreen.set('pos',[BoxWidth /2+ScreenWidth/2+SlitWidth/2 BoxWidth/2]); RightScreen.set('base','center'); %creates sepearation to the right of the slit model.geom('geometry').run; %builds geometry we predifined mesh1 = model.mesh.create('mesh1','geometry'); ftri1 = mesh1.feature.create('ftri1','FreeTri'); mesh1.feature('size').set('hauto','4'); mesh1.run; % Sets Mesh Size; Smaller numbers are more fine 1-9 %mphgeom(model,'geometry'); %mphmesh(model); %Displays Mesh model.material.create('mat1', 'Common'); model.material('mat1').materialType('nonSolid'); model.material('mat1').set('family', 'air'); model.material('mat1').propertyGroup.create('RefractiveIndex', 'Refractive index'); model.material('mat1').propertyGroup.create('NonlinearModel', 'Nonlinear model'); %defines the material used for air and its properties model.material('mat1').propertyGroup('RefractiveIndex').set('n', ''); model.material('mat1').propertyGroup('RefractiveIndex').set('ki', ''); model.material('mat1').propertyGroup('RefractiveIndex').set('n', {'1' '0' '0' '0' '1' '0' '0' '0' '1'}); model.material('mat1').propertyGroup('RefractiveIndex').set('ki', {'0' '0' '0' '0' '0' '0' '0' '0' '0'}); model.material('mat1').propertyGroup('def').set('relpermeability', {'1' '0' '0' '0' '1' '0' '0' '0' '1'}); model.material('mat1').propertyGroup('def').set('relpermittivity', {'1' '0' '0' '0' '1' '0' '0' '0' '1'}); model.material('mat1').propertyGroup('def').set('electricconductivity', {'0[S/m]' '0' '0' '0' '0[S/m]' '0' '0' '0' '0[S/m]'}); model.material('mat1').propertyGroup('NonlinearModel').set('BA', '(def.gamma+1)/2'); model.material('mat1').selection.set([1]); %gives values to its properties and assigns air to domain 1 model.material.create('mat2', 'Common'); model.material('mat2').label('Steel AISI 4340'); model.material('mat2').set('family', 'steel'); model.material('mat2').propertyGroup('def').set('relpermeability', {'1' '0' '0' '0' '1' '0' '0' '0' '1'}); model.material('mat2').propertyGroup('def').set('relpermittivity', {'1' '0' '0' '0' '1' '0' '0' '0' '1'}); model.material('mat2').propertyGroup('def').set('electricconductivity', {'4.032e6[S/m]' '0' '0' '0' '4.032e6[S/m]' '0' '0' '0' '4.032e6[S/m]'}); model.material('mat2').set('family', 'steel'); model.material('mat2').selection.set([2 3]); %defines the material used for steel and its properties, assigns steel to %domains 2 and 3 model.param.set('lambda', '500[nm]'); %defines parameter for wavelength model.physics.create('emw', 'ElectromagneticWaves', 'geometry'); model.physics('emw').create('port1', 'Port', 1); model.physics('emw').feature('port1').selection.set([2]); model.physics('emw').create('sctr1', 'Scattering', 1); model.physics('emw').feature('sctr1').selection.set([1 5 7 12 14]); model.physics('emw').create('init2', 'init', 2); model.physics('emw').feature('init2').selection.set([1 2 3]); %creates physics for the model, using emw model, defines boundaries model.physics('emw').feature('port1').set('E0', [1; 0; 0]); %sets initial values for the port model.study.create('study1'); model.study('study1').create('freq', 'Frequency'); %sets up study 1 for frequency domain model.sol.create('sol1'); model.sol('sol1').study('study1'); model.sol('sol1').attach('study1'); model.sol('sol1').create('st1', 'StudyStep'); model.sol('sol1').create('v1', 'Variables'); model.sol('sol1').create('s1', 'Stationary'); model.sol('sol1').feature('s1').create('p1', 'Parametric'); model.sol('sol1').feature('s1').create('fc1', 'FullyCoupled'); model.sol('sol1').feature('s1').create('d1', 'Direct'); model.sol('sol1').feature('s1').feature.remove('fcDef'); %Creates solution to study 1 model.result.numerical.create('gev1', 'EvalGlobal'); model.result.numerical('gev1').set('probetag', 'none'); model.result.create('pg1', 'PlotGroup2D'); model.result('pg1').create('surf1', 'Surface'); model.study('study1').feature('freq').set('plist', '(3*10^8)[m/s]/lambda'); model.study('study1').run; %runs study 1