Tutorial

Basic usage

The program may be run with a Lua script as an argument, in which case the script is run and then the program terminates, or without an argument, in which case it enters interactive mode with a Lua shell.

The basic flow of a script is listed below.

  1. Obtain a new simulation object:
    S = S4.NewSimulation()
    

    S now contains a simulation object with a blank specification, and no solutions.

  2. Define all materials:
    S:AddMaterial('name', {eps_real, eps_imag})
    
  3. Add all layers:
    S:AddLayer('name', thickness, 'material_name')
    
  4. Add patterning to layers:
    S:SetLayerPatternCircle('layer_name',
    																							'inside_material',
    																							{center_x, center_y},
    																							radius)
    
  5. Specify the excitation mechanism:
    S:SetExcitationPlanewave(
    		{angle_phi, angle_theta}, -- phi in [0,180), theta in [0,360)
    		{s_pol_amp, s_pol_phase}, -- phase in degrees
    		{p_pol_amp, p_pol_phase})
    
  6. Specify the operating frequency:
    S:SetFrequency(0.4)
    
  7. Obtain desired output:
    forward_power, backward_power = S:GetPoyntingFlux('layer_name', z_offset)
    print(forward_power, backward_power)
    

Fourier Modal Method formulations

There has been extensive literature on the best way to generate the Fourier series coefficients for the in-plane dielectric profiles of each layer. S4 implements a number of different formulations. The following functions determine which formulation is selected:

In addition, the following functions control accuracy and the lattice truncation:

To simplify the choice for users, the table below summarizes the recommended settings. It is recommended to always use circular truncation unless there is a good reason to do otherwise. Speed indicates the speed of the Fourier coefficient generation, which is usually not the dominant part of the simulation time.

Options Can handle Anisotropic? Recommended resolution Speed Accuracy
none yes - fast poor
Disc yes 8 medium poor
Subpixel yes 4 medium medium
Pol no 8 slow good
Pol+Normal no 8 slow good
Pol+Jones no 8 slow good
Disc+Pol no* 4 slow medium
Disc+Pol+Normal no* 4 slow medium
Disc+Pol+Jones no* 4 slow medium

*: The formulation does not strictly work correctly for anisotropic media however it may still work. Proper support for anisotropic materials is in principle possible. There are currently no plans for implementing generation of the proper basis fields for this feature.

Examples

The source distribution of S4 includes numerous fully working didactic examples as well as examples replicating published results. You can find these examples in the examples/ directory of the source tarball.