Forcing
The code implements forcing in various modules (currently in TwoDTurb
and BarotropicQG
). Forcing can be either deterministic or stochastic (random). For deterministic forcing the implementation is straightforward; for stochastic forcing there are two main train of thoughts: Itô calculus and Stratonovich calculus.
Both stochastic calculi give the same results. But once we decide to use one of the two calculi we have to remain consistent and use that calculus for everywhere. There is a lot of confusion and mostly the confusion stems from not using the same stochastic calculus consistently throughout the computation but rather interchanging between the two.
FourierFlows
uses Stratonovich calculus throughout the code. This choise was made because Stratonovich calculus works the same with both stochastic and deterministic forcing, i.e. with Stratonovich calculus we have the same chain rules for differentiation for stochastic functions as the chain rules we learn in normal-deterministic calculus). Therefore, the code written as is does not really "care" of what forcing the user implements.
If you are interested in learning more regarding the two stochastic calculi and how they are numerically implemented then read on; otherwise you can skip this section of the documentation and go to the Module Tutorials.
Stochastic Differential Equations (SDEs)
A differential equation in the form: \begin{equation} \frac{\dd x}{\dd t} = f(x)\com\quad x(t0)=0\com \end{equation} can also be written in an integral form: \begin{equation} x(t) = \int{t0}^{t} f(x(s))\,\dd s\per \end{equation} In a similar manner, a stochastic differential equation \begin{equation} \dd x = f(x)\,\dd t + g(x)\,\dd Wt\com\quad x(t0)=0\com \end{equation} with \dd Wt$ a white-noise process, can be written in an integral form as: \begin{equation} x(t) = \int{t0}^{t} f(x(s))\,\dd s + \int{t0}^{t} g(x(s))\,\dd W_s \per \end{equation} Of course now, the last integral is a stochastic integral and there is not a single straight-forward way of computing it –- there are a lot of different ways we can approximate it as a Riemannian sum and each of them leads to a different answer. The two most popular ways for computing such stochastic integrals are:
Because the white noise process is not continuous the two definitions do not converge to the same result; the two definitions give thoroughly different results. And to overcome that they come along with different chain rules, i.e., chain rules that are not necessarily the same as those in plain old calculus.
An SDE can be written also in differential form. Because we cannot formally form $\dd W/\dd t$, since $W$ is nowhere differentiable, we write an SDE in differential form as:
The circle in $g(x_t)\circ\dd W_t$ is used to differentiate between Itô or Stratonovich calculus.
A variable change $y=G(x)$ is done as follows according to the two different calculi:
The above are the so called stochastic chain rules. All derivatives of $G$ are evaluated at $x_t$.
It's easy to see that the extra drift-term in Itô's interpretation of the stochastic integral, i.e., ${\color{Green}\half g^2\, \dd^2G/\dd x^2}$ is exactly equal to the ensemble mean of the Stratonovich stochastic integral. This is that case because, by construction, the Itô stochastic integral has zero ensemble mean since at every instant the noise is multiplied with $g$ evaluated before the action of the noise occurs; $g$ and $\dd W$ are uncorrelated and thus: \begin{equation} {\color{Green}\laa g(xt)\dd Wt \raa =0}\quad\text{while}\quad {\color{Magenta}\laa g(xt)\circ\dd Wt \raa \ne 0}\per \end{equation} The above is demonstrated by evaluating the simple stochastic integral:
SDEs rarely can be solved in closed form; most often numerical solution of SDEs is brought to the rescue. Itô calculus has the advantage that is very easily implemented numerically. On the other hand, Stratonovich calculus coincides with that from normal calculus and this stems from the fact that it vies the white noise process as a series of colored noise processes with the de-correlation time tending to zero. This last fact is what made Stratonovich calculus more popular in the physics community. A nice discussion on the differences and similarities between the two calculi is done by van Kampen.
A simple Stochastic Differential Equation (SDE): the Ornstein–Uhlenbeck process
One of the simpler SDEs is the Ornstein–Uhlenbeck process. A variation of which is: \begin{equation} x(t) = \int{t0}^{t} -\mu x(s)\,\dd s + \int{t0}^{t} \sqrt{\sigma}\,\dd Ws \per\label{eq:OU} \end{equation} Note that in differential form this is: \begin{equation} \dd xt = -\mu xt \,\dd t + \sqrt{\sigma}\,\dd Ws \per\label{eq:1} \end{equation} Luckily, here there is no need to distinguish between Itô and Stratonovich. This is because $g$ is independent of $x(t)$. But we stress that this is only a fortuitous However, this is often not the case.
How do we time-step this SDE numerically? Let us assume a discretization of time into time-steps of $\tau$: $t_j=(j-1)\tau$. (What follows can be easily transfer to non-uniform time discretization.) With that, we denote $x_j\defn x(t_j)$. Then the Euler–Mayorama time-step scheme for \eqref{eq:1} is \begin{equation} x{j+1} = xj + (-\mu xj)\tau + \sqrt{\sigma}(W{j+1}-W_j)\per \end{equation}
Now let us ask the following question: How can we compute the work done by the noise? In other words, if we are interested in the evolution of the "energy" $E\defn \half x^2$, how is the noise term attributing in the growth of $E$? To answer that we first have to find the SDE that energy $E$ obeys. But, in doing so, it is important to adopt a single interpretation for computing stochastic integrals as now a transformation of variables is needed. That is, depending on whether we choose to interpret the stochastic integrals according to Itô or to Stratonovich calculus, $E$ evolves as:
\begin{equation} {\color{Green}\text{Itô}: \dd Et = \left( -2\mu Et + \half \sigma \right)\dd t + xt \sqrt{\sigma}\dd Wt}\com\label{eq:E_ito} \end{equation}
\begin{equation} {\color{Magenta}\text{Stratonovich}: \dd Et = -2\mu Et \dd t + xt\circ \sqrt{\sigma}\dd Wt}\per\label{eq:E_str} \end{equation}
How do we compute the work $P$ done by the noise? Thus the work done by the stochastic forcing is:
Say we didn't know the rules for transforming Stratonovich to Itô and we were wondering what is the extra drift term we have to include in the Itô formulations, i.e. the $\half\sigma$ term. We can compute the Itô's drift-term using that it is exactly equal to $\la x_t\circ\sqrt{\sigma}\dd W_t\ra$; and for the latter we can use the "usual" calculus. That is, rewrite \eqref{eq:OU} as:
\begin{equation} \dot{x} = -\mu x + \xi\com\label{eq:OUcont} \end{equation}
where $\xi(t)$ is understood to be the "continuous" version of the white-noise process which is formally only understood in terms of distributions. The forcing $\xi$ has the properties:
Thus we need to compute $\la P_t \ra = \la x(t) \xi(t) \ra$. But \eqref{eq:OUcont} has formally the solution:
and utilizing the above we get
Above we used that $\int_0^t\delta(t-s)\dd s = \half$, which is consistent with Stratonovich symmetric interpretation of stochastic integrals.
Numerical implementation
How do we time-step \eqref{eq:E_ito}? We use the Euler–Maruyama time-stepping scheme:
However, we cannot use Euler–Maruyama for time-stepping \eqref{eq:Estr} since the Euler–Maruyama is "Itô"-thinking. To time-step \eqref{eq:Estr} we have to approximate $g$ in the middle of the time-step. There are many ways to do that, one of which is the, so called, Euler–Heun method:
Figure above shows a comparison of the energy evolution as done from:
- direct computation as $\half x_t^2$,
- time-integration of \eqref{eq:E_ito}, and
- time-integration of \eqref{eq:E_str}.
Figures below show the ensemble mean energy budgets (using 1000 ensemble members) as computed using Itô and Stratonovich. For the energy budget to close we have to be consistent: if we time-step the energy equation based on Stratonovich calculus then we must compute the work also according to Stratonovich. (For more details see examples/forcing/simpleSDEItoStratonovich.jl
.
A simple Stochastic Partial Differential Equation (SPDE)
We want now to transfer all the knowledge we got from the previous sections to PDEs. In particular we'll focus on the simple SPDE:
\begin{equation} \partial_t \nabla^2\psi(\bx, t) = -\mu \nabla^2\psi(\bx, t) + \xi(\bx,t)\com\label{eq:PDEcont} \end{equation}
which is also equivalently written as:
\begin{equation} \dd \nabla^2\psit(\bx) = -\mu \nabla^2\psit(\bx) \dd t + \sqrt{\sigma} \dd W_t(\bx) \end{equation}
The form \eqref{eq:PDEcont} is the continuous version understood in the Stratonovich interpretation (similar to \eqref{eq:OUcont}). Thus, forcing $\xi$ obeys now:
that is the forcing is white in time but spatially correlated; its spatial correlation is prescribed by the function $Q$ which is, necessarily, homogeneous in all its arguments (see discussion by Constantinou (see Appendix A).
The above describes the vorticity evolution of a two-dimensional fluid $\nabla^2\psi$ which is stochastically forced while dissipated by linear drag $\mu$. The energy of the fluid is:
where the overbar denotes average over $x$ and $y$. To obtain the energy equation we multiply \eqref{eq:PDEcont} with $-\psi$ and average over the whole domain. Thus, the work done by the forcing is given by the term:
but the above is a stochastic integral and it is meaningless without a rule for computing the stochastic integral.
Numerically, the work done by the forcing can be obtained Stratonovich-wise as: \begin{align} Pj = -\,\overline{\frac{\psi(\bx,tj)+\psi(\bx,t{j+1})}{2} \xi(\bx,t{j+1}) }^{x,y}\com \end{align} or Itô-wise \begin{align} Pj = -\,\overline{ \psi(\bx,tj) \xi(\bx,t_{j+1}) }^{x,y} + \text{drift}\com \end{align} But how much is the Itô drift term in this case? As in the previous section, the drift is precisely the ensemble mean of the Stratonovich work, i.e.:
But again the above can be computed relatively easy if we use the "formal" solution of \eqref{eq:PDEcont}:
which implies
Thus, the drift, or in this case the mean energy input rate by the stochastic forcing, is precisely determined from the spatial correlation of the forcing. Let us denote:
Therefore, work for a single forcing realization is computed numerically as:
Remember, previously the work done by the stochastic forcing was:
and by sampling over various forcing realizations:
The code uses Stratonovich. For example, the work done by the forcing in the TwoDTurb
module is computed based on \eqref{eq:PtStrat} with the function
@inline function work(s, v::ForcedVars, g)
@. v.Uh = g.invKKrsq * (v.prevsol + s.sol)/2.0 * conj(v.Fh)
1/(g.Lx*g.Ly)*FourierFlows.parsevalsum(v.Uh, g)
end
A bit-less-simple SPDE
It turns out that nothing changes if we include the nonlinear terms in the vorticity equation: \begin{equation} \partial_t \nabla^2\psi(\bx, t) + \J(\psi,\nabla^2\psi) = -\mu \nabla^2\psi(\bx, t) + \xi(\bx,t)\per\per\label{eq:PDEcont2} \end{equation} The nonlinearity does not alter the Itô drift; thus the ensemble mean energy input by the stochastic forcing, remains the same. We can easily verify this from the "formal" solution of \eqref{eq:PDEcont2}:
When multiplied with $\xi(\bx,t)$ the last term vanishes since its only non-zero contribution comes from the point $s=t$ which is of measure zero (in the integrated sense).
Figure below shows the energy budgets for a numerical solution of \eqref{eq:PDEcont2} starting from rest ($\psi(\bx,0)=0$) in a doubly periodic square domain of size $L$ (examples/twodturb/IsotropicRingForcing.jl
). The forcing was prescribed to have power in a narrow ring in wavenumber space:
with $k_f L/(2\pi) = 12$ and $\delta_f L/(2\pi) = 2$. The mean energy input rate was set to $\varepsilon = 0.1$.