\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 \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 \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{\tt in}  & {\em n} & Number of cells\\
\hline
\mbox{\tt in}  & {\em h} & cell widths (size N) \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in}  & {\em u} & cell averages (size N) \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em edge\+\_\+values} & edge values of piecewise polynomials \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt 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}
69   \textcolor{comment}{! Arguments}
70   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: n\textcolor{comment}{ !< Number of cells}
71   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{ !< cell widths (size N) [H]}
72   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{ !< cell averages (size N) [A]}
73   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_values\textcolor{comment}{ !< edge values of piecewise polynomials [A]}
74   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: ppoly\_coef\textcolor{comment}{ !< coefficients of piecewise polynomials, mainly [A]}
75 
76   \textcolor{comment}{! Local variables}
77   \textcolor{keywordtype}{real}          :: u0, u1               \textcolor{comment}{! cell averages}
78   \textcolor{keywordtype}{real}          :: h0, h1               \textcolor{comment}{! corresponding cell widths}
79   \textcolor{keywordtype}{real}          :: slope                \textcolor{comment}{! retained PLM slope}
80   \textcolor{keywordtype}{real}          :: u0\_l, u0\_r           \textcolor{comment}{! edge values}
81 
82   \textcolor{comment}{! -----------------------------------------}
83   \textcolor{comment}{! Left edge value in the left boundary cell}
84   \textcolor{comment}{! -----------------------------------------}
85   h0 = h(1)
86   h1 = h(2)
87 
88   u0 = u(1)
89   u1 = u(2)
90 
91   \textcolor{comment}{! The standard PLM slope is computed as a first estimate for the}
92   \textcolor{comment}{! interpolation within the cell}
93   slope = 2.0 * ( u1 - u0 )
94 
95   \textcolor{comment}{! The right edge value is then computed and we check whether this}
96   \textcolor{comment}{! right edge value is consistent: it cannot be larger than the edge}
97   \textcolor{comment}{! value in the neighboring cell if the data set is increasing.}
98   \textcolor{comment}{! If the right value is found to too large, the slope is further limited}
99   \textcolor{comment}{! by using the edge value in the neighboring cell.}
100   u0\_r = u0 + 0.5 * slope
101 
102   \textcolor{keywordflow}{if} ( (u1 - u0) * (edge\_values(2,1) - u0\_r) < 0.0 ) \textcolor{keywordflow}{then}
103     slope = 2.0 * ( edge\_values(2,1) - u0 )
104 \textcolor{keywordflow}{  endif}
105 
106   \textcolor{comment}{! Using the limited slope, the left edge value is reevaluated and}
107   \textcolor{comment}{! the interpolant coefficients recomputed}
108   \textcolor{keywordflow}{if} ( h0 /= 0.0 ) \textcolor{keywordflow}{then}
109     edge\_values(1,1) = u0 - 0.5 * slope
110   \textcolor{keywordflow}{else}
111     edge\_values(1,1) = u0
112 \textcolor{keywordflow}{  endif}
113 
114   ppoly\_coef(1,1) = edge\_values(1,1)
115   ppoly\_coef(1,2) = edge\_values(1,2) - edge\_values(1,1)
116 
117   \textcolor{comment}{! ------------------------------------------}
118   \textcolor{comment}{! Right edge value in the left boundary cell}
119   \textcolor{comment}{! ------------------------------------------}
120   h0 = h(n-1)
121   h1 = h(n)
122 
123   u0 = u(n-1)
124   u1 = u(n)
125 
126   slope = 2.0 * ( u1 - u0 )
127 
128   u0\_l = u1 - 0.5 * slope
129 
130   \textcolor{keywordflow}{if} ( (u1 - u0) * (u0\_l - edge\_values(n-1,2)) < 0.0 ) \textcolor{keywordflow}{then}
131     slope = 2.0 * ( u1 - edge\_values(n-1,2) )
132 \textcolor{keywordflow}{  endif}
133 
134   \textcolor{keywordflow}{if} ( h1 /= 0.0 ) \textcolor{keywordflow}{then}
135     edge\_values(n,2) = u1 + 0.5 * slope
136   \textcolor{keywordflow}{else}
137     edge\_values(n,2) = u1
138 \textcolor{keywordflow}{  endif}
139 
140   ppoly\_coef(n,1) = edge\_values(n,1)
141   ppoly\_coef(n,2) = edge\_values(n,2) - edge\_values(n,1)
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{\tt in}  & {\em n} & Number of cells\\
\hline
\mbox{\tt in}  & {\em h} & cell widths (size N) \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in}  & {\em u} & cell average properties (size N) \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em edge\+\_\+values} & Potentially modified edge values \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em ppoly\+\_\+coef} & Potentially modified piecewise polynomial coefficients, mainly \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect} & A negligibly small width \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt 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}
28   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: n\textcolor{comment}{ !< Number of cells}
29   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{ !< cell widths (size N) [H]}
30   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: u\textcolor{comment}{ !< cell average properties (size N) [A]}
31   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: edge\_values\textcolor{comment}{ !< Potentially modified edge values [A]}
32   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(inout)} :: ppoly\_coef\textcolor{comment}{ !< Potentially modified}
33 \textcolor{comment}{                                           !! piecewise polynomial coefficients, mainly [A]}
34   \textcolor{keywordtype}{real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width [H]}
35   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true use older, less acccurate expressions.}
36 
37   \textcolor{comment}{! Local variables}
38   \textcolor{keywordtype}{integer}   :: k            \textcolor{comment}{! loop index}
39   \textcolor{keywordtype}{real}      :: u0\_l, u0\_r   \textcolor{comment}{! edge values (left and right)}
40 
41   \textcolor{comment}{! Bound edge values (routine found in 'edge\_values.F90')}
42   \textcolor{keyword}{call }bound\_edge\_values( n, h, u, edge\_values, h\_neglect, answers\_2018 )
43 
44   \textcolor{comment}{! Systematically average discontinuous edge values (routine found in}
45   \textcolor{comment}{! 'edge\_values.F90')}
46   \textcolor{keyword}{call }average\_discontinuous\_edge\_values( n, edge\_values )
47 
48   \textcolor{comment}{! Loop on interior cells to build interpolants}
49   \textcolor{keywordflow}{do} k = 1,n
50 
51     u0\_l = edge\_values(k,1)
52     u0\_r = edge\_values(k,2)
53 
54     ppoly\_coef(k,1) = u0\_l
55     ppoly\_coef(k,2) = u0\_r - u0\_l
56 
57 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end loop on interior cells}
58 
\end{DoxyCode}
