The S4 Lua programming interfaceS4 is built as a set of extensions to the Lua scripting language. Usage of S4 involves writing a Lua script to call into various parts of S4. Here we describe all of the S4 specific functions that can be called within the Lua environment. Contents
S4 libraryAll top level functions of S4 are located in the NewSimulationReturns a new blank Simulation object. Usage
ArgumentsNone. Return values
NewSpectrumSamplerReturns a new SpectrumSampler object. Usage
Arguments
Return values
NewInterpolatorReturns a new Interpolator object. Usage
Arguments
The second argument should be a table of tables. Each subtable should have as its first element the abscissa of a data sample, and the second element should be a table of all the ordinate values. The ordinate ordering is clearly important, and only the number of ordinate values for the first abscissa value determines the assumed number of ordinate values for the remaining abscissae. Return values
SolveInParallelForces the computation of a layer solution for several simulation objects in parallel. When compiled without thread support, the computations are done serially. Usage
Arguments
Return valuesNone. ConvertUnitsPerforms unit conversions. Usage
Arguments
Return valuesThe converted value, or nil if no conversion was possible. IntegratePerforms adaptive numerical integration in an arbitrary number of dimensions. Usage
Arguments
Return valuesReturns the integrated value and an estimate of the error. argWhen used with the When no command line switch is specified, Multiple variables may be passed in by passing in multiple Lua statements:
Then within the script, the variables may be set with the statement
MPIRankOn a version of S4 with MPI support, gives the MPI machine rank (0-based index of processor node). For versions without MPI support, this is always 0. MPISizeOn a version of S4 with MPI support, gives the MPI size (total number of processor nodes). For versions without MPI support, this is always 1. Simulation objectThe Simulation object is the primary object which computes solutions to systems.
When a new Simulation object is requested from SetLatticeSets the real-space lattice. Usage
ArgumentsThis function can take a single numeric argument, which sets the period for a 1D lattice. This function can also take two table arguments, each of which must have two numeric elements. The first table specifies the x- and y-coordinates of the first lattice basis vector, while the second table specifies the second basis vector. The basis vectors should have positive orientation (the cross product of the first with the second should yield a vector with positive z-coordinate). Return valuesNone SetNumGSets the maximum number of in-plane (x and y) Fourier expansion orders to use. All fields and eigenmodes of the system use the same Fourier basis of the same dimension. The computation time is roughly proportional to the cube of this number, and the memory usage is roughly proportional to the square. Usage
Arguments
Return valuesNone AddMaterialAdds a new material with a specified dielectric constant. Usage
Arguments
Return valuesNone SetMaterialUpdates an existing material with a new dielectric constant or adds a material if none exists. Usage
Arguments
Return valuesNone AddLayerAdds a new unpatterned layer with a specified thickness and material. Usage
Arguments
Return valuesNone SetLayerUpdates an existing layer with a new thickness and removes all layer patterning. If no matching layer is found, adds a new unpatterned layer with a specified thickness and material. The behavior is undefined if the new material does not match the old material during an update (currently, the new material is ignored, but this may change in the future). If only the thickness needs to be modified, use SetLayerThickness. Usage
Arguments
Return valuesNone SetLayerThicknessUpdates an existing layer with a new thickness. Previously cached layer eigenmodes are preserved, making this function the preferred way to update a layer’s thickness. Usage
Arguments
Return valuesNone AddLayerCopyAdds a new layer with a specified thickness, but identical patterning as another existing layer. Note that this merely creates a reference to the copied layer; further patterning of the copied layer also affects the new layer. Additionally, a copy of a copy cannot be made. Usage
Arguments
Return valuesNone SetLayerPatternCircleAdds a (filled) circle of a specified material to an existing non-copy layer. The circle should not intersect any other patterning shapes, but may contain or be contained within other shapes. Usage
Arguments
Return valuesNone SetLayerPatternEllipseAdds a (filled) ellipse of a specified material to an existing non-copy layer. The ellipse should not intersect any other patterning shapes, but may contain or be contained within other shapes. Usage
Arguments
Return valuesNone SetLayerPatternRectangleAdds a (filled) rectangle of a specified material to an existing non-copy layer. The rectangle should not intersect any other patterning shapes, but may contain or be contained within other shapes. Usage
Arguments
Return valuesNone SetLayerPatternPolygonAdds a (filled) polygon of a specified material to an existing non-copy layer. The polygon should not self-intersect nor intersect any other patterning shapes, but may contain or be contained within other shapes. The polygon must also be specified with positive orientation (the vertices circle CCW about an interior point). Usage
Arguments
Return valuesNone SetExcitationPlanewaveSets the excitation to be a planewave incident upon the front (first layer specified) of the structure. If both tilt angles are specified to be zero, then the planewave is normally incident with the electric field polarized along the x-axis for the p-polarization. The phase of each polarization is defined at the origin (z = 0). Usage
Arguments
Return valuesNone SetFrequencySets the operating frequency of the system (and excitation). Usage
Arguments
Return valuesNone GetReciprocalLatticeRetrieves the reciprocal lattice basis vectors. The vectors lack the scaling by 2pi (multiply them by 2pi to obtain the true reciprocal lattice basis vectors). Usage
ArgumentsNone. Return values
GetEpsilonRetrieves the dielectric constant at a particular point in the system by reconstructing the Fourier series using the G-vectors of the system. Note that this reconstruction is not representative of the actual dielectric constant profile used in simulations (such a notion is not meaningful). The reconstruction is created using the closed-form Fourier series coefficients of the specified patterning, summed over the terms comprising the G-vector list obtained from lattice truncation. This function exists to provide an intuitive sense for the spatial resolution of a particular G-vector truncation order. Usage
Arguments
Return values
OutputLayerPatternDescriptionOutputs a list of PostScript commands to render the exact layer pattern description from the specified patterning commands. Assumes letter-sized paper. Usage
Arguments
Return valuesNone. OutputLayerPatternRealizationOutputs a Gnuplot format dump of the Fourier series reconstruction of the dielectric constant in the unit cell. Note that the output will appear distorted for non-orthogonal unit cells. Note that this reconstruction is not representative of the actual dielectric constant profile used in simulations (such a notion is not meaningful). The reconstruction is created using the closed-form Fourier series coefficients of the specified patterning, summed over the terms comprising the G-vector list obtained from lattice truncation. This function exists to provide an intuitive sense for the spatial resolution of a particular G-vector truncation order. Usage
Arguments
Return valuesNone. OutputStructurePOVRayOutputs a POV-Ray script that will render one unit cell of the structure in 3D. Materials named Usage
Arguments
Return valuesNone. GetNumGReturns the specified number of Fourier series orders to use (number of G-vectors), or, if a solution has been computed, the actual number of G-vectors used. Usage
ArgumentsNone. Return values
GetGListReturns a table of reciprocal lattice coordinates of the Fourier series orders used. The coordinates are in the reciprocal lattice basis, and so they are integers. Usage
ArgumentsNone. Return values
GetDiffractionOrderReturns the index (1-based) of a particular diffraction order. The index can be used directly in GetPoyntingFluxByOrder to obtain the diffracted power of a particular order. The coordinate arguments are in the reciprocal lattice basis, and so they are integers. A particular diffraction order is only a meaningful concept in a uniform (unpatterned) layer, otherwise the diffraction order corresponds to an arbitrary layer eigenfunction index. Usage
Arguments
Return values
GetAmplitudesReturns the raw mode amplitudes within a particular layer. For uniform (unpatterned) layers, the modes are simply the diffracted orders, and the indexing of the returned amplitudes corresponds to the value obtained from GetDiffractedOrder. The first value is guaranteed to be the straight transmitted or specularly reflected diffraction order. For patterned layers, there is typically no meaningful information in these amplitudes. Usage
Arguments
Return values
GetPoyntingFluxReturns the integral of the Poynting flux density over a unit cell surface normal to the z-direction. In other words, the z-component of the Poynting flux is returned. Usage
Arguments
Return values
GetPoyntingFluxByOrderReturns the integral of the Poynting flux density over a unit cell surface normal to the z-direction for each Fourier series order. In other words, the z-component of the Poynting flux for each order is returned. Usage
Arguments
Return values
GetStressTensorIntegralReturns the integral of the electromagnetic stress tensor over a unit cell surface normal to the z-direction. Usage
Arguments
Return values
GetLayerEnergyDensityIntegralReturns the volume integral of the electromagnetic energy density (epsilon*|E|^2 + |H|^2) over a unit cell throughout the entire thickness of a layer. Usage
Arguments
Return values
GetLayerElectricEnergyDensityIntegralReturns the volume integral of the electric energy density (epsilon*|E|^2) over a unit cell throughout the entire thickness of a layer. Usage
Arguments
Return values
GetLayerMagneticEnergyDensityIntegralReturns the volume integral of the magnetic energy density (|H|^2) over a unit cell throughout the entire thickness of a layer. Usage
Arguments
Return values
GetLayerElectricFieldIntensityIntegralReturns the volume integral of the squared electric field intensity (|E|^2) over a unit cell throughout the entire thickness of a layer. Usage
Arguments
Return values
GetLayerZIntegralReturns the line integral along z (depth direction) of the squared magnitudes of electric and magnetic field components (|Ex|^2, |Ey|^2, etc.) throughout the entire thickness of a layer. Usage
Arguments
Return values
GetEFieldReturns the electric field at a particular point within the structure. Usage
Arguments
Return values
GetHFieldReturns the magnetic field at a particular point within the structure. Usage
Arguments
Return values
GetFieldsReturns the electric and magnetic field at a particular point within the structure. Note that it is more efficient to call this function when both fields are needed. Usage
Arguments
Return values
GetSMatrixDeterminantReturns the determinant of the S-matrix (scattering matrix) of the entire structure. The determinant is an analytic function in the complex frequency plane and has poles at the complex modal frequencies of the system. Usage
ArgumentsNone. Return values
UseLanczosSmoothingEnables or disables smoothing of the Fourier series representations of the layer dielectric constants using the Lanczos sigma factor (box filtering). This reduces the Gibbs phenomenon ringing in the real space reconstruction. Usage
Arguments
Return valuesNone. UseDiscretizedEpsilonEnables or disables the use of discretization in generating the Fourier coefficients of the in-plane epsilon profiles, instead of using values from closed-form equations. When enabled, the coefficients are obtained by FFT. See the list of formulations for details. Usage
Arguments
Return valuesNone. UsePolarizationDecompositionEnables or disables the use of proper in-plane Fourier factorization rules by decomposing fields into a polarization basis which conforms to the material boundaries. The polarization basis field is generated automatically by computing a quasi-harmonic vector field everywhere tangent to the layer pattern boundaries. This option is not guaranteed to work in the presence of tensor dielectric constants. Enabling this feature typically improves convergence with respect to the number of G-vectors. See the list of formulations for details. Usage
Arguments
Return valuesNone. UseSubpixelSmoothingEnables or disables the use of second-order accurate epsilon averaging rules within a pixel. The average epsilon within a pixel is computed using the fill factor of each material and the interface direction. Enabling this feature may improve convergence with respect to the number of G-vectors. See the list of formulations for details. Usage
Arguments
Return valuesNone. UseJonesVectorBasisThis option only has an effect with Enabling this feature may improve convergence with respect to the number of G-vectors. See the list of formulations for details. Usage
Arguments
Return valuesNone. UseNormalVectorBasisThis option only has an effect with Enabling this feature may improve convergence with respect to the number of G-vectors. See the list of formulations for details. Usage
Arguments
Return valuesNone. SetResolutionThis option only has an effect with See the list of formulations for details. Usage
Arguments
Return valuesNone. SetBasisFieldDumpPrefixSetting this option to a filename prefix causes the vector field used by the polarization decomposition to be dumped to files (one for each layer) in Gnuplot format. The files are named by concatenating the provided prefix string with each layer’s name. Usage
Arguments
Return valuesNone. SetLatticeTruncationSets the type of lattice truncation to use when selecting G-vectors. Usage
Arguments
Return valuesNone. SetVerbositySets the type of lattice truncation to use when selecting G-vectors. Usage
Arguments
Return valuesNone. UseLessMemorySetting this option will prevent storage of certain intermediate results. This will save approximately 30% memory for non-trivial layers. The drawback is slower computation of any output quantities that require solutions. Usage
Arguments
Return valuesNone. CloneDuplicates an existing Simulation object, copying all materials, layers, and excitation information. No partial solution information is copied. Usage
ArgumentsNone. Return valuesA copy of the Simulation object. SpectrumSampler objectThe SpectrumSampler object provides a convenient way to sample spectral information of a system. For example, it is used to resolve sharp peaks in transmission spectra. Interaction with a SpectrumSampler object is by contract; a new frequency is retrieved from it by which simulation results at that frequency are computed, and then the results are submitted. The frequencies given out by a SpectrumSampler object aim to produce a visually pleasing plot of the resulting spectrum by limiting the maximum normalized bend angles between adjacent line segments of the plot. A typical usage is shown below:
IsDoneQueries whether the SpectrumSampler has completed sampling. When sampling has been completed, no further frequencies should be requested from the SpectrumSampler object, and no further results should be submitted. Usage
ArgumentsNone. Return valuesA boolean value indicating whether sampling has completed. GetFrequencyRetrieves the next frequency at which to sample the spectrum. This function should only be used if the SpectrumSampler object was created with Usage
ArgumentsNone. Return valuesThe (numeric) frequency at which the next result should be computed and submitted. GetFrequenciesRetrieves the next set of frequencies at which to sample the spectrum. This function should only be used if the SpectrumSampler object was created with Usage
ArgumentsNone. Return valuesA list of (numeric) frequencies at which the next results should be computed and submitted. SubmitResultSubmits a result to the SpectrumSampler object. The result is assumed to be at the frequency of the last requested frequency. This function should only be used if the SpectrumSampler object was created with Usage
Arguments
Return valuesA boolean value indicating whether sampling has completed. SubmitResultsSubmits a set of results to the SpectrumSampler object. The results are assumed to be at the frequencies of the last requested frequencies. This function should only be used if the SpectrumSampler object was created with Usage
Arguments
Return valuesA boolean value indicating whether sampling has completed. GetSpectrumRetrieves a list of all sampled frequencies and submitted results. This function should only be used when the SpectrumSampler object indicates that sampling is complete. Usage
ArgumentsNone. Return valuesAn array (with length equal to the number of samples) of pairs (arrays of length 2) containing the sampled frequency and corresponding submitted result. Interpolator objectThe Interpolator object provides a tool to perform various types of interpolation on data. The most common use is to interpolate between experimentally determined values for dieletric constants. A typical usage is shown below.
At each x (abscissa) value, any number of y (ordinate) values can be specified for interpolation. GetRetrieves the interpolated ordinates for a given abscissa value. Usage
Arguments
Return valuesA list of interpolated ordinate values. |