% Chapter 3
\chapter{Broad Band Fixed-beam Leaky Wave Antenna} % Main chapter title
\label{Chapter3}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}
\chead{\rightmark}

The leaky-wave antenna presented in this thesis consists of two components: a slot-line array to generate the leaky-wave radiation and a rectangular graded dielectric superstrate placed on top of it. The superstate receives the generated leaky-wave radiation from the underlying slot array and couples it to free-space. The inhomogeneous distribution of permittivity inside the superstrate guides the wave to produce refraction at the upper interface at a specific angle. The geometric compensation technique presented in Sec. \ref{sec:geocomp} is employed in this chapter to design the rectangular slab. The chapter begins by describing the context of the fixed-beam radiation for the slot-array and proceeds to describe the design procedure. It is demonstrated that the geometric compensation technique decidedly improves the radiation characteristics of the antenna. A few variations of the proposed design are also presented in the final section of this chapter.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Design principle}
The design of the proposed leaky-wave antenna is influenced by the analysis of an infinitely long and optically narrow slot-line located at the interface between two different dielectric media \cite{Neto2003}\cite{Maci2004}. The radiation mechanism from such slot-lines is demonstrated in section \ref{SLLWA}. Figure \ref{fig:coupling}a is a similar illustration, showing a slot aperture extending in the positive $x$ direction and etched on a metallic ground plane in the $xy$ plane. A dielectric slab with a dielectric permittivity $\epsilon_r$ is located on top of the slot-line while the region underneath is free-space. If the slot aperture is transversely excited with a current element, a leaky-wave mode will propagate longitudinally in the direction of $x$ axis and continuously generate leaky-wave radiation into the dielectric slab. However, the generated leaky-wave radiation remains confined inside the superstrate due to total internal reflection at the air-dielectric interface, as illustrated by the ray-diagram in Fig. \ref{fig:coupling}a.
%
\begin{figure} [t!]
\centering
\noindent
\hspace*{\fill}%
  \mbox{\subfloat[]
        {\begin{overpic}[scale=0.35]{Figures/Chapter3/fig_coupling/metaprism_1}
			\put(22,43){\footnotesize Uniform dielectric}
		\end{overpic}}}
	\hfill%
	\mbox{\subfloat[]
        {\begin{overpic}[scale=0.35]{Figures/Chapter3/fig_coupling/metaprism_2}
			\put(35,35){\footnotesize Uniform}
			\put(35,28){\footnotesize dielectric}
			\put(72,83){\footnotesize $\theta_{\mathrm{rad}}$}
		\end{overpic}}}
		\hspace*{\fill}%

	\mbox{\subfloat[]
        {\begin{overpic}[scale=0.35]{Figures/Chapter3/fig_coupling/metaprism_3}
			\put(42,62){\footnotesize $\theta_{\mathrm{rad}}$}
			\put(38,27){\footnotesize Graded index}
			\put(38,20){\footnotesize dielectric}
			\put(-40,40){\vector(2,0){25}}
			\put(-40,40){\vector(0,2){25}}
			\put(-40,40){\vector(2,0){25}}
			\put(-40,40){\vector(3,2){20}}
			\put(-13,40){\footnotesize $x$}
			\put(-42,69){\footnotesize $y$}
			\put(-17,53){\footnotesize $z$}
			\put(130,40){\vector(2,0){25}}
			\put(130,40){\vector(0,2){25}}
			\put(130,40){\vector(2,0){25}}
			\put(130,40){\vector(3,2){20}}
			\put(157,40){\footnotesize $H_x$}
			\put(132,69){\footnotesize $H_y$}
			\put(151,53){\footnotesize $E_z$}
	\end{overpic}}}

  \caption[A diagram showing how a slot emitted leaky-wave radiation from a corner-fed slot-line leaky-wave antenna array remains trapped inside the uniform dielectric superstrate. A convex dielectric domain couples the generated radiation into free-space. The same phenomenon can be implemented with a rectangular graded-dielectric superstrate. ]{The slot emitted leaky-wave radiation from a corner-fed slot-line leaky-wave antenna array remains trapped inside the uniform dielectric superstrate (a). The phase-mismatch at the interface is reduced at a uniform dielectric convex layer which couples the generated radiation (b). The same phenomenon can be implemented with a rectangular graded-dielectric layer (c).  }
\label{fig:coupling}
\end{figure}
%
The incident angle (measured from broadside) of the leaky-wave at the upper interface of the uniform dielectric slab needs to be reduced in order to be coupled into free-space. This could be achieved by replacing the rectangular slab with a convex dielectric superstrate to couple the radiation into free-space through its curved upper interface, as shown in Fig. \ref{fig:coupling}b. The leaky-wave antenna reported in \cite{Neto2005} functioned with similar configuration. Here we seek to reduce the profile of the antenna and enable radiation in directions other than broadside.

Using transformation electromagnetics, the convex dielectric superstrate shown in Fig. \ref{fig:coupling}b is reshaped into an inhomogeneous rectangular one as shown Fig. \ref{fig:coupling}c. In contrast to the curved upper interface of the uniform dielectric medium in Fig. \ref{fig:coupling}b, the air-interface of the rectangular superstrate in Fig. \ref{fig:coupling}c is parallel to the slot-line. The inhomogeneous superstrate mimics the uniform dielectric hemisphere in Fig. \ref{fig:coupling}a and bends the slot-generated radiation to reduce its inident angle at the interface. The phase-profile of the wave along the upper interface of the superstrate determines the radiation angle of the leaky-wave antenna. The design process of the antenna involves obtaining the dimensions and permittivity distribution of the superstrate through transformation electromagnetics.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{Design considerations}
The leaky-wave antenna presented in this thesis consists of a slot-line array with a rectangular superstrate placed on top of it, as demonstrated in Fig. \ref{fig:coupling}c. The graded index dielectric superstate receives the generated leaky wave radiation from underlying the slot array and couple into free-space. The design of the antenna was conducted with an infinite slot array. The superstrate was consequently considered infinitely stretched in the direction transverse to the slot length, which aided saving computational resources by reducing the overall simulation domain.

The essential parameters considered for designing the leaky-wave antenna are:

\begin{itemize}
    \item The radiation angle: The fixed-beam leaky-wave antenna proposed by Neto \textit{et al.} was limited to broadside radiation \cite{Neto2005}\cite{Bruni2007}. The primary design criterion for the leaky-wave antenna is to produce a main beam at an oblique direction. The design procedure and simulation results presented in this chapter aims for a fixed radiation angle $\theta_{\mathrm{rad}} = 30^\circ$ from broadside. %This radiation angle was chosen to distinct the primary beam from the secondary lobes over the desired bandwidth. That being said, this angle can be chosen arbitrarily by the designer.

    \item Constituent material: The superstrate of the leaky-wave antenna consists of non-magnetic graded dielectric index material. The permittivity ($\epsilon$) of the slab is spatially distributed with unity permeability ($\mu$) value. The permittivity variation of the slab is two-dimensional with no variation in the direction transverse (the $z$ direction) to the slot-line. The superstrate was designed such that the value of relative permittivity ranges from 1 to 9. A maximum relative permittivity value of 9 was specifically chosen to limit the $\epsilon_r$ values to those of commonly available dielectrics. A maximum value of relative permittivity of 9 limits the refractive index value to 3. The minimum relative permittivity value was chosen to be unity because a relative permittivity below one would require artificial dielectrics which are either narrowband or require active elements. For instance, the antenna proposed by Sievenpiper consists of a dielectric substrate with relative permittivity below unity \cite{Sievenpiper2011}. However, the design utilizes active non-foster circuits to achieve fixed-beam radiation from the antenna. The design process of the antenna presented in this thesis was limited to passive devices only.

    \item Length of the antenna: In order to keep the antenna structure from being bulky, the length of the superstrate as well as the slot array was initially specified to be $L = 6 \lambda_0$, where $\lambda_0$ is the free-space wavelength. An antenna of such dimension is electromagnetically large for general applications. However, leaky-wave antennas are typically electromagnetically much long, typically around 10-12 wavelengths. It will be shown later that the desired antenna performance can be achieved from a length $L = 4.2 \lambda_0$, which is smaller than previous designs proposed by Neto \textit{et al.} and Sievenpiper.

    \item Frequency bandwidth: The objective was to achieve a percentage bandwidth over 100\%. While operating over a broad band, the antenna as well as the slot array becomes electrically smaller with the decrease of frequency. At lower frequencies, the leaky wave mode in the slot fails to radiate sufficient energy due to reduced length for propagation. This introduces reflections inside the slot that creates longitudinal reflections and interference inside the slot. As a result, the far-field radiation at lower frequencies contains higher sidelobe and wider beam at lower frequencies, as will be shown in later in section \ref{simres}. One way to get around this problem is to terminate the slot with a matched load so that the reflected waves do not interfere with the leaky-wave mode. In contrast to operation at lower frequencies, at higher frequencies, the antenna demonstrates improved performance in terms of sidelobe level and directivity because the antenna becomes electrically longer. We consider $2f_0$ for the upper frequency limit of the antenna, which leads to a length of $12 \lambda$ at the maximum frequency. The final design was simulated to have a fractional bandwidth of 5:1 where the sidelobe level remained below $30\%$ and the directivity was above 11.
\end{itemize}

\begin{figure}
\centering
 	\begin{overpic}[scale=0.7]{Figures/Chapter3/fig_structure/structure}

 	        \put(-14,72){\footnotesize $2.9 \lambda_0$}
			\put(78,76){\footnotesize $4.2 \lambda_0$}
			\put(84,-5){\footnotesize $0.1 \lambda_0$}
			\put(57,-5){\footnotesize $0.02 \lambda_0$}
			\put(0,15){\footnotesize $v$}
			\put(7,28){\footnotesize $u$}
			\put(18,33){\footnotesize $z$}

  \end{overpic}

  \caption[The structure and physical dimensions of the simulated antenna.]{The structure and physical dimensions of the simulated antenna. All lengths are represented in terms of free-space wavelength $\lambda_0$ where frequency is $c$. The yellow substrate represents an inhomogeneous dielectric slab.}
\label{fig:structure}
\end{figure}

Hence the primary design criterion for the leaky-wave antenna was to produce a main beam at a fixed angle $\theta_{\mathrm{rad}} = 30^\circ$ over a wide-frequency range from $0.5f_0$ to $2f_0$. The designed antenna structure as well as the dimensions obtained through transformation electromagnetics is presented in Fig. \ref{fig:structure}. The slot width of the infinite slot array was specified to be $0.02 \lambda_0$ with an array spacing of $0.1 \lambda_0$. As will be shown, the antenna length and height was $4.2 \lambda_0$ and $2.9 \lambda_0$, respectively.

%\section{Validation of Simulations}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%\label{App:NFTFF} describes validation process of the near field to far field process.

\section{Design of the superstrate} \label{sec:design}
The rectangular superstrate of the leaky-wave antenna is designed using transformation optics along with the geometric compensation technique demonstrated in section \ref{sec:geocomp}. According to the technique, the rectangular shape of the superstrate is considered in the target domain. The graded permittivity distribution inside the superstrate is achieved through a two-step numerical conformal transformation process.

\begin{figure} [t!]
\centering
  \noindent
\hspace*{1.5cm}
\mbox{\subfloat[]{
	\begin{overpic}[scale=0.4]{Figures/Chapter2/fig_simulation_domain/domain_corner}
			\put(42,18){\footnotesize L=6$\lambda$}
			\put(50,46){\footnotesize air}
			\put(50,73){\footnotesize dielectric}
			\put(-8,28){\footnotesize PEC}
	%		\put(-10,42){\footnotesize \fbox{PML}}
			\put(-16,39){\footnotesize Excitation}
			\put(08,90){\vector(-2,0){15}}
			\put(08,90){\vector(0,2){15}}
			\put(08,90){\vector(-2,0){15}}
			\put(08,90){\vector(3,4){8}}
			\put(-10,90){\footnotesize $y$}
			\put(5,105){\footnotesize $z$}
			\put(15,102){\footnotesize $x$}

  \end{overpic}}}
  \hspace*{1.5cm}%
    \mbox{\subfloat[]{

  	\begin{overpic}[scale=0.4]{Figures/Chapter2/fig_simulation_domain/domain2D}
        \put(50,87){\footnotesize L}
        \put(35,43){\footnotesize dielectric}
         \put(42,18){\footnotesize air}
  \end{overpic}}}
 \hspace*{2cm}%

  \caption[Simulation setup for the analysis of the proposed leaky-wave antenna.]{Simulation setup for the analysis of the proposed leaky-wave antenna. Half of a unit cell is simulated with the PEC boundary conditions that extending the structure infinitely in the $z$ direction. The dashed region represents PML absorbing layer while the solid region is the actual simulation domain.}
\label{fig:simdomain2}
\end{figure}

\begin{figure} [t!]
\centering
  \noindent
  %
  \hspace*{\fill}%
 \mbox{\subfloat[]{
    	\begin{overpic}[trim={4cm -.6cm .6cm 1.2cm},clip,scale=0.3]{Figures/Chapter2/fig_simulation_domain/Ez1}
    			\put(70,0){\vector(2,0){10}}
    			\put(70,0){\vector(0,2){10}}
    			\put(80,01){\footnotesize $x$}
    			\put(70,11.5){\footnotesize $y$}
    			\put(68.5,-1.5){\footnotesize $\otimes$}
    			\put(66.5,-5){\footnotesize $z$}
    				\put(-4,47){\footnotesize \rotatebox{90}{$y (\lambda_0)$}}
    				\put(30,0){\footnotesize {$x (\lambda_0)$}}

    			\linethickness{.7mm}
    			\put(15,90){\line(2,0){9}}
    			\put(16.5,92){\footnotesize $\lambda_0$}

  \end{overpic}}}
  %
  %
   \mbox{\subfloat[]{
   	\begin{overpic}[trim={0cm 0cm .1cm 1cm},clip,scale=0.42, keepaspectratio=true]{Figures/Chapter2/fig_simulation_domain/Ez2}
  \end{overpic}}}
  \hspace*{\fill}%

  \hspace*{\fill}%
     \mbox{\subfloat[]{
   	\begin{overpic}[scale=0.5]{Figures/Chapter2/fig_simulation_domain/Ez3.png}
  \end{overpic}}}
  \hspace*{\fill}%
  %
  \caption[Fields produced in a uniform dielectric half-space that are used to determine the source domain geometry.]{(color inline) The fields produced in the structure demonstrated in Fig. \ref{fig:simdomain2} (a). The unwrapped phase (degrees) of the fields are plotted and used to determine the source domain geometry for the transformation optics procees. The blue lines correspond to the upper interface that corresponds to the phase profile being linear (b). The linear phase profile along the upper interface (c).}
\label{fig:simdomain2b}
\end{figure}

In the first step, an initial hypothetical geometry in the source domain is obtained through the technique shown in \ref{detsourcedom}. Using Eq. \ref{eq:lingrad}, a linear phase gradient is obtained which is a function of the radiation angle $\theta_{\mathrm{rad}}$ from broadside in the target domain. The achieved phase gradient is used to crop a shape out of a uniform dielectric half-space having a relative permittivity $\epsilon_r = 2$ is placed on top of a thin slot array. The scenario is simulated in COMSOL multiphysics. Figure \ref{fig:simdomain2} presents the simulation setup. An infinite array of slot-line etched on a ground plane placed at the interface of air and a dielectric was simulated using PEC/PMC symmetry planes and PML layers to mimic an infinite array located at the interface of two infinitely stretched half spaces. The solid lines represent the actual region of consideration while the dotted lines show the PML absorbing layers. They grey surface portrays the ground plane that holds a slot-line extended in the positive $\pm x$ direction. The slot-line is excited at the corner with a current source transverse to the length. The ground plane and the slot extends into the PML layer in the positive $\pm x$ direction. The PML layer absorbs the propagating leaky-wave mode in the slot-line and prevents reflections from boundary \cite{chew1995}. Standing waves originated from the reflected fields would cause error in determination of the source domain geometry.  In the negative $x$ direction there is an air gap between the PML boundary and round plane. The PML layer on the left of air gap infinitely extends the free-space region in in the negative $x$ direction, allowing simulation of a corner-fed leaky-wave antenna. The ground plane as well as the slot  perfect electric conductor (PEC) boundaries repeat the domain in the $\pm z$ direction, extending the structure into an infinite array \cite{sadiku2001}.

\begin{figure} [t!]
\centering
  \noindent
    \hspace*{\fill}%
  \mbox{\subfloat[]{
  \begin{overpic}[trim={0cm 0.0cm 0cm 0cm},clip,scale=0.35, keepaspectratio=true]{Figures/Chapter3/fig_transformation/phasecompensation_a}
				\put(3,-4){\footnotesize $z$}
				\put(10,45){\footnotesize $y$}
				\put(107,18){\footnotesize $x$}
				\put(53,77){\footnotesize Cut-line}
	\end{overpic}}}
\hspace*{\fill}%

\hspace*{\fill}%
\mbox{\subfloat[]{
  \begin{overpic}[trim={0cm 0.0cm 0cm 0cm},clip,scale=0.25, keepaspectratio=true]{Figures/Chapter3/fig_transformation/initial_source.png}
				\put(-4,53){\footnotesize $A$}
				\put(96,22){\footnotesize $B$}
				\put(-4,-5){\footnotesize $C$}
				\put(96,-6){\footnotesize $D$}
				\put(-10,-10){\vector(2,0){20}}
				\put(-10,-10){\vector(0,2){20}}
				\put(12,-12){\footnotesize $x$}
				\put(-12,15){\footnotesize $y$}
	\end{overpic}}}
\hspace*{\fill}%
  \mbox{\subfloat[]{
  \begin{overpic}[trim={0cm 0.2cm 0cm 0cm},clip,scale=0.25, keepaspectratio=true]{Figures/Chapter3/fig_transformation/initial_target.png}
				\put(-3,37){\footnotesize $a$}
				\put(97,37){\footnotesize $b$}
				\put(-3,0){\footnotesize $c$}
				\put(97,0){\footnotesize $d$}
				\put(-10,-10){\vector(2,0){20}}
				\put(-10,-10){\vector(0,2){20}}
				\put(12,-12){\footnotesize $u$}
				\put(-12,14){\footnotesize $v$}
				\put(7,47){\vector(2,0){88}}
				\put(95,47){\vector(-2,0){90}}
				\put(43.5,50){\footnotesize $L$}
				\put(105,0){\vector(0,2){42}}
				\put(105,42){\vector(0,-2){42}}
				\put(107,20){\footnotesize $H$}
	\end{overpic}}}
	  \hspace*{\fill}%
  \caption[Conformal transformation of the initial geometry into a rectangular domain.]{The initial geometry (a) that leads to a linear phase profile in the source domain. The conformal mapping from initial homogeneous source domain (b) to initial graded dielectric target domain (c).}
\label{fig:Geocomp}
\end{figure}

The transverse current source excitation of the slot-line generates a leaky-wave mode propagate in $x$ direction and radiates primarily into the upper dielectric half-space. Generated waves form a phase distribution in the dielectric half-space. The fields originated from the structure and the corresponding unwrapped phase are presented in Fig. \ref{fig:simdomain2b}a and \ref{fig:simdomain2b}b. The source domain geometry for the geometric compensation technique is selected using linear variation of phase with space. The electric field transverse to the length of the slot is considered to find the phase gradient from the dielectric half-space. The blue lines in Fig. \ref{fig:simdomain2b}b represent the upper interface that is selected using the linear phase profile in Fig. \ref{fig:simdomain2b}c. The upper interface of the source domain geometry designed with the intention of creating a linear phase profile, corresponding to a fixed radiation $\theta_{\mathrm{rad}}$ from broadside. Figure \ref{fig:Geocomp}a presents the geometry in the source domain which is determined for a radiation angle of $\theta_{\mathrm{rad}} = 30^\circ$. The overall design is carried out for a two-dimensional conformal transformation. Therefore, region under the upper interface (blue line) can be infinitely stretched in the $\pm z$ direction to find the domain in Fig. \ref{fig:Geocomp}a. The geometry with an infinite slot array at the bottom interface is presented in Fig. \ref{fig:Geocomp}a. The linear phase gradient along the upper interface of the geometry can be observed along a cut-line in the upper interface.

For the two-dimensional conformal transformation, the geometries in figures \ref{fig:Geocomp}b and \ref{fig:Geocomp}c are considered. The shape $ABCD$ in \ref{fig:Geocomp}b is a portion of the uniform dielectric in the $xy$ plane along the cut-line indicating in Fig. \ref{fig:Geocomp}a. Using the description in section \ref{detsourcedom}, the geometry $ABCD$ is numerically mapped into a rectangle $abcd$ in $(u,v)$ domain presented in Fig. \ref{fig:Geocomp}c. The initial curved upper boundary is generated by setting the phase gradient along the curve equal to a constant. The constant is a function of the radiation angle from $ab$ in the target domain. The length of the target domain was specified to be $L = 6 \lambda_0$. Its height $H$, limited by the conformal module was $2.9 \lambda_0$. The permittivity distribution inside the rectangular medium is obtained from the transformation process. If the inhomogeneous rectangular superstrate is placed on top of the slot array used in the initial transformation process, generated leaky-wave radiation couples into free-space. The radiation angle depends on the phase-gradient along the upper interface $ab$. Due to the change of length of the upper boundary ($AB$ to $ab$), the phase gradient along $ab$ deviates from the expected linear profile. Figure \ref{fig:phaseini} presents the phase gradient along the radiating interface $ab$ in the target domain, which is clearly non-linear with repect to an ideal linear phase-profile. The non-linearity in phase profile along the interface leads unsatisfactory radiation patterns where the primary lobe deviates from the desired $30^\circ$ radiation angle and radiated power is significantly distributed in the side and back lobes. The linear radiation patterns from the structure are shown in Fig. \ref{fig:cornergeneral_uncomp} for a frequency range of $.5f_0$ to $2f_0$. The plot shows that although the the structure has been designed from a source domain for $30^\circ$ radiation, the primary beam deviates from the angle over the frequency range.

\begin{figure} [t]
\pgfplotsset{compat=1.5,
scale=.9,
tick label style={font=\small},
label style={font=\small},
legend style={font=\small},
% tick style={thick}
}
  \begin{center}
 \input{Figures/Chapter3/fig_smallercorner_polar/fig_polar_general_uncomp.tex}
 \end{center}
  \caption[Radiation patterns of the uncompensated leaky-wave antenna at different frequencies.]{(color inline) Radiation patterns (linear) of the uncompensated leaky-wave antenna at different frequencies. The six radiation patterns are for $0.5f_0$-$2f_0$, where $f_0=c$. Higher gain patters represents higher frequencies.}
\label{fig:cornergeneral_uncomp}
\end{figure}
%
\begin{figure} [t]
\pgfplotsset{compat=1.5,
width=7.5cm,
height=4.64cm,
tick label style={font=\small},
label style={font=\small},
legend style={font=\small},
% tick style={thick}
}
  \begin{center}
 \input{Figures/Chapter3/fig_phase/fig_phase_ini.tex}
 \end{center}
  \caption[Unwrapped phase profiles along the upper boundary of the uncompensated geometry in the target domain.]{Unwrapped phase profiles along the upper boundary of the initially transformed geometry. The dashed blue line presents the ideal linear phase gradient required.}
\label{fig:phaseini}
\end{figure}

In order to achieve a solid fixed-beam performance, the phase gradient along the upper interface of the superstrate needs to be precisely linear. In order to fix the discrepancies in the phase gradient, conformal transformation is required to be carried out. Using Eq. \ref{eq:comp}, a modified source domain is selected that leads to a different target domain medium. As described in the previous chapter, the modified geometry is selected from the unwrapped phase of the fields radiated into a uniform dielectric half-space. The red line in Fig. \ref{fig:phase}a presents upper interface of the compensated geometry, while the blue line is the initially selected interface (Fig. \ref{fig:simdomain2b}).

The modified geometry with the slot array is presented in Fig. \ref{fig:LWAcompensation}a. A slice of the modified source domain along a cut-line is presented by geometry $A'B'C'D'$ in Fig. \ref{fig:LWAcompensation}b. The shape is mapped to the rectangular geometry $a'b'c'd'$ in Fig. \ref{fig:LWAcompensation}c through a two-dimensional conformal transformation. The geometry $a'b'c'd'$ is eventually used as the superstrate of the leaky-wave antenna superstrate. The domain has the same length $L$ as compared to the uncompensated one, however, has a height $H' = 2.9 \lambda_0$.

%and presented in Fig. \ref{fig:LWAcompensation}a. The phase gradient along a cut line along the upper interface is not linear. However, the corresponding target domain has a linear phase profile along its upper interface.
\begin{figure} [t]
\centering
  \noindent
    \hspace*{\fill}%
\pgfplotsset{compat=1.5,
width=7cm,
height=6cm,
tick label style={font=\small},
label style={font=\small},
legend style={font=\small},
% tick style={thick}
}
\hspace*{\fill}%
  \mbox{\subfloat[]{
  \begin{overpic}[trim={4cm -.3cm 2.5cm 0cm},clip,scale=0.65, keepaspectratio=true]{Figures/Chapter3/fig_phase/Ez21_tricked}
  	\put(-4,52){\footnotesize \rotatebox{90}{$y (\lambda_0)$}}
  	\put(30,3){\footnotesize {$x (\lambda_0)$}}
		\end{overpic}}}
\hspace*{\fill}%
  \mbox{\subfloat[]{
 \input{Figures/Chapter3/fig_phase/fig_phase.tex} }}
     \hspace*{\fill}%
  \caption[Compensating the source domain geometry using the corrected phase-profile.] {(color inline) Determining the compensated geometry from the surface plot of phase (degrees) corresponding to the fields in an uniform dielectric half-space(a). Unwrapped phase profiles along the upper boundaries of the initial and compensated geometry (b).}
\label{fig:phase}
\end{figure}

The blue curve in Fig. \ref{fig:phase}a demonstrates how the phase profile along the upper boundary $ab$ is more linear as compared to the initial design. The plot illustrates how the linearity in phase-profile along the radiating interface improves after applying the geometric compensation technique. As will be shown in section \ref{simres}, the geometrically compensated target domain $a'b'c'd'$ demonstrates improved antenna perforamnce as cormpared to the initially designed medium $abcd$.
\begin{figure} [t!]
\centering
  \noindent
    \hspace*{\fill}%
 \mbox{\subfloat[]{
  \begin{overpic}[trim={0cm 0.0cm 0cm 0cm},clip,scale=0.30, keepaspectratio=true]{Figures/Chapter3/fig_transformation/phasecompensation_b}

				\put(3,-4){\footnotesize $w$}
				\put(10,45){\footnotesize $v$}
				\put(105,13){\footnotesize $u$}
				\put(53,77){\footnotesize Cut-line}
	\end{overpic}}}
\hspace*{\fill}%

\hspace*{\fill}%
	\noindent
	\mbox{\subfloat[]{
  \begin{overpic}[trim={0cm 0.0cm 0cm 0cm},clip,scale=0.25, keepaspectratio=true]{Figures/Chapter3/fig_transformation/compensated_source.png}
				\put(-4,50){\footnotesize $A'$}
				\put(94,20){\footnotesize $B'$}
				\put(-4,-2){\footnotesize $C'$}
				\put(94,-2){\footnotesize $D'$}
				\put(-10,-10){\vector(2,0){20}}
				\put(-10,-10){\vector(0,2){20}}
				\put(12,-12){\footnotesize $x$}
				\put(-12,14){\footnotesize $y$}
	\end{overpic}}}
\hspace*{\fill}%
  \mbox{\subfloat[]{
  \begin{overpic}[trim={0cm 1.8cm 0cm 0cm},clip,scale=0.25, keepaspectratio=true]{Figures/Chapter3/fig_transformation/compensated_target.png}
			    \put(-2,30){\footnotesize $a'$}
				\put(93,30){\footnotesize $b'$}
				\put(-2,0){\footnotesize $c'$}
				\put(93,0){\footnotesize $d'$}
				\put(-10,-10){\vector(2,0){20}}
				\put(-10,-10){\vector(0,2){20}}
				\put(12,-12){\footnotesize $u$}
				\put(-12,14){\footnotesize $v$}
				\put(9,42){\vector(2,0){81}}
				\put(87,42){\vector(-2,0){81}}
				\put(46,45){\footnotesize $L$}
				\put(105,2){\vector(0,2){33}}
				\put(105,35){\vector(0,-2){33}}
				\put(107,17.5){\footnotesize $H'$}
	\end{overpic}}}
	  \hspace*{\fill}%
  \caption[The compensated source domain geometry and its transformation to rectangular target domain.] {The compensated geometry (a) that leads to a linear phase profile in the target domain. The conformal mapping from geometrically-compensated homogeneous source domain (b) to geometrically compensated graded dielectric target domain (c).}
\label{fig:LWAcompensation}
\end{figure}

It is observed that the relative permittivity inside the superstrate varies from 0.0790 to 8.8748, as shown in the countour plot of Fig. \ref{fig:permittivity}. Naturally occurring dielectric materials generally have a refractive index greater than unity. Media having a relative permittivity bellow unity needs to be implemented using resonant materials which are narrowband. In order to avoid resonant materials, the region with relative permittivity below 1 were approximated to be 1. The region with unity relative permittivity was distributed along the last end of the superstrate, as illustrated in Fig. \ref{fig:permittivity}. This effectively trimmed the physical length of the superstrate from $L=6 \lambda_0$ to $L=4.2 \lambda_0$, causing an drop in directivity and increase in sidelobe levels.% \textcolor{red}{do you have percentage change?}.
\begin{figure} [t!]
\centering
 	\begin{overpic}[scale=0.8]{Figures/Chapter3/fig_permittivity/corner_fed.png}

  \end{overpic}

  \caption[Permittivity distribution inside the geometrically compensated superstate in the target domain.]{Permittivity distribution inside the geometrically compensated superstate in the target domain.}
\label{fig:permittivity}
\end{figure}

The fields in the target domain $a'b'c'd'$ in Fig. \ref{fig:LWAcompensation}c are re-simulated in the next section with a slot array placed at the bottom interface $c'd'$. The array is specified by a slot spacing of $\lambda_0/10$, slot width of $\lambda_0/50$, and slot length of $6\lambda_0$, where $\lambda_0$ is the free-space wavelength.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Antenna performance} \label{simres}
The leaky-wave antenna is designed as described in section \ref{sec:design} and simulated using COMSOL Multiphysics. The simulated antenna consisted of a corner-fed infinite slot array with a graded index dielectric superstrate on top, similar to the structure shown in Fig. \ref{fig:coupling}c. The rectangular superstrate is designed through transformation optics to linearize the phase along the air-dielectric interface.

\subsection{Fixed-beam broad band performance}
\begin{figure} [t!]
\centering
 	\begin{overpic}[trim={0.5cm -0.5cm 0.5cm 1.4cm},clip,scale=0.35]{Figures/Chapter3/fig_permittivity/Ez.png}

\put(1,41){\footnotesize \rotatebox{90}{$v (\lambda_0)$}}
\put(37,0){\footnotesize {$u (\lambda_0)$}}
  \end{overpic}

  \caption[Simulated electric field of the designed fixed-beam leaky-wave antenna.]{(color inline) Simulated electric field transverse to the slot. The slot generated leaky-wave radiation bends towards the higher permittivity region and couples into free-space.}
\label{fig:field}
\end{figure}
\begin{figure} [h!]
\pgfplotsset{compat=1.5,
scale=.9,
tick label style={font=\small},
label style={font=\small},
legend style={font=\small},
% tick style={thick}
}
  \begin{center}
 \input{Figures/Chapter3/fig_smallercorner_polar/fig_polar_general.tex}
 \end{center}
  \caption[Radiation patterns of the compensated leaky-wave antenna at different frequencies.]{(color inline) Radiation patterns (linear) of the compensated leaky-wave antenna at different frequencies. The six radiation patterns are for $0.5f_0$-$2f_0$, where $f_0=c$. Higher gain patters represents higher frequencies.}
\label{fig:cornergeneral}
\end{figure}
%
Fig. \ref{fig:field} depicts how the fields bend inside the graded dielectric index substrate and subsequently couple into free-space. Interference of fields is visible inside the superstrate which is originated from the reflection at the air-dielectric interface. The oblique radiation of the leaky-wave is visible from the coupled waves. Figure \ref{fig:cornergeneral} illustrates linear radiation patterns of the antenna over broad bandwidth. The six curves represent the radiation patterns from $.5f_0$ to $2f_0$ ($f_0=c$). The plot shows that the structure generates a primary beam directed approximately at the same angle, at $30^\circ$ from broadside in this case.

\subsection{Improvement of radiation pattern using geometric compensation technique}

\begin{figure} [t!]
\pgfplotsset{compat=1.5,
scale=.58,
tick label style={font=\small},
label style={font=\small},
legend style={font=\small},
% tick style={thick}
}
  \begin{center}

 \input{Figures/Chapter3/fig_smallercorner_polar/fig_polar_1.tex}
  \hspace*{\fill}%
  \input{Figures/Chapter3/fig_smallercorner_polar/fig_polar_4.tex}

  \input{Figures/Chapter3/fig_smallercorner_polar/fig_polar_8.tex}
  \hspace*{\fill}%
  \input{Figures/Chapter3/fig_smallercorner_polar/fig_polar_10.tex}

  \input{Figures/Chapter3/fig_smallercorner_polar/fig_polar_12.tex}
  \hspace*{\fill}%
  \input{Figures/Chapter3/fig_smallercorner_polar/fig_polar_16.tex}

 \end{center}
  \caption[Normalized radiation patterns for the initial and compensated (blue) corner-fed leaky-wave antenna at particular frequencies.]{(color inline) Normalized radiation patterns for the initial (red) and compensated (blue) leaky-wave antenna at different frequencies.}
\label{fig:cornerpolar}
\end{figure}
%
\begin{figure} [t!]
	\pgfplotsset{compat=1.5,
		width=20cm,
		height=5.2cm,
		scale=.8,
		tick label style={font=\small},
		label style={font=\small},
		legend style={font=\small},
		% tick style={thick}
	}
	\begin{center}
		\input{Figures/Chapter3/fig_smallercorner_characterize/fig_radangle_corner.tex}
	\end{center}
  \caption[Characterization plots comparing the angle of radiation, sidelobe level, backlobe level, 3dB beamwidth and directivity of the corner-fed antenna over a broad bandwidth.]{(color inline) (a) Radiated beam angle, (b) 3dB beam width, (c) sidelobe level, (d) backlobe level and (e) directivity of the leaky-wave antenna for the geometrically compensated superstrate (blue) and initially designed superstrate (red). The dashed black line in (a) represents the average beam angle of $33^o$.}
\label{fig:cornerradpattern}
\end{figure}

%
To compare the performance of the antenna at different frequencies, normalized radiation patterns at different frequencies need to be compared. Normalized radiation patterns at different frequencies comparing the initial design and the compensated design is presented in Fig. \ref{fig:cornerpolar}. The blue and red curves presents the far-field radiation pattern for the geometrically compensated and initial design, respectively. The normalized radiation patterns illustrates how the performance of the antenna increases with the increase of frequency. At higher frequencies, the electrical antenna structure is long enough to allow the leaky-wave mode in the slot to decay. However, the antenna structure becomes electrically smaller at lower frequencies. The propagating leaky-wave mode is strong enough at the end of the structure is strong enough to cause significant standing wave components in the slot. Therefore the antenna performance degrades at lower frequencies. Regardless of higher sidelobe and backlobe levels at lower frequencies, the primary beam remains at the designed angle ($\theta_{\mathrm{rad}} = 30^\circ$ from broadside).

Fig. \ref{fig:cornerradpattern} presents the parameters of the simulated leaky-wave antenna with the geometrically compensated superstrate and the initial design. Simulated radiation angle, 3dB beamwidth, percentage sidelobe level, percentage backlobe level and directivity of the antenna at different frequencies for both initial and geometrically compensated design. As illustrated in Fig. \ref{fig:cornerradpattern}a, the radiation angle for the compensated superstrate remain consistent as compared to the initial design, fluctuating around the designed $30$ degrees over the desired bandwidth. According to in Fig. \ref{fig:cornerradpattern}b, 3dB beamwidth for the compensated design is relatively less than the initial design and follows a downward trend with the increase of frequency. The sidelobe level (Fig. \ref{fig:cornerradpattern}c) and backlobe level (Fig. \ref{fig:cornerradpattern}d) graphs show the percentage sidelobe and backlobe level for the compensated design is reasonably less than that for the initial design throughout the frequency range. At the lower cut-off frequency the simulated sidelobe level and backlobe level are $37.3\%$ and $79.8\%$, respectively for the compensated superstrate while results for the same antenna parameters initial design are $46.4\%$ and $91.6\%$, respectively. The percentage sidelobe level and  backlobe level marginally decrease to $30\%$ and $46\%$for the compensated superstrate, being lower than the initial design over the frequency range. As for the directivity of the leaky-wave antenna in Fig. \ref{fig:cornerradpattern}e, it shows an upward trend with the increase of frequency for both designs. The compensated design generates more directive beam over the range of frequency, evaluated to be $4.6$ and $15$ at the lower and upper cut-off frequencies, respectively.

\begin{figure} [t!]
\centering
  \noindent
\hspace*{\fill}%
	\noindent
  \pgfplotsset{compat=1.5,
scale=1,
tick label style={font=\small},
label style={font=\small},
legend style={font=\small},
width=6cm,
height=3.8cm,
% tick style={thick}
}
\hspace*{\fill}%
\mbox{\subfloat[] {\input{Figures/Chapter3/fig_Zin/fig_zin.tex}}}
\hspace*{\fill}%
\mbox{\subfloat[] {\input{Figures/Chapter3/fig_Zin/fig_returnloss.tex}}}
\hspace*{\fill}%
  \caption[Input impedance and the return loss of the geometrically compensated leaky-wave antenna.]{(color inline) Real (brown) and imaginary (green) input impedance of the leaky-wave antenna with the geometrically-compensated superstrate (a). Return loss (dB) matched to the average input impedance ($Z_0$=69.367 + 73.64j Ohms)(b). }
\label{fig:inimp}
\end{figure}

Real and imaginary part of the input impedance has been calculated using Eq. \ref{eq:eta}. The impedance as a function of frequency for the simulated leaky-wave antenna is presented in Fig. \ref{fig:inimp}a. It is observed that the input impedance is fairly consistent over the desired range of frequency, which indicates that the antenna can be fairly matched to an optimized network over the entire operating bandwidth. Figure \ref{fig:inimp}b presents the return loss of the structure when matched to the average value of the input impedance ($Z_0$=69.367 + 73.64j Ohmss).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Center-fed design with a back reflector}

For certain applications, a fixed-beam antenna may be required to produce two beams instead of a single beam. The corner-fed design explained in previous section can be extended into a center-fed leaky-wave antenna. It will be later shown that at some frequencies, the backlobe level of the antenna is high. A back reflector was incorporated can the structure to eliminate the backlobes; however, the effect of the back reflector on primary beam direction, the sidelobes and directivity is unknown.

\begin{figure} [th!]
\centering
 	\begin{overpic}[scale=0.5]{Figures/Chapter5/fig_double/domain}
 	\put(22,60){\footnotesize Uniform dielectric}
 	\put(-25,43){\footnotesize Line current}
 	\put(-39,32){\footnotesize Ground plane (PEC)}
 	\put(-10,25){\footnotesize PMC}
 	\put(-9,20){\footnotesize PEC}

 	\put(30,95){\footnotesize PML}
 	\put(35,4){\footnotesize PML}
 	\put(71,55){\footnotesize PML}

 	\put(101,10){\footnotesize $x$}
	\put(88,23){\footnotesize $y$}
	\put(84,15){\footnotesize $z$}
 	\end{overpic}

  \caption[Simulation domain of the center-fed leaky-wave antenna with a back-reflector.]{Simulation domain of the center-fed leaky-wave antenna with a back-reflector.}
\label{fig:double}
\end{figure}
%
\begin{figure} [t!]
	\pgfplotsset{compat=1.5,
		width=20cm,
		height=5.2cm,
		scale=.8,
		tick label style={font=\small},
		label style={font=\small},
		legend style={font=\small},
		% tick style={thick}
	}
	\begin{center}
		\input{Figures/Chapter5/fig_double/fig_double.tex}
	\end{center}
    \caption[Characterization plots comparing the Peak field, Radiated beam angle, sidelobe level, 3dB beam width, and broadside field of the slot radiation into a two diefferent halfspaces.]{(color inline) Peak field, Radiated beam angle, sidelobe level, 3dB beam width, and broadside field of the slot radiation into a halfspace having $\epsilon_r=2$ (red) and $\epsilon_r=4$ (violet). The $x$ axis represents the distance of a ground plane from the slot plane.}
\label{fig:char_epsilon}
\end{figure}

In order to observe the variation of the leaky-wave radiation in presence of a back reflector, a slot-line was placed under a uniform dielectric half-space with a PEC back reflector. The simulation domain is presented in Fig. \ref{fig:double}. The slot-line is positioned under a dielectric half-space (grey region). PEC and PMC symmetry places were implemented to simulated the structural periodicity of the center-fed design. The distance of the back reflector was varied from $0.5 \lambda_0$ to $1.5 \lambda_0$ to observe the radiation inside the dielectric. The peak field, angle of radiation (measure from broadside), percentage sidelobe level and beamwidth is observed and presented in Fig. \ref{fig:char_epsilon}. Two different dielectric half spaces, having relative permittivity values of $2$ and $4$, were simulated for each position of back-reflector. It is observed that the position of the back reflector less than $0.5 \lambda$ contains zero side lobes and contains decent directivity. Therefore, the back reflector is to be placed in that particular region.

\begin{figure} [t!]
\centering
 	\begin{overpic}[scale=0.8]{Figures/Chapter3/fig_permittivity/center_fed.png}

  \end{overpic}
  \caption[Permittivity distribution inside the inhomogeneous superstrate used for the center-fed design.]{(color inline) Permittivity distribution inside the inhomogeneous superstrate used for the center-fed design.}
\label{fig:eps_double}
\end{figure}

The center-fed design was simulated using COMSOL with and without a back reflector. The graded-dielectric superstrate was design using transformation optics and improved by the geometric compensation technique. Figure \ref{fig:eps_double} presents the dielectric distribution of the superstrate, designed using the geometric compensation technique. To simulated the antenna as a center-fed design with two primary beams, is extended in the positive and negative $x$ direction. In that way, the structure of the antenna doubles in size, however, two primary beams are generated from the structure. The superstrate is designed using the geometric compensation technique. A back reflector is placed at a distance $0.25 \lambda_0$ below the slot-line. Figure \ref{fig:polar} represents the normalized far-field plots of the center-fed design. The red curves present the patterns for the aced uncompensated design, while the blue and red curve shows the pattern for the geometrically compensated design without and with a back reflector, respectively.
%
\begin{figure} [th!]
\pgfplotsset{compat=1.5,
scale=.58,
tick label style={font=\small},
label style={font=\small},
legend style={font=\small},
% tick style={thick}
}
  \begin{center}

 \input{Figures/Chapter3/fig_smallercenter_polar/fig_polar_1.tex}
  \hspace*{\fill}%
  \input{Figures/Chapter3/fig_smallercenter_polar/fig_polar_4.tex}

  \input{Figures/Chapter3/fig_smallercenter_polar/fig_polar_8.tex}
  \hspace*{\fill}%
  \input{Figures/Chapter3/fig_smallercenter_polar/fig_polar_10.tex}

  \input{Figures/Chapter3/fig_smallercenter_polar/fig_polar_12.tex}
  \hspace*{\fill}%
  \input{Figures/Chapter3/fig_smallercenter_polar/fig_polar_16.tex}

 \end{center}
  \caption[Normalized radiation patterns for the initial as well as the compensated center-fed leaky-wave antenna with and without a backreflector at different frequencies.] {(color inline) Normalized radiation patterns for the initial (red) as well as the compensated center-fed leaky-wave antenna with (green) and without (blue) a backreflector at different frequencies.}
\label{fig:polar}
\end{figure}
%
%
Fig. \ref{fig:centeradpattern} illustrates the antenna parameters of the simulated center-fed design for geometrically compensated superstrate with and without a back reflector as well as for the initial design. It can be observed that although the back reflector eliminates the backlobe of the antenna, it increases the overall sidelobe level and beam variation over the beamwidth. However, it increases the directivity of the antenna.

\begin{figure} [t!]
	\pgfplotsset{compat=1.5,
		width=20cm,
		height=5.2cm,
		scale=.8,
		tick label style={font=\small},
		label style={font=\small},
		legend style={font=\small},
		% tick style={thick}
	}
	\begin{center}
		\input{Figures/Chapter3/fig_smallercorner_characterize/fig_radangle_center.tex}
	\end{center}
  \caption[Characterization plots comparing the angle of radiation, sidelobe level, backlobe level, 3dB beamwidth and directivity of the center-fed antenna over a broad bandwidth.]{(color inline) (a) Radiated beam angle, (b) 3dB beam width, (c) sidelobe level, (d) backlobe level and (e) directivity of the leaky-wave antenna for the geometrically compensated superstrate (blue) the back reflector (green) and initially designed superstrate (red).}
\label{fig:centeradpattern}
\end{figure}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Summary}
%The phase of the wave constitute a precise profile at the upper interface of the that determines the radiation angle of the transmitted radiation. The permittivity distribution of the superstrate is obtained through transformation electromagnetics and is considered as the target domain in the process. The shape of corresponding homogeneous source domain determines the aspect ratio and permittivity profile of the superstrate. Using numerical quasi-conformal transformation, the rectangular inhomogeneous superstate is designed to behave like the homogeneous dielectric medium so that the two media have identical far-field field behavior.  However, later sections in this chapter will demonstrate that the optically transformed rectangular media  do not behave like the initial media because of discrepancies in phase distribution at the radiating interface. The phase-deviations at the interface deteriorates the broad band performance of the antenna with increased sidelobe level, backlobe level, directivity. In order to fix the discrepancies and improve the antenna performance, a two-step quasi-conformal transformation is required which We propose as \textit{geometric compensation technique}. Following sections demonstrate the origins of the phase-discrepancies and the technique of geometric compensation.

Using the geometric compensation technique presented in Ch. \ref{Chapter2}, a leaky-wave antenna with fixed beam characteristics has been demonstrated in this chapter. Couple of variations, included a corner-fed as well as a center-fed with and without a back reflector, in the design process has been shown with simulations results and analysis. The results depict that the design using geometric compensation technique indeed offers improved radiation from the antenna as compared to the preliminary design shown in Ch. \ref{Chapter5}.


\subsection{UCLA Learning \& Forgetting Lab}

\subsubsection{New theory of disuse}
Finally, sometimes people cannot recall information at one point in time, but can recall it later. In looking at these situations, it seems that our memories work in strange and unpredictable ways. The function of our memories, however, may be predictable. The New Theory of Disuse (R. A. Bjork \& E. L. Bjork, 1992) posits that there are two indices of memory strength: storage strength (SS) and retrieval strength (RS).

Storage strength is how well learned something is;

retrieval strength is how accessible (or retrievable) something is.

The New Theory of Disuse postulates that RS and SS interact in interesting ways. For example, the more SS information has, the bigger the boost in RS it will receive as a consequence of restudy (e.g., you can relearn a childhood address much more quickly than a new address, even if you can't recall either of them initially). The more RS that information has, the smaller the boost in SS as a consequence of restudy (e.g., simply repeating to-be-learned information over and over again is not very helpful for really learning that information because you are probably practicing rote rehearsal, without forming the deeper connections necessary to improve long-term retention).

\subsubsection{How we learn versus How we think we learn: Desirable Difficulties in Theory and Practise}

\textbf{Introduction to Desirable Difficulties}

Imagine a scenario in which a teacher has students practice different examples of a single type of math problem for an hour in class. By the end of the hour, it may seem—both to the teacher and to the students—that this type of math problem has been mastered. On a test two weeks later, however, the benefit may not be evident. In fact, much to the dismay of the teacher and the students, performance during training is not always representative of long-term learning. In contrast to the story told above, in which an easy training method was followed by poor performance later, imagine that the teacher had interleaved many different types of problems during in-class training drills.

There are, in fact, certain training conditions that are difficult and appear to impede performance during training but that yield greater long-term benefits than their easier training counterparts. R. A. Bjork (1994) dubbed these difficult but effective training conditions desirable difficulties.

Other examples of desirable difficulties (explained in greater detail in later portions of this webpage) include spacing rather than massing repetitions of to-be-learned information (R. A. Bjork \& Allen, 1970; for review, see Cepeda, Pashler, Vul, Wixted, \& Rohrer, 2006), testing rather than re-studying information (Halamish \& R. A. Bjork, 2011; for review, see Roediger \& Karpicke, 2006), and varying the conditions of practice instead of keeping them constant.

\subsubsection{Spacing}
It is common sense that when we want to learn information, we study that information multiple times. The schedules by which we space repetitions can make a huge difference, however, in how well we learn and retain information we study. The spacing effect is the finding that information that is presented repeatedly over spaced intervals is learned much better than information that is repeated without intervals (i.e., massed presentation). This effect is one of the most robust results in all of cognitive psychology and has been shown to be effective over a large range of stimuli and retention intervals from nonsense syllables (Ebbinghaus, 1885) to foreign language learning across many months (Bahrick, Bahrick, Bahrick \& Bahrick, 1993).

reducing the accessibility of information in memory fosters additional learning of that information (see New Theory of Disuse). In this view, increasing the spacing between learning trials enhances learning because it decreases accessibility of the to-be-learned information.

\textbf{Indeed, R. A. Bjork and Allen (1970) found that increasing the difficulty of an intervening distractor task without changing the duration of the spacing interval leads to improved learning, much like a spacing effect.}

accessibility increased, rather than decreased, with delay— R. A. Bjork, Kornell and Cheung (2009) reversed the spacing effect

This theory of spacing would predict that an optimal learning schedule is one with expanding retrieval practice, rather than equally spaced practices. With successive practices, information is better learned and becomes inaccessible more slowly. As the greatest learning occurs when information accessibility is low (but not impossible), increasingly longer lags between retrieval practices should lead to better long-term learning. Indeed, Landauer and R. A. Bjork (1978) showed that expanding retrieval is better than uniform retrieval in two well-controlled experiments.

\subsubsection{Interleaving}
Spacing is one of the most robust, effective ways of improving learning. However, spacing calls for intervals of time in between repetitions, and this may not be the most efficient use of time. Imagine you have three final exams to study for. If you were to space out study of three whole courses, you might as well start your course review before the quarter even begins! Particularly when one has several different things to learn, an effective strategy is to interleave one's study: Study a little bit of history, then a little bit of psychology followed by a chapter of statistics and go back again to history. Repeat (best if in a blocked-randomized order).

Interleaving benefits not only memory for what is studied, but also leads to benefits in the transfer of learned skills (e.g. Carson \& Wiegand, 1979). The theory is that interleaving requires learners to constantly "reload" motor programs (in the case of motor skills) or retrieve strategies/information (in the case of cognitive skills) and allows learners to extract more general rules that aid transfer.

Interleaving is to shuffle the exemplars of a given category between exemplars of other similar categories. Interleaving however has the effect of both creating temporal spacing between exemplars of a given category and creating temporal juxtaposition of exemplars of different categories.

Kornell, Birnbaum, Bjork, and Bjork (in preparation) investigated these separate effects and found that \textbf{temporal juxtaposition, which allows for discrimination processes, is more critical to inductive learning than simple temporal spacing is.}
% So I should shuffle the questions, and categories.

\textbf{OBS:} Additionally, although spacing alone and interleaving alone offer benefits to inductive learning performance (both desirable difficulties, combining the two manipulations does not provide an additive benefit to inductive learning performance (see Interactions between Desirable Difficulties).

\textbf{Perceptual desirable difficulties}
Fluency, or the subjective ease of processing information, can provide learners with a useful basis for judging how well information has been understood. Perceptual variations are among the most obvious--and, sometimes, the most misleading—cues to the fluency of information. For example, when you encounter fonts that are difficult to read or words in very small print, you may experience a sense of disfluency—that is, you may have a feeling that the unusual or small typefaces are more difficult to process than more common typefaces.

These types of perceptual cues often cause people to think that disfluent information will be harder to remember than fluent information. Some research, however, indicates that perceptual disfluency can be a desirable difficulty (Diemand-Yauman, Oppenheimer, \& Vaughan, 2010). The subjective difficulty of processing disfluent information can actually lead people to engage in deeper processing strategies, which then results in higher recall for those items (Alter, Oppenheimer, Epley, \& Eyre, 2007).
\todo{Detta är också nyttig insikt}

\textbf{Interactions between desirable difficulties}
It is not enough to simply provide educators with a list of desirable difficulties and claim that our work in optimizing learning has been completed. It may be that certain combinations of desirable difficulties interact to yield super-additive or sub-additive effects, if the processes by which the desirable difficulties work enhance or interfere with each other. Research into these interactions is therefore important on both practical ("What is best for learning?") and theoretical ("How do these desirable difficulties work to influence memory?") levels.

%Kritik:
At longer spacing intervals, variation actually hurts memory performance.

Furthermore, the results of this study supported the study-phase retrieval theory of spacing over the encoding variability theory of spacing (see Spacing).

Current studies in this line of research include examining the interactions between spacing and generation and spacing and variation with educationally relevant materials, such as text passages and glossary-style definitions. Interactions are also being explored with inductive learning, and Kornell, Birnbaum, Bjork \& Bjork (in preparation) have found a subadditive effect of spacing and interleaving in the induction of butterfly species (see Interleaving).

\subsubsection{Learning concepts and catagories}
Kornell and R. A. Bjork (2008) found that while many students believe that studying examples of a category all at once leads to more effective inductive learning than studying them intermixed with examples of other to-be-learned categories, the opposite is in fact true (see Interleaving).

\subsubsection{Goal-Directed Forgetting: Directed forgetting}
In the typical list-based directed forgetting paradigm (E. L. Bjork \& R. A. Bjork, 1996), a participant will study two lists of words, and is notified after each list whether or not it will be tested later on. If a list is tested after the learner was notified that it would not be tested, the learner will show weaker recall for that list, compared to a baseline condition in which all lists are expected to be tested, demonstrating the costs of directed forgetting. Interestingly, it is commonly found that recall of any list that was expected to be tested will be greater than that of the baseline condition, demonstrating the unexpected benefits of directed forgetting.
\todo{This suggests that if Josefina says to the students that X will be tested, people will pay more attention}

\subsubsection{Metacognition}
Metacognition refers to the subjective awareness of one's own knowledge. In the Bjork Learning and Forgetting Lab, we focus on how this relates to learning and study behaviors, or metamemory. Metamemory consists of both monitoring the state of one's memory (or lack thereof) as well as using this information to control study decisions. Accurate metamemory can be crucial for a student in determining the success of his or her own study program.

\textbf{Fluency and biases}
(students) instead seem to assume that what they know at the time the judgment is made is an accurate reflection of what they will know at a later time point.

\textbf{Awareness of study strategies}
 Zechmeister and Shaughnessy (1980) showed that people tend to think massed repetitions are more effective than spaced repetitions. Massed repetitions lead to greater short-term performance, but impair long-term performance (e.g., Simon \& Bjork, 2001); this dissociation could explain why people think massed repetitions are more effective. Kornell and R. A. Bjork (2008) found that in the case of inductive learning, the belief that massed presentation is better than spaced presentation holds true even after people have taken a test and have done better with spacing! At the same time, other recent work (e.g., Benjamin \& Bird, 2006; Toppino \& Cohen, 2010) has found evidence that people do prefer later re-study to immediate re-study when allowed to choose between the two.
 \todo{Detta är också nyttigt för mig att känna till}


\lab{Algorithms}{An Introduction to Parallel Programming using MPI}{Introduction to Parallel Programming}
\objective{Learn the basics of parallel computing on distributed memory machines using MPI for Python}
\objective{Learn how to write basic parallel algorithms such as the trapezoidal rule}
\label{lab:MPI_Intro}

\section*{Why Parallel Computing?}
Over the past few decades, vast increases in computational power have come through
increased single processor performance, which have almost wholly been driven by smaller transistors.
However, these faster transistors generate more heat, which destabilizes circuits.
The so-called ``heat wall'' refers to the physical limits of single processors to
become faster because of the growing inability to sufficiently dissipate heat.

To get around this physical limitation, parallel computing was born.
It began, as with most things, in many different systems and styles, involving various systems.
Some systems had shared memory between many processors and some systems had a separate
program for each processor while others ran all the processors off the same base program.

Today, the most commonly used method for high performance computing is a single-program,
multiple-data system with message passing.
Essentially, these supercomputers are made up of many, many normal computers, each with their own memory.
These normal computers are all running the same program and are able to communicate with each other. Although they all run the same program file, each process takes a different execution path through the code, as a result of the interactions that message passing makes possible.

Note that the commands being executed by process \emph{a} are going to be different
from process \emph{b}. Thus, we could actually write two separate computer programs
in different files to accomplish this.
However, the most common method today has become to write both processes in a single program,
using conditionals and techniques from the Message Passing Interface to control which
lines of execution get assigned to which process.

This is a very different architecture than ``normal'' computers, and it requires a
different kind of software. You can't take a traditional program and expect it to
magically run faster on a supercomputer; you have to completely design a new algorithm
to take advantage of the unique opportunities parallel computing gives.

\section*{MPI: the Message Passing Interface}
At its most basic, the Message Passing Interface (MPI) provides functions for sending
and receiving messages between different processes.

MPI was developed out of the need for standardization of programming parallel systems.
It is different than other approaches in that MPI does not specify a particular language.
Rather, MPI specifies a library of functions--the syntax and semantics of message passing routines--that can be called from other programming languages,
such as Python and C. MPI provides a very powerful and very general way of expressing parallelism.
It can be thought of as ``the assembly language of parallel computing,'' because of this
generality and the detail that it forces the programmer to deal with
\footnote{Parallel Programming with MPI, by Peter S. Pacheco, p. 7}.
In spite of this apparent drawback, MPI is important because it was the first portable,
universally available standard for programming parallel systems and is the \emph{de facto} standard.
That is, MPI makes it possible for programmers to develop portable, parallel software libraries,
an extremely valuable contribution.
Until recently, one of the biggest problems in parallel computing was the lack of software.
However, parallel software is growing faster thanks in large part to this standardization.

\begin{problem}
Most modern personal computers now have multicore processors.
In order to take advantage of the extra available computational power, a single program must be specially designed.
Programs that are designed for these multicore processors are also ``parallel'' programs, typically written using POSIX threads or OpenMP.
MPI, on the other hand, is designed with a different kind of architecture in mind.
How does the architecture of a system for which MPI is designed differ what POSIX threads or OpenMP is designed for?
What is the difference between MPI and OpenMP or Pthreads?
\end{problem}

\section*{Why MPI for Python?}
In general, parallel programming is much more difficult and complex than in serial.
Python is an excellent language for algorithm design and for solving problems that
don't require maximum performance.
This makes Python great for prototyping and writing small to medium sized parallel programs.
This is especially useful in parallel computing, where the code becomes especially complex.
However, Python is not designed specifically for high performance computing and its
parallel capabilities are still somewhat underdeveloped, so in practice it is better
to write production code in fast, compiled languages, such as C or Fortran.

We use a Python library, mpi4py, because it retains most of the functionality of
C implementations of MPI, making it a good learning tool since it will be easy to
translate these programs to C later.
There are three main differences to keep in mind between mpi4py and MPI in C:
\begin{itemize}
    \item Python is array-based. C and Fortran are not.
    \item mpi4py is object oriented. MPI in C is not.
    \item mpi4py supports two methods of communication to implement each of the basic MPI commands.
    They are the upper and lower case commands (e.g. \li{Bcast(...)} and \li{bcast(...)}).
    The uppercase implementations use traditional MPI datatypes while the lower case use
    Python's pickling method. Pickling offers extra convenience to using mpi4py,
    but the traditional method is faster. In these labs, we will only use the uppercase functions.
\end{itemize}

\section*{Introduction to MPI}
As tradition has it, we will start with a Hello World program.
\lstinputlisting[style=fromfile]{hello.py}
Save this program as \texttt{hello.py} and execute it from the command line as follows:
\begin{lstlisting}[style=ShellInput]
$ mpirun -n 5 python hello.py
\end{lstlisting}
The program should output something like this:
\begin{lstlisting}[style=ShellOutput]
Hello world! I'm process number 3.
Hello world! I'm process number 2.
Hello world! I'm process number 0.
Hello world! I'm process number 4.
Hello world! I'm process number 1.
\end{lstlisting}
Notice that when you try this on your own, the lines will not necessarily print in order.
This is because there will be five separate processes running autonomously, and we cannot
know beforehand which one will execute its \li{print} statement first.

\begin{warn}
It is usually bad practice to perform I/O (e.g., call \li{print}) from any process
besides the root process, though it can oftentimes be a useful tool for debugging.
\end{warn}

\section*{Execution}
How does this program work? As mentioned above, mpi4py programs are follow the single-program
multiple-data paradigm, and therefore each process will run the same code a bit differently.
When we execute
\begin{lstlisting}[style=ShellInput]
$ mpirun -n 5 python hello.py
\end{lstlisting}
a number of things happen:

First, the mpirun program is launched.
This is the program which starts MPI, a wrapper around whatever program you to pass into it.
The ``-n 5'' option specifies the desired number of processes.
In our case, 5 processes are run, with each one being an instance of the program ``python''.
To each of the 5 instances of python, we pass the argument ``hello.py'' which is the name of our program's text file,
located in the current directory. Each of the five instances of python then opens the
\texttt{hello.py} file and runs the same program.
The difference in each process's execution environment is that the processes are given
different ranks in the communicator. Because of this, each process prints a different
number when it executes.

MPI and Python combine to make wonderfully succinct source code.
In the above program, the line \li{from mpi4py import MPI} loads the MPI module from the mpi4py package.
The line \li{COMM = MPI.COMM_WORLD} accesses a static communicator object, which represents a group of processes which can communicate with each other via MPI commands.

The next line, \li{RANK = COMM.Get_rank()}, is where things get interesting.
A ``rank'' is the process's id within a communicator, and they are essential to learning
about other processes. When the program mpirun is first executed, it creates a
global communicator and stores it in the variable \li{MPI.COMM_WORLD}.
One of the main purposes of this communicator is to give each of the five processes a
unique identifier, or ``rank''. When each process calls \li{COMM.Get_rank()},
the communicator returns the rank of that process.
\li{RANK} points to a local variable, which is unique for every calling process
because each process has its own separate copy of local variables.
This gives us a way to distinguish different processes while writing all of the source code
for the five processes in a single file.

In more advanced MPI programs, you can create your own communicators, which means that
any process can be part of more than one communicator at any given time.
In this case, the process will likely have a different rank within each communicator.

Here is the syntax for \li{Get_size()} and \li{Get_rank()}, where \li{Comm} is a communicator object:
\begin{description}
\item[Comm.Get\_size()]
Returns the number of processes in the communicator. It will return the same number to every process.
Parameters:
\begin{description}
    \item[Return value] - the number of processes in the communicator
    \item[Return type] - integer
\end{description}
Example:
\lstinputlisting[style=FromFile]{Get_size_example.py}
\item[Comm.Get\_rank()]
Determines the rank of the calling process in the communicator.
Parameters:
\begin{description}
    \item[Return value] - rank of the calling process in the communicator
    \item[Return type] - integer
\end{description}
Example:
\lstinputlisting[style=FromFile]{Get_rank_example.py}
\end{description}

\begin{problem}
Write the ``Hello World'' program from above so that every process prints out its
rank and the size of the communicator
(for example, process 3 on a communicator of size 5 prints ``Hello World from process 3 out of 5!'').
\end{problem}

\section*{The Communicator}
A communicator is a logical unit that defines which processes are allowed to
send and receive messages. In most of our programs we will only deal with the \li{MPI.COMM_WORLD}
communicator, which contains all of the running processes.
In more advanced MPI programs, you can create custom communicators to group only a small
subset of the processes together. By organizing processes this way, MPI can
physically rearrange which processes are assigned to which CPUs and optimize your
program for speed. Note that within two different communicators, the same process
will most likely have a different rank.

Note that one of the main differences between mpi4py and MPI in C or Fortran,
besides being array-based, is that mpi4py is largely object oriented.
Because of this, there are some minor changes between the mpi4py implementation of
MPI and the official MPI specification.

For instance, the MPI Communicator in mpi4py is a Python class and MPI functions
like \li{Get_size()} or \li{Get_rank()} are instance methods of the communicator class.
Throughout these MPI labs, you will see functions like \li{Get_rank()} presented as
\li{Comm.Get_rank()} where it is implied that \li{Comm} is a communicator object.

\section*{Separate Codes in One File}
When an MPI program is run, each process receives the same code.
However, each process is assigned a different rank, allowing us to specify separate
behaviors for each process. In the following code, all processes are given the same two numbers.
However, though there is only one file, 3 processes are given completely different instructions
for what to do with them. Process 0 sums them, process 1 multiplies them,
and process 2 takes the maximum of them:
\lstinputlisting[style=FromFile]{separateCode.py}

\begin{problem}
Write a program in which the the processes with an even rank print ``Hello'' and
process with an odd rank print ``Goodbye.''
Print the process number along with the ``Hello'' or ``Goodbye''
(for example, ``Goodbye from process 3'').
\end{problem}

\begin{problem}
Sometimes the program you write can only run correctly if it has a certain number of processes.
Although you typically want to avoid writing these kinds of programs, sometimes it is
inconvenient or unavoidable. Write a program that runs only if it has 5 processes.
Upon failure, the root node should print ``Error: This program must run with 5 processes''
and upon success the root node should print ``Success!'' To exit, call the function
\li{COMM.Abort()}.
\end{problem}

As was mentioned the simplest message passing involves two processes: a sender and a receiver. We will use these methods to parallelize the Trapezoidal Rule.

\section*{Simple Message Passing}
Let us begin by demonstrating a program designed for two processes. One will draw a random number and then send it to the other. We will do this using the routines \li{Comm.Send} and \li{Comm.Recv} (short for ``receive''):

\lstinputlisting[style=FromFile]{passValue.py}

To illustrate simple message passing, we have one process choose a random number and then pass it to the other. Inside the recieving process, we have it print out the value of the variable \li{num_buffer} \emph{before} it calls \li{Recv} to prove that it really is recieving the variable through the message passing interface.

Here is the syntax for \li{Send} and \li{Recv}, where \li{Comm} is a communicator object:

\begin{description}
\item[Comm.Send(buf, dest=0, tag=0)]
Performs a basic send. This send is a point-to-point communication. It sends information from exactly one process to exactly one other process.
Parameters:
\begin{description}
\item[buf (array-like)] – data to send.

% TODO expand here- must be numpy array (as a pointer) and won't work with strings

\item[dest (integer)] – rank of destination
\item[tag (integer)] – message tag
\end{description}
Example:
\lstinputlisting[style=FromFile]{Send_example.py}
\item[Comm.Recv(buf, source=0, tag=0, Status status=None)]
Basic point-to-point receive of data.
Parameters:
\begin{description}
\item[buf (array-like)] – initial address of receive buffer (choose receipt location)
\item[source (integer)] – rank of source
\item[tag (integer)] – message tag
\item[status (Status)] – status of object
\end{description}
Example:
See example for Send()
\end{description}

\begin{info}
\li{Send} and \li{Recv} are referred to as \emph{blocking} functions. That is, if a process calls \li{Recv}, it will sit idle until it has received a message from a corresponding \li{Send} before it will proceeed. (However, the process that calls \li{Comm.Send} will \emph{not} necessarily block until the message is recieved- it depends on the implementation) There are corresponding \emph{non-blocking} functions \li{Isend} and \li{Irecv} (The \emph{I} stands for immediate). In essence, \li{Irecv} will return immediately. If a process calls \li{Irecv} and doesn't find a message ready to be picked up, it will indicate to the system that it is expecting a message, proceed beyond the \li{Irecv} to do other useful work, and then check back later to see if the message has arrived. This can be used to dramatically improve performance.
\end{info}

% TODO ASK is Send blocking in C? It isn't in python... I added in a note here

\begin{info}
When calling \li{Comm.Recv}, you can allow the calling process to accept a message from any process that happend to be sending to the receiving process. This is done by setting source to a predefined MPI constant, \li{source=ANY_SOURCE} (note that you would first need to import this with from \li{mpi4py.MPI import ANY_SOURCE} or use the syntax \li{source=MPI.ANY_SOURCE}).
\end{info}

\begin{problem}
Write a Python script \texttt{passVector.py} (adapted from \texttt{passValue.py}) that passes an $n$ by $1$ vector of random values from one process to the other. Write it so that the user passes the value of $n$ in as a command-line argument (similar to the code developed later in this lab for the trapezoidal rule).
\end{problem}

\begin{problem}
Try modifying some of the parameters in \li{Send} and \li{Recv} in the code from the previous exercise (\li{dest}, \li{source}, and \li{tag}).  What happens to the program? Does it hang or crash? What do you suppose the \li{tag} parameter does?
\end{problem}
% TODO delete this one?

\begin{problem}
Write a Python script \texttt{passCircular.py} (again adapted from \texttt{passValue.py}). This time, write the program so that each process with rank $i$ sends a random value to the process with rank $i+1$ in the global communicator. The process with the highest rank will send its random value to the root process. Notice that we are communicating in a ring. For communication, only use \li{Send} and \li{Recv}. The program should work for any number of processes. (Hint: Remember that \li{Send} and \li{Recv} are blocking functions. Does the order in which \li{Send} and \li{Recv} are called matter?)
% TODO \li{} for referencing file?
\end{problem}

\section*{The Trapezoidal Rule}
Now that we understand basic communication in MPI, we will proceed by parallelizing our first algorithm--numerical integration using the ``trapezoidal rule.'' Early on in most calculus classes, students learn to estimate integrals using the trapezoidal rule. A range to be integrated is divided into many vertical slivers, and each sliver is approximated with a trapezoid. The area of each trapezoid is computed, and then all their areas are added together.

% LaTeX to display the trapezoidal rule:
\begin{eqnarray*}%{rcl}
\textrm{Area}
&\approx&
\sum_{i=0}^{n-1}\frac{[f(a+i \Delta x)+f(a + (i+1) \Delta x)]}{2}\cdot\Delta x \\
&=&
\left[-\frac{f(a)+f(b)}{2}+\sum_{i=0}^{n}f(a+i\Delta x)\right]\cdot\Delta x
\end{eqnarray*}
where $\Delta x=(b-a)/n$.

% Trapezoid rule picture:
\begin{figure}[h]
\centering
\includegraphics[width=.5\textwidth]{TrapezoidRule.png}
\caption{The trapezoid rule in action. TODO get a copyright-kosher version.}
\label{fig:trapezoidal_rule}
\end{figure}
% I took this template for icluding images from the data structures lab

In Python, a simple serial formulation of the trapezoidal rule would be as follows:

\lstinputlisting[style=FromFile]{trapSerial.py}

A moment of thought should convince the reader that this algorithm reflects the formula given above.

\section*{Parallelizing the Trapezoidal Rule}
The first and most important step in parallelizing an algorithm is determining which computations are independent. With the trapezoidal rule, it's easy to see that the area of each trapezoid can be calculated independently, so dividing the data at the trapezoid level seems natural.

Currently, the algorithm divides up the interval into $n$ subintervals. To parallelize this process, we will distribute these $n$ subintervals to the available processes:

\lstinputlisting[style=FromFile]{trapParallel_1.py}

In this parallel approach, the original interval is split such that each process gets an equal-sized subinterval to integrate. After integrating, each process sends its result to the root node, which sums up the results and displays them. Although this is fairly straightforward, there are two important things to note:

First, notice how the trapezoids are divided among the processes: The processors each individually calculate the specifics of which subinterval they will be integrating. We could have written the algorithm such that process 0 divides up the work for the other processors and tells them each what their ranges are. However, this would introduce an unnecessary bottleneck: all of the other processes would be idling while waiting for their assignment to arrive from the root process. By having each process calculate its own range, we gain a large speedup.

Second, notice how the results are summed. We know how many results we should be receiving, so the root process simply accepts the messages in the order that they arrive. This is achieved using the tag \li{MPI.ANY_SOURCE} in the \li{COMM.Recv} method. In following labs we will learn about even more effective ways to gather the results of many different processes' computations.
% todo link to lab where we learn gather (next lab). Talk about the speed up we gained here? but in this case there is no speedup...

% MPI has two mechanisms specifically designed to partition the message space: tags and communicators. The tag parameter is there in the case that two messages with the same size and datatype are sent to the same process. In that case, the program would not necessarily be able to tell apart the data. So the programmer can attach different tags that he or she defines to the sent data to keep them straight.
% TODO find somewhere else for this paragraph to fit in maybe? Maybe as the answer to that problem from the intro that asks what tags do?

At this point, you should test the code for yourself. Save the code in a file named \texttt{trapParallel\_1.py} and try running it from the command line using the following input:
\begin{lstlisting}[style=ShellInput]
$ mpirun -n 4 python trapParallel_1.py 0.0 1.0 10000
\end{lstlisting}
The output should appear like this:
\begin{lstlisting}[style=ShellOutput]
With 10000 trapezoids, our estimate of the integral of x^2 from 0.0 to 1.0 is:
    0.333333335
\end{lstlisting}
We have successfully parallelized our first algorithm!

\section*{Load Balancing}
Although we have parallelized the trapezoidal rule, our algorithm is still rather naive. Notice that if the number of processes does not evenly divide the number of trapezoids, the code will break down. Try running the trapezoid program with n = 10007 trapezoids:
\begin{lstlisting}[style=ShellInput]
$ mpirun -n 4 python trapParallel_1.py 0.0 1.0 10007
\end{lstlisting}
This will produce the following:
\begin{lstlisting}[style=ShellOutput]
With 10007 trapezoids, our estimate of the integral of x^2 from 0.0 to 1.0 is:
    0.333233404949
\end{lstlisting}

We know that the estimate of the integral should improve as $n$ grows larger, but this estimate is much worse. This happened because \li{local_n}, the number of trapezoids that each processor calculates, must be an integer. To solve this problem, we could require that the user always choose a value of $n$ that is divisible by the number of processors. However, good parallel code should let the user worry as little as possible about the parallelization and should function exactly as the serial version does. Thus, we should improve the code to let it handle the case where $n$ is not divisible by the number of processes.

One way to solve this problem would be to designate one process to handle the leftover trapezoids that; i.e. give each process \li{int(n/SIZE)} trapezoids and assign the remaining \li{n \% SIZE} trapezoids to the last process as well. Thus, the \li{local_n} of each process would be an integer. However, this method can be incredibly inefficient: What if we ran the program with $100$ processes and $n=1099$ trapezoids? Then each process would have \li{int(1099/100) = 10} trapezoids to calculate... except for the last process, which would have \li{10 + 1099 \% 100 = 109} trapezoids!

\emph{A parallel program can only be as fast as its slowest process.} We call this principle \emph{load balancing}. In this case, one process has to do over ten times as much work as the other processes! The other processes will end up waiting idle until the last one finishes. Ignoring communication costs and other overhead, this program could be nearly 10 times faster if we divided up the work more evenly. The important concept to remember is that any time a process is idling, we are losing efficiency.

In the case of the trapezoidal rule, load-balancing the code means two things. First, between any two processes, the number of trapezoids given to each must differ by at most $1$. Second, each process should estimate the area of a contiguous group of trapezoids. Although estimating an integral is not a very time-consuming operation, by estimating over contiguous groups of trapezoids we are minimizing the amount of duplicate work the processes have to do, which is good practice.

\begin{problem}
Implement the \emph{load-balancing} fix to the code \texttt{trapParallel\_1.py}. The program should be able to take in any number of trapezoids $n$ for any number of processes and the trapezoids should be divided among the processes evenly, differing by at most one between any two processes. Each process should independently calculate which section of trapezoids it should calculate.

For example, if the program is run with 5 processes and 12 trapezoids, processes 0 should calculate the first 3 trapezoids, process 1 should calculate the next 3 trapezoids, process 2 should calculate the next 2 trapezoids, process 3 should calculate the next 2 trapezoids, and process 4 should calculate the last 2 trapezoids.
\end{problem}


\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath,mathpazo,siunitx,xparse,tikz,enumitem,fancyhdr,pgfplots}
\usepackage{geometry}[1in]
\usepackage[document]{ragged2e}
\usepackage{tabularx}
\usepackage{tabulary}
\usepackage{pgfplotstable}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{xtab}
\usepackage{paracol}
\usepackage{array}
\usepackage{multicol}
\usepackage{paracol}
\usepackage{float}
\usepackage{mathtools}
\usetikzlibrary{patterns}

\newcommand{\me}{\mathrm{e}}

\makeatletter
\newcommand{\pgfplotsdrawaxis}{\pgfplots@draw@axis}
\makeatother
%%Needed to properly display graphs
\pgfplotsset{only axis on top/.style={axis on top=false, after end axis/.code={
             \pgfplotsset{axis line style=opaque, ticklabel style=opaque, tick style=opaque,
                          grid=none}\pgfplotsdrawaxis}},compat=1.9,width=5.5in}
%\pgfplotsset{width=10cm,compat=1.9}

\pagestyle{fancy}
\fancyhf{}
\lhead{Steven Glasford}
\chead{Homework 4}
\rhead{Page \thepage}

\title{Homework 4}
\author{Steven Glasford}
\date{\parbox{\linewidth}{\centering%
    %%Adds the last compiled date
    \today\endgraf\medskip
    Math-451-M001}}

%%Creates a new symbol for plus and minus together
\newcommand{\rpm}{\sbox0{$1$}\sbox2{$\scriptstyle\pm$}
  \raise\dimexpr(\ht0-\ht2)/2\relax\box2 }

%%Creates a nice format for displaying the steps taken
\newlist{steps}{enumerate}{1}
\setlist[steps, 1]{label = Step \arabic*:}

\ExplSyntaxOn
%%new command to round numbers
\newcommand*{\prlen}[1]{%
   % round to 1 digit:
    \pgfmathparse{round(10)/10.0}%
    %\pgfkeys{/pgf/number format/precision=1}
    %\pgfmathresult
    \pgfmathprintnumber[fixed, precision=2]{\pgfmathresult}
}
\ExplSyntaxOff

\newcommand{\drawge}{-- (rel axis cs:1,0) -- (rel axis cs:1,1) -- (rel axis cs:0,1) \closedcycle}
\newcommand{\drawle}{-- (rel axis cs:1,1) -- (rel axis cs:1,0) -- (rel axis cs:0,0) \closedcycle}

\begin{document}
%% adds the title to the document
\maketitle
%% adds the table of contents to the document
\tableofcontents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Question 10 from chapter 5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\chapter{RLC Circuit Problem}

\section{Problem Statement}

%Consider the electrical circuit diagrammed in Figure 5.6. The circuit consists of a capacitor, a resistor, and an inductor in a simple closed loop. The effect of each component of the circuit of is measured in terms of the relationship between current and voltage on that branch of the loop. An idealized physical model gives the relations

%\begin{align}
%    C\dfrac{dv_C}{dt} &= i_C \label{capacitor} \\
%    v_R &= f(i_R) \label{resisotr} \\
%    L\dfrac{di_L}{dt} &= v_L \label{inductor}
%\end{align}

%where equation \ref{capacitor} refers to the capacitor, \ref{resisotr} refers to the resistor and \ref{inductor} refers to the inductor.
\emph{This problem is number 10 from Chapter 5 of the book.}

Reconsider the RLC circuit of Example 5.3, but now suppose that the capacitance $C=1/5$.
\begin{enumerate}[label=(\alph*),ref=(\alph*)]
    \item\label{RLC:A} Sketch the vector field for this model.
    \item\label{RLC:B} Use the eigenvalue method to test the stability of the equilibrium at the origin.
    \item\label{RLC:C} Determine the linear system that approximates the behavior of the original dynamical system in the neighborhood of the origin. Write the general solution to this linear system, and sketch the linear phase portrait.
    \item\label{RLC:D} Sketch the complete phase portrait for this model, using the results of parts \ref{RLC:A} and \ref{RLC:C}. How does the behavior of the RLC circuit change when the capacitance $C$ is lowered?
\end{enumerate}

This problem will heavily refer to Example 5.3 of the book.

\section{Vector Field}

In Example 5.3 several equations are given with variable $C$, so replacing $C$ with 1/5 in equations 5.20

\begin{align}
    x'_1 &= -x^3_1-4x_1-x_2 \label{RLC:x1} \\
    x'_2 &= 5x_1 \label{RLC:x2}
\end{align}

and for equation 5.21 we get

\begin{align}
    f_1(x_1,x_2) &= -x_1^3-4x_1-x_2 \label{RLC:f1}\\
    f_2(x_1,x_2) &= 5x_1 \label{RLC:f2}
\end{align}

\begin{figure}[h]
    \centering
    \includegraphics[width=5in]{vector.png}
    \caption{The vector field using equations \ref{RLC:x1} and \ref{RLC:x2}}
    \label{fig:vector}
\end{figure}

\section{Testing Stability using the Eigenvalue method}

In order to do the eigenvalue method we must first find the Jacobian matrix and then find the values from there, luckily however the book has already done the calculation to determine the eigenvalues which are: $$\lambda = -2 \pm \sqrt{4-\dfrac{1}{C}}$$

so plugging in $1/5$ for $C$ we get

\begin{align}
    -\lambda &= -2 \pm i \label{RLC:eigenvalues}
\end{align}

The negative component of $\lambda$ implies that the function is stable and the imaginary component implies that it is not asymptotically stable instead it has spiral stability.

\section{General Solution}
Next we need to find a linear system to approximate the solution the following function also comes from Example 5.3 in the book:

\begin{center}
    \begin{pmatrix}
        $\lambda + 4$ & $1$ \\
        $-5$ & $\lambda$
    \end{pmatrix}
    \begin{pmatrix}
        x_1\\
        x_2
    \end{pmatrix}
    $=$
    \begin{pmatrix}
        0\\
        0
    \end{pmatrix}
\end{center}

replacing lambda and using maple to find solve $\vec{X}$ we get eigenvectors of
\begin{center}
    $k = $ \begin{bmatrix}
    -2\pm i\\5
    \end{bmatrix}
\end{center}

next we plug this information into an approximate general solution for the linear system similar to the solution of equation 5.19 in example 5.3.

\begin{center}

    $\begin{pmatrix}
        x_1\\x_2
    \end{pmatrix}
    = c_1\begin{pmatrix}
        -2+i\\5
    \end{pmatrix}e^{(-2+i)t}+c_2 \begin{pmatrix}
        -2-i\\5
    \end{pmatrix}e^{(-2-i)t}$

\end{center}

which can be reduced using Euler's identity to an equation without imaginary numbers as:

$$\vec{X} = c_1e^{-2t} \left(\begin{bmatrix}
-2\\5
\end{bmatrix}cos(t)-\begin{bmatrix}
-2\\5
\end{bmatrix}sin(t)\right)+c_2e^{-2t} \left(\begin{bmatrix}
-2\\5
\end{bmatrix}sin(t)+\begin{bmatrix}
-2\\5
\end{bmatrix}cos(t)\right)$$

\newpage

\section{Complete Phase Portrait}
\begin{figure}[h]
    \centering
    \includegraphics[width=5in]{complete.png}
    \caption{The complete phase portrait of the RLC problem}
    \label{fig:complete}
\end{figure}

\newpage

\section{Further remarks}
The behavior of the RLC circuit changes when the capacitance is lowered the swirls as seen in figure \ref{fig:complete} get tighter. Figure \ref{fig:complete1} is when the capacitance equal to 1/7, and notice how the swirls are tighter than in \ref{fig:complete}.

\begin{figure}[h]
    \centering
    \includegraphics[width=5in]{complete1.png}
    \caption{The complete phase portrait with $C=1/7$}
    \label{fig:complete1}
\end{figure}

\chapter{Space Docking}

\secion{Problem Statement}

\begin{flushleft}
Reconsider the space docking problem of Example 5.2, but now approximate the discrete time dynamical system
\end{flushleft}
$$\Delta x_{1} = -kwx_{1} - kcx_{2}$$
$$\Delta x_{1} - x_{2}$$
\begin{flushleft}
by its continuous time analogue
\end{flushleft}
$$\dfrac{dx_{1}}{dt} = -kwx_{1} - kcx_{2}$$
$$\dfrac{dx_{2}}{dt} = x_{1} - x_{2}$$
\begin{enumerate}[label=(\alph*),ref=(\alph*)]
\item Show that the continuous time model has a stable equilibrium at (0,0). Assume $w = 10, c = 5, k = 0.02$
\item Solve the continuous model using the method of eigenvalues and eigenvectors
\item Draw the complete phase portrait for this model
\item Comment on any differences between the behavior of the discrete and continuous model
\end{enumerate}

\section{Solving the Model}
\subsection{Variables \& Assumptions}
\begin{flushleft}
Given the values of $w, c,$ and $k$ we get the following continous model
\end{flushleft}
$$\dfrac{dx_{1}}{dt} = -0.2x_{1} - 0.1x_{2}$$
$$\dfrac{dx_{2}}{dt} = x_{1} - x_{2}$$
\begin{flushleft}
Which we will use as the basis of our problem
\end{flushleft}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Solving the Model}
\subsection{Variables \& Assumptions}
\begin{flushleft}
Given the values of $w, c,$ and $k$ we get the following continuous model
\end{flushleft}
$$\dfrac{dx_{1}}{dt} = -0.2x_{1} - 0.1x_{2}$$
$$\dfrac{dx_{2}}{dt} = x_{1} - x_{2}$$
\begin{flushleft}
Which we will use as the basis of our problem
\end{flushleft}
\subsection{Equilibrium}
\begin{flushleft}
We want to show that $(0,0)$ is a point of stability and equilibrium for our system. This is done by finding where our two equations equal to zero. then, we plot them and where they intersect is a point of equilibrium.
\end{flushleft}
$$f1: x_{2} = \dfrac{-0.2x_{1}}{0.1}$$

$$f2: x_{2} = x_{1}$$
\begin{flushleft}
When we plot these two graphs $f1$ and $f2$, as seen down below, we can see that they intersect at $(0,0)$, proving that there is equilibrium at this point.
\end{flushleft}

\begin{center}
\begin{tikzpicture}
\begin{axis}
[
    axis lines = left,
    xlabel = $x_{1}$,
    ylabel = $x_{2}$,
    legend pos = outer north east,
]
%Graph 1
\addplot
 [
    domain=-2:2,
    samples=100,
    color=red,
    ]
{(-0.2*x)/0.1};
\addlegendentry{$f1$}
%Graph 2
\addplot
 [
    domain=-2:2,
    samples=100,
    color=green,
    ]
{x};
\addlegendentry{$f2$}
\end{axis}
\end{tikzpicture}
\end{center}

\subsection{Eigenvalue and Eigenvector Method}
\begin{flushleft}
To solve our system using the method of eigenvalues and eigenvectors, we need it in a matrix that has the following form
\end{flushleft}
\[ \left( \begin{array}{ccc}
\dfrac{\partial f1}{x_{1}} & \dfrac{\partial f1}{x_{2}}\\
\dfrac{\partial f2}{x_{1}} & \dfrac{\partial f2}{x_{2}} \end{array} \right)\]
\begin{flushleft}
When we go this and evaluate it at the point $(0,0)$ we obtain the following
\end{flushleft}
\[ \left( \begin{array}{ccc}
-0.2 & -0.1 \\
1 & 1 \end{array} \right)\]
\begin{flushleft}
Finding the eigenvalue we get a characteristic equation of
\end{flushleft}
$$ \lambda^{2} - 0.8 \lambda - 0.1$$
\begin{flushleft}
And solving for the eigenvalue we get eigenvalues of
\end{flushleft}
$$\lambda_{1} = \dfrac{4+\sqrt{26}}{10}, \lambda_{2} = \dfrac{4-\sqrt{26}}{10}$$
\begin{flushleft}
Their perspective eigenvectors would be the following
\end{flushleft}
\[ \left( \begin{array}{c}
-0.901 \\
1 \end{array} \right)\]

 \[ \left( \begin{array}{c}
\dfrac{-6+\sqrt{26}}{10} \\
1 \end{array} \right)\]

\begin{flushleft}
With this, we can see that our general solution using the Eigenvalue and Eigenvector method is
\end{flushleft}
$$x_{1}(t) = c_{1} * -0.901e^{ \dfrac{4+\sqrt{26}}{10}} +c_{2}*\dfrac{-6+\sqrt{26}}{10}e^{ \dfrac{4-\sqrt{26}}{10}}$$

$$ x_{2}(t) = c_{1}e^{ \dfrac{4+\sqrt{26}}{10}} +c_{2}e^{ \dfrac{4-\sqrt{26}}{10}}$$
\begin{flushleft}
This is the general solution to our system using the eigenvalue and eigenvector method
\end{flushleft}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Phase Portrait}
\begin{flushleft}
Now that we have the general solution to our system, we can choose a few values for $c_{1}$ and $c_{2}$ to plot the parametric graph. We superimpose a graph of the linear vector field in order to indicate the orientation of the solution curves. The arrows indicate the direction of the flow. This can be seen down below in figure 1.1. We can see that the vector field sinks into our point of equilibrium at $(0,0)$.
\end{flushleft}
\begin{figure}[h]
    \centering
    \includegraphics[width=3in]{vectorgraph.png}
    \caption{Phase Portrait}
    \label{fig:vector}
\end{figure}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Discrete vs Continuous Models}
\begin{flushleft}
In a discrete time model, the values of variables are remain unchanged throughout each non-zero region of time while in the continuous model that we did in the problem, the variables have a  particular value for a region between two points. Hence, why when for the discrete time $x(t)$ approaches $(0,0)$ for any initial condition.
\end{flushleft}

\end{document}