Custom Mathematical Operations
Allows the user to augment the functionality of OPTISCAN through use of custom mathematical electric field calculations.
Overview:
In order to use a Custom Mathematical Operation object, you need to create an m-file which uses the following function declaration formation:
function [mop, curlink, simdata, errmsg] = function_name(action, mop curlink, simdata);
if the function call is successful, the the function should set the output variable as follows:
errmsg = ”;
if the function call is not successful, and therefore the simulation should be stopped, then errmsg should be set equal to a description of the error that occurred:
errmsg = ‘The Input Field Cannot be Zero’;
Sometimes it is important for the mathematical operation to know what kind of input link is connected to it. This can be done by querying curlink for its linktype :
if istransmitted(curlink) %the input linktype is transmitted elseif isreflected(curlink) %the input linktype is reflected else %an electric field is not explicitly being transmitted to %the MOP object. end
For the following configuration:
the istransmitted(curlink) function would return “true” since the input link is propagating transmitted electric fields to the MOP object. The electric fields can be retrieved through the simdata variable:
transmitted fields
Ext = simdata.Ext
Eyt = simdata.Eyt
Ezt = simdata.Ezt
reflected fields
Exr = simdata.Exr
Eyt = simdata.Eyr
Ezt = simdata.Ezr
The ordinate and abcissa vectors can be similarly queried using:
sysxvec = simdata.sysxvec; %x-positions of each column
sysyvec = simdata.sysyvec; %y-positions of each row
After the function is finished modifying the fields and/or the ordinate and abcissa vectors, it needs to update the simdata variable using:
simdate.Ext = Ext;
simdata.Eyt = Eyt;
etc….
The MOP function may wish to save some information between invocations. The simdata variable allows the function to retrieve the custom “user data” that is associated with a specific MOP object by using:
userdata = simdata.userdata
if isempty(userdata) %need to initialize the userdata userdata.sinvector = sin( linspace(0,2*pi,100); userdata.cosvector = cos( linspace(0,2*pi,100); end
After the custom “user data” is initialized and/or updated, it can be stored by using:
simdata.userdata = userdata;
The following is a list of other simdata properties that may be useful:
- simdata.NHighNA – number of samples to use for High Numerical Aperature optics calculations.
- simdata.NLowNa – number of samples to use for Low Numerical Aperature optics calculations.
- simdata.LAMBDA – the current value for LAMBDA
- simdata.SourceType – 1 for coherent, 2 for incoherent.
- simdata.SourceTypePoints – number of source points for an incoherent source.
- simdata.PointCount – current source point number for an incoherent source.
- simdata.VisitCount – number of times that the current object has been calculated.
The project directory may be determined using:
project_path = fullfile(mop,”,”);
Example – this simple MOP function calculates the Total Aerial Irradiance of the input fields and stores it in Ext:
function [mop, curlink, simdata, errmsg] = mymop(action, mop, curlink, simdata) errmsg = ''; %retreive the desired electric fields: if istransmitted(curlink) ex = simdata.Ext; ey = simdata.Eyt; ez = simdata.Ezt; elseif istransmitted(curlink) ex = simdata.Exr; ey = simdata.Eyr; ez = simdata.Ezr; else errmsg = 'Need an Input Link!'; return; end; %store the calculated "Total Aerial Irradiance" in ex: ex = 3*10^8*0.5*8.85e-12*(abs(ex).^2+abs(ey).^2+abs(ez).^2); % set the other fields to 0 ey = 0; ez = 0; %update the source fieds simdata.Ext = ex; simdata.Eyt = ey; simdata.Ezt = ez; simdata.Exr = 0; simdata.Eyr = 0; simdata.Ezr = 0;
An example system where this script might be used is calculating the Total Aerial Irradiance of a source, even though the Source Editor can do this for you without any programming at all:
Configurable Variables – A MOP function can be used in conjunction with a Delta Object. For more information about this advanced feature, see the information on Configurable Variables.
– Delta Object used with a MOP object.