\documentclass{aiaa-tc}

\usepackage{color}
\usepackage{amsmath}
%\usepackage{overcite}
\usepackage{graphicx}
\usepackage{subfig}
\usepackage{authblk}
\usepackage{amsfonts}

\input basic.ltx
\def\directory{EPSF/}

%------------------------------------------------------------------------------
% MAS Additions
\newcommand{\mas}[1]{\textcolor{magenta}{#1}}
\newcommand{\qw}[1]{\textcolor{blue}{#1}}
%useful for showing deleted text
\renewcommand{\kill}[1]{\textcolor{red}{\sout{#1}}}

\usepackage[normalem]{ulem}  % mas addition
\newcommand{\uvec}[1]{\bar{#1}}
\newcommand{\tens}[1]{\underline{\underline{#1}}}
\renewcommand{\vec}[1]{\underline{#1}}
\renewcommand{\skew}[1]{\widetilde{#1}}
%------------------------------------------------------------------------------

\title{BeamDyn: A High-Fidelity Wind Turbine Blade Solver in the FAST
Modular Framework}

\author[1]{Qi Wang\thanks{Research Engineer, National Wind Technology Center, AIAA Member. Email: Qi.Wang2@nrel.gov}}
\author[2]{Nick Johnson\thanks{Graduate Research Assistant, Department of
Mechanical Engineering.}}
 \author[1]{Michael A. Sprague\thanks{Senior Research Scientist,
Computational Science Center.}}
 \author[1]{Jason Jonkman\thanks{Senior Engineer, National Wind Technology Center, AIAA Professional Member.}}
 \affil[1]{National Renewable Energy Laboratory, Golden, CO 80401}
 \affil[2]{Colorado School of Mines, Golden, CO 80401}

 \renewcommand\Authands{, and }

\begin{document}

\maketitle

\begin{abstract}
{BeamDyn, a Legendre-spectral-finite-element implementation of geometrically
exact beam theory (GEBT), was developed to meet the design challenges
associated with highly flexible composite wind turbine blades. In this
paper, the governing equations of GEBT are reformulated into a nonlinear
state-space form to support its coupling within the
modular framework of the FAST wind turbine
computer-aided engineering (CAE) tool. Different time integration
schemes (implicit and explicit) were implemented and examined for wind
turbine analysis.  Numerical examples are presented to demonstrate the capability of this new beam solver. An example analysis of a realistic wind turbine blade, the CX-100, is also presented as validation.}
\end{abstract}

\section{Introduction} In recent years, wind power installations in the United States have exceeded 60
gigawatts in generation capacity, and have become an increasingly important part of the overall energy
portfolio. Simultaneously, the size of wind turbines has also increased in
the quest for economies of scale.   To ensure the performance and
reliability of wind turbines, it is crucial to use computer-aided engineering (CAE) tools that are capable of analyzing wind
turbine blades accurately and efficiently. Although modern
computers enable three-dimensional (3D) analysis
of a fully resolved blade, such analyses are too
expensive for iterative and probabilistic design. However, composite wind
turbine blades are well represented as nonlinear beam models, which can
capture the deformation response under realistic
operating conditions with high fidelity, and in a small fraction of the time required by a
fully resolved 3D simulation.

Beam models are widely used to analyze structures in which one dimension is much larger than the other two.  Many engineering
structures such as  bridges, joists, and helicopter
rotor blades may be modeled as beams.  Similarly, beam models are well suited for analyzing wind turbine blades, towers, and shafts.  Most wind turbine
blades are constructed of composite materials, which are more complicated than isotropic beams to analyze because of elastic coupling
effects, high flexibility, and initial twist/curvatures.  The geometrically exact beam theory (GEBT), first proposed by
Reissner\cite{Ressiner1973}, is a beam-deformation model useful in efficient analysis of highly flexible composite structures.
For instance, GEBT has demonstrated efficacy in helicopter rotor analysis \cite{Hodges:2007}.
Simo\cite{Simo1985} and Simo and Vu-Quoc\cite{Simo1986} extended Reissner's
work to include 3D dynamic problems. Jeleni\'c and
Crisfield\cite{Crisfield1999} derived a finite-element (FE) method that
interpolates the rotation field, thereby preserving the geometric exactness
of this theory. Notably, Ibrahimbegovi\'c and his colleagues
implemented this theory for static\cite{Ibrahim1995} and
dynamic\cite{Ibrahim1998} analysis. Readers are referred to
Hodges\cite{HodgesBeamBook}, in which comprehensive derivations and discussions
on nonlinear composite-beam theories can be found. Recently, a mixed
 FE formulation of GEBT along with the numerical implementation was presented by
Yu and Blair\cite{YuGEBT}.

FAST is a CAE tool developed by the National Renewable Energy Laboratory
(NREL) for analyzing both land-based and
offshore wind turbines under realistic operating conditions.  The current
beam model in FAST is not capable of predictive analysis of highly flexible,
composite wind turbine blades.
Recently, FAST has been reformulated under a
new modularized framework that provides a rigorous means by which various
mathematical systems are implemented in distinct modules. These modules are interconnected
to solve for the globally coupled dynamic responses of wind turbines and wind
plants \cite{Jonkman:2013,website:FASTModularizationFramework}.

In this paper, a 3D displacement-based
implementation of geometrically exact beam theory using Legendre
spectral finite elements is presented. The theory is reformulated in a
nonlinear state-space form for the purpose of integrating with the FAST
framework, thereby introducing an optional high-fidelity beam model as an
alternative to the current beam model. Several first-order form time integrators, including the explicit fourth-order Runge-Kutta (RK4) and implicit second-order Adams-Moulton (AM2), are examined. This work builds on previous efforts
that demonstrated the implementation of GEBT and spatial discretization using Legendre spectral finite elements
(LSFEs)\cite{Wang:GEBT2013,Wang:SFE2013,Wang:GEBT2014,Sprague:FAST2014} in analyzing composite wind turbine blades. The paper is organized as
follows.  First, the theoretical foundation of the geometrically exact beam
theory along with the reformulation of the governing equations into a
state-space form is introduced. Coupling to the FAST framework is then
discussed. Finally, numerical examples are
provided to verify and validate the accuracy and efficiency of the present model for
composite wind turbine blades.

~

\section{Geometrically Exact Beam Theory}

This section briefly reviews the geometrically exact beam theory. Further details on the content of this section can be found in many other papers and textbooks \cite{HodgesBeamBook,Bauchau:2010,YuGEBT}.
Figure~\ref{Kinematics} shows a beam in its initial undeformed
and deformed states. A reference frame $\mathbf{b}_i$ is introduced along the
beam axis for the undeformed state and a frame $\mathbf{B}_i$ is introduced
along each point of the deformed beam axis. The curvilinear coordinate $x_1$ defines the intrinsic parameterization of the reference line.
\begin{figure}
\centering
\includegraphics[width=5.0in]{\directory Kinematics.eps}
\caption{A beam deformation schematic.} \label{Kinematics}
\end{figure}
In this paper, matrix notation is used to denote vectorial or vectorial-like quantities. For example, an underline denotes a vector $\underline{u}$, a bar denotes unit vector $\bar{n}$, and a double underline denotes a tensor $\underline{\underline{\Delta}}$. Note that sometimes the underlines only denote the dimension of the corresponding matrix. The governing equations of motion for geometrically exact beam theory can be written as \cite{Bauchau:2010}
\begin{align}
	\label{GovernGEBT-1}
	\dot{\underline{h}} - \underline{F}^\prime &= \underline{f} \\
	\label{GovernGEBT-2}
	\dot{\underline{g}} + \dot{\tilde{u}} \underline{h} - \underline{M}^\prime + (\tilde{x}_0^\prime + \tilde{u}^\prime)^T \underline{F} &= \underline{m}
\end{align}
where $\vec{h}$ and $\vec{g}$ are the linear and angular momenta resolved in the inertial coordinate system, respectively; $\vec{F}$ and $\vec{M}$ are the beam's sectional force and moment resultants, respectively; $\vec{u}$ is the one-dimensional (1D) displacement of a point on the reference line; $\vec{x}_0$ is the position vector of a point along the beam's reference line;  and $\vec{f}$ and $\vec{m}$ are the distributed force and moment applied to the beam structure.  The notation $(\bullet)^\prime$ indicates a derivative with respect to beam axis $x_1$ and $\dot{(\bullet)}$ indicates a derivative with respect to time. The tilde operator $(\skew{\bullet})$ defines a skew-symmetric tensor corresponding to the given vector. In the literature, it is also termed as ``cross-product matrix". For example,
\[
	\skew{n} =
	     		\begin{bmatrix}
			0 & -n_3 & n_2 \\
			n_3 & 0 & -n_1 \\
			-n_2 & n_1 & 0\\
			\end{bmatrix}
\]
The constitutive equations relate the velocities to the momenta and the 1D strain measures to the sectional resultants as
\begin{align}
	\label{ConstitutiveMass}
	\begin{Bmatrix}
	\underline{h} \\
	\underline{g}
	\end{Bmatrix}
	= \underline{\underline{\mathcal{M}}} \begin{Bmatrix}
	\dot{\underline{u}} \\
	\underline{\omega}
	\end{Bmatrix} \\
	\label{ConstitutiveStiff}
	\begin{Bmatrix}
	\underline{F} \\
	\underline{M}
	\end{Bmatrix}
	= \underline{\underline{\mathcal{C}}} \begin{Bmatrix}
	\underline{\epsilon} \\
	\underline{\kappa}
	\end{Bmatrix}
\end{align}
where $\underline{\underline{\mathcal{M}}}$ and
$\underline{\underline{\mathcal{C}}}$ are the $6 \times 6$ sectional mass
and stiffness matrices, respectively (note that they are not really tensors);
$\underline{\epsilon}$ and $\underline{\kappa}$ are the 1D strains and
curvatures, respectively; and, $\underline{\omega}$ is the angular velocity
vector that is defined by the rotation tensor $\underline{\underline{R}}$ as
$\underline{\omega} =
axial(\dot{\underline{\underline{R}}}~\underline{\underline{R}}^T)$. The axial vector $\vec{a}$ associated with a second-order tensor $\tens{A}$ is denoted $\vec{a}=axial(\tens{A})$ and its components are defined as
\begin{equation}
    \label{axial}
    \vec{a} = axial(\tens{A})=\begin{Bmatrix}
    a_1 \\
    a_2 \\
    a_3
    \end{Bmatrix}
    =\frac{1}{2}
    \begin{Bmatrix}
    A_{32}-A_{23} \\
    A_{13}-A_{31} \\
    A_{21}-A_{12}
    \end{Bmatrix}
\end{equation}
The 1D strain measures are defined as
\begin{equation}
    \label{1DStrain}
    \begin{Bmatrix}
        \vec{\epsilon} \\
        \vec{\kappa}
    \end{Bmatrix}
    =
    \begin{Bmatrix}
        \vec{x}^\prime_0 + \vec{u}^\prime - (\tens{R} ~\tens{R}_0) \bar{\imath}_1 \\
        \vec{k}
    \end{Bmatrix}
\end{equation}
where $\vec{k} = axial [(\tens{R R_0})^\prime (\tens{R R_0})^T]$ is the sectional
curvature vector resolved in the inertial basis and $\bar{\imath}_1$ is the unit
vector along $x_1$ direction in the inertial basis. Note that these
three sets of equations, including equations of motion
Eq.~\eqref{GovernGEBT-1} and \eqref{GovernGEBT-2}, constitutive equations
Eq.~\eqref{ConstitutiveMass} and \eqref{ConstitutiveStiff}, and kinematical
equations Eq.~\eqref{1DStrain}, provide a full mathematical description of elasticity problems.

For a displacement-based finite-element implementation, there are six
degrees of freedom at each node: three displacement components and three
rotation components. Here, $\vec{q}$ denotes the elemental
displacement array as $\underline{q}^T=\left[
\underline{u}^T~~\underline{p}^T\right]$ where $\vec{u}$ is the
displacement and $\vec{p}$ is the rotation-parameter vector. The
acceleration array can thus be defined as $\underline{a}^T=\left[
\ddot{\underline{u}}^T~~ \dot{\underline{\omega}}^T \right]$. For nonlinear
finite-element analysis, the discretized forms of
displacement, velocity, and acceleration are written as
\begin{align}
	\label{DiscretizedDisp}
	\underline{q} (x_1) &= \underline{\underline{N}} ~\hat{\underline{q}}~~~~~~~~\underline{q}^T = \left[ \underline{u}^T~~\underline{p}^T \right] \\
	\label{DiscretizedVel}
	\underline{v}(x_1) &= \underline{\underline{N}}~\hat{\underline{v}}~~~~~~~~\underline{v}^T = \left[\underline{\dot{u}}^T~~\underline{\omega}^T \right] \\
	\label{DiscretizedAcc}
	\underline{a}(x_1) &= \underline{\underline{N}}~ \hat{\underline{a}}~~~~~~~~\underline{a}^T = \left[ \ddot{\underline{u}}^T~~\dot{\underline{\omega}}^T \right]
\end{align}
where $\tens{N}$ is the shape function matrix and $(\hat{\cdot})$ denotes a
column matrix of nodal values.

\section{State-Space Formulation}
NREL has put considerable effort into improving the modularity of FAST. The modules in the new framework can be coupled in one of two ways in the time domain: loose and tight. In the loose coupling scheme, data are exchanged between the modules at each coupling step, but each module tracks its own states and integrates its own equations with its own solver. In a tightly coupled time-integration scheme, each module sets up its own equations, but the states are tracked and integrated by a solver common to all of the modules. To enable the most flexibility, it is useful to create modules (such as BeamDyn) so that they can support both loose and tight coupling. More details on the FAST modularization framework and an initial assessment of the numerical stability, numerical accuracy, and computational performance of various coupling schemes can be found in \cite{Jonkman:2013,Sprague:2013,Sprague:FAST2014}.

To accommodate the tight coupling scheme in the FAST modular framework, the governing equations
\eqref{GovernGEBT-1} and \eqref{GovernGEBT-2} needed to be reformulated
into a state-space form. First, these equations are recast in compact form
as
\begin{equation}
    \label{CompactGovernGEBT}
    \underline{\mathcal{F}}^I - (\underline{\mathcal{F}}^{C})^\prime + \underline{\mathcal{F}}^D = \underline{\mathcal{F}}^{ext}
\end{equation}
where $\underline{\mathcal{F}}^I, \underline{\mathcal{F}}^C$ and $\underline{\mathcal{F}}^D$, and $\underline{\mathcal{F}}^{ext}$ are the inertial force term, two elastic force terms, and externally applied force term, respectively; their definitions are
\begin{align}
    \label{InertialForce}
    \underline{\mathcal{F}}^I &= \begin{Bmatrix}
    \dot{\underline{h}} \\
    \dot{\underline{g}}
    \end{Bmatrix}
    + \begin{bmatrix}
    \underline{\underline{0}} & \underline{\underline{0}} \\
    \dot{\tilde{u}}  &  \underline{\underline{0}}
    \end{bmatrix}
    \begin{Bmatrix}
    \vec{h} \\
    \vec{g}
    \end{Bmatrix} \\
    \label{ElasticForceFc}
     \underline{\mathcal{F}}^C &= \begin{Bmatrix}
    \underline{F} \\
    \underline{M}
    \end{Bmatrix} \\
    \label{ElasticForceFd}
    \underline{\mathcal{F}}^D &= \begin{Bmatrix}
    \underline{0} \\
    (\tilde{x}^\prime_0 + \tilde{u}^\prime)^T \underline{F}
    \end{Bmatrix} \\
    \label{AppliedForce}
    \underline{\mathcal{F}}^{ext} &= \begin{Bmatrix}
    \underline{f} \\
    \underline{m}
    \end{Bmatrix}
\end{align}
Along with the constitutive equations \eqref{ConstitutiveMass} and \eqref{ConstitutiveStiff}, the inertial force $\underline{\mathcal{F}}^I$ can be written explicitly as
\begin{align}
    \underline{\mathcal{F}}^I &= \begin{Bmatrix}
    m \ddot{\underline{u}} + ( \dot{\tilde{\omega}} + \tilde{\omega} \tilde{\omega} ) m \underline{\eta} \\
    m \tilde{\eta} \ddot{\underline{u}} + \underline{\underline{\varrho}} \dot{\underline{\omega}} + \tilde{\omega}  \underline{\underline{\varrho}} \underline{\omega}
    \end{Bmatrix} \nonumber \\
    \label{InertialForce2}
    &= \begin{bmatrix}
    m \underline{\underline{I}} & m \tilde{\eta}^T \\
    m \tilde{\eta} & \underline{\underline{\varrho}}
    \end{bmatrix}
    \begin{Bmatrix}
    \ddot{\underline{u}} \\
    \dot{\underline{\omega}}
    \end{Bmatrix} +
    \begin{bmatrix}
    \underline{\underline{0}} & m \tilde{\omega} \tilde{\eta}^T \\
    \underline{\underline{0}} & \tilde{\omega}  \underline{\underline{\varrho}}
    \end{bmatrix}
    \begin{Bmatrix}
    \dot{\underline{u}} \\
    \underline{\omega}
    \end{Bmatrix} \\
    &  \equiv \tens{\mathfrak{M}} \underline{a} + \underline{\underline{\mathcal{G}}} \underline{v}  \nonumber
\end{align}
where $m$ is the mass density per unit span; $\underline{\eta}$ is the
center of mass location;  $\underline{\underline{\varrho}}$ is the moment of
inertia; and $\tens{I}$ is the identity matrix. The definitions of the acceleration vector $\underline{a}$ and velocity vector $\underline{v}$ can be found in Eq.~\eqref{DiscretizedAcc} and \eqref{DiscretizedVel}, respectively. Using the newly introduced matrices, the compact form of the equations of motion can be rewritten as
\begin{equation}
    \label{CompactForm2}
    \underline{\underline{\mathfrak{M}}}~ \underline{a} + f(\underline{q},\underline{v},t) = 0
\end{equation}
where
\begin{equation}
    \label{CompactForm3}
    f(\underline{q},\underline{v},t) = \underline{\mathcal{F}}^F - \underline{\mathcal{F}}^{C\prime} + \underline{\mathcal{F}}^D - \underline{\mathcal{F}}^{ext}
\end{equation}
\begin{align}
    \underline{\mathcal{F}}^F &= \underline{\underline{\mathcal{G}}} \underline{v}  \nonumber \\
    \label{CompactForm4}
    &= \begin{bmatrix}
    \underline{\underline{0}} & m \tilde{\omega} \tilde{\eta}^T \\
    \underline{\underline{0}} & \tilde{\omega}  \underline{\underline{\varrho}}
    \end{bmatrix}
    \begin{Bmatrix}
    \dot{\underline{u}} \\
    \underline{\omega}
    \end{Bmatrix}
\end{align}

A weighted residual formulation is used to enforce the dynamic equilibrium conditions in Eq.~\eqref{CompactForm2}
\begin{equation}
    \label{FEM-1}
    \int_0^l \tens{N}^T (\tens{\mathfrak{M}} \vec{a} + \vec{\mathcal{F}}^F - \vec{\mathcal{F}}^{C\prime} + \vec{\mathcal{F}}^D - \vec{\mathcal{F}}^{ext}) d x_1=0
\end{equation}
The above equation can be recast as
\begin{equation}
    \label{FEM-2}
    \tens{M} \hat{a} = F(\vec{q},\vec{v},t)
\end{equation}
where
\begin{align}
    \label{FEM-3}
    \tens{M} &= \int_0^l \tens{N}^T \tens{\mathfrak{M}}~ \tens{N}~dx_1 \\
    \label{FEM-4}
    \vec{F}(\vec{q},\vec{v},t) &= \int_0^l \tens{N}^T (-\vec{\mathcal{F}}^F + \vec{\mathcal{F}}^{C\prime} - \vec{\mathcal{F}}^D + \vec{\mathcal{F}}^{ext}) d x_1
\end{align}

To derive the state-space form of the governing equations, the state variable in first-order form $\vec{x}(t)$ is introduced as
\begin{equation}
    \label{StateSpaceX}
    \vec{x}(t) \equiv \begin{Bmatrix}
    \vec{q}(t) \\
    \vec{v}(t)
    \end{Bmatrix}
\end{equation}
Note that the second component of $\vec{x}(t)$ is not $\vec{\dot{q}}$ but $\vec{v}$ because the angular velocity $\vec{\omega}$ cannot be calculated as the time derivative of the rotation parameter $\vec{p}$. The angular velocity is related to the rotation parameter by the tangent matrix as $\omega = \tens{H}(p) \dot{\vec{p}}$ \cite{Bauchau:2010}. Substituting the discretized quantities in Eqs.~\eqref{DiscretizedDisp} to \eqref{DiscretizedAcc} into Eq.~\eqref{StateSpaceX} and using the relation
\begin{equation}
    \label{AccVel}
    \vec{a} = \vec{\dot{v}} = \begin{Bmatrix}
    \vec{\ddot{u}} \\
    \vec{\dot{\omega}}
    \end{Bmatrix}
\end{equation}
The state-space form can be obtained as
\begin{equation}
    \label{StateSpaceGov-1}
    \tens{A} ~\dot{\hat{\vec{x}}}(t) = \mathfrak{f}(\hat{\vec{x}}(t),t)
\end{equation}
with initial condition
\begin{equation}
    \label{StateSpaceGov-2}
    \hat{\vec{x}}(0) = \hat{\vec{x}}_0
\end{equation}
where
\begin{align}
    \label{StateSpaceGov-3}
    \tens{A} (\hat{\vec{x}}(t)) &= \begin{bmatrix}
    \tens{D} & \tens{0} \\
    \tens{0} & \tens{M}
    \end{bmatrix}  \\
    \label{StateSpaceGov-4}
    \tens{D} (\hat{\vec{x}}(t)) &= \int_0^l \tens{N}^T \begin{bmatrix}
    \tens{I}_3 & \tens{0} \\
    \tens{0} & \tens{H}
    \end{bmatrix}
    \tens{N}~dx_1 \\
    \label{StateSpaceGov-5}
    \mathfrak{f}(\hat{\vec{x}}(t),t) &=  \begin{Bmatrix}
    \int_0^l \tens{N}^T \vec{v}~dx_1 \\
    \vec{F}(\hat{\vec{x}}(t),t)
    \end{Bmatrix} \\
    \label{StateSpaceGov-7}
    \hat{\vec{x}}_0 &= \begin{Bmatrix}
    \hat{\vec{q}}_0 \\
    \hat{\vec{v}}_0
    \end{Bmatrix}
\end{align}
Note that the state-space form, in
Eq.~\eqref{StateSpaceGov-1} and \eqref{StateSpaceGov-2}, can be solved with
any number of ordinary differential equations (ODE) integrators
for first-order-in-time systems. A viscous damping term is also implemented to account for the structural damping. The damping force is defined as
\begin{equation}
   \label{Damping}
   \vec{f}_d = \tens{\mu}~ \tens{\mathcal{C}} \begin{Bmatrix}
   \dot{\epsilon} \\
   \dot{\kappa}
   \end{Bmatrix}
\end{equation}
where $ \tens{\mu}$ is a user-provided damping-coefficient diagonal matrix. The damping force can be recast in two separate parts, like $\vec{\mathcal{F}}^C$ and $\vec{\mathcal{F}}^D$ in the elastic force, as
\begin{align}
   \label{DampingForce-1}
   \vec{\mathcal{F}}^C_d &= \begin{Bmatrix}
   \vec{F}_d \\
   \vec{M}_d
   \end{Bmatrix} \\
   \label{DampingForce-2}
   \vec{\mathcal{F}}^D_d &= \begin{Bmatrix}
    \vec{0} \\
    (\tilde{x}^\prime_0 + \tilde{u}^\prime)^T \underline{F}_d
    \end{Bmatrix}
\end{align}
Readers are refered to Ref.[16] for more details on the damping force and its linearization.

\section{Implementation of BeamDyn}
The state-space form of GEBT was numerically implemented into a beam solver, called BeamDyn. BeamDyn has two sources of input:  the user-prescribed parameters and per time step data from the FAST driver code. The input parameters from the users are:
\begin{enumerate}
    \item Key points that define the natural geometry of the beam; these key points are interpolated by cubic splines
    \item Sectional constants for a 1D beam model
    \item Finite-element mesh information (order of element)
    \item Selection of static \cite{Wang:GEBT2014} or dynamic analysis
    \item Time integrators and associated parameters: RK4, AM2, or Generalized-$\alpha$ (for loosing coupling only).
\end{enumerate}

It is intended to couple separate instances of BeamDyn to FAST for each blade.  Structurally, the coupling will involve passing motions of the blade root for each blade from FAST's ElastoDyn structural module to BeamDyn; including position, velocity, and acceleration (both translation and rotation); and passing root loads for each blade from BeamDyn to ElastoDyn (both forces and moments).  Aerodynamically, the coupling will involve passing motions of the nodes distributed along each blade from BeamDyn to FAST's AeroDyn aerodynamics module; including position, velocity, and acceleration (both translation and rotation); and passing aerodynamic loads distributed along the blade from AeroDyn to BeamDyn.  FAST will also send BeamDyn the gravity vector and initial hub motions at initialization to enable an initialization of BeamDyn's states.  While not needed to enable the coupling of BeamDyn to FAST, BeamDyn will also calculate the internal loads along the beam, calculated by subtracting the inertial loads from the externally applied loads.

The implementation of GEBT with RK4 is straightforward; however, for the AM2 scheme, a linearization is required because of its implicit nature. By applying the trapezoidal rule, the state-space form in Eq.~\eqref{StateSpaceGov-1} can be recast as
\begin{equation}
    \label{AM2-Govn}
%    \tens{A}_{k+1} (\hat{\vec{x}}_{k+1}-\hat{\vec{x}}_{k})+\tens{A}_k \hat{\vec{x}}_{k+1} - \Delta t \mathfrak{f}(\hat{\vec{x}}_{k+1},t_{k+1}) = \tens{A}_k \hat{\vec{x}}_{k} + \Delta t \mathfrak{f}(\hat{\vec{x}}_{k},t_{k})
    \tens{A}_{k+1} (\hat{\vec{x}}_{k+1}-\hat{\vec{x}}_{k} - \frac{\Delta t}{2} \vec{\dot{\hat{x}}}_k) =  \frac{\Delta t}{2} \mathfrak{f}(\hat{\vec{x}}_{k+1},t_{k+1})
\end{equation}
where the subscript denotes the discretized time step in which the value is evaluated, and $\Delta t$ is the time step size. A linearization is needed to solve this nonlinear equation. The linearized equation is as follows
\begin{equation}
    \label{AM2-Linearized}
    \begin{bmatrix}
    \hat{\tens{K}}_1 & \hat{\tens{C}}_1 \\
    \hat{\tens{K}}_2 & \hat{\tens{C}}_2
    \end{bmatrix}
    \begin{Bmatrix}
    \Delta \hat{\vec{q}} \\
    \Delta \hat{\vec{v}}
    \end{Bmatrix}
    =
    \begin{Bmatrix}
    \hat{\vec{F}}_1 \\
    \hat{\vec{F}}_2
    \end{Bmatrix}
\end{equation}
The coefficient matrices are written as
\begin{align}
    \label{Linear-K1}
    \hat{\tens{K}}_1 &= \int_0^l \tens{N}^T\tens{K}_1~\tens{N}~dx_1 \\
    \label{Linear-C1}
    \hat{\tens{C}}_1 &= \int_0^l \tens{N}^T\tens{C}_1~\tens{N}~dx_1 \\
    \label{Linear-K2}
    \hat{\tens{K}}_2 &= \int_0^l  \tens{N}^T (\tens{A}_2 - \tens{A}_3 + \frac{\Delta t}{2} \tens{A}_1 + \frac{\Delta t}{2} \tens{A}_5 + \frac{\Delta t}{2} \mathcal{Q}) \tens{N}~dx_1 \nonumber \\
    &+ \int_0^l \left( \tens{N}^T \frac{\Delta t}{2} \tens{\mathcal{P}}~ \tens{N}^\prime + \tens{N}^{\prime T} \frac{\Delta t}{2} \tens{\mathcal{S}}~ \tens{N}^\prime + \tens{N}^T \frac{\Delta t}{2} \tens{\mathcal{O}}~ \tens{N}\right) ~dx_1 \\
    \label{Linear-C2}
    \hat{\tens{C}}_2 &= \int_0^l \tens{N}^T (\tens{\mathfrak{M}}+\frac{\Delta t}{2} \tens{A}_4)~\tens{N}~dx_1
\end{align}
where the newly introduced matrices are
\begin{align}
   \label{K1}
   \tens{K}_1 &=
   \begin{bmatrix}
   \tens{I}_3 & \tens{0} \\
   \tens{0} & \tens{B}(\vec{p},\vec{p}) + \tens{H} - \tens{B}(\vec{p},\vec{p}_k) -\frac{\Delta t}{2} \tens{B}(\vec{p},\vec{\dot{p}}_k)
   \end{bmatrix} \\
   \label{C1}
   \tens{C}_1 &=
   -\frac{\Delta t}{2} \begin{bmatrix}
   \tens{I}_3 & \tens{0} \\
   \tens{0} & \tens{I}_3
   \end{bmatrix} \\
   \label{A1}
   \tens{A}_1 &=
    \begin{bmatrix}
   \tens{0} & m \dot{\tilde{\omega}}_k \tilde{\eta}^T \\
   \tens{0} & m \ddot{\tilde{u}}_k \tilde{\eta}+\tens{\rho} \dot{\tilde{\omega}}_k-\widetilde{\tens{\rho}{\dot{\vec{\omega}}_k}}
   \end{bmatrix} \\
   \label{A2}
   \tens{A}_2 &=
    \begin{bmatrix}
   \tens{0} & m \tilde{\omega} \tilde{\eta}^T \\
   \tens{0} & m \dot{\tilde{u}} \tilde{\eta}+\tens{\rho} \tilde{\omega}-\widetilde{\tens{\rho}\vec{\omega} }
   \end{bmatrix} \\
   \label{A3}
   \tens{A}_3 &=
    \begin{bmatrix}
   \tens{0} & m \tilde{\omega}_k \tilde{\eta}^T \\
   \tens{0} & m \dot{\tilde{u}}_k \tilde{\eta}+\tens{\rho} \tilde{\omega}_k-\widetilde{\tens{\rho}\vec{\omega}_k}
   \end{bmatrix} \\
   \label{A4}
   \tens{A}_4 &=
    \begin{bmatrix}
   \tens{0} & \widetilde{\tilde{\omega}m\vec{\eta}}^T+\tilde{\omega}m\tilde{\eta}^T \\
   \tens{0} & \widetilde{\tens{\rho}\vec{\omega}}^T+\tilde{\omega}\tens{\rho}
   \end{bmatrix} \\
   \label{A5}
   \tens{A}_5 &=
    \begin{bmatrix}
   \tens{0} & \tilde{\omega} \tilde{\omega} m \tilde{\eta}^T \\
   \tens{0} & \tilde{\omega} (\tens{\rho} \tilde{\omega} - \widetilde{\tens{\rho} \vec{\omega}}
   \end{bmatrix}
\end{align}
The $\tens{\mathcal{O}}$, $\tens{\mathcal{P}}$, $\tens{\mathcal{Q}}$, and $\tens{\mathcal{S}}$ can be found in previous work by Wang et al \cite{Wang:GEBT2014}. It is also noted that the $\tens{B}$ matrix is a linearization of the tangent matrix $\tens{H}$ defined as
\begin{equation}
    \label{Bmatrix}
    \tens{B}(\vec{p},\vec{a}) = \frac{\partial (\tens{H}(\vec{p})) \vec{a}}{\partial \vec{p}}
\end{equation}

One major difficulty in implementing geometrically nonlinear theory is the description of rotations in 3D space. As discussed in many articles \cite{Crisfield:1999,Bauchau:2010,Bottasso:1998}, there will be a singular point for any type of vectorial parameterization. To address this singular point, we implemented an algorithm proposed by Crisfield and Jeleni\'c \cite{Crisfield:1999}, in which the relative rotations are interpolated instead of the total rotations within one element. Although the magnitude of the total rotation may be large, it is reasonable to assume that the relative rotation in one finite element is smaller than $\pi$. In the time domain, all the nodal rotations need to be rescaled at the same time so the highly nonlinear governing equations in Eq.~\eqref{GovernGEBT-1} and \eqref{GovernGEBT-2} are linearized about the correct point.

In summary, the newly developed BeamDyn has the following features:
\begin{enumerate}
    \item It is based on the state-space form of geometrically exact beam theory, thus, it can be easily integrated into FAST as a structural module with both loose-coupling and tight-coupling schemes using time integrators for first-order form ordinary differential equations (ODEs)
    \item The spectral finite-element method is used to discretize the space domain; exponential convergence rate can be expected for a smooth solution
    \item It is compatible with the FAST modularization network. Variables are categorized into input, output, states, and parameters.
\end{enumerate}

\section{BeamDyn Verification and Validation}
In this section, several numerical cases to verify and validate BeamDyn against numerical solutions and experimental data are presented. As discussed in the introduction, modern wind turbine blade features include initial twists/curvatures, elastic coupling, and high flexibility. BeamDyn's capabilities in addressing these features are examined.

\subsection{Initially Twisted/Curved Beams}

An initially twisted beam was examined first. A straight beam ($k_2=k_3=0$) with an initial twist ($k_1\neq 0$) is shown in Figure~\ref{Twist1}. The beam is linearly twisted in the positive $\theta_1$ direction from 0 degrees at the root to 90 degrees at the tip. Table~\ref{E1Property} shows the material properties for A36 steel, the beam geometry, and the force applied at the free tip along $x_3$ direction. The height and base values reported in the table are the height and base of the rectangular cross section. The beam was discretized using a seventh-order LSFE to obtain a converged results. It is widely known that the well-refined 3D finite-element solution can be considered exact; here we use the 3D results as benchmark solutions. The results for the twisted beam are shown in Table~\ref{E1u} and compared to the baseline results obtained from extremely refined 3D ANSYS analysis using SOLID186 elements. We see that the tip results are quite large (35\% of total length) and that the agreement between the solid-element and beam-element solutions is very good.  These results also serve to validate the beam-modeling approach.

\begin{figure}
\centering
\includegraphics[width=5.0in]{\directory twist_beam.eps}
\caption{Sketch of an initially twisted beam.}
\label{Twist1}
\end{figure}

 \begin{table}
\caption{\label{E1Property} Properties of twisted beam}
\begin{center}
    \begin{tabular}{| l | l |}
    	\hline
    	Property               & Value   \\ \hline
    	Elastic Modulus                      & 200 GPa \\ \hline
    	Shear Modulus                      & 79.3 GPa \\ \hline
    	Height                      & 0.5 m   \\ \hline
    	Base                      & 0.25 m  \\ \hline
    	Length                      & 10 m    \\ \hline
    	Force                      & 4000 kN \\ \hline
    \end{tabular}
\end{center}
\end{table}

\begin{table}
\caption{\label{E1u} Comparison of tip displacements of an initially twisted beam}
\begin{center}
    \begin{tabular}{| l | l | l | l | l | l | l |}
    	\hline
    	        & $u_1$ (m) & $u_2$ (m) & $u_3$ (m)  \\ \hline
    	BeamDyn  & -1.132727     & -1.715123       & -3.578671      \\  \hline
    	ANSYS   & -1.134192     & -1.714467      & -3.584232     \\ \hline
    	Percent Error   & 0.129\%     & 0.038\%      & 0.155\%     \\ \hline
    \end{tabular}
\end{center}
\end{table}

Next, an initially curved beam was examined. It is clear that the initial curvature plays a major role in the distribution of the elastic forces within the beam. As such, it is very important to ensure that BeamDyn is capable of modeling this effect properly. A widely used benchmark problem for a curved beam is the case proposed by Bathe \cite{Bathe1979}, which was analyzed for verification. Figure~\ref{E1Curved} shows the configuration of the cantilevered curved beam being analyzed. The beam lies in the $x_1$, $x_2$ plane, the positive $x_1$ direction and the negative $x_2$ direction. A force of 600 pounds is applied in the positive $x_3$ direction. The beam is defined by the 45-degree arc with 100-inch radius centered at 100 inches in the negative $x_2$ direction.  The geometry of the cross section for the curved beam is square, and the material properties can be found in Ref.[20].  The beam was discretized by a fifth-order LSFE. The results of this static analysis are shown in Table~\ref{E1CurvedDisp} and are compared to the results published in Bathe \cite{Bathe1979}.

\begin{figure}
\centering
\includegraphics[width=2.5in]{\directory E1Curved.eps}
\caption{Sketch of an initially curved beam.}
\label{E1Curved}
\end{figure}

\begin{table}
\caption{\label{E1CurvedDisp} Comparison of tip displacements of an initially curved beam }
\begin{center}
    \begin{tabular}{| l | l | l | l | l | l | l |}
    	\hline
    	        & $u_1$ (inches) & $u_2$ (inches) & $u_3$ (inches)  \\ \hline
    	BeamDyn (one LSFE) & -23.7     & 13.5       & 53.4      \\  \hline
    	Bathe-Bolourchi \cite{Bathe1979}   & -23.5     & 13.4       & 53.4     \\ \hline
    \end{tabular}
\end{center}
\end{table}

It can be seen from these results that the simulations from BeamDyn for a initially curved beam match quite well with the published results. The results of these cases suggest that BeamDyn is capable of modeling beams with initial twist and curvatures.

\subsection{Static Analysis of CX-100 Blade}
The primary intended use of BeamDyn is analyzing anisotropic wind turbine blades, therefore, the CX-100 was chosen as a validation case. The CX-100 is a 9-m blade designed by Sandia National Laboratories \cite{paquette2006modeling}. It was chosen for this analysis because it is well characterized, with a wealth of publicly available data regarding its construction and material properties.

The cross-sectional properties as derived from VABS for this beam were provided by D.J.\ Luscher of Los Alamos National Laboratory. These properties were provided at 40 points along the beam. For example, a typical stiffness matrix corresponding to 2.2 m along the span of the blade is given by
\begin{align*}
C =10^3 \times \begin{bmatrix}
	193,000 & -75.4   & 12.2   & -75.2  & -1970    & -3500    \\
	-75.4  & 19,500 & 4,760   & 62.6  & 67.3    & 11.3    \\
	12.2  & 4,760   & 7,210 & -450  & 17.0    & 2.68    \\
	-75.2  & 62.6   & -450   & 518 & 1.66    & -1.11    \\
	-1,970  & 67.3   & 17.0   & 1.66  & 2,280 & -879    \\
	-3,500  & 11.6   & 2.68   & -1.11  & -875    & 4,240
\end{bmatrix}
\end{align*}
where the units associated with stiffness values are $C_{ij}$ (N), $C_{i,j+3}$ (N $\cdot$ m), and $C_{i+3,j+3}$ (N $\cdot$ m$^2$) for $i,j = 1,2,3$.

Figure~\ref{CX100Sketch} shows the various material layups and the geometry of the CX-100 blade. Each color represents a section with unique material properties. Figure~\ref{normalized1} shows the normalized bending stiffness along the length of the blade where a sharp gradient in the beam axial direction can be observed. The graph shows that the bending stiffness jumped to about 10\% of its root value in under 10\% of the blade length.

\begin{figure}
\centering
\includegraphics[width=3.0in]{\directory CX100Sketch.eps}
\caption{Material layup and geometry of the CX-100 wind turbine blade\cite{paquette2006modeling}.}
\label{CX100Sketch}
\end{figure}

\begin{figure}
\centering
\includegraphics[width=3.0in]{\directory normalized1.eps}
\caption{Normalized bending stiffness as a function of normalized blade length.}
\label{normalized1}
\end{figure}

Figure~\ref{CX100Setup} shows the test configuration for the static test performed at the National Wind Technology Center (NWTC) in Boulder, Colorado. The whiffle-tree configuration of the test apparatus applied the load at 3.00 m, 5.81 m, and 7.26 m from the root of the blade to achieve a maximum root moment of 128.6 kN m. The loads and positions are given in Table~\ref{CX100Load} below.

\begin{figure}
\centering
\includegraphics[width=5.0in]{\directory CX100Setup.eps}
\caption{Test configuration for the static pull test conducted at the NWTC \cite{paquette2006modeling}.}
\label{CX100Setup}
\end{figure}

\begin{table}
\caption{\label{CX100Load}Positions and applied loads during the CX-100 static loads testing at the NWTC  }
\begin{center}
    \begin{tabular}{| l | l |l |}
    	\hline
    	 Saddle \# &     Radial Position (m) & Applied Load (kN)  \\ \hline
    1&	3.00 & 16.9         \\  \hline
    2&	5.81   & 5.47         \\ \hline
    3&	    	7.26   & 5.59         \\ \hline
    \end{tabular}
\end{center}
\end{table}

The out-of-plane displacements, $u_3$, at each of the load points were tracked for the experiment and are given in Table~\ref{CX100Results}. The BeamDyn simulation was completed using four seventh-order LSFEs and the results are given in Table~\ref{CX100Results}.
\begin{table}
\caption{\label{CX100Results}Experimental and BeamDyn simulation results for the CX-100 static test  }
\begin{center}
    \begin{tabular}{| l | l | l | l |}
    	\hline
    	             & $u_3$ at saddle \#1 (m) & $u_3$ at saddle \#2 (m) & $u_3$ at saddle \#3 (m) \\ \hline
    	Experimental & 0.083530             & 0.381996               & 0.632460             \\ \hline
    	BeamDyn      & 0.072056               & 0.381074                & 0.698850           \\ \hline
    	    	Percent Error      &        13.74\%        & 0.24\%                & 10.5\%           \\ \hline
    \end{tabular}
\end{center}
\end{table}
The displacements are plotted in Figure~\ref{CX100Disp_New} and are overall in good agreement. One reason to explain the discrepancies between BeamDyn results and experimental data is that the coupling effects between the degrees of freedom was difficult to measure in the experiments. The results obtained by NLBeam, a nonlinear beam solver developed by Los Alamos National Laboratory, also can be found in Figure~\ref{CX100Disp_New} \cite{Luscher:2013}. While the NLBeam solution was understood to use the same sectional data as the BeamDyn solution, it is currently unknown why the NLBeam solution differs.  The focus of this case was to validate BeamDyn, not verify BeamDyn against NLBeam, and no attempt has been made to find the source of the differences.

\begin{figure}
\centering
\includegraphics[width=3.0in]{\directory CX100Disp_New.eps}
\caption{Displacement $u_3$ along the length of the blade for experimental data and BeamDyn simulation.}
\label{CX100Disp_New}
\end{figure}

Next, a convergence study of the tip displacements was completed for the CX-100 blade in BeamDyn. Figure~\ref{CX100conv3} shows the error as a function of the number of nodes (5 nodes represents 2 nodes per each of the 4 elements, 9 nodes represents 3 nodes per each of the 4 elements, etc.). The percentage error was calculated against the experimental data in Table~\ref{CX100Results}. It can be seen that the convergence rate is not exponential as desired. This is likely due to the fact that as more nodes are added, different material-property stations are used; those data are not smoothly distributed in space. For the next simulation, the blade was meshed such that the element boundaries coincide with the locations where the sectional properties are defined. As previously mentioned, the cross-sectional properties for the CX-100 blade were given at 40 locations along the length of the blade. To have an element coincide with each sectional property, 39 LSFEs were needed. Figure~\ref{CX100elem2} shows the results of this simulation. Each circle on the plot indicates an additional order of the LSFE, with the maximum being six. These results demonstrated that  exponential convergence was achieved with this simulation, albeit with many elements. It can therefore be stated that for composite beams with sharp gradients and erratic data in the cross-sectional stiffness matrix, the spectral convergence is compromised, unless element boundaries coincident with the discontinuities. It should be noted here that although the convergence rate suffers as a result of sharp gradients and erratic data in the cross-sectional stiffness matrix as other finite element \cite{Luscher:2013}, the simulations still return reasonable results in comparison to the experiment data, suggesting that a lack of exponential convergence does not compromise the utility of BeamDyn.

\begin{figure}
\centering
\includegraphics[width=3.0in]{\directory CX100conv3.eps}
\caption{ Percent error in $u_3$ as a function of the number of nodes.}
\label{CX100conv3}
\end{figure}

\begin{figure}
\centering
\includegraphics[width=3.0in]{\directory CX100elem2.eps}
\caption{Percent error in $u_3$ compared to a highly refined solution in BeamDyn as a function of the number of nodes for 39 first- to sixth-order LSFEs, coincident with sectional properties.}
\label{CX100elem2}
\end{figure}

\subsection{Dynamics of a Cantilevered Beam}
For verification of BeamDyn's dynamic analysis capability using the AM2 integrator, a benchmark problem for damping effects in the Dymore release package is used as an example. This example involves a dynamic analysis of a uniform cantilevered beam under an impulsive excitation, which is shown in Figure~\ref{Impulsive}. The excitation was applied at the free tip along both the $x_2$ and $x_3$ directions simultaneously. The simulation range was 0 to 1 second. The sectional stiffness constants can be found in Table~\ref{E3Stiffness} and the units were the same as those used in the previous example. This beam is 2.4 meters long. The inertia properties were: $1.61$ kg/m for the unit mass density, $8.60 \times 10^{-4}$ and $1.10 \times 10^{-4}$ kg m$^{2}$ for the mass moment of inertia about $x_2$ and $x_3$ direction, respectively.   Two cases were analyzed: one without damping effects and the other with damping coefficients of $8.0 \times  10^{-4}$ s for all the six degrees of freedom. The time steps for these two cases are $1 \times 10^{-4}$ and $5 \times 10^{-4}$ seconds, respectively, given that the damping will help the convergence and stability during simulation. The beam was discretized by one fifth-order element in BeamDyn analysis for a converged result. The time histories of all the displacement and rotation components are plotted in Figure~\ref{E3U}. The damping effects can be clearly observed from these results. Furthermore, the accuracy of the present results of damped case were examined by the root-mean-square (RMS) errors, which aggregates the magnitudes of the errors in predictions for various times into a single measure of predictive performance. The error was calculated using
\begin{equation}
\varepsilon_{RMS}=\sqrt{\frac{\sum_{k=0}^{n_{max}}[u_3^k-u_b(t^k)]^2}{\sum_{k=0}^{n_{max}}[u_b(t^k)]^2}}
\label{RMSdefi}
\end{equation}
where $u_b(t)$ is the benchmark solution given by Dymore using eight third-order elements and $5 \times 10^{-4}$s time increment. The RMS error for three displacement components were $1.80 \times 10^{-3}$, $1.32 \times 10^{-3}$, and $2.70 \times 10^{-3}$, respectively.

\begin{figure}
\centering
\includegraphics[width=3.0in]{\directory AM2_Excitation.eps}
\caption{ Impulsive excitation.}
\label{Impulsive}
\end{figure}

\begin{table}
\caption{\label{E3Stiffness} Stiffness constants of the cantilevered beam in Example C }
\begin{center}
    \begin{tabular}{| c | c | c | c | c | c |}
    	\hline
    	       $C_{11}$      & $C_{22}$  & $C_{33}$ & $C_{44} $& $C_{55}$ & $C_{66}$ \\
	       \hline
    	4.35E+07 & 1.40E+07    &2.81E+06  & 2.81E+04 &2.33E+04 & 2.99E+05 \\
	\hline
    \end{tabular}
\end{center}
\end{table}

\begin{figure}
    \centering
    \begin{tabular}{c}
    \subfloat[$u_1$]{\label{E3U:u1}\includegraphics[width=3.0 in]{\directory  AM2_u1.eps}} \qquad
\subfloat[$u_2$]{\label{E3U:u2}\includegraphics[width=3.0in]{\directory  AM2_u2.eps}} \\
\subfloat[$u_3$]{\label{E3U:u3}\includegraphics[width=3.0 in]{\directory  AM2_u3.eps}} \qquad
\subfloat[$p_1$]{\label{E3U:p1}\includegraphics[width=3.0 in]{\directory  AM2_p1.eps}} \\
\subfloat[$p_2$]{\label{E3U:p2}\includegraphics[width=3.0 in]{\directory  AM2_p2.eps}} \qquad
\subfloat[$p_3$]{\label{E3U:p3}\includegraphics[width=3.0 in]{\directory  AM2_p3.eps}} \\
\end{tabular}
\caption{Tip displacement and rotation histories of a cantilever beam under impulsive excitation.}
\label{E3U}
\end{figure}

\subsection{Analysis of NREL 5-MW Blade}
The last example is to examine the efficiency and accuracy of the different time integrators that have been implemented in BeamDyn. The NREL 5-MW blade was analyzed in a cantilever condition, while a white-noise force is applied at the free tip along the flap direction. White noise was used to mimic the magnitude and frequency content of applied aerodynamic loads under realistic turbulent conditions. The damping coefficient is set to $10^{-3}$ s. Figure~\ref{E4Force} shows the time history of the applied force and its power spectral density (PSD). The flap direction responses are plotted in Figure~\ref{E4Displacement}. Four cases were conducted in BeamDyn: the first three cases were using the AM2 time integrator with time step size: $2.5 \times 10^{-2}$ s, $5 \times 10^{-3}$ s, and $5 \times 10^{-4}$ s, respectively, while the fourth case was using RK4 time integrator with time step sizes $5 \times 10^{-6}$ s.  It can be observed that for an implicit AM2 time step beyond 0.005 s, the solution is nearly identical to the fully resolved explicit RK4 solution.  For an AM2 time step of 0.025 s, the solution remains stable and tracks the other solutions, but error grows at higher frequencies.  The spikes at 0.7 Hz and 2 Hz correspond to the first and second blade flapwise natural frequencies, respectively.  The spike above 5 Hz--above the frequency range of excitation--is brought about by nonlinear effects.
\begin{figure}
    \centering
    \begin{tabular}{c}
    \subfloat[Time history of applied force]{\label{E4Force:Force}\includegraphics[width=5.0 in]{\directory  5MW_Flap_Force_Final.eps}} \\
\subfloat[PSD of applied force]{\label{E4Force:PSD}\includegraphics[width=5.0in]{\directory  5MW_Flap_Force_PSD_Final.eps}} \\
\end{tabular}
\caption{Applied white noise force at the tip of a cantilevered NREL 5-MW blade.}
\label{E4Force}
\end{figure}

\begin{figure}
    \centering
    \begin{tabular}{c}
    \subfloat[Time history of flap displacement]{\label{E4Displacement:Disp}\includegraphics[width=5.0 in]{\directory  u_5MW_flap_final.eps}} \\
\subfloat[PSD of flap displacement]{\label{E4Displacement:PSD}\includegraphics[width=5.0in]{\directory  u_5MW_flap_psd_final.eps}} \\
\end{tabular}
\caption{Flap direction responses of a cantilevered NREL 5-MW blade under white noise excitation.}
\label{E4Displacement}
\end{figure}

The convergence rate against time step size for the AM2 integrator is also examined. The result from the RK4 simulation is taken as the benchmark solution. The normalized RMS error defined in Eq.~\eqref{RMSdefi} is plotted in Figure~\ref{RMS_5MW}, in which second-order convergence as a function of time increment size can be observed. It is also pointed out that a full Newton-Raphson algorithm has been implemented in BeamDyn. The total and average numbers of linear system solves, which are related to the computational time required for the solution, are plotted in Figure~\ref{E4NR}. It can be observed that while the total number of linear system solves reduces with increasing time step, the average number of solves per step increases.  This means that the computation time cannot be cut in two by doubling the time step.
\begin{figure}
\centering
\includegraphics[width=3.0in]{\directory RMS_5MW.eps}
\caption{ Normalized RMS error of flapwise displacement histories as a function of time step size for AM2 time integrator. The dashed line shows ideal second-order convergence.}
\label{RMS_5MW}
\end{figure}

\begin{figure}
    \centering
    \begin{tabular}{c}
    \subfloat[Total number of linear system solves]{\label{E4NR:Total}\includegraphics[width=3.0 in]{\directory  TotalNR.eps}} \qquad
\subfloat[Average number of linear system solves per step]{\label{E4NR:Average}\includegraphics[width=3.0in]{\directory  AveNR.eps}} \\
\end{tabular}
\caption{Total and average numbers of linear system solves in the simulations.}
\label{E4NR}
\end{figure}

%For this 100s simulation with a time step size of $2.5 \times 10^{-2}$ s, the total number of solved linear system is 37839; while this number for the RK4 simulation with a time step size of $5 \times 10^{-6}$ s  is $8 \times 10^{7}$.

 \section{Summary}
  This paper reported on the development of BeamDyn, a beam solver in the FAST modularization framework. Geometrically exact beam theory has been reformulated into the first-order state-space form so that first-order time integrators, as required by FAST framework for tight-coupling analysis, can be applied. Numerical examples are provided to verify and validate the capability of BeamDyn in analyzing initially curved/twisted beams. A validation example is also presented where the numerical results are compared with experimental data. In all the cases, good agreement was observed.  The convergence rate for analysis of realistic wind turbine blade is discussed. The features of BeamDyn can be summarized as follows:
  \begin{enumerate}
  \item Based on geometrically exact beam theory, BeamDyn is capable of dealing with geometric nonlinear beam problems with arbitrary magnitude of displacements and rotations for both static and dynamic analyses
  \item Along with a preprocessor like PreComp or VABS, BeamDyn takes full elastic coupling effects into account
  \item The governing equations are reformulated into state-space form, thus, making it amendable into FAST for tight-coupling analysis
  \item The space is discretized by spectral finite elements, which is a p-version finite element, so that exponential convergence rate can be expected for smooth solutions
  \item Different time integrators have been implemented in BeamDyn; users will have options based on their needs
  \item BeamDyn is implemented following the programming requirements (data structures and interfaces) of the FAST modularization framework.
  \end{enumerate}
   Future work includes the proposal of a practical approach to smooth the geometry and sectional constants to help achieve the expected exponential convergence rate. In addition, this module will be coupled to FAST and verification and validation will be conducted on a full wind turbine system.

\section*{Acknowledgments}

This work was supported by the U.S. Department of Energy under Contract No.\
DE-AC36-08GO28308 with the National Renewable Energy Laboratory. Funding for the work was provided by the DOE Office of Energy Efficiency and Renewable Energy, Wind and Water Power Technologies Office. Support
was also provided through a laboratory directed research and development grant
\textit{High-Fidelity Computational Modeling of Wind-Turbine Structural
Dynamics}. The authors would also like to acknowledge D.J. Luscher for CX-100 sectional data.

\bibliographystyle{aiaa}
\bibliography{references}

\end{document}


\documentclass[12pt]{article}
\title{Discouragement Attacks}
\author{
        Vitalik Buterin \\
        Ethereum Foundation
}
\date{\today}
\usepackage{graphicx}

\begin{document}
\maketitle
\begin{abstract}
We explore ``discouragement attacks" on economic consensus mechanisms. A discouragement attack consists of an attacker acting maliciously inside a consensus mechanism in order to reduce other validators' revenue, even at some cost to themselves, in order to encourage the victims to drop out of the mechanism. The motivations to conduct discouragement attacks are twofold. First, the attacks can increase the attacker's profit, as the mechanism may contain ``competitive" dynamics where some validators dropping out increases revenue to the remaining ones. Second, the attacks can be part of a two-step strategy where the second step is to carry out a traditional $51\%$ attack on the consensus algorithm against a now much smaller set of ``honest" validators warding off the attacker, and hence pay a much lower cost for the attack.
\end{abstract}

\section{Introduction}
Consider the following type of attack on a proof of stake blockchain. The rules of the chain are as follows: there is a maximum total reward $R$, and if there are $N$ validators (consider each validator as having deposited one coin) then each validator, during every 10-second slot, has a chance to earn a reward of $\frac{R}{N}$ if they actually sign a message that contributes to the chain's consensus during that round. An attacker that controls $\frac{N}{2} + 1$ validators starts refusing to include messages from all remaining validators. Initially, the attack reduces the victims' revenue to zero and leaves the attacker's revenue unchanged. However, the victims then see no incentive to continue to be validators and exit the proof of stake mechanism. The validator count reduces to $\frac{N}{2} + 1$, and the attacker's revenue increases from $R * \frac{\frac{N}{2} + 1}{N}$ to $R$.

Here is a possible alternative ending: once everyone but the attacker leaves, the attacker slowly exits their validators until only one validator remains. They then perform a double-spending attack, censorship attack or any other kind of attack on the chain. In either case, it's clear that this kind of two-step strategy is potentially a much cheaper way of bringing down blockchains than a direct frontal attack.

\section{Griefing factors}

To analyze attacks like these, a common tool that we use is the \emph{griefing factor}. A mechanism in some equilibrium has a griefing factor of $N$ if the attacker has a mechanism by which they can sacrifice \$1 of their own funds to cause \$N of losses to the other participants. If attackers can harm others costlessly or profitably, the griefing factor is $\infty$. With respect to attackers with $\ge \frac{1}{2}$ of all validators, the toy proof of stake mechanism we described above has griefing factor $\infty$.

However, it is possible to modify the mechanism to bound the griefing factor: if $M$ out of $N$ validators are seen signing a message, then each validator that signs only earns $\frac{R}{N} * \frac{M}{N}$. Then, if the possibility of victims withdrawing or depositing is not taken into account, an attacker with $\frac{N}{2}$ validators censoring $k$ validators (for simplicity of analysis we'll assume that 51\% attacks are possible with exactly 50\%) cuts the reward of all online validators from $\frac{R}{N}$ to $\frac{R}{N} * \frac{N-k}{N}$, and so causes:

\begin{itemize}
\item $\frac{N}{2} * \frac{R}{N} * \frac{k}{N} = R * \frac{k}{2N}$ losses to themselves due to reward reduction
\item $\frac{R}{N} * k = R * \frac{k}{N}$ losses to victims of censorship
\item $(\frac{N}{2} - k) * \frac{R}{N} * \frac{k}{N} = R * (\frac{k}{2N} - \frac{k^2}{N^2})$ losses to others due to reward reduction
\end{itemize}

As $k$ approaches zero, the griefing factor approaches $\frac{R * \frac{k}{N} + R * \frac{k}{2N}}{R * \frac{k}{2N}} = 3$. As $k$ approaches $\frac{N}{2}$, the griefing factor approaches $\frac{\frac{k}{N}}{\frac{k}{2N}} = 2$. Minorities can also grief majorities by going offline, and for a minority attacker the griefing factor is limited to $1$ for small attacks and $\frac{1}{2}$ for attacks with size approaching half the entire validator set. In the rest of our analysis, we will speak abstractly about proof of stake mechanisms with particular griefing factors; this will allow us to compartmentalize our analysis.

\section{Epsilon attacks}

We will start off examining a particular subclass of attack, where the extent of the attack is small. That is, the attacker selectively censors or otherwise interferes with a small portion of the messages of the victims, reducing their rewards but not enough to make them all leave.

In our naive examples above, the reward given to each validator was a $\frac{1}{N}$ share of some fixed total pot, $R$, where $N$ is the total number of validators (or total deposit size). But this is really only one policy among many possible policies. We can categorize many of them with the equation $r = N^{-p}$, where:

\begin{itemize}
\item $p=0$: constant ``interest rate", eg. under optimal conditions each validator earns a return of $8\%$ per year.
\item $p=\frac{1}{2}$: the rewards (and penalties) to validators scale with $\frac{1}{\sqrt{N}}$, so \textit{total} rewards scale with $\sqrt{N}$. This is a compromise between $p=0$ and $p=1$.
\item $p=1$: constant total reward, ie. the total payout of the protocol is dependent only on what percentage of validators take what actions, not on the total deposit size.
\item $p=\infty$: the protocol is dead-set on ensuring that the total deposit size is some specific constant $N_k$ no matter what. If the total deposit size exceeds $N_k$, the protocol keeps decreasing rewards until it drops to $N_k$, and if the total deposit size is below $N_k$, the protocol keeps increasing rewards until it rises to $N_k$. Mathematically, we represent this as the reward curve being a vertical line at $x = N_k$, being equal $\infty$ below $N_k$ and $0$ above $N_k$.
\end{itemize}

Note that if revenues to validators are dominated by transaction fees, then $p=1$ will hold.

We now rephrase the problem into the language of supply and demand: there exist a set of players, each of which has some \textit{reserve reward level} at which they are willing to become validators in the consensus mechanism. This is the supply curve, where the reward level is the price. The protocol, which offers rewards for participation in the consensus mechanism, sets the demand curve. If $p=0$, the demand curve is horizontal - the protocol offers that interest rate to an unlimited number of validators. If $p=\infty$, the demand curve is vertical. For any other $p$, the demand curve is declining diagonally. For simplicity, we will suppose that the supply curve is $N = r^k$ for some $k$ (eg. $k = 1$) where $r$ is the per-validator reward offered. Absent any attacks, the status-quo values of $N$ and $r$ are the intersection of the supply curve offered by potential validators and the demand curve offered by the protocol.

\includegraphics[width=300px]{disc_chart1.png}

We model an attack as \emph{pushing the entire demand curve down}, and in addition costing or benefiting the attacker. We can determine everyone's equilibrium profit by calculating the intersection of the (unchanged) supply curve and the new (depressed) demand curve, and then adding a term to take into account the fact that the attacker's profits as a percentage of their deposits may be less or more than everyone else's.

\includegraphics[width=300px]{disc_chart2.png}

Locally, we can see the protocol reward curve as a straight line with slope $-p$, and the supply curve of users' willingness to participate as a straight line with slope $k$. If the reward curve is pushed down by $\epsilon$, then the validator count is pushed left by $\frac{\epsilon}{k+p}$ and the reward is reduced by $\epsilon * \frac{k}{k + p}$ (another way to think about it is that everyone loses $\epsilon$ from the attack and then \emph{recovers} $\frac{p}{k+p}$ from the equilibrium shifting left). Hence, for example, if $k = p = 1$, then because of the marginal validators the attack drives away, everyone (including victims and attacker) earns back an amount equal to half the original per-validator loss of each victim. If $k = 1$ and $p = \frac{1}{2}$, then everyone only earns back a third.

Note that the analysis does not change if the attacker makes a targeted attack, provided the attacker does not have special knowledge about the victim's willingness to be a validator (to preserve this assumption, we generally recommend proof of stake validators try to remain anonymous). The reason is that an attack on $\frac{1}{M}$ of the validator set with the same griefing factor harms them $M$ times as much, driving $M$ times as many to leave, but the set affected is only $\frac{1}{M}$ in size, so on net the same number of victims leave as a result of the attack.

Griefing factors are highest when the attacker has exactly half of the validators. This is convenient, because it means that the size of the attacker and victim sets are the same, so the griefing factor is also the ratio of the losses of average rewards \emph{of each validator}. Let us suppose the victims lose $\epsilon$. If the mechanism has a griefing factor of $N$, then the attacker loses $\epsilon * \frac{1}{N}$. If everyone recovers $\epsilon * r$ where $r = \frac{p}{k+p}$, then the victims' losses become $\epsilon * (1-r)$ and the attacker's losses $\epsilon * (\frac{1}{N} - r)$. Hence, an attack can be profitable if $\frac{p}{k+p} > \frac{1}{N}$.

\includegraphics[width=300px]{disc_chart3.png}

If $N = 3$, as is the case in the simplest collective-penalty scheme described above, and we assume $k=1$, then this implies we need $p \le \frac{1}{2}$ for epsilon attacks to be unprofitable.

\section{Total attacks}

Attackers with less than 50\% of the validator set, or attackers trying to make the attack \emph{look} innocuous (eg. passing it off as abnormally high network latency) only have epsilon attacks at their disposal. An epsilon attack has the disadvantage that the attack must keep running, continuing to cost the attacker. But what if the attacker can drive \emph{everyone} out (eg. attack enough to push victims' revenues to below zero)? Then, from inside the mechanism, it looks as though no one is attacking (as all victims are no longer participating), and so the attacker is claiming their full maximum rewards. In fact, if $p > 0$, the attacker is claiming \emph{more} rewards than before.

Additionally, unlike epsilon attacks, total attacks can be used to drive the cost of doing an outright attack on the chain (eg. reverting finality) down to zero, although only blocks finalized after the non-attacking validators all leave can be reverted cheaply, so it may be philosophically more correct to consider such an attack an attack on \emph{liveness} rather than \emph{safety}.

One answer may be: if a total attack, driving the revenues of innocent validators to below zero, is taking place, clients can detect this, and coordinate a minority soft fork extra-protocol to remove the attacker. But can we do better?

We could choose $p < 0$ to make such attacks greatly unprofitable; however, this imposes great instability on the protocol because small shifts in demand for validating could lead to very large shifts in both the size of the validator set and the total issuance; indeed, as $p$ approaches $-k$ arbitrarily small shifts in demand can cause arbitrarily large shifts in validator set size. Hence, such an approach is likely nonviable.

Another approach is to limit the rate at which validators exit, making it difficult for many validators to leave at the same time. This would require an attacker to sustain an attack for a longer period of time, during which the community could mount a response, and costing the attacker more in the meantime. Particularly, one could freeze all validator withdrawals for the entire period during which the protocol detects that there is an attack and validators are not earning money. An attacker could still attack at zero cost in a richer economic model by \emph{precommitting} to attack and letting other validators leave first, but this would be more complicated to implement.

Finally, one can add an ``assurance contract'' mechanic into the deposit mechanism: a validator wishing to enter can specify the minimum validator set size at which they are willing to enter (eg. if there are 1000 validators currently in the validator set one could specify $\le 1000$ to enter immediately or one could specify 1500). The deposit mechanism would try to induct as many validators as possible such that every validator would satisfy its constraint (eg. if there are currently 1000 validators waiting, and new validators want to join with specified minimums 1001 1003 1004 1004 1006, then the first four could be inducted, as that would increase the count to 1004 which would satisfy all four of them, but the remaining one would not be inducted as if all five joined the total validator count would become 1005, and $1005 < 1006$. This would allow validators to more easily coordinate to fight back against attacks, effectively by saying ``I'm willing to join only if enough others join at the same time to defeat this attacker with me".

\section{Conclusion}

Discouragement attacks as a cheaper way of attacking a consensus algorithm are one of the hardest classes of attacks to come up with defenses against. This is even more true in proof of work: if a 51\% attack succeeds, then there is a coordination problem opposing ``honest" miners trying to recover the original fork, as none have the private incentive to participate in a fork unless everyone else does. There are some possible strategies for mitigating these attacks especially in a proof of stake system, including making them take longer to execute, easier to coordinate to defeat, and less profitable, but none are perfect. In general, this is still an active area of research, and more research on counter-strategies is desired.

\bibliographystyle{abbrv}
\bibliography{main}

\end{document}


\documentclass[11pt,letter]{article}

\usepackage{latexsym, color, graphicx, comment}
\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{empheq}
\hypersetup{colorlinks=true,linkcolor=blue}

\newcommand{\vect}[1]{\mbox{\boldmath $#1$}}
\newcommand{\gyrophase}{\varphi}
\newcommand{\energy}{\varepsilon}
\renewcommand{\Re}{\mathrm{Re}}
\renewcommand{\Im}{\mathrm{Im}}
\newcommand{\todo}[1]{\textcolor{red}{#1}}
%\newcommand{\kxfac}{\kappa_x}
\newcommand{\kxfac}{\mathtt{kxfac}}
\newcommand{\bmag}{\mathtt{bmag}}
\newcommand{\smz}{\mathtt{smz}}
\newcommand{\gdstwo}{\mathtt{gds2}}
\newcommand{\gdstwoone}{\mathtt{gds21}}
\newcommand{\gdstwotwo}{\mathtt{gds22}}
\newcommand{\gbdrift}{\mathtt{gbdrift}}
\newcommand{\gbdriftO}{\mathtt{gbdrift0}}
\newcommand{\cvdrift}{\mathtt{cvdrift}}
\newcommand{\cvdriftO}{\mathtt{cvdrift0}}
\newcommand{\fprim}{\mathtt{fprim}}
\newcommand{\tprim}{\mathtt{tprim}}
\newcommand{\jtwist}{\mathtt{jtwist}}
\newcommand{\gradpar}{\mathtt{gradpar}}
\newcommand{\delthet}{\mathtt{delthet}}
\newcommand{\codedt}{\mathtt{code\_dt}}

\title{Definitions for GS2 full-flux-surface stellarator geometry}
\author{Matt Landreman}

\begin{document}
\maketitle

In this note, we state the definitions used for geometric quantities in the full-flux-surface
version of GS2, and we detail how these quantities are computed from the information
in a VMEC output file. We also derive how the twist-and-shift parallel boundary condition
and box size quantization conditions, familiar from flux tube simulations,
are modified in a full-surface calculation.

\section{Review of GS2 geometry definitions}

\subsection{Definitions valid for any GS2 geometry}
First, we review the definitions used in the flux tube version of GS2,
as discussed in the note {\ttfamily gs2\_geometry\_definitions.pdf}.
The Clebsch representation of the magnetic field is
\begin{equation}
\vect{B} = \nabla\psi\times\nabla\alpha.
\label{eq:Clebsch}
\end{equation}
We take $\psi$ to represent a flux surface label, but do not (yet) assume that it is necessarily the poloidal or toroidal flux. The $\alpha$ coordinate is a field line label on the flux surface.
New coordinates $x=x(\psi)$ and $y=y(\alpha)$ are introduced that are scaled versions of $\psi$ and $\alpha$
with dimensions of length. In a flux tube simulation where $x$ and $y$ only vary on a length scale comparable to the gyroradius, then
\begin{align}
&x = \frac{dx}{d\psi} \left[ \psi - \psi_0 \right], \\
&y = \frac{dy}{d\alpha} \left[ \alpha - \alpha_0 \right] \nonumber,
\end{align}
where $dx/d\psi$ and $dy/d\alpha$ are constant within the flux tube,
and $\psi_0$ and $\alpha_0$
are the coordinates around which the flux tube is centered.

A reference magnetic field strength $B_{ref}$ and reference length $L_{ref}$ are introduced for normalization.
Then the quantities needed to specify the geometry in GS2 are the following:
\begin{align}
\bmag & = \frac{B}{B_{ref}}, \label{eq:bmag} \\
\gradpar &= L_{ref} \nabla_{||} z, \\
\gdstwo &= |\nabla y |^2  = \left( \frac{dy}{d\alpha} \right)^2 |\nabla\alpha|^2 , \\
\gdstwoone &= \hat{s} \nabla x \cdot \nabla y = \hat{s} \frac{dx}{d\psi} \frac{dy}{d\alpha} \nabla\psi\cdot\nabla\alpha , \\
\gdstwotwo &= \hat{s}^2|\nabla x |^2  = \hat{s}^2 \left( \frac{dx}{d\psi} \right)^2 |\nabla\psi |^2. \\
\gbdrift &= \frac{2 B_{ref} L_{ref}}{B^3} \vect{B}\times\nabla B\cdot \nabla y, \\
\gbdriftO &= \hat{s} \frac{2 B_{ref} L_{ref}}{B^3} \vect{B}\times\nabla B\cdot \nabla x,  \\
\cvdrift &= \frac{2 B_{ref} L_{ref}}{B^2} \vect{B}\times\vect{\kappa} \cdot \nabla y,  \\
\cvdriftO &= \hat{s} \frac{2 B_{ref} L_{ref}}{B^2} \vect{B}\times\vect{\kappa} \cdot \nabla x, \label{eq:cvdrift0} \\
\kxfac & = B_{ref} \frac{dx}{d\psi} \frac{dy}{d\alpha}, \label{eq:kxfac} \\
\fprim &=
B_{ref} L_{ref}
\frac{dy}{d\alpha} \frac{dx}{d\psi} \frac{1}{n_s} \frac{d n_s}{d x}, \\
\tprim &=
B_{ref} L_{ref}
\frac{dy}{d\alpha} \frac{dx}{d\psi} \frac{1}{T_s} \frac{d T_s}{d x}. \label{eq:tprim}
\end{align}
These quantities are all dimensionless. In the definition of $\gradpar$, $z$ is any parallel coordinate; the parallel coordinate
is called {\ttfamily theta} in GS2, although it need not be the poloidal angle.
Also $\hat{s}$ is whichever number is used to define $\theta_0=${\ttfamily theta0} in the relation
\begin{equation}
\theta_0 = \frac{k_x}{\hat{s} k_y}.
\end{equation}
The above quantities (\ref{eq:bmag})-(\ref{eq:cvdrift0}) are functions of the parallel coordinate $z$.
The quantity $\kxfac$ is a single number, and the quantities $\fprim$ and $\tprim$  are each single numbers
for each particle species.

Since $\vect{B}\times\vect{\kappa}\cdot\nabla\psi = \vect{b}\times\nabla B\cdot\nabla\psi$ for any
static ideal MHD equilibrium (at any $\beta$), then $\cvdriftO=\gbdriftO$.

\subsection{Definitions used previously for stellarator geometry in GS2}

In stellarator calculations that have been performed using the standard flux tube version of GS2
and the GIST geometry interface,
the following additional definitions have been made.
The flux surface label $\psi$ has been taken to be the toroidal flux divided by $2\pi$.
Therefore for consistency with (\ref{eq:Clebsch}),
$\alpha = \theta - \iota \zeta$ where $\iota = 1/q$ is the rotational transform,
$q$ is the safety factor, and $\theta$ and $\zeta$ are straight-field-line poloidal and toroidal angles.
While the GIST GS2 interface takes $\theta$ and $\zeta$ to be Boozer
angles, all the expressions below are equally valid for other straight-field-line angles such as PEST or Hamada coordinates.

In GIST, the parallel coordinate $z$ is presently taken to be the Boozer poloidal angle. However none of the expressions in this note are altered if a different choice is desired.

In GIST, the reference length $L_{ref}$ is taken to be the effective minor radius computed by VMEC, named Aminor\_p in
the VMEC wout*.nc file.
The reference magnetic field is taken to be
\begin{equation}
B_{ref} = \frac{2 \psi_{LCFS}}{L_{ref}^2}
\label{eq:Bref}
\end{equation}
where $\psi_{LCFS}$ is the value of $\psi$ at the outermost VMEC flux surface. The choice (\ref{eq:Bref}) is
motivated by the cylindrical limit: the toroidal flux enclosed by the outermost VMEC surface is equivalent to the flux of a field $B_{ref}$ through a circle of radius $L_{ref}$.

The radial coordinate $x$ is then chosen to be
\begin{equation}
x = L_{ref} \sqrt{\frac{\psi}{\psi_{LCFS}}} = L_{ref} \sqrt{s},
\label{eq:gist_x}
\end{equation}
where $s = \psi / \psi_{LCFS} \in [0,1]$ is the flux surface label coordinate
used in VMEC.
The choice (\ref{eq:gist_x}) is natural since
$x$ then reduces to the usual minor radius in the cylindrical limit.
%the toroidal flux $2\pi\psi$ scales like the square of the radius in the cylindrical limit.
It follows that
\begin{equation}
\frac{dx}{d\psi} = \frac{L_{ref}}{2 \sqrt{ \psi \psi_{LCFS}}}
= \frac{1}{L_{ref} B_{ref}} \sqrt{ \frac{\psi_{LCFS}}{\psi}}.
\label{eq:psi_x_conversion}
\end{equation}

Another choice made in GIST is $\kxfac=1$. According to (\ref{eq:kxfac}), we are then required to take
\begin{equation}
\frac{d y}{d\alpha} = L_{ref} \sqrt{\frac{\psi}{\psi_{LCFS}}} .
\label{eq:dy_dalpha}
\end{equation}

GIST computes the global shear parameter $\hat{s}$ using
\begin{equation}
\hat{s} = \frac{x}{q} \frac{dq}{dx}.
\end{equation}

Now that $dx/d\psi$ and $dy/d\alpha$ are specified, equations (\ref{eq:bmag})-(\ref{eq:tprim})
can be evaluated to obtain explicit expressions for the geometry arrays computed by GIST for GS2:
\begin{eqnarray}
\bmag &=& B/B_{ref}, \label{eq:gist_Bref}\\
\gradpar &=& L_{ref} \nabla_{||} z, \\
\gdstwo &=& |\nabla y|^2 = |\nabla\alpha|^2 L_{ref}^2 \frac{\psi}{\psi_{LCFS}}, \\
\gdstwoone &=& \hat{s} \nabla x \cdot \nabla y = \frac{\hat{s}}{B_{ref}} \nabla\psi\cdot\nabla\alpha , \\
\gdstwotwo &=& \hat{s}^2|\nabla x |^2  = \left( \frac{\hat{s}}{L_{ref} B_{ref}}\right)^2 \frac{\psi_{LCFS}}{\psi} |\nabla\psi |^2, \\
\gbdrift &=& \frac{2 B_{ref} L_{ref}^2}{B^3} \sqrt{\frac{\psi}{\psi_{LCFS}}} \vect{B}\times\nabla B\cdot \nabla \alpha, \\
\gbdriftO &=& \hat{s} \frac{2 }{B^3}   \sqrt{\frac{\psi_{LCFS}}{\psi}} \vect{B}\times\nabla B\cdot \nabla \psi, \\
\cvdrift &=& \frac{2 B_{ref} L_{ref}^2}{B^2} \sqrt{\frac{\psi}{\psi_{LCFS}}} \vect{B}\times\vect{\kappa} \cdot \nabla \alpha, \\
\cvdriftO &=& \hat{s} \frac{2 }{B^2}  \sqrt{\frac{\psi_{LCFS}}{\psi}} \vect{B}\times\vect{\kappa} \cdot \nabla \psi,  \label{eq:gist_cvdrift0} \\
\fprim &=&   \frac{L_{ref}}{n_s} \frac{d n_s}{d x}, \\
\tprim &=&   \frac{L_{ref}}{T_s} \frac{d T_s}{d x}.
\end{eqnarray}

\section{VMEC coordinates}

The VMEC code uses a toroidal coordinate $\zeta$ which is the conventional azimuthal angle of cylindrical coordinates.

We let $\theta_v$ denote the poloidal angle used in VMEC, which is \emph{not} a straight-field-line coordinate.
We also let $\theta_p$ denote the PEST poloidal angle, i.e. the straight-field-line angle which results when
the toroidal angle is chosen to be the conventional azimuthal angle of cylindrical coordinates, as in VMEC.
The conversion between the two coordinates is
\begin{equation}
\theta_p = \theta_v + \Lambda,
\end{equation}
where $\Lambda$ is the quantity given by the {\ttfamily lmns} and {\ttfamily lmnc} arrays in VMEC.
Thus, the field line label we need for GS2 geometry quantities is
\begin{equation}
\alpha = \theta_v + \Lambda - \iota \zeta.
\label{eq:alpha_vmec}
\end{equation}

VMEC provides many quantities as functions of the coordinates $(s, \theta_v, \zeta)$,
where again $s = \psi / \psi_{LCFS}$.
Specifically, it provides the Fourier amplitudes for expansions in $\theta_v$ and $\zeta$,
on grid points equally spaced in $s$.
The quantities that are available include
$\Lambda$, $B$, the cylindrical coordinates $(R,Z)$, the components
\begin{align}
B^\theta &= \vect{B}\cdot\nabla\theta_v, \nonumber \\
B^\zeta &= \vect{B}\cdot\nabla\zeta, \nonumber \\
B_s &= \vect{B}\cdot\frac{\partial\vect{r}}{\partial s}, \nonumber \\
B_\theta &= \vect{B}\cdot\frac{\partial\vect{r}}{\partial \theta_v}, \nonumber \\
B_\zeta &= \vect{B}\cdot\frac{\partial\vect{r}}{\partial \zeta}, \nonumber
\end{align}
and the Jacobian
\begin{equation}
\sqrt{g} = \frac{\partial \vect{r}}{\partial s} \cdot \frac{\partial \vect{r}}{\partial\theta_v} \times \frac{\partial\vect{r}}{\partial\zeta}
= \frac{1}{\nabla s \cdot \nabla \theta_v \times\nabla\zeta}.
\label{eq:Jacobian}
\end{equation}
Here $\vect{r}(s,\theta_v,\zeta)$ is the position vector.
Throughout this note, we will use $\sqrt{g}$ to denote the Jacobian of the non-straight-field-line
VMEC coordinates, as in (\ref{eq:Jacobian}).

%\begin{align}
%\vect{B} &= \nabla\psi \times \nabla\theta_p + \iota \nabla\zeta \times \nabla\psi \nonumber \\
%& = \nabla\psi \times \nabla\theta_v + \nabla\psi \times \nabla \Lambda + \iota \nabla\zeta \times \nabla\psi .
%\end{align}

\section{Computation of GS2 geometry quantities from VMEC data}

Given the desired central flux surface $\psi_0$, and given a desired set of grid points in $\alpha$ and $\zeta$,
a 1D nonlinear root-finding algorithm is applied to solve (\ref{eq:alpha_vmec}) for the
value of $\theta_v$ at each grid point. The $\bmag$ array is then obtained by evaluating $B$
at the $(\theta_v, \zeta)$ grid points, using VMEC's Fourier arrays {\ttfamily bmnc} and {\ttfamily bmns}.

For the full-flux-surface calculation, we will take the parallel coordinate $z$ to be the toroidal angle $\zeta$.
Then to evaluate $\gradpar$, we use
\begin{equation}
\gradpar = L_{ref} \frac{\vect{B}\cdot\nabla\zeta}{B} = L_{ref} \frac{B^\zeta}{B},
\end{equation}
%\begin{align}
%\gradpar
%&=\frac{\vect{B}\cdot\nabla\zeta}{B}
%=\frac{\nabla\psi\times\nabla\alpha\cdot\nabla\zeta}{B}
%=\frac{\nabla\psi\times\nabla(\theta_v +\Lambda - \iota\zeta)\cdot\nabla\zeta}{B}
%=\frac{\nabla\psi\times\nabla(\theta_v +\Lambda)\cdot\nabla\zeta}{B} \nonumber \\
%&=\frac{1}{B \sqrt{g}} \left( 1 + \frac{\partial\Lambda}{\partial\theta_v}\right).
%\end{align}
where $B^\zeta$ is available in the VMEC output through the variables {\ttfamily bsupvmnc} and {\ttfamily bsupvmns}.

To evaluate the quantities {\ttfamily gds*}, we must obtain the Cartesian components of
$\nabla\psi$ and $\nabla \alpha$. To this end, we use the dual relations:
\begin{align}
\nabla s &=  \frac{1}{\sqrt{g}} \frac{\partial\vect{r}}{\partial\theta_v} \times \frac{\partial\vect{r}}{\partial\zeta}, \label{eq:nabla_s}\\
\nabla\theta_v &= \frac{1}{\sqrt{g}} \frac{\partial\vect{r}}{\partial\zeta} \times \frac{\partial\vect{r}}{\partial s}
\label{eq:nabla_theta}.
\end{align}
The right hand sides of these two expressions can be evaluated in terms of Cartesian components using the VMEC
outputs {\ttfamily rmnc}, {\ttfamily rmns}, {\ttfamily zmnc}, and {\ttfamily zmns}, yielding
Cartesian components for $\nabla s$ and $\nabla\theta_v$. Also the Cartesian components of $\nabla\zeta$
are known since $\zeta$ is the standard toroidal angle.
We can then compute
\begin{equation}
\nabla\psi = \frac{d\psi}{ds} \nabla s = \psi_{LCFS}  \frac{1}{\sqrt{g}} \frac{\partial\vect{r}}{\partial\theta_v} \times \frac{\partial\vect{r}}{\partial\zeta}
\end{equation}
and
\begin{align}
\nabla\alpha
&= \nabla(\theta_v + \Lambda - \iota \zeta) \nonumber \\
&= \left(\frac{\partial\Lambda}{\partial s} - \zeta \frac{d\iota}{ds}\right)\nabla s
+ \left( 1 + \frac{\partial\Lambda}{\partial\theta_v}\right) \nabla\theta_v
+ \left( -\iota + \frac{\partial\Lambda}{\partial\zeta}\right) \nabla\zeta.
\label{eq:grad_alpha}
\end{align}
\todo{Do we want to subtract {\ttfamily zeta\_center} from $\zeta$ here so the secular $\zeta$ term in $\nabla\alpha$ vanishes at the center of the domain? Or might we want it to vanish somehwhere other than the center of the domain?}
Now that Cartesian components of $\nabla\psi$ and $\nabla \alpha$ are known, $\gdstwo$, $\gdstwoone$, and $\gdstwotwo$ can be computed.

To evaluate $\gbdriftO = \cvdriftO$, we can use
\begin{align}
\vect{B}\times\nabla B\cdot\nabla\psi
&=
\vect{B}\times\nabla \zeta \cdot \nabla \psi \frac{\partial B}{\partial \zeta} + \vect{B}\times\nabla \theta_v \cdot \nabla \psi \frac{\partial B}{\partial \theta_v} \nonumber \\
&=  \left(
B_\theta \nabla\theta_v \times\nabla\zeta\cdot\nabla s \frac{\partial B}{\partial\zeta} + B_\zeta \nabla\zeta\times\nabla\theta_v\cdot\nabla s \frac{\partial B}{\partial\theta_v} \right) \frac{d\psi}{ds} \nonumber \\
&= \left( B_\theta \frac{\partial B}{\partial\zeta} - B_\zeta \frac{\partial B}{\partial\theta_v} \right) \frac{\psi_{LCFS} }{\sqrt{g} }.
\end{align}
To obtain this result we have used
\begin{equation}
\nabla B = \frac{\partial B}{\partial s} \nabla s + \frac{\partial B}{\partial\theta_v} \nabla\theta_v + \frac{\partial B}{\partial\zeta} \nabla\zeta
\label{eq:gradB}
\end{equation}
and
\begin{equation}
\vect{B} = B_s \nabla s + B_\theta \nabla \theta_v + B_\zeta \nabla\zeta.
\label{eq:Bsub}
\end{equation}
The quantity $B_\theta$ is available as the VMEC outputs {\ttfamily bsubumnc} and {\ttfamily bsubumns},
and the quantity $B_\zeta$ is available as the VMEC outputs {\ttfamily bsubvmnc} and {\ttfamily bsubvmns}.

A couple of options are possible for computing $\gbdrift$. One method is to compute the Cartesian components of $\nabla B$ using
(\ref{eq:gradB})
together with (\ref{eq:nabla_s})-(\ref{eq:nabla_theta}). Furthermore, the Cartesian components of $\vect{B}$ can be computed from
\begin{align}
\vect{B} &= \nabla\psi \times \nabla (\theta_v + \Lambda) + \iota \nabla\zeta\times\nabla\psi \nonumber \\
&= \frac{d\psi}{ds} \left[ \left( 1 + \frac{\partial\Lambda}{\partial\theta_v}\right) \nabla s \times\nabla\theta_v
+ \left(\iota - \frac{\partial\Lambda}{\partial\zeta}\right) \nabla\zeta\times\nabla s \right] \nonumber \\
&= \frac{\psi_{LCFS}}{\sqrt{g}} \left[ \left(1 + \frac{\partial\Lambda}{\partial\theta_v}\right) \frac{\partial\vect{r}}{\partial\zeta}
+ \left( \iota - \frac{\partial\Lambda}{\partial\zeta}\right) \frac{\partial\vect{r}}{\partial\theta_v}\right].
\end{align}
Now that Cartesian components of $\vect{B}$, $\nabla B$, and $\nabla \alpha$ are all known, their cross product
needed for $\gbdrift$ is straightforward. Alternatively, $\gbdrift$ can be computed by substituting (\ref{eq:gradB})-(\ref{eq:Bsub}) and (\ref{eq:grad_alpha}) into $\vect{B}\times\nabla B \cdot\nabla\alpha$, yielding
\begin{align}
\vect{B}\times\nabla B \cdot\nabla\alpha
=
\frac{1}{\sqrt{g}} &\left[
B_s \frac{\partial B}{\partial \theta_v} \left(\frac{\partial \Lambda}{\partial\zeta} - \iota \right)
+ B_\theta \frac{\partial B}{\partial\zeta} \left( \frac{\partial\Lambda}{\partial s} - \zeta \frac{d\iota}{ds}\right)
+ B_\zeta \frac{\partial B}{\partial s} \left( 1 + \frac{\partial \Lambda}{\partial \theta_v}\right) \right. \nonumber \\
&\left.-B_\zeta \frac{\partial B}{\partial\theta_v} \left( \frac{\partial\Lambda}{\partial s} - \zeta \frac{d\iota}{ds}\right)
-B_\theta \frac{\partial B}{\partial s} \left( \frac{\partial \Lambda}{\partial\zeta}-\iota\right)
-B_s \frac{\partial B}{\partial\zeta} \left( 1 + \frac{\partial\Lambda}{\partial\theta_v}\right)
\right].
\end{align}

The last quantity we need to evaluate is $\cvdrift$. Using
\begin{align}
\vect{B}\times\vect{\kappa}
&= \vect{B}\times(\vect{b}\cdot\nabla \vect{b})
= \vect{B}\times \left[ (\nabla\times\vect{b}) \times\vect{b}\right] \nonumber \\
&= \vect{B} \times \left[ -\frac{1}{B^2} \left( \nabla B \times\vect{B}\right)\times\vect{b} + \frac{\mu_0}{B^2} \vect{j}\times\vect{B}\right] \nonumber \\
&= \frac{1}{B} \vect{B}\times\nabla B + \frac{\mu_0}{B^2} \frac{dp}{ds} \vect{B}\times\nabla s,
\end{align}
(where we have used the MHD equilibrium equation $\vect{j}\times\vect{B} = \nabla p$), we find
\begin{equation}
\cvdrift = \gbdrift
+ \frac{2 B_{ref} L_{ref}^2}{B^2} \sqrt{\frac{\psi}{\psi_{LCFS}}} \frac{\mu_0}{B^2} \frac{dp}{ds} \vect{B}\times\nabla s \cdot \nabla \alpha.
\end{equation}
In the last term, $\vect{B}\times\nabla s \cdot \nabla \alpha$ can either
be evaluated using the Cartesian components of $\vect{B}$, $\nabla s$, and $\nabla \alpha$,
the calculation of which has already been described,
or by combining (\ref{eq:grad_alpha}) and (\ref{eq:Bsub}) to obtain
\begin{equation}
\vect{B}\times\nabla s \cdot \nabla \alpha
= \frac{1}{\sqrt{g}} \left[
B_\zeta \left( 1  + \frac{\partial\Lambda}{\partial\theta_v}\right)
-B_\theta \left( \frac{\partial\Lambda}{\partial\zeta} - \iota \right) \right].
\end{equation}

\section{Parallel boundary condition and wavenumber quantization for a full surface calculation}

Let us now consider a full-flux-surface calculations, using field-aligned coordinates.
We continue to use $\psi$ and $\alpha$ as perpendicular coordinates, and $\zeta$ as the third (parallel) coordinate.
In a full-flux-surface calculation, the range of $\alpha$ is $[0,\; 2\pi)$,
which can be seen from the fact at fixed $\psi$ and $\zeta$, the $2\pi$-periodicity of quantities in
$\theta_p$ implies $2\pi$-periodicity in $\alpha$.

Just as in a flux tube code, fluctuating quantities such as the electrostatic potential $\phi$ are represented as
\begin{equation}
\phi(\psi,\alpha,\zeta)
=\sum_{k_\psi, k_\alpha} \bar{\phi}_{k_\psi,k_\alpha}(\zeta) \exp\left( i k_\alpha \alpha + i k_\psi \left[ \psi - \psi_0\right] \right).
\label{eq:fluctuations}
\end{equation}
Again, $\psi_0$ indicates the flux surface about which the numerical domain is centered.
The wavenumbers with respect to $(\psi,\alpha)$ are related to wavenumbers with respect to $(x,y)$ through
\begin{align}
\label{eq:k_conversion}
k_x &= k_\psi \frac{d\psi}{dx}, \\
k_y &= k_\alpha \frac{d\alpha}{dy} \nonumber.
\end{align}
Note that $k_\alpha$ ranges over the integers, due to the $2\pi$-periodicity in $\alpha$ discussed above.
The choice of $y$ (\ref{eq:dy_dalpha}) then implies the wavenumber grid in $y$ must be
\begin{equation}
k_y \rho_{ref} = \frac{\rho_{ref}}{L_{ref} \sqrt{s(\psi_0)}} \times (\mathrm{integers}).
\end{equation}
We take fluctuating quantities to be periodic in $\psi$, just as in a flux tube code. The allowed values of $k_\psi$ and associated `box size' in $\psi$
will be derived below.

We take fluctuating quantities to be periodic in $\zeta$ with period $2 \pi P$ at fixed $\psi$ and $\theta_p$.
Here, $P$ is a rational number, typically the inverse of the number of field periods (e.g. 5 for W7-X).
One could also choose $P=1$ to simulate the entire toroidal domain, or choose $P=$ integer / (number of field periods)
for an intermediate domain size. When $P=1$, this periodicity condition is the true periodicity of the torus.
When $P=$ integer / (number of field periods), the periodicity imposed in the code is effectively a statement
of statistical periodicity of the turbulence at geometrically equivalent points in the domain. To see the implications of imposing
periodicity in $\zeta$ at fixed $\theta_p$, we substitute $\alpha = \theta_p - \iota \zeta$ and the Taylor expansion
\begin{equation}
\iota \approx \iota(\psi_0) + \frac{d\iota}{d\psi} \left[ \psi - \psi_0\right]
\label{eq:Taylor_iota}
\end{equation}
into (\ref{eq:fluctuations}). (We take $d\iota/d\psi$ to be evaluated at $\psi_0$, and hence constant over the domain.) The result is
\begin{equation}
\phi
=\sum_{k_\psi, k_\alpha} \bar{\phi}_{k_\psi,k_\alpha}(\zeta) \exp
\left( i k_\alpha \theta_p
-i k_\alpha \iota(\psi_0) \zeta
+i \left[- k_\alpha \frac{d\iota}{d\psi}  \zeta
 + k_\psi\right] \left[ \psi - \psi_0\right] \right).
\end{equation}
When a particular $(k_\psi,k_\alpha)$ Fourier mode gets to the end of the $\zeta$ domain ($\zeta = 2\pi P$), we want
the mode to connect exactly to another Fourier mode in the simulation $(k'_\psi,k'_\alpha)$, with the latter evaluated
at $\zeta=0$. Mathematically, this condition is
\begin{align}
&\bar{\phi}_{k_\psi,k_\alpha}(2\pi P) \exp
\left( i k_\alpha \theta_p
-i k_\alpha \iota(\psi_0) 2\pi P
+i \left[- k_\alpha \frac{d\iota}{d\psi}  2 \pi P
+ k_\psi\right] \left[ \psi - \psi_0\right] \right) \nonumber \\
&=
\bar{\phi}_{k'_\psi,k'_\alpha}(0) \exp
\left( i k'_\alpha \theta_p
+i k'_\psi\left[ \psi - \psi_0\right] \right) .
\label{eq:parallelBC}
\end{align}
For this equation to hold for all $\theta_p$ at fixed $\psi$, we must have $k'_\alpha = k_\alpha$.
For equality to hold for all $\psi$ at fixed $\theta_p$, we must have
\begin{equation}
k'_\psi
= k_\psi - k_\alpha \frac{d\iota}{d\psi}  2 \pi P.
\label{eq:twist_and_shift}
\end{equation}
This last result is analogous to the twist-and-shift condition used in flux-tube GS2.
If $k'_\psi$ is to be included in the wavenumber grid, and assuming the $k_\psi$ grid consists of integer multiples of some
$k_{\psi,min}$, then the difference $k'_\psi - k_\psi$ should
be an integer multiple of $k_{\psi,min}$.
In particular this must be true for the smallest nonzero $k_\alpha$, which is 1.
Thus, we conclude
\begin{equation}
\frac{d\iota}{d\psi} 2\pi P = (\jtwist) k_{\psi,min}
\end{equation}
where $\jtwist$ is an integer. It follows that the `box size' in $\psi$, denoted $L_\psi$, is
\begin{equation}
L_\psi = \frac{2\pi}{k_{\psi,min}} =
\frac{(\jtwist)}{P} \left( \frac{d\iota}{d\psi} \right)^{-1}.
\end{equation}
Using (\ref{eq:k_conversion}) and (\ref{eq:psi_x_conversion}), the equivalent box size in $x$ is
\begin{equation}
L_x = \frac{dx}{d\psi} L_\psi = \frac{2\pi}{k_{x,min}} =
\frac{(\jtwist)}{ P L_{ref} B_{ref} \sqrt{s}} \left( \frac{d\iota}{d\psi} \right)^{-1}.
\label{eq:Lx}
\end{equation}
Unfortunately, in low-shear stellarators like W7-X and HSX, $d \iota/d\psi$ in
(\ref{eq:Lx}) can be quite small, meaning $L_x$ must be quite large.

Equation (\ref{eq:parallelBC}) also indicates there should be a phase shift when two Fourier modes
are connected:
\begin{equation}
\bar{\phi}_{k_\psi,k_\alpha}(2\pi P) \exp
\left( -i k_\alpha \iota(\psi_0) 2\pi P \right)
=
\bar{\phi}_{k'_\psi,k_\alpha}(0).
\label{eq:phase}
\end{equation}

\subsection{Continuity of geometric quantities}

%It is interesting to check whether
We can verify that various terms in the gyrokinetic equation are continuous
% when a Fourier mode is followed
across the parallel boundary condition. First, let us consider the magnetic drift term:
\begin{align}
\vect{v}_{m}\cdot \nabla h
&= \vect{v}_{m} \cdot \nabla \left[
\sum_{k_\psi,k_\alpha} \bar{h}_{k_\psi,k_\alpha}(\zeta) \exp \left( i k_\alpha \alpha + i k_\psi [\psi - \psi_0] \right) \right] \nonumber \\
&\approx
\sum_{k_\psi,k_\alpha} \bar{h}_{k_\psi,k_\alpha}(\zeta)
\exp \left( i k_\alpha \alpha + i k_\psi [\psi - \psi_0] \right)
\left[ i k_\alpha \vect{v}_{m}\cdot \nabla \alpha + i k_\psi \vect{v}_{m}\cdot\nabla\psi \right] \nonumber \\
& =
\sum_{k_\psi,k_\alpha} \bar{h}_{k_\psi,k_\alpha}(\zeta)
\exp \left( i k_\alpha [\theta_p - \iota \zeta] + i k_\psi [\psi - \psi_0] \right) \nonumber \\
& \hspace{1in}\times \left[ i k_\alpha \vect{v}_{m}\cdot \left(\nabla \theta_p - \iota \nabla\zeta - \zeta \frac{d\iota}{d\psi} \nabla\psi \right) + i k_\psi \vect{v}_{m}\cdot\nabla\psi \right],
\label{eq:grad_B_drift_term}
\end{align}
where $h$ is the nonadiabatic distribution function. (The $\approx$ above comes from dropping the slow $\zeta$ dependence of $\bar{h}_{k_\psi,\zeta}$
in the gradient.) As $\zeta$ is increased, just before the boundary $\zeta = 2\pi P$ we have
\begin{align}
\left( \vect{v}_{m}\cdot \nabla h \right)_-
& =
\sum_{k_\psi,k_\alpha} \bar{h}_{k_\psi,k_\alpha}(2\pi P)
\exp \left( i k_\alpha [\theta_p - \iota 2\pi P] + i k_\psi [\psi - \psi_0] \right) \nonumber \\
& \hspace{1in}\times \left[ i k_\alpha \vect{v}_{m}\cdot \left(\nabla \theta_p - \iota \nabla\zeta - 2\pi P \frac{d\iota}{d\psi} \nabla\psi \right) + i k_\psi \vect{v}_{m}\cdot\nabla\psi \right].
\label{eq:v_B_term_minus}
\end{align}
The subscript on the left hand side indicates that we have evaluated the result just to the left of the boundary.
On the other side of the boundary ($\zeta = 0$), (\ref{eq:grad_B_drift_term}) evaluates to
\begin{equation}
\left(\vect{v}_{m}\cdot \nabla h \right)_+
=
\sum_{k_\psi,k_\alpha} \bar{h}_{k'_\psi,k_\alpha}(0)
\exp \left( i k_\alpha \theta_p  + i k'_\psi [\psi - \psi_0] \right)
\left[ i k_\alpha \vect{v}_{m}\cdot \left(\nabla \theta_p - \iota \nabla\zeta \right) + i k'_\psi \vect{v}_{m}\cdot\nabla\psi \right].
\end{equation}
In this last equation, we were free to put primes on $k_\psi$ because it is summed over. Applying
(\ref{eq:twist_and_shift}) and (\ref{eq:phase}),
\begin{align}
\left(\vect{v}_{m}\cdot \nabla h \right)_+
=&
\sum_{k_\psi,k_\alpha} \bar{h}_{k_\psi,k_\alpha}(2\pi P)
\exp \left( i k_\alpha \theta_p   -i k_\alpha \iota(\psi_0) 2\pi P+ i \left[ k_\psi - k_\alpha \frac{d\iota}{d\psi}  2 \pi P\right] [\psi - \psi_0] \right) \nonumber \\
& \hspace{1in} \times \left[ i k_\alpha \vect{v}_{m}\cdot \left(\nabla \theta_p - \iota \nabla\zeta \right) + i \left[ k_\psi - k_\alpha \frac{d\iota}{d\psi}  2 \pi P\right] \vect{v}_{m}\cdot\nabla\psi \right].
\label{eq:v_B_term_plus}
\end{align}
Using (\ref{eq:Taylor_iota}), it can be seen that (\ref{eq:v_B_term_minus}) is identical to  (\ref{eq:v_B_term_plus}),
so the magnetic drift term is indeed continuous across the boundary.

\todo{Also show continuity for $\langle \phi \rangle_R$...}

\begin{comment}

perpendicular wavenumber appearing inside the Bessel functions:
\begin{equation}
k_{\perp}^2 = k_\alpha^2 |\nabla \alpha|^2 + 2 k_\alpha k_\psi \nabla\alpha\times\nabla\psi + k_\psi^2 |\nabla\psi|^2.
\label{eq:kperp2}
\end{equation}
Using
\begin{equation}
\nabla\alpha = \nabla\theta_p - \iota \nabla\zeta - \zeta \frac{d\iota}{d\psi} \nabla\psi,
\end{equation}
we find that (\ref{eq:kperp2})

\end{comment}

\end{document}