\hypertarget{namespaceregrid__interp}{}\section{regrid\+\_\+interp Module Reference}
\label{namespaceregrid__interp}\index{regrid\+\_\+interp@{regrid\+\_\+interp}}


\subsection{Detailed Description}
Vertical interpolation for regridding. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \hyperlink{structregrid__interp_1_1interp__cs__type}{interp\+\_\+cs\+\_\+type}
\begin{DoxyCompactList}\small\item\em Control structure for \hyperlink{namespaceregrid__interp}{regrid\+\_\+interp} module. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \hyperlink{namespaceregrid__interp_a3d1406836d089b4553421776277e1339}{regridding\+\_\+set\+\_\+ppolys} (CS, densities, n0, h0, ppoly0\+\_\+E, ppoly0\+\_\+S, ppoly0\+\_\+coefs, degree, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Builds an interpolated profile for the densities within each grid cell. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespaceregrid__interp_a52b8ce5b52f9d45f8180c6fd75388174}{interpolate\+\_\+grid} (n0, h0, x0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, target\+\_\+values, degree, n1, h1, x1, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Given target values (e.\+g., density), build new grid based on polynomial. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespaceregrid__interp_abaef8cc7e1258b61710adbd6fb742122}{build\+\_\+and\+\_\+interpolate\+\_\+grid} (CS, densities, n0, h0, x0, target\+\_\+values, n1, h1, x1, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Build a grid by interpolating for target values. \end{DoxyCompactList}\item 
real function \hyperlink{namespaceregrid__interp_a30dfad0833745d069498db25c1538238}{get\+\_\+polynomial\+\_\+coordinate} (N, h, x\+\_\+g, edge\+\_\+values, ppoly\+\_\+coefs, target\+\_\+value, degree, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Given a target value, find corresponding coordinate for given polynomial. \end{DoxyCompactList}\item 
integer function \hyperlink{namespaceregrid__interp_ab4d21d91c26022a3e79268be4fe14d44}{interpolation\+\_\+scheme} (interp\+\_\+scheme)
\begin{DoxyCompactList}\small\item\em Numeric value of interpolation\+\_\+scheme corresponding to scheme name. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespaceregrid__interp_ae77f3027ed51829db5d4ed6dbc744550}{set\+\_\+interp\+\_\+scheme} (CS, interp\+\_\+scheme)
\begin{DoxyCompactList}\small\item\em Store the interpolation\+\_\+scheme value in the interp\+\_\+\+CS based on the input string. \end{DoxyCompactList}\item 
subroutine, public \hyperlink{namespaceregrid__interp_a9ed8b5720d74090e95ca0074240a0d8a}{set\+\_\+interp\+\_\+extrap} (CS, extrap)
\begin{DoxyCompactList}\small\item\em Store the boundary\+\_\+extrapolation value in the interp\+\_\+\+CS. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespaceregrid__interp_a0ec76d7fa1b5308e54bc44a25dca551c}\label{namespaceregrid__interp_a0ec76d7fa1b5308e54bc44a25dca551c}} 
integer, parameter \hyperlink{namespaceregrid__interp_a0ec76d7fa1b5308e54bc44a25dca551c}{interpolation\+\_\+p1m\+\_\+h2} = 0
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$2) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_a490ec10b45d4eb0055fd09d5bc787570}\label{namespaceregrid__interp_a490ec10b45d4eb0055fd09d5bc787570}} 
integer, parameter \hyperlink{namespaceregrid__interp_a490ec10b45d4eb0055fd09d5bc787570}{interpolation\+\_\+p1m\+\_\+h4} = 1
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$2) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_ad0e6beb11f02b409e4c203c4847a949e}\label{namespaceregrid__interp_ad0e6beb11f02b409e4c203c4847a949e}} 
integer, parameter \hyperlink{namespaceregrid__interp_ad0e6beb11f02b409e4c203c4847a949e}{interpolation\+\_\+p1m\+\_\+ih4} = 2
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$2) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_a5854f2a813d5b963987d298ca770a7e7}\label{namespaceregrid__interp_a5854f2a813d5b963987d298ca770a7e7}} 
integer, parameter \hyperlink{namespaceregrid__interp_a5854f2a813d5b963987d298ca770a7e7}{interpolation\+\_\+plm} = 3
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$2) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_a06cc3d7cc7ce4321646cc5599a83544d}\label{namespaceregrid__interp_a06cc3d7cc7ce4321646cc5599a83544d}} 
integer, parameter \hyperlink{namespaceregrid__interp_a06cc3d7cc7ce4321646cc5599a83544d}{interpolation\+\_\+ppm\+\_\+h4} = 4
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$3) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_a35916399421e799d1ad987663817350e}\label{namespaceregrid__interp_a35916399421e799d1ad987663817350e}} 
integer, parameter \hyperlink{namespaceregrid__interp_a35916399421e799d1ad987663817350e}{interpolation\+\_\+ppm\+\_\+ih4} = 5
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$3) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_a201c2e2dd8cc9581406f2e1066caa50b}\label{namespaceregrid__interp_a201c2e2dd8cc9581406f2e1066caa50b}} 
integer, parameter \hyperlink{namespaceregrid__interp_a201c2e2dd8cc9581406f2e1066caa50b}{interpolation\+\_\+p3m\+\_\+ih4ih3} = 6
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$4) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_ae72fa5caf83881dda1ec2c4130bcb261}\label{namespaceregrid__interp_ae72fa5caf83881dda1ec2c4130bcb261}} 
integer, parameter \hyperlink{namespaceregrid__interp_ae72fa5caf83881dda1ec2c4130bcb261}{interpolation\+\_\+p3m\+\_\+ih6ih5} = 7
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$4) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_a18c34dfd8e5582e94c76fa0dee5c8390}\label{namespaceregrid__interp_a18c34dfd8e5582e94c76fa0dee5c8390}} 
integer, parameter \hyperlink{namespaceregrid__interp_a18c34dfd8e5582e94c76fa0dee5c8390}{interpolation\+\_\+pqm\+\_\+ih4ih3} = 8
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$4) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_acd2d0f29f9e3383c6f97969c028a46cc}\label{namespaceregrid__interp_acd2d0f29f9e3383c6f97969c028a46cc}} 
integer, parameter \hyperlink{namespaceregrid__interp_acd2d0f29f9e3383c6f97969c028a46cc}{interpolation\+\_\+pqm\+\_\+ih6ih5} = 9
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$5) \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_ab5894f4be17b065c3939294014200a32}\label{namespaceregrid__interp_ab5894f4be17b065c3939294014200a32}} 
real, parameter, public \hyperlink{namespaceregrid__interp_ab5894f4be17b065c3939294014200a32}{nr\+\_\+offset} = 1e-\/6
\begin{DoxyCompactList}\small\item\em When the N-\/R algorithm produces an estimate that lies outside \mbox{[}0,1\mbox{]}, the estimate is set to be equal to the boundary location, 0 or 1, plus or minus an offset, respectively, when the derivative is zero at the boundary \mbox{[}nondim\mbox{]}. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_a6543421d37edc724a8a7928ccf54a21c}\label{namespaceregrid__interp_a6543421d37edc724a8a7928ccf54a21c}} 
integer, parameter, public \hyperlink{namespaceregrid__interp_a6543421d37edc724a8a7928ccf54a21c}{nr\+\_\+iterations} = 8
\begin{DoxyCompactList}\small\item\em Maximum number of Newton-\/\+Raphson iterations. Newton-\/\+Raphson iterations are used to build the new grid by finding the coordinates associated with target densities and interpolations of degree larger than 1. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_aa85701b7a23c13c6ac8b19916b13bb3e}\label{namespaceregrid__interp_aa85701b7a23c13c6ac8b19916b13bb3e}} 
real, parameter, public \hyperlink{namespaceregrid__interp_aa85701b7a23c13c6ac8b19916b13bb3e}{nr\+\_\+tolerance} = 1e-\/12
\begin{DoxyCompactList}\small\item\em Tolerance for Newton-\/\+Raphson iterations (stop when increment falls below this) \mbox{[}nondim\mbox{]}. \end{DoxyCompactList}\end{DoxyCompactItemize}
\textbf{ }\par
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespaceregrid__interp_a3ef8c1375e14fdf87fcd6997f54808eb}\label{namespaceregrid__interp_a3ef8c1375e14fdf87fcd6997f54808eb}} 
integer, parameter \hyperlink{namespaceregrid__interp_a3ef8c1375e14fdf87fcd6997f54808eb}{degree\+\_\+1} = 1
\begin{DoxyCompactList}\small\item\em Interpolant degrees. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_ae60a96eeb669ff4dfa45f8518742a454}\label{namespaceregrid__interp_ae60a96eeb669ff4dfa45f8518742a454}} 
integer, parameter \hyperlink{namespaceregrid__interp_ae60a96eeb669ff4dfa45f8518742a454}{degree\+\_\+2} = 2
\begin{DoxyCompactList}\small\item\em Interpolant degrees. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_a3c0fdeca3856901e56168587dfa1ae9f}\label{namespaceregrid__interp_a3c0fdeca3856901e56168587dfa1ae9f}} 
integer, parameter \hyperlink{namespaceregrid__interp_a3c0fdeca3856901e56168587dfa1ae9f}{degree\+\_\+3} = 3
\begin{DoxyCompactList}\small\item\em Interpolant degrees. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_af4b7a5ee9f8833f1defeb74cf10ae79d}\label{namespaceregrid__interp_af4b7a5ee9f8833f1defeb74cf10ae79d}} 
integer, parameter \hyperlink{namespaceregrid__interp_af4b7a5ee9f8833f1defeb74cf10ae79d}{degree\+\_\+4} = 4
\begin{DoxyCompactList}\small\item\em Interpolant degrees. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespaceregrid__interp_af4013d842f389abc724a0d2f34366eda}\label{namespaceregrid__interp_af4013d842f389abc724a0d2f34366eda}} 
integer, parameter, public \hyperlink{namespaceregrid__interp_af4013d842f389abc724a0d2f34366eda}{degree\+\_\+max} = 5
\begin{DoxyCompactList}\small\item\em Interpolant degrees. \end{DoxyCompactList}\end{DoxyCompactItemize}



\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespaceregrid__interp_abaef8cc7e1258b61710adbd6fb742122}\label{namespaceregrid__interp_abaef8cc7e1258b61710adbd6fb742122}} 
\index{regrid\+\_\+interp@{regrid\+\_\+interp}!build\+\_\+and\+\_\+interpolate\+\_\+grid@{build\+\_\+and\+\_\+interpolate\+\_\+grid}}
\index{build\+\_\+and\+\_\+interpolate\+\_\+grid@{build\+\_\+and\+\_\+interpolate\+\_\+grid}!regrid\+\_\+interp@{regrid\+\_\+interp}}
\subsubsection{\texorpdfstring{build\+\_\+and\+\_\+interpolate\+\_\+grid()}{build\_and\_interpolate\_grid()}}
{\footnotesize\ttfamily subroutine, public regrid\+\_\+interp\+::build\+\_\+and\+\_\+interpolate\+\_\+grid (\begin{DoxyParamCaption}\item[{type(\hyperlink{structregrid__interp_1_1interp__cs__type}{interp\+\_\+cs\+\_\+type}), intent(in)}]{CS,  }\item[{real, dimension(n0), intent(in)}]{densities,  }\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0+1), intent(in)}]{x0,  }\item[{real, dimension(n1+1), intent(in)}]{target\+\_\+values,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(n1), intent(inout)}]{h1,  }\item[{real, dimension(n1+1), intent(inout)}]{x1,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})}



Build a grid by interpolating for target values. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em cs} & A control structure for \hyperlink{namespaceregrid__interp}{regrid\+\_\+interp}\\
\hline
\mbox{\tt in}  & {\em n0} & The number of points on the input grid\\
\hline
\mbox{\tt in}  & {\em n1} & The number of points on the output grid\\
\hline
\mbox{\tt in}  & {\em densities} & Input cell densities \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}\\
\hline
\mbox{\tt in}  & {\em target\+\_\+values} & Target values of interfaces \mbox{[}R $\sim$$>$ kg m-\/3\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h0} & Initial cell widths \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in}  & {\em x0} & Source interface positions \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em h1} & Output cell widths \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em x1} & Target interface positions \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions \mbox{[}H\mbox{]} in the same units as h0.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect\+\_\+edge} & A negligibly small width for the purpose of edge value calculations \mbox{[}H\mbox{]} in the same units as h0. \\
\hline
\end{DoxyParams}


Definition at line 309 of file regrid\+\_\+interp.\+F90.


\begin{DoxyCode}
309   \textcolor{keywordtype}{type}(interp\_cs\_type),  \textcolor{keywordtype}{intent(in)}    :: cs\textcolor{comment}{  !< A control structure for regrid\_interp}
310   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: n0\textcolor{comment}{  !< The number of points on the input grid}
311   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: n1\textcolor{comment}{  !< The number of points on the output grid}
312   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}    :: densities\textcolor{comment}{ !< Input cell densities [R ~> kg m-3]}
313   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1+1)}, \textcolor{keywordtype}{intent(in)}    :: target\_values\textcolor{comment}{ !< Target values of interfaces [R ~> kg m-3]}
314   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}    :: h0\textcolor{comment}{  !< Initial cell widths [H]}
315   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0+1)}, \textcolor{keywordtype}{intent(in)}    :: x0\textcolor{comment}{  !< Source interface positions [H]}
316   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1)},   \textcolor{keywordtype}{intent(inout)} :: h1\textcolor{comment}{  !< Output cell widths [H]}
317   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1+1)}, \textcolor{keywordtype}{intent(inout)} :: x1\textcolor{comment}{  !< Target interface positions [H]}
318   \textcolor{keywordtype}{real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}
319 \textcolor{comment}{                                           !! purpose of cell reconstructions [H]}
320 \textcolor{comment}{                                           !! in the same units as h0.}
321   \textcolor{keywordtype}{real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width}
322 \textcolor{comment}{                                           !! for the purpose of edge value calculations [H]}
323 \textcolor{comment}{                                           !! in the same units as h0.}
324 
325   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)} :: ppoly0\_e   \textcolor{comment}{! Polynomial edge values [R ~> kg m-3]}
326   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)} :: ppoly0\_s   \textcolor{comment}{! Polynomial edge slopes [R H-1]}
327   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,DEGREE\_MAX+1)} :: ppoly0\_c  \textcolor{comment}{! Polynomial interpolant coeficients on the local 0-1 grid
       [R ~> kg m-3]}
328   \textcolor{keywordtype}{integer} :: degree
329 
330   \textcolor{keyword}{call }regridding\_set\_ppolys(cs, densities, n0, h0, ppoly0\_e, ppoly0\_s, ppoly0\_c, &
331        degree, h\_neglect, h\_neglect\_edge)
332   \textcolor{keyword}{call }interpolate\_grid(n0, h0, x0, ppoly0\_e, ppoly0\_c, target\_values, degree, &
333        n1, h1, x1, answers\_2018=cs%answers\_2018)
\end{DoxyCode}
\mbox{\Hypertarget{namespaceregrid__interp_a30dfad0833745d069498db25c1538238}\label{namespaceregrid__interp_a30dfad0833745d069498db25c1538238}} 
\index{regrid\+\_\+interp@{regrid\+\_\+interp}!get\+\_\+polynomial\+\_\+coordinate@{get\+\_\+polynomial\+\_\+coordinate}}
\index{get\+\_\+polynomial\+\_\+coordinate@{get\+\_\+polynomial\+\_\+coordinate}!regrid\+\_\+interp@{regrid\+\_\+interp}}
\subsubsection{\texorpdfstring{get\+\_\+polynomial\+\_\+coordinate()}{get\_polynomial\_coordinate()}}
{\footnotesize\ttfamily real function regrid\+\_\+interp\+::get\+\_\+polynomial\+\_\+coordinate (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{N,  }\item[{real, dimension(n), intent(in)}]{h,  }\item[{real, dimension(n+1), intent(in)}]{x\+\_\+g,  }\item[{real, dimension(n,2), intent(in)}]{edge\+\_\+values,  }\item[{real, dimension(n,\hyperlink{namespaceregrid__interp_af4013d842f389abc724a0d2f34366eda}{degree\+\_\+max}+1), intent(in)}]{ppoly\+\_\+coefs,  }\item[{real, intent(in)}]{target\+\_\+value,  }\item[{integer, intent(in)}]{degree,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Given a target value, find corresponding coordinate for given polynomial. 

Here, \textquotesingle{}ppoly\textquotesingle{} is assumed to be a piecewise discontinuous polynomial of degree \textquotesingle{}degree\textquotesingle{} throughout the domain defined by \textquotesingle{}grid\textquotesingle{}. A target value is given and we need to determine the corresponding grid coordinate to define the new grid.

If the target value is out of range, the grid coordinate is simply set to be equal to one of the boundary coordinates, which results in vanished layers near the boundaries.

IT IS A\+S\+S\+U\+M\+ED T\+H\+AT T\+HE P\+I\+E\+C\+E\+W\+I\+SE P\+O\+L\+Y\+N\+O\+M\+I\+AL IS M\+O\+N\+O\+T\+O\+N\+I\+C\+A\+L\+LY I\+N\+C\+R\+E\+A\+S\+I\+NG. IF T\+H\+IS IS N\+OT T\+HE C\+A\+SE, T\+HE N\+EW G\+R\+ID M\+AY BE I\+L\+L-\/\+D\+E\+F\+I\+N\+ED.

It is assumed that the number of cells defining \textquotesingle{}grid\textquotesingle{} and \textquotesingle{}ppoly\textquotesingle{} are the same.


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n} & Number of grid cells\\
\hline
\mbox{\tt in}  & {\em h} & Grid cell thicknesses \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in}  & {\em x\+\_\+g} & Grid interface locations \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in}  & {\em edge\+\_\+values} & Edge values of interpolating polynomials \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ppoly\+\_\+coefs} & Coefficients of interpolating polynomials \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in}  & {\em target\+\_\+value} & Target value to find position for \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in}  & {\em degree} & Degree of the interpolating polynomials\\
\hline
\mbox{\tt in}  & {\em answers\+\_\+2018} & If true use older, less acccurate expressions.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The position of x\+\_\+g at which target\+\_\+value is found \mbox{[}H\mbox{]} 
\end{DoxyReturn}


Definition at line 354 of file regrid\+\_\+interp.\+F90.


\begin{DoxyCode}
354   \textcolor{comment}{! Arguments}
355   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)} :: n\textcolor{comment}{            !< Number of grid cells}
356   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(N)},   \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{            !< Grid cell thicknesses [H]}
357   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(N+1)}, \textcolor{keywordtype}{intent(in)} :: x\_g\textcolor{comment}{          !< Grid interface locations [H]}
358   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(N,2)}, \textcolor{keywordtype}{intent(in)} :: edge\_values\textcolor{comment}{  !< Edge values of interpolating polynomials [A]}
359   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(N,DEGREE\_MAX+1)}, \textcolor{keywordtype}{intent(in)} :: ppoly\_coefs\textcolor{comment}{  !< Coefficients of interpolating polynomials
       [A]}
360   \textcolor{keywordtype}{real},                 \textcolor{keywordtype}{intent(in)} :: target\_value\textcolor{comment}{ !< Target value to find position for [A]}
361   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)} :: degree\textcolor{comment}{       !< Degree of the interpolating polynomials}
362   \textcolor{keywordtype}{logical},    \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: answers\_2018\textcolor{comment}{ !< If true use older, less acccurate expressions.}
363   \textcolor{keywordtype}{real}                             :: x\_tgt\textcolor{comment}{        !< The position of x\_g at which target\_value is found
       [H]}
364 
365   \textcolor{comment}{! Local variables}
366   \textcolor{keywordtype}{real}                        :: xi0         \textcolor{comment}{! normalized target coordinate [nondim]}
367   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(DEGREE\_MAX)} :: a           \textcolor{comment}{! polynomial coefficients [A]}
368   \textcolor{keywordtype}{real}                        :: numerator
369   \textcolor{keywordtype}{real}                        :: denominator
370   \textcolor{keywordtype}{real}                        :: delta       \textcolor{comment}{! Newton-Raphson increment [nondim]}
371 \textcolor{comment}{!   real                        :: x           ! global target coordinate}
372   \textcolor{keywordtype}{real}                        :: eps         \textcolor{comment}{! offset used to get away from boundaries [nondim]}
373   \textcolor{keywordtype}{real}                        :: grad        \textcolor{comment}{! gradient during N-R iterations [A]}
374   \textcolor{keywordtype}{integer} :: i, k, iter  \textcolor{comment}{! loop indices}
375   \textcolor{keywordtype}{integer} :: k\_found     \textcolor{comment}{! index of target cell}
376   \textcolor{keywordtype}{character(len=200)} :: mesg
377   \textcolor{keywordtype}{logical} :: use\_2018\_answers  \textcolor{comment}{! If true use older, less acccurate expressions.}
378 
379   eps = nr\_offset
380   k\_found = -1
381   use\_2018\_answers = .true. ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(answers\_2018)) use\_2018\_answers = answers\_2018
382 
383   \textcolor{comment}{! If the target value is outside the range of all values, we}
384   \textcolor{comment}{! force the target coordinate to be equal to the lowest or}
385   \textcolor{comment}{! largest value, depending on which bound is overtaken}
386   \textcolor{keywordflow}{if} ( target\_value <= edge\_values(1,1) ) \textcolor{keywordflow}{then}
387     x\_tgt = x\_g(1)
388     \textcolor{keywordflow}{return}  \textcolor{comment}{! return because there is no need to look further}
389 \textcolor{keywordflow}{  endif}
390 
391   \textcolor{comment}{! Since discontinuous edge values are allowed, we check whether the target}
392   \textcolor{comment}{! value lies between two discontinuous edge values at interior interfaces}
393   \textcolor{keywordflow}{do} k = 2,n
394     \textcolor{keywordflow}{if} ( ( target\_value >= edge\_values(k-1,2) ) .AND. ( target\_value <= edge\_values(k,1) ) ) \textcolor{keywordflow}{then}
395       x\_tgt = x\_g(k)
396       \textcolor{keywordflow}{return}   \textcolor{comment}{! return because there is no need to look further}
397 \textcolor{keywordflow}{    endif}
398 \textcolor{keywordflow}{  enddo}
399 
400   \textcolor{comment}{! If the target value is outside the range of all values, we}
401   \textcolor{comment}{! force the target coordinate to be equal to the lowest or}
402   \textcolor{comment}{! largest value, depending on which bound is overtaken}
403   \textcolor{keywordflow}{if} ( target\_value >= edge\_values(n,2) ) \textcolor{keywordflow}{then}
404     x\_tgt = x\_g(n+1)
405     \textcolor{keywordflow}{return}  \textcolor{comment}{! return because there is no need to look further}
406 \textcolor{keywordflow}{  endif}
407 
408   \textcolor{comment}{! At this point, we know that the target value is bounded and does not}
409   \textcolor{comment}{! lie between discontinuous, monotonic edge values. Therefore,}
410   \textcolor{comment}{! there is a unique solution. We loop on all cells and find which one}
411   \textcolor{comment}{! contains the target value. The variable k\_found holds the index value}
412   \textcolor{comment}{! of the cell where the taregt value lies.}
413   \textcolor{keywordflow}{do} k = 1,n
414     \textcolor{keywordflow}{if} ( ( target\_value > edge\_values(k,1) ) .AND. ( target\_value < edge\_values(k,2) ) ) \textcolor{keywordflow}{then}
415       k\_found = k
416       \textcolor{keywordflow}{exit}
417 \textcolor{keywordflow}{    endif}
418 \textcolor{keywordflow}{  enddo}
419 
420   \textcolor{comment}{! At this point, 'k\_found' should be strictly positive. If not, this is}
421   \textcolor{comment}{! a major failure because it means we could not find any target cell}
422   \textcolor{comment}{! despite the fact that the target value lies between the extremes. It}
423   \textcolor{comment}{! means there is a major problem with the interpolant. This needs to be}
424   \textcolor{comment}{! reported.}
425   \textcolor{keywordflow}{if} ( k\_found == -1 ) \textcolor{keywordflow}{then}
426     \textcolor{keyword}{write}(mesg,*) \textcolor{stringliteral}{'Could not find target coordinate'}, target\_value, \textcolor{stringliteral}{'in get\_polynomial\_coordinate. This is
       '}//&
427                   \textcolor{stringliteral}{'caused by an inconsistent interpolant (perhaps not monotonically increasing):'}, &
428                   target\_value, edge\_values(1,1), edge\_values(n,2)
429     \textcolor{keyword}{call }mom\_error( fatal, mesg )
430 \textcolor{keywordflow}{  endif}
431 
432   \textcolor{comment}{! Reset all polynomial coefficients to 0 and copy those pertaining to}
433   \textcolor{comment}{! the found cell}
434   a(:) = 0.0
435   \textcolor{keywordflow}{do} i = 1,degree+1
436     a(i) = ppoly\_coefs(k\_found,i)
437 \textcolor{keywordflow}{  enddo}
438 
439   \textcolor{comment}{! Guess the middle of the cell to start Newton-Raphson iterations}
440   xi0 = 0.5
441 
442   \textcolor{comment}{! Newton-Raphson iterations}
443   \textcolor{keywordflow}{do} iter = 1,nr\_iterations
444 
445     \textcolor{keywordflow}{if} (use\_2018\_answers) \textcolor{keywordflow}{then}
446       numerator = a(1) + a(2)*xi0 + a(3)*xi0*xi0 + a(4)*xi0*xi0*xi0 + &
447                   a(5)*xi0*xi0*xi0*xi0 - target\_value
448       denominator = a(2) + 2*a(3)*xi0 + 3*a(4)*xi0*xi0 + 4*a(5)*xi0*xi0*xi0
449     \textcolor{keywordflow}{else}  \textcolor{comment}{! These expressions are mathematicaly equivalent but more accurate.}
450       numerator = (a(1) - target\_value) + xi0*(a(2) + xi0*(a(3) + xi0*(a(4) + a(5)*xi0)))
451       denominator = a(2) + xi0*(2.*a(3) + xi0*(3.*a(4) + 4.*a(5)*xi0))
452 \textcolor{keywordflow}{    endif}
453 
454     delta = -numerator / denominator
455 
456     xi0 = xi0 + delta
457 
458     \textcolor{comment}{! Check whether new estimate is out of bounds. If the new estimate is}
459     \textcolor{comment}{! indeed out of bounds, we manually set it to be equal to the overtaken}
460     \textcolor{comment}{! bound with a small offset towards the interior when the gradient of}
461     \textcolor{comment}{! the function at the boundary is zero (in which case, the Newton-Raphson}
462     \textcolor{comment}{! algorithm does not converge).}
463     \textcolor{keywordflow}{if} ( xi0 < 0.0 ) \textcolor{keywordflow}{then}
464       xi0 = 0.0
465       grad = a(2)
466       \textcolor{keywordflow}{if} ( grad == 0.0 ) xi0 = xi0 + eps
467 \textcolor{keywordflow}{    endif}
468 
469     \textcolor{keywordflow}{if} ( xi0 > 1.0 ) \textcolor{keywordflow}{then}
470       xi0 = 1.0
471       \textcolor{keywordflow}{if} (use\_2018\_answers) \textcolor{keywordflow}{then}
472         grad = a(2) + 2*a(3) + 3*a(4) + 4*a(5)
473       \textcolor{keywordflow}{else}  \textcolor{comment}{! These expressions are mathematicaly equivalent but more accurate.}
474         grad = a(2) + (2.*a(3) + (3.*a(4) + 4.*a(5)))
475 \textcolor{keywordflow}{      endif}
476       \textcolor{keywordflow}{if} ( grad == 0.0 ) xi0 = xi0 - eps
477 \textcolor{keywordflow}{    endif}
478 
479     \textcolor{comment}{! break if converged or too many iterations taken}
480     \textcolor{keywordflow}{if} ( abs(delta) < nr\_tolerance ) \textcolor{keywordflow}{exit}
481 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end Newton-Raphson iterations}
482 
483   x\_tgt = x\_g(k\_found) + xi0 * h(k\_found)
\end{DoxyCode}
\mbox{\Hypertarget{namespaceregrid__interp_a52b8ce5b52f9d45f8180c6fd75388174}\label{namespaceregrid__interp_a52b8ce5b52f9d45f8180c6fd75388174}} 
\index{regrid\+\_\+interp@{regrid\+\_\+interp}!interpolate\+\_\+grid@{interpolate\+\_\+grid}}
\index{interpolate\+\_\+grid@{interpolate\+\_\+grid}!regrid\+\_\+interp@{regrid\+\_\+interp}}
\subsubsection{\texorpdfstring{interpolate\+\_\+grid()}{interpolate\_grid()}}
{\footnotesize\ttfamily subroutine, public regrid\+\_\+interp\+::interpolate\+\_\+grid (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0+1), intent(in)}]{x0,  }\item[{real, dimension(n0,2), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(n0,\hyperlink{namespaceregrid__interp_af4013d842f389abc724a0d2f34366eda}{degree\+\_\+max}+1), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{real, dimension(n1+1), intent(in)}]{target\+\_\+values,  }\item[{integer, intent(in)}]{degree,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(n1), intent(inout)}]{h1,  }\item[{real, dimension(n1+1), intent(inout)}]{x1,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})}



Given target values (e.\+g., density), build new grid based on polynomial. 

Given the grid \textquotesingle{}grid0\textquotesingle{} and the piecewise polynomial interpolant \textquotesingle{}ppoly0\textquotesingle{} (possibly discontinuous), the coordinates of the new grid \textquotesingle{}grid1\textquotesingle{} are determined by finding the corresponding target interface densities.


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n0} & Number of points on source grid\\
\hline
\mbox{\tt in}  & {\em n1} & Number of points on target grid\\
\hline
\mbox{\tt in}  & {\em h0} & Thicknesses of source grid cells \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in}  & {\em x0} & Source interface positions \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+e} & Edge values of interpolating polynomials \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+coefs} & Coefficients of interpolating polynomials \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in}  & {\em target\+\_\+values} & Target values of interfaces \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in}  & {\em degree} & Degree of interpolating polynomials\\
\hline
\mbox{\tt in,out}  & {\em h1} & Thicknesses of target grid cells \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em x1} & Target interface positions \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in}  & {\em answers\+\_\+2018} & If true use older, less acccurate expressions. \\
\hline
\end{DoxyParams}


Definition at line 272 of file regrid\+\_\+interp.\+F90.


\begin{DoxyCode}
272   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}     :: n0\textcolor{comment}{            !< Number of points on source grid}
273   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}     :: n1\textcolor{comment}{            !< Number of points on target grid}
274   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}     :: h0\textcolor{comment}{            !< Thicknesses of source grid cells [H]}
275   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0+1)}, \textcolor{keywordtype}{intent(in)}     :: x0\textcolor{comment}{            !< Source interface positions [H]}
276   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)}, \textcolor{keywordtype}{intent(in)}     :: ppoly0\_e\textcolor{comment}{      !< Edge values of interpolating polynomials [A]}
277   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,DEGREE\_MAX+1)}, &
278                           \textcolor{keywordtype}{intent(in)}    :: ppoly0\_coefs\textcolor{comment}{  !< Coefficients of interpolating polynomials [A]}
279   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1+1)},  \textcolor{keywordtype}{intent(in)}    :: target\_values\textcolor{comment}{ !< Target values of interfaces [A]}
280   \textcolor{keywordtype}{integer},                \textcolor{keywordtype}{intent(in)}    :: degree\textcolor{comment}{        !< Degree of interpolating polynomials}
281   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1)},    \textcolor{keywordtype}{intent(inout)} :: h1\textcolor{comment}{            !< Thicknesses of target grid cells [H]}
282   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1+1)},  \textcolor{keywordtype}{intent(inout)} :: x1\textcolor{comment}{            !< Target interface positions [H]}
283   \textcolor{keywordtype}{logical},      \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{  !< If true use older, less acccurate expressions.}
284 
285   \textcolor{comment}{! Local variables}
286   \textcolor{keywordtype}{logical}   :: use\_2018\_answers  \textcolor{comment}{! If true use older, less acccurate expressions.}
287   \textcolor{keywordtype}{integer}        :: k \textcolor{comment}{! loop index}
288   \textcolor{keywordtype}{real}           :: t \textcolor{comment}{! current interface target density}
289 
290   \textcolor{comment}{! Make sure boundary coordinates of new grid coincide with boundary}
291   \textcolor{comment}{! coordinates of previous grid}
292   x1(1) = x0(1)
293   x1(n1+1) = x0(n0+1)
294 
295   \textcolor{comment}{! Find coordinates for interior target values}
296   \textcolor{keywordflow}{do} k = 2,n1
297     t = target\_values(k)
298     x1(k) = get\_polynomial\_coordinate( n0, h0, x0, ppoly0\_e, ppoly0\_coefs, t, degree, &
299                                         answers\_2018=answers\_2018 )
300     h1(k-1) = x1(k) - x1(k-1)
301 \textcolor{keywordflow}{  enddo}
302   h1(n1) = x1(n1+1) - x1(n1)
303 
\end{DoxyCode}
\mbox{\Hypertarget{namespaceregrid__interp_ab4d21d91c26022a3e79268be4fe14d44}\label{namespaceregrid__interp_ab4d21d91c26022a3e79268be4fe14d44}} 
\index{regrid\+\_\+interp@{regrid\+\_\+interp}!interpolation\+\_\+scheme@{interpolation\+\_\+scheme}}
\index{interpolation\+\_\+scheme@{interpolation\+\_\+scheme}!regrid\+\_\+interp@{regrid\+\_\+interp}}
\subsubsection{\texorpdfstring{interpolation\+\_\+scheme()}{interpolation\_scheme()}}
{\footnotesize\ttfamily integer function regrid\+\_\+interp\+::interpolation\+\_\+scheme (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{interp\+\_\+scheme }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Numeric value of interpolation\+\_\+scheme corresponding to scheme name. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em interp\+\_\+scheme} & Name of the interpolation scheme Valid values include \char`\"{}\+P1\+M\+\_\+\+H2\char`\"{}, \char`\"{}\+P1\+M\+\_\+\+H4\char`\"{}, \char`\"{}\+P1\+M\+\_\+\+I\+H2\char`\"{}, \char`\"{}\+P\+L\+M\char`\"{}, \char`\"{}\+P\+P\+M\+\_\+\+H4\char`\"{}, \char`\"{}\+P\+P\+M\+\_\+\+I\+H4\char`\"{}, \char`\"{}\+P3\+M\+\_\+\+I\+H4\+I\+H3\char`\"{}, \char`\"{}\+P3\+M\+\_\+\+I\+H6\+I\+H5\char`\"{}, \char`\"{}\+P\+Q\+M\+\_\+\+I\+H4\+I\+H3\char`\"{}, and \char`\"{}\+P\+Q\+M\+\_\+\+I\+H6\+I\+H5\char`\"{} \\
\hline
\end{DoxyParams}


Definition at line 488 of file regrid\+\_\+interp.\+F90.


\begin{DoxyCode}
488   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{intent(in)} :: interp\_scheme\textcolor{comment}{ !< Name of the interpolation scheme}
489 \textcolor{comment}{        !! Valid values include "P1M\_H2", "P1M\_H4", "P1M\_IH2", "PLM", "PPM\_H4",}
490 \textcolor{comment}{        !!   "PPM\_IH4", "P3M\_IH4IH3", "P3M\_IH6IH5", "PQM\_IH4IH3", and "PQM\_IH6IH5"}
491 
492   \textcolor{keywordflow}{select case} ( uppercase(trim(interp\_scheme)) )
493     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"P1M\_H2"});     interpolation\_scheme = interpolation\_p1m\_h2
494     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"P1M\_H4"});     interpolation\_scheme = interpolation\_p1m\_h4
495     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"P1M\_IH2"});    interpolation\_scheme = interpolation\_p1m\_ih4
496     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PLM"});        interpolation\_scheme = interpolation\_plm
497     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PPM\_H4"});     interpolation\_scheme = interpolation\_ppm\_h4
498     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PPM\_IH4"});    interpolation\_scheme = interpolation\_ppm\_ih4
499     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"P3M\_IH4IH3"}); interpolation\_scheme = interpolation\_p3m\_ih4ih3
500     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"P3M\_IH6IH5"}); interpolation\_scheme = interpolation\_p3m\_ih6ih5
501     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PQM\_IH4IH3"}); interpolation\_scheme = interpolation\_pqm\_ih4ih3
502     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PQM\_IH6IH5"}); interpolation\_scheme = interpolation\_pqm\_ih6ih5
503 \textcolor{keywordflow}{    case default} ; \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"regrid\_interp: "}//&
504      \textcolor{stringliteral}{"Unrecognized choice for INTERPOLATION\_SCHEME ("}//trim(interp\_scheme)//\textcolor{stringliteral}{")."})
505 \textcolor{keywordflow}{  end select}
\end{DoxyCode}
\mbox{\Hypertarget{namespaceregrid__interp_a3d1406836d089b4553421776277e1339}\label{namespaceregrid__interp_a3d1406836d089b4553421776277e1339}} 
\index{regrid\+\_\+interp@{regrid\+\_\+interp}!regridding\+\_\+set\+\_\+ppolys@{regridding\+\_\+set\+\_\+ppolys}}
\index{regridding\+\_\+set\+\_\+ppolys@{regridding\+\_\+set\+\_\+ppolys}!regrid\+\_\+interp@{regrid\+\_\+interp}}
\subsubsection{\texorpdfstring{regridding\+\_\+set\+\_\+ppolys()}{regridding\_set\_ppolys()}}
{\footnotesize\ttfamily subroutine, public regrid\+\_\+interp\+::regridding\+\_\+set\+\_\+ppolys (\begin{DoxyParamCaption}\item[{type(\hyperlink{structregrid__interp_1_1interp__cs__type}{interp\+\_\+cs\+\_\+type}), intent(in)}]{CS,  }\item[{real, dimension(n0), intent(in)}]{densities,  }\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0,2), intent(inout)}]{ppoly0\+\_\+E,  }\item[{real, dimension(n0,2), intent(inout)}]{ppoly0\+\_\+S,  }\item[{real, dimension(n0,\hyperlink{namespaceregrid__interp_af4013d842f389abc724a0d2f34366eda}{degree\+\_\+max}+1), intent(inout)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(inout)}]{degree,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})}



Builds an interpolated profile for the densities within each grid cell. 

It may happen that, given a high-\/order interpolator, the number of available layers is insufficient (e.\+g., there are two available layers for a third-\/order P\+PM ih4 scheme). In these cases, we resort to the simplest continuous linear scheme (P1M h2).


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em cs} & Interpolation control structure\\
\hline
\mbox{\tt in}  & {\em n0} & Number of cells on source grid\\
\hline
\mbox{\tt in}  & {\em densities} & Actual cell densities \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in}  & {\em h0} & cell widths on source grid \mbox{[}H\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em ppoly0\+\_\+e} & Edge value of polynomial \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em ppoly0\+\_\+s} & Edge slope of polynomial \mbox{[}A H-\/1\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial \mbox{[}A\mbox{]}\\
\hline
\mbox{\tt in,out}  & {\em degree} & The degree of the polynomials\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions \mbox{[}H\mbox{]} in the same units as h0.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect\+\_\+edge} & A negligibly small width for the purpose of edge value calculations \mbox{[}H\mbox{]} in the same units as h0. \\
\hline
\end{DoxyParams}


Definition at line 80 of file regrid\+\_\+interp.\+F90.


\begin{DoxyCode}
80   \textcolor{keywordtype}{type}(interp\_cs\_type),  \textcolor{keywordtype}{intent(in)}    :: cs\textcolor{comment}{ !< Interpolation control structure}
81   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: n0\textcolor{comment}{ !< Number of cells on source grid}
82   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}    :: densities\textcolor{comment}{ !< Actual cell densities [A]}
83   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}    :: h0\textcolor{comment}{ !< cell widths on source grid [H]}
84   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)}, \textcolor{keywordtype}{intent(inout)} :: ppoly0\_e\textcolor{comment}{  !< Edge value of polynomial [A]}
85   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)}, \textcolor{keywordtype}{intent(inout)} :: ppoly0\_s\textcolor{comment}{  !< Edge slope of polynomial [A H-1]}
86   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,DEGREE\_MAX+1)}, \textcolor{keywordtype}{intent(inout)} :: ppoly0\_coefs\textcolor{comment}{ !< Coefficients of polynomial [A]}
87   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(inout)} :: degree\textcolor{comment}{    !< The degree of the polynomials}
88   \textcolor{keywordtype}{real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}
89 \textcolor{comment}{                                             !! purpose of cell reconstructions [H]}
90 \textcolor{comment}{                                             !! in the same units as h0.}
91   \textcolor{keywordtype}{real},        \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width}
92 \textcolor{comment}{                                             !! for the purpose of edge value calculations [H]}
93 \textcolor{comment}{                                             !! in the same units as h0.}
94   \textcolor{comment}{! Local variables}
95   \textcolor{keywordtype}{logical} :: extrapolate
96 
97   \textcolor{comment}{! Reset piecewise polynomials}
98   ppoly0\_e(:,:) = 0.0
99   ppoly0\_s(:,:) = 0.0
100   ppoly0\_coefs(:,:) = 0.0
101 
102   extrapolate = cs%boundary\_extrapolation
103 
104   \textcolor{comment}{! Compute the interpolated profile of the density field and build grid}
105   \textcolor{keywordflow}{select case} (cs%interpolation\_scheme)
106 
107     \textcolor{keywordflow}{case} ( interpolation\_p1m\_h2 )
108       degree = degree\_1
109       \textcolor{keyword}{call }edge\_values\_explicit\_h2( n0, h0, densities, ppoly0\_e )
110       \textcolor{keyword}{call }p1m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
111       \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
112         \textcolor{keyword}{call }p1m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs )
113 \textcolor{keywordflow}{      endif}
114 
115     \textcolor{keywordflow}{case} ( interpolation\_p1m\_h4 )
116       degree = degree\_1
117       \textcolor{keywordflow}{if} ( n0 >= 4 ) \textcolor{keywordflow}{then}
118         \textcolor{keyword}{call }edge\_values\_explicit\_h4( n0, h0, densities, ppoly0\_e, h\_neglect\_edge, answers\_2018=cs
      %answers\_2018 )
119       \textcolor{keywordflow}{else}
120         \textcolor{keyword}{call }edge\_values\_explicit\_h2( n0, h0, densities, ppoly0\_e )
121 \textcolor{keywordflow}{      endif}
122       \textcolor{keyword}{call }p1m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
123       \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
124         \textcolor{keyword}{call }p1m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs )
125 \textcolor{keywordflow}{      endif}
126 
127     \textcolor{keywordflow}{case} ( interpolation\_p1m\_ih4 )
128       degree = degree\_1
129       \textcolor{keywordflow}{if} ( n0 >= 4 ) \textcolor{keywordflow}{then}
130         \textcolor{keyword}{call }edge\_values\_implicit\_h4( n0, h0, densities, ppoly0\_e, h\_neglect\_edge, answers\_2018=cs
      %answers\_2018 )
131       \textcolor{keywordflow}{else}
132         \textcolor{keyword}{call }edge\_values\_explicit\_h2( n0, h0, densities, ppoly0\_e )
133 \textcolor{keywordflow}{      endif}
134       \textcolor{keyword}{call }p1m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
135       \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
136         \textcolor{keyword}{call }p1m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs )
137 \textcolor{keywordflow}{      endif}
138 
139     \textcolor{keywordflow}{case} ( interpolation\_plm )
140       degree = degree\_1
141       \textcolor{keyword}{call }plm\_reconstruction( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect )
142       \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
143         \textcolor{keyword}{call }plm\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect )
144 \textcolor{keywordflow}{      endif}
145 
146     \textcolor{keywordflow}{case} ( interpolation\_ppm\_h4 )
147       \textcolor{keywordflow}{if} ( n0 >= 4 ) \textcolor{keywordflow}{then}
148         degree = degree\_2
149         \textcolor{keyword}{call }edge\_values\_explicit\_h4( n0, h0, densities, ppoly0\_e, h\_neglect\_edge, answers\_2018=cs
      %answers\_2018 )
150         \textcolor{keyword}{call }ppm\_reconstruction( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
151         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
152           \textcolor{keyword}{call }ppm\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, &
153                                            ppoly0\_coefs, h\_neglect )
154 \textcolor{keywordflow}{        endif}
155       \textcolor{keywordflow}{else}
156         degree = degree\_1
157         \textcolor{keyword}{call }edge\_values\_explicit\_h2( n0, h0, densities, ppoly0\_e )
158         \textcolor{keyword}{call }p1m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
159         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
160           \textcolor{keyword}{call }p1m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs )
161 \textcolor{keywordflow}{        endif}
162 \textcolor{keywordflow}{      endif}
163 
164     \textcolor{keywordflow}{case} ( interpolation\_ppm\_ih4 )
165       \textcolor{keywordflow}{if} ( n0 >= 4 ) \textcolor{keywordflow}{then}
166         degree = degree\_2
167         \textcolor{keyword}{call }edge\_values\_implicit\_h4( n0, h0, densities, ppoly0\_e, h\_neglect\_edge, answers\_2018=cs
      %answers\_2018 )
168         \textcolor{keyword}{call }ppm\_reconstruction( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
169         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
170           \textcolor{keyword}{call }ppm\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, &
171                                            ppoly0\_coefs, h\_neglect )
172 \textcolor{keywordflow}{        endif}
173       \textcolor{keywordflow}{else}
174         degree = degree\_1
175         \textcolor{keyword}{call }edge\_values\_explicit\_h2( n0, h0, densities, ppoly0\_e )
176         \textcolor{keyword}{call }p1m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
177         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
178           \textcolor{keyword}{call }p1m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs )
179 \textcolor{keywordflow}{        endif}
180 \textcolor{keywordflow}{      endif}
181 
182     \textcolor{keywordflow}{case} ( interpolation\_p3m\_ih4ih3 )
183       \textcolor{keywordflow}{if} ( n0 >= 4 ) \textcolor{keywordflow}{then}
184         degree = degree\_3
185         \textcolor{keyword}{call }edge\_values\_implicit\_h4( n0, h0, densities, ppoly0\_e, h\_neglect\_edge, answers\_2018=cs
      %answers\_2018 )
186         \textcolor{keyword}{call }edge\_slopes\_implicit\_h3( n0, h0, densities, ppoly0\_s, h\_neglect, answers\_2018=cs%answers\_2018 
      )
187         \textcolor{keyword}{call }p3m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_s, &
188                                 ppoly0\_coefs, h\_neglect, answers\_2018=cs%answers\_2018 )
189         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
190           \textcolor{keyword}{call }p3m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_s, &
191                                            ppoly0\_coefs, h\_neglect, h\_neglect\_edge )
192 \textcolor{keywordflow}{        endif}
193       \textcolor{keywordflow}{else}
194         degree = degree\_1
195         \textcolor{keyword}{call }edge\_values\_explicit\_h2( n0, h0, densities, ppoly0\_e )
196         \textcolor{keyword}{call }p1m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
197         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
198           \textcolor{keyword}{call }p1m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs )
199 \textcolor{keywordflow}{        endif}
200 \textcolor{keywordflow}{      endif}
201 
202     \textcolor{keywordflow}{case} ( interpolation\_p3m\_ih6ih5 )
203       \textcolor{keywordflow}{if} ( n0 >= 6 ) \textcolor{keywordflow}{then}
204         degree = degree\_3
205         \textcolor{keyword}{call }edge\_values\_implicit\_h6( n0, h0, densities, ppoly0\_e, h\_neglect\_edge, answers\_2018=cs
      %answers\_2018 )
206         \textcolor{keyword}{call }edge\_slopes\_implicit\_h5( n0, h0, densities, ppoly0\_s, h\_neglect, answers\_2018=cs%answers\_2018 
      )
207         \textcolor{keyword}{call }p3m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_s, &
208                                 ppoly0\_coefs, h\_neglect, answers\_2018=cs%answers\_2018 )
209         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
210           \textcolor{keyword}{call }p3m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_s, &
211                    ppoly0\_coefs, h\_neglect, h\_neglect\_edge )
212 \textcolor{keywordflow}{        endif}
213       \textcolor{keywordflow}{else}
214         degree = degree\_1
215         \textcolor{keyword}{call }edge\_values\_explicit\_h2( n0, h0, densities, ppoly0\_e )
216         \textcolor{keyword}{call }p1m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
217         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
218           \textcolor{keyword}{call }p1m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs )
219 \textcolor{keywordflow}{        endif}
220 \textcolor{keywordflow}{      endif}
221 
222     \textcolor{keywordflow}{case} ( interpolation\_pqm\_ih4ih3 )
223       \textcolor{keywordflow}{if} ( n0 >= 4 ) \textcolor{keywordflow}{then}
224         degree = degree\_4
225         \textcolor{keyword}{call }edge\_values\_implicit\_h4( n0, h0, densities, ppoly0\_e, h\_neglect\_edge, answers\_2018=cs
      %answers\_2018 )
226         \textcolor{keyword}{call }edge\_slopes\_implicit\_h3( n0, h0, densities, ppoly0\_s, h\_neglect, answers\_2018=cs%answers\_2018 
      )
227         \textcolor{keyword}{call }pqm\_reconstruction( n0, h0, densities, ppoly0\_e, ppoly0\_s, &
228                                  ppoly0\_coefs, h\_neglect, answers\_2018=cs%answers\_2018 )
229         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
230           \textcolor{keyword}{call }pqm\_boundary\_extrapolation\_v1( n0, h0, densities, ppoly0\_e, ppoly0\_s, &
231                                  ppoly0\_coefs, h\_neglect )
232 \textcolor{keywordflow}{        endif}
233       \textcolor{keywordflow}{else}
234         degree = degree\_1
235         \textcolor{keyword}{call }edge\_values\_explicit\_h2( n0, h0, densities, ppoly0\_e )
236         \textcolor{keyword}{call }p1m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
237         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
238           \textcolor{keyword}{call }p1m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs )
239 \textcolor{keywordflow}{        endif}
240 \textcolor{keywordflow}{      endif}
241 
242     \textcolor{keywordflow}{case} ( interpolation\_pqm\_ih6ih5 )
243       \textcolor{keywordflow}{if} ( n0 >= 6 ) \textcolor{keywordflow}{then}
244         degree = degree\_4
245         \textcolor{keyword}{call }edge\_values\_implicit\_h6( n0, h0, densities, ppoly0\_e, h\_neglect\_edge, answers\_2018=cs
      %answers\_2018 )
246         \textcolor{keyword}{call }edge\_slopes\_implicit\_h5( n0, h0, densities, ppoly0\_s, h\_neglect, answers\_2018=cs%answers\_2018 
      )
247         \textcolor{keyword}{call }pqm\_reconstruction( n0, h0, densities, ppoly0\_e, ppoly0\_s, &
248                                  ppoly0\_coefs, h\_neglect, answers\_2018=cs%answers\_2018 )
249         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
250           \textcolor{keyword}{call }pqm\_boundary\_extrapolation\_v1( n0, h0, densities, ppoly0\_e, ppoly0\_s, &
251                                  ppoly0\_coefs, h\_neglect )
252 \textcolor{keywordflow}{        endif}
253       \textcolor{keywordflow}{else}
254         degree = degree\_1
255         \textcolor{keyword}{call }edge\_values\_explicit\_h2( n0, h0, densities, ppoly0\_e )
256         \textcolor{keyword}{call }p1m\_interpolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
257         \textcolor{keywordflow}{if} (extrapolate) \textcolor{keywordflow}{then}
258           \textcolor{keyword}{call }p1m\_boundary\_extrapolation( n0, h0, densities, ppoly0\_e, ppoly0\_coefs )
259 \textcolor{keywordflow}{        endif}
260 \textcolor{keywordflow}{      endif}
261 \textcolor{keywordflow}{  end select}
262 
\end{DoxyCode}
\mbox{\Hypertarget{namespaceregrid__interp_a9ed8b5720d74090e95ca0074240a0d8a}\label{namespaceregrid__interp_a9ed8b5720d74090e95ca0074240a0d8a}} 
\index{regrid\+\_\+interp@{regrid\+\_\+interp}!set\+\_\+interp\+\_\+extrap@{set\+\_\+interp\+\_\+extrap}}
\index{set\+\_\+interp\+\_\+extrap@{set\+\_\+interp\+\_\+extrap}!regrid\+\_\+interp@{regrid\+\_\+interp}}
\subsubsection{\texorpdfstring{set\+\_\+interp\+\_\+extrap()}{set\_interp\_extrap()}}
{\footnotesize\ttfamily subroutine, public regrid\+\_\+interp\+::set\+\_\+interp\+\_\+extrap (\begin{DoxyParamCaption}\item[{type(\hyperlink{structregrid__interp_1_1interp__cs__type}{interp\+\_\+cs\+\_\+type}), intent(inout)}]{CS,  }\item[{logical, intent(in)}]{extrap }\end{DoxyParamCaption})}



Store the boundary\+\_\+extrapolation value in the interp\+\_\+\+CS. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em cs} & A control structure for \hyperlink{namespaceregrid__interp}{regrid\+\_\+interp}\\
\hline
\mbox{\tt in}  & {\em extrap} & Indicate whether high-\/order boundary extrapolation should be used in boundary cells \\
\hline
\end{DoxyParams}


Definition at line 520 of file regrid\+\_\+interp.\+F90.


\begin{DoxyCode}
520   \textcolor{keywordtype}{type}(interp\_cs\_type), \textcolor{keywordtype}{intent(inout)} :: cs\textcolor{comment}{  !< A control structure for regrid\_interp}
521   \textcolor{keywordtype}{logical},              \textcolor{keywordtype}{intent(in)}    :: extrap\textcolor{comment}{ !< Indicate whether high-order boundary}
522 \textcolor{comment}{                                             !! extrapolation should be used in boundary cells}
523 
524   cs%boundary\_extrapolation = extrap
\end{DoxyCode}
\mbox{\Hypertarget{namespaceregrid__interp_ae77f3027ed51829db5d4ed6dbc744550}\label{namespaceregrid__interp_ae77f3027ed51829db5d4ed6dbc744550}} 
\index{regrid\+\_\+interp@{regrid\+\_\+interp}!set\+\_\+interp\+\_\+scheme@{set\+\_\+interp\+\_\+scheme}}
\index{set\+\_\+interp\+\_\+scheme@{set\+\_\+interp\+\_\+scheme}!regrid\+\_\+interp@{regrid\+\_\+interp}}
\subsubsection{\texorpdfstring{set\+\_\+interp\+\_\+scheme()}{set\_interp\_scheme()}}
{\footnotesize\ttfamily subroutine, public regrid\+\_\+interp\+::set\+\_\+interp\+\_\+scheme (\begin{DoxyParamCaption}\item[{type(\hyperlink{structregrid__interp_1_1interp__cs__type}{interp\+\_\+cs\+\_\+type}), intent(inout)}]{CS,  }\item[{character(len=$\ast$), intent(in)}]{interp\+\_\+scheme }\end{DoxyParamCaption})}



Store the interpolation\+\_\+scheme value in the interp\+\_\+\+CS based on the input string. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em cs} & A control structure for \hyperlink{namespaceregrid__interp}{regrid\+\_\+interp}\\
\hline
\mbox{\tt in}  & {\em interp\+\_\+scheme} & Name of the interpolation scheme Valid values include \char`\"{}\+P1\+M\+\_\+\+H2\char`\"{}, \char`\"{}\+P1\+M\+\_\+\+H4\char`\"{}, \char`\"{}\+P1\+M\+\_\+\+I\+H2\char`\"{}, \char`\"{}\+P\+L\+M\char`\"{}, \char`\"{}\+P\+P\+M\+\_\+\+H4\char`\"{}, \char`\"{}\+P\+P\+M\+\_\+\+I\+H4\char`\"{}, \char`\"{}\+P3\+M\+\_\+\+I\+H4\+I\+H3\char`\"{}, \char`\"{}\+P3\+M\+\_\+\+I\+H6\+I\+H5\char`\"{}, \char`\"{}\+P\+Q\+M\+\_\+\+I\+H4\+I\+H3\char`\"{}, and \char`\"{}\+P\+Q\+M\+\_\+\+I\+H6\+I\+H5\char`\"{} \\
\hline
\end{DoxyParams}


Definition at line 510 of file regrid\+\_\+interp.\+F90.


\begin{DoxyCode}
510   \textcolor{keywordtype}{type}(interp\_cs\_type), \textcolor{keywordtype}{intent(inout)} :: cs\textcolor{comment}{  !< A control structure for regrid\_interp}
511   \textcolor{keywordtype}{character(len=*)},     \textcolor{keywordtype}{intent(in)} :: interp\_scheme\textcolor{comment}{ !< Name of the interpolation scheme}
512 \textcolor{comment}{        !! Valid values include "P1M\_H2", "P1M\_H4", "P1M\_IH2", "PLM", "PPM\_H4",}
513 \textcolor{comment}{        !!   "PPM\_IH4", "P3M\_IH4IH3", "P3M\_IH6IH5", "PQM\_IH4IH3", and "PQM\_IH6IH5"}
514 
515   cs%interpolation\_scheme = interpolation\_scheme(interp\_scheme)
\end{DoxyCode}
