\section{Trim Analysis}
This section details the computation of ``trim'' (steady flight) configurations, in which the vehicle acceleration components along body axes are zero and the rotor response is periodic and briefly describes the pseudo-code used to include the free-vortex wake during trim.

The ODEs of interest are strongly coupled to each other,  especially for the rotor dynamics. Explicit expressions for the accelerations (second time derivatives of displacements) as a function of forcing and velocities are lengthy and cumbersome to manipulate. One way to simplify the beam equations is to make small-angle assumptions and use an ordering scheme (Ref. \cite{Datta}), which then restricts the validity of the analysis to small angles. Alternately, it is possible to use the original form of the governing ODEs
\begin{equation}
\label{eqn:allodes}
\vector{f}(\dot{\vector{y}}, \textrm{ } \vector{y},\textrm{ } \vector{u},\textrm{ } t\textrm{ } ) \quad = \quad \overline{\boldsymbol\epsilon} \quad = \quad \vector{0}
\end{equation}
with a \emph{class} of techniques that, given an initial guess $\vector{y}_0(t)$, obtain a solution $\vector{y}(t)$ such that $e(\overline{\boldsymbol\epsilon}) < \delta$, where $e(\overline{\boldsymbol\epsilon})$ is an error metric and $\delta$ is a user-specified threshold that is used to terminate the solution process to required numerical precision. Thus, the task of simulating vehicle dynamics is simplified to that of programming the logic for computing \emph{numerical} values of $\overline{\boldsymbol\epsilon}$ for a given $\vector{y}, \dot{\vector{y}}, \vector{u}$ and leveraging open-source subprograms from NETLIB for obtaining trim solutions and simulating maneuvering flight (Ref. \cite{CeliSoln}).

\subsection{\textbf{Definition of Trim}}
The term ``trim'' is used to refer to a steady flight condition in which the translational and angular acceleration components along and about the body axes are zero. Therefore, trim includes steady level flight, steady climbing flight, steady level turns and steady climbing/descending turns of constant radii. The concept of rotorcraft trim evolved from the corresponding definition for fixed-wing platforms, and so it is useful to define aircraft trim first.

\subsubsection{Aircraft Trim}
Trim for a fixed-wind aircraft is defined as a steady flight condition in which the control settings, orientations and velocity of the vehicle produce forces (inertial and aerodynamic) that exactly cancel out contibutions from gravity and buoyancy, thus allowing the aircraft to remain in its state of rest or uniform motion `` indefinitely ". The force distributions on a fixed-wing aircraft in trim are steady, hence the aerodynamic and inertial loads at any two instants in time will be near-identical. There may still be fluctuations in these loads at extremely high frequencies (determined by the RPMs of the various rotors inside the engine), but the amplitudes of these fluctuations are so small that their effect on aircraft trim is negligible.\\
Unlike a fixed wing, the aerodynamic and inertial loads generated by each rotor blade are not steady. In forward flight, rotor blades experience time-varying dynamic pressures and operating angles of attack, and therefore undergoes unsteady motion in response to these time-varying force and moment distributions along the span. These unsteady motions result in time-varying inertial blade loads in addition to the fluctuating aerodynamic loads, hence the forces transmitted to the airframe are vibratory in nature. With these considerations, rotor trim can be defined.

\subsubsection{Rotor trim}
When the controls for a rotor (collective and cyclic pitch inputs) are held constant, the rotor is said to be trimmed if the blade response is periodic, i.e. it has reached steady-state, and the forces and moments, when averaged over this period, do not change over successive cycles. Often, the time period is assumed to be that reqiured for one rotor revolution, due to the cyclic variation of the free-stream velocities as seen by the blade and the kinematics of the pitch control system.

\subsubsection{Rotorcraft Trim}
Just as fixed-wing trim is not significantly affect by engine vibrations, it is assumed that, for the purposes of enforcing body force and moment equilibrium, rotorcraft trim is insensitive to the \emph{oscillatory} forces and moments transmitted to the hub. Instead, the \emph{time-averaged} forces and moments will be used to represent the contributions from rotor loads to Eqs. (\ref{eqn:bodyF1}) - (\ref{eqn:bodyM3}). This assumption is justified since the vibratory loads manifest at sufficiently large frequencies that the airframe response is negligible and the vehicle trim state is unaffected (Ref. \cite{Kim}). When the blade motion is periodic \emph{and} the time-averaged forces and moments generated by the rotor are sufficient for establishing vehicle force and moment equilibrium, the system is said to be in \emph{coupled trim} or \emph{propulsive trim}.

The most general case of trim considered is a steady coordinated helical climbing turn of constant radius (Ref. \cite{CeliTurn}). This flight condition is defined by three parameters : the flight speed $V$, the flight path angle $\gamma$ (positive for climb) and the turn rate $\dot{\psi}$ (positive for nose-right turns). Using this definition,
\begin{itemize}
\item Steady level turning flight is a special case in which $\gamma$ = 0 (constant altitude)
\item Steady climbing flight is a special case in which $\dot{\psi}$ = 0
\item Steady level forward flight is a special case in which $\gamma$ = 0 and $\dot{\psi}$ = 0
\item Hover is a special case in which $\gamma$ = 0, $V$ = 0 and $\dot{\psi}$ = 0
\end{itemize}
Mathematically, trim is enforced by imposing additional conditions on the govering ODE set Eq. (\ref{eqn:allodes}). For the rotorcraft trim problem, the differential equations reduce to nonlinear algebraic equations that may be represented as
\begin{equation}
\label{eqn:allAE}
\vector{F}(\vector{X}) \quad = \quad \overline{\boldsymbol\epsilon}_\textrm{trim} \quad = \quad \vector{0}
\end{equation}
The problem of trim is then converted to solving a set of algebraic equations for the so-called \emph{trim unknowns}. The trim unknowns include the rotor response, vehicle attitudes, rotor induced inflow ratios and the pilot controls. Solution of the trim equations is achieved by manipulation of the trim variables $\vector{X}$ using a numerical solver (Ref. \cite{HYBRD}) until an error metric e($\rvert\overline{\boldsymbol\epsilon}\rvert_\textrm{trim}$) falls below a user-specified threshold $\delta_\textrm{trim}$. To avoid formulating an over-determined or under-determined system of equations, the number of trim variables $\vector{X}$ must be equal to the number of trim equations $\vector{F}$. The trim equations and corresponding trim variables are given in the following section. The trim solver is called \textbf{hybrd}, a NETLIB subroutine from the package \textbf{MINPACK}. The wrappers used for various types of trim are
\begin{itemize}
\item \textbf{AEResiduals} : simultaneous vehicle-rotor trim with harmonic balance
\item \textbf{AEResFET} : vehicle trim with numerical FET
\item \textbf{AEResRotorResponse} : obtain rotor response with fixed controls
\item \textbf{AEResQddot} : obtain blade accelerations for fixed controls and response
\item \textbf{AEResAirframe} : obtain airframe vibratory response
\end{itemize}

The programming logic for all these cases is common, i.e. the calculation of the ODE residuals is unchanged. It is only the manipulation of these residuals that is unique to each of these adapters that \textbf{numerically convert the governing ODEs to algebraic (trim) equations}.
\subsection{\textbf{Trim Equations and Trim Variables}}
\begin{itemize}
\item \textbf{The components of time-averaged fuselage translational and rotational accelerations along and about the body axes must be zero}, as given in Eqs. (\ref{eqn:bodyF1}) - (\ref{eqn:bodyM3}). Using `` T '' to represent time period for one rotor revolution, the first six trim equations are
\begin{eqnarray}
\label{eqn:vehicleeqm1}
\int_0^{T} \dot{u}_{_\textrm{F }} dt \quad = \quad \epsilon_{_\textrm{RB1}} \quad = \quad 0 \\
\int_0^{T} \dot{v}_{_\textrm{F }} dt \quad = \quad \epsilon_{_\textrm{RB2}} \quad = \quad 0 \\
\int_0^{T} \dot{w}_{_\textrm{F }} dt \quad = \quad \epsilon_{_\textrm{RB3}} \quad = \quad 0 \\
\int_0^{T} \dot{p}_{_\textrm{F }} dt \quad = \quad \epsilon_{_\textrm{RB4}} \quad = \quad 0 \\
\int_0^{T} \dot{q}_{_\textrm{F }} dt \quad = \quad \epsilon_{_\textrm{RB5}} \quad = \quad 0 \\
\label{eqn:vehicleeqm2}
\int_0^{T} \dot{r}_{_\textrm{F }} dt \quad = \quad \epsilon_{_\textrm{RB6}} \quad = \quad 0
\end{eqnarray}
Equations (\ref{eqn:vehicleeqm1}) - (\ref{eqn:vehicleeqm2}) constitute the six trim conditions that enforce vehicle force and moment equilibrium under steady flight conditions. The corresponding trim variables are the pilot controls ($\delta_0$, $\delta_\textrm{lat}$, $\delta_\textrm{lon}$, $\delta_\textrm{ped}$) and the fuselage pitch and roll attitudes ($\phi_{_\textrm{F}}$, $\theta_{_\textrm{F}}$). The last two trim variables are indirect controls, in the sense that they cannot be immediately adjusted by the pilot. Instead, the vehicle has to be \emph{flown into} these orientations using the four direct controls that influence the lift distributions over the rotor disks. The trim equation residuals for the airframe are set in \textbf{update\_airframe\_AEResiduals}.

\item \textbf{The rotor must be trimmed}, i.e. the motions of all blades must be individually periodic. Since we assume that all blades are identical, it follows that \textbf{all blades must exhibit identical motions} with phase offsets corresponding to their relative azimuthal spacing. Therefore, the problem of obtaining the motion of all blades of a particular rotor is simplified to that of obtaining the motion of a reference blade. Without loss of generality, the first blade is chosen to be the reference blade.

A further assumption is made at this stage to simplify the analysis - that the resulting periodic blade motion is well-represented using a Fourier series in integer multiples of the rotor frequency $\Omega$. This method is often called \emph{harmonic balance}, and can capture the dominant blade motions (with regard to flight dynamics) using the first few harmonics. \textbf{A Galerkin method with harmonic balance is used to obtain the time-resolution of the rotating blade modes}. The generalized coordinates of a blade at azimuth $\psi$ can be approximated to
\begin{equation}
\label{eqn:qharm}
\grkvec{\eta}_{j}(\psi) \quad \approx \quad \grkvec{\eta}_0 \quad + \quad \sum_{k=1}^\textrm{Nh} \left(\grkvec{\eta}_\textrm{kc} \textrm{ } \cos k\psi \quad + \quad \grkvec{\eta}_\textrm{ks} \textrm{ } \sin k\psi \right)
\end{equation}
$\grkvec{\eta}_0$ represents the steady part of the generalized coordinates, and the amplitudes of the sine and cosine components for the \mbox{`` $k^\textrm{th}$ ''} harmonic are \mbox{($\grkvec{\eta}_{kc}$ , $\grkvec{\eta}_{ks}$)}.
The N$_\textrm{m}$(1+2 N$_\textrm{h}$) Fourier coefficients are the trim variables that define the rotor blade motions with respect to the undeformed rotating preconed axes. These Fourier coefficients are used to compute the blade deflections which are substituted into the beam equations, to yield the mode-weighted ODE residuals
\begin{equation}
\overline{\boldsymbol\epsilon}_\textrm{blade 1} \quad = \quad \vector{f}_\textrm{beam} (\vector{y}_1, \textrm{ }\dot{\vector{y}}_1, \textrm{ } \vector{u}, \textrm{ }t)
\end{equation}
Here, $\vector{f}_\textrm{beam}$ represents the ODEs governing rotating beam dynamics, i.e. the mode-weighted flap, lag and torsion equations. $\vector{y}_1$ represents a subset of the state vector that contains the 12 rigid-body fuselage states and the generalized coordinates (together with their first time derivatives) for the reference blade. Since we are using Galerkin's method, the corresponding trim equations are obtained by weighting the beam equations with the azimuthal shape functions and integrating over one revolution. The algebraic equation residuals corresponding to the steady, cosine and sine components of blade motions are
\begin{align}
\grkvec{\epsilon}_\textrm{steady} \quad = \quad &\int_{0}^T \grkvec{\epsilon}_\textrm{blade 1} (t) \qquad \qquad \quad \textrm{ } dt\\
\grkvec{\epsilon}_\textrm{cos,k} \quad = \quad &\int_{0}^T \grkvec{\epsilon}_\textrm{blade 1} (t) \quad \cos k \Omega t \quad dt\\
\grkvec{\epsilon}_\textrm{sin,k} \quad = \quad &\int_{0}^T \grkvec{\epsilon}_\textrm{blade 1} (t) \quad \sin k \Omega t \quad dt
\end{align}
These residuals are computed in \textbf{update\_rotor\_AEResiduals}.
\item \textbf{The components of helicopter linear, angular velocities along fuselage body axes, and roll and pitch attitudes must be time-invariant} \\
For trimmed flight, the vehicle must move at constant speed V. The orientation of the free-stream velocity vector relative to the airframe can be described using the spherical angles $\alpha_{_\textrm{F}}$ and $\beta_{_\textrm{F}}$ as defined in Eq. (\ref{eqn:fusab}). The translation velocity components along helicopter body axes are
\begin{equation}
\label{eqn:uvwf}
\left.
\begin{aligned}
u_{_\textrm{F}} \quad = \quad &\textrm{V} \textrm{ }\cos \alpha_{_\textrm{F}} \cos \beta_{_\textrm{F}} \\
v_{_\textrm{F}} \quad = \quad &\textrm{V} \textrm{ }\sin \beta_{_\textrm{F}} \\
w_{_\textrm{F}} \quad = \quad &\textrm{V} \textrm{ }\sin \alpha_{_\textrm{F}} \cos \beta_{_\textrm{F}} \qquad \qquad
\end{aligned}
\right\}
\end{equation}
The rigid-body trim variables are converted to states in \textbf{interpret\_trim\_variables}, and the rotor trim variables are converted to states in \textbf{interpret\_rotor\_trimvars}.

The helicopter yaw rate $\dot{\psi}_{_\textrm{F}}$ must be constant and the Euler pitch and roll attitudes must be time-invariant. Applying these conditions to Eqs. (\ref{eqn:pqrf}), the angular velocity components along body axes are obtained as
\begin{equation}
\label{eqn:angturn}
\left.
\begin{aligned}
p_{_\textrm{F}} \quad = & -\dot{\psi}_{_\textrm{F}} \sin \theta_{_\textrm{F}} \qquad \\
q_{_\textrm{F}} \quad = &\quad \dot{\psi}_{_\textrm{F}} \cos \theta_{_\textrm{F}} \sin \phi_{_\textrm{F}} \qquad  \\
r_{_\textrm{F}} \quad = &\quad \dot{\psi}_{_\textrm{F}} \cos \theta_{_\textrm{F}} \cos \phi_{_\textrm{F}} \quad \qquad \quad
\end{aligned}
\right\}
\end{equation}
At low forward speeds, the reduced dynamic pressure on the vertical stabilizer renders it ineffective for producing anti-torque. Therefore, \textbf{below a certain threshold airspeed, the helicopter is constrained to fly with zero sideslip angle}, i.e.
\[ \beta_{_\textrm{F}} \quad = \quad 0 \]
\textbf{Above the threshold airspeed, all turns must be coordinated} to increase ride comfort and reduce the danger of entering a spin. Mathematically, turn coordination is enforced by setting the cumulative component of inertial and gravitational forces along the $\ihat{j}_{_\textrm{B}}$ direction to zero. Substituting Eqs. (\ref{eqn:uvwf}) and Eqs. (\ref{eqn:angturn}) in Eq. (\ref{eqn:bodyF2}) yields the residual of the turn coordination equation as
\begin{equation}
\label{eqn:turncoord}
\epsilon_\textrm{coord} \quad = \quad \textrm{V} \dot{\psi}_{_\textrm{F}} \cos \beta_{_\textrm{F}} (\cos \alpha_{_\textrm{F}} \cos \theta_{_\textrm{F}} \cos \phi_{_\textrm{F}} \textrm{ }+\textrm{ } \sin \theta_{_\textrm{F}} \sin \alpha_{_\textrm{F}}) - g \sin \phi_{_\textrm{F}} \cos \theta_{_\textrm{F}}
\end{equation}
Another kinematic relationship exists between the climb angle $\gamma$, the Euler angles ($\psi$, $\theta$, $\phi$)$_{_\textrm{F}}$  and the wind angles ($\alpha$, $\beta$)$_{_\textrm{F}}$. To determine this relationship, consider the velocity components of the helicopter along fuselage body axes, as given in Eqs. (\ref{eqn:uvwf}). The velocity components along the earth-fixed axes can be obtained using the rotation matrix from body axes to gravity axes as
\begin{equation}
\begin{Bmatrix} \dot{\textrm{x}}_{_\textrm{F}} \\\dot{\textrm{y}}_{_\textrm{F}} \\ \dot{\textrm{z}}_{_\textrm{F}} \end{Bmatrix} \quad = \quad \tee_{GB} \begin{Bmatrix} u_{_\textrm{F}} \\ v_{_\textrm{F}} \\ w_{_\textrm{F}} \end{Bmatrix}
\end{equation}
The component along $\ihat{k}_{_\textrm{G}}$ is given by the third row of the right hand side. By definition, the same velocity component is equal to
\[ \dot{\textrm{z}}_{_\textrm{F}} \quad = \quad -V \sin \gamma\]
The negative sign accounts for the fact that $\ihat{k}_{_\textrm{G}}$ points downward and a positive $\gamma$ indicates a steady increase in altitude. \textbf{The equation of flight path} can be obtained by comparing the two expressions for $\dot{\textrm{z}}_{_\textrm{F}}$ above, and dividing by the velocity magnitude V. The residual of this trim equation is
\begin{equation}
\label{eqn:fp}
\left.
\begin{aligned}
\epsilon_{_\textrm{FP}} \quad = \quad & \cos \alpha_{_\textrm{F}} \cos \beta_{_\textrm{F}} \sin \theta_{_\textrm{F}} \quad - \quad \sin \gamma_{_\textrm{F}} \\
- & \cos \theta_{_\textrm{F}}(\sin \beta_{_\textrm{F}} \sin \phi_{_\textrm{F}} \textrm{ + } \sin \alpha_{_\textrm{F}} \cos \beta_{_\textrm{F}} \cos \phi_{_\textrm{F}}) \qquad \qquad
\end{aligned}
\right\}
\end{equation}
The trim variables corresponding to the turn coordination and flight path equations are ($\alpha_{_\textrm{F}}$, $\beta_{_\textrm{F}}$). Perfect hover with identically zero forward speed is simulated by replacing the flight path equation with
\begin{equation*}
\epsilon_{_\textrm{FP}} \quad = \quad \alpha_{_\textrm{F}} \qquad \qquad \textbf{\textrm{at hover}}
\end{equation*}
The kinematic consistency equations are computed in the routine \textbf{FPTCRes}.
\item \textbf{The inflow ratios are time-invariant} when averaged over one revolution of the main rotor. The corresponding trim equation residuals are
\begin{align*}
\epsilon_{\lambda_{TR}} \quad = \quad &\int_0^T \dot{\lambda}_{_\textrm{TR}} \textrm{ }dt \\
\epsilon_{\lambda_{0,MR}} \quad = \quad &\int_0^T \dot{\lambda}_{0_\textrm{MR}} \textrm{ }dt \\
\epsilon_{\lambda_{1c,MR}} \quad = \quad &\int_0^T \dot{\lambda}_{\textrm{1c}_\textrm{MR}} \textrm{ }dt \\
\epsilon_{\lambda_{1s,MR}} \quad = \quad &\int_0^T \dot{\lambda}_{\textrm{1s}_\textrm{MR}} \textrm{ }dt
\end{align*}
\end{itemize}
The ODEs governing the inflow dynamics are converted to trim equations in the routine \textbf{update\_inflow\_AEResiduals}.
\subsection{\textbf{Free-Vortex Wake Model in Trim}}
When the free wake model is used in trim, all the trim conditions given in the previous sections are enforced. The main rotor inflow equations are initially used to generate a starting guess for the trim controls, rotor response and fuselage orientations. Once trim is achieved with dynamic inflow, the main rotor inflow equations are removed from the trim equations and a `` loose-coupling '' procedure is used to periodically exchange information over one rotor revolution between the aerodynamics and rotor/flight dynamics. Reference \cite{Alfred} provides details on the loose-coupling trim procedure, and a brief summary is given here for completeness.

\begin{enumerate}
\item With the trim controls, fuselage velocity and blade motions from the previous iteration, the free wake solution is marched forward in time until the L1 norm of the inflow over the rotor disk reduces below a threshold value $\delta_\textrm{inflow}$. This operation is performed by the routine \textbf{converge\_wake\_inflow}.
\item The inflow distribution over the rotor disk is computed from the converged free wake geometry and frozen. This step is performed by the routine \textbf{rindvt} (wake folder).
\item Using this \textit{frozen} inflow distribution, the trim procedure is applied a solution for simultaneous vehicle equilibrium and rotor response periodicity. Once trim is achieved with the inflow distribution from step 2, the structural/flight dynamics are \emph{frozen}. This procedure is performed by the routine \textbf{AESolver}.
\item Steps 1-3 are repeatedly performed until the L1 norm of trim variables (excluding 2/rev and higher rotor harmonics) reduce below a threshold $\delta_{_\textrm{TV}}$. This operation is controlled by the routine \textbf{iterative\_trim}.
\end{enumerate}

\subsection{\textbf{Galerkin vs. Rayleigh-Ritz, FET vs. Harmonic Balance}}
There are two key differences between \textbf{UMARC} and \textbf{HeliUM}.
\begin{itemize}
\item \textbf{The first difference is the time resolution of the rotor modes}. While HeliUM uses harmonic balance to obtain simultaneous rotor-vehicle trim, \textbf{UMARC} uses a Finite Element in Time method, using local polynomials to express the time-variation of blade motion. This choice of time shape function (trigonometric vs. Lagrangian interpolation polynomials) implies that blade inertial loads are computed differently in the two codes, and each method exhibits its own strengths and deficiencies. For example, Lagrangian time shape functions yield necessarily discontinuous accelerations across time nodes, while harmonic balance \textit{forces} continuity in displacement, velocity and acceleration. The validity of harmonic balance comes into question when there is impulsive loading on the blade at moderate advance ratios due to dynamic stall or advancing blade compressibility.
\item \textbf{The second key difference is the technique used to manipulate the rotor dynamics and recast the equations into a solvable form.} The choice of a semi-implicit (partially numerical) formulation of the beam equations in \textbf{HeliUM} allows for using a state-space representation throughout the analysis, which eliminates duplication in programming. However, the dynamics are ``hidden'' in the numbers, which are generated only during run-time. For beginners, the subtleties in the trim process, i.e. a numerical reduction of the governing ODEs to algebraic equations is not immediately obvious. The biggest advantage of this approach is the sheer power and flexibility afforded to the developer in terms of adding features in a modular fashion. In \textbf{UMARC}, the analytically derived rotating beam equations of motion are recast into a linearized form with select Taylor-series expansions about zero deflection. This formulation is easier to grasp, since terms like acceleration and Coriolis force appear explicitly in the equations of motion. This ``explicitness'' is numerically more efficient to implement, since it replaces sines and cosines with polynomial approximations. However, adding additional physical effects (e.g. time-varying RPM fluctuations, hub angular velocities/accelerations, free-stream flow velocity acceleration) requires re-derivation of parts of the analysis, and the lead time for expanding program capabilities is considerable. The art of cherry-picking cross-couplings in flap, lag and torsion based on an ordering scheme quickly balloons into an exercise in superhuman book-keeping, and is extremely error-prone. Further, programming these long expressions (the physical origins of which are lost in the reduction of sines and cosines to polynomials) does not leave a clean trail of code to follow.
\end{itemize}

In this section, I describe how to combine the best of both worlds - i.e. preserve the modularity of a state-space representation with large deflections, while simultaneously obtaining accurate inertial loads using Finite Element in Time, using a modification of the \textbf{UMARC} trim process.

\subsection{\textbf{Conventional trim process for rotors}}
\textbf{Disclaimer}: I have skipped the non-essential steps in an attempt to be concise. Wherever possible, higher spatial and time derivatives must be eliminated using integration by parts. Using a simple example of a rotor blade undergoing elastic flap deflections, the \textbf{UMARC} rotor trim process is explained here. The rotor blade is modeled as a rotating Euler-Bernoulli beam, with its flap dynamics governed by the PDE
\begin{equation}
\left( EI w''\right)'' \spc + \spc m\ddot{w} \spc - \spc \left(T w'\right)' \quad = \quad f_z(w, \dot{w}, \theta_\textrm{con}, t)
\end{equation}
The blade deflections are split into a space-dependent and time-dependent part, assuming separation of variables of the form
\begin{equation}
w(x,t) \quad = \quad \sum q_j(t) \spc V_i(x)
\end{equation}
The aim of rotor trim is to find the rotor motions $w(x,t)$ such that the governing PDE is satisfied \textit{not at every point on the beam}, but instead in an \textit{approximate} sense (see Sections \ref{sec:galerkin} and \ref{sec:modes}). (While \textbf{UMARC} uses a Rayleigh-Ritz forumation to obtain the blade governing equations, a Galerkin method yields identical results for the same trial functions) Thus, the aim is to satisfy the following \textit{ODEs}
\begin{equation}
\int_0^L \left[\spc \left( EI w''\right)'' \spc + \spc m\ddot{w} \spc - \spc \left(T w'\right)' \spc \right] \phi_i(x) dx \quad = \quad \int_0^L f_z \spc \phi_i(x) dx
\end{equation}
There are as many ODEs as there are weighting functions $\phi_i$. The right hand side of the \textit{weak} formulation is the external loading (aerodynamics). Since the aerodynamic loads depend on blade motion velocities, there are ``hidden'' dependencies of $f_z$ on $w, \dot{w}$ and $\ddot{w}$. To solve for $w$ ``analytically'', these dependencies are ``exposed'' using analytical Taylor-series expansions for $f_z$ as
\begin{equation}
f_z \quad = \quad f_0 \spc + \spc + \frac{df}{dw} (w - w_0) \spc + \spc \frac{df}{d\dot{w}} (\dot{w} - \dot{w}_0) \spc + \spc \cdots
\end{equation}
Applying separation of variables, the weak formulation can be written as a spring-mass-damper type second-order ODE, given by
\begin{equation}
\vector{M} \ddot{\vector{q}} \spc + \spc \vector{C} \dot{\vector{q}} \spc + \spc \vector{K} \vector{q} \quad = \quad \vector{F}_0(t) \spc + \spc \vector{F}_\textrm{non-lin}(t)
\end{equation}
The terms \textbf{F}$_0(t)$ is dependent only on control inputs, and \textbf{F}$_\textrm{non-lin}(t)$ contains the ``higher-order terms'' resulting from the Taylor-series expansion. The mass and stiffness matrices depend only on blade properties, and can be used to perform modal reduction (Section \ref{sec:modes}) to yield the modal equations
\begin{equation}
\left[\overline{\vector{M}}\right] \ddot{\grkvec\eta} \spc + \spc \left[\overline{\vector{C}}\right] \dot{\grkvec\eta} \spc + \spc \left[\overline{\vector{K}}\right] \grkvec\eta \quad = \quad \overline{\vector{F}}(t)
\end{equation}
Here, $\left[\overline{\spc}\right]$ represents a modal matrix, obtained from the \textit{nodal} matrices using the transformation
\begin{equation}
\left[\vector{modal}\right] \quad = \quad \vector{V}^\textrm{T} \spc \left[\vector{nodal}\right] \spc \vector{V}
\end{equation}
Here, $\vector{V}$ represents a matrix of eigenvectors.

Using these finite numbers of ODEs, an approximate solution is applied again to obtain the time resolution of the rotor modes $\grkvec\eta$. Instead of solving the modal equations for \textit{each} point in time, the time history of rotor modes over one revolution (in rotor trim) is expanded as a linear combination of trial functions as
\begin{equation}
\grkvec\eta(t) \quad = \quad \sum H_j(t) \grkvec\xi_j
\end{equation}
The approximate solution is obtained by satisfying the following condition
\begin{equation}
\left[ \int_0^T \vector{H}^\textrm{T} \left( \left[\overline{\vector{M}}\right] \ddot{\vector{H}} \spc + \spc \left[\overline{\vector{C}}\right] \dot{\vector{H}} \spc + \spc \left[\overline{\vector{K}}\right] \vector{H} \right) \spc dt \right] \grkvec\xi \quad = \quad \int_0^T \vector{H}^\textrm{T} \spc \overline{\vector{F}} \spc dt
\end{equation}
The coefficient matrix on the left hand side that multiplies $\grkvec\xi$ is evaluated numerically from the modal mass, damping and stiffness matrices, since the non-linearities are packaged into locally-linearized additions to the left hand side. The right hand side is also evaluated numerically from the control inputs and rotor operating condition, and a system of linear equations is solved to obtain the time shape function coefficients of the rotor modes. Since the blade accelerations are discontinuous when using finite elements in time with Lagrangian or Hermitian shape functions, they are instead obtained by inverting the modal equations, i.e.
\begin{equation}
\ddot{\grkvec\eta} \quad = \quad \left[\overline{\vector{M}}\right]^{-1} \left( \spc \overline{\vector{F}}(t) \spc - \spc \left[\overline{\vector{C}}\right] \dot{\grkvec\eta} \spc - \spc \left[\overline{\vector{K}}\right] \grkvec\eta \spc \right)
\end{equation}
To recap,
\begin{itemize}
\item Linearization of aerodynamic, structural and inertial loads, combined with the small-angles assumption provides analytical expressions that can be manipulated to obtain the rotor response.
\item Replacing trigonometric expressions with polynomials increases computational efficiency, while preserving more than 95\% accuracy.
\item \textbf{An ordering scheme is required to deal with lengthy analytical expressions, and the formulation must be re-derived for different materials (e.g. composites)}
\item In \textbf{UMARC}, the processes of vehicle trim and rotor trim are isolated from each other. Using the blade mode shapes and the coefficients of the individual time shape functions $\grkvec\eta$, the airloads and inertial loads can be computed for a given set of controls. These controls are iteratively adjusted starting from an initial guess using a Jacobian trim process. \textbf{Thus, the rotor trim process is hand-crafted using explicit analytical expressions, but the vehicle trim process is handled numerically.}
\end{itemize}

\subsection{\textbf{Numerical FET}}
The basic idea is to apply \textbf{UMARC}'s \textit{vehicle trim} numerical approach to also obtain the rotor motions using the following steps
\begin{itemize}
\item Assume that $w(x,t) \quad = \quad \sum \sum \xi_{ij} \spc V_i(x) \spc H_j(t)$ is available as an initial guess (instead of a quantity that needs to be ``solved for''). $V_i(x)$ is the spatial trial function, $H_j(t)$ is the temporal trial function and $\xi_{ij}$  is the time shape function coefficient of a rotor blade mode.
\item For a given set of $V_i(x)$, $H_j(t)$, find $\xi_{ij}$ such that the following set of \textit{approximate} equations are satisfied
\begin{equation}
\int_0^T H_j(t) \int_0^L \left(\textrm{LHS} - \textrm{RHS}\right) V_i(x) \spc dx \spc dt \quad = \quad  \epsilon_{ij} \quad = \quad 0
\end{equation}
\item Starting from an initial guess, iteratively adjust $\xi_{ij}$ to minimize $|\epsilon_{ij}|$, $i = 1, 2, \cdots N_m, \quad j = 1, 2, \cdots N_t$. The advantage of this approach is that the deflections are ``known'' at every time instant and point on the beam, and the need for small-angle approximations or analytical expressions are eliminated entirely. The present beam model is therefore spatially ``exact''.
\item By replacing the time shape functions $H_j(t)$ with trigonometric functions, we also preserve the ability to switch to harmonic balance without changing the trim structure.
\item The calculation of inertial loads and vehicle trim process uses the same framework, and the numerical routines need not be duplicated.
\item The rotor dynamics are, in effect, invisible to the trim solver. This modularity allows for adding additional complexity to the simulation (e.g. axial degrees of freedom, trailing-edge flaps or multiple rotors) without having to modify the rest of the code.
\end{itemize}

\subsubsection{Accelerated FET using Harmonic Balance}
The main disadvantage of FET is that the rotor and vehicle trim processes must be decoupled due to the discontinuities in the second time derivatives of the time shape functions. Obtaining the vehicle trim Jacobian is the most computationally expensive step in the trim process, since each set of trial controls require a trimmed rotor to obtain accurate hub loads. The key idea, therefore, is to speed up the computation of this Jacobian so that faster solutions may be obtained with FET.
By contrast, harmonic balance enforces continuity in accelerations, which allows for simultaneous vehicle and rotor trim at the cost of ignoring step changes in aerodynamic forcing (e.g. advancing blade shocks and retreating blade stall). This capability allows us to write the trim equations for the coupled rotor-body system as
\begin{equation}
\begin{Bmatrix} \grkvec\epsilon_\textrm{NR} \\ \grkvec\epsilon_\textrm{R} \end{Bmatrix} \quad = \quad \begin{Bmatrix} \vector{f}_\textrm{NR} (\vector{x}_\textrm{NR}, \spc \vector{x}_\textrm{R}) \\ \vector{f}_\textrm{R} (\vector{x}_\textrm{NR}, \spc \vector{x}_\textrm{R}) \end{Bmatrix}
\end{equation}
$\grkvec\epsilon$ represents the residuals of the trim equations, $\vector{x}$ denotes the trim variables and the subscripts denote non-rotating (NR) and rotating (R) components, i.e. everything but the rotor motions, and the rotor motions. Using finite-differences, the Jacobian matrix \textbf{J} may be partitioned as
\begin{equation}
\begin{Bmatrix} \grkvec\epsilon_\textrm{NR} \\ \grkvec\epsilon_\textrm{R} \end{Bmatrix} \quad = \quad \begin{bmatrix} \vector{J}_{11} & \vector{J}_{12} \\ \vector{J}_{21} & \vector{J}_{22} \end{bmatrix} \spc \begin{Bmatrix} \Delta \vector{x}_\textrm{NR} \\ \Delta \vector{x}_\textrm{R}  \end{Bmatrix}
\end{equation}
The linearized rotor trim equations may be written as
\begin{equation}
\grkvec\epsilon_\textrm{R} \quad = \quad \textbf{J}_{21} \spc \Delta \textbf{x}_\textrm{NR} \spc + \spc \textbf{J}_{22} \spc \Delta \textbf{x}_\textrm{R}
\end{equation}
The linearized vehicle trim equations may be written as
\begin{equation}
\grkvec\epsilon_\textrm{NR} \quad = \quad \textbf{J}_{11} \spc \Delta \textbf{x}_\textrm{NR} \spc + \spc \textbf{J}_{12} \spc \Delta \textbf{x}_\textrm{R}
\end{equation}
For harmonic balance, the entire Jacobian \textbf{J} is used for simultaneous rotor-vehicle trim. For FET, we require a \textit{reduced} Jacobian that represents the sensitivity of integrated vehicle loads to changes in vehicle trim variables, \textit{with a trimmed rotor}. Expanding on the operative word,
\[ \textrm{\textbf{For a trimmed rotor}} \qquad \grkvec\epsilon_\textrm{R} \quad = \quad \vector{0} \]
Thus,
\[ \textbf{J}_{21} \spc \Delta \textbf{x}_\textrm{NR} \spc + \spc \textbf{J}_{22} \spc \Delta \textbf{x}_\textrm{R} \quad = \quad \vector{0} \]
The rotor trim variables may be obtained in terms of the vehicle trim variables as
\[ \Delta\textbf{x}_\textrm{R} \quad = \quad -\textbf{J}_{22}^{-1} \spc \textbf{J}_{21} \spc \Delta\textbf{x}_\textrm{NR} \]
Substituting this expression in the linearized vehicle trim equations to yield
\begin{align*}
\grkvec\epsilon_\textrm{NR} \quad = \quad &\textbf{J}_{11} \spc \Delta \textbf{x}_\textrm{NR} \spc - \spc \textbf{J}_{12} \spc \textbf{J}_{22}^{-1} \spc \textbf{J}_{21} \spc \Delta\textbf{x}_\textrm{R} \\
\spc = \quad & \left(\spc \textbf{J}_{11} \spc - \spc \textbf{J}_{12} \spc \textbf{J}_{22}^{-1} \spc \textbf{J}_{21} \spc \right) \spc \Delta \textbf{x}_\textrm{R}
\end{align*}
An inspection of the above expression reveals that the FET trim Jacobian is
\begin{equation}
\textbf{J}_\textrm{FET} \quad = \quad \textbf{J}_{11} \spc - \spc \textbf{J}_{12} \spc \textbf{J}_{22}^{-1} \spc \textbf{J}_{21}
\end{equation}
Partitions of the trim Jacobians from Harmonic Balance can be manipulated and reduced for use with FET, therefore bypassing the most time-consuming part of the computations. This manner of reduction of a sensitivity matrix is similar to the procedure used to obtain a stability derivative model of a helicopter.


\section{Feynman Diagramm}

Having introduced Gell-Mann and Low theorem, the only left is how to calculate the expectation values of time-ordered operators in Eq \ref{greenexp}.
In this section, we will show how to use a diagrammatic approach to calculate them with the help of Wicki's theorem.

However, since we have mentioned that all perturbation theory gives the same result, one way wonder why do we need such a strange approach?
Then answer is the algebraic way to calculate perturbation terms is so complicated that it is difficult to understand what does it represent for.
In contrast, Feynman diagrams give a simple visualization of what would otherwise be an arcane and abstract formula.
As David Kaiser writes, "since the middle of the 20th century, theoretical physicists have increasingly turned to this tool to help them undertake critical calculations", and so "Feynman diagrams have revolutionized nearly every aspect of theoretical physics". \cite{kaiser}

Before introducing Wick's theorem, let's first have an observation of the expression we want to calculate:
\begin{equation}
	\langle\Phi_{0}|
	\hat{\mathcal{T}} \left[ c_u^{\dagger} c_v^{\dagger} \ldots c_i c_j \ldots \right]
	| \Phi_{0}\rangle
\end{equation}

Since creation operator add an electron while annihilation operator remove an electron, they must be paired somehow to get a nonzero final result.
Mathematically, we give the definition of physical and unphysical operators:

Since creation and annihilation operators will give the following effects on Hartree-Fock state:
\begin{equation} \label{cceffect}
	\begin{aligned}
		c_{p}^{\dagger} | \Phi_{0} \rangle=\left\{\begin{array}{ll}{ | \Phi_{p}^{N+1} \rangle} & {\text { for } n_{p}=0} \\ {0} & {\text { for } n_{p}=1}\end{array}\right.
		\\
		c_{p} | \Phi_{0} \rangle=\left\{\begin{array}{ll}{ | \Phi_{p}^{N-1} \rangle} & {\text { for } n_{p}=1} \\ {0} & {\text { for } n_{p}=0}\end{array}\right.
	\end{aligned}
\end{equation}
An operator is referred to as physical if the outcome is an $N\pm 1$ state (first and third case in \ref{cceffect}) and unphysical if the outcome is 0 (second and fourth case in \ref{cceffect}).

Then we define the normal-ordered product, which puts all physical operators to the left of unphysical operators:
\begin{equation}
	\hat{\mathcal{N}}\left[O_{i} O_{j} O_{k} \ldots\right] \equiv(-1)^{P^{\prime}} O_{P^{\prime}(i)} O_{P^{\prime}(j)} \ldots
\end{equation}

The so-called "pairing" process is formally defined as contraction:
\begin{equation}
	\wick{
		\c1 O_{r} \c1 O_{s} \equiv \hat{\mathcal{T}}\left[O_{r} O_{s}\right]-\hat{\mathcal{N}}\left[O_{r} O_{s}\right]
	}
\end{equation}

Wick's theorem \cite{wickproof} establishes a reformulation of a general time-ordered product
of fermion operators in terms of normal-ordered products and contractions. It may be stated as follows:

A $\hat{\mathcal{T}}$ product of m fermion operators can be transformed into a sum of $\hat{\mathcal{T}}$ products with all possible contractions of $k = 0, 1, \dots, [m/2]$ operator pairs:
\begin{equation}
	\begin{aligned}
		\hat{\boldsymbol{T}}\left[O_{i} O_{j} O_{k} O_{l} \ldots O_{r} O_{s} O_{t}\right]&=
		\hat{\mathcal{N}}\left[O_{i} O_{j} O_{k} O_{l} \ldots O_{r} O_{s} O_{t}\right]
		\\
		&+\hat{\mathcal{N}}\left[\wick{\c1 O_{i} \c1 O_{j} O_{k} \ldots}\right] +\hat{\mathcal{N}}\left[\wick{\c1 O_{i} O_{j} \c1 O_{k} \ldots}\right]+\ldots
		\\
		&+\hat{\mathcal{N}}\left[\wick{\c1 O_{i} \c1 O_{j} \c1 O_{k} \c1 O_{l} \ldots}\right]+\ldots
		\\
		&+\hat{\mathcal{N}}\left[\wick{\c3 O_{i} \c2 O_{j} \c1 O_{k} \ldots \c1 O_{r} \c2 O_{s} \c3 O_{t}}\right] \ldots
	\end{aligned}
\end{equation}

According to the property of the $\hat{\mathcal{N}}$ products, only the fully contracted terms contribute to the expectation value:
\begin{equation}
	\langle\Phi_{0}|
	\hat{\mathcal{T}}\left[O_{i} O_{j} O_{k} O_{l} \ldots O_{r} O_{s} O_{t}\right]
	| \Phi_{0}\rangle
	=\hat{\mathcal{N}}\left[\wick{\c3 O_{i} \c2 O_{j} \c1 O_{k} \ldots \c1  O_{r} \c2 O_{s} \c3 O_{t}}\right]+\ldots
\end{equation}

With Wick's theorem, we can finally calculate Green functions by series.
The perturbed Hamiltonian is:
\begin{equation}
	\hat{H}_{I}(t)=\sum w_{r s} c_{r}^{\dagger}(t) c_{s}(t)+\frac{1}{2} \sum V_{u v r s} c_{u}^{\dagger}(t) c_{v}^{\dagger}(t) c_{s}(t) c_{r}(t)
\end{equation}

First Order:
\begin{equation}
	\begin{aligned}
		&i \tilde{G}_{p q}^{(1)}\left(t, t^{\prime}\right)=
		(-i) \frac{1}{2} \sum_{r, s} w_{r s}
		\int_{-\infty}^{\infty} \mathrm{d} t_{1} e^{-\epsilon|t_{1}|}
		\langle\Phi_{0}|
		\hat{\mathcal{T}}\left[
			c_{r}^{\dagger}\left(t_{1}\right)
			c_{s}\left(t_{1}\right)
			c_{p}(t)
			c_{q}^{\dagger}\left(t^{\prime}\right)
			\right]
		| \Phi_{0}\rangle
	\\
		&+(-i) \frac{1}{2} \sum_{u, v, r, s} V_{u v r s}
		\int_{-\infty}^{\infty} \mathrm{d} t_{1} e^{-\epsilon|t_{1}|}
		\langle\Phi_{0}|
		\hat{\mathcal{T}}\left[
			c_{u}^{\dagger}\left(t_{1}\right)
			c_{v}^{\dagger}\left(t_{1}\right)
			c_{s}\left(t_{1}\right)
			c_{r}\left(t_{1}\right)
			c_{p}(t)
			c_{q}^{\dagger}\left(t^{\prime}\right)
		\right]
		| \Phi_{0}\rangle
	\end{aligned}
\end{equation}

Then we calculate the time-ordered products:
\begin{equation}
	\begin{aligned}
		&w_{rs}
		\langle\Phi_{0}|
		\hat{\mathcal{T}}\left[
			c_{r}^{\dagger}\left(t_{1}\right)
			c_{s}\left(t_{1}\right)
			c_{p}(t)
			c_{q}^{\dagger}\left(t^{\prime}\right)
			\right]
		| \Phi_{0}\rangle
		\\
		=&w_{rs} (G^0_{pr}(t,t_1) G^0_{sq}(t_1,t^{\prime}) - G^0_{rs}(t_1,t_1) G^0_{pq}(t,t^{\prime}))
		\\
		=&w_{pq} G^0_p(t,t_1) G^0_q(t_1,t^{\prime}) - w_{rr} G^0_r(t_1,t_1) \delta_{pq} G^0_{p}(t,t^{\prime})
		\\
		=&A+B
	\end{aligned}
\end{equation}
where $G^0_{pq}(t,t^{\prime}) = \delta_{pq} G^0_{p}(t,t^{\prime})$ is used in the last step

\begin{equation}
	\begin{aligned}
		&V_{uvrs}
		\langle\Phi_{0}|
		\hat{\mathcal{T}}\left[
			c_{u}^{\dagger}\left(t_{1}\right)
			c_{v}^{\dagger}\left(t_{1}\right)
			c_{s}\left(t_{1}\right)
			c_{r}\left(t_{1}\right)
			c_{p}(t)
			c_{q}^{\dagger}\left(t^{\prime}\right)
		\right]
		| \Phi_{0}\rangle
		\\
		=& -V_{pr[qr]} G^0_{p}(t,t_1) G^0_{r}(t_1,t_1) G^0_{q}(t_1,t^{\prime})
		- V_{rs[rs]} G^0_r(t_1,t_1) G^0_s(t_1,t_1) \delta_{pq} G^0_p(t,t^{\prime})
		\\
		=&C+D
	\end{aligned}
\end{equation}

The idea of feynman diagram is to assign each expression (A, B, C, D) here to a diagram.
The rule is to assign each time (including $t$, $t^{\prime}$ and time appearing as integration variable) a vertex, to assign each free Green function a line or curve which connects the two vertices corresponding to the time variables of the Green function itself.
The starting time of the Green function in interest is always on the bottom while in end time is always on the top.

In expression A, free Green function first propagate from time $t$ to $t_1$, and then from $t_1$ to $t^{\prime}$, which corresponds to a connected line as is shown in Diagram A.
In expression B, one free Green function propagates from $t$ to $t^{\prime}$, which corresponds to a line, while the other propagates from $t_1$ to itself, which corresponds to a loop (a curve ends at the starting vertex).
The case C and D are also similar, except that $t_1$ has four indexes, which means it should be connected to four lines or curves.

\begin{figure}[ht]
	\centering
	\begin{subfigure}{0.2\textwidth}
		\centering
		\includegraphics[height=3cm]{figures/diagramA.png}
		\caption{Diagram A}
	\end{subfigure}
	\begin{subfigure}{0.2\textwidth}
		\centering
		\includegraphics[height=3cm]{figures/diagramB.png}
		\caption{Diagram B}
	\end{subfigure}
	\begin{subfigure}{0.2\textwidth}
		\centering
		\includegraphics[height=3cm]{figures/diagramC.png}
		\caption{Diagram C}
	\end{subfigure}
	\begin{subfigure}{0.2\textwidth}
		\centering
		\includegraphics[height=3cm]{figures/diagramD.png}
		\caption{Diagram D}
	\end{subfigure}
\end{figure}

Additionally, we find that in the $w_{rs}$ case (A and B), there is always one incoming line and one outcoming line for each intermediate vertex, which is because of one creation operator and one annihilation operator in the expression $W=w_{rs} c_r^{\dagger} c_s$.
In the $V_{uvrs}$ case (C and D), there are always two incoming lines and two outcoming lines for each intermediate vertex, which is because of two creation operators and two annihilation operators in the expression $V=\frac{1}{2}V_{uvrs} c_u^{\dagger} c_v^{\dagger} c_s c_r$.

Compared with the expressions, the diagrams are very simple, which is one of its advantages.
In fact, Feynman diagram can not only show the structure of expression, but can also restore all the algebraic details.
This means that, instead of doing any algebraic calculation, we can just draw all the possible diagrams and then use some rules to translate to algebraic results.
Then we will derive the rules:

For each vertex, we assign $w_{rs}$ or $V_{uv[rs]}$ depending on whether it's a $w$ vertex or a $V$ vertex:

\hspace{0.2\textwidth}
\begin{minipage}{0.08\textwidth}
	\includegraphics[height=3cm]{figures/vertexW.png}
\end{minipage}
\begin{minipage}{0.2\textwidth}
	$=w_{rs}$
\end{minipage}
\begin{minipage}{0.18\textwidth}
	\includegraphics[height=3cm]{figures/vertexV.png}
\end{minipage}
\begin{minipage}{0.1\textwidth}
	$=V_{uv[rs]}$
\end{minipage}

It is easy to understand the result of $w$ vertex, since $W=w_{rs} c_r^{\dagger} c_s$.
For the $V$ case, $V=\frac{1}{2}V_{uvrs} c_u^{\dagger} c_v^{\dagger} c_s c_r$.
Wick's theorem states all possible of contraction should be included, thus any algebraic expression will have "partners" that the only difference is the exchange of index $u$ and $v$, or $s$ and $r$, or both.
Thus, instead of $\frac{1}{2}V_{uvrs}$, the proper magnitude should be $\frac{1}{2}V_{[uv][rs]}=V_{uv[rs]}$.

However, it is not always the case, since sometimes we will meet double counting.
For example in the double loop in Diagram D, which corresponds to algebraic expression
\begin{equation}
	\langle\Phi_{0}|
	\hat{\mathcal{T}}\left[
		c_{u}^{\dagger}\left(t_{1}\right)
		c_{v}^{\dagger}\left(t_{1}\right)
		c_{s}\left(t_{1}\right)
		c_{r}\left(t_{1}\right)
	\right]
	| \Phi_{0}\rangle
\end{equation}

Obviously, there is only two contraction schemes, i.e. $u$ with $s$, $v$ with $r$, or $u$ with $r$, $v$ with $s$.
Thus, we meet double counting here.
Generally, when two lines are equal, double counting happens.
Thus, the final result should be divided by two for each pair of equal lines.

Each line or curve is assigned by its corresponding Green function, which is also easy to understand.
In the case of higher orders, the expression is
\begin{equation} \label{greenexp}
\begin{aligned}
	i \tilde{G}^n_{p q}\left(t, t^{\prime}\right)
	=& \frac{(-i)^{n}}{n !}
	\int_{-\infty}^{\infty} \mathrm{d} t_{1} e^{-\epsilon|t_{1}|} \ldots \int_{-\infty}^{\infty} \mathrm{d} t_{n} e^{-\epsilon|t_{n}|}
	\\
	& \langle\Phi_{0}|
	\hat{\boldsymbol{T}}\left[\hat{H}_{I}\left(t_{1}\right) \ldots \hat{H}_{I}\left(t_{n}\right) c_{p}(t) c_{q}^{\dagger}\left(t^{\prime}\right)\right]|
	\Phi_{0}\rangle
\end{aligned}
\end{equation}
which has a factor of $\frac{(-i)^n}{n!}$.

However, $t_1 \dots t_n$ are treated on each footing and can also be exchanged when calculating the time-ordered product, thus it will contribute a factor $n!$.
Thus the overall factor is $(-i)^n$.

Last but not least, we need to determine the overall sign of the expression.
Unfortunately, it is impossible to determine the sign just from diagram, thus one must go back to any one of the algebraic expressions and then count how many times one need to commute creation and annihilation operator in the expression of time-ordered product.

Feynman diagram drawn by above rules is refered as Abrikosov diagram.

Then we go back to the calculation of first order Green function.
Let's first focus on expression B and D.
Both parts contain $G^0_{pq}(t,t^{\prime})$, which corresponds to a separate line in Diagram B and D.
Now we introduce the famous linked-cluster theorem, which states that all diagrams contain a separate $G^0_{pq}(t,t^{\prime}$ line will be canceled by the denominator of Eq \ref{greenexp}.
The proof is given in the reference \cite{main}.
Here we take first order Green function as an example.

Up to the first order, Green function can be written as
\begin{equation}
	\begin{aligned}
		i\tilde{G}_{pq}(t,t^{\prime})=&i \delta_{pq} G^0_{p}(t,t^{\prime})
		\\
		+&w_{pq} G^0_p(t,t_1) G^0_q(t_1,t^{\prime}) - w_{rr} G^0_r(t_1,t_1) \delta_{pq} G^0_{p}(t,t^{\prime})
		\\
		-&V_{pr[qr]} G^0_{p}(t,t_1) G^0_{r}(t_1,t_1) G^0_{q}(t_1,t^{\prime})
		- V_{rs[rs]} G^0_r(t_1,t_1) G^0_s(t_1,t_1) \delta_{pq} G^0_p(t,t^{\prime})
		\\
		+&O(2)
	\end{aligned}
\end{equation}
while the denominator is
\begin{equation}
	\langle\Phi_{0}|\hat{U}_{\epsilon}(0,-\infty)| \Phi_{0}\rangle=1
		- w_{rr} G^0_r(t_1,t_1)
		- V_{rs[rs]} G^0_r(t_1,t_1) G^0_s(t_1,t_1)
		+ O(2)
\end{equation}

Thus up to the first order,  the overall Green function reads
\begin{equation}
	i G_{pq}(t,t^{\prime})=i \delta_{pq} G^0_{p}(t,t^{\prime})
	+w_{pq} G^0_p(t,t_1) G^0_q(t_1,t^{\prime})
	-V_{pr[qr]} G^0_{p}(t,t_1) G^0_{r}(t_1,t_1) G^0_{q}(t_1,t^{\prime}) +O(2)
\end{equation}
where all unlinked diagrams are canceled.

As we mentioned before, both the numerator and denominator contains divergent terms, which will be canceled after division.
In fact, the divergent parts are exactly the unlinked diagrams.
Thus, linked-cluster theorem decreases the number of diagrams we need to calculate, and also guarantees the result is finite and thus physical.

Then we analyze the rest terms of first order Green function:
\begin{equation}
	\begin{aligned}
		i G^1_{pq}(t,t^{\prime}) &= w_{pq} G^0_p(t,t_1) G^0_q(t_1,t^{\prime})
		-V_{pr[qr]} G^0_{p}(t,t_1) G^0_{r}(t_1,t_1) G^0_{q}(t_1,t^{\prime})
		\\
		&= G^0_p(t,t_1) G^0_q(t_1,t^{\prime}) (w_{pq}-V_{pr[qr]}G^0_r(t_1,t_1)
		\\
		&= G^0_p(t,t_1) G^0_q(t_1,t^{\prime}) (w_{pq}+V_{pr[qr]}n_r)
		\\
		&=0
	\end{aligned}
\end{equation}
where
\begin{equation}
	\begin{aligned}
		G^0_r(t_1,t_1)&=G^0_r(t_1,t_1^{+})
		\\
		&=- \langle\Phi_{0}|
		c_r^{\dagger} c_r
		| \Phi_{0}\rangle
		\\
		&=-n_r
	\end{aligned}
\end{equation}
is used.

In fact, the diagrams that contain $w$ vertex will always cancel with the diagrams that contain free Green function line starting and ending with the same $V$ vertex.
According to Eq \ref{greenexp}, $H_I$, which is $W$ and $V$ always appear together.
Thus, any diagram contain $V_{pr[qr]}n_r$ will automatically contain $r_{pq}$.
This result means that we can skip all diagrams with $W$ vertex and that contain free Green function line starting and ending with the same $V$ vertex at the same time.
Thus, we will not consider $W$ vertex in the following.

Then we summarize the Feynman rules for Abrikosov diagram:
\begin{itemize}
	\item Draw all topologically distinct connected diagrams with $n$ interaction dots and $2n + 1$ directed (solid) free Green’s function starting at the outer vertex $(p, t)$ and ending at the outer vertex $(q, t^{\prime})$.
		At each interaction dot, two Green function start and two end; assign a time argument to each interaction dot.
	\item Attach one-particle indices and time arguments to the free Green function lines; the arrows define the order of the time arguments. Replace the graphical symbols (free Green function lines and interaction dots) by the respective analytical expressions.
	\item Sum over indices and integrate over time arguments of the inner vertices.
	\item The overall phase of an Abrikosov diagram can only be fixed by inspecting one of the Feynman diagrams comprised in the Abrikosov diagram.
		The phase is to be adapted in such a way that this Feynman diagram is reproduced correctly by the Abrikosov expression.
	\item Apply a factor of $\frac{1}{2}$ for each pair of (topologically) equivalent free Green function lines to compensate for double counting of Feynman diagrams. Double counting may arise for other reasons at fourth and higher order, and this possibility must be checked at the level of Feynman diagrams.
\end{itemize}

We calculate the second order Green function as the end of this section:
According to the Feynman diagram, we first draw all possible topologically inequivalent diagrams.
In the case of second order Green function, there is only one diagram:
\begin{figure}[h]
	\centering
	\includegraphics[height=4cm]{figures/order2.png}
	\caption{Diagram of second order Green function}
\end{figure}

Note that the two curves are identical ( start and end with the same vertices).
Thus, according the Feynman rules, we can easily determine the second order Green function up to a overall sign:
\begin{equation} \label{order2}
	\begin{aligned}
	G_{p q}^{(2)}\left(t, t^{\prime}\right)=\pm \frac{1}{2} \sum_{r, u, v_{-\infty}} & \int_{-\infty}^{\infty} \mathrm{d} t_{1} \int_{-\infty}^{\infty} \mathrm{d} t_{2} V_{p r[u v]} V_{u v[q r]}
	\\
	& G_{p}^{0}\left(t, t_{1}\right) G_{u}^{0}\left(t_{1}, t_{2}\right) G_{v}^{0}\left(t_{1}, t_{2}\right) G_{r}^{0}\left(t_{2}, t_{1}\right) G_{q}^{0}\left(t_{2}, t^{\prime}\right)
	\end{aligned}
\end{equation}

To determine the overall sign, we only need to consider the case
\begin{equation}
	\langle\Phi_{0}|
	\hat{\mathcal{T}}\left[
		\wick{\c4 c_{u}^{\dagger}\left(t_{1}\right) \c3 c_{v}^{\dagger}\left(t_{1}\right) \c2 c_{s}\left(t_{1}\right) \c1 c_{r}\left(t_{1}\right) \c1 c_{i}^{\dagger}\left(t_{2}\right) \c2 c_{j}^{\dagger}\left(t_{2}\right) \c3 c_{l}\left(t_{2}\right) \c1 c_{k}\left(t_{2}\right) \c4 c_{p}(t) \c1 c_{q}^{\dagger}\left(t^{\prime}\right)}
		\right]
		| \Phi_{0}\rangle
\end{equation}
which gives an overall sign of $-1$, which is canceled with the factor $(-i)^2$.

Thus the overall sign of expression Eq \ref{order2} should be positive.


\documentclass[]{article}
 \usepackage{amsmath}
 \usepackage{amssymb}
 \usepackage{mathdots}
% \usepackage{amsthm}
% \usepackage{textcomp}
 \parindent=0mm
 \parskip=2.5mm
% \parindent=0mm
% \renewcommand{\arraystretch}{1.35}
% \usepackage{cite}

%\usepackage[acronym,nonumberlist]{glossaries}
%\makeglossaries
\usepackage{graphicx}
\graphicspath{{Figures/}}
\usepackage[small,bf,up]{caption}
\providecommand{\diff}[3]{\frac{d^{#3} #1}{d #2^{#3}}}
\providecommand{\pdiff}[3]{\frac{\partial^{#3} #1}{\partial #2^{#3}}}
\providecommand{\abs}[1]{\left \lvert#1\right \rvert}
\providecommand{\etal}[0]{\textit{et al. }}
\oddsidemargin 15mm                        % 1 inch + lefthand margin on odd numbered pages
\evensidemargin 15mm                       % 1 inch + lefthand margin on even numbered pages
\textwidth 145mm

%\usepackage[round]{natbib}
%
\setcounter{MaxMatrixCols}{20}
\usepackage[square,numbers,comma,sort&compress]{natbib}
\usepackage{listings}
%\bibliographystyle{plainnat}
\bibliographystyle{unsrt}
%\usepackage{nomencl}
%\nomlabelwidth=15mm
%\makeindex
%\makenomenclature

\date{\today}
\title{Probabilistic Transient Propagation (PTP), Background and Mathematics}

\author{Richard Collins}

\begin{document}
\maketitle

\begin{abstract}

\end{abstract}

\section{Transient Equations}
Here we are going to model the basic transient equations,
\begin{equation}\label{TranEqns}
 \begin{split}
 \pdiff{H}{t}{} + \frac{a^2}{gA}\pdiff{Q}{x}{} &= 0 \\
\pdiff{H}{x}{} + \frac{1}{gA}\pdiff{Q}{t}{} + \frac{\lambda}{2 g DA^2}Q \abs{Q} &= 0
 \end{split}
\end{equation}

These are a pair of coupled non-linear hyperbolic partial differential equations that describe the change in head and flow along a pipe.
They need to be coupled with suitable, initial and boundary conditions to complete the solution.

\section{Method of Characteristics}
The standard solution technique for solving \eqref{TranEqns} numerical is to use the Method of Characteristics (MOC).
The MOC converts the partial differential equations into ordinary differential equations along characteristic lines in the solution space, along which the information about changes flows.
To apply the MOC to \eqref{TranEqns} we first multiply the momentum equation by a currently unknown factor $K$, then add the two equations together:
\begin{equation}
 \pdiff{H}{t}{} + \frac{a^2}{gA}\pdiff{Q}{x}{} + K \pdiff{H}{x}{} + K \frac{1}{gA}\pdiff{Q}{t}{} + K \frac{\lambda}{2 g DA^2}Q \abs{Q} = 0
\end{equation}
without explicitly going into why, if we set $K$ to be the wavespeed $a$, then we get the following:  (NOTE THIS ISN'T QUITE RIGHT CHECK WITH WYLIE AND STREETER)
\begin{equation}
 \pdiff{H}{t}{} + a \pdiff{H}{x}{} + \frac{a}{gA}\left(\pdiff{Q}{t}{} + a \pdiff{Q}{x}{} \right) + \frac{a \lambda}{2 g DA^2}Q \abs{Q} = 0
\end{equation}
The total derivative of a function $f(x,t)$ w.r.t time is given by $\pdiff{f}{t}{} + \diff{x}{t}{}\pdiff{f}{x}{}$ so we can see that we have formed a series of total derivatives.
\begin{equation}
 \diff{H}{t}{} \pm \frac{a}{gA}\diff{Q}{t}{} \pm \frac{a \lambda}{2 g DA^2}Q \abs{Q} = 0
\end{equation}
this pair of equations is only valid along the lines when
\begin{equation}
 \diff{x}{t}{} = \pm a
\end{equation}

To simplify the calculations below we will rewrite the equation as:
\begin{equation}
 \diff{H}{t}{} \pm B \diff{Q}{t}{} \pm \frac{R}{\Delta x} Q \abs{Q} = 0
\end{equation}
with $B = \frac{a}{g A}$ and $R = \frac{\lambda \Delta x}{2 g D A^2}$.
Note: that $R$ contains some modelling error.

NEEDS A BIT IN HERE ABOUT HOW TO GET TO THE NEXT BIT

\begin{figure}[htp]
 \centering
 \caption{Mesh discretisation for the MOC}
 \label{MOCmesh}
\end{figure}

The equations need to be integrated along the lines AP and B, which is easy for the first pair of terms but becomes complicated for the final term.

Once we have integrated along the two lines then we have the pair of equations:
\begin{equation}\label{posChar}
 H_P = C_p + B_p Q_P
\end{equation}
and
\begin{equation}\label{negChar}
 H_P = C_m + B_m Q_P
\end{equation}

with the constants of integration given by:
\begin{equation}
 \begin{split}
  C_p &= H_A + Q_A \left(B - R \abs{Q_A} (1-\epsilon)\right) \\
  B_p &= B + \epsilon R \abs{Q_A} \\
  C_m &= H_B - Q_B \left(B - R \abs{Q_B} (1-\epsilon)\right) \\
  B_m &= B + \epsilon R \abs{Q_B} \\
 \end{split}
\end{equation}

we will explore the use of $\epsilon$ a little later.

If we combine \eqref{posChar} and \eqref{negChar} we can generate equations that take the information from both the forward and backward characteristic for head and flow at the current point.
\begin{equation}\label{BaseEqn}
 \begin{split}
  H_P &= \frac{B_m C_p + B_p C_m}{B_m + B_p} \\
  Q_P &= \frac{C_p - C_m}{B_m + B_p} \\
 \end{split}
\end{equation}

These two equations are the fundamental equations that we will use going forward.
$C_m$, $B_m$, $C_p$ and $B_p$ are functions of the flows and heads at the adjacent points.

\section{Kalman Filter}
STUFF HERE ON THE BACKGROUND TO THE KALMAN FILTER

\begin{equation}
\begin{split}
 \mathbf{\hat{x}}_t &= \mathbf{F}_t \mathbf{\hat{x}}_{t-1} + \mathbf{B} \mathbf{u}_t + \mathbf{\hat{w}}_t \\
 \mathbf{\hat{z}}_t &= \mathbf{H}_t \mathbf{\hat{x}}_t + \mathbf{\hat{v}}_t \\
\end{split}
\end{equation}

\subsection{Ability to use the Kalman Filter to model the transient equations}
As mentioned above the Kalman filter can be used to model linear dynamic models, however the transient equations are non-linear.
Therefore we will have to do some linearisation to make the equations suitable to be modelled in this way.
There are a number of approaches that will work, see Section \ref{EKF} for a more general approach, however here we will use a simpler technique.
If we look at the original equations \eqref{TranEqns} we see that, if we assume $A$, $D$, $a$ and $\lambda$ are constants, the only non-linearity is in the flow in the final term of the momentum equation.
Therefore if we can linearise this then the equation will be linear and suitable for modelling with the Kalman Filter.

If we assume that the changes in flow rate during the transient are small, and the flow rate  remains close to the original flow rate then we can say that:
\begin{equation}
 Q\abs{Q} \approx Q Q_0
\end{equation}
where $Q_0$ is the initial flow at the start of the simulation.
$Q_0$ obviously remains a constant and the equations are now linear.
\begin{equation}\label{TranEqnsLinear}
 \begin{split}
 \pdiff{H}{t}{} + \frac{a^2}{gA}\pdiff{Q}{x}{} &= 0 \\
\pdiff{H}{x}{} + \frac{1}{gA}\pdiff{Q}{t}{} + \frac{\lambda Q_0}{2 g DA^2}Q &= 0
 \end{split}
\end{equation}

If we apply the MOC to this pair of equations, we again get \eqref{BaseEqn}, however the characteristics are slightly modified.
\begin{equation}
 \begin{split}
  C_p &= H_A +  B Q_A - R Q_A Q_0 \\
  B_p &= B \\
  C_m &= H_B - B Q_B + R Q_B Q_0\\
  B_m &= B  \\
 \end{split}
\end{equation}

The full equations for predicting the head and flow rate at $P$ are simple enough to be worth writing out in full.
\begin{equation}\label{LinearH}
 H_P = \frac{1}{2} \left[H_A +  H_B + \left(-R Q_0 + B \right)Q_A + \left(R Q_0 - B\right) Q_B \right]
\end{equation}
and
\begin{equation}\label{LinearQ}
 Q_P = \frac{1}{2} \left[\frac{H_A}{B} + \frac{H_B}{B} + \left(1-\frac{R Q_0}{B} \right)Q_A + \left(1-\frac{R Q_0}{B}\right)Q_B    \right]
\end{equation}

We can rewrite this is a more Kalman filter type way:
\begin{equation}
\begin{split}
 \mathbf{x}_{h,t} &= \frac{1}{2} \left[ \mathbf{x}_{h-1,t-1} +   \mathbf{x}_{h+1,t-1} \left(-R Q_0 + B \right) \mathbf{x}_{q-1,t-1} + \left(R Q_0 - B\right)  \mathbf{x}_{q+1,t-1} \right]\\
  \mathbf{x}_{q,t} &= \frac{1}{2} \left[\frac{\mathbf{x}_{h-1,t-1}}{B} + \frac{\mathbf{x}_{h+1,t-1}}{B} + \left(1-\frac{R Q_0}{B} \right)\mathbf{x}_{q-1,t-1} + \left(1-\frac{R Q_0}{B}\right)\mathbf{x}_{q+1,t-1}    \right]
 \end{split}
\end{equation}
where $h$ is now the position in the state vector corresponding to the head at $P$ and $q$ is the position corresponding to the flow rate at $P$.

The construction of the dynamics matrix can then be seen to be:
\begin{equation}
\begin{bmatrix}
\vdots \\
 x_{h-1} \\
 x_{h} \\
 x_{h+1} \\
 \vdots \\
  x_{q-1} \\
 x_{q} \\
 x_{q+1} \\
  \vdots
\end{bmatrix}_t
=
\begin{bmatrix}
\ddots & \dots& \dots& \dots& \dots& \dots& \dots&\dots &\iddots\\
\dots 0 & \frac{1}{2}& 0 & \frac{1}{2} & 0 \dots0&  \frac{1}{2}\left(-R Q_0 + B \right) & 0 & \frac{1}{2}\left(R Q_0 - B\right)&0\dots \\
\vdots & \vdots& \vdots& \vdots& \vdots& \vdots& \vdots& \vdots& \vdots\\
\dots 0 & \frac{1}{2 B} &0& \frac{1}{2 B} & 0  \dots 0  & \frac{1}{2} \left(1-\frac{R Q_0}{B} \right) & 0 & \frac{1}{2} \left(1-\frac{R Q_0}{B} \right) & 0\dots\\
\iddots & \dots& \dots& \dots& \dots& \dots& \dots &\dots &\ddots\\
\end{bmatrix}
\begin{bmatrix}
\vdots \\
 x_{h-1} \\
 x_{h} \\
 x_{h+1} \\
 \vdots \\
  x_{q-1} \\
 x_{q} \\
 x_{q+1} \\
  \vdots
\end{bmatrix}_{t-1}
\end{equation}
which is a nicely sparse matrix.

\subsection{How Gaussian are the uncertainties?}
Kalman filters only really work with Gaussian uncertainty (noise).
So there is a question of how close to Gaussian are any uncertainties.
If we look at \eqref{LinearH} and \eqref{LinearQ} we can see that as well as uncertainty in the state we need to account for uncertainty in $R$ and $B$ and some combinations of these factors.

\begin{equation}
 B = \frac{a}{g A}
\end{equation}

\begin{equation}
 R = \frac{\lambda \Delta x}{2 g D A^2}
\end{equation}

\section{Extended Kalman Filter}\label{EKF}
Note that the full transient equations are non-linear so the standard Kalman filter approach is unavailable.
Instead we have to use the extended Kalman filter which uses the Jacobian of the evolution equations to approximate the evolution of the system covariance.

Here we include the Extended Kalman Filter Equations.

The basic equation relies on the ability to formulate the problem into a way which allows the next state of the system is only a function of the previous state, some control inputs (which we will not consider for now) and some uncertainty.
\begin{equation}
\begin{split}
 \mathbf{\hat{x}}_t &= f(\mathbf{\hat{x}}_{t-1}) + \mathbf{\hat{w}}_t \\
 \mathbf{\hat{z}}_t &= h(\mathbf{\hat{x}}_t) + \mathbf{\hat{v}}_t \\
\end{split}
\end{equation}

where $f(\cdot)$ and $h(\cdot)$ are some, potentially, non-linear mappings of the evolution of the state and the measurements, and $w$ and $v$ are the zero-mean Gaussian noise vectors.
The state evolution can be calculated in what ever non-linear way is most appropriate, i.e. by a matrix method, or any other technique.
\begin{equation}
 \mathbf{\hat{x}}_t = f(\mathbf{\hat{x}_{t-1}})
\end{equation}
however the covariance matrices are calculated using:
\begin{equation}
 \mathbf{P}_t = \mathbf{F}_{k-1} \mathbf{P}_{t-1} \mathbf{F}_{k-1}^T + \mathbf{Q}_{t-1}
\end{equation}

where $\mathbf{F}$ is the Jacobian matrix of the function $f(\cdot)$
\begin{equation}
 \mathbf{F} = \pdiff{f}{\mathbf{\hat{x}}}{}
\end{equation}

\subsection{Calculation of the Jacobian}
To calculate the Jacobian of the evolution equation we first need to determine our state vectors and actually what our state evolution equations are:

\subsubsection{State Vector}
In this formulation the state vector is composed of the Heads and flows at each nodal position, however due to the non-linearity we also need to include the pipe diameter, friction factor (and possibly the pipe wave speed) on each pipe reach between nodes.
If the number of Nodes in the model is $N$, the size of our state vector (not including wavespeed) will be $2N + 2(N-1) = 4N -2$, (or $5N-3$ if wave speed is included).

\end{document}


\chapter{Dynamical Systems}
\label{chp:dynamicalsystems}

\begin{multicols}{2}[\subsubsection*{Contents of this chapter}]
   \printcontents{}{1}{\setcounter{tocdepth}{2}}
\end{multicols}

This is dangerously familiar ground for physicists. A dynamical system is some system:

\begin{equation}
\partial_t\mathbf{x} = \mathbf{f}(\mathbf{x},t,\mathbf{u};\mathbf{\beta})
\end{equation}

Where $\mathbf{x}$ are the state space coordinates of the system at some time $t$, and $\mathbf{f}$ is the \textit{dynamics} of the system. $\mathbf{u}$ is some control input and $\mathbf{\beta}$ are parameters. A system where $\mathbf{f}$ depends on time is called \textit{non-autonomous} and a system that has an $\mathbf{f}$ that does not depend on time is called \textit{autonomous}.

Conventionally, the dynamics $\mathbf{f}$ are derived from first principles. Increasingly, it is possible to infer them from data. Challenges arise from:

\begin{itemize}
\item Nonlinear $\mathbf{f}$, that is, the system cannot be described in the form $\partial_t\mathbf{x}=\mathbf{Ax}$
\item Unknown $\mathbf{f}$
\item High dimensional state vector $\mathbf{x}$
\item Chaos, Transients
\item Noise, Stochastic forcing functions
\item Multiscale dynamics
\item Uncertainty (in parameters etc.)
\end{itemize}

\section{Mode Decompositions}
Modal decompositions express the evolving state of a system in terms of a superposition of basis vectors that are the eigenfunctions of a time-translation operator. In general, the rank of the basis space is the same as the state space dimension, but in practice only a few of those modes have "energy". That means that the description of a system in terms of a modal decomposition often requires orders of magnitude fewer parameters than the description of the state space. Extracting the dominant modes also amounts to extracting the dominant dynamics of the system, with the assumption possibly being that the discarded low-energy modes are noise. In so far, modal decomposition runs closely parallel to decomposition-based dimensionality reduction techniques such as SVD, PCA and ICA, though explicitly introducing the notion of a trajectory through time.

The modes are properties of the time translation operator and the state space. Therefore, the description in terms of modes is compatible with an arbitrary, unpredictable forcing function acting on the system, so long as it does not affect the time translation operator or the state space. For example, the description of the oscillation of a guitar string in terms of modes remains valid regardless of the song that is being played. However, changing the length of the string increases the size of the state space, and increasing the tension in the string accelerates its reversion from being struck away from its equilibrium, and therefore it's time translation operator. In those cases the modes of the system are changed.

\section{Koopman and Frobenius-Perron Operators}
The Koopman Operator, or composition operator, is the classical analogue of the time translation operator $e^{-i\mathbf{\hat{H}}t/\hbar}$ in quantum mechanics. It describes dynamics in terms of the \textit{Heisenberg Picture}, in which operators, rather than states, have time-dependence. It describes autonomous systems (in quantum mechanics, that would be a system where the Hamiltonian $\mathbf{\hat{H}}$ nor the size of the state space depend on time).

Consider a dynamical system evolving on a manifold $\mathscr{M}$, so that, in discrete time:

\begin{equation}
\mathbf{x}_{k+1} = \mathbf{f}(\mathbf{x}_{k})
\end{equation}

Where $\mathbf{x}\in\mathscr{M}$ are the state space coordinates of the system at a given time. Given a scalar valued function on the state space $g:\mathscr{M} \rightarrow \mathbb{R}$, the Koopman Operator $\mathbf{\hat{K}}$ acts as:

\begin{equation}
\mathbf{\hat{K}}g(\mathbf{x}) = g(\mathbf{f}(\mathbf{x}))
\end{equation}

Which acts as time translation by one step.

The Koopman Operator is infinite dimensional and linear, even though the dynamical system might be nonlinear with a finite state space. The Frobenius-Perron Operator (sometimes also Ruelle Operator, Ruelle-Frobenius-Perron Operator, or Transfer Operator) is the right adjoint of the Koopman operator, so that an approximation of one provides an approximation of the other. Rather than a function in state space, it translates the state space density in time. Let $\mathbf{\hat{P}}$ be the Frobenius-Perron Operator. Let the state space density be $\rho(\mathbf{x}$, and define some operator $\mathbf{\hat{A}}$, so that $\mathbf{\hat{A}}\rho(\mathbf{x}) = g(\mathbf{x})$. Then, in terms of either the Koopman or the Frobenius-Perron approach, the average value of the quantity $\left< g(\mathbf{x}(t))\right>$ at time $t$ in the Koopman picture or in the Frobenius-Perron picture is \cite{cvitanovic2016chaos,salova2019koopman}:

\begin{equation}
\begin{array}{rl}
\left< g(\mathbf{x}(t))\right> =& \int_\mathscr{M} \mathrm{d}x \mathbf{\hat{K}}(t)\mathbf{\hat{A}}\rho(\mathbf{x}) \\
& \int_\mathscr{M} \mathrm{d}x \mathbf{\hat{A}}\mathbf{\hat{P}}(t)\rho(\mathbf{x})
\end{array}
\end{equation}

Which implies that $\mathbf{\hat{K}}(t)\mathbf{\hat{A}} \left[\mathbf{\hat{P}}(t)\right]^{-1} = \left[\mathbf{\hat{K}}(t) \right]^{-1} \mathbf{\hat{A}} \mathbf{\hat{P}}(t) = \mathbf{\hat{A}}$.

The function $g(\mathbf{x}(t))$ is an \textit{observable} of the system, which might be a pixel value, the value of a stock portfolio, the energy of a particle, or something like that. The state space coordinates $\mathbf{x}(t)$ may or may not correspond to quantities that are actually observable. Their role is to uniquely parametrize the possible states of the system. The Koopman Operator acts on observables, which is probably why it seems to come up more often in data-driven work.

% POD

\section{Proper Orthogonal Decomposition (POD)}
Proper Orthogonal Decomposition (POD) seeks a lower-rank representation of a dynamical system that, as far as I can see, is entirely analogous to SVD or PCA \cite{megretski2004pod}. Given a system $\mathbf{x}(t) \in \mathbb{R}^n$, one looks for a low-rank projection $\Pi_r$ that minimizes the expected value of the error:

\begin{equation}
\argmin \mathbb{E}_t||\mathbf{x}(t) - \mathbf{\Pi}\mathbf{x}(t)||_{2}
\end{equation}

This is the same loss function as for PCA, and so the projection matrix $\mathbf{\Pi}_r = \sum_{i=1}^{r} \mathbf{v}_i\mathbf{v}^T_i$ where $\mathbf{v}_i$ is the $i$th principal component vector.

The POD does not have anything to say about the dynamics of a system, indeed, the time-ordering of the snapshots has no effect on the result. As such, performing POD on a system across different time windows should yield different decompositions unless the system is completely at rest, even when the dynamics of the system are steady. The first orthogonal component is simply the point in state space that the system is most correlated with across the observed time-frame.

% DMD
\section{Dynamic Mode Decomposition (DMD)}
\label{sec:dmd}
Dynamic Mode Decomposition (DMD) fits a reduced-rank, linear dynamical system to multi-dimensional time-series data. The rank-reduction is useful when the state space is very high-dimensional, for example when each time step is an image with many pixels. Canonically, fitting and rank reduction relies on SVD, so that the method is based on $L^2$ loss. It originated in the fluid dynamics community, where very high-dimensional state spaces are common because dynamics must be resolved across many length scales.

In case of plain-vanilla DMD, the dataset consists of pairs of snapshots of the system, which show the system at two subsequent time steps, i.e. $\{(\mathbf{x}_t,\mathbf{y}_t): \mathbf{y}_t = \mathbf{x}_{t+\delta t} \}$. Often, the different pairs show the system on different state space trajectories. That is, they may originate with many different "incarnations" of the system. To me it looks basically like an VAR(1) model, except that it can handle a very high dimensional state vector by extracting the leading eigendecomposition of the coefficient matrix without having to calculate it. It also looks a lot like fitting the transition matrix of a Markov Chain.

Given a set of $m$ snapshots of the system $\{\mathbf{x}_t:\ t\in[1,m], \mathbf{x}_t \in \mathbb{R}^{n}\}$, let $\mathbf{X}_{1,m-1} = \left[\mathbf{x}_1,\mathbf{x}_2,...,\mathbf{x}_{t-1},\mathbf{x}_{m-1}\right]$ be the matrix of state vectors from $t\in[1,m-1]$ and $\mathbf{X}_{2,m}$ be the matrix of state vectors advanced by one time step from $t\in[2,m]$. Then dynamic mode decomposition essentially looks for linear dynamics using linear regression:

\begin{equation}
\mathbf{X}_{2,m} = \mathbf{A}\mathbf{X}_{1,m-1}
\end{equation}

Where $\mathbf{A} \in \mathbb{R}^{n\times n}$ is square and therefore diagonalizable, but may be very large.

Let $a_{i,j}$ be the entry in the $i$th row and $j$th column of $\mathbf{A}$. Elementwise, the equation for the $i$th state variable at time $t$, $x_{i,t} = [\mathbf{x}_t]_i$ is written:

\begin{equation}
x_{i,t} = \sum_j a_{i,j} x_{i,t-1}
\end{equation}

The eigenvectors of $\mathbf{A}$  correspond to normal modes of the system. The corresponding eigenvectors, which may be real or complex, predict the evolution of the mode over time.

The size of $\mathbf{A}\in\mathbb{R}^{n\times n}$ may be so large that extracting its eigenvectors and eigenvalues may be computationally intractable. DMD instead derives a smaller matrix $\mathbf{A'}$ that has the same eigenvalues as $\mathbf{A}$ and uses those to also finds the eigenvectors.

\begin{equation}
\begin{array}{ll}
1. & \mathbf{X}_{1,m-1} = \mathbf{U}\mathbf{\Sigma}\mathbf{V}^T,\ \ \ \ \mathbf{X}_{2,m} = \mathbf{AU\Sigma V}^T\\
2. & \mathbf{U}^T\mathbf{X}_{2,m}\mathbf{V\Sigma}^{-1} = \mathbf{U}^{T}\mathbf{AU} = \mathbf{A'}\\
3. & \mathbf{A'}\mathbf{W} = \mathbf{W}\mathbf{\Lambda} \\
4. & \mathbf{\Phi} = \mathbf{X}^T\mathbf{V\Sigma}^{-1}\mathbf{W}
\end{array}
\end{equation}

If the system has low dimensional structure, the matrix $\mathbf{A'}$ can be further reduced by only keeping the first $r$ vectors in $\mathbf{U}$. The final transformation$\mathbf{\Phi}$ gives high-dimensional eigenvectors of the full matrix $\mathbf{A}$.

\citeasnoun{stevebrunton} suggests that DMD is, in spirit, a combination of principal component analysis and the Fourier transform in time. The fact that DMD exists in a regression framework there are a huge number of extensions that can be leveraged. In particular, \citeasnoun{stevebrunton} delves into combining DMD with compressed sensing. What is surprising is that the dynamics that are modeled by DMD are not necessarily linear. The matrix $\mathbf{A}$ is large enough to approximate nonlinear dynamics.

\section{Extended Dynamical Mode Decomposition (EDMD)}
\label{sec:edmd}

\section{Sparse Identification of Nonlinear Dynamics (SINDy)}
\label{sec:sindy}

\section{DMD with Irregularly Sampled Timesteps}