Calculates the reflection and transmission of a plane wave through a layered periodic media using Fourier expansions. This function returns the fraction of transmitted and reflected power for both S and P polarizations. All results are returned in a single dataset as a function of frequency and incidence angle. Optionally, the results can be returned as a function of grating order as well.
In order to use the rcwa command, an FDTD object must be included in the simulation to define a mesh grid. The span of the FDTD object should match the span of the RCWA solver, but otherwise the FDTD object properties do not affect the RCWA simulation.
For more information on the RCWA solver, see RCWA Solver Introduction.
Syntax  Description 

result = rcwa(geometry,excitation);  Returns a struct with fields defining the total energy and number of kvectors. The geometry argument is struct with fields that define device geometry. The excitation argument is struct defining the incident plane wave properties. See below for more information on the command results and arguments. 
result = rcwa(geometry,excitation,options); 
The additional argument, options , is a struct that determines the number of kvectors and whether grating order results should be calculated. See below for more information. 
Device Geometry
The device geometry used in the RCWA simulation is created using geometry objects, similar to the FDTD solver. The geometry
struct used as an argument to the rcwa command determines the:
 Injection axis of the plane wave source
 Span of the multilayer structure along the injection axis
 Span of the unit cell in the transverse directions
 Positions of the interfaces between the layers
The geometry
struct has the following fields:
Field  Units  Type  Description 

injection_axis  String  Injection axis, either "xaxis" , "yaxis" or "zaxis" . 

x_min  m  Scalar  Dimension of the geometry at x min 
x_max 
m 
Scalar 
Dimension of the geometry at x max 
y_min 
m 
Scalar 
Dimension of the geometry at y min 
y_max 
m 
Scalar 
Dimension of the geometry at y max 
z_min 
m 
Scalar 
Dimension of the geometry at z max 
z_max 
m 
Scalar 
Dimension of the geometry at z max 
layer_positions 
m 
Matrix 
Array containing the positions of the interfaces between the layers inside the simulation region. The positions are ordered from closest to the plane wave source to the farthest. 
The plane wave is injected along the positive direction of the chosen axis. A layer for the cladding/substrate on either side of the stack should be included to account for reflections from the interfaces between the cladding/substrate and first/last layers of the stack.
Plane Wave Source Properties
The properties of the plane wave used as a source in the RCWA simulation are set using the excitation
argument of the rcwa command.
The excitation
argument is a struct defining the incident plane wave with the following fields:
Field  Default  Units  Type  Description 

f  0  Hz  Matrix  Frequency array 
phi  0  Degrees  Matrix  Azimuthal angle array 
theta  0  Degrees  Matrix  Radial angle array 
s_pol  0  Scalar  Activate spolarization  
p_pol  0  Scalar  Activate ppolarization 
The frequency points and incident angles of the source can be set as single values or matrices containing a range of values. The RCWA solver results will be calculated at each combination of these frequency and angle values.
The polarization of the source can be set with the s_pol
and p_pol
fields. If both s_pol
and p_pol
are set to zero, results for both the S and P polarized source plane waves will be calculated. If one is set to 1 and the other is set to 0, only the results for the polarization set to 1 will be calculated.
Other Options
The maximum number of kvectors and whether to report results in terms of the grating orders can be set with the options
argument of the rcwa command. The options
argument is a struct with the following fields:
Field  Default  Type  Description 

max_N  50  Scalar  Largest number of kvectors 
report_grating_orders  false  Boolean  Reports total reflection/transmission when false. Reports reflection/transmission into each grating order if true. 
All of the fields are optional. Increasing the maximum number of kvectors will increase the accuracy of the simulation, but the simulation time required will be increased as well.
If report_grating_orders
is false
, only the total reflected/transmitted power will be returned. If it is set to true
, the transmission into each of the grating orders will be calculated as well.
Results
The results of the RCWA solver simulation are returned by the rcwa command as a struct with the following fields:
Field  Type  Description 

TotalEnergy  Dataset  Total power reflection and transmission as a function of wavelength and incident angle (radians). If a particular polarization is chosen, the result will be returned as R and T . If neither polarization is chosen, the results for each polarization will be returned separately as Rs , Ts , Rp , and Tp . 
NumK  Scalar  Number of kvectors using during simulation 
GratingOrders (if report_grating_orders is true) 
Dataset  Total power reflection and transmission for each grating order as a function of wavelength, incident angle (radians), and grating order index. If a particular polarization is chosen, the result will be returned as R_grating and T_grating . If neither polarization is chosen, the results for each polarization will be returned separately as Rs_grating , Ts_grating , Rp_grating , and Tp_grating . 
Example
The following script can be run on an empty FDTD simulation file to run the RCWA solver for a simple photonic crystal structure. The total power reflected and transmitted with a plane wave source at normal incidence is calculated with the RCWA solver and plotted.
a = 1e6;
# set RCWA solver properties
geometry = struct;
geometry.injection_axis = "xaxis";
geometry.x_min = a/2;
geometry.x_max = a/2;
geometry.y_min = a/2;
geometry.y_max = a/2;
geometry.z_min = a/2;
geometry.z_max = a/2;
geometry.layer_positions = [a/4,a/4];
excitation = struct;
excitation.f =0.5*c/a;
excitation.phi = 0;
excitation.theta = 15;
options={"max_N":10};
# create geometry
addrect;
set("x min",geometry.layer_positions(1));
set("x max",geometry.layer_positions(2));
set("y min",geometry.y_min);
set("y max",geometry.y_max);
set("z min",geometry.z_min);
set("z max",geometry.z_max );
set("index",sqrt(12));
addcircle;
set("z min",geometry.layer_positions(1));
set("z max",geometry.layer_positions(2));
set("radius",0.2*a);
set("index",1);
set("first axis","y");
set("rotation 1",90);
# add FDTD solver region
addfdtd;
set("x min",geometry.x_min);
set("x max",geometry.x_max);
set("y min",geometry.y_min);
set("y max",geometry.y_max);
set("z min",geometry.z_min);
set("z max",geometry.z_max);
# run RCWA solver and plot results
RT = rcwa(geometry, excitation, options);
TE = RT.TotalEnergy;
plot(excitation.f,TE.Rs,TE.Ts,TE.Rp,TE.Tp,"frequency (Hz)","Power");
legend("Rs","Ts","Rp","Tp");