/*
*   GratingCoupler Class
*
*   Methods for:
*       determining the refractive index of a waveguiding thin film
*       in an asymmetric slab waveguide from the grating coupling angle and the core layer thickness
*       and for obtaining the normalised propagation vector versus guiding layer thickness
*
*       determinimg the refractive index of the superstrate [analyte solution in a grating coupler sensor]
*
*       obtaining the normalised propagation vector versus guiding layer thickness
*       dispersion curve for an asymmetric slab waveguide
*
*   This is a subclass of the superclasses PlanarWaveguideCoupler
*
*   Author:  Dr Michael Thomas Flanagan.
*
*   Created: 28 April 2006
*
*   DOCUMENTATION:
*   See Michael Thomas Flanagan's Java library on-line web page:
*   http://www.ee.ucl.ac.uk/~mflanaga/java/GratingCoupler.html
*   http://www.ee.ucl.ac.uk/~mflanaga/java/
*
*   Copyright (c) April 2006   Michael Thomas Flanagan
*
*   PERMISSION TO COPY:
*   Permission to use, copy and modify this software and its documentation for
*   NON-COMMERCIAL purposes is granted, without fee, provided that an acknowledgement
*   to the author, Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies.
*
*   Dr Michael Thomas Flanagan makes no representations about the suitability
*   or fitness of the software for any or for a particular purpose.
*   Michael Thomas Flanagan shall not be liable for any damages suffered
*   as a result of using, modifying or distributing this software or its derivatives.
*
***************************************************************************************/

package flanagan.optics;

import flanagan.math.Fmath;
import flanagan.analysis.ErrorProp;
import flanagan.plot.*;
import flanagan.optics.*;

public class GratingCoupler extends PlanarWaveguide{

    // CLASS VARIABLES

    private double[] thicknessesTE = null;      // thicknesses for experimental TE mode thimeasurements
    private double[] anglesDegTE = null;        // coupling angles, in degrees, for experimental TE mode measurements
    private double[] anglesRadTE = null;        // coupling angles, in radians, for experimental TE mode measurements
    private double[] errorsDegTE = null;        // errors in coupling angles, in degrees, for experimental TE mode measurements
    private double[] errorsRadTE = null;        // errors in coupling angles, in radians, for experimental TE mode measurements
    private double[] modeNumbersTE = null;      // mode numbers for experimental TE mode measurements
    private double[] effectiveRefractiveIndicesTE = null;   // effective refractive indices for TE mode measurements
    private double[] effectiveErrorsTE = null;  // propagated errors for effective refractive indices for TE mode measurements
    private int numberOfTEmeasurementsGrating = 0; // number of TE mode thickness measurement
    private boolean setMeasurementsTEgrating = false; // = true when TE mode measurements entered
    private boolean setTEerrors = false;        // = true if TE mode errors are set

    private boolean calcEffectiveDone = false;  // = true when effective refractive indices calculated

    private double[] thicknessesTM = null;      // thicknesses for experimental TM mode thimeasurements
    private double[] anglesDegTM = null;        // coupling angles, in degrees, for experimental TM mode measurements
    private double[] anglesRadTM = null;        // coupling angles, in radians, for experimental TM mode measurements
    private double[] errorsDegTM = null;        // errors in coupling angles, in degrees, for experimental TM mode measurements
    private double[] errorsRadTM = null;        // errors in coupling angles, in radians, for experimental TM mode measurements
    private double[] modeNumbersTM = null;      // mode numbers for experimental TM mode measurements
    private double[] effectiveRefractiveIndicesTM = null;   // effective refractive indices for TM mode measurements
    private double[] effectiveErrorsTM = null;  // propagated errors for effective refractive indices for TM mode measurements
    private int numberOfTMmeasurementsGrating = 0; // number of TM mode thickness measurement
    private boolean setMeasurementsTMgrating = false;    // = true when TM mode measurements entered
    private boolean setTMerrors = false;        // = true if TM mode errors are set

    private int numberOfMeasurementsGrating = 0;  // total number of thickness measurements entered
    private boolean setMeasurementsGrating = false;    // = true when TE and/or TM mode measurements entered

    private double gratingPitch = 0.0D;         // Grating pitch, metres
    private boolean setGratingPitch = false;    // = true when grating pitch entered
    private int[] gratingOrderTE = null;        // Grating order for each TE mode measurement, default value = 1
    private boolean setGratingOrderTE = false;  // = true when TE mode grating orders entered
    private int[] gratingOrderTM = null;        // Grating order for each TM mode measurement, default value = 1
    private boolean setGratingOrderTM = false;  // = true when TM mode grating orders entered

    private double superstrateRI = 0.0;         // Superstrate refractive index
    private boolean setSuperstrateRI = false;   // equals true when superstrate refractice index entered

    // CONSTRUCTOR
    public GratingCoupler(){
    }


    // GRATING
    // Enter pitch
    public void setGratingPitch(double pitch){
        this.gratingPitch = pitch;
        this.setGratingPitch = true;
        if(this.setMeasurementsGrating && super.setWavelength)this.calcEffectiveRefractiveIndices();
    }

    // Enter grating orders for TE measurements
    public void setSetTEmodeGratingOrder(int[] order){
        this.gratingOrderTE = order;
        int m = order.length;
        if(this.setMeasurementsTEgrating)if(m!=this.numberOfTEmeasurementsGrating)throw new IllegalArgumentException("Number of grating orders entered, " + m + ", is not equal to the number of measurements previously entered, " + this.numberOfTEmeasurementsGrating);
        if(this.setMeasurementsGrating && this.setGratingPitch && super.setWavelength)this.calcEffectiveRefractiveIndices();
    }

    // Enter grating orders for TM measurements
    public void setSetTMmodeGratingOrder(int[] order){
        this.gratingOrderTM = order;
        int m = order.length;
        if(this.setMeasurementsTMgrating)if(m!=this.numberOfTMmeasurementsGrating)throw new IllegalArgumentException("Number of grating orders entered, " + m + ", is not equal to the number of measurements previously entered, " + this.numberOfTEmeasurementsGrating);
        if(this.setMeasurementsGrating && this.setGratingPitch && super.setWavelength)this.calcEffectiveRefractiveIndices();
    }

    // Enter superstrate refractive index (overrides superclass method)
    public void setSuperstrateRefractiveIndex(double index){
        if(this.calcEffectiveDone)this.clearData();
        this.superstrateRI = index;
        super.superstrateRefractiveIndex = index;
        this.setSuperstrateRI = true;
        if(this.setMeasurementsGrating && this.setGratingPitch && super.setWavelength)this.calcEffectiveRefractiveIndices();
    }


    // Return analyte solution refractive index
    public double getAnalyteSolutionRefractiveIndex(){
        return super.getSuperstrateRefractiveIndex();
    }

    // Return analyte solution refractive index
    public double getStandardDeviationAnalyteSolutionRefractiveIndex(){
        return super.getStandardDeviationSuperstrateRefractiveIndex();
    }


    // THICKNESS (metres), COUPLING ANGLE (degrees) AND MODE NUMBER DATA
    // Enter TE mode data for a single measurement without error
    public void enterTEmodeData(double thickness, double angle, double modeNumber){
        if(this.setMeasurementsTEgrating){
            if(this.setTEerrors)throw new IllegalArgumentException("All Entered data must either all have associated errors entered or all have no associated errors entered");
            int nNew = this.numberOfTEmeasurementsGrating + 1;
            double[] hold = new double[nNew];
            for(int i=0; i 

Ads help maintain this website.