\hypertarget{namespacepqm__functions}{}\section{pqm\+\_\+functions Module Reference}
\label{namespacepqm__functions}\index{pqm\_functions@{pqm\_functions}}


\subsection{Detailed Description}
Piecewise quartic reconstruction functions. 

Date of creation\+: 2008.\+06.\+06 L. White.

This module contains routines that handle one-\/dimensionnal finite volume reconstruction using the piecewise quartic method (P\+QM). \subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacepqm__functions_afa6f7b5430011f03c428b329c5f42fae}{pqm\+\_\+reconstruction}} (N, h, u, edge\+\_\+values, edge\+\_\+slopes, ppoly\+\_\+coef, h\+\_\+neglect, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Reconstruction by quartic polynomials within each cell. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacepqm__functions_aab9f3108956943c39ed2d4b675d78021}{pqm\+\_\+limiter}} (N, h, u, edge\+\_\+values, edge\+\_\+slopes, h\+\_\+neglect, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Limit the piecewise quartic method reconstruction. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacepqm__functions_ad970064d6c3540fd00dff2453d0778d7}{pqm\+\_\+boundary\+\_\+extrapolation}} (N, h, u, edge\+\_\+values, ppoly\+\_\+coef)
\begin{DoxyCompactList}\small\item\em Reconstruction by parabolas within boundary cells. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacepqm__functions_a1e0e86d8470dd334b9cd676f511f6720}{pqm\+\_\+boundary\+\_\+extrapolation\+\_\+v1}} (N, h, u, edge\+\_\+values, edge\+\_\+slopes, ppoly\+\_\+coef, h\+\_\+neglect)
\begin{DoxyCompactList}\small\item\em Reconstruction by parabolas within boundary cells. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacepqm__functions_a3bd59442a660e0e66c29603c992932e6}\label{namespacepqm__functions_a3bd59442a660e0e66c29603c992932e6}} 
real, parameter \mbox{\hyperlink{namespacepqm__functions_a3bd59442a660e0e66c29603c992932e6}{hneglect\+\_\+dflt}} = 1.E-\/30
\begin{DoxyCompactList}\small\item\em Default negligible cell thickness. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacepqm__functions_ad970064d6c3540fd00dff2453d0778d7}\label{namespacepqm__functions_ad970064d6c3540fd00dff2453d0778d7}} 
\index{pqm\_functions@{pqm\_functions}!pqm\_boundary\_extrapolation@{pqm\_boundary\_extrapolation}}
\index{pqm\_boundary\_extrapolation@{pqm\_boundary\_extrapolation}!pqm\_functions@{pqm\_functions}}
\subsubsection{\texorpdfstring{pqm\_boundary\_extrapolation()}{pqm\_boundary\_extrapolation()}}
{\footnotesize\ttfamily subroutine, public pqm\+\_\+functions\+::pqm\+\_\+boundary\+\_\+extrapolation (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{N,  }\item[{real, dimension(\+:), intent(in)}]{h,  }\item[{real, dimension(\+:), intent(in)}]{u,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{edge\+\_\+values,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{ppoly\+\_\+coef }\end{DoxyParamCaption})}



Reconstruction by parabolas within boundary cells. 

The following explanations apply to the left boundary cell. The same reasoning holds for the right boundary cell.

A parabola needs to be built in the cell and requires three degrees of freedom, which are the right edge value and slope and the cell average. The right edge values and slopes are taken to be that of the neighboring cell (i.\+e., the left edge value and slope of the neighboring cell). The resulting parabola is not necessarily monotonic and the traditional P\+PM limiter is used to modify one of the edge values in order to yield a monotonic parabola.

It is assumed that the size of the array \textquotesingle{}u\textquotesingle{} is equal to the number of cells defining \textquotesingle{}grid\textquotesingle{} and \textquotesingle{}ppoly\textquotesingle{}. No consistency check is performed here. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n} & Number of cells \\
\hline
\mbox{\texttt{ in}}  & {\em h} & cell widths (size N) \mbox{[}H\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em u} & cell averages (size N) \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em edge\+\_\+values} & Edge value of polynomial \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em ppoly\+\_\+coef} & Coefficients of polynomial, mainly \mbox{[}A\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 355 of file P\+Q\+M\+\_\+functions.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{355   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: N\textcolor{comment}{ !< Number of cells}}
\DoxyCodeLine{356 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{ !< cell widths (size N) [H]}}
\DoxyCodeLine{357 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{ !< cell averages (size N) [A]}}
\DoxyCodeLine{358 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_values\textcolor{comment}{    !< Edge value of polynomial [A]}}
\DoxyCodeLine{359 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: ppoly\_coef\textcolor{comment}{ !< Coefficients of polynomial, mainly [A]}}
\DoxyCodeLine{360   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{361   \textcolor{keywordtype}{integer}       :: i0, i1}
\DoxyCodeLine{362 \textcolor{keywordtype}{  real}          :: u0, u1}
\DoxyCodeLine{363 \textcolor{keywordtype}{  real}          :: h0, h1}
\DoxyCodeLine{364 \textcolor{keywordtype}{  real}          :: a, b, c, d, e}
\DoxyCodeLine{365 \textcolor{keywordtype}{  real}          :: u0\_l, u0\_r}
\DoxyCodeLine{366 \textcolor{keywordtype}{  real}          :: u1\_l, u1\_r}
\DoxyCodeLine{367 \textcolor{keywordtype}{  real}          :: slope}
\DoxyCodeLine{368 \textcolor{keywordtype}{  real}          :: exp1, exp2}
\DoxyCodeLine{369 }
\DoxyCodeLine{370   \textcolor{comment}{! ----- Left boundary -----}}
\DoxyCodeLine{371   i0 = 1}
\DoxyCodeLine{372   i1 = 2}
\DoxyCodeLine{373   h0 = h(i0)}
\DoxyCodeLine{374   h1 = h(i1)}
\DoxyCodeLine{375   u0 = u(i0)}
\DoxyCodeLine{376   u1 = u(i1)}
\DoxyCodeLine{377 }
\DoxyCodeLine{378   \textcolor{comment}{! Compute the left edge slope in neighboring cell and express it in}}
\DoxyCodeLine{379   \textcolor{comment}{! the global coordinate system}}
\DoxyCodeLine{380   b = ppoly\_coef(i1,2)}
\DoxyCodeLine{381   u1\_r = b *(h0/h1)     \textcolor{comment}{! derivative evaluated at xi = 0.0,}}
\DoxyCodeLine{382                         \textcolor{comment}{! expressed w.r.t. xi (local coord. system)}}
\DoxyCodeLine{383 }
\DoxyCodeLine{384   \textcolor{comment}{! Limit the right slope by the PLM limited slope}}
\DoxyCodeLine{385   slope = 2.0 * ( u1 - u0 )}
\DoxyCodeLine{386   \textcolor{keywordflow}{if} ( abs(u1\_r) > abs(slope) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{387     u1\_r = slope}
\DoxyCodeLine{388 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{389 }
\DoxyCodeLine{390   \textcolor{comment}{! The right edge value in the boundary cell is taken to be the left}}
\DoxyCodeLine{391   \textcolor{comment}{! edge value in the neighboring cell}}
\DoxyCodeLine{392   u0\_r = edge\_values(i1,1)}
\DoxyCodeLine{393 }
\DoxyCodeLine{394   \textcolor{comment}{! Given the right edge value and slope, we determine the left}}
\DoxyCodeLine{395   \textcolor{comment}{! edge value and slope by computing the parabola as determined by}}
\DoxyCodeLine{396   \textcolor{comment}{! the right edge value and slope and the boundary cell average}}
\DoxyCodeLine{397   u0\_l = 3.0 * u0 + 0.5 * u1\_r - 2.0 * u0\_r}
\DoxyCodeLine{398 }
\DoxyCodeLine{399   \textcolor{comment}{! Apply the traditional PPM limiter}}
\DoxyCodeLine{400   exp1 = (u0\_r - u0\_l) * (u0 - 0.5*(u0\_l+u0\_r))}
\DoxyCodeLine{401   exp2 = (u0\_r - u0\_l) * (u0\_r - u0\_l) / 6.0}
\DoxyCodeLine{402 }
\DoxyCodeLine{403   \textcolor{keywordflow}{if} ( exp1 > exp2 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{404     u0\_l = 3.0 * u0 - 2.0 * u0\_r}
\DoxyCodeLine{405 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{406 }
\DoxyCodeLine{407   \textcolor{keywordflow}{if} ( exp1 < -exp2 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{408     u0\_r = 3.0 * u0 - 2.0 * u0\_l}
\DoxyCodeLine{409 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{410 }
\DoxyCodeLine{411   edge\_values(i0,1) = u0\_l}
\DoxyCodeLine{412   edge\_values(i0,2) = u0\_r}
\DoxyCodeLine{413 }
\DoxyCodeLine{414   a = u0\_l}
\DoxyCodeLine{415   b = 6.0 * u0 - 4.0 * u0\_l - 2.0 * u0\_r}
\DoxyCodeLine{416   c = 3.0 * ( u0\_r + u0\_l - 2.0 * u0 )}
\DoxyCodeLine{417 }
\DoxyCodeLine{418   \textcolor{comment}{! The quartic is reduced to a parabola in the boundary cell}}
\DoxyCodeLine{419   ppoly\_coef(i0,1) = a}
\DoxyCodeLine{420   ppoly\_coef(i0,2) = b}
\DoxyCodeLine{421   ppoly\_coef(i0,3) = c}
\DoxyCodeLine{422   ppoly\_coef(i0,4) = 0.0}
\DoxyCodeLine{423   ppoly\_coef(i0,5) = 0.0}
\DoxyCodeLine{424 }
\DoxyCodeLine{425   \textcolor{comment}{! ----- Right boundary -----}}
\DoxyCodeLine{426   i0 = n-1}
\DoxyCodeLine{427   i1 = n}
\DoxyCodeLine{428   h0 = h(i0)}
\DoxyCodeLine{429   h1 = h(i1)}
\DoxyCodeLine{430   u0 = u(i0)}
\DoxyCodeLine{431   u1 = u(i1)}
\DoxyCodeLine{432 }
\DoxyCodeLine{433   \textcolor{comment}{! Compute the right edge slope in neighboring cell and express it in}}
\DoxyCodeLine{434   \textcolor{comment}{! the global coordinate system}}
\DoxyCodeLine{435   b = ppoly\_coef(i0,2)}
\DoxyCodeLine{436   c = ppoly\_coef(i0,3)}
\DoxyCodeLine{437   d = ppoly\_coef(i0,4)}
\DoxyCodeLine{438   e = ppoly\_coef(i0,5)}
\DoxyCodeLine{439   u1\_l = (b + 2*c + 3*d + 4*e)      \textcolor{comment}{! derivative evaluated at xi = 1.0}}
\DoxyCodeLine{440   u1\_l = u1\_l * (h1/h0)}
\DoxyCodeLine{441 }
\DoxyCodeLine{442   \textcolor{comment}{! Limit the left slope by the PLM limited slope}}
\DoxyCodeLine{443   slope = 2.0 * ( u1 - u0 )}
\DoxyCodeLine{444   \textcolor{keywordflow}{if} ( abs(u1\_l) > abs(slope) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{445     u1\_l = slope}
\DoxyCodeLine{446 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{447 }
\DoxyCodeLine{448   \textcolor{comment}{! The left edge value in the boundary cell is taken to be the right}}
\DoxyCodeLine{449   \textcolor{comment}{! edge value in the neighboring cell}}
\DoxyCodeLine{450   u0\_l = edge\_values(i0,2)}
\DoxyCodeLine{451 }
\DoxyCodeLine{452   \textcolor{comment}{! Given the left edge value and slope, we determine the right}}
\DoxyCodeLine{453   \textcolor{comment}{! edge value and slope by computing the parabola as determined by}}
\DoxyCodeLine{454   \textcolor{comment}{! the left edge value and slope and the boundary cell average}}
\DoxyCodeLine{455   u0\_r = 3.0 * u1 - 0.5 * u1\_l - 2.0 * u0\_l}
\DoxyCodeLine{456 }
\DoxyCodeLine{457   \textcolor{comment}{! Apply the traditional PPM limiter}}
\DoxyCodeLine{458   exp1 = (u0\_r - u0\_l) * (u1 - 0.5*(u0\_l+u0\_r))}
\DoxyCodeLine{459   exp2 = (u0\_r - u0\_l) * (u0\_r - u0\_l) / 6.0}
\DoxyCodeLine{460 }
\DoxyCodeLine{461   \textcolor{keywordflow}{if} ( exp1 > exp2 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{462     u0\_l = 3.0 * u1 - 2.0 * u0\_r}
\DoxyCodeLine{463 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{464 }
\DoxyCodeLine{465   \textcolor{keywordflow}{if} ( exp1 < -exp2 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{466     u0\_r = 3.0 * u1 - 2.0 * u0\_l}
\DoxyCodeLine{467 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{468 }
\DoxyCodeLine{469   edge\_values(i1,1) = u0\_l}
\DoxyCodeLine{470   edge\_values(i1,2) = u0\_r}
\DoxyCodeLine{471 }
\DoxyCodeLine{472   a = u0\_l}
\DoxyCodeLine{473   b = 6.0 * u1 - 4.0 * u0\_l - 2.0 * u0\_r}
\DoxyCodeLine{474   c = 3.0 * ( u0\_r + u0\_l - 2.0 * u1 )}
\DoxyCodeLine{475 }
\DoxyCodeLine{476   \textcolor{comment}{! The quartic is reduced to a parabola in the boundary cell}}
\DoxyCodeLine{477   ppoly\_coef(i1,1) = a}
\DoxyCodeLine{478   ppoly\_coef(i1,2) = b}
\DoxyCodeLine{479   ppoly\_coef(i1,3) = c}
\DoxyCodeLine{480   ppoly\_coef(i1,4) = 0.0}
\DoxyCodeLine{481   ppoly\_coef(i1,5) = 0.0}
\DoxyCodeLine{482 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacepqm__functions_a1e0e86d8470dd334b9cd676f511f6720}\label{namespacepqm__functions_a1e0e86d8470dd334b9cd676f511f6720}} 
\index{pqm\_functions@{pqm\_functions}!pqm\_boundary\_extrapolation\_v1@{pqm\_boundary\_extrapolation\_v1}}
\index{pqm\_boundary\_extrapolation\_v1@{pqm\_boundary\_extrapolation\_v1}!pqm\_functions@{pqm\_functions}}
\subsubsection{\texorpdfstring{pqm\_boundary\_extrapolation\_v1()}{pqm\_boundary\_extrapolation\_v1()}}
{\footnotesize\ttfamily subroutine, public pqm\+\_\+functions\+::pqm\+\_\+boundary\+\_\+extrapolation\+\_\+v1 (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{N,  }\item[{real, dimension(\+:), intent(in)}]{h,  }\item[{real, dimension(\+:), intent(in)}]{u,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{edge\+\_\+values,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{edge\+\_\+slopes,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{ppoly\+\_\+coef,  }\item[{real, intent(in), optional}]{h\+\_\+neglect }\end{DoxyParamCaption})}



Reconstruction by parabolas within boundary cells. 

The following explanations apply to the left boundary cell. The same reasoning holds for the right boundary cell.

A parabola needs to be built in the cell and requires three degrees of freedom, which are the right edge value and slope and the cell average. The right edge values and slopes are taken to be that of the neighboring cell (i.\+e., the left edge value and slope of the neighboring cell). The resulting parabola is not necessarily monotonic and the traditional P\+PM limiter is used to modify one of the edge values in order to yield a monotonic parabola.

It is assumed that the size of the array \textquotesingle{}u\textquotesingle{} is equal to the number of cells defining \textquotesingle{}grid\textquotesingle{} and \textquotesingle{}ppoly\textquotesingle{}. No consistency check is performed here. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n} & Number of cells \\
\hline
\mbox{\texttt{ in}}  & {\em h} & cell widths (size N) \mbox{[}H\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em u} & cell averages (size N) \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em edge\+\_\+values} & Edge value of polynomial \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em edge\+\_\+slopes} & Edge slope of polynomial \mbox{[}A H-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em ppoly\+\_\+coef} & Coefficients of polynomial, mainly \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions \mbox{[}H\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 502 of file P\+Q\+M\+\_\+functions.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{502   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: N\textcolor{comment}{ !< Number of cells}}
\DoxyCodeLine{503 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{ !< cell widths (size N) [H]}}
\DoxyCodeLine{504 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{ !< cell averages (size N) [A]}}
\DoxyCodeLine{505 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_values\textcolor{comment}{    !< Edge value of polynomial [A]}}
\DoxyCodeLine{506 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_slopes\textcolor{comment}{    !< Edge slope of polynomial [A H-1]}}
\DoxyCodeLine{507 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: ppoly\_coef\textcolor{comment}{ !< Coefficients of polynomial, mainly [A]}}
\DoxyCodeLine{508 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{  !< A negligibly small width for}}
\DoxyCodeLine{509 \textcolor{comment}{                                           !! the purpose of cell reconstructions [H]}}
\DoxyCodeLine{510   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{511   \textcolor{keywordtype}{integer} :: i0, i1}
\DoxyCodeLine{512   \textcolor{keywordtype}{integer} :: inflexion\_l}
\DoxyCodeLine{513   \textcolor{keywordtype}{integer} :: inflexion\_r}
\DoxyCodeLine{514 \textcolor{keywordtype}{  real}    :: u0, u1, um}
\DoxyCodeLine{515 \textcolor{keywordtype}{  real}    :: h0, h1}
\DoxyCodeLine{516 \textcolor{keywordtype}{  real}    :: a, b, c, d, e}
\DoxyCodeLine{517 \textcolor{keywordtype}{  real}    :: ar, br, beta}
\DoxyCodeLine{518 \textcolor{keywordtype}{  real}    :: u0\_l, u0\_r}
\DoxyCodeLine{519 \textcolor{keywordtype}{  real}    :: u1\_l, u1\_r}
\DoxyCodeLine{520 \textcolor{keywordtype}{  real}    :: u\_plm}
\DoxyCodeLine{521 \textcolor{keywordtype}{  real}    :: slope}
\DoxyCodeLine{522 \textcolor{keywordtype}{  real}    :: alpha1, alpha2, alpha3}
\DoxyCodeLine{523 \textcolor{keywordtype}{  real}    :: rho, sqrt\_rho}
\DoxyCodeLine{524 \textcolor{keywordtype}{  real}    :: gradient1, gradient2}
\DoxyCodeLine{525 \textcolor{keywordtype}{  real}    :: x1, x2}
\DoxyCodeLine{526 \textcolor{keywordtype}{  real}    :: hNeglect}
\DoxyCodeLine{527 }
\DoxyCodeLine{528   hneglect = hneglect\_dflt ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect)) hneglect = h\_neglect}
\DoxyCodeLine{529 }
\DoxyCodeLine{530   \textcolor{comment}{! ----- Left boundary (TOP) -----}}
\DoxyCodeLine{531   i0 = 1}
\DoxyCodeLine{532   i1 = 2}
\DoxyCodeLine{533   h0 = h(i0)}
\DoxyCodeLine{534   h1 = h(i1)}
\DoxyCodeLine{535   u0 = u(i0)}
\DoxyCodeLine{536   u1 = u(i1)}
\DoxyCodeLine{537   um = u0}
\DoxyCodeLine{538 }
\DoxyCodeLine{539   \textcolor{comment}{! Compute real slope and express it w.r.t. local coordinate system}}
\DoxyCodeLine{540   \textcolor{comment}{! within boundary cell}}
\DoxyCodeLine{541   slope = 2.0 * ( u1 - u0 ) / ( ( h0 + h1 ) + hneglect )}
\DoxyCodeLine{542   slope = slope * h0}
\DoxyCodeLine{543 }
\DoxyCodeLine{544   \textcolor{comment}{! The right edge value and slope of the boundary cell are taken to be the}}
\DoxyCodeLine{545   \textcolor{comment}{! left edge value and slope of the adjacent cell}}
\DoxyCodeLine{546   a = ppoly\_coef(i1,1)}
\DoxyCodeLine{547   b = ppoly\_coef(i1,2)}
\DoxyCodeLine{548 }
\DoxyCodeLine{549   u0\_r = a          \textcolor{comment}{! edge value}}
\DoxyCodeLine{550   u1\_r = b / (h1 + hneglect) \textcolor{comment}{! edge slope (w.r.t. global coord.)}}
\DoxyCodeLine{551 }
\DoxyCodeLine{552   \textcolor{comment}{! Compute coefficient for rational function based on mean and right}}
\DoxyCodeLine{553   \textcolor{comment}{! edge value and slope}}
\DoxyCodeLine{554   \textcolor{keywordflow}{if} (u1\_r /= 0.) \textcolor{keywordflow}{then} \textcolor{comment}{! HACK by AJA}}
\DoxyCodeLine{555     beta = 2.0 * ( u0\_r - um ) / ( (h0 + hneglect)*u1\_r) - 1.0}
\DoxyCodeLine{556   \textcolor{keywordflow}{else}}
\DoxyCodeLine{557     beta = 0.}
\DoxyCodeLine{558 \textcolor{keywordflow}{  endif} \textcolor{comment}{! HACK by AJA}}
\DoxyCodeLine{559   br = u0\_r + beta*u0\_r - um}
\DoxyCodeLine{560   ar = um + beta*um - br}
\DoxyCodeLine{561 }
\DoxyCodeLine{562   \textcolor{comment}{! Left edge value estimate based on rational function}}
\DoxyCodeLine{563   u0\_l = ar}
\DoxyCodeLine{564 }
\DoxyCodeLine{565   \textcolor{comment}{! Edge value estimate based on PLM}}
\DoxyCodeLine{566   u\_plm = um - 0.5 * slope}
\DoxyCodeLine{567 }
\DoxyCodeLine{568   \textcolor{comment}{! Check whether the left edge value is bounded by the mean and}}
\DoxyCodeLine{569   \textcolor{comment}{! the PLM edge value. If so, keep it and compute left edge slope}}
\DoxyCodeLine{570   \textcolor{comment}{! based on the rational function. If not, keep the PLM edge value and}}
\DoxyCodeLine{571   \textcolor{comment}{! compute corresponding slope.}}
\DoxyCodeLine{572   \textcolor{keywordflow}{if} ( abs(um-u0\_l) < abs(um-u\_plm) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{573     u1\_l = 2.0 * ( br - ar*beta)}
\DoxyCodeLine{574     u1\_l = u1\_l / (h0 + hneglect)}
\DoxyCodeLine{575   \textcolor{keywordflow}{else}}
\DoxyCodeLine{576     u0\_l = u\_plm}
\DoxyCodeLine{577     u1\_l = slope / (h0 + hneglect)}
\DoxyCodeLine{578 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{579 }
\DoxyCodeLine{580   \textcolor{comment}{! Monotonize quartic}}
\DoxyCodeLine{581   inflexion\_l = 0}
\DoxyCodeLine{582 }
\DoxyCodeLine{583   a = u0\_l}
\DoxyCodeLine{584   b = h0 * u1\_l}
\DoxyCodeLine{585   c = 30.0 * um - 12.0*u0\_r - 18.0*u0\_l + 1.5*h0*(u1\_r - 3.0*u1\_l)}
\DoxyCodeLine{586   d = -60.0 * um + h0 *(6.0*u1\_l - 4.0*u1\_r) + 28.0*u0\_r + 32.0*u0\_l}
\DoxyCodeLine{587   e = 30.0 * um + 2.5*h0*(u1\_r - u1\_l) - 15.0*(u0\_l + u0\_r)}
\DoxyCodeLine{588 }
\DoxyCodeLine{589   alpha1 = 6*e}
\DoxyCodeLine{590   alpha2 = 3*d}
\DoxyCodeLine{591   alpha3 = c}
\DoxyCodeLine{592 }
\DoxyCodeLine{593   rho = alpha2 * alpha2 - 4.0 * alpha1 * alpha3}
\DoxyCodeLine{594 }
\DoxyCodeLine{595   \textcolor{comment}{! Check whether inflexion points exist. If so, transform the quartic}}
\DoxyCodeLine{596   \textcolor{comment}{! so that both inflexion points coalesce on the left edge.}}
\DoxyCodeLine{597   \textcolor{keywordflow}{if} (( alpha1 /= 0.0 ) .and. ( rho >= 0.0 )) \textcolor{keywordflow}{then}}
\DoxyCodeLine{598 }
\DoxyCodeLine{599     sqrt\_rho = sqrt( rho )}
\DoxyCodeLine{600 }
\DoxyCodeLine{601     x1 = 0.5 * ( - alpha2 - sqrt\_rho ) / alpha1}
\DoxyCodeLine{602     \textcolor{keywordflow}{if} ( (x1 > 0.0) .and. (x1 < 1.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{603       gradient1 = 4.0 * e * (x1**3) + 3.0 * d * (x1**2) + 2.0 * c * x1 + b}
\DoxyCodeLine{604       \textcolor{keywordflow}{if} ( gradient1 * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{605         inflexion\_l = 1}
\DoxyCodeLine{606 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{607 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{608 }
\DoxyCodeLine{609     x2 = 0.5 * ( - alpha2 + sqrt\_rho ) / alpha1}
\DoxyCodeLine{610     \textcolor{keywordflow}{if} ( (x2 > 0.0) .and. (x2 < 1.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{611       gradient2 = 4.0 * e * (x2**3) + 3.0 * d * (x2**2) + 2.0 * c * x2 + b}
\DoxyCodeLine{612       \textcolor{keywordflow}{if} ( gradient2 * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{613         inflexion\_l = 1}
\DoxyCodeLine{614 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{615 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{616 }
\DoxyCodeLine{617 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{618 }
\DoxyCodeLine{619   \textcolor{keywordflow}{if} (( alpha1 == 0.0 ) .and. ( alpha2 /= 0.0 )) \textcolor{keywordflow}{then}}
\DoxyCodeLine{620 }
\DoxyCodeLine{621     x1 = - alpha3 / alpha2}
\DoxyCodeLine{622     \textcolor{keywordflow}{if} ( (x1 >= 0.0) .and. (x1 <= 1.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{623       gradient1 = 3.0 * d * (x1**2) + 2.0 * c * x1 + b}
\DoxyCodeLine{624       \textcolor{keywordflow}{if} ( gradient1 * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{625         inflexion\_l = 1}
\DoxyCodeLine{626 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{627 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{628 }
\DoxyCodeLine{629 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{630 }
\DoxyCodeLine{631   \textcolor{keywordflow}{if} ( inflexion\_l == 1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{632 }
\DoxyCodeLine{633     \textcolor{comment}{! We modify the edge slopes so that both inflexion points}}
\DoxyCodeLine{634     \textcolor{comment}{! collapse onto the left edge}}
\DoxyCodeLine{635     u1\_l = ( 10.0 * um - 2.0 * u0\_r - 8.0 * u0\_l ) / (3.0*h0 + hneglect)}
\DoxyCodeLine{636     u1\_r = ( -10.0 * um + 6.0 * u0\_r + 4.0 * u0\_l ) / (h0 + hneglect)}
\DoxyCodeLine{637 }
\DoxyCodeLine{638     \textcolor{comment}{! One of the modified slopes might be inconsistent. When that happens,}}
\DoxyCodeLine{639     \textcolor{comment}{! the inconsistent slope is set equal to zero and the opposite edge value}}
\DoxyCodeLine{640     \textcolor{comment}{! and edge slope are modified in compliance with the fact that both}}
\DoxyCodeLine{641     \textcolor{comment}{! inflexion points must still be located on the left edge}}
\DoxyCodeLine{642     \textcolor{keywordflow}{if} ( u1\_l * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{643 }
\DoxyCodeLine{644       u1\_l = 0.0}
\DoxyCodeLine{645       u0\_r = 5.0 * um - 4.0 * u0\_l}
\DoxyCodeLine{646       u1\_r = 20.0 * (um - u0\_l) / ( h0 + hneglect )}
\DoxyCodeLine{647 }
\DoxyCodeLine{648     \textcolor{keywordflow}{elseif} ( u1\_r * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{649 }
\DoxyCodeLine{650       u1\_r = 0.0}
\DoxyCodeLine{651       u0\_l = (5.0*um - 3.0*u0\_r) / 2.0}
\DoxyCodeLine{652       u1\_l = 10.0 * (-um + u0\_r) / (3.0 * h0 + hneglect )}
\DoxyCodeLine{653 }
\DoxyCodeLine{654 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{655 }
\DoxyCodeLine{656 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{657 }
\DoxyCodeLine{658   \textcolor{comment}{! Store edge values, edge slopes and coefficients}}
\DoxyCodeLine{659   edge\_values(i0,1) = u0\_l}
\DoxyCodeLine{660   edge\_values(i0,2) = u0\_r}
\DoxyCodeLine{661   edge\_slopes(i0,1) = u1\_l}
\DoxyCodeLine{662   edge\_slopes(i0,2) = u1\_r}
\DoxyCodeLine{663 }
\DoxyCodeLine{664   a = u0\_l}
\DoxyCodeLine{665   b = h0 * u1\_l}
\DoxyCodeLine{666   c = 30.0 * um - 12.0*u0\_r - 18.0*u0\_l + 1.5*h0*(u1\_r - 3.0*u1\_l)}
\DoxyCodeLine{667   d = -60.0 * um + h0 *(6.0*u1\_l - 4.0*u1\_r) + 28.0*u0\_r + 32.0*u0\_l}
\DoxyCodeLine{668   e = 30.0 * um + 2.5*h0*(u1\_r - u1\_l) - 15.0*(u0\_l + u0\_r)}
\DoxyCodeLine{669 }
\DoxyCodeLine{670     \textcolor{comment}{! Store coefficients}}
\DoxyCodeLine{671   ppoly\_coef(i0,1) = a}
\DoxyCodeLine{672   ppoly\_coef(i0,2) = b}
\DoxyCodeLine{673   ppoly\_coef(i0,3) = c}
\DoxyCodeLine{674   ppoly\_coef(i0,4) = d}
\DoxyCodeLine{675   ppoly\_coef(i0,5) = e}
\DoxyCodeLine{676 }
\DoxyCodeLine{677   \textcolor{comment}{! ----- Right boundary (BOTTOM) -----}}
\DoxyCodeLine{678   i0 = n-1}
\DoxyCodeLine{679   i1 = n}
\DoxyCodeLine{680   h0 = h(i0)}
\DoxyCodeLine{681   h1 = h(i1)}
\DoxyCodeLine{682   u0 = u(i0)}
\DoxyCodeLine{683   u1 = u(i1)}
\DoxyCodeLine{684   um = u1}
\DoxyCodeLine{685 }
\DoxyCodeLine{686   \textcolor{comment}{! Compute real slope and express it w.r.t. local coordinate system}}
\DoxyCodeLine{687   \textcolor{comment}{! within boundary cell}}
\DoxyCodeLine{688   slope = 2.0 * ( u1 - u0 ) / ( h0 + h1 )}
\DoxyCodeLine{689   slope = slope * h1}
\DoxyCodeLine{690 }
\DoxyCodeLine{691   \textcolor{comment}{! The left edge value and slope of the boundary cell are taken to be the}}
\DoxyCodeLine{692   \textcolor{comment}{! right edge value and slope of the adjacent cell}}
\DoxyCodeLine{693   a = ppoly\_coef(i0,1)}
\DoxyCodeLine{694   b = ppoly\_coef(i0,2)}
\DoxyCodeLine{695   c = ppoly\_coef(i0,3)}
\DoxyCodeLine{696   d = ppoly\_coef(i0,4)}
\DoxyCodeLine{697   e = ppoly\_coef(i0,5)}
\DoxyCodeLine{698   u0\_l = a + b + c + d + e                  \textcolor{comment}{! edge value}}
\DoxyCodeLine{699   u1\_l = (b + 2*c + 3*d + 4*e) / h0         \textcolor{comment}{! edge slope (w.r.t. global coord.)}}
\DoxyCodeLine{700 }
\DoxyCodeLine{701   \textcolor{comment}{! Compute coefficient for rational function based on mean and left}}
\DoxyCodeLine{702   \textcolor{comment}{! edge value and slope}}
\DoxyCodeLine{703   \textcolor{keywordflow}{if} (um-u0\_l /= 0.) \textcolor{keywordflow}{then} \textcolor{comment}{! HACK by AJA}}
\DoxyCodeLine{704     beta = 0.5*h1*u1\_l / (um-u0\_l) - 1.0}
\DoxyCodeLine{705   \textcolor{keywordflow}{else}}
\DoxyCodeLine{706     beta = 0.}
\DoxyCodeLine{707 \textcolor{keywordflow}{  endif} \textcolor{comment}{! HACK by AJA}}
\DoxyCodeLine{708   br = beta*um + um - u0\_l}
\DoxyCodeLine{709   ar = u0\_l}
\DoxyCodeLine{710 }
\DoxyCodeLine{711   \textcolor{comment}{! Right edge value estimate based on rational function}}
\DoxyCodeLine{712   \textcolor{keywordflow}{if} (1+beta /= 0.) \textcolor{keywordflow}{then} \textcolor{comment}{! HACK by AJA}}
\DoxyCodeLine{713     u0\_r = (ar + 2*br + beta*br ) / ((1+beta)*(1+beta))}
\DoxyCodeLine{714   \textcolor{keywordflow}{else}}
\DoxyCodeLine{715     u0\_r = um + 0.5 * slope \textcolor{comment}{! PLM}}
\DoxyCodeLine{716 \textcolor{keywordflow}{  endif} \textcolor{comment}{! HACK by AJA}}
\DoxyCodeLine{717 }
\DoxyCodeLine{718   \textcolor{comment}{! Right edge value estimate based on PLM}}
\DoxyCodeLine{719   u\_plm = um + 0.5 * slope}
\DoxyCodeLine{720 }
\DoxyCodeLine{721   \textcolor{comment}{! Check whether the right edge value is bounded by the mean and}}
\DoxyCodeLine{722   \textcolor{comment}{! the PLM edge value. If so, keep it and compute right edge slope}}
\DoxyCodeLine{723   \textcolor{comment}{! based on the rational function. If not, keep the PLM edge value and}}
\DoxyCodeLine{724   \textcolor{comment}{! compute corresponding slope.}}
\DoxyCodeLine{725   \textcolor{keywordflow}{if} ( abs(um-u0\_r) < abs(um-u\_plm) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{726     u1\_r = 2.0 * ( br - ar*beta ) / ( (1+beta)*(1+beta)*(1+beta) )}
\DoxyCodeLine{727     u1\_r = u1\_r / h1}
\DoxyCodeLine{728   \textcolor{keywordflow}{else}}
\DoxyCodeLine{729     u0\_r = u\_plm}
\DoxyCodeLine{730     u1\_r = slope / h1}
\DoxyCodeLine{731 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{732 }
\DoxyCodeLine{733   \textcolor{comment}{! Monotonize quartic}}
\DoxyCodeLine{734   inflexion\_r = 0}
\DoxyCodeLine{735 }
\DoxyCodeLine{736   a = u0\_l}
\DoxyCodeLine{737   b = h1 * u1\_l}
\DoxyCodeLine{738   c = 30.0 * um - 12.0*u0\_r - 18.0*u0\_l + 1.5*h1*(u1\_r - 3.0*u1\_l)}
\DoxyCodeLine{739   d = -60.0 * um + h1*(6.0*u1\_l - 4.0*u1\_r) + 28.0*u0\_r + 32.0*u0\_l}
\DoxyCodeLine{740   e = 30.0 * um + 2.5*h1*(u1\_r - u1\_l) - 15.0*(u0\_l + u0\_r)}
\DoxyCodeLine{741 }
\DoxyCodeLine{742   alpha1 = 6*e}
\DoxyCodeLine{743   alpha2 = 3*d}
\DoxyCodeLine{744   alpha3 = c}
\DoxyCodeLine{745 }
\DoxyCodeLine{746   rho = alpha2 * alpha2 - 4.0 * alpha1 * alpha3}
\DoxyCodeLine{747 }
\DoxyCodeLine{748   \textcolor{comment}{! Check whether inflexion points exist. If so, transform the quartic}}
\DoxyCodeLine{749   \textcolor{comment}{! so that both inflexion points coalesce on the right edge.}}
\DoxyCodeLine{750   \textcolor{keywordflow}{if} (( alpha1 /= 0.0 ) .and. ( rho >= 0.0 )) \textcolor{keywordflow}{then}}
\DoxyCodeLine{751 }
\DoxyCodeLine{752     sqrt\_rho = sqrt( rho )}
\DoxyCodeLine{753 }
\DoxyCodeLine{754     x1 = 0.5 * ( - alpha2 - sqrt\_rho ) / alpha1}
\DoxyCodeLine{755     \textcolor{keywordflow}{if} ( (x1 > 0.0) .and. (x1 < 1.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{756       gradient1 = 4.0 * e * (x1**3) + 3.0 * d * (x1**2) + 2.0 * c * x1 + b}
\DoxyCodeLine{757       \textcolor{keywordflow}{if} ( gradient1 * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{758         inflexion\_r = 1}
\DoxyCodeLine{759 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{760 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{761 }
\DoxyCodeLine{762     x2 = 0.5 * ( - alpha2 + sqrt\_rho ) / alpha1}
\DoxyCodeLine{763     \textcolor{keywordflow}{if} ( (x2 > 0.0) .and. (x2 < 1.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{764       gradient2 = 4.0 * e * (x2**3) + 3.0 * d * (x2**2) + 2.0 * c * x2 + b}
\DoxyCodeLine{765       \textcolor{keywordflow}{if} ( gradient2 * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{766         inflexion\_r = 1}
\DoxyCodeLine{767 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{768 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{769 }
\DoxyCodeLine{770 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{771 }
\DoxyCodeLine{772   \textcolor{keywordflow}{if} (( alpha1 == 0.0 ) .and. ( alpha2 /= 0.0 )) \textcolor{keywordflow}{then}}
\DoxyCodeLine{773 }
\DoxyCodeLine{774     x1 = - alpha3 / alpha2}
\DoxyCodeLine{775     \textcolor{keywordflow}{if} ( (x1 >= 0.0) .and. (x1 <= 1.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{776       gradient1 = 3.0 * d * (x1**2) + 2.0 * c * x1 + b}
\DoxyCodeLine{777       \textcolor{keywordflow}{if} ( gradient1 * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{778         inflexion\_r = 1}
\DoxyCodeLine{779 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{780 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{781 }
\DoxyCodeLine{782 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{783 }
\DoxyCodeLine{784   \textcolor{keywordflow}{if} ( inflexion\_r == 1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{785 }
\DoxyCodeLine{786     \textcolor{comment}{! We modify the edge slopes so that both inflexion points}}
\DoxyCodeLine{787     \textcolor{comment}{! collapse onto the right edge}}
\DoxyCodeLine{788     u1\_r = ( -10.0 * um + 8.0 * u0\_r + 2.0 * u0\_l ) / (3.0 * h1)}
\DoxyCodeLine{789     u1\_l = ( 10.0 * um - 4.0 * u0\_r - 6.0 * u0\_l ) / h1}
\DoxyCodeLine{790 }
\DoxyCodeLine{791     \textcolor{comment}{! One of the modified slopes might be inconsistent. When that happens,}}
\DoxyCodeLine{792     \textcolor{comment}{! the inconsistent slope is set equal to zero and the opposite edge value}}
\DoxyCodeLine{793     \textcolor{comment}{! and edge slope are modified in compliance with the fact that both}}
\DoxyCodeLine{794     \textcolor{comment}{! inflexion points must still be located on the right edge}}
\DoxyCodeLine{795     \textcolor{keywordflow}{if} ( u1\_l * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{796 }
\DoxyCodeLine{797       u1\_l = 0.0}
\DoxyCodeLine{798       u0\_r = ( 5.0 * um - 3.0 * u0\_l ) / 2.0}
\DoxyCodeLine{799       u1\_r = 10.0 * (um - u0\_l) / (3.0 * h1)}
\DoxyCodeLine{800 }
\DoxyCodeLine{801     \textcolor{keywordflow}{elseif} ( u1\_r * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{802 }
\DoxyCodeLine{803       u1\_r = 0.0}
\DoxyCodeLine{804       u0\_l = 5.0 * um - 4.0 * u0\_r}
\DoxyCodeLine{805       u1\_l = 20.0 * ( -um + u0\_r ) / h1}
\DoxyCodeLine{806 }
\DoxyCodeLine{807 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{808 }
\DoxyCodeLine{809 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{810 }
\DoxyCodeLine{811   \textcolor{comment}{! Store edge values, edge slopes and coefficients}}
\DoxyCodeLine{812   edge\_values(i1,1) = u0\_l}
\DoxyCodeLine{813   edge\_values(i1,2) = u0\_r}
\DoxyCodeLine{814   edge\_slopes(i1,1) = u1\_l}
\DoxyCodeLine{815   edge\_slopes(i1,2) = u1\_r}
\DoxyCodeLine{816 }
\DoxyCodeLine{817   a = u0\_l}
\DoxyCodeLine{818   b = h1 * u1\_l}
\DoxyCodeLine{819   c = 30.0 * um - 12.0*u0\_r - 18.0*u0\_l + 1.5*h1*(u1\_r - 3.0*u1\_l)}
\DoxyCodeLine{820   d = -60.0 * um + h1 *(6.0*u1\_l - 4.0*u1\_r) + 28.0*u0\_r + 32.0*u0\_l}
\DoxyCodeLine{821   e = 30.0 * um + 2.5*h1*(u1\_r - u1\_l) - 15.0*(u0\_l + u0\_r)}
\DoxyCodeLine{822 }
\DoxyCodeLine{823   ppoly\_coef(i1,1) = a}
\DoxyCodeLine{824   ppoly\_coef(i1,2) = b}
\DoxyCodeLine{825   ppoly\_coef(i1,3) = c}
\DoxyCodeLine{826   ppoly\_coef(i1,4) = d}
\DoxyCodeLine{827   ppoly\_coef(i1,5) = e}
\DoxyCodeLine{828 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacepqm__functions_aab9f3108956943c39ed2d4b675d78021}\label{namespacepqm__functions_aab9f3108956943c39ed2d4b675d78021}} 
\index{pqm\_functions@{pqm\_functions}!pqm\_limiter@{pqm\_limiter}}
\index{pqm\_limiter@{pqm\_limiter}!pqm\_functions@{pqm\_functions}}
\subsubsection{\texorpdfstring{pqm\_limiter()}{pqm\_limiter()}}
{\footnotesize\ttfamily subroutine pqm\+\_\+functions\+::pqm\+\_\+limiter (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{N,  }\item[{real, dimension(\+:), intent(in)}]{h,  }\item[{real, dimension(\+:), intent(in)}]{u,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{edge\+\_\+values,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{edge\+\_\+slopes,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Limit the piecewise quartic method reconstruction. 

Standard P\+QM limiter (White \& Adcroft, J\+CP 2008).

It is assumed that the dimension of \textquotesingle{}u\textquotesingle{} is equal to the number of cells defining \textquotesingle{}grid\textquotesingle{} and \textquotesingle{}ppoly\textquotesingle{}. No consistency check is performed. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n} & Number of cells \\
\hline
\mbox{\texttt{ in}}  & {\em h} & cell widths (size N) \mbox{[}H\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em u} & cell average properties (size N) \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em edge\+\_\+values} & Potentially modified edge values \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em edge\+\_\+slopes} & Potentially modified edge slopes \mbox{[}A H-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions \mbox{[}H\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em answers\+\_\+2018} & If true use older, less acccurate expressions. \\
\hline
\end{DoxyParams}


Definition at line 76 of file P\+Q\+M\+\_\+functions.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{76   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: N\textcolor{comment}{ !< Number of cells}}
\DoxyCodeLine{77 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{ !< cell widths (size N) [H]}}
\DoxyCodeLine{78 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{ !< cell average properties (size N) [A]}}
\DoxyCodeLine{79 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_values\textcolor{comment}{ !< Potentially modified edge values [A]}}
\DoxyCodeLine{80 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_slopes\textcolor{comment}{ !< Potentially modified edge slopes [A H-1]}}
\DoxyCodeLine{81 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width for}}
\DoxyCodeLine{82 \textcolor{comment}{                                           !! the purpose of cell reconstructions [H]}}
\DoxyCodeLine{83   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true use older, less acccurate expressions.}}
\DoxyCodeLine{84 }
\DoxyCodeLine{85   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{86   \textcolor{keywordtype}{integer} :: k            \textcolor{comment}{! loop index}}
\DoxyCodeLine{87   \textcolor{keywordtype}{integer} :: inflexion\_l}
\DoxyCodeLine{88   \textcolor{keywordtype}{integer} :: inflexion\_r}
\DoxyCodeLine{89 \textcolor{keywordtype}{  real}    :: u0\_l, u0\_r     \textcolor{comment}{! edge values [A]}}
\DoxyCodeLine{90 \textcolor{keywordtype}{  real}    :: u1\_l, u1\_r     \textcolor{comment}{! edge slopes [A H-1]}}
\DoxyCodeLine{91 \textcolor{keywordtype}{  real}    :: u\_l, u\_c, u\_r  \textcolor{comment}{! left, center and right cell averages [A]}}
\DoxyCodeLine{92 \textcolor{keywordtype}{  real}    :: h\_l, h\_c, h\_r  \textcolor{comment}{! left, center and right cell widths [H]}}
\DoxyCodeLine{93 \textcolor{keywordtype}{  real}    :: sigma\_l, sigma\_c, sigma\_r \textcolor{comment}{! left, center and right van Leer slopes}}
\DoxyCodeLine{94 \textcolor{keywordtype}{  real}    :: slope          \textcolor{comment}{! retained PLM slope}}
\DoxyCodeLine{95 \textcolor{keywordtype}{  real}    :: a, b, c, d, e}
\DoxyCodeLine{96 \textcolor{keywordtype}{  real}    :: alpha1, alpha2, alpha3}
\DoxyCodeLine{97 \textcolor{keywordtype}{  real}    :: rho, sqrt\_rho}
\DoxyCodeLine{98 \textcolor{keywordtype}{  real}    :: gradient1, gradient2}
\DoxyCodeLine{99 \textcolor{keywordtype}{  real}    :: x1, x2}
\DoxyCodeLine{100 \textcolor{keywordtype}{  real}    :: hNeglect}
\DoxyCodeLine{101 }
\DoxyCodeLine{102   hneglect = hneglect\_dflt ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect)) hneglect = h\_neglect}
\DoxyCodeLine{103 }
\DoxyCodeLine{104   \textcolor{comment}{! Bound edge values}}
\DoxyCodeLine{105   \textcolor{keyword}{call }bound\_edge\_values( n, h, u, edge\_values, hneglect, answers\_2018 )}
\DoxyCodeLine{106 }
\DoxyCodeLine{107   \textcolor{comment}{! Make discontinuous edge values monotonic (thru averaging)}}
\DoxyCodeLine{108   \textcolor{keyword}{call }check\_discontinuous\_edge\_values( n, u, edge\_values )}
\DoxyCodeLine{109 }
\DoxyCodeLine{110   \textcolor{comment}{! Loop on interior cells to apply the PQM limiter}}
\DoxyCodeLine{111   \textcolor{keywordflow}{do} k = 2,n-1}
\DoxyCodeLine{112 }
\DoxyCodeLine{113     \textcolor{comment}{!if ( h(k) < 1.0 ) cycle}}
\DoxyCodeLine{114 }
\DoxyCodeLine{115     inflexion\_l = 0}
\DoxyCodeLine{116     inflexion\_r = 0}
\DoxyCodeLine{117 }
\DoxyCodeLine{118     \textcolor{comment}{! Get edge values, edge slopes and cell width}}
\DoxyCodeLine{119     u0\_l = edge\_values(k,1)}
\DoxyCodeLine{120     u0\_r = edge\_values(k,2)}
\DoxyCodeLine{121     u1\_l = edge\_slopes(k,1)}
\DoxyCodeLine{122     u1\_r = edge\_slopes(k,2)}
\DoxyCodeLine{123 }
\DoxyCodeLine{124     \textcolor{comment}{! Get cell widths and cell averages (boundary cells are assumed to}}
\DoxyCodeLine{125     \textcolor{comment}{! be local extrema for the sake of slopes)}}
\DoxyCodeLine{126     h\_l = h(k-1)}
\DoxyCodeLine{127     h\_c = h(k)}
\DoxyCodeLine{128     h\_r = h(k+1)}
\DoxyCodeLine{129     u\_l = u(k-1)}
\DoxyCodeLine{130     u\_c = u(k)}
\DoxyCodeLine{131     u\_r = u(k+1)}
\DoxyCodeLine{132 }
\DoxyCodeLine{133     \textcolor{comment}{! Compute limited slope}}
\DoxyCodeLine{134     sigma\_l = 2.0 * ( u\_c - u\_l ) / ( h\_c + hneglect )}
\DoxyCodeLine{135     sigma\_c = 2.0 * ( u\_r - u\_l ) / ( h\_l + 2.0*h\_c + h\_r + hneglect )}
\DoxyCodeLine{136     sigma\_r = 2.0 * ( u\_r - u\_c ) / ( h\_c + hneglect )}
\DoxyCodeLine{137 }
\DoxyCodeLine{138     \textcolor{keywordflow}{if} ( (sigma\_l * sigma\_r) > 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{139       slope = sign( min(abs(sigma\_l),abs(sigma\_c),abs(sigma\_r)), sigma\_c )}
\DoxyCodeLine{140     \textcolor{keywordflow}{else}}
\DoxyCodeLine{141       slope = 0.0}
\DoxyCodeLine{142 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{143 }
\DoxyCodeLine{144     \textcolor{comment}{! If one of the slopes has the wrong sign compared with the}}
\DoxyCodeLine{145     \textcolor{comment}{! limited PLM slope, it is set equal to the limited PLM slope}}
\DoxyCodeLine{146     \textcolor{keywordflow}{if} ( u1\_l*slope <= 0.0 ) u1\_l = slope}
\DoxyCodeLine{147     \textcolor{keywordflow}{if} ( u1\_r*slope <= 0.0 ) u1\_r = slope}
\DoxyCodeLine{148 }
\DoxyCodeLine{149     \textcolor{comment}{! Local extremum --> flatten}}
\DoxyCodeLine{150     \textcolor{keywordflow}{if} ( (u0\_r - u\_c) * (u\_c - u0\_l) <= 0.0) \textcolor{keywordflow}{then}}
\DoxyCodeLine{151       u0\_l = u\_c}
\DoxyCodeLine{152       u0\_r = u\_c}
\DoxyCodeLine{153       u1\_l = 0.0}
\DoxyCodeLine{154       u1\_r = 0.0}
\DoxyCodeLine{155       inflexion\_l = -1}
\DoxyCodeLine{156       inflexion\_r = -1}
\DoxyCodeLine{157 \textcolor{keywordflow}{    endif}}
\DoxyCodeLine{158 }
\DoxyCodeLine{159     \textcolor{comment}{! Edge values are bounded and averaged when discontinuous and not}}
\DoxyCodeLine{160     \textcolor{comment}{! monotonic, edge slopes are consistent and the cell is not an extremum.}}
\DoxyCodeLine{161     \textcolor{comment}{! We now need to check and encorce the monotonicity of the quartic within}}
\DoxyCodeLine{162     \textcolor{comment}{! the cell}}
\DoxyCodeLine{163     \textcolor{keywordflow}{if} ( (inflexion\_l == 0) .AND. (inflexion\_r == 0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{164 }
\DoxyCodeLine{165       a = u0\_l}
\DoxyCodeLine{166       b = h\_c * u1\_l}
\DoxyCodeLine{167       c = 30.0 * u(k) - 12.0*u0\_r - 18.0*u0\_l + 1.5*h\_c*(u1\_r - 3.0*u1\_l)}
\DoxyCodeLine{168       d = -60.0 * u(k) + h\_c *(6.0*u1\_l - 4.0*u1\_r) + 28.0*u0\_r + 32.0*u0\_l}
\DoxyCodeLine{169       e = 30.0 * u(k) + 2.5*h\_c*(u1\_r - u1\_l) - 15.0*(u0\_l + u0\_r)}
\DoxyCodeLine{170 }
\DoxyCodeLine{171       \textcolor{comment}{! Determine the coefficients of the second derivative}}
\DoxyCodeLine{172       \textcolor{comment}{! alpha1 xi\string^2 + alpha2 xi + alpha3}}
\DoxyCodeLine{173       alpha1 = 6*e}
\DoxyCodeLine{174       alpha2 = 3*d}
\DoxyCodeLine{175       alpha3 = c}
\DoxyCodeLine{176 }
\DoxyCodeLine{177       rho = alpha2 * alpha2 - 4.0 * alpha1 * alpha3}
\DoxyCodeLine{178 }
\DoxyCodeLine{179       \textcolor{comment}{! Check whether inflexion points exist}}
\DoxyCodeLine{180       \textcolor{keywordflow}{if} (( alpha1 /= 0.0 ) .and. ( rho >= 0.0 )) \textcolor{keywordflow}{then}}
\DoxyCodeLine{181 }
\DoxyCodeLine{182         sqrt\_rho = sqrt( rho )}
\DoxyCodeLine{183 }
\DoxyCodeLine{184         x1 = 0.5 * ( - alpha2 - sqrt\_rho ) / alpha1}
\DoxyCodeLine{185         x2 = 0.5 * ( - alpha2 + sqrt\_rho ) / alpha1}
\DoxyCodeLine{186 }
\DoxyCodeLine{187         \textcolor{comment}{! Check whether both inflexion points lie in [0,1]}}
\DoxyCodeLine{188         \textcolor{keywordflow}{if} ( (x1 >= 0.0) .AND. (x1 <= 1.0) .AND. \&}
\DoxyCodeLine{189              (x2 >= 0.0) .AND. (x2 <= 1.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{190 }
\DoxyCodeLine{191           gradient1 = 4.0 * e * (x1**3) + 3.0 * d * (x1**2) + 2.0 * c * x1 + b}
\DoxyCodeLine{192           gradient2 = 4.0 * e * (x2**3) + 3.0 * d * (x2**2) + 2.0 * c * x2 + b}
\DoxyCodeLine{193 }
\DoxyCodeLine{194           \textcolor{comment}{! Check whether one of the gradients is inconsistent}}
\DoxyCodeLine{195           \textcolor{keywordflow}{if} ( (gradient1 * slope < 0.0) .OR. \&}
\DoxyCodeLine{196                (gradient2 * slope < 0.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{197             \textcolor{comment}{! Decide where to collapse inflexion points}}
\DoxyCodeLine{198             \textcolor{comment}{! (depends on one-sided slopes)}}
\DoxyCodeLine{199             \textcolor{keywordflow}{if} ( abs(sigma\_l) < abs(sigma\_r) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{200               inflexion\_l = 1}
\DoxyCodeLine{201             \textcolor{keywordflow}{else}}
\DoxyCodeLine{202               inflexion\_r = 1}
\DoxyCodeLine{203 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{204 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{205 }
\DoxyCodeLine{206         \textcolor{comment}{! If both x1 and x2 do not lie in [0,1], check whether}}
\DoxyCodeLine{207         \textcolor{comment}{! only x1 lies in [0,1]}}
\DoxyCodeLine{208         \textcolor{keywordflow}{elseif} ( (x1 >= 0.0) .AND. (x1 <= 1.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{209 }
\DoxyCodeLine{210           gradient1 = 4.0 * e * (x1**3) + 3.0 * d * (x1**2) + 2.0 * c * x1 + b}
\DoxyCodeLine{211 }
\DoxyCodeLine{212           \textcolor{comment}{! Check whether the gradient is inconsistent}}
\DoxyCodeLine{213           \textcolor{keywordflow}{if} ( gradient1 * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{214             \textcolor{comment}{! Decide where to collapse inflexion points}}
\DoxyCodeLine{215             \textcolor{comment}{! (depends on one-sided slopes)}}
\DoxyCodeLine{216             \textcolor{keywordflow}{if} ( abs(sigma\_l) < abs(sigma\_r) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{217               inflexion\_l = 1}
\DoxyCodeLine{218             \textcolor{keywordflow}{else}}
\DoxyCodeLine{219               inflexion\_r = 1}
\DoxyCodeLine{220 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{221 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{222 }
\DoxyCodeLine{223         \textcolor{comment}{! If x1 does not lie in [0,1], check whether x2 lies in [0,1]}}
\DoxyCodeLine{224         \textcolor{keywordflow}{elseif} ( (x2 >= 0.0) .AND. (x2 <= 1.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{225 }
\DoxyCodeLine{226           gradient2 = 4.0 * e * (x2**3) + 3.0 * d * (x2**2) + 2.0 * c * x2 + b}
\DoxyCodeLine{227 }
\DoxyCodeLine{228           \textcolor{comment}{! Check whether the gradient is inconsistent}}
\DoxyCodeLine{229           \textcolor{keywordflow}{if} ( gradient2 * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{230             \textcolor{comment}{! Decide where to collapse inflexion points}}
\DoxyCodeLine{231             \textcolor{comment}{! (depends on one-sided slopes)}}
\DoxyCodeLine{232             \textcolor{keywordflow}{if} ( abs(sigma\_l) < abs(sigma\_r) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{233               inflexion\_l = 1}
\DoxyCodeLine{234             \textcolor{keywordflow}{else}}
\DoxyCodeLine{235               inflexion\_r = 1}
\DoxyCodeLine{236 \textcolor{keywordflow}{            endif}}
\DoxyCodeLine{237 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{238 }
\DoxyCodeLine{239 \textcolor{keywordflow}{        endif} \textcolor{comment}{! end checking where the inflexion points lie}}
\DoxyCodeLine{240 }
\DoxyCodeLine{241 \textcolor{keywordflow}{      endif} \textcolor{comment}{! end checking if alpha1 != 0 AND rho >= 0}}
\DoxyCodeLine{242 }
\DoxyCodeLine{243       \textcolor{comment}{! If alpha1 is zero, the second derivative of the quartic reduces}}
\DoxyCodeLine{244       \textcolor{comment}{! to a straight line}}
\DoxyCodeLine{245       \textcolor{keywordflow}{if} (( alpha1 == 0.0 ) .and. ( alpha2 /= 0.0 )) \textcolor{keywordflow}{then}}
\DoxyCodeLine{246 }
\DoxyCodeLine{247           x1 = - alpha3 / alpha2}
\DoxyCodeLine{248           \textcolor{keywordflow}{if} ( (x1 >= 0.0) .AND. (x1 <= 1.0) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{249 }
\DoxyCodeLine{250             gradient1 = 4.0 * e * (x1**3) + 3.0 * d * (x1**2) + 2.0 * c * x1 + b}
\DoxyCodeLine{251 }
\DoxyCodeLine{252             \textcolor{comment}{! Check whether the gradient is inconsistent}}
\DoxyCodeLine{253             \textcolor{keywordflow}{if} ( gradient1 * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{254               \textcolor{comment}{! Decide where to collapse inflexion points}}
\DoxyCodeLine{255               \textcolor{comment}{! (depends on one-sided slopes)}}
\DoxyCodeLine{256               \textcolor{keywordflow}{if} ( abs(sigma\_l) < abs(sigma\_r) ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{257                 inflexion\_l = 1}
\DoxyCodeLine{258               \textcolor{keywordflow}{else}}
\DoxyCodeLine{259                 inflexion\_r = 1}
\DoxyCodeLine{260 \textcolor{keywordflow}{              endif}}
\DoxyCodeLine{261 \textcolor{keywordflow}{            endif} \textcolor{comment}{! check slope consistency}}
\DoxyCodeLine{262 }
\DoxyCodeLine{263 \textcolor{keywordflow}{          endif}}
\DoxyCodeLine{264 }
\DoxyCodeLine{265 \textcolor{keywordflow}{      endif} \textcolor{comment}{! end check whether we can find the root of the straight line}}
\DoxyCodeLine{266 }
\DoxyCodeLine{267 \textcolor{keywordflow}{    endif} \textcolor{comment}{! end checking whether to shift inflexion points}}
\DoxyCodeLine{268 }
\DoxyCodeLine{269     \textcolor{comment}{! At this point, we know onto which edge to shift inflexion points}}
\DoxyCodeLine{270     \textcolor{keywordflow}{if} ( inflexion\_l == 1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{271 }
\DoxyCodeLine{272       \textcolor{comment}{! We modify the edge slopes so that both inflexion points}}
\DoxyCodeLine{273       \textcolor{comment}{! collapse onto the left edge}}
\DoxyCodeLine{274       u1\_l = ( 10.0 * u\_c - 2.0 * u0\_r - 8.0 * u0\_l ) / (3.0*h\_c + hneglect )}
\DoxyCodeLine{275       u1\_r = ( -10.0 * u\_c + 6.0 * u0\_r + 4.0 * u0\_l ) / ( h\_c + hneglect )}
\DoxyCodeLine{276 }
\DoxyCodeLine{277       \textcolor{comment}{! One of the modified slopes might be inconsistent. When that happens,}}
\DoxyCodeLine{278       \textcolor{comment}{! the inconsistent slope is set equal to zero and the opposite edge value}}
\DoxyCodeLine{279       \textcolor{comment}{! and edge slope are modified in compliance with the fact that both}}
\DoxyCodeLine{280       \textcolor{comment}{! inflexion points must still be located on the left edge}}
\DoxyCodeLine{281       \textcolor{keywordflow}{if} ( u1\_l * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{282 }
\DoxyCodeLine{283         u1\_l = 0.0}
\DoxyCodeLine{284         u0\_r = 5.0 * u\_c - 4.0 * u0\_l}
\DoxyCodeLine{285         u1\_r = 20.0 * (u\_c - u0\_l) / ( h\_c + hneglect )}
\DoxyCodeLine{286 }
\DoxyCodeLine{287       \textcolor{keywordflow}{elseif} ( u1\_r * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{288 }
\DoxyCodeLine{289         u1\_r = 0.0}
\DoxyCodeLine{290         u0\_l = (5.0*u\_c - 3.0*u0\_r) / 2.0}
\DoxyCodeLine{291         u1\_l = 10.0 * (-u\_c + u0\_r) / (3.0 * h\_c + hneglect)}
\DoxyCodeLine{292 }
\DoxyCodeLine{293 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{294 }
\DoxyCodeLine{295     \textcolor{keywordflow}{elseif} ( inflexion\_r == 1 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{296 }
\DoxyCodeLine{297       \textcolor{comment}{! We modify the edge slopes so that both inflexion points}}
\DoxyCodeLine{298       \textcolor{comment}{! collapse onto the right edge}}
\DoxyCodeLine{299       u1\_r = ( -10.0 * u\_c + 8.0 * u0\_r + 2.0 * u0\_l ) / (3.0 * h\_c + hneglect)}
\DoxyCodeLine{300       u1\_l = ( 10.0 * u\_c - 4.0 * u0\_r - 6.0 * u0\_l ) / (h\_c + hneglect)}
\DoxyCodeLine{301 }
\DoxyCodeLine{302       \textcolor{comment}{! One of the modified slopes might be inconsistent. When that happens,}}
\DoxyCodeLine{303       \textcolor{comment}{! the inconsistent slope is set equal to zero and the opposite edge value}}
\DoxyCodeLine{304       \textcolor{comment}{! and edge slope are modified in compliance with the fact that both}}
\DoxyCodeLine{305       \textcolor{comment}{! inflexion points must still be located on the right edge}}
\DoxyCodeLine{306       \textcolor{keywordflow}{if} ( u1\_l * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{307 }
\DoxyCodeLine{308         u1\_l = 0.0}
\DoxyCodeLine{309         u0\_r = ( 5.0 * u\_c - 3.0 * u0\_l ) / 2.0}
\DoxyCodeLine{310         u1\_r = 10.0 * (u\_c - u0\_l) / (3.0 * h\_c + hneglect)}
\DoxyCodeLine{311 }
\DoxyCodeLine{312       \textcolor{keywordflow}{elseif} ( u1\_r * slope < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{313 }
\DoxyCodeLine{314         u1\_r = 0.0}
\DoxyCodeLine{315         u0\_l = 5.0 * u\_c - 4.0 * u0\_r}
\DoxyCodeLine{316         u1\_l = 20.0 * ( -u\_c + u0\_r ) / (h\_c + hneglect)}
\DoxyCodeLine{317 }
\DoxyCodeLine{318 \textcolor{keywordflow}{      endif}}
\DoxyCodeLine{319 }
\DoxyCodeLine{320 \textcolor{keywordflow}{    endif} \textcolor{comment}{! clause to check where to collapse inflexion points}}
\DoxyCodeLine{321 }
\DoxyCodeLine{322     \textcolor{comment}{! Save edge values and edge slopes for reconstruction}}
\DoxyCodeLine{323     edge\_values(k,1) = u0\_l}
\DoxyCodeLine{324     edge\_values(k,2) = u0\_r}
\DoxyCodeLine{325     edge\_slopes(k,1) = u1\_l}
\DoxyCodeLine{326     edge\_slopes(k,2) = u1\_r}
\DoxyCodeLine{327 }
\DoxyCodeLine{328 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end loop on interior cells}}
\DoxyCodeLine{329 }
\DoxyCodeLine{330   \textcolor{comment}{! Constant reconstruction within boundary cells}}
\DoxyCodeLine{331   edge\_values(1,:) = u(1)}
\DoxyCodeLine{332   edge\_slopes(1,:) = 0.0}
\DoxyCodeLine{333 }
\DoxyCodeLine{334   edge\_values(n,:) = u(n)}
\DoxyCodeLine{335   edge\_slopes(n,:) = 0.0}
\DoxyCodeLine{336 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacepqm__functions_afa6f7b5430011f03c428b329c5f42fae}\label{namespacepqm__functions_afa6f7b5430011f03c428b329c5f42fae}} 
\index{pqm\_functions@{pqm\_functions}!pqm\_reconstruction@{pqm\_reconstruction}}
\index{pqm\_reconstruction@{pqm\_reconstruction}!pqm\_functions@{pqm\_functions}}
\subsubsection{\texorpdfstring{pqm\_reconstruction()}{pqm\_reconstruction()}}
{\footnotesize\ttfamily subroutine, public pqm\+\_\+functions\+::pqm\+\_\+reconstruction (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{N,  }\item[{real, dimension(\+:), intent(in)}]{h,  }\item[{real, dimension(\+:), intent(in)}]{u,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{edge\+\_\+values,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{edge\+\_\+slopes,  }\item[{real, dimension(\+:,\+:), intent(inout)}]{ppoly\+\_\+coef,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})}



Reconstruction by quartic polynomials within each cell. 

It is assumed that the dimension of \textquotesingle{}u\textquotesingle{} is equal to the number of cells defining \textquotesingle{}grid\textquotesingle{} and \textquotesingle{}ppoly\textquotesingle{}. No consistency check is performed. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em n} & Number of cells \\
\hline
\mbox{\texttt{ in}}  & {\em h} & cell widths (size N) \mbox{[}H\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em u} & cell averages (size N) \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em edge\+\_\+values} & Edge value of polynomial \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em edge\+\_\+slopes} & Edge slope of polynomial \mbox{[}A H-\/1\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em ppoly\+\_\+coef} & Coefficients of polynomial, mainly \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions \mbox{[}H\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em answers\+\_\+2018} & If true use older, less acccurate expressions. \\
\hline
\end{DoxyParams}


Definition at line 21 of file P\+Q\+M\+\_\+functions.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{21   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: N\textcolor{comment}{ !< Number of cells}}
\DoxyCodeLine{22 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{ !< cell widths (size N) [H]}}
\DoxyCodeLine{23 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{ !< cell averages (size N) [A]}}
\DoxyCodeLine{24 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_values\textcolor{comment}{    !< Edge value of polynomial [A]}}
\DoxyCodeLine{25 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_slopes\textcolor{comment}{    !< Edge slope of polynomial [A H-1]}}
\DoxyCodeLine{26 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: ppoly\_coef\textcolor{comment}{ !< Coefficients of polynomial, mainly [A]}}
\DoxyCodeLine{27 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{  !< A negligibly small width for}}
\DoxyCodeLine{28 \textcolor{comment}{                                           !! the purpose of cell reconstructions [H]}}
\DoxyCodeLine{29   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true use older, less acccurate expressions.}}
\DoxyCodeLine{30 }
\DoxyCodeLine{31   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{32   \textcolor{keywordtype}{integer}   :: k                \textcolor{comment}{! loop index}}
\DoxyCodeLine{33 \textcolor{keywordtype}{  real}      :: h\_c              \textcolor{comment}{! cell width}}
\DoxyCodeLine{34 \textcolor{keywordtype}{  real}      :: u0\_l, u0\_r       \textcolor{comment}{! edge values (left and right) [A]}}
\DoxyCodeLine{35 \textcolor{keywordtype}{  real}      :: u1\_l, u1\_r       \textcolor{comment}{! edge slopes (left and right) [A H-1]}}
\DoxyCodeLine{36 \textcolor{keywordtype}{  real}      :: a, b, c, d, e    \textcolor{comment}{! parabola coefficients}}
\DoxyCodeLine{37 }
\DoxyCodeLine{38   \textcolor{comment}{! PQM limiter}}
\DoxyCodeLine{39   \textcolor{keyword}{call }pqm\_limiter( n, h, u, edge\_values, edge\_slopes, h\_neglect, answers\_2018 )}
\DoxyCodeLine{40 }
\DoxyCodeLine{41   \textcolor{comment}{! Loop on cells to construct the cubic within each cell}}
\DoxyCodeLine{42   \textcolor{keywordflow}{do} k = 1,n}
\DoxyCodeLine{43 }
\DoxyCodeLine{44     u0\_l = edge\_values(k,1)}
\DoxyCodeLine{45     u0\_r = edge\_values(k,2)}
\DoxyCodeLine{46 }
\DoxyCodeLine{47     u1\_l = edge\_slopes(k,1)}
\DoxyCodeLine{48     u1\_r = edge\_slopes(k,2)}
\DoxyCodeLine{49 }
\DoxyCodeLine{50     h\_c = h(k)}
\DoxyCodeLine{51 }
\DoxyCodeLine{52     a = u0\_l}
\DoxyCodeLine{53     b = h\_c * u1\_l}
\DoxyCodeLine{54     c = 30.0 * u(k) - 12.0*u0\_r - 18.0*u0\_l + 1.5*h\_c*(u1\_r - 3.0*u1\_l)}
\DoxyCodeLine{55     d = -60.0 * u(k) + h\_c *(6.0*u1\_l - 4.0*u1\_r) + 28.0*u0\_r + 32.0*u0\_l}
\DoxyCodeLine{56     e = 30.0 * u(k) + 2.5*h\_c*(u1\_r - u1\_l) - 15.0*(u0\_l + u0\_r)}
\DoxyCodeLine{57 }
\DoxyCodeLine{58     \textcolor{comment}{! Store coefficients}}
\DoxyCodeLine{59     ppoly\_coef(k,1) = a}
\DoxyCodeLine{60     ppoly\_coef(k,2) = b}
\DoxyCodeLine{61     ppoly\_coef(k,3) = c}
\DoxyCodeLine{62     ppoly\_coef(k,4) = d}
\DoxyCodeLine{63     ppoly\_coef(k,5) = e}
\DoxyCodeLine{64 }
\DoxyCodeLine{65 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end loop on cells}}
\DoxyCodeLine{66 }

\end{DoxyCode}
