Calculates the reflection and transmission of a plane wave through a layered periodic media using the RCWA solver. This function returns various results, including the fraction of transmitted and reflected power for both S and P polarizations as well as the electric and magnetic field values at specified locations. 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, a 3D FDTD solver 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.
Note: The rcwa command will be deprecated in release 2023 R2. We recommend using the RCWA solver object to run RCWA simulations instead. This object can be used to set up and run RCWA simulations in scripts with the addrcwa, set, and run commands.
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, whether grating order results should be calculated, and where the electric and magnetic fields 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 
An array containing the positions of the interfaces between the layers inside the simulation region. 
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 the 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  
direction  "forward"  String  Direction of propagation of the incident plane wave. Can be "forward" or "backward", where "forward" indicates the positive direction along the specified axis (i.e. +x) and "backward" indicates the negative direction (i.e. x). 
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, whether to report results in terms of the grating orders, and the locations where the electric and magnetic field values are to be returned 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  100  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. 
report_amplitudes  false  Boolean 
When true, the rcwa command returns:

fields_monitor_x, fields_monitor_y, fields_monitor_z  None  Matrix  Specifies the x, y, and z values where the electric and magnetic field values will be calculated. The fields will be calculated at each (x, y, z) combination of values. All three must be specified if field values are to be returned. 
report_raw_data  false  Boolean  When true, the result returned by the rcwa command can be used as an input for the rcwasweeppropagation command to efficiently run the RCWA solver again with different layer positions. See the rcwasweeppropagation page for more information. 
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  See RCWA Solver  Simulation Object. 
NumK  Scalar  Number of kvectors used during simulation 
GratingOrders (returned if report_grating_orders is true) 
Dataset  See RCWA Solver  Simulation Object. 
Fields (returned if fields_monitor_x , fields_monitor_y , and fields_monitor_z are given) 
Dataset  The calculated values of the electric and magnetic fields at the locations specified by fields_monitor_x , fields_monitor_y , and fields_monitor_z . If a particular source polarization has been chosen the electric and magnetic fields will be returned as E and H . If both polarizations are kept, the fields will be returned as E_p , H_p , E_s , and H_s . The dimensions of the results are length(fields_monitor_x) x length(fields_monitor_y) x length(fields_monitor_z) x length(frequency) x length(theta angle) x length(phi angle) 
Amplitudes (returned if report_amplitudes is true) 
Dataset  See RCWA Solver  Simulation Object. 
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. The calculated E and H fields along the zaxis will also be plotted.
a = 1e6;
# set RCWA solver properties
geometry = struct;
geometry.injection_axis = "zaxis";
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;
discretization = linspace(a/2,a/2,51); # z locations where fields will be calculated
options={"max_N":10,
"fields_monitor_z":discretization,
"fields_monitor_x":[0],
"fields_monitor_y":[0]};
# create geometry
addrect;
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.layer_positions(1));
set("z max",geometry.layer_positions(2));
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);
# 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
result = rcwa(geometry, excitation, options);
fields = result.Fields;
Es = pinch(fields.Es);
Hs = pinch(fields.Hs);
Ep = pinch(fields.Ep);
Hp = pinch(fields.Hp);
plot(options.fields_monitor_z,sqrt(sum(abs(Es)^2,2)),"z (m)","Es","","linewidth=2");
legend("");
TE = result.TotalEnergy;
plot(excitation.f,TE.Rs,TE.Ts,TE.Rp,TE.Tp,"frequency (Hz)","Power");
legend("Rs","Ts","Rp","Tp");