Added the vertical smoothing via FFTs

This commit is contained in:
TechWizzart 2020-09-19 20:12:22 +02:00
parent 612dcb100b
commit 9c8baa2cd6
No known key found for this signature in database
GPG Key ID: 151E66B6CEF55F2E
5 changed files with 11 additions and 7 deletions

View File

@ -55,4 +55,5 @@ only applies to variables in code, every symbol in equations are explained at th
\item $smooth_u$: The smoothing parameter for the $u$ component of the velocity. \item $smooth_u$: The smoothing parameter for the $u$ component of the velocity.
\item $smooth_v$: The smoothing parameter for the $v$ component of the velocity. \item $smooth_v$: The smoothing parameter for the $v$ component of the velocity.
\item $smooth_w$: The smoothing parameter for the $w$ component of the velocity. \item $smooth_w$: The smoothing parameter for the $w$ component of the velocity.
\item $smooth_{vert}$: The smoothing parameter for the vertical part of the velocities.
\end{itemize} \end{itemize}

View File

@ -162,7 +162,8 @@ potential temperature and vice versa. The whole process of moving temperature ar
\autoref{eq:thermal potential} and \autoref{eq:potential temp} into code and create an overarching function that calls the previously mentioned equations. Let us start with \autoref{eq:thermal potential} and \autoref{eq:potential temp} into code and create an overarching function that calls the previously mentioned equations. Let us start with
\autoref{eq:thermal potential} which is described in \autoref{alg:temp to pot}. Note that $\frac{R}{C_a}$ does not change as they are constants, therefore we can precompute them which saves quite \autoref{eq:thermal potential} which is described in \autoref{alg:temp to pot}. Note that $\frac{R}{C_a}$ does not change as they are constants, therefore we can precompute them which saves quite
a bit of time (namely $O(n^3)$ divisions, where $n$ is the length of each dimension of $T_a$). Also note that we can inverse the process by inserting a minus in the exponent and swapping $T_a$ a bit of time (namely $O(n^3)$ divisions, where $n$ is the length of each dimension of $T_a$). Also note that we can inverse the process by inserting a minus in the exponent and swapping $T_a$
and $\theta$, which can easily be done in the call to \autoref{alg:temp to pot}. and $\theta$, which can easily be done in the call to \autoref{alg:temp to pot}. To avoid confusion we rename $p_0$ to $p_r$ as we talk about a reference pressure, instead of the already defined
pressure from a previous calculation round.
\begin{algorithm} \begin{algorithm}
\SetKwInOut{Input}{Input} \SetKwInOut{Input}{Input}
@ -176,9 +177,9 @@ and $\theta$, which can easily be done in the call to \autoref{alg:temp to pot}.
} }
\For{$i \leftarrow 0$ \KwTo $T_a.length$}{ \For{$i \leftarrow 0$ \KwTo $T_a.length$}{
\For{$j \leftarrow 0$ \KwTo $T_a[i].length$}{ \For{$j \leftarrow 0$ \KwTo $T_a[i].length$}{
$p_0 \leftarrow p[i, j 0]$ \; $p_r \leftarrow p[i, j 0]$ \;
\For{$k \leftarrow 0$ \KwTo $T_a[i, j].length$}{ \For{$k \leftarrow 0$ \KwTo $T_a[i, j].length$}{
$\theta[i, j, k] \leftarrow T_a[i, j, k] (\frac{p[i, j, k]}{p_0})^{\kappa}$ $\theta[i, j, k] \leftarrow T_a[i, j, k] (\frac{p[i, j, k]}{p_r})^{\kappa}$
} }
} }
} }

View File

@ -110,6 +110,7 @@ definitions can be found in \autoref{alg:model constants}. What the $adv$ boolea
$smooth_u \leftarrow 0.8$ \Comment*[l]{The smoothing parameter for the $u$ component of the velocity} $smooth_u \leftarrow 0.8$ \Comment*[l]{The smoothing parameter for the $u$ component of the velocity}
$smooth_v \leftarrow 0.8$ \Comment*[l]{The smoothing parameter for the $v$ component of the velocity} $smooth_v \leftarrow 0.8$ \Comment*[l]{The smoothing parameter for the $v$ component of the velocity}
$smooth_w \leftarrow 0.3$ \Comment*[l]{The smoothing parameter for the $w$ component of the velocity} $smooth_w \leftarrow 0.3$ \Comment*[l]{The smoothing parameter for the $w$ component of the velocity}
$smooth_{vert} \leftarrow 0.3$ \Comment*[l]{The smoothing parameter for the vertical part of the velocities}
$count \leftarrow 0$ \; $count \leftarrow 0$ \;
\For{$j \in [0, top]$}{ \For{$j \in [0, top]$}{
$heights[j] \leftarrow count$ \Comment*[l]{The height of a layer (\si{m})} $heights[j] \leftarrow count$ \Comment*[l]{The height of a layer (\si{m})}

View File

@ -150,7 +150,7 @@ do not consider the data that occurs so infrequently that it means nothing. We d
\begin{algorithm} \begin{algorithm}
$u \leftarrow \texttt{Smooth}(u, smooth_u)$ \; $u \leftarrow \texttt{Smooth}(u, smooth_u)$ \;
$v \leftarrow \texttt{Smooth}(v, smooth_v)$ \; $v \leftarrow \texttt{Smooth}(v, smooth_v)$ \;
$w \leftarrow \texttt{Smooth}(w, smooth_w)$ \; $w \leftarrow \texttt{Smooth}(w, smooth_w, smooth_{vert})$ \;
\caption{Smoothing the velocity} \caption{Smoothing the velocity}
\label{alg:smoothv} \label{alg:smoothv}
\end{algorithm} \end{algorithm}

View File

@ -302,12 +302,12 @@ a later point in the future. It will then be found here, so you will have to sta
With that out of the way (or rather on the TODO list), we need to create a smoothing operation out of it. We do this in \autoref{alg:smooth}. Keep in mind that \texttt{FFT} the call is to the With that out of the way (or rather on the TODO list), we need to create a smoothing operation out of it. We do this in \autoref{alg:smooth}. Keep in mind that \texttt{FFT} the call is to the
multidimensional Fast Fourier Transform algorithm, \texttt{IFFT} the call to the inverse of the multidimensional Fast Fourier Transform algorithm (also on the TODO list) and that the $int()$ multidimensional Fast Fourier Transform algorithm, \texttt{IFFT} the call to the inverse of the multidimensional Fast Fourier Transform algorithm (also on the TODO list) and that the $int()$
function ensures that the number in brackets is an integer. Also note that the inverse of the FFT might give complex answers, and we only want real answers which the $.real$ ensures. We only function ensures that the number in brackets is an integer. Also note that the inverse of the FFT might give complex answers, and we only want real answers which the $.real$ ensures. We only
take the real part and return that. take the real part and return that. $v$ is an optional parameter with default value $0.5$ which does absolutely nothing in this algorithm.
\begin{algorithm} \begin{algorithm}
\SetKwInOut{Input}{Input} \SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output} \SetKwInOut{Output}{Output}
\Input{Array $a$, smoothing factor $s$} \Input{Array $a$, smoothing factor $s$, vertical smoothing factor $v \leftarrow 0.5$}
\Output{Array $A$ with less variation} \Output{Array $A$ with less variation}
$nlat \leftarrow a.length$ \; $nlat \leftarrow a.length$ \;
$nlon \leftarrow a[0].length$ \; $nlon \leftarrow a[0].length$ \;
@ -315,6 +315,7 @@ take the real part and return that.
$temp \leftarrow \texttt{FFT}(a)$ \; $temp \leftarrow \texttt{FFT}(a)$ \;
$temp[int(nlat s):int(nlat(1 - s)),:,:] \leftarrow 0$ \; $temp[int(nlat s):int(nlat(1 - s)),:,:] \leftarrow 0$ \;
$temp[:,int(nlon s):int(nlon(1 - s)),:] \leftarrow 0$ \; $temp[:,int(nlon s):int(nlon(1 - s)),:] \leftarrow 0$ \;
$temp[:,:,int(nlevels v):int(nlevels(1 - v))] \leftarrow 0$ \;
\Return $\texttt{IFFT}(temp).real$ \; \Return $\texttt{IFFT}(temp).real$ \;
\caption{Smoothing function} \caption{Smoothing function}
\label{alg:smooth} \label{alg:smooth}