The structure group shown below and located in the associated file can be is used in the 2D square and triangular photonic crystal bandstructure calculation examples.
Elements of the structure group
A structure group consists of two elements
- a group of structure primitives
- a setup script to setup or edit the grouped primitives
The figure above shows the 2D photonic crystal array structure group from the attached triangular_lattice.fsp file. The structure group consists of an array of rods, whose radius, number, and spacing is set by the setup script.
Structure groups are created using the ADD STRUCTURE GROUP option of the Groups button in the main toolbar. If you choose to edit a structure group object, then you will see that there are three tabs in the edit dialog box. The PROPERTIES tab contains input parameters for the script. In the PC structure group, the input parameters are the radius of the rods, the size of the array, the lattice spacing along the two axes of symmetry, and the angle between the axes. The SCRIPT tab contains the setup script that creates a physical structure. In the PC structure group, the script sets up the array of rods. The ROTATIONS tab is used to set the overall orientation of the group. The first two tabs will be discussed in more detail below.
Properties tab
The PROPERTIES tab is only available for structure groups, shown in the screenshot below. It contains all the input parameters that are needed to set up the physical structure. Custom user property variables may be added with the ADD button and removed with the REMOVE button.
There are two sections in the properties tab:
- ORIGIN: The location of the origin of the group, in the global coordinate frame.
- USER PROPERTIES: User properties are parameters that can be used to set up the structure. Each user property has a name and a type (number, frequency, etc). The user properties can be set manually in the edit GUI or through script commands.
Script Tab
The SCRIPT tab, shown in the screenshot below, contains the setup script that is used to create and/or edit structures within the group. The script tab can contain script commands that are used to set up a structure or edit the properties of structures located within the structure group. The structure group has access to the user variables defined in the PROPERTIES tab and can change the properties of any objects that are contained in the group. The script does not have access to objects which are not located in the group and does not share the same variable space as the script prompt.
The following buttons and regions are available in the Script tab:
- SCRIPT: This is where the script commands are written. To find a list of script commands, see the Scripting Language section of the Reference Guide.
- TEST/SCRIPT OUTPUT: Press the TEST button to run the script. If there are no syntax errors in the script the SCRIPT OUTPUT will read <script complete>.
Note that:
- the user parameters are used in the script to create the array. For example, the user property "radius", which is highlighted in blue in the screenshot of the PROPERTIES tab is used in the following manner to set the radius of the rods to 120 nm.
addcircle;
set("radius",radius);
- the select and unselect script commands are used in the script. When these are called, only elements in the group are selected. The scope of the setup script is limited to objects within the group.
- the setup script does not have access to the global workspace variables (those defined in the script prompt or in a script file). The script has its own private variable workspace. In addition, any variables defined in the setup script cannot be obtained from the script prompt or from a script file.
- objects are created relative to the origin of the group. So for example, if the origin was set to (5,0,0) microns in the VARIABLES tab, then the following commands would add a rectangular structure centered at (10,0,0) microns, as measured in the global coordinate frame.
addrect;
set("x",5e-6);
- the TEST button runs the script and generates the array shown in the image at the top of this page. If there are no syntax errors in the script, you will see the line <script complete> in the script output. If there is a syntax error, the location of the error will be given in the script output. An example of an error message is: syntax error: prompt line: 38.
- the script is also run every time the TEST or OK button is pressed or a property of the structure group is changed with a script command.
Benefits of using structure groups
Parameter Sweeps:
Structure groups simplify parameter sweeps. The following lines can be used in a script file or script prompt to loop through one of the lattice parameters of the 2D photonic crystal array. Each time the set script command is called the setup script runs is executed, editing the array so that it has a the new lattice parameter. Also, these values can be used as parameter sweep variables or part of the figure of merit in optimizations.
a(i) = linspace(1e-6,6e-6,4) #array of lattice parameters
for(i=1:length(a)) {
switchtolayout;
#edit structure group
select("2D photonic crystal array");
set("ax",a(i));
run;
#run simulation
# do something
}
Copying and Pasting (Modularity):
Structure groups can be copied and pasted from one simulation to another using the CTRL+C and CTRL+V shortcut key combinations on the keyboard.
Simplifies running script files:
Master scripts can be kept shorter by moving some of the script within the group. This can be seen, for example, in the parameter sweep example. Also, in the script in the analysis groups, there is no risk of unintentionally overwriting variables. Any variables defined in a script file or in the script prompt become workspace variables and can be used or overwritten by any script that is run afterward. In contrast, the variables in the script of a structure group are not workspace variables, and the structure group script does not have access to the workspace variables
Creating a structure group from a script
It is possible to create a structure group from a script, as shown in the following example code:
addstructuregroup;
set("name","cube");
adduserprop("length",2,1e-6);
set("construction group",1);
# define the setup script by setting the 'script' property.
# Note that the entire script must be contained within a set of
# quote characters. Typically single quote characters are used
# to contain the entire string, which allows double quotes to be
# used within the script.
set('script','
addrect;
set("x span",length);
set("y span",length);
set("z span",length);
');
See also
Structures, Analysis groups, Arrays of objects, addstructuregroup (script command), PC Bandstructure, Object Library