VB Script Function for Observation Line

Compatibility:

10 PowerAtCenterWavelength()

Purpose: Calculates power at the Center Wavelength. The Center Wavelength value is specified at the primary (key) Input Plane. All types of 2D (CW, GMCW) simulations support this function.

11 PowerAtWavelength( double dWavelength ) Arguments:

dWavelength– specifies a wavelength value for which the calculations should be performed. Wavelength value must be greater than zero.

Purpose: Calculates power at the specified Wavelength. This function should be used with 2D GMCW simulations. It can be used with 2D CW simulations as well. However, in this case it makes sense only when non- linear materials have been used to construct project components, and one can expect some harmonic frequencies to be generated.

12 CalcPowerSpectrum( dStartWavelength, dEndWavelength, nNumberOfPoints )

Arguments:

dStartWavelength– a double value of the spectrum start wavelength. Its value has to be smaller than the value of End Wavelength argument. dEndWavelength– a double value of the spectrum end wavelength. Its value has to be greater than the value of Start Wavelength value has to be greater than the value of Start Wavelength

nNumberOfPoints– an integer value of the number of sampling points within the spectrum. Its value has to be greater than one.

Purpose: Calculates power spectrum for the specified number of wavelength sampling points. This function can be used only with 2D GMCW simulations. When used with other type of simulations, the function will return zero as the power value.

13 GetPowerAtSpectralPoint( nPointIndex ) Arguments:

nPointIndex– an integer value of the spectral point. The points are indexed starting from zero.

Purpose: Retrieves a value of previously calculated power at the specified sampling point. The function will return zero if called before the CalcPowerSpectrum() has been executed.

14 CalcNormalizedPowerSpectrum( dStartWavelength, dEndWavelength, nNumberOfPoints, sInputPlaneLabel )

Arguments:

dStartWavelength– a double value of the spectrum start wavelength. Its value has to be smaller than the value of End Wavelength argument.

dEndWavelength– a double value of the spectrum end wavelength. Its value has to be greater than the value of Start Wavelength

nNumberOfPoints– an integer value of the number of sampling points within the spectrum. Its value has to be greater than one.

sInputPlaneLabel– label of the Input Plane, which signal is going to be used for normalization. The Input Plane with the specified label must be one of the active ones generating GMCW signal.

Purpose: Calculates power spectrum normalized to the power signal of the specified Input Plane, for the specified number of wavelength sampling points. This function can be used only with 2D GMCW simulations. When used with other type of simulations, the function will return zero as the power value.

Note: Normalization is calculated against an existing, active Input Plane. The Input Plane must generate GMCW signal.

15 GetNormalizedPowerAtSpectralPoint( nPointIndex ) Arguments:

nPointIndex– an integer value of the spectral point. The points are indexed starting from zero

Purpose: Retrieves a value of previously calculated power at the specified sampling point. The function will return zero if called before the CalcNormalizedPowerSpectrum() has been executed.

Note: For more detail on this function, please refer to the VBScript Reference manual.

OptiFDTD provides a template in a sample file to show you how to use these functions. Users are encouraged to copy this template as their own project. The template sample can be found in the sample folder: Sample36_VBS_ ToGet_Power_Spectrum.FDT

The following demonstrates these functions.

Step Action
1 In the OptiFDTD Sample folder, open Sample36_2D_TE_VBS_PowerSpectrum.FDT in the Waveguide Layout Designer.
2 Double-click on the Input Plane to check the 2D input wave settings.
3 Select all the objects in the layout, then click “Delete” key to delete all the objects
4 Click Test Script” shortcut toolbar or select “ Test Script” in the Simulation menu.

Now al the objects in the layout are recreated by VB script.

5 Click the Scripting tab to go to the Script page.
6 This layout is designed by VB script. In the Scripting page, the first 110 lines is the VB code to generate the layout.  After the first 110 lines, it is the code to get the power transmittance and reflection.  A VB subroutine is designed which contained the above VB function. The user can just copy the subroutine to their own design to get the corresponding power or power transmittance value.
7 Save this layout to a different folder.

Note: You can change the project name

8 Select “Simulation 2D using Script” to start the simulation.
9 After the simulation, you will find that the following result files are exported from the VB function.

Sample36_2D_TE_VBS_ Power_Spectrum_NormalizedPowerSpectrum.txt Sample36_2D_TE_VBS_

Power_Spectrum_PowerAtCenterWavelength.txt

Sample36_2D_TE_VBS_ Power_Spectrum_PowerAtWavelength.txt

Sample36_2D_TE_VBS_ Power_Spectrum_PowerSpectrum.txt

Note: Each file contains the results for two Observation lines due to the fact that the VB Script function called the spectrum calculation for each observation line.

The VBScript function called the spectrum calculation for each observation line.

VB script function for Observation area post-simulation analysis

20 Integer GetPowerTypeCount()

Returns the number of power types (P_u, P_v, P_total) collected by this area.

21 String GetPowerTypeID( Integer Ratio_Type )

Returns a string name of the power type for the given number for the area.

0 – Returns the “u” name.

1 – Returns the “v” name.

2 – Returns the “total” name.

P_u P_v P_total
XY Area Pzx Pzy Pz
YZ Areal Pxy Pxz Px
ZX Area Pyz Pyx Py

Table 2: Power name presentation

Note:

•     Pzx means the power goes to the z-direction, while field polarization is in x direction

•     Pzy means the power goes to the z-direction, while field polarization is in y direction

•     Pz=Pzx+Pzy

•     Please check the chapter “Power calculation and Poynting Vector” for the power calculation formula

22 Double CalculatePowerRatioCW( String Ratio_Type )

Returns the power ratio at the center wavelength for the given ratio type for the area.

23 Double CalculatePowerRatioCW_u()

Returns the “u” power at the center wavelength for the area. See above table for which power is returned based on orientation.

24 Double CalculatePowerRatioCW_v()

Returns the “v” power at the center wavelength for the area.

25 Double CalculatePowerRatioCWTotal()

Returns the “total” power at the center wavelength for the area.

26 Object CalculatePowerSpectrum( String Ratio_Type )

Returns the power spectrum normalized on the key input for the given ratio type for the area.

27 Object CalculatePowerSpectrum_u()

Returns the “u” power spectrum for the area. See above table for which power is returned based on orientation.

28 Object CalculatePowerSpectrum_v()

Returns the “v” power spectrum for the area.

29 Object CalculatePowerSpectrumTotal()

Returns the “total” power spectrum for the area.

The power spectrum functions return “Objects” that contain the spectrum information. These are “Auto Coordinates” objects and have the following functions:

30 WriteF2D( String File_Name )

Write the data to a “f2d” file. Refer to the appendices for more information about format etc..

31 Integer GetSize()

Return the size of the array contained in the object. This will equal the size of the power spectrum.

32 Double GetXAt( Integer Index )

Get the X value at the given index. This will be the wavelength in um for the power spectrum.

33 Double GetYAt()

Get the Y value at the given index. This will be the normalized power value for the power spectrum.

When using the parameter sweep simulation, OptiFDTD will automatically use the above VB function to get the power spectrum results.  Parameter Sweep Definition dialog box provides an option called “Generate User Script”. If this option is used, user can check the Scripting page to review how the VB functions are being used.