\hypertarget{namespacep1m__functions}{}\section{p1m\+\_\+functions Module Reference}
\label{namespacep1m__functions}\index{p1m\_functions@{p1m\_functions}}


\subsection{Detailed Description}
Linear interpolation functions. 

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

This module contains p1m (linear) interpolation routines.

p1m interpolation is performed by estimating the edge values and linearly interpolating between them. \subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacep1m__functions_a233a7aff25cf6581421f76bba053d758}{p1m\+\_\+interpolation}} (N, h, u, edge\+\_\+values, ppoly\+\_\+coef, h\+\_\+neglect, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Linearly interpolate between edge values. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacep1m__functions_a1a45cb8f3f794172d2a19b53e10416c6}{p1m\+\_\+boundary\+\_\+extrapolation}} (N, h, u, edge\+\_\+values, ppoly\+\_\+coef)
\begin{DoxyCompactList}\small\item\em Interpolation by linear polynomials within boundary cells. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacep1m__functions_a1a45cb8f3f794172d2a19b53e10416c6}\label{namespacep1m__functions_a1a45cb8f3f794172d2a19b53e10416c6}} 
\index{p1m\_functions@{p1m\_functions}!p1m\_boundary\_extrapolation@{p1m\_boundary\_extrapolation}}
\index{p1m\_boundary\_extrapolation@{p1m\_boundary\_extrapolation}!p1m\_functions@{p1m\_functions}}
\subsubsection{\texorpdfstring{p1m\_boundary\_extrapolation()}{p1m\_boundary\_extrapolation()}}
{\footnotesize\ttfamily subroutine, public p1m\+\_\+functions\+::p1m\+\_\+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})}



Interpolation by linear polynomials within boundary cells. 

The left and right edge values in the left and right boundary cells, respectively, are estimated using a linear extrapolation within the cells.

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 values of piecewise polynomials \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in,out}}  & {\em ppoly\+\_\+coef} & coefficients of piecewise polynomials, mainly \mbox{[}A\mbox{]} \\
\hline
\end{DoxyParams}


Definition at line 69 of file P1\+M\+\_\+functions.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{69   \textcolor{comment}{! Arguments}}
\DoxyCodeLine{70   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: N\textcolor{comment}{ !< Number of cells}}
\DoxyCodeLine{71 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{ !< cell widths (size N) [H]}}
\DoxyCodeLine{72 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{ !< cell averages (size N) [A]}}
\DoxyCodeLine{73 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_values\textcolor{comment}{ !< edge values of piecewise polynomials [A]}}
\DoxyCodeLine{74 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: ppoly\_coef\textcolor{comment}{ !< coefficients of piecewise polynomials, mainly [A]}}
\DoxyCodeLine{75 }
\DoxyCodeLine{76   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{77 \textcolor{keywordtype}{  real}          :: u0, u1               \textcolor{comment}{! cell averages}}
\DoxyCodeLine{78 \textcolor{keywordtype}{  real}          :: h0, h1               \textcolor{comment}{! corresponding cell widths}}
\DoxyCodeLine{79 \textcolor{keywordtype}{  real}          :: slope                \textcolor{comment}{! retained PLM slope}}
\DoxyCodeLine{80 \textcolor{keywordtype}{  real}          :: u0\_l, u0\_r           \textcolor{comment}{! edge values}}
\DoxyCodeLine{81 }
\DoxyCodeLine{82   \textcolor{comment}{! -----------------------------------------}}
\DoxyCodeLine{83   \textcolor{comment}{! Left edge value in the left boundary cell}}
\DoxyCodeLine{84   \textcolor{comment}{! -----------------------------------------}}
\DoxyCodeLine{85   h0 = h(1)}
\DoxyCodeLine{86   h1 = h(2)}
\DoxyCodeLine{87 }
\DoxyCodeLine{88   u0 = u(1)}
\DoxyCodeLine{89   u1 = u(2)}
\DoxyCodeLine{90 }
\DoxyCodeLine{91   \textcolor{comment}{! The standard PLM slope is computed as a first estimate for the}}
\DoxyCodeLine{92   \textcolor{comment}{! interpolation within the cell}}
\DoxyCodeLine{93   slope = 2.0 * ( u1 - u0 )}
\DoxyCodeLine{94 }
\DoxyCodeLine{95   \textcolor{comment}{! The right edge value is then computed and we check whether this}}
\DoxyCodeLine{96   \textcolor{comment}{! right edge value is consistent: it cannot be larger than the edge}}
\DoxyCodeLine{97   \textcolor{comment}{! value in the neighboring cell if the data set is increasing.}}
\DoxyCodeLine{98   \textcolor{comment}{! If the right value is found to too large, the slope is further limited}}
\DoxyCodeLine{99   \textcolor{comment}{! by using the edge value in the neighboring cell.}}
\DoxyCodeLine{100   u0\_r = u0 + 0.5 * slope}
\DoxyCodeLine{101 }
\DoxyCodeLine{102   \textcolor{keywordflow}{if} ( (u1 - u0) * (edge\_values(2,1) - u0\_r) < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{103     slope = 2.0 * ( edge\_values(2,1) - u0 )}
\DoxyCodeLine{104 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{105 }
\DoxyCodeLine{106   \textcolor{comment}{! Using the limited slope, the left edge value is reevaluated and}}
\DoxyCodeLine{107   \textcolor{comment}{! the interpolant coefficients recomputed}}
\DoxyCodeLine{108   \textcolor{keywordflow}{if} ( h0 /= 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{109     edge\_values(1,1) = u0 - 0.5 * slope}
\DoxyCodeLine{110   \textcolor{keywordflow}{else}}
\DoxyCodeLine{111     edge\_values(1,1) = u0}
\DoxyCodeLine{112 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{113 }
\DoxyCodeLine{114   ppoly\_coef(1,1) = edge\_values(1,1)}
\DoxyCodeLine{115   ppoly\_coef(1,2) = edge\_values(1,2) - edge\_values(1,1)}
\DoxyCodeLine{116 }
\DoxyCodeLine{117   \textcolor{comment}{! ------------------------------------------}}
\DoxyCodeLine{118   \textcolor{comment}{! Right edge value in the left boundary cell}}
\DoxyCodeLine{119   \textcolor{comment}{! ------------------------------------------}}
\DoxyCodeLine{120   h0 = h(n-1)}
\DoxyCodeLine{121   h1 = h(n)}
\DoxyCodeLine{122 }
\DoxyCodeLine{123   u0 = u(n-1)}
\DoxyCodeLine{124   u1 = u(n)}
\DoxyCodeLine{125 }
\DoxyCodeLine{126   slope = 2.0 * ( u1 - u0 )}
\DoxyCodeLine{127 }
\DoxyCodeLine{128   u0\_l = u1 - 0.5 * slope}
\DoxyCodeLine{129 }
\DoxyCodeLine{130   \textcolor{keywordflow}{if} ( (u1 - u0) * (u0\_l - edge\_values(n-1,2)) < 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{131     slope = 2.0 * ( u1 - edge\_values(n-1,2) )}
\DoxyCodeLine{132 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{133 }
\DoxyCodeLine{134   \textcolor{keywordflow}{if} ( h1 /= 0.0 ) \textcolor{keywordflow}{then}}
\DoxyCodeLine{135     edge\_values(n,2) = u1 + 0.5 * slope}
\DoxyCodeLine{136   \textcolor{keywordflow}{else}}
\DoxyCodeLine{137     edge\_values(n,2) = u1}
\DoxyCodeLine{138 \textcolor{keywordflow}{  endif}}
\DoxyCodeLine{139 }
\DoxyCodeLine{140   ppoly\_coef(n,1) = edge\_values(n,1)}
\DoxyCodeLine{141   ppoly\_coef(n,2) = edge\_values(n,2) - edge\_values(n,1)}
\DoxyCodeLine{142 }

\end{DoxyCode}
\mbox{\Hypertarget{namespacep1m__functions_a233a7aff25cf6581421f76bba053d758}\label{namespacep1m__functions_a233a7aff25cf6581421f76bba053d758}} 
\index{p1m\_functions@{p1m\_functions}!p1m\_interpolation@{p1m\_interpolation}}
\index{p1m\_interpolation@{p1m\_interpolation}!p1m\_functions@{p1m\_functions}}
\subsubsection{\texorpdfstring{p1m\_interpolation()}{p1m\_interpolation()}}
{\footnotesize\ttfamily subroutine, public p1m\+\_\+functions\+::p1m\+\_\+interpolation (\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,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})}



Linearly interpolate between edge values. 

The resulting piecewise interpolant is stored in \textquotesingle{}ppoly\textquotesingle{}. See \textquotesingle{}ppoly.\+F90\textquotesingle{} for a definition of this structure.

The edge values M\+U\+ST have been estimated prior to calling this routine.

The estimated edge values must be limited to ensure monotonicity of the interpolant. We also make sure that edge values are N\+OT discontinuous.

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 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 ppoly\+\_\+coef} & Potentially modified piecewise polynomial coefficients, mainly \mbox{[}A\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em h\+\_\+neglect} & A negligibly small width \mbox{[}H\mbox{]} \\
\hline
\mbox{\texttt{ in}}  & {\em answers\+\_\+2018} & If true use older, less acccurate expressions. \\
\hline
\end{DoxyParams}


Definition at line 28 of file P1\+M\+\_\+functions.\+F90.


\begin{DoxyCode}{0}
\DoxyCodeLine{28   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: N\textcolor{comment}{ !< Number of cells}}
\DoxyCodeLine{29 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{ !< cell widths (size N) [H]}}
\DoxyCodeLine{30 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{ !< cell average properties (size N) [A]}}
\DoxyCodeLine{31 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_values\textcolor{comment}{ !< Potentially modified edge values [A]}}
\DoxyCodeLine{32 \textcolor{keywordtype}{  real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: ppoly\_coef\textcolor{comment}{ !< Potentially modified}}
\DoxyCodeLine{33 \textcolor{comment}{                                           !! piecewise polynomial coefficients, mainly [A]}}
\DoxyCodeLine{34 \textcolor{keywordtype}{  real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width [H]}}
\DoxyCodeLine{35   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true use older, less acccurate expressions.}}
\DoxyCodeLine{36 }
\DoxyCodeLine{37   \textcolor{comment}{! Local variables}}
\DoxyCodeLine{38   \textcolor{keywordtype}{integer}   :: k            \textcolor{comment}{! loop index}}
\DoxyCodeLine{39 \textcolor{keywordtype}{  real}      :: u0\_l, u0\_r   \textcolor{comment}{! edge values (left and right)}}
\DoxyCodeLine{40 }
\DoxyCodeLine{41   \textcolor{comment}{! Bound edge values (routine found in 'edge\_values.F90')}}
\DoxyCodeLine{42   \textcolor{keyword}{call }bound\_edge\_values( n, h, u, edge\_values, h\_neglect, answers\_2018 )}
\DoxyCodeLine{43 }
\DoxyCodeLine{44   \textcolor{comment}{! Systematically average discontinuous edge values (routine found in}}
\DoxyCodeLine{45   \textcolor{comment}{! 'edge\_values.F90')}}
\DoxyCodeLine{46   \textcolor{keyword}{call }average\_discontinuous\_edge\_values( n, edge\_values )}
\DoxyCodeLine{47 }
\DoxyCodeLine{48   \textcolor{comment}{! Loop on interior cells to build interpolants}}
\DoxyCodeLine{49   \textcolor{keywordflow}{do} k = 1,n}
\DoxyCodeLine{50 }
\DoxyCodeLine{51     u0\_l = edge\_values(k,1)}
\DoxyCodeLine{52     u0\_r = edge\_values(k,2)}
\DoxyCodeLine{53 }
\DoxyCodeLine{54     ppoly\_coef(k,1) = u0\_l}
\DoxyCodeLine{55     ppoly\_coef(k,2) = u0\_r - u0\_l}
\DoxyCodeLine{56 }
\DoxyCodeLine{57 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end loop on interior cells}}
\DoxyCodeLine{58 }

\end{DoxyCode}
