\hypertarget{namespacemom__remapping}{}\section{mom\+\_\+remapping Module Reference}
\label{namespacemom__remapping}\index{mom\+\_\+remapping@{mom\+\_\+remapping}}


\subsection{Detailed Description}
Provides column-\/wise vertical remapping functions. \subsection*{Data Types}
\begin{DoxyCompactItemize}
\item 
type \mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}
\begin{DoxyCompactList}\small\item\em Container for remapping parameters. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Functions/\+Subroutines}
\begin{DoxyCompactItemize}
\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a50e96a4a1083bb1fae3ca0130b6a2c11}{remapping\+\_\+set\+\_\+param}} (CS, remapping\+\_\+scheme, boundary\+\_\+extrapolation, check\+\_\+reconstruction, check\+\_\+remapping, force\+\_\+bounds\+\_\+in\+\_\+subcell, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Set parameters within remapping object. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a5777b80186106733e7a182694d708fba}{extract\+\_\+member\+\_\+remapping\+\_\+cs}} (CS, remapping\+\_\+scheme, degree, boundary\+\_\+extrapolation, check\+\_\+reconstruction, check\+\_\+remapping, force\+\_\+bounds\+\_\+in\+\_\+subcell)
\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a80ed96a40bd7320cfe4213e1550365f0}{buildgridfromh}} (nz, h, x)
\begin{DoxyCompactList}\small\item\em Calculate edge coordinate x from cell width h. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__remapping_accd6922c5eb61fa77c11869d8b219f7c}{ispossumerrsignificant}} (n1, sum1, n2, sum2)
\begin{DoxyCompactList}\small\item\em Compare two summation estimates of positive data and judge if due to more than round-\/off. When two sums are calculated from different vectors that should add up to the same value, the results can differ by round off. The round off error can be bounded to be proportional to the number of operations. This function returns true if the difference between sum1 and sum2 is larger than than the estimated round off bound. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_abe4a1d5b1b9f26063a5e4aba5be0b0a5}{remapping\+\_\+core\+\_\+h}} (CS, n0, h0, u0, n1, h1, u1, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Remaps column of values u0 on grid h0 to grid h1 assuming the top edge is aligned. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a38bd02a8643f4a984bc3985f34106d9a}{remapping\+\_\+core\+\_\+w}} (CS, n0, h0, u0, n1, dx, u1, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Remaps column of values u0 on grid h0 to implied grid h1 where the interfaces of h1 differ from those of h0 by dx. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a5bb0006054c9fa4522783aa3f1f500d5}{build\+\_\+reconstructions\+\_\+1d}} (CS, n0, h0, u0, ppoly\+\_\+r\+\_\+coefs, ppoly\+\_\+r\+\_\+E, ppoly\+\_\+r\+\_\+S, i\+Method, h\+\_\+neglect, h\+\_\+neglect\+\_\+edge)
\begin{DoxyCompactList}\small\item\em Creates polynomial reconstructions of u0 on the source grid h0. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a1756ab9c7329e586ded97e7270b14d4d}{check\+\_\+reconstructions\+\_\+1d}} (n0, h0, u0, deg, boundary\+\_\+extrapolation, ppoly\+\_\+r\+\_\+coefs, ppoly\+\_\+r\+\_\+E, ppoly\+\_\+r\+\_\+S)
\begin{DoxyCompactList}\small\item\em Checks that edge values and reconstructions satisfy bounds. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_ab933069898cb9de16ec60f175185762e}{remap\+\_\+via\+\_\+sub\+\_\+cells}} (n0, h0, u0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, n1, h1, method, force\+\_\+bounds\+\_\+in\+\_\+subcell, u1, uh\+\_\+err, ah\+\_\+sub, aisub\+\_\+src, aiss, aise)
\begin{DoxyCompactList}\small\item\em Remaps column of n0 values u0 on grid h0 to grid h1 with n1 cells by calculating the n0+n1+1 sub-\/integrals of the intersection of h0 and h1, and the summing the appropriate integrals into the h1$\ast$u1 values. h0 and h1 must have the same units. \end{DoxyCompactList}\item 
real function, public \mbox{\hyperlink{namespacemom__remapping_a89dde73fbc6eec035c8dabc225a9c210}{average\+\_\+value\+\_\+ppoly}} (n0, u0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, method, i0, xa, xb)
\begin{DoxyCompactList}\small\item\em Returns the average value of a reconstruction within a single source cell, i0, between the non-\/dimensional positions xa and xb (xa$<$=xb) with dimensional separation dh. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a0b392b7cbac49fc8ab52b2830e3a9306}{measure\+\_\+input\+\_\+bounds}} (n0, h0, u0, edge\+\_\+values, h0tot, h0err, u0tot, u0err, u0min, u0max)
\begin{DoxyCompactList}\small\item\em Measure totals and bounds on source grid. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a5453aeefe69feaff159b67f3a4bd2366}{measure\+\_\+output\+\_\+bounds}} (n1, h1, u1, h1tot, h1err, u1tot, u1err, u1min, u1max)
\begin{DoxyCompactList}\small\item\em Measure totals and bounds on destination grid. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_add104225e8ea85f4e6a324da6be3dba2}{remapbyprojection}} (n0, h0, u0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, n1, h1, method, u1, h\+\_\+neglect)
\begin{DoxyCompactList}\small\item\em Remaps column of values u0 on grid h0 to grid h1 by integrating over the projection of each h1 cell onto the h0 grid. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_ad41da2080e01eaed0b189079801b3c9b}{remapbydeltaz}} (n0, h0, u0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, n1, dx1, method, u1, h1, h\+\_\+neglect)
\begin{DoxyCompactList}\small\item\em Remaps column of values u0 on grid h0 to implied grid h1 where the interfaces of h1 differ from those of h0 by dx. The new grid is defined relative to the original grid by change dx1(\+:) = x\+New(\+:) -\/ x\+Old(\+:) and the remapping calculated so that h\+New(k) q\+New(k) = h\+Old(k) q\+Old(k) + F(k+1) -\/ F(k) where F(k) = dx1(k) q\+Average and where q\+Average is the average q\+Old in the region z\+Old(k) to z\+New(k). \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a98e87df5ab2fcf8483894f95c4fde672}{integraterecononinterval}} (n0, h0, u0, ppoly0\+\_\+E, ppoly0\+\_\+coefs, method, xL, xR, hC, u\+Ave, j\+Start, x\+Start, h\+\_\+neglect)
\begin{DoxyCompactList}\small\item\em Integrate the reconstructed column profile over a single cell. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a494289c324db2496816f2687f4ceea76}{dzfromh1h2}} (n1, h1, n2, h2, dx)
\begin{DoxyCompactList}\small\item\em Calculates the change in interface positions based on h1 and h2. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a81211827af45207130d25cae520b55e5}{initialize\+\_\+remapping}} (CS, remapping\+\_\+scheme, boundary\+\_\+extrapolation, check\+\_\+reconstruction, check\+\_\+remapping, force\+\_\+bounds\+\_\+in\+\_\+subcell, answers\+\_\+2018)
\begin{DoxyCompactList}\small\item\em Constructor for remapping control structure. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_a41a89ac62578250500b7a450d5fdfae7}{setreconstructiontype}} (string, CS)
\begin{DoxyCompactList}\small\item\em Changes the method of reconstruction Use this routine to parse a string parameter specifying the reconstruction and re-\/allocates work arrays appropriately. It is called from initialize\+\_\+remapping but can be called from an external module too. \end{DoxyCompactList}\item 
subroutine, public \mbox{\hyperlink{namespacemom__remapping_a10ca09dcc83f53137647ba51ba5deb72}{end\+\_\+remapping}} (CS)
\begin{DoxyCompactList}\small\item\em Destrcutor for remapping control structure. \end{DoxyCompactList}\item 
logical function, public \mbox{\hyperlink{namespacemom__remapping_a5849f564453d5ed76fb4feffd41eca26}{remapping\+\_\+unit\+\_\+tests}} (verbose)
\begin{DoxyCompactList}\small\item\em Runs unit tests on remapping functions. Should only be called from a single/root thread Returns True if a test fails, otherwise False. \end{DoxyCompactList}\item 
logical function \mbox{\hyperlink{namespacemom__remapping_a3235506c107c81b116cec92952dd8cbb}{test\+\_\+answer}} (verbose, n, u, u\+\_\+true, label, tol)
\begin{DoxyCompactList}\small\item\em Returns true if any cell of u and u\+\_\+true are not identical. Returns false otherwise. \end{DoxyCompactList}\item 
subroutine \mbox{\hyperlink{namespacemom__remapping_ad1246e94fd3b411c2ea8ba675a52874b}{dumpgrid}} (n, h, x, u)
\begin{DoxyCompactList}\small\item\em Convenience function for printing grid to screen. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Variables}
\begin{DoxyCompactItemize}
\item 
\mbox{\Hypertarget{namespacemom__remapping_a3dad5d18f7b13f14230f9c50f976c14d}\label{namespacemom__remapping_a3dad5d18f7b13f14230f9c50f976c14d}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a3dad5d18f7b13f14230f9c50f976c14d}{remapping\+\_\+pcm}} = 0
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$1) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_ac174af1d37725840215d9e65525b4a58}\label{namespacemom__remapping_ac174af1d37725840215d9e65525b4a58}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_ac174af1d37725840215d9e65525b4a58}{remapping\+\_\+plm}} = 1
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$2) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a40ab417b859bc139c78739f29291641f}\label{namespacemom__remapping_a40ab417b859bc139c78739f29291641f}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a40ab417b859bc139c78739f29291641f}{remapping\+\_\+ppm\+\_\+h4}} = 2
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$3) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a186e67e08bd3485a2850d20ecbf3be85}\label{namespacemom__remapping_a186e67e08bd3485a2850d20ecbf3be85}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a186e67e08bd3485a2850d20ecbf3be85}{remapping\+\_\+ppm\+\_\+ih4}} = 3
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$3) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a782d61555a87cd8a68a37ed8a9bb4a95}\label{namespacemom__remapping_a782d61555a87cd8a68a37ed8a9bb4a95}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a782d61555a87cd8a68a37ed8a9bb4a95}{remapping\+\_\+pqm\+\_\+ih4ih3}} = 4
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$4) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a0890124a6b6d71f31c6d382f52172337}\label{namespacemom__remapping_a0890124a6b6d71f31c6d382f52172337}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a0890124a6b6d71f31c6d382f52172337}{remapping\+\_\+pqm\+\_\+ih6ih5}} = 5
\begin{DoxyCompactList}\small\item\em O(h$^\wedge$5) remapping scheme. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_ac1cc04f1f416e9132c98a416e3cf286d}\label{namespacemom__remapping_ac1cc04f1f416e9132c98a416e3cf286d}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_ac1cc04f1f416e9132c98a416e3cf286d}{integration\+\_\+pcm}} = 0
\begin{DoxyCompactList}\small\item\em Piecewise Constant Method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a37c86f210a0a7732da5906716f080141}\label{namespacemom__remapping_a37c86f210a0a7732da5906716f080141}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a37c86f210a0a7732da5906716f080141}{integration\+\_\+plm}} = 1
\begin{DoxyCompactList}\small\item\em Piecewise Linear Method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a1ad21cf7ed0b74aeb469799d9d748c85}\label{namespacemom__remapping_a1ad21cf7ed0b74aeb469799d9d748c85}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a1ad21cf7ed0b74aeb469799d9d748c85}{integration\+\_\+ppm}} = 3
\begin{DoxyCompactList}\small\item\em Piecewise Parabolic Method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a356299a6f7a626edd65e449246a4b60d}\label{namespacemom__remapping_a356299a6f7a626edd65e449246a4b60d}} 
integer, parameter \mbox{\hyperlink{namespacemom__remapping_a356299a6f7a626edd65e449246a4b60d}{integration\+\_\+pqm}} = 5
\begin{DoxyCompactList}\small\item\em Piecewise Quartic Method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a348a14b44b2dff0964e53ec4091b796b}\label{namespacemom__remapping_a348a14b44b2dff0964e53ec4091b796b}} 
character(len=40) \mbox{\hyperlink{namespacemom__remapping_a348a14b44b2dff0964e53ec4091b796b}{mdl}} = \char`\"{}M\+O\+M\+\_\+remapping\char`\"{}
\begin{DoxyCompactList}\small\item\em This module\textquotesingle{}s name. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a8c5a45fb3f4f16cc89405a51fd7361cc}\label{namespacemom__remapping_a8c5a45fb3f4f16cc89405a51fd7361cc}} 
character(len=256), public \mbox{\hyperlink{namespacemom__remapping_a8c5a45fb3f4f16cc89405a51fd7361cc}{remappingschemesdoc}} = \char`\"{}P\+CM (1st-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{}\+P\+L\+M (2nd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{}\+P\+P\+M\+\_\+\+H4 (3rd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{}\+P\+P\+M\+\_\+\+I\+H4 (3rd-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{}\+P\+Q\+M\+\_\+\+I\+H4\+I\+H3 (4th-\/order accurate)\textbackslash{}n\char`\"{}// \char`\"{}\+P\+Q\+M\+\_\+\+I\+H6\+I\+H5 (5th-\/order accurate)\textbackslash{}n\char`\"{}
\begin{DoxyCompactList}\small\item\em Documentation for external callers. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a5978c723e71e49b2f54768fea10000cb}\label{namespacemom__remapping_a5978c723e71e49b2f54768fea10000cb}} 
character(len=3), public \mbox{\hyperlink{namespacemom__remapping_a5978c723e71e49b2f54768fea10000cb}{remappingdefaultscheme}} = \char`\"{}P\+LM\char`\"{}
\begin{DoxyCompactList}\small\item\em Default remapping method. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a3f6a36677ae2737e9cd9d5875110ffc1}\label{namespacemom__remapping_a3f6a36677ae2737e9cd9d5875110ffc1}} 
real, parameter \mbox{\hyperlink{namespacemom__remapping_a3f6a36677ae2737e9cd9d5875110ffc1}{hneglect\+\_\+dflt}} = 1.E-\/30
\begin{DoxyCompactList}\small\item\em A thickness \mbox{[}H $\sim$$>$ m or kg m-\/2\mbox{]} that can be added to thicknesses in a denominator without changing the numerical result, except where a division by zero would otherwise occur. \end{DoxyCompactList}\item 
\mbox{\Hypertarget{namespacemom__remapping_a8b7945e5d6bd0a3387df90476eca0014}\label{namespacemom__remapping_a8b7945e5d6bd0a3387df90476eca0014}} 
logical, parameter \mbox{\hyperlink{namespacemom__remapping_a8b7945e5d6bd0a3387df90476eca0014}{old\+\_\+algorithm}} = .false.
\begin{DoxyCompactList}\small\item\em Use the old \char`\"{}broken\char`\"{} algorithm. This is a temporary measure to assist debugging until we delete the old algorithm. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Function/\+Subroutine Documentation}
\mbox{\Hypertarget{namespacemom__remapping_a89dde73fbc6eec035c8dabc225a9c210}\label{namespacemom__remapping_a89dde73fbc6eec035c8dabc225a9c210}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!average\+\_\+value\+\_\+ppoly@{average\+\_\+value\+\_\+ppoly}}
\index{average\+\_\+value\+\_\+ppoly@{average\+\_\+value\+\_\+ppoly}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{average\+\_\+value\+\_\+ppoly()}{average\_value\_ppoly()}}
{\footnotesize\ttfamily real function, public mom\+\_\+remapping\+::average\+\_\+value\+\_\+ppoly (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(\+:), intent(in)}]{u0,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(in)}]{method,  }\item[{integer, intent(in)}]{i0,  }\item[{real, intent(in)}]{xa,  }\item[{real, intent(in)}]{xb }\end{DoxyParamCaption})}



Returns the average value of a reconstruction within a single source cell, i0, between the non-\/dimensional positions xa and xb (xa$<$=xb) with dimensional separation dh. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n0} & Number of cells in source grid\\
\hline
\mbox{\tt in}  & {\em u0} & Cell means\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+e} & Edge value of polynomial\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial\\
\hline
\mbox{\tt in}  & {\em method} & Remapping scheme to use\\
\hline
\mbox{\tt in}  & {\em i0} & Source cell index\\
\hline
\mbox{\tt in}  & {\em xa} & Non-\/dimensional start position within source cell\\
\hline
\mbox{\tt in}  & {\em xb} & Non-\/dimensional end position within source cell \\
\hline
\end{DoxyParams}


Definition at line 930 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
930   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: n0\textcolor{comment}{     !< Number of cells in source grid}
931   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: u0(:)\textcolor{comment}{  !< Cell means}
932   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: ppoly0\_E(:,:)\textcolor{comment}{     !< Edge value of polynomial}
933   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: ppoly0\_coefs(:,:)\textcolor{comment}{ !< Coefficients of polynomial}
934   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: method\textcolor{comment}{ !< Remapping scheme to use}
935   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: i0\textcolor{comment}{     !< Source cell index}
936   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: xa\textcolor{comment}{     !< Non-dimensional start position within source cell}
937   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: xb\textcolor{comment}{     !< Non-dimensional end position within source cell}
938   \textcolor{comment}{! Local variables}
939   \textcolor{keywordtype}{real} :: u\_ave, xa\_2, xb\_2, xa2pxb2, xapxb
940   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: r\_3 = 1.0/3.0 \textcolor{comment}{! Used in evaluation of integrated polynomials}
941 
942   \textcolor{keywordtype}{real} :: mx, a\_L, a\_R, u\_c, Ya, Yb, my, xa2b2ab, Ya2b2ab, a\_c
943 
944   \textcolor{keywordflow}{if} (xb > xa) \textcolor{keywordflow}{then}
945     \textcolor{keywordflow}{select case} ( method )
946       \textcolor{keywordflow}{case} ( integration\_pcm )
947         u\_ave = u0(i0)
948       \textcolor{keywordflow}{case} ( integration\_plm )
949         u\_ave = (                                           &
950             ppoly0\_coefs(i0,1)                       &
951           + ppoly0\_coefs(i0,2) * 0.5 * ( xb + xa ) )
952       \textcolor{keywordflow}{case} ( integration\_ppm )
953         mx = 0.5 * ( xa + xb )
954         a\_l = ppoly0\_e(i0, 1)
955         a\_r = ppoly0\_e(i0, 2)
956         u\_c = u0(i0)
957         a\_c = 0.5 * ( ( u\_c - a\_l ) + ( u\_c - a\_r ) ) \textcolor{comment}{! a\_6 / 6}
958         \textcolor{keywordflow}{if} (mx<0.5) \textcolor{keywordflow}{then}
959           \textcolor{comment}{! This integration of the PPM reconstruction is expressed in distances from the left edge}
960           xa2b2ab = (xa*xa+xb*xb)+xa*xb
961           u\_ave = a\_l + ( ( a\_r - a\_l ) * mx &
962                           + a\_c * ( 3. * ( xb + xa ) - 2.*xa2b2ab ) )
963         \textcolor{keywordflow}{else}
964           \textcolor{comment}{! This integration of the PPM reconstruction is expressed in distances from the right edge}
965           ya = 1. - xa
966           yb = 1. - xb
967           my = 0.5 * ( ya + yb )
968           ya2b2ab = (ya*ya+yb*yb)+ya*yb
969           u\_ave = a\_r  + ( ( a\_l - a\_r ) * my &
970                            + a\_c * ( 3. * ( yb + ya ) - 2.*ya2b2ab ) )
971 \textcolor{keywordflow}{        endif}
972       \textcolor{keywordflow}{case} ( integration\_pqm )
973         xa\_2 = xa*xa
974         xb\_2 = xb*xb
975         xa2pxb2 = xa\_2 + xb\_2
976         xapxb = xa + xb
977         u\_ave = (                                                                               &
978               ppoly0\_coefs(i0,1)                                                         &
979           + ( ppoly0\_coefs(i0,2) * 0.5 * ( xapxb )                                       &
980           + ( ppoly0\_coefs(i0,3) * r\_3 * ( xa2pxb2 + xa*xb )                             &
981           + ( ppoly0\_coefs(i0,4) * 0.25* ( xa2pxb2 * xapxb )                             &
982           +   ppoly0\_coefs(i0,5) * 0.2 * ( ( xb*xb\_2 + xa*xa\_2 ) * xapxb + xa\_2*xb\_2 ) ) ) ) )
983 \textcolor{keywordflow}{      case default}
984         \textcolor{keyword}{call }mom\_error( fatal,\textcolor{stringliteral}{'The selected integration method is invalid'} )
985 \textcolor{keywordflow}{    end select}
986   \textcolor{keywordflow}{else} \textcolor{comment}{! dh == 0.}
987     \textcolor{keywordflow}{select case} ( method )
988       \textcolor{keywordflow}{case} ( integration\_pcm )
989         u\_ave =        ppoly0\_coefs(i0,1)
990       \textcolor{keywordflow}{case} ( integration\_plm )
991        \textcolor{comment}{!u\_ave =        ppoly0\_coefs(i0,1)   &}
992        \textcolor{comment}{!      + xa *   ppoly0\_coefs(i0,2)}
993         a\_l = ppoly0\_e(i0, 1)
994         a\_r = ppoly0\_e(i0, 2)
995         ya = 1. - xa
996         \textcolor{keywordflow}{if} (xa < 0.5) \textcolor{keywordflow}{then}
997           u\_ave = a\_l + xa * ( a\_r - a\_l )
998         \textcolor{keywordflow}{else}
999           u\_ave = a\_r + ya * ( a\_l - a\_r )
1000 \textcolor{keywordflow}{        endif}
1001       \textcolor{keywordflow}{case} ( integration\_ppm )
1002        \textcolor{comment}{!u\_ave =        ppoly0\_coefs(i0,1)   &}
1003        \textcolor{comment}{!      + xa * ( ppoly0\_coefs(i0,2)   &}
1004        \textcolor{comment}{!      + xa *   ppoly0\_coefs(i0,3) )}
1005         a\_l = ppoly0\_e(i0, 1)
1006         a\_r = ppoly0\_e(i0, 2)
1007         u\_c = u0(i0)
1008         a\_c = 3. * ( ( u\_c - a\_l ) + ( u\_c - a\_r ) ) \textcolor{comment}{! a\_6}
1009         ya = 1. - xa
1010         \textcolor{keywordflow}{if} (xa < 0.5) \textcolor{keywordflow}{then}
1011           u\_ave = a\_l + xa * ( ( a\_r - a\_l ) + a\_c * ya )
1012         \textcolor{keywordflow}{else}
1013           u\_ave = a\_r + ya * ( ( a\_l - a\_r ) + a\_c * xa )
1014 \textcolor{keywordflow}{        endif}
1015       \textcolor{keywordflow}{case} ( integration\_pqm )
1016         u\_ave =        ppoly0\_coefs(i0,1)   &
1017               + xa * ( ppoly0\_coefs(i0,2)   &
1018               + xa * ( ppoly0\_coefs(i0,3)   &
1019               + xa * ( ppoly0\_coefs(i0,4)   &
1020               + xa *   ppoly0\_coefs(i0,5) ) ) )
1021 \textcolor{keywordflow}{      case default}
1022         \textcolor{keyword}{call }mom\_error( fatal,\textcolor{stringliteral}{'The selected integration method is invalid'} )
1023 \textcolor{keywordflow}{    end select}
1024 \textcolor{keywordflow}{  endif}
1025   average\_value\_ppoly = u\_ave
1026 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a5bb0006054c9fa4522783aa3f1f500d5}\label{namespacemom__remapping_a5bb0006054c9fa4522783aa3f1f500d5}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!build\+\_\+reconstructions\+\_\+1d@{build\+\_\+reconstructions\+\_\+1d}}
\index{build\+\_\+reconstructions\+\_\+1d@{build\+\_\+reconstructions\+\_\+1d}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{build\+\_\+reconstructions\+\_\+1d()}{build\_reconstructions\_1d()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::build\+\_\+reconstructions\+\_\+1d (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{real, dimension(n0,cs\%degree+1), intent(out)}]{ppoly\+\_\+r\+\_\+coefs,  }\item[{real, dimension(n0,2), intent(out)}]{ppoly\+\_\+r\+\_\+E,  }\item[{real, dimension(n0,2), intent(out)}]{ppoly\+\_\+r\+\_\+S,  }\item[{integer, intent(out)}]{i\+Method,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})}



Creates polynomial reconstructions of u0 on the source grid h0. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em cs} & Remapping control structure\\
\hline
\mbox{\tt in}  & {\em n0} & Number of cells on source grid\\
\hline
\mbox{\tt in}  & {\em h0} & Cell widths on source grid\\
\hline
\mbox{\tt in}  & {\em u0} & Cell averages on source grid\\
\hline
\mbox{\tt out}  & {\em ppoly\+\_\+r\+\_\+coefs} & Coefficients of polynomial\\
\hline
\mbox{\tt out}  & {\em ppoly\+\_\+r\+\_\+e} & Edge value of polynomial\\
\hline
\mbox{\tt out}  & {\em ppoly\+\_\+r\+\_\+s} & Edge slope of polynomial\\
\hline
\mbox{\tt out}  & {\em imethod} & Integration method\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions 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 in the same units as h0. \\
\hline
\end{DoxyParams}


Definition at line 358 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
358   \textcolor{keywordtype}{type}(remapping\_CS),    \textcolor{keywordtype}{intent(in)}  :: CS\textcolor{comment}{ !< Remapping control structure}
359   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{ !< Number of cells on source grid}
360   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{ !< Cell widths on source grid}
361   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{ !< Cell averages on source grid}
362   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,CS%degree+1)}, &
363                          \textcolor{keywordtype}{intent(out)} :: ppoly\_r\_coefs\textcolor{comment}{ !< Coefficients of polynomial}
364   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)}, \textcolor{keywordtype}{intent(out)} :: ppoly\_r\_E\textcolor{comment}{ !< Edge value of polynomial}
365   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)}, \textcolor{keywordtype}{intent(out)} :: ppoly\_r\_S\textcolor{comment}{ !< Edge slope of polynomial}
366   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(out)} :: iMethod\textcolor{comment}{ !< Integration method}
367   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},        \textcolor{keywordtype}{intent(in)}  :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}
368 \textcolor{comment}{                                         !! purpose of cell reconstructions}
369 \textcolor{comment}{                                         !! in the same units as h0.}
370   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},        \textcolor{keywordtype}{intent(in)}  :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width}
371 \textcolor{comment}{                                         !! for the purpose of edge value}
372 \textcolor{comment}{                                         !! calculations in the same units as h0.}
373   \textcolor{comment}{! Local variables}
374   \textcolor{keywordtype}{integer} :: local\_remapping\_scheme
375   \textcolor{keywordtype}{integer} :: remapping\_scheme\textcolor{comment}{ !< Remapping scheme}
376   \textcolor{keywordtype}{logical} :: boundary\_extrapolation\textcolor{comment}{ !< Extrapolate at boundaries if true}
377 
378   \textcolor{comment}{! Reset polynomial}
379   ppoly\_r\_e(:,:) = 0.0
380   ppoly\_r\_s(:,:) = 0.0
381   ppoly\_r\_coefs(:,:) = 0.0
382   imethod = -999
383 
384   local\_remapping\_scheme = cs%remapping\_scheme
385   \textcolor{keywordflow}{if} (n0<=1) \textcolor{keywordflow}{then}
386     local\_remapping\_scheme = remapping\_pcm
387   \textcolor{keywordflow}{elseif} (n0<=3) \textcolor{keywordflow}{then}
388     local\_remapping\_scheme = min( local\_remapping\_scheme, remapping\_plm )
389   \textcolor{keywordflow}{elseif} (n0<=4) \textcolor{keywordflow}{then}
390     local\_remapping\_scheme = min( local\_remapping\_scheme, remapping\_ppm\_h4 )
391 \textcolor{keywordflow}{  endif}
392   \textcolor{keywordflow}{select case} ( local\_remapping\_scheme )
393     \textcolor{keywordflow}{case} ( remapping\_pcm )
394       \textcolor{keyword}{call }pcm\_reconstruction( n0, u0, ppoly\_r\_e, ppoly\_r\_coefs)
395       imethod = integration\_pcm
396     \textcolor{keywordflow}{case} ( remapping\_plm )
397       \textcolor{keyword}{call }plm\_reconstruction( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect )
398       \textcolor{keywordflow}{if} ( cs%boundary\_extrapolation ) \textcolor{keywordflow}{then}
399         \textcolor{keyword}{call }plm\_boundary\_extrapolation( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect)
400 \textcolor{keywordflow}{      endif}
401       imethod = integration\_plm
402     \textcolor{keywordflow}{case} ( remapping\_ppm\_h4 )
403       \textcolor{keyword}{call }edge\_values\_explicit\_h4( n0, h0, u0, ppoly\_r\_e, h\_neglect\_edge, answers\_2018=cs%answers\_2018 )
404       \textcolor{keyword}{call }ppm\_reconstruction( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
405       \textcolor{keywordflow}{if} ( cs%boundary\_extrapolation ) \textcolor{keywordflow}{then}
406         \textcolor{keyword}{call }ppm\_boundary\_extrapolation( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect )
407 \textcolor{keywordflow}{      endif}
408       imethod = integration\_ppm
409     \textcolor{keywordflow}{case} ( remapping\_ppm\_ih4 )
410       \textcolor{keyword}{call }edge\_values\_implicit\_h4( n0, h0, u0, ppoly\_r\_e, h\_neglect\_edge, answers\_2018=cs%answers\_2018 )
411       \textcolor{keyword}{call }ppm\_reconstruction( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect, answers\_2018=cs
      %answers\_2018 )
412       \textcolor{keywordflow}{if} ( cs%boundary\_extrapolation ) \textcolor{keywordflow}{then}
413         \textcolor{keyword}{call }ppm\_boundary\_extrapolation( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, h\_neglect )
414 \textcolor{keywordflow}{      endif}
415       imethod = integration\_ppm
416     \textcolor{keywordflow}{case} ( remapping\_pqm\_ih4ih3 )
417       \textcolor{keyword}{call }edge\_values\_implicit\_h4( n0, h0, u0, ppoly\_r\_e, h\_neglect\_edge, answers\_2018=cs%answers\_2018 )
418       \textcolor{keyword}{call }edge\_slopes\_implicit\_h3( n0, h0, u0, ppoly\_r\_s, h\_neglect, answers\_2018=cs%answers\_2018 )
419       \textcolor{keyword}{call }pqm\_reconstruction( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_s, ppoly\_r\_coefs, h\_neglect, &
420                                answers\_2018=cs%answers\_2018 )
421       \textcolor{keywordflow}{if} ( cs%boundary\_extrapolation ) \textcolor{keywordflow}{then}
422         \textcolor{keyword}{call }pqm\_boundary\_extrapolation\_v1( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_s, &
423                                             ppoly\_r\_coefs, h\_neglect )
424 \textcolor{keywordflow}{      endif}
425       imethod = integration\_pqm
426     \textcolor{keywordflow}{case} ( remapping\_pqm\_ih6ih5 )
427       \textcolor{keyword}{call }edge\_values\_implicit\_h6( n0, h0, u0, ppoly\_r\_e, h\_neglect\_edge, answers\_2018=cs%answers\_2018 )
428       \textcolor{keyword}{call }edge\_slopes\_implicit\_h5( n0, h0, u0, ppoly\_r\_s, h\_neglect, answers\_2018=cs%answers\_2018 )
429       \textcolor{keyword}{call }pqm\_reconstruction( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_s, ppoly\_r\_coefs, h\_neglect, &
430                                answers\_2018=cs%answers\_2018 )
431       \textcolor{keywordflow}{if} ( cs%boundary\_extrapolation ) \textcolor{keywordflow}{then}
432         \textcolor{keyword}{call }pqm\_boundary\_extrapolation\_v1( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_s, &
433                                             ppoly\_r\_coefs, h\_neglect )
434 \textcolor{keywordflow}{      endif}
435       imethod = integration\_pqm
436 \textcolor{keywordflow}{    case default}
437       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_remapping, build\_reconstructions\_1d: '}//&
438            \textcolor{stringliteral}{'The selected remapping method is invalid'} )
439 \textcolor{keywordflow}{  end select}
440 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a80ed96a40bd7320cfe4213e1550365f0}\label{namespacemom__remapping_a80ed96a40bd7320cfe4213e1550365f0}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!buildgridfromh@{buildgridfromh}}
\index{buildgridfromh@{buildgridfromh}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{buildgridfromh()}{buildgridfromh()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::buildgridfromh (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{nz,  }\item[{real, dimension(nz), intent(in)}]{h,  }\item[{real, dimension(nz+1), intent(inout)}]{x }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Calculate edge coordinate x from cell width h. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em nz} & Number of cells\\
\hline
\mbox{\tt in}  & {\em h} & Cell widths\\
\hline
\mbox{\tt in,out}  & {\em x} & Edge coordiantes starting at x(1)=0 \\
\hline
\end{DoxyParams}


Definition at line 142 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
142   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}    :: nz\textcolor{comment}{ !< Number of cells}
143   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nz)},   \textcolor{keywordtype}{intent(in)}    :: h\textcolor{comment}{  !< Cell widths}
144   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(nz+1)}, \textcolor{keywordtype}{intent(inout)} :: x\textcolor{comment}{  !< Edge coordiantes starting at x(1)=0}
145   \textcolor{comment}{! Local variables}
146   \textcolor{keywordtype}{integer} :: k
147 
148   x(1) = 0.0
149   \textcolor{keywordflow}{do} k = 1,nz
150     x(k+1) = x(k) + h(k)
151 \textcolor{keywordflow}{  enddo}
152 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a1756ab9c7329e586ded97e7270b14d4d}\label{namespacemom__remapping_a1756ab9c7329e586ded97e7270b14d4d}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!check\+\_\+reconstructions\+\_\+1d@{check\+\_\+reconstructions\+\_\+1d}}
\index{check\+\_\+reconstructions\+\_\+1d@{check\+\_\+reconstructions\+\_\+1d}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{check\+\_\+reconstructions\+\_\+1d()}{check\_reconstructions\_1d()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::check\+\_\+reconstructions\+\_\+1d (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{integer, intent(in)}]{deg,  }\item[{logical, intent(in)}]{boundary\+\_\+extrapolation,  }\item[{real, dimension(n0,deg+1), intent(out)}]{ppoly\+\_\+r\+\_\+coefs,  }\item[{real, dimension(n0,2), intent(out)}]{ppoly\+\_\+r\+\_\+E,  }\item[{real, dimension(n0,2), intent(out)}]{ppoly\+\_\+r\+\_\+S }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Checks that edge values and reconstructions satisfy bounds. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n0} & Number of cells on source grid\\
\hline
\mbox{\tt in}  & {\em h0} & Cell widths on source grid\\
\hline
\mbox{\tt in}  & {\em u0} & Cell averages on source grid\\
\hline
\mbox{\tt in}  & {\em deg} & Degree of polynomial reconstruction\\
\hline
\mbox{\tt in}  & {\em boundary\+\_\+extrapolation} & Extrapolate at boundaries if true\\
\hline
\mbox{\tt out}  & {\em ppoly\+\_\+r\+\_\+coefs} & Coefficients of polynomial\\
\hline
\mbox{\tt out}  & {\em ppoly\+\_\+r\+\_\+e} & Edge value of polynomial\\
\hline
\mbox{\tt out}  & {\em ppoly\+\_\+r\+\_\+s} & Edge slope of polynomial \\
\hline
\end{DoxyParams}


Definition at line 446 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
446   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{ !< Number of cells on source grid}
447   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},      \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{ !< Cell widths on source grid}
448   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},      \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{ !< Cell averages on source grid}
449   \textcolor{keywordtype}{integer},                  \textcolor{keywordtype}{intent(in)}  :: deg\textcolor{comment}{ !< Degree of polynomial reconstruction}
450   \textcolor{keywordtype}{logical},                  \textcolor{keywordtype}{intent(in)}  :: boundary\_extrapolation\textcolor{comment}{ !< Extrapolate at boundaries if true}
451   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,deg+1)},\textcolor{keywordtype}{intent(out)} :: ppoly\_r\_coefs\textcolor{comment}{ !< Coefficients of polynomial}
452   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)},    \textcolor{keywordtype}{intent(out)} :: ppoly\_r\_E\textcolor{comment}{ !< Edge value of polynomial}
453   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)},    \textcolor{keywordtype}{intent(out)} :: ppoly\_r\_S\textcolor{comment}{ !< Edge slope of polynomial}
454   \textcolor{comment}{! Local variables}
455   \textcolor{keywordtype}{integer} :: i0, n
456   \textcolor{keywordtype}{real} :: u\_l, u\_c, u\_r \textcolor{comment}{! Cell averages}
457   \textcolor{keywordtype}{real} :: u\_min, u\_max
458   \textcolor{keywordtype}{logical} :: problem\_detected
459 
460   problem\_detected = .false.
461   \textcolor{keywordflow}{do} i0 = 1, n0
462     u\_l = u0(max(1,i0-1))
463     u\_c = u0(i0)
464     u\_r = u0(min(n0,i0+1))
465     \textcolor{keywordflow}{if} (i0 > 1 .or. .not. boundary\_extrapolation) \textcolor{keywordflow}{then}
466       u\_min = min(u\_l, u\_c)
467       u\_max = max(u\_l, u\_c)
468       \textcolor{keywordflow}{if} (ppoly\_r\_e(i0,1) < u\_min) \textcolor{keywordflow}{then}
469         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,i4,5(x,a,1pe24.16))'}) \textcolor{stringliteral}{'Left edge undershoot at'},i0,\textcolor{stringliteral}{'u(i0-1)='},u\_l,\textcolor{stringliteral}{'u(i0)='},u\_c, &
470                                           \textcolor{stringliteral}{'edge='},ppoly\_r\_e(i0,1),\textcolor{stringliteral}{'err='},ppoly\_r\_e(i0,1)-u\_min
471         problem\_detected = .true.
472 \textcolor{keywordflow}{      endif}
473       \textcolor{keywordflow}{if} (ppoly\_r\_e(i0,1) > u\_max) \textcolor{keywordflow}{then}
474         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,i4,5(x,a,1pe24.16))'}) \textcolor{stringliteral}{'Left edge overshoot at'},i0,\textcolor{stringliteral}{'u(i0-1)='},u\_l,\textcolor{stringliteral}{'u(i0)='},u\_c, &
475                                           \textcolor{stringliteral}{'edge='},ppoly\_r\_e(i0,1),\textcolor{stringliteral}{'err='},ppoly\_r\_e(i0,1)-u\_max
476         problem\_detected = .true.
477 \textcolor{keywordflow}{      endif}
478 \textcolor{keywordflow}{    endif}
479     \textcolor{keywordflow}{if} (i0 < n0 .or. .not. boundary\_extrapolation) \textcolor{keywordflow}{then}
480       u\_min = min(u\_c, u\_r)
481       u\_max = max(u\_c, u\_r)
482       \textcolor{keywordflow}{if} (ppoly\_r\_e(i0,2) < u\_min) \textcolor{keywordflow}{then}
483         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,i4,5(x,a,1pe24.16))'}) \textcolor{stringliteral}{'Right edge undershoot at'},i0,\textcolor{stringliteral}{'u(i0)='},u\_c,\textcolor{stringliteral}{'u(i0+1)='},u\_r, &
484                                           \textcolor{stringliteral}{'edge='},ppoly\_r\_e(i0,2),\textcolor{stringliteral}{'err='},ppoly\_r\_e(i0,2)-u\_min
485         problem\_detected = .true.
486 \textcolor{keywordflow}{      endif}
487       \textcolor{keywordflow}{if} (ppoly\_r\_e(i0,2) > u\_max) \textcolor{keywordflow}{then}
488         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,i4,5(x,a,1pe24.16))'}) \textcolor{stringliteral}{'Right edge overshoot at'},i0,\textcolor{stringliteral}{'u(i0)='},u\_c,\textcolor{stringliteral}{'u(i0+1)='},u\_r, &
489                                           \textcolor{stringliteral}{'edge='},ppoly\_r\_e(i0,2),\textcolor{stringliteral}{'err='},ppoly\_r\_e(i0,2)-u\_max
490         problem\_detected = .true.
491 \textcolor{keywordflow}{      endif}
492 \textcolor{keywordflow}{    endif}
493     \textcolor{keywordflow}{if} (i0 > 1) \textcolor{keywordflow}{then}
494       \textcolor{keywordflow}{if} ( (u\_c-u\_l)*(ppoly\_r\_e(i0,1)-ppoly\_r\_e(i0-1,2)) < 0.) \textcolor{keywordflow}{then}
495         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,i4,5(x,a,1pe24.16))'}) \textcolor{stringliteral}{'Non-monotonic edges at'},i0,\textcolor{stringliteral}{'u(i0-1)='},u\_l,\textcolor{stringliteral}{'u(i0)='},u\_c, &
496                                           \textcolor{stringliteral}{'right edge='},ppoly\_r\_e(i0-1,2),\textcolor{stringliteral}{'left edge='},ppoly\_r\_e(i0,1)
497         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(5(a,1pe24.16,x))'}) \textcolor{stringliteral}{'u(i0)-u(i0-1)'},u\_c-u\_l,\textcolor{stringliteral}{'edge diff='},ppoly\_r\_e(i0,1)-ppoly\_r\_e(i0-1,2)
498         problem\_detected = .true.
499 \textcolor{keywordflow}{      endif}
500 \textcolor{keywordflow}{    endif}
501     \textcolor{keywordflow}{if} (problem\_detected) \textcolor{keywordflow}{then}
502       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a,1p9e24.16)'}) \textcolor{stringliteral}{'Polynomial coeffs:'},ppoly\_r\_coefs(i0,:)
503       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(3(a,1pe24.16,x))'}) \textcolor{stringliteral}{'u\_l='},u\_l,\textcolor{stringliteral}{'u\_c='},u\_c,\textcolor{stringliteral}{'u\_r='},u\_r
504       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a4,10a24)'}) \textcolor{stringliteral}{'i0'},\textcolor{stringliteral}{'h0(i0)'},\textcolor{stringliteral}{'u0(i0)'},\textcolor{stringliteral}{'left edge'},\textcolor{stringliteral}{'right edge'},\textcolor{stringliteral}{'Polynomial coefficients'}
505       \textcolor{keywordflow}{do} n = 1, n0
506         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i4,1p10e24.16)'}) n,h0(n),u0(n),ppoly\_r\_e(n,1),ppoly\_r\_e(n,2),ppoly\_r\_coefs(n,:)
507 \textcolor{keywordflow}{      enddo}
508       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{'MOM\_remapping, check\_reconstructions\_1d: '}// &
509                    \textcolor{stringliteral}{'Edge values or polynomial coefficients were inconsistent!'})
510 \textcolor{keywordflow}{    endif}
511 \textcolor{keywordflow}{  enddo}
512 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_ad1246e94fd3b411c2ea8ba675a52874b}\label{namespacemom__remapping_ad1246e94fd3b411c2ea8ba675a52874b}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!dumpgrid@{dumpgrid}}
\index{dumpgrid@{dumpgrid}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{dumpgrid()}{dumpgrid()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::dumpgrid (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n,  }\item[{real, dimension(\+:), intent(in)}]{h,  }\item[{real, dimension(\+:), intent(in)}]{x,  }\item[{real, dimension(\+:), intent(in)}]{u }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Convenience function for printing grid to screen. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n} & Number of cells\\
\hline
\mbox{\tt in}  & {\em h} & Cell thickness\\
\hline
\mbox{\tt in}  & {\em x} & Interface delta\\
\hline
\mbox{\tt in}  & {\em u} & Cell average values \\
\hline
\end{DoxyParams}


Definition at line 1919 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1919   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: n\textcolor{comment}{ !< Number of cells}
1920   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)} :: h\textcolor{comment}{ !< Cell thickness}
1921   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)} :: x\textcolor{comment}{ !< Interface delta}
1922   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)} :: u\textcolor{comment}{ !< Cell average values}
1923   \textcolor{keywordtype}{integer} :: i
1924   \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'("i=",20i10)'}) (i,i=1,n+1)
1925   \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'("x=",20es10.2)'}) (x(i),i=1,n+1)
1926   \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'("i=",5x,20i10)'}) (i,i=1,n)
1927   \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'("h=",5x,20es10.2)'}) (h(i),i=1,n)
1928   \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'("u=",5x,20es10.2)'}) (u(i),i=1,n)
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a494289c324db2496816f2687f4ceea76}\label{namespacemom__remapping_a494289c324db2496816f2687f4ceea76}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!dzfromh1h2@{dzfromh1h2}}
\index{dzfromh1h2@{dzfromh1h2}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{dzfromh1h2()}{dzfromh1h2()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::dzfromh1h2 (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(\+:), intent(in)}]{h1,  }\item[{integer, intent(in)}]{n2,  }\item[{real, dimension(\+:), intent(in)}]{h2,  }\item[{real, dimension(\+:), intent(out)}]{dx }\end{DoxyParamCaption})}



Calculates the change in interface positions based on h1 and h2. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n1} & Number of cells on source grid\\
\hline
\mbox{\tt in}  & {\em h1} & Cell widths of source grid (size n1)\\
\hline
\mbox{\tt in}  & {\em n2} & Number of cells on target grid\\
\hline
\mbox{\tt in}  & {\em h2} & Cell widths of target grid (size n2)\\
\hline
\mbox{\tt out}  & {\em dx} & Change in interface position (size n2+1) \\
\hline
\end{DoxyParams}


Definition at line 1526 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1526   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}  :: n1\textcolor{comment}{ !< Number of cells on source grid}
1527   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}  :: h1\textcolor{comment}{ !< Cell widths of source grid (size n1)}
1528   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)}  :: n2\textcolor{comment}{ !< Number of cells on target grid}
1529   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(in)}  :: h2\textcolor{comment}{ !< Cell widths of target grid (size n2)}
1530   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, \textcolor{keywordtype}{intent(out)} :: dx\textcolor{comment}{ !< Change in interface position (size n2+1)}
1531   \textcolor{comment}{! Local variables}
1532   \textcolor{keywordtype}{integer} :: k
1533   \textcolor{keywordtype}{real} :: x1, x2
1534 
1535   x1 = 0.
1536   x2 = 0.
1537   dx(1) = 0.
1538   \textcolor{keywordflow}{do} k = 1, max(n1,n2)
1539     \textcolor{keywordflow}{if} (k <= n1) x1 = x1 + h1(k) \textcolor{comment}{! Interface k+1, right of source cell k}
1540     \textcolor{keywordflow}{if} (k <= n2) \textcolor{keywordflow}{then}
1541       x2 = x2 + h2(k) \textcolor{comment}{! Interface k+1, right of target cell k}
1542       dx(k+1) = x2 - x1 \textcolor{comment}{! Change of interface k+1, target - source}
1543 \textcolor{keywordflow}{    endif}
1544 \textcolor{keywordflow}{  enddo}
1545 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a10ca09dcc83f53137647ba51ba5deb72}\label{namespacemom__remapping_a10ca09dcc83f53137647ba51ba5deb72}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!end\+\_\+remapping@{end\+\_\+remapping}}
\index{end\+\_\+remapping@{end\+\_\+remapping}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{end\+\_\+remapping()}{end\_remapping()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::end\+\_\+remapping (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(inout)}]{CS }\end{DoxyParamCaption})}



Destrcutor for remapping control structure. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em cs} & Remapping control structure \\
\hline
\end{DoxyParams}


Definition at line 1607 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1607   \textcolor{keywordtype}{type}(remapping\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Remapping control structure}
1608 
1609   cs%degree = 0
1610 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a5777b80186106733e7a182694d708fba}\label{namespacemom__remapping_a5777b80186106733e7a182694d708fba}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!extract\+\_\+member\+\_\+remapping\+\_\+cs@{extract\+\_\+member\+\_\+remapping\+\_\+cs}}
\index{extract\+\_\+member\+\_\+remapping\+\_\+cs@{extract\+\_\+member\+\_\+remapping\+\_\+cs}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{extract\+\_\+member\+\_\+remapping\+\_\+cs()}{extract\_member\_remapping\_cs()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::extract\+\_\+member\+\_\+remapping\+\_\+cs (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(out), optional}]{remapping\+\_\+scheme,  }\item[{integer, intent(out), optional}]{degree,  }\item[{logical, intent(out), optional}]{boundary\+\_\+extrapolation,  }\item[{logical, intent(out), optional}]{check\+\_\+reconstruction,  }\item[{logical, intent(out), optional}]{check\+\_\+remapping,  }\item[{logical, intent(out), optional}]{force\+\_\+bounds\+\_\+in\+\_\+subcell }\end{DoxyParamCaption})}


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em cs} & Control structure for remapping module\\
\hline
\mbox{\tt out}  & {\em remapping\+\_\+scheme} & Determines which reconstruction scheme to use\\
\hline
\mbox{\tt out}  & {\em degree} & Degree of polynomial reconstruction\\
\hline
\mbox{\tt out}  & {\em boundary\+\_\+extrapolation} & If true, extrapolate boundaries\\
\hline
\mbox{\tt out}  & {\em check\+\_\+reconstruction} & If true, reconstructions are checked for consistency.\\
\hline
\mbox{\tt out}  & {\em check\+\_\+remapping} & If true, the result of remapping are checked for conservation and bounds.\\
\hline
\mbox{\tt out}  & {\em force\+\_\+bounds\+\_\+in\+\_\+subcell} & If true, the intermediate values used in remapping are forced to be bounded. \\
\hline
\end{DoxyParams}


Definition at line 122 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
122   \textcolor{keywordtype}{type}(remapping\_CS), \textcolor{keywordtype}{intent(in)} :: CS\textcolor{comment}{ !< Control structure for remapping module}
123   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: remapping\_scheme\textcolor{comment}{        !< Determines which reconstruction scheme to
       use}
124   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: degree\textcolor{comment}{                  !< Degree of polynomial reconstruction}
125   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: boundary\_extrapolation\textcolor{comment}{  !< If true, extrapolate boundaries}
126   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: check\_reconstruction\textcolor{comment}{    !< If true, reconstructions are checked for
       consistency.}
127   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: check\_remapping\textcolor{comment}{         !< If true, the result of remapping are checked}
128 \textcolor{comment}{                                                            !!  for conservation and bounds.}
129   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: force\_bounds\_in\_subcell\textcolor{comment}{ !< If true, the intermediate values used in}
130 \textcolor{comment}{                                                            !! remapping are forced to be bounded.}
131 
132   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(remapping\_scheme)) remapping\_scheme = cs%remapping\_scheme
133   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(degree)) degree = cs%degree
134   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(boundary\_extrapolation)) boundary\_extrapolation = cs%boundary\_extrapolation
135   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(check\_reconstruction)) check\_reconstruction = cs%check\_reconstruction
136   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(check\_remapping)) check\_remapping = cs%check\_remapping
137   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(force\_bounds\_in\_subcell)) force\_bounds\_in\_subcell = cs%force\_bounds\_in\_subcell
138 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a81211827af45207130d25cae520b55e5}\label{namespacemom__remapping_a81211827af45207130d25cae520b55e5}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!initialize\+\_\+remapping@{initialize\+\_\+remapping}}
\index{initialize\+\_\+remapping@{initialize\+\_\+remapping}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{initialize\+\_\+remapping()}{initialize\_remapping()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::initialize\+\_\+remapping (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(inout)}]{CS,  }\item[{character(len=$\ast$), intent(in)}]{remapping\+\_\+scheme,  }\item[{logical, intent(in), optional}]{boundary\+\_\+extrapolation,  }\item[{logical, intent(in), optional}]{check\+\_\+reconstruction,  }\item[{logical, intent(in), optional}]{check\+\_\+remapping,  }\item[{logical, intent(in), optional}]{force\+\_\+bounds\+\_\+in\+\_\+subcell,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})}



Constructor for remapping control structure. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em cs} & Remapping control structure\\
\hline
\mbox{\tt in}  & {\em remapping\+\_\+scheme} & Remapping scheme to use\\
\hline
\mbox{\tt in}  & {\em boundary\+\_\+extrapolation} & Indicate to extrapolate in boundary cells\\
\hline
\mbox{\tt in}  & {\em check\+\_\+reconstruction} & Indicate to check reconstructions\\
\hline
\mbox{\tt in}  & {\em check\+\_\+remapping} & Indicate to check results of remapping\\
\hline
\mbox{\tt in}  & {\em force\+\_\+bounds\+\_\+in\+\_\+subcell} & Force subcells values to be bounded\\
\hline
\mbox{\tt in}  & {\em answers\+\_\+2018} & If true use older, less acccurate expressions. \\
\hline
\end{DoxyParams}


Definition at line 1551 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1551   \textcolor{comment}{! Arguments}
1552   \textcolor{keywordtype}{type}(remapping\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Remapping control structure}
1553   \textcolor{keywordtype}{character(len=*)},   \textcolor{keywordtype}{intent(in)}    :: remapping\_scheme\textcolor{comment}{ !< Remapping scheme to use}
1554   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: boundary\_extrapolation\textcolor{comment}{ !< Indicate to extrapolate in boundary cells}
1555   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: check\_reconstruction\textcolor{comment}{ !< Indicate to check reconstructions}
1556   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: check\_remapping\textcolor{comment}{ !< Indicate to check results of remapping}
1557   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: force\_bounds\_in\_subcell\textcolor{comment}{ !< Force subcells values to be bounded}
1558   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},  \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true use older, less acccurate expressions.}
1559 
1560   \textcolor{comment}{! Note that remapping\_scheme is mandatory for initialize\_remapping()}
1561   \textcolor{keyword}{call }remapping\_set\_param(cs, remapping\_scheme=remapping\_scheme, boundary\_extrapolation=
      boundary\_extrapolation,  &
1562                check\_reconstruction=check\_reconstruction, check\_remapping=check\_remapping, &
1563                force\_bounds\_in\_subcell=force\_bounds\_in\_subcell, answers\_2018=answers\_2018)
1564 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a98e87df5ab2fcf8483894f95c4fde672}\label{namespacemom__remapping_a98e87df5ab2fcf8483894f95c4fde672}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!integraterecononinterval@{integraterecononinterval}}
\index{integraterecononinterval@{integraterecononinterval}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{integraterecononinterval()}{integraterecononinterval()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::integraterecononinterval (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(\+:), intent(in)}]{h0,  }\item[{real, dimension(\+:), intent(in)}]{u0,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(in)}]{method,  }\item[{real, intent(in)}]{xL,  }\item[{real, intent(in)}]{xR,  }\item[{real, intent(in)}]{hC,  }\item[{real, intent(out)}]{u\+Ave,  }\item[{integer, intent(inout)}]{j\+Start,  }\item[{real, intent(inout)}]{x\+Start,  }\item[{real, intent(in), optional}]{h\+\_\+neglect }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Integrate the reconstructed column profile over a single cell. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n0} & Number of cells in source grid\\
\hline
\mbox{\tt in}  & {\em h0} & Source grid sizes (size n0)\\
\hline
\mbox{\tt in}  & {\em u0} & Source cell averages\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+e} & Edge value of polynomial\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial\\
\hline
\mbox{\tt in}  & {\em method} & Remapping scheme to use\\
\hline
\mbox{\tt in}  & {\em xl} & Left edges of target cell\\
\hline
\mbox{\tt in}  & {\em xr} & Right edges of target cell\\
\hline
\mbox{\tt in}  & {\em hc} & Cell width hC = xR -\/ xL\\
\hline
\mbox{\tt out}  & {\em uave} & Average value on target cell\\
\hline
\mbox{\tt in,out}  & {\em jstart} & The index of the cell to start searching from On exit, contains index of last cell used\\
\hline
\mbox{\tt in,out}  & {\em xstart} & The left edge position of cell j\+Start On first entry should be 0.\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions in the same units as h. \\
\hline
\end{DoxyParams}


Definition at line 1227 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1227   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: n0\textcolor{comment}{     !< Number of cells in source grid}
1228   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: h0\textcolor{comment}{     !< Source grid sizes (size n0)}
1229   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}    :: u0\textcolor{comment}{     !< Source cell averages}
1230   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}    :: ppoly0\_E\textcolor{comment}{ !< Edge value of polynomial}
1231   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}    :: ppoly0\_coefs\textcolor{comment}{ !< Coefficients of polynomial}
1232   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}    :: method\textcolor{comment}{ !< Remapping scheme to use}
1233   \textcolor{keywordtype}{real},                 \textcolor{keywordtype}{intent(in)}    :: xL\textcolor{comment}{     !< Left edges of target cell}
1234   \textcolor{keywordtype}{real},                 \textcolor{keywordtype}{intent(in)}    :: xR\textcolor{comment}{     !< Right edges of target cell}
1235   \textcolor{keywordtype}{real},                 \textcolor{keywordtype}{intent(in)}    :: hC\textcolor{comment}{     !< Cell width hC = xR - xL}
1236   \textcolor{keywordtype}{real},                 \textcolor{keywordtype}{intent(out)}   :: uAve\textcolor{comment}{   !< Average value on target cell}
1237   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(inout)} :: jStart\textcolor{comment}{ !< The index of the cell to start searching from}
1238 \textcolor{comment}{                                   !< On exit, contains index of last cell used}
1239   \textcolor{keywordtype}{real},                 \textcolor{keywordtype}{intent(inout)} :: xStart\textcolor{comment}{ !< The left edge position of cell jStart}
1240 \textcolor{comment}{                                   !< On first entry should be 0.}
1241   \textcolor{keywordtype}{real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}
1242 \textcolor{comment}{                                          !! purpose of cell reconstructions}
1243 \textcolor{comment}{                                          !! in the same units as h.}
1244   \textcolor{comment}{! Local variables}
1245   \textcolor{keywordtype}{integer} :: j, k
1246   \textcolor{keywordtype}{integer} :: jL, jR       \textcolor{comment}{! indexes of source cells containing target}
1247                           \textcolor{comment}{! cell edges}
1248   \textcolor{keywordtype}{real}    :: q            \textcolor{comment}{! complete integration}
1249   \textcolor{keywordtype}{real}    :: xi0, xi1     \textcolor{comment}{! interval of integration (local -- normalized}
1250                           \textcolor{comment}{! -- coordinates)}
1251   \textcolor{keywordtype}{real}    :: x0jLl, x0jLr \textcolor{comment}{! Left/right position of cell jL}
1252   \textcolor{keywordtype}{real}    :: x0jRl, x0jRr \textcolor{comment}{! Left/right position of cell jR}
1253   \textcolor{keywordtype}{real}    :: hAct         \textcolor{comment}{! The distance actually used in the integration}
1254                           \textcolor{comment}{! (notionally xR - xL) which differs due to roundoff.}
1255   \textcolor{keywordtype}{real}    :: x0\_2, x1\_2, x02px12, x0px1 \textcolor{comment}{! Used in evaluation of integrated polynomials}
1256   \textcolor{keywordtype}{real}     :: hNeglect    \textcolor{comment}{! A negligible thicness in the same units as h.}
1257   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{parameter} :: r\_3 = 1.0/3.0 \textcolor{comment}{! Used in evaluation of integrated polynomials}
1258 
1259   hneglect = hneglect\_dflt ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect)) hneglect = h\_neglect
1260 
1261   q = -1.e30
1262   x0jll = -1.e30
1263   x0jrl = -1.e30
1264 
1265   \textcolor{comment}{! Find the left most cell in source grid spanned by the target cell}
1266   jl = -1
1267   x0jlr = xstart
1268   \textcolor{keywordflow}{do} j = jstart, n0
1269     x0jll = x0jlr
1270     x0jlr = x0jll + h0(j)
1271     \textcolor{comment}{! Left edge is found in cell j}
1272     \textcolor{keywordflow}{if} ( ( xl >= x0jll ) .AND. ( xl <= x0jlr ) ) \textcolor{keywordflow}{then}
1273       jl = j
1274       \textcolor{keywordflow}{exit} \textcolor{comment}{! once target grid cell is found, exit loop}
1275 \textcolor{keywordflow}{    endif}
1276 \textcolor{keywordflow}{  enddo}
1277   jstart = jl
1278   xstart = x0jll
1279 
1280 \textcolor{comment}{! ! HACK to handle round-off problems. Need only at  j=n0.}
1281 \textcolor{comment}{! ! This moves the effective cell boundary outwards a smidgen.}
1282 \textcolor{comment}{! if (xL>x0jLr) x0jLr = xL}
1283 
1284   \textcolor{comment}{! If, at this point, jL is equal to -1, it means the vanished}
1285   \textcolor{comment}{! cell lies outside the source grid. In other words, it means that}
1286   \textcolor{comment}{! the source and target grids do not cover the same physical domain}
1287   \textcolor{comment}{! and there is something very wrong !}
1288   \textcolor{keywordflow}{if} ( jl == -1 ) \textcolor{keyword}{call }mom\_error(fatal, &
1289           \textcolor{stringliteral}{'MOM\_remapping, integrateReconOnInterval: '}//&
1290           \textcolor{stringliteral}{'The location of the left-most cell could not be found'})
1291 
1292 
1293   \textcolor{comment}{! ============================================================}
1294   \textcolor{comment}{! Check whether target cell is vanished. If it is, the cell}
1295   \textcolor{comment}{! average is simply the interpolated value at the location}
1296   \textcolor{comment}{! of the vanished cell. If it isn't, we need to integrate the}
1297   \textcolor{comment}{! quantity within the cell and divide by the cell width to}
1298   \textcolor{comment}{! determine the cell average.}
1299   \textcolor{comment}{! ============================================================}
1300   \textcolor{comment}{! 1. Cell is vanished}
1301  \textcolor{comment}{!if ( abs(xR - xL) <= epsilon(xR)*max(abs(xR),abs(xL)) ) then}
1302   \textcolor{keywordflow}{if} ( abs(xr - xl) == 0.0 ) \textcolor{keywordflow}{then}
1303 
1304     \textcolor{comment}{! We check whether the source cell (i.e. the cell in which the}
1305     \textcolor{comment}{! vanished target cell lies) is vanished. If it is, the interpolated}
1306     \textcolor{comment}{! value is set to be mean of the edge values (which should be the same).}
1307     \textcolor{comment}{! If it isn't, we simply interpolate.}
1308     \textcolor{keywordflow}{if} ( h0(jl) == 0.0 ) \textcolor{keywordflow}{then}
1309       uave = 0.5 * ( ppoly0\_e(jl,1) + ppoly0\_e(jl,2) )
1310     \textcolor{keywordflow}{else}
1311       \textcolor{comment}{! WHY IS THIS NOT WRITTEN AS xi0 = ( xL - x0jLl ) / h0(jL) ---AJA}
1312       xi0 = xl / ( h0(jl) + hneglect ) - x0jll / ( h0(jl) + hneglect )
1313 
1314       \textcolor{keywordflow}{select case} ( method )
1315         \textcolor{keywordflow}{case} ( integration\_pcm )
1316           uave =         ppoly0\_coefs(jl,1)
1317         \textcolor{keywordflow}{case} ( integration\_plm )
1318           uave =         ppoly0\_coefs(jl,1)   &
1319                + xi0 *   ppoly0\_coefs(jl,2)
1320         \textcolor{keywordflow}{case} ( integration\_ppm )
1321           uave =         ppoly0\_coefs(jl,1)   &
1322                + xi0 * ( ppoly0\_coefs(jl,2)   &
1323                + xi0 *   ppoly0\_coefs(jl,3) )
1324         \textcolor{keywordflow}{case} ( integration\_pqm )
1325           uave =         ppoly0\_coefs(jl,1)   &
1326                + xi0 * ( ppoly0\_coefs(jl,2)   &
1327                + xi0 * ( ppoly0\_coefs(jl,3)   &
1328                + xi0 * ( ppoly0\_coefs(jl,4)   &
1329                + xi0 *   ppoly0\_coefs(jl,5) ) ) )
1330 \textcolor{keywordflow}{        case default}
1331           \textcolor{keyword}{call }mom\_error( fatal,\textcolor{stringliteral}{'The selected integration method is invalid'} )
1332 \textcolor{keywordflow}{      end select}
1333 
1334 \textcolor{keywordflow}{    endif} \textcolor{comment}{! end checking whether source cell is vanished}
1335 
1336   \textcolor{comment}{! 2. Cell is not vanished}
1337   \textcolor{keywordflow}{else}
1338 
1339     \textcolor{comment}{! Find the right most cell in source grid spanned by the target cell}
1340     jr = -1
1341     x0jrr = xstart
1342     \textcolor{keywordflow}{do} j = jstart,n0
1343       x0jrl = x0jrr
1344       x0jrr = x0jrl + h0(j)
1345       \textcolor{comment}{! Right edge is found in cell j}
1346       \textcolor{keywordflow}{if} ( ( xr >= x0jrl ) .AND. ( xr <= x0jrr ) ) \textcolor{keywordflow}{then}
1347         jr = j
1348         \textcolor{keywordflow}{exit}  \textcolor{comment}{! once target grid cell is found, exit loop}
1349 \textcolor{keywordflow}{      endif}
1350 \textcolor{keywordflow}{    enddo} \textcolor{comment}{! end loop on source grid cells}
1351 
1352     \textcolor{comment}{! If xR>x0jRr then the previous loop reached j=n0 and the target}
1353     \textcolor{comment}{! position, xR, was beyond the right edge of the source grid (h0).}
1354     \textcolor{comment}{! This can happen due to roundoff, in which case we set jR=n0.}
1355     \textcolor{keywordflow}{if} (xr>x0jrr) jr = n0
1356 
1357     \textcolor{comment}{! To integrate, two cases must be considered: (1) the target cell is}
1358     \textcolor{comment}{! entirely contained within a cell of the source grid and (2) the target}
1359     \textcolor{comment}{! cell spans at least two cells of the source grid.}
1360 
1361     \textcolor{keywordflow}{if} ( jl == jr ) \textcolor{keywordflow}{then}
1362       \textcolor{comment}{! The target cell is entirely contained within a cell of the source}
1363       \textcolor{comment}{! grid. This situation is represented by the following schematic, where}
1364       \textcolor{comment}{! the cell in which xL and xR are located has index jL=jR :}
1365       \textcolor{comment}{!}
1366       \textcolor{comment}{! ----|-----o--------o----------|-------------}
1367       \textcolor{comment}{!           xL       xR}
1368       \textcolor{comment}{!}
1369       \textcolor{comment}{! Determine normalized coordinates}
1370 \textcolor{preprocessor}{#ifdef \_\_USE\_ROUNDOFF\_SAFE\_ADJUSTMENTS\_\_}
1371 \textcolor{preprocessor}{}      xi0 = max( 0., min( 1., ( xl - x0jll ) / ( h0(jl) + hneglect ) ) )
1372       xi1 = max( 0., min( 1., ( xr - x0jll ) / ( h0(jl) + hneglect ) ) )
1373 \textcolor{preprocessor}{#else}
1374 \textcolor{preprocessor}{}      xi0 = xl / h0(jl) - x0jll / ( h0(jl) + hneglect )
1375       xi1 = xr / h0(jl) - x0jll / ( h0(jl) + hneglect )
1376 \textcolor{preprocessor}{#endif}
1377 \textcolor{preprocessor}{}
1378       hact = h0(jl) * ( xi1 - xi0 )
1379 
1380       \textcolor{comment}{! Depending on which polynomial is used, integrate quantity}
1381       \textcolor{comment}{! between xi0 and xi1. Integration is carried out in normalized}
1382       \textcolor{comment}{! coordinates, hence: \(\backslash\)int\_xL^xR p(x) dx = h \(\backslash\)int\_xi0^xi1 p(xi) dxi}
1383       \textcolor{keywordflow}{select case} ( method )
1384         \textcolor{keywordflow}{case} ( integration\_pcm )
1385           q = ( xr - xl ) * ppoly0\_coefs(jl,1)
1386         \textcolor{keywordflow}{case} ( integration\_plm )
1387           q = ( xr - xl ) * (                            &
1388               ppoly0\_coefs(jl,1)                         &
1389             + ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 ) )
1390         \textcolor{keywordflow}{case} ( integration\_ppm )
1391           q = ( xr - xl ) * (                            &
1392                 ppoly0\_coefs(jl,1)                       &
1393             + ( ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 ) &
1394             +   ppoly0\_coefs(jl,3) * r\_3 * ( ( xi1*xi1 + xi0*xi0 ) + xi0*xi1 ) ) )
1395         \textcolor{keywordflow}{case} ( integration\_pqm )
1396           x0\_2 = xi0*xi0
1397           x1\_2 = xi1*xi1
1398           x02px12 = x0\_2 + x1\_2
1399           x0px1 = xi1 + xi0
1400           q = ( xr - xl ) * (                                    &
1401                 ppoly0\_coefs(jl,1)                               &
1402             + ( ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 )         &
1403             + ( ppoly0\_coefs(jl,3) * r\_3 * ( x02px12 + xi0*xi1 ) &
1404             +   ppoly0\_coefs(jl,4) * 0.25* ( x02px12 * x0px1 )   &
1405             +   ppoly0\_coefs(jl,5) * 0.2 * ( ( xi1*x1\_2 + xi0*x0\_2 ) * x0px1 + x0\_2*x1\_2 ) ) ) )
1406 \textcolor{keywordflow}{        case default}
1407           \textcolor{keyword}{call }mom\_error( fatal,\textcolor{stringliteral}{'The selected integration method is invalid'} )
1408 \textcolor{keywordflow}{      end select}
1409 
1410     \textcolor{keywordflow}{else}
1411     \textcolor{comment}{! The target cell spans at least two cells of the source grid.}
1412     \textcolor{comment}{! This situation is represented by the following schematic, where}
1413     \textcolor{comment}{! the cells in which xL and xR are located have indexes jL and jR,}
1414     \textcolor{comment}{! respectively :}
1415     \textcolor{comment}{!}
1416     \textcolor{comment}{! ----|-----o---|--- ... --|---o----------|-------------}
1417     \textcolor{comment}{!           xL                 xR}
1418     \textcolor{comment}{!}
1419     \textcolor{comment}{! We first integrate from xL up to the right boundary of cell jL, then}
1420     \textcolor{comment}{! add the integrated amounts of cells located between jL and jR and then}
1421     \textcolor{comment}{! integrate from the left boundary of cell jR up to xR}
1422 
1423       q = 0.0
1424 
1425       \textcolor{comment}{! Integrate from xL up to right boundary of cell jL}
1426 \textcolor{preprocessor}{#ifdef \_\_USE\_ROUNDOFF\_SAFE\_ADJUSTMENTS\_\_}
1427 \textcolor{preprocessor}{}      xi0 = max( 0., min( 1., ( xl - x0jll ) / ( h0(jl) + hneglect ) ) )
1428 \textcolor{preprocessor}{#else}
1429 \textcolor{preprocessor}{}      xi0 = (xl - x0jll) / ( h0(jl) + hneglect )
1430 \textcolor{preprocessor}{#endif}
1431 \textcolor{preprocessor}{}      xi1 = 1.0
1432 
1433       hact = h0(jl) * ( xi1 - xi0 )
1434 
1435       \textcolor{keywordflow}{select case} ( method )
1436         \textcolor{keywordflow}{case} ( integration\_pcm )
1437           q = q + ( x0jlr - xl ) * ppoly0\_coefs(jl,1)
1438         \textcolor{keywordflow}{case} ( integration\_plm )
1439           q = q + ( x0jlr - xl ) * (                     &
1440               ppoly0\_coefs(jl,1)                         &
1441             + ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 ) )
1442         \textcolor{keywordflow}{case} ( integration\_ppm )
1443           q = q + ( x0jlr - xl ) * (                     &
1444                 ppoly0\_coefs(jl,1)                       &
1445             + ( ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 ) &
1446             +   ppoly0\_coefs(jl,3) * r\_3 * ( ( xi1*xi1 + xi0*xi0 ) + xi0*xi1 ) ) )
1447         \textcolor{keywordflow}{case} ( integration\_pqm )
1448           x0\_2 = xi0*xi0
1449           x1\_2 = xi1*xi1
1450           x02px12 = x0\_2 + x1\_2
1451           x0px1 = xi1 + xi0
1452           q = q + ( x0jlr - xl ) * (                             &
1453                 ppoly0\_coefs(jl,1)                               &
1454             + ( ppoly0\_coefs(jl,2) * 0.5 * ( xi1 + xi0 )         &
1455             + ( ppoly0\_coefs(jl,3) * r\_3 * ( x02px12 + xi0*xi1 ) &
1456             +   ppoly0\_coefs(jl,4) * 0.25* ( x02px12 * x0px1 )   &
1457             +   ppoly0\_coefs(jl,5) * 0.2 * ( ( xi1*x1\_2 + xi0*x0\_2 ) * x0px1 + x0\_2*x1\_2 ) ) ) )
1458 \textcolor{keywordflow}{        case default}
1459           \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'The selected integration method is invalid'} )
1460 \textcolor{keywordflow}{      end select}
1461 
1462       \textcolor{comment}{! Integrate contents within cells strictly comprised between jL and jR}
1463       \textcolor{keywordflow}{if} ( jr > (jl+1) ) \textcolor{keywordflow}{then}
1464         \textcolor{keywordflow}{do} k = jl+1,jr-1
1465           q = q + h0(k) * u0(k)
1466           hact = hact + h0(k)
1467 \textcolor{keywordflow}{        enddo}
1468 \textcolor{keywordflow}{      endif}
1469 
1470       \textcolor{comment}{! Integrate from left boundary of cell jR up to xR}
1471       xi0 = 0.0
1472 \textcolor{preprocessor}{#ifdef \_\_USE\_ROUNDOFF\_SAFE\_ADJUSTMENTS\_\_}
1473 \textcolor{preprocessor}{}      xi1 = max( 0., min( 1., ( xr - x0jrl ) / ( h0(jr) + hneglect ) ) )
1474 \textcolor{preprocessor}{#else}
1475 \textcolor{preprocessor}{}      xi1 = (xr - x0jrl) / ( h0(jr) + hneglect )
1476 \textcolor{preprocessor}{#endif}
1477 \textcolor{preprocessor}{}
1478       hact = hact + h0(jr) * ( xi1 - xi0 )
1479 
1480       \textcolor{keywordflow}{select case} ( method )
1481         \textcolor{keywordflow}{case} ( integration\_pcm )
1482           q = q + ( xr - x0jrl ) * ppoly0\_coefs(jr,1)
1483         \textcolor{keywordflow}{case} ( integration\_plm )
1484           q = q + ( xr - x0jrl ) * (                     &
1485               ppoly0\_coefs(jr,1)                         &
1486             + ppoly0\_coefs(jr,2) * 0.5 * ( xi1 + xi0 ) )
1487         \textcolor{keywordflow}{case} ( integration\_ppm )
1488           q = q + ( xr - x0jrl ) * (                     &
1489                 ppoly0\_coefs(jr,1)                       &
1490             + ( ppoly0\_coefs(jr,2) * 0.5 * ( xi1 + xi0 ) &
1491             +   ppoly0\_coefs(jr,3) * r\_3 * ( ( xi1*xi1 + xi0*xi0 ) + xi0*xi1 ) ) )
1492         \textcolor{keywordflow}{case} ( integration\_pqm )
1493           x0\_2 = xi0*xi0
1494           x1\_2 = xi1*xi1
1495           x02px12 = x0\_2 + x1\_2
1496           x0px1 = xi1 + xi0
1497           q = q + ( xr - x0jrl ) * (                             &
1498                 ppoly0\_coefs(jr,1)                               &
1499             + ( ppoly0\_coefs(jr,2) * 0.5 * ( xi1 + xi0 )         &
1500             + ( ppoly0\_coefs(jr,3) * r\_3 * ( x02px12 + xi0*xi1 ) &
1501             +   ppoly0\_coefs(jr,4) * 0.25* ( x02px12 * x0px1 )   &
1502             +   ppoly0\_coefs(jr,5) * 0.2 * ( ( xi1*x1\_2 + xi0*x0\_2 ) * x0px1 + x0\_2*x1\_2 ) ) ) )
1503 \textcolor{keywordflow}{        case default}
1504           \textcolor{keyword}{call }mom\_error( fatal,\textcolor{stringliteral}{'The selected integration method is invalid'} )
1505 \textcolor{keywordflow}{      end select}
1506 
1507 \textcolor{keywordflow}{    endif} \textcolor{comment}{! end integration for non-vanished cells}
1508 
1509     \textcolor{comment}{! The cell average is the integrated value divided by the cell width}
1510 \textcolor{preprocessor}{#ifdef \_\_USE\_ROUNDOFF\_SAFE\_ADJUSTMENTS\_\_}
1511 \textcolor{preprocessor}{}\textcolor{keywordflow}{if} (hact==0.) \textcolor{keywordflow}{then}
1512     uave = ppoly0\_coefs(jl,1)
1513 \textcolor{keywordflow}{else}
1514     uave = q / hact
1515 \textcolor{keywordflow}{endif}
1516 \textcolor{preprocessor}{#else}
1517 \textcolor{preprocessor}{}    uave = q / hc
1518 \textcolor{preprocessor}{#endif}
1519 \textcolor{preprocessor}{}
1520 \textcolor{keywordflow}{  endif} \textcolor{comment}{! endif clause to check if cell is vanished}
1521 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_accd6922c5eb61fa77c11869d8b219f7c}\label{namespacemom__remapping_accd6922c5eb61fa77c11869d8b219f7c}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!ispossumerrsignificant@{ispossumerrsignificant}}
\index{ispossumerrsignificant@{ispossumerrsignificant}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{ispossumerrsignificant()}{ispossumerrsignificant()}}
{\footnotesize\ttfamily logical function mom\+\_\+remapping\+::ispossumerrsignificant (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n1,  }\item[{real, intent(in)}]{sum1,  }\item[{integer, intent(in)}]{n2,  }\item[{real, intent(in)}]{sum2 }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Compare two summation estimates of positive data and judge if due to more than round-\/off. When two sums are calculated from different vectors that should add up to the same value, the results can differ by round off. The round off error can be bounded to be proportional to the number of operations. This function returns true if the difference between sum1 and sum2 is larger than than the estimated round off bound. 

\begin{DoxyNote}{Note}
This estimate/function is only valid for summation of positive data.
\end{DoxyNote}

\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n1} & Number of values in sum1\\
\hline
\mbox{\tt in}  & {\em n2} & Number of values in sum2\\
\hline
\mbox{\tt in}  & {\em sum1} & Sum of n1 values\\
\hline
\mbox{\tt in}  & {\em sum2} & Sum of n2 values\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
True if difference in sums is large 
\end{DoxyReturn}


Definition at line 164 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
164   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: n1\textcolor{comment}{   !< Number of values in sum1}
165   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{intent(in)} :: n2\textcolor{comment}{   !< Number of values in sum2}
166   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)} :: sum1\textcolor{comment}{ !< Sum of n1 values}
167   \textcolor{keywordtype}{real},    \textcolor{keywordtype}{intent(in)} :: sum2\textcolor{comment}{ !< Sum of n2 values}
168   \textcolor{keywordtype}{logical}             :: isPosSumErrSignificant\textcolor{comment}{ !< True if difference in sums is large}
169   \textcolor{comment}{! Local variables}
170   \textcolor{keywordtype}{real} :: sumErr, allowedErr, eps
171 
172   \textcolor{keywordflow}{if} (sum1<0.) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'isPosSumErrSignificant: sum1<0 is not allowed!'})
173   \textcolor{keywordflow}{if} (sum2<0.) \textcolor{keyword}{call }mom\_error(fatal,\textcolor{stringliteral}{'isPosSumErrSignificant: sum2<0 is not allowed!'})
174   sumerr = abs(sum1-sum2)
175   eps = epsilon(sum1)
176   allowederr = eps*0.5*(\textcolor{keywordtype}{real}(n1-1)*sum1+\textcolor{keywordtype}{real}(n2-1)*sum2)
177   \textcolor{keywordflow}{if} (sumerr>allowederr) \textcolor{keywordflow}{then}
178     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'isPosSumErrSignificant: sum1,sum2='},sum1,sum2
179     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'isPosSumErrSignificant: eps='},eps
180     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'isPosSumErrSignificant: err,n*eps='},sumerr,allowederr
181     \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'isPosSumErrSignificant: err/eps,n1,n2,n1+n2='},sumerr/eps,n1,n2,n1+n2
182     ispossumerrsignificant = .true.
183   \textcolor{keywordflow}{else}
184     ispossumerrsignificant = .false.
185 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a0b392b7cbac49fc8ab52b2830e3a9306}\label{namespacemom__remapping_a0b392b7cbac49fc8ab52b2830e3a9306}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!measure\+\_\+input\+\_\+bounds@{measure\+\_\+input\+\_\+bounds}}
\index{measure\+\_\+input\+\_\+bounds@{measure\+\_\+input\+\_\+bounds}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{measure\+\_\+input\+\_\+bounds()}{measure\_input\_bounds()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::measure\+\_\+input\+\_\+bounds (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{real, dimension(n0,2), intent(in)}]{edge\+\_\+values,  }\item[{real, intent(out)}]{h0tot,  }\item[{real, intent(out)}]{h0err,  }\item[{real, intent(out)}]{u0tot,  }\item[{real, intent(out)}]{u0err,  }\item[{real, intent(out)}]{u0min,  }\item[{real, intent(out)}]{u0max }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Measure totals and bounds on source grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n0} & Number of cells on source grid\\
\hline
\mbox{\tt in}  & {\em h0} & Cell widths on source grid\\
\hline
\mbox{\tt in}  & {\em u0} & Cell averages on source grid\\
\hline
\mbox{\tt in}  & {\em edge\+\_\+values} & Cell edge values on source grid\\
\hline
\mbox{\tt out}  & {\em h0tot} & Sum of cell widths\\
\hline
\mbox{\tt out}  & {\em h0err} & Magnitude of round-\/off error in h0tot\\
\hline
\mbox{\tt out}  & {\em u0tot} & Sum of cell widths times values\\
\hline
\mbox{\tt out}  & {\em u0err} & Magnitude of round-\/off error in u0tot\\
\hline
\mbox{\tt out}  & {\em u0min} & Minimum value in reconstructions of u0\\
\hline
\mbox{\tt out}  & {\em u0max} & Maximum value in reconstructions of u0 \\
\hline
\end{DoxyParams}


Definition at line 1031 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1031   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{ !< Number of cells on source grid}
1032   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{ !< Cell widths on source grid}
1033   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)},   \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{ !< Cell averages on source grid}
1034   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)}, \textcolor{keywordtype}{intent(in)}  :: edge\_values\textcolor{comment}{ !< Cell edge values on source grid}
1035   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: h0tot\textcolor{comment}{ !< Sum of cell widths}
1036   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: h0err\textcolor{comment}{ !< Magnitude of round-off error in h0tot}
1037   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: u0tot\textcolor{comment}{ !< Sum of cell widths times values}
1038   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: u0err\textcolor{comment}{ !< Magnitude of round-off error in u0tot}
1039   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: u0min\textcolor{comment}{ !< Minimum value in reconstructions of u0}
1040   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: u0max\textcolor{comment}{ !< Maximum value in reconstructions of u0}
1041   \textcolor{comment}{! Local variables}
1042   \textcolor{keywordtype}{integer} :: k
1043   \textcolor{keywordtype}{real} :: eps
1044 
1045   eps = epsilon(h0(1))
1046   h0tot = h0(1)
1047   h0err = 0.
1048   u0tot = h0(1) * u0(1)
1049   u0err = 0.
1050   u0min = min( edge\_values(1,1), edge\_values(1,2) )
1051   u0max = max( edge\_values(1,1), edge\_values(1,2) )
1052   \textcolor{keywordflow}{do} k = 2, n0
1053     h0tot = h0tot + h0(k)
1054     h0err = h0err + eps * max(h0tot, h0(k))
1055     u0tot = u0tot + h0(k) * u0(k)
1056     u0err = u0err + eps * max(abs(u0tot), abs(h0(k) * u0(k)))
1057     u0min = min( u0min, edge\_values(k,1), edge\_values(k,2) )
1058     u0max = max( u0max, edge\_values(k,1), edge\_values(k,2) )
1059 \textcolor{keywordflow}{  enddo}
1060 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a5453aeefe69feaff159b67f3a4bd2366}\label{namespacemom__remapping_a5453aeefe69feaff159b67f3a4bd2366}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!measure\+\_\+output\+\_\+bounds@{measure\+\_\+output\+\_\+bounds}}
\index{measure\+\_\+output\+\_\+bounds@{measure\+\_\+output\+\_\+bounds}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{measure\+\_\+output\+\_\+bounds()}{measure\_output\_bounds()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::measure\+\_\+output\+\_\+bounds (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(n1), intent(in)}]{h1,  }\item[{real, dimension(n1), intent(in)}]{u1,  }\item[{real, intent(out)}]{h1tot,  }\item[{real, intent(out)}]{h1err,  }\item[{real, intent(out)}]{u1tot,  }\item[{real, intent(out)}]{u1err,  }\item[{real, intent(out)}]{u1min,  }\item[{real, intent(out)}]{u1max }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Measure totals and bounds on destination grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n1} & Number of cells on destination grid\\
\hline
\mbox{\tt in}  & {\em h1} & Cell widths on destination grid\\
\hline
\mbox{\tt in}  & {\em u1} & Cell averages on destination grid\\
\hline
\mbox{\tt out}  & {\em h1tot} & Sum of cell widths\\
\hline
\mbox{\tt out}  & {\em h1err} & Magnitude of round-\/off error in h1tot\\
\hline
\mbox{\tt out}  & {\em u1tot} & Sum of cell widths times values\\
\hline
\mbox{\tt out}  & {\em u1err} & Magnitude of round-\/off error in u1tot\\
\hline
\mbox{\tt out}  & {\em u1min} & Minimum value in reconstructions of u1\\
\hline
\mbox{\tt out}  & {\em u1max} & Maximum value in reconstructions of u1 \\
\hline
\end{DoxyParams}


Definition at line 1065 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1065   \textcolor{keywordtype}{integer},               \textcolor{keywordtype}{intent(in)}  :: n1\textcolor{comment}{ !< Number of cells on destination grid}
1066   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1)},   \textcolor{keywordtype}{intent(in)}  :: h1\textcolor{comment}{ !< Cell widths on destination grid}
1067   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1)},   \textcolor{keywordtype}{intent(in)}  :: u1\textcolor{comment}{ !< Cell averages on destination grid}
1068   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: h1tot\textcolor{comment}{ !< Sum of cell widths}
1069   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: h1err\textcolor{comment}{ !< Magnitude of round-off error in h1tot}
1070   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: u1tot\textcolor{comment}{ !< Sum of cell widths times values}
1071   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: u1err\textcolor{comment}{ !< Magnitude of round-off error in u1tot}
1072   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: u1min\textcolor{comment}{ !< Minimum value in reconstructions of u1}
1073   \textcolor{keywordtype}{real},                  \textcolor{keywordtype}{intent(out)} :: u1max\textcolor{comment}{ !< Maximum value in reconstructions of u1}
1074   \textcolor{comment}{! Local variables}
1075   \textcolor{keywordtype}{integer} :: k
1076   \textcolor{keywordtype}{real} :: eps
1077 
1078   eps = epsilon(h1(1))
1079   h1tot = h1(1)
1080   h1err = 0.
1081   u1tot = h1(1) * u1(1)
1082   u1err = 0.
1083   u1min = u1(1)
1084   u1max = u1(1)
1085   \textcolor{keywordflow}{do} k = 2, n1
1086     h1tot = h1tot + h1(k)
1087     h1err = h1err + eps * max(h1tot, h1(k))
1088     u1tot = u1tot + h1(k) * u1(k)
1089     u1err = u1err + eps * max(abs(u1tot), abs(h1(k) * u1(k)))
1090     u1min = min(u1min, u1(k))
1091     u1max = max(u1max, u1(k))
1092 \textcolor{keywordflow}{  enddo}
1093 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_ab933069898cb9de16ec60f175185762e}\label{namespacemom__remapping_ab933069898cb9de16ec60f175185762e}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!remap\+\_\+via\+\_\+sub\+\_\+cells@{remap\+\_\+via\+\_\+sub\+\_\+cells}}
\index{remap\+\_\+via\+\_\+sub\+\_\+cells@{remap\+\_\+via\+\_\+sub\+\_\+cells}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{remap\+\_\+via\+\_\+sub\+\_\+cells()}{remap\_via\_sub\_cells()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::remap\+\_\+via\+\_\+sub\+\_\+cells (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{real, dimension(n0,2), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(n1), intent(in)}]{h1,  }\item[{integer, intent(in)}]{method,  }\item[{logical, intent(in)}]{force\+\_\+bounds\+\_\+in\+\_\+subcell,  }\item[{real, dimension(n1), intent(out)}]{u1,  }\item[{real, intent(out)}]{uh\+\_\+err,  }\item[{real, dimension(n0+n1+1), intent(out), optional}]{ah\+\_\+sub,  }\item[{integer, dimension(n0+n1+1), intent(out), optional}]{aisub\+\_\+src,  }\item[{integer, dimension(n0), intent(out), optional}]{aiss,  }\item[{integer, dimension(n0), intent(out), optional}]{aise }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Remaps column of n0 values u0 on grid h0 to grid h1 with n1 cells by calculating the n0+n1+1 sub-\/integrals of the intersection of h0 and h1, and the summing the appropriate integrals into the h1$\ast$u1 values. h0 and h1 must have the same units. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n0} & Number of cells in source grid\\
\hline
\mbox{\tt in}  & {\em h0} & Source grid widths (size n0)\\
\hline
\mbox{\tt in}  & {\em u0} & Source cell averages (size n0)\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+e} & Edge value of polynomial\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial\\
\hline
\mbox{\tt in}  & {\em n1} & Number of cells in target grid\\
\hline
\mbox{\tt in}  & {\em h1} & Target grid widths (size n1)\\
\hline
\mbox{\tt in}  & {\em method} & Remapping scheme to use\\
\hline
\mbox{\tt in}  & {\em force\+\_\+bounds\+\_\+in\+\_\+subcell} & Force sub-\/cell values to be bounded\\
\hline
\mbox{\tt out}  & {\em u1} & Target cell averages (size n1)\\
\hline
\mbox{\tt out}  & {\em uh\+\_\+err} & Estimate of bound on error in sum of u$\ast$h\\
\hline
\mbox{\tt out}  & {\em ah\+\_\+sub} & h\+\_\+sub\\
\hline
\mbox{\tt out}  & {\em aisub\+\_\+src} & i\+\_\+sub\+\_\+src\\
\hline
\mbox{\tt out}  & {\em aiss} & isrc\+\_\+start\\
\hline
\mbox{\tt out}  & {\em aise} & isrc\+\_\+ens \\
\hline
\end{DoxyParams}


Definition at line 520 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
520   \textcolor{keywordtype}{integer},           \textcolor{keywordtype}{intent(in)}    :: n0\textcolor{comment}{     !< Number of cells in source grid}
521   \textcolor{keywordtype}{real},              \textcolor{keywordtype}{intent(in)}    :: h0(n0)\textcolor{comment}{  !< Source grid widths (size n0)}
522   \textcolor{keywordtype}{real},              \textcolor{keywordtype}{intent(in)}    :: u0(n0)\textcolor{comment}{  !< Source cell averages (size n0)}
523   \textcolor{keywordtype}{real},              \textcolor{keywordtype}{intent(in)}    :: ppoly0\_E(n0,2)\textcolor{comment}{            !< Edge value of polynomial}
524   \textcolor{keywordtype}{real},              \textcolor{keywordtype}{intent(in)}    :: ppoly0\_coefs(:,:)\textcolor{comment}{ !< Coefficients of polynomial}
525   \textcolor{keywordtype}{integer},           \textcolor{keywordtype}{intent(in)}    :: n1\textcolor{comment}{     !< Number of cells in target grid}
526   \textcolor{keywordtype}{real},              \textcolor{keywordtype}{intent(in)}    :: h1(n1)\textcolor{comment}{  !< Target grid widths (size n1)}
527   \textcolor{keywordtype}{integer},           \textcolor{keywordtype}{intent(in)}    :: method\textcolor{comment}{ !< Remapping scheme to use}
528   \textcolor{keywordtype}{logical},           \textcolor{keywordtype}{intent(in)}    :: force\_bounds\_in\_subcell\textcolor{comment}{ !< Force sub-cell values to be bounded}
529   \textcolor{keywordtype}{real},              \textcolor{keywordtype}{intent(out)}   :: u1(n1)\textcolor{comment}{  !< Target cell averages (size n1)}
530   \textcolor{keywordtype}{real},              \textcolor{keywordtype}{intent(out)}   :: uh\_err\textcolor{comment}{ !< Estimate of bound on error in sum of u*h}
531   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},    \textcolor{keywordtype}{intent(out)}   :: ah\_sub(n0+n1+1)\textcolor{comment}{ !< h\_sub}
532   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: aisub\_src(n0+n1+1)\textcolor{comment}{ !< i\_sub\_src}
533   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: aiss(n0)\textcolor{comment}{ !< isrc\_start}
534   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)}   :: aise(n0)\textcolor{comment}{ !< isrc\_ens}
535   \textcolor{comment}{! Local variables}
536   \textcolor{keywordtype}{integer} :: i\_sub \textcolor{comment}{! Index of sub-cell}
537   \textcolor{keywordtype}{integer} :: i0 \textcolor{comment}{! Index into h0(1:n0), source column}
538   \textcolor{keywordtype}{integer} :: i1 \textcolor{comment}{! Index into h1(1:n1), target column}
539   \textcolor{keywordtype}{integer} :: i\_start0 \textcolor{comment}{! Used to record which sub-cells map to source cells}
540   \textcolor{keywordtype}{integer} :: i\_start1 \textcolor{comment}{! Used to record which sub-cells map to target cells}
541   \textcolor{keywordtype}{integer} :: i\_max \textcolor{comment}{! Used to record which sub-cell is the largest contribution of a source cell}
542   \textcolor{keywordtype}{real} :: dh\_max \textcolor{comment}{! Used to record which sub-cell is the largest contribution of a source cell}
543   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0+n1+1)} :: h\_sub \textcolor{comment}{! Width of each each sub-cell}
544   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0+n1+1)} :: uh\_sub \textcolor{comment}{! Integral of u*h over each sub-cell}
545   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0+n1+1)} :: u\_sub \textcolor{comment}{! Average of u over each sub-cell}
546   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n0+n1+1)} :: isub\_src \textcolor{comment}{! Index of source cell for each sub-cell}
547   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n0)} :: isrc\_start \textcolor{comment}{! Index of first sub-cell within each source cell}
548   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n0)} :: isrc\_end \textcolor{comment}{! Index of last sub-cell within each source cell}
549   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n0)} :: isrc\_max \textcolor{comment}{! Index of thickest sub-cell within each source cell}
550   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)} :: h0\_eff \textcolor{comment}{! Effective thickness of source cells}
551   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)} :: u0\_min \textcolor{comment}{! Minimum value of reconstructions in source cell}
552   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)} :: u0\_max \textcolor{comment}{! Minimum value of reconstructions in source cell}
553   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n1)} :: itgt\_start \textcolor{comment}{! Index of first sub-cell within each target cell}
554   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{dimension(n1)} :: itgt\_end \textcolor{comment}{! Index of last sub-cell within each target cell}
555   \textcolor{keywordtype}{real} :: xa, xb \textcolor{comment}{! Non-dimensional position within a source cell (0..1)}
556   \textcolor{keywordtype}{real} :: h0\_supply, h1\_supply \textcolor{comment}{! The amount of width available for constructing sub-cells}
557   \textcolor{keywordtype}{real} :: dh \textcolor{comment}{! The width of the sub-cell}
558   \textcolor{keywordtype}{real} :: duh \textcolor{comment}{! The total amount of accumulated stuff (u*h)}
559   \textcolor{keywordtype}{real} :: dh0\_eff \textcolor{comment}{! Running sum of source cell thickness}
560   \textcolor{comment}{! For error checking/debugging}
561   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{parameter} :: force\_bounds\_in\_target = .true. \textcolor{comment}{! To fix round-off issues}
562   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{parameter} :: adjust\_thickest\_subcell = .true. \textcolor{comment}{! To fix round-off conservation issues}
563   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{parameter} :: debug\_bounds = .false. \textcolor{comment}{! For debugging overshoots etc.}
564   \textcolor{keywordtype}{integer} :: k, i0\_last\_thick\_cell
565   \textcolor{keywordtype}{real} :: h0tot, h0err, h1tot, h1err, h2tot, h2err, u02\_err
566   \textcolor{keywordtype}{real} :: u0tot, u0err, u0min, u0max, u1tot, u1err, u1min, u1max, u2tot, u2err, u2min, u2max, u\_orig
567   \textcolor{keywordtype}{logical} :: src\_has\_volume\textcolor{comment}{ !< True if h0 has not been consumed}
568   \textcolor{keywordtype}{logical} :: tgt\_has\_volume\textcolor{comment}{ !< True if h1 has not been consumed}
569 
570   \textcolor{keywordflow}{if} (old\_algorithm) isrc\_max(:)=1
571 
572   i0\_last\_thick\_cell = 0
573   \textcolor{keywordflow}{do} i0 = 1, n0
574     u0\_min(i0) = min(ppoly0\_e(i0,1), ppoly0\_e(i0,2))
575     u0\_max(i0) = max(ppoly0\_e(i0,1), ppoly0\_e(i0,2))
576     \textcolor{keywordflow}{if} (h0(i0)>0.) i0\_last\_thick\_cell = i0
577 \textcolor{keywordflow}{  enddo}
578 
579   \textcolor{comment}{! Initialize algorithm}
580   h0\_supply = h0(1)
581   h1\_supply = h1(1)
582   src\_has\_volume = .true.
583   tgt\_has\_volume = .true.
584   i0 = 1 ; i1 = 1
585   i\_start0 = 1 ; i\_start1 = 1
586   i\_max = 1
587   dh\_max = 0.
588   dh0\_eff = 0.
589 
590   \textcolor{comment}{! First sub-cell is always vanished}
591   h\_sub(1) = 0.
592   isrc\_start(1) = 1
593   isrc\_end(1) = 1
594   isrc\_max(1) = 1
595   isub\_src(1) = 1
596 
597   \textcolor{comment}{! Loop over each sub-cell to calculate intersections with source and target grids}
598   \textcolor{keywordflow}{do} i\_sub = 2, n0+n1+1
599 
600     \textcolor{comment}{! This is the width of the sub-cell, determined by which ever column has the least}
601     \textcolor{comment}{! supply available to consume.}
602     dh = min(h0\_supply, h1\_supply)
603 
604     \textcolor{comment}{! This is the running sum of the source cell thickness. After summing over each}
605     \textcolor{comment}{! sub-cell, the sum of sub-cell thickness might differ from the original source}
606     \textcolor{comment}{! cell thickness due to round off.}
607     dh0\_eff = dh0\_eff + min(dh, h0\_supply)
608 
609     \textcolor{comment}{! Record the source index (i0) that this sub-cell integral belongs to. This}
610     \textcolor{comment}{! is needed to index the reconstruction coefficients for the source cell}
611     \textcolor{comment}{! used in the integrals of the sub-cell width.}
612     isub\_src(i\_sub) = i0
613     h\_sub(i\_sub) = dh
614 
615     \textcolor{comment}{! For recording the largest sub-cell within a source cell.}
616     \textcolor{keywordflow}{if} (dh >= dh\_max) \textcolor{keywordflow}{then}
617       i\_max = i\_sub
618       dh\_max = dh
619 \textcolor{keywordflow}{    endif}
620 
621     \textcolor{comment}{! Which ever column (source or target) has the least width left to consume determined}
622     \textcolor{comment}{! the width, dh, of sub-cell i\_sub in the expression for dh above.}
623     \textcolor{keywordflow}{if} (h0\_supply <= h1\_supply .and. src\_has\_volume) \textcolor{keywordflow}{then}
624       \textcolor{comment}{! h0\_supply is smaller than h1\_supply) so we consume h0\_supply and increment the}
625       \textcolor{comment}{! source cell index.}
626       h1\_supply = h1\_supply - dh \textcolor{comment}{! Although this is a difference the result will}
627                                  \textcolor{comment}{! be non-negative because of the conditional.}
628       \textcolor{comment}{! Record the sub-cell start/end index that span the source cell i0.}
629       isrc\_start(i0) = i\_start0
630       isrc\_end(i0) = i\_sub
631       i\_start0 = i\_sub + 1
632       \textcolor{comment}{! Record the sub-cell that is the largest fraction of the source cell.}
633       isrc\_max(i0) = i\_max
634       i\_max = i\_sub + 1
635       dh\_max = 0.
636       \textcolor{comment}{! Record the source cell thickness found by summing the sub-cell thicknesses.}
637       h0\_eff(i0) = dh0\_eff
638       \textcolor{comment}{! Move the source index.}
639       \textcolor{keywordflow}{if} (old\_algorithm) \textcolor{keywordflow}{then}
640         \textcolor{keywordflow}{if} (i0 < i0\_last\_thick\_cell) \textcolor{keywordflow}{then}
641           i0 = i0 + 1
642           h0\_supply = h0(i0)
643           dh0\_eff = 0.
644           \textcolor{keywordflow}{do} \textcolor{keywordflow}{while} (h0\_supply==0. .and. i0<i0\_last\_thick\_cell)
645             \textcolor{comment}{! This loop skips over vanished source cells}
646             i0 = i0 + 1
647             h0\_supply = h0(i0)
648 \textcolor{keywordflow}{          enddo}
649         \textcolor{keywordflow}{else}
650           h0\_supply = 1.e30
651 \textcolor{keywordflow}{        endif}
652       \textcolor{keywordflow}{else}
653         \textcolor{keywordflow}{if} (i0 < n0) \textcolor{keywordflow}{then}
654           i0 = i0 + 1
655           h0\_supply = h0(i0)
656           dh0\_eff = 0.
657         \textcolor{keywordflow}{else}
658           h0\_supply = 0.
659           src\_has\_volume = .false.
660 \textcolor{keywordflow}{        endif}
661 \textcolor{keywordflow}{      endif}
662     \textcolor{keywordflow}{elseif} (h0\_supply >= h1\_supply .and. tgt\_has\_volume) \textcolor{keywordflow}{then}
663       \textcolor{comment}{! h1\_supply is smaller than h0\_supply) so we consume h1\_supply and increment the}
664       \textcolor{comment}{! target cell index.}
665       h0\_supply = h0\_supply - dh \textcolor{comment}{! Although this is a difference the result will}
666                                  \textcolor{comment}{! be non-negative because of the conditional.}
667       \textcolor{comment}{! Record the sub-cell start/end index that span the target cell i1.}
668       itgt\_start(i1) = i\_start1
669       itgt\_end(i1) = i\_sub
670       i\_start1 = i\_sub + 1
671       \textcolor{comment}{! Move the target index.}
672       \textcolor{keywordflow}{if} (i1 < n1) \textcolor{keywordflow}{then}
673         i1 = i1 + 1
674         h1\_supply = h1(i1)
675       \textcolor{keywordflow}{else}
676         \textcolor{keywordflow}{if} (old\_algorithm) \textcolor{keywordflow}{then}
677           h1\_supply = 1.e30
678         \textcolor{keywordflow}{else}
679           h1\_supply = 0.
680           tgt\_has\_volume = .false.
681 \textcolor{keywordflow}{        endif}
682 \textcolor{keywordflow}{      endif}
683     \textcolor{keywordflow}{elseif} (src\_has\_volume) \textcolor{keywordflow}{then}
684       \textcolor{comment}{! We ran out of target volume but still have source cells to consume}
685       h\_sub(i\_sub) = h0\_supply
686       \textcolor{comment}{! Record the sub-cell start/end index that span the source cell i0.}
687       isrc\_start(i0) = i\_start0
688       isrc\_end(i0) = i\_sub
689       i\_start0 = i\_sub + 1
690       \textcolor{comment}{! Record the sub-cell that is the largest fraction of the source cell.}
691       isrc\_max(i0) = i\_max
692       i\_max = i\_sub + 1
693       dh\_max = 0.
694       \textcolor{comment}{! Record the source cell thickness found by summing the sub-cell thicknesses.}
695       h0\_eff(i0) = dh0\_eff
696       \textcolor{keywordflow}{if} (i0 < n0) \textcolor{keywordflow}{then}
697         i0 = i0 + 1
698         h0\_supply = h0(i0)
699         dh0\_eff = 0.
700       \textcolor{keywordflow}{else}
701         h0\_supply = 0.
702         src\_has\_volume = .false.
703 \textcolor{keywordflow}{      endif}
704     \textcolor{keywordflow}{elseif} (tgt\_has\_volume) \textcolor{keywordflow}{then}
705       \textcolor{comment}{! We ran out of source volume but still have target cells to consume}
706       h\_sub(i\_sub) = h1\_supply
707       \textcolor{comment}{! Record the sub-cell start/end index that span the target cell i1.}
708       itgt\_start(i1) = i\_start1
709       itgt\_end(i1) = i\_sub
710       i\_start1 = i\_sub + 1
711       \textcolor{comment}{! Move the target index.}
712       \textcolor{keywordflow}{if} (i1 < n1) \textcolor{keywordflow}{then}
713         i1 = i1 + 1
714         h1\_supply = h1(i1)
715       \textcolor{keywordflow}{else}
716         h1\_supply = 0.
717         tgt\_has\_volume = .false.
718 \textcolor{keywordflow}{      endif}
719     \textcolor{keywordflow}{else}
720       stop \textcolor{stringliteral}{'remap\_via\_sub\_cells: THIS SHOULD NEVER HAPPEN!'}
721 \textcolor{keywordflow}{    endif}
722 
723 \textcolor{keywordflow}{  enddo}
724 
725   \textcolor{comment}{! Loop over each sub-cell to calculate average/integral values within each sub-cell.}
726   xa = 0.
727   dh0\_eff = 0.
728   uh\_sub(1) = 0.
729   u\_sub(1) = ppoly0\_e(1,1)
730   u02\_err = 0.
731   \textcolor{keywordflow}{do} i\_sub = 2, n0+n1
732 
733     \textcolor{comment}{! Sub-cell thickness from loop above}
734     dh = h\_sub(i\_sub)
735 
736     \textcolor{comment}{! Source cell}
737     i0 = isub\_src(i\_sub)
738 
739     \textcolor{comment}{! Evaluate average and integral for sub-cell i\_sub.}
740     \textcolor{comment}{! Integral is over distance dh but expressed in terms of non-dimensional}
741     \textcolor{comment}{! positions with source cell from xa to xb  (0 <= xa <= xb <= 1).}
742     dh0\_eff = dh0\_eff + dh \textcolor{comment}{! Cumulative thickness within the source cell}
743     \textcolor{keywordflow}{if} (h0\_eff(i0)>0.) \textcolor{keywordflow}{then}
744       xb = dh0\_eff / h0\_eff(i0) \textcolor{comment}{! This expression yields xa <= xb <= 1.0}
745       xb = min(1., xb) \textcolor{comment}{! This is only needed when the total target column is wider than the source column}
746       u\_sub(i\_sub) = average\_value\_ppoly( n0, u0, ppoly0\_e, ppoly0\_coefs, method, i0, xa, xb)
747     \textcolor{keywordflow}{else} \textcolor{comment}{! Vanished cell}
748       xb = 1.
749       u\_sub(i\_sub) = u0(i0)
750 \textcolor{keywordflow}{    endif}
751     \textcolor{keywordflow}{if} (debug\_bounds) \textcolor{keywordflow}{then}
752       \textcolor{keywordflow}{if} (method<5 .and.(u\_sub(i\_sub)<u0\_min(i0) .or. u\_sub(i\_sub)>u0\_max(i0))) \textcolor{keywordflow}{then}
753         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Sub cell average is out of bounds'},i\_sub,\textcolor{stringliteral}{'method='},method
754         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'xa,xb: '},xa,xb
755         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Edge values: '},ppoly0\_e(i0,:),\textcolor{stringliteral}{'mean'},u0(i0)
756         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'a\_c: '},(u0(i0)-ppoly0\_e(i0,1))+(u0(i0)-ppoly0\_e(i0,2))
757         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Polynomial coeffs: '},ppoly0\_coefs(i0,:)
758         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Bounds min='},u0\_min(i0),\textcolor{stringliteral}{'max='},u0\_max(i0)
759         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Average: '},u\_sub(i\_sub),\textcolor{stringliteral}{'rel to min='},u\_sub(i\_sub)-u0\_min(i0),\textcolor{stringliteral}{'rel to max='},u\_sub(i\_sub
      )-u0\_max(i0)
760         \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_remapping, remap\_via\_sub\_cells: '}//&
761              \textcolor{stringliteral}{'Sub-cell average is out of bounds!'} )
762 \textcolor{keywordflow}{      endif}
763 \textcolor{keywordflow}{    endif}
764     \textcolor{keywordflow}{if} (force\_bounds\_in\_subcell) \textcolor{keywordflow}{then}
765       \textcolor{comment}{! These next two lines should not be needed but when using PQM we found roundoff}
766       \textcolor{comment}{! can lead to overshoots. These lines sweep issues under the rug which need to be}
767       \textcolor{comment}{! properly .. later. -AJA}
768       u\_orig = u\_sub(i\_sub)
769       u\_sub(i\_sub) = max( u\_sub(i\_sub), u0\_min(i0) )
770       u\_sub(i\_sub) = min( u\_sub(i\_sub), u0\_max(i0) )
771       u02\_err = u02\_err + dh*abs( u\_sub(i\_sub) - u\_orig )
772 \textcolor{keywordflow}{    endif}
773     uh\_sub(i\_sub) = dh * u\_sub(i\_sub)
774 
775     \textcolor{keywordflow}{if} (isub\_src(i\_sub+1) /= i0) \textcolor{keywordflow}{then}
776       \textcolor{comment}{! If the next sub-cell is in a different source cell, reset the position counters}
777       dh0\_eff = 0.
778       xa = 0.
779     \textcolor{keywordflow}{else}
780       xa = xb \textcolor{comment}{! Next integral will start at end of last}
781 \textcolor{keywordflow}{    endif}
782 
783 \textcolor{keywordflow}{  enddo}
784   u\_sub(n0+n1+1) = ppoly0\_e(n0,2)                   \textcolor{comment}{! This value is only needed when total target column}
785   uh\_sub(n0+n1+1) = ppoly0\_e(n0,2) * h\_sub(n0+n1+1) \textcolor{comment}{! is wider than the source column}
786 
787   \textcolor{keywordflow}{if} (adjust\_thickest\_subcell) \textcolor{keywordflow}{then}
788     \textcolor{comment}{! Loop over each source cell substituting the integral/average for the thickest sub-cell (within}
789     \textcolor{comment}{! the source cell) with the residual of the source cell integral minus the other sub-cell integrals}
790     \textcolor{comment}{! aka a genius algorithm for accurate conservation when remapping from Robert Hallberg
       (@Hallberg-NOAA).}
791     \textcolor{keywordflow}{do} i0 = 1, i0\_last\_thick\_cell
792       i\_max = isrc\_max(i0)
793       dh\_max = h\_sub(i\_max)
794       \textcolor{keywordflow}{if} (dh\_max > 0.) \textcolor{keywordflow}{then}
795         \textcolor{comment}{! duh will be the sum of sub-cell integrals within the source cell except for the thickest
       sub-cell.}
796         duh = 0.
797         \textcolor{keywordflow}{do} i\_sub = isrc\_start(i0), isrc\_end(i0)
798           \textcolor{keywordflow}{if} (i\_sub /= i\_max) duh = duh + uh\_sub(i\_sub)
799 \textcolor{keywordflow}{        enddo}
800         uh\_sub(i\_max) = u0(i0)*h0(i0) - duh
801         u02\_err = u02\_err + max( abs(uh\_sub(i\_max)), abs(u0(i0)*h0(i0)), abs(duh) )
802 \textcolor{keywordflow}{      endif}
803 \textcolor{keywordflow}{    enddo}
804 \textcolor{keywordflow}{  endif}
805 
806   \textcolor{comment}{! Loop over each target cell summing the integrals from sub-cells within the target cell.}
807   uh\_err = 0.
808   \textcolor{keywordflow}{do} i1 = 1, n1
809     \textcolor{keywordflow}{if} (h1(i1) > 0.) \textcolor{keywordflow}{then}
810       duh = 0. ; dh = 0.
811       i\_sub = itgt\_start(i1)
812       \textcolor{keywordflow}{if} (force\_bounds\_in\_target) \textcolor{keywordflow}{then}
813         u1min = u\_sub(i\_sub)
814         u1max = u\_sub(i\_sub)
815 \textcolor{keywordflow}{      endif}
816       \textcolor{keywordflow}{do} i\_sub = itgt\_start(i1), itgt\_end(i1)
817         \textcolor{keywordflow}{if} (force\_bounds\_in\_target) \textcolor{keywordflow}{then}
818           u1min = min(u1min, u\_sub(i\_sub))
819           u1max = max(u1max, u\_sub(i\_sub))
820 \textcolor{keywordflow}{        endif}
821         dh = dh + h\_sub(i\_sub)
822         duh = duh + uh\_sub(i\_sub)
823         \textcolor{comment}{! This accumulates the contribution to the error bound for the sum of u*h}
824         uh\_err = uh\_err + max(abs(duh),abs(uh\_sub(i\_sub)))*epsilon(duh)
825 \textcolor{keywordflow}{      enddo}
826       u1(i1) = duh / dh
827       \textcolor{comment}{! This is the contribution from the division to the error bound for the sum of u*h}
828       uh\_err = uh\_err + abs(duh)*epsilon(duh)
829       \textcolor{keywordflow}{if} (force\_bounds\_in\_target) \textcolor{keywordflow}{then}
830         u\_orig = u1(i1)
831         u1(i1) = max(u1min, min(u1max, u1(i1)))
832         \textcolor{comment}{! Adjusting to be bounded contributes to the error for the sum of u*h}
833         uh\_err = uh\_err + dh*abs( u1(i1)-u\_orig )
834 \textcolor{keywordflow}{      endif}
835     \textcolor{keywordflow}{else}
836       u1(i1) = u\_sub(itgt\_start(i1))
837 \textcolor{keywordflow}{    endif}
838 \textcolor{keywordflow}{  enddo}
839 
840   \textcolor{comment}{! Check errors and bounds}
841   \textcolor{keywordflow}{if} (debug\_bounds) \textcolor{keywordflow}{then}
842     \textcolor{keyword}{call }measure\_input\_bounds( n0, h0, u0, ppoly0\_e, h0tot, h0err, u0tot, u0err, u0min, u0max )
843     \textcolor{keyword}{call }measure\_output\_bounds( n1, h1, u1, h1tot, h1err, u1tot, u1err, u1min, u1max )
844     \textcolor{keyword}{call }measure\_output\_bounds( n0+n1+1, h\_sub, u\_sub, h2tot, h2err, u2tot, u2err, u2min, u2max )
845     \textcolor{keywordflow}{if} (method<5) \textcolor{keywordflow}{then} \textcolor{comment}{! We except PQM until we've debugged it}
846     \textcolor{keywordflow}{if} (     (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err+u02\_err .and. abs(h1tot-h0tot)<h0err+h1err) &
847         .or. (abs(u2tot-u0tot)>u0err+u2err+u02\_err .and. abs(h2tot-h0tot)<h0err+h2err) &
848         .or. (u1min<u0min .or. u1max>u0max) ) \textcolor{keywordflow}{then}
849       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'method = '},method
850       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Source to sub-cells:'}
851       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H: h0tot='},h0tot,\textcolor{stringliteral}{'h2tot='},h2tot,\textcolor{stringliteral}{'dh='},h2tot-h0tot,\textcolor{stringliteral}{'h0err='},h0err,\textcolor{stringliteral}{'h2err='},h2err
852       \textcolor{keywordflow}{if} (abs(h2tot-h0tot)>h0err+h2err) &
853         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H non-conservation difference='},h2tot-h0tot,\textcolor{stringliteral}{'allowed err='},h0err+h2err,\textcolor{stringliteral}{' <-----!'}
854       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'UH: u0tot='},u0tot,\textcolor{stringliteral}{'u2tot='},u2tot,\textcolor{stringliteral}{'duh='},u2tot-u0tot,\textcolor{stringliteral}{'u0err='},u0err,\textcolor{stringliteral}{'u2err='},u2err,&
855                  \textcolor{stringliteral}{'adjustment err='},u02\_err
856       \textcolor{keywordflow}{if} (abs(u2tot-u0tot)>u0err+u2err) &
857         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U non-conservation difference='},u2tot-u0tot,\textcolor{stringliteral}{'allowed err='},u0err+u2err,\textcolor{stringliteral}{' <-----!'}
858       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Sub-cells to target:'}
859       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H: h2tot='},h2tot,\textcolor{stringliteral}{'h1tot='},h1tot,\textcolor{stringliteral}{'dh='},h1tot-h2tot,\textcolor{stringliteral}{'h2err='},h2err,\textcolor{stringliteral}{'h1err='},h1err
860       \textcolor{keywordflow}{if} (abs(h1tot-h2tot)>h2err+h1err) &
861         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H non-conservation difference='},h1tot-h2tot,\textcolor{stringliteral}{'allowed err='},h2err+h1err,\textcolor{stringliteral}{' <-----!'}
862       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'UH: u2tot='},u2tot,\textcolor{stringliteral}{'u1tot='},u1tot,\textcolor{stringliteral}{'duh='},u1tot-u2tot,\textcolor{stringliteral}{'u2err='},u2err,\textcolor{stringliteral}{'u1err='},u1err,\textcolor{stringliteral}{
      'uh\_err='},uh\_err
863       \textcolor{keywordflow}{if} (abs(u1tot-u2tot)>u2err+u1err) &
864         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U non-conservation difference='},u1tot-u2tot,\textcolor{stringliteral}{'allowed err='},u2err+u1err,\textcolor{stringliteral}{' <-----!'}
865       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'Source to target:'}
866       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H: h0tot='},h0tot,\textcolor{stringliteral}{'h1tot='},h1tot,\textcolor{stringliteral}{'dh='},h1tot-h0tot,\textcolor{stringliteral}{'h0err='},h0err,\textcolor{stringliteral}{'h1err='},h1err
867       \textcolor{keywordflow}{if} (abs(h1tot-h0tot)>h0err+h1err) &
868         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H non-conservation difference='},h1tot-h0tot,\textcolor{stringliteral}{'allowed err='},h0err+h1err,\textcolor{stringliteral}{' <-----!'}
869       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'UH: u0tot='},u0tot,\textcolor{stringliteral}{'u1tot='},u1tot,\textcolor{stringliteral}{'duh='},u1tot-u0tot,\textcolor{stringliteral}{'u0err='},u0err,\textcolor{stringliteral}{'u1err='},u1err,\textcolor{stringliteral}{
      'uh\_err='},uh\_err
870       \textcolor{keywordflow}{if} (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err) &
871         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U non-conservation difference='},u1tot-u0tot,\textcolor{stringliteral}{'allowed err='},u0err+u1err+uh\_err,\textcolor{stringliteral}{'
       <-----!'}
872       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0min='},u0min,\textcolor{stringliteral}{'u1min='},u1min,\textcolor{stringliteral}{'u2min='},u2min
873       \textcolor{keywordflow}{if} (u1min<u0min) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U minimum overshoot='},u1min-u0min,\textcolor{stringliteral}{' <-----!'}
874       \textcolor{keywordflow}{if} (u2min<u0min) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U2 minimum overshoot='},u2min-u0min,\textcolor{stringliteral}{' <-----!'}
875       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0max='},u0max,\textcolor{stringliteral}{'u1max='},u1max,\textcolor{stringliteral}{'u2max='},u2max
876       \textcolor{keywordflow}{if} (u1max>u0max) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U maximum overshoot='},u1max-u0max,\textcolor{stringliteral}{' <-----!'}
877       \textcolor{keywordflow}{if} (u2max>u0max) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U2 maximum overshoot='},u2max-u0max,\textcolor{stringliteral}{' <-----!'}
878       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,6a24,2a3)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'h0'},\textcolor{stringliteral}{'left edge'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'right edge'},\textcolor{stringliteral}{'h1'},\textcolor{stringliteral}{'u1'},\textcolor{stringliteral}{'is'},\textcolor{stringliteral}{'ie'}
879       \textcolor{keywordflow}{do} k = 1, max(n0,n1)
880         \textcolor{keywordflow}{if} (k<=min(n0,n1)) \textcolor{keywordflow}{then}
881           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16,2i3)'}) k,h0(k),ppoly0\_e(k,1),u0(k),ppoly0\_e(k,2),h1(k),u1(k),itgt\_start(k)
      ,itgt\_end(k)
882         \textcolor{keywordflow}{elseif} (k>n0) \textcolor{keywordflow}{then}
883           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,96x,1p2e24.16,2i3)'}) k,h1(k),u1(k),itgt\_start(k),itgt\_end(k)
884         \textcolor{keywordflow}{else}
885           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p4e24.16)'}) k,h0(k),ppoly0\_e(k,1),u0(k),ppoly0\_e(k,2)
886 \textcolor{keywordflow}{        endif}
887 \textcolor{keywordflow}{      enddo}
888       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,2a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'Polynomial coefficients'}
889       \textcolor{keywordflow}{do} k = 1, n0
890         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16)'}) k,u0(k),ppoly0\_coefs(k,:)
891 \textcolor{keywordflow}{      enddo}
892       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,3a24,a3,2a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'Sub-cell h'},\textcolor{stringliteral}{'Sub-cell u'},\textcolor{stringliteral}{'Sub-cell hu'},\textcolor{stringliteral}{'i0'},\textcolor{stringliteral}{'xa'},\textcolor{stringliteral}{'xb'}
893       xa = 0.
894       dh0\_eff = 0.
895       \textcolor{keywordflow}{do} k = 1, n0+n1+1
896         dh = h\_sub(k)
897         i0 = isub\_src(k)
898         dh0\_eff = dh0\_eff + dh \textcolor{comment}{! Cumulative thickness within the source cell}
899         xb = dh0\_eff / h0\_eff(i0) \textcolor{comment}{! This expression yields xa <= xb <= 1.0}
900         xb = min(1., xb) \textcolor{comment}{! This is only needed when the total target column is wider than the source column}
901         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p3e24.16,i3,1p2e24.16)'}) k,h\_sub(k),u\_sub(k),uh\_sub(k),i0,xa,xb
902         \textcolor{keywordflow}{if} (k<=n0+n1) \textcolor{keywordflow}{then}
903           \textcolor{keywordflow}{if} (isub\_src(k+1) /= i0) \textcolor{keywordflow}{then}
904             dh0\_eff = 0.; xa = 0.
905           \textcolor{keywordflow}{else}
906             xa = xb
907 \textcolor{keywordflow}{          endif}
908 \textcolor{keywordflow}{        endif}
909 \textcolor{keywordflow}{      enddo}
910       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_remapping, remap\_via\_sub\_cells: '}//&
911              \textcolor{stringliteral}{'Remapping result is inconsistent!'} )
912 \textcolor{keywordflow}{    endif}
913 \textcolor{keywordflow}{    endif} \textcolor{comment}{! method<5}
914 \textcolor{keywordflow}{  endif} \textcolor{comment}{! debug\_bounds}
915 
916   \textcolor{comment}{! Include the error remapping from source to sub-cells in the estimate of total remapping error}
917   uh\_err = uh\_err + u02\_err
918 
919   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(ah\_sub)) ah\_sub(1:n0+n1+1) = h\_sub(1:n0+n1+1)
920   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(aisub\_src)) aisub\_src(1:n0+n1+1) = isub\_src(1:n0+n1+1)
921   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(aiss)) aiss(1:n0) = isrc\_start(1:n0)
922   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(aise)) aise(1:n0) = isrc\_end(1:n0)
923 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_ad41da2080e01eaed0b189079801b3c9b}\label{namespacemom__remapping_ad41da2080e01eaed0b189079801b3c9b}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!remapbydeltaz@{remapbydeltaz}}
\index{remapbydeltaz@{remapbydeltaz}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{remapbydeltaz()}{remapbydeltaz()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::remapbydeltaz (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(\+:), intent(in)}]{h0,  }\item[{real, dimension(\+:), intent(in)}]{u0,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(\+:), intent(in)}]{dx1,  }\item[{integer, intent(in)}]{method,  }\item[{real, dimension(\+:), intent(out)}]{u1,  }\item[{real, dimension(\+:), intent(out), optional}]{h1,  }\item[{real, intent(in), optional}]{h\+\_\+neglect }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Remaps column of values u0 on grid h0 to implied grid h1 where the interfaces of h1 differ from those of h0 by dx. The new grid is defined relative to the original grid by change dx1(\+:) = x\+New(\+:) -\/ x\+Old(\+:) and the remapping calculated so that h\+New(k) q\+New(k) = h\+Old(k) q\+Old(k) + F(k+1) -\/ F(k) where F(k) = dx1(k) q\+Average and where q\+Average is the average q\+Old in the region z\+Old(k) to z\+New(k). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n0} & Number of cells in source grid\\
\hline
\mbox{\tt in}  & {\em h0} & Source grid sizes (size n0)\\
\hline
\mbox{\tt in}  & {\em u0} & Source cell averages (size n0)\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+e} & Edge value of polynomial\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial\\
\hline
\mbox{\tt in}  & {\em n1} & Number of cells in target grid\\
\hline
\mbox{\tt in}  & {\em dx1} & Target grid edge positions (size n1+1)\\
\hline
\mbox{\tt in}  & {\em method} & Remapping scheme to use\\
\hline
\mbox{\tt out}  & {\em u1} & Target cell averages (size n1)\\
\hline
\mbox{\tt out}  & {\em h1} & Target grid widths (size n1)\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions in the same units as h. \\
\hline
\end{DoxyParams}


Definition at line 1148 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1148   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{     !< Number of cells in source grid}
1149   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{     !< Source grid sizes (size n0)}
1150   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{     !< Source cell averages (size n0)}
1151   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}  :: ppoly0\_E\textcolor{comment}{ !< Edge value of polynomial}
1152   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:,:)}, \textcolor{keywordtype}{intent(in)}  :: ppoly0\_coefs\textcolor{comment}{ !< Coefficients of polynomial}
1153   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}  :: n1\textcolor{comment}{     !< Number of cells in target grid}
1154   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(in)}  :: dx1\textcolor{comment}{    !< Target grid edge positions (size n1+1)}
1155   \textcolor{keywordtype}{integer},              \textcolor{keywordtype}{intent(in)}  :: method\textcolor{comment}{ !< Remapping scheme to use}
1156   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)},   \textcolor{keywordtype}{intent(out)} :: u1\textcolor{comment}{     !< Target cell averages (size n1)}
1157   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(:)}, &
1158               \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(out)} :: h1\textcolor{comment}{     !< Target grid widths (size n1)}
1159   \textcolor{keywordtype}{real},       \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}  :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}
1160 \textcolor{comment}{                                           !! purpose of cell reconstructions}
1161 \textcolor{comment}{                                           !! in the same units as h.}
1162   \textcolor{comment}{! Local variables}
1163   \textcolor{keywordtype}{integer} :: iTarget
1164   \textcolor{keywordtype}{real}    :: xL, xR    \textcolor{comment}{! coordinates of target cell edges}
1165   \textcolor{keywordtype}{real}    :: xOld, hOld, uOld
1166   \textcolor{keywordtype}{real}    :: xNew, hNew, h\_err
1167   \textcolor{keywordtype}{real}    :: uhNew, hFlux, uAve, fluxL, fluxR
1168   \textcolor{keywordtype}{integer} :: jStart \textcolor{comment}{! Used by integrateReconOnInterval()}
1169   \textcolor{keywordtype}{real}    :: xStart \textcolor{comment}{! Used by integrateReconOnInterval()}
1170 
1171   \textcolor{comment}{! Loop on cells in target grid. For each cell, iTarget, the left flux is}
1172   \textcolor{comment}{! the right flux of the cell to the left, iTarget-1.}
1173   \textcolor{comment}{! The left flux is initialized by started at iTarget=0 to calculate the}
1174   \textcolor{comment}{! right flux which can take into account the target left boundary being}
1175   \textcolor{comment}{! in the interior of the source domain.}
1176   fluxr = 0.
1177   h\_err = 0. \textcolor{comment}{! For measuring round-off error}
1178   jstart = 1
1179   xstart = 0.
1180   \textcolor{keywordflow}{do} itarget = 0,n1
1181     fluxl = fluxr \textcolor{comment}{! This does nothing for iTarget=0}
1182 
1183     \textcolor{keywordflow}{if} (itarget == 0) \textcolor{keywordflow}{then}
1184       xold = 0.     \textcolor{comment}{! Left boundary is at x=0}
1185       hold = -1.e30 \textcolor{comment}{! Should not be used for iTarget = 0}
1186       uold = -1.e30 \textcolor{comment}{! Should not be used for iTarget = 0}
1187     \textcolor{keywordflow}{elseif} (itarget <= n0) \textcolor{keywordflow}{then}
1188       xold = xold + h0(itarget) \textcolor{comment}{! Position of right edge of cell}
1189       hold = h0(itarget)
1190       uold = u0(itarget)
1191       h\_err = h\_err + epsilon(hold) * max(hold, xold)
1192     \textcolor{keywordflow}{else}
1193       hold = 0.       \textcolor{comment}{! as if for layers>n0, they were vanished}
1194       uold = 1.e30    \textcolor{comment}{! and the initial value should not matter}
1195 \textcolor{keywordflow}{    endif}
1196     xnew = xold + dx1(itarget+1)
1197     xl = min( xold, xnew )
1198     xr = max( xold, xnew )
1199 
1200     \textcolor{comment}{! hFlux is the positive width of the remapped volume}
1201     hflux = abs(dx1(itarget+1))
1202     \textcolor{keyword}{call }integraterecononinterval( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, method, &
1203                                    xl, xr, hflux, uave, jstart, xstart )
1204     \textcolor{comment}{! uAve is the average value of u, independent of sign of dx1}
1205     fluxr = dx1(itarget+1)*uave \textcolor{comment}{! Includes sign of dx1}
1206 
1207     \textcolor{keywordflow}{if} (itarget>0) \textcolor{keywordflow}{then}
1208       hnew = hold + ( dx1(itarget+1) - dx1(itarget) )
1209       hnew = max( 0., hnew )
1210       uhnew = ( uold * hold ) + ( fluxr - fluxl )
1211       \textcolor{keywordflow}{if} (hnew>0.) \textcolor{keywordflow}{then}
1212         u1(itarget) = uhnew / hnew
1213       \textcolor{keywordflow}{else}
1214         u1(itarget) = uave
1215 \textcolor{keywordflow}{      endif}
1216       \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h1)) h1(itarget) = hnew
1217 \textcolor{keywordflow}{    endif}
1218 
1219 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end iTarget loop on target grid cells}
1220 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_add104225e8ea85f4e6a324da6be3dba2}\label{namespacemom__remapping_add104225e8ea85f4e6a324da6be3dba2}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!remapbyprojection@{remapbyprojection}}
\index{remapbyprojection@{remapbyprojection}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{remapbyprojection()}{remapbyprojection()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::remapbyprojection (\begin{DoxyParamCaption}\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(\+:), intent(in)}]{h0,  }\item[{real, dimension(\+:), intent(in)}]{u0,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+E,  }\item[{real, dimension(\+:,\+:), intent(in)}]{ppoly0\+\_\+coefs,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(\+:), intent(in)}]{h1,  }\item[{integer, intent(in)}]{method,  }\item[{real, dimension(\+:), intent(out)}]{u1,  }\item[{real, intent(in), optional}]{h\+\_\+neglect }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Remaps column of values u0 on grid h0 to grid h1 by integrating over the projection of each h1 cell onto the h0 grid. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em n0} & Number of cells in source grid\\
\hline
\mbox{\tt in}  & {\em h0} & Source grid widths (size n0)\\
\hline
\mbox{\tt in}  & {\em u0} & Source cell averages (size n0)\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+e} & Edge value of polynomial\\
\hline
\mbox{\tt in}  & {\em ppoly0\+\_\+coefs} & Coefficients of polynomial\\
\hline
\mbox{\tt in}  & {\em n1} & Number of cells in target grid\\
\hline
\mbox{\tt in}  & {\em h1} & Target grid widths (size n1)\\
\hline
\mbox{\tt in}  & {\em method} & Remapping scheme to use\\
\hline
\mbox{\tt out}  & {\em u1} & Target cell averages (size n1)\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions in the same units as h. \\
\hline
\end{DoxyParams}


Definition at line 1100 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1100   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: n0\textcolor{comment}{     !< Number of cells in source grid}
1101   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: h0(:)\textcolor{comment}{  !< Source grid widths (size n0)}
1102   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: u0(:)\textcolor{comment}{  !< Source cell averages (size n0)}
1103   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: ppoly0\_E(:,:)\textcolor{comment}{     !< Edge value of polynomial}
1104   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: ppoly0\_coefs(:,:)\textcolor{comment}{ !< Coefficients of polynomial}
1105   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: n1\textcolor{comment}{     !< Number of cells in target grid}
1106   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(in)}    :: h1(:)\textcolor{comment}{  !< Target grid widths (size n1)}
1107   \textcolor{keywordtype}{integer},       \textcolor{keywordtype}{intent(in)}    :: method\textcolor{comment}{ !< Remapping scheme to use}
1108   \textcolor{keywordtype}{real},          \textcolor{keywordtype}{intent(out)}   :: u1(:)\textcolor{comment}{  !< Target cell averages (size n1)}
1109   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}   :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}
1110 \textcolor{comment}{                                           !! purpose of cell reconstructions}
1111 \textcolor{comment}{                                           !! in the same units as h.}
1112   \textcolor{comment}{! Local variables}
1113   \textcolor{keywordtype}{integer}       :: iTarget
1114   \textcolor{keywordtype}{real}          :: xL, xR       \textcolor{comment}{! coordinates of target cell edges}
1115   \textcolor{keywordtype}{integer}       :: jStart \textcolor{comment}{! Used by integrateReconOnInterval()}
1116   \textcolor{keywordtype}{real}          :: xStart \textcolor{comment}{! Used by integrateReconOnInterval()}
1117 
1118   \textcolor{comment}{! Loop on cells in target grid (grid1). For each target cell, we need to find}
1119   \textcolor{comment}{! in which source cells the target cell edges lie. The associated indexes are}
1120   \textcolor{comment}{! noted j0 and j1.}
1121   xr = 0. \textcolor{comment}{! Left boundary is at x=0}
1122   jstart = 1
1123   xstart = 0.
1124   \textcolor{keywordflow}{do} itarget = 1,n1
1125     \textcolor{comment}{! Determine the coordinates of the target cell edges}
1126     xl = xr
1127     xr = xl + h1(itarget)
1128 
1129     \textcolor{keyword}{call }integraterecononinterval( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, method, &
1130                                    xl, xr, h1(itarget), u1(itarget), jstart, xstart, h\_neglect )
1131 
1132 \textcolor{keywordflow}{  enddo} \textcolor{comment}{! end iTarget loop on target grid cells}
1133 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_abe4a1d5b1b9f26063a5e4aba5be0b0a5}\label{namespacemom__remapping_abe4a1d5b1b9f26063a5e4aba5be0b0a5}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!remapping\+\_\+core\+\_\+h@{remapping\+\_\+core\+\_\+h}}
\index{remapping\+\_\+core\+\_\+h@{remapping\+\_\+core\+\_\+h}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{remapping\+\_\+core\+\_\+h()}{remapping\_core\_h()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::remapping\+\_\+core\+\_\+h (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(n1), intent(in)}]{h1,  }\item[{real, dimension(n1), intent(out)}]{u1,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})}



Remaps column of values u0 on grid h0 to grid h1 assuming the top edge is aligned. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em cs} & Remapping control structure\\
\hline
\mbox{\tt in}  & {\em n0} & Number of cells on source grid\\
\hline
\mbox{\tt in}  & {\em h0} & Cell widths on source grid\\
\hline
\mbox{\tt in}  & {\em u0} & Cell averages on source grid\\
\hline
\mbox{\tt in}  & {\em n1} & Number of cells on target grid\\
\hline
\mbox{\tt in}  & {\em h1} & Cell widths on target grid\\
\hline
\mbox{\tt out}  & {\em u1} & Cell averages on target grid\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions 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 in the same units as h0. \\
\hline
\end{DoxyParams}


Definition at line 190 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
190   \textcolor{keywordtype}{type}(remapping\_CS),  \textcolor{keywordtype}{intent(in)}  :: CS\textcolor{comment}{ !< Remapping control structure}
191   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{ !< Number of cells on source grid}
192   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)}, \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{ !< Cell widths on source grid}
193   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)}, \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{ !< Cell averages on source grid}
194   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}  :: n1\textcolor{comment}{ !< Number of cells on target grid}
195   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1)}, \textcolor{keywordtype}{intent(in)}  :: h1\textcolor{comment}{ !< Cell widths on target grid}
196   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1)}, \textcolor{keywordtype}{intent(out)} :: u1\textcolor{comment}{ !< Cell averages on target grid}
197   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},      \textcolor{keywordtype}{intent(in)}  :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}
198 \textcolor{comment}{                                         !! purpose of cell reconstructions}
199 \textcolor{comment}{                                         !! in the same units as h0.}
200   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},      \textcolor{keywordtype}{intent(in)}  :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width}
201 \textcolor{comment}{                                         !! for the purpose of edge value}
202 \textcolor{comment}{                                         !! calculations in the same units as h0.}
203   \textcolor{comment}{! Local variables}
204   \textcolor{keywordtype}{integer} :: iMethod
205   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)}           :: ppoly\_r\_E            \textcolor{comment}{!Edge value of polynomial}
206   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)}           :: ppoly\_r\_S            \textcolor{comment}{!Edge slope of polynomial}
207   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,CS%degree+1)} :: ppoly\_r\_coefs \textcolor{comment}{!Coefficients of polynomial}
208   \textcolor{keywordtype}{integer} :: k
209   \textcolor{keywordtype}{real} :: eps, h0tot, h0err, h1tot, h1err, u0tot, u0err, u0min, u0max, u1tot, u1err, u1min, u1max, uh\_err
210   \textcolor{keywordtype}{real} :: hNeglect, hNeglect\_edge
211 
212   hneglect = 1.0e-30 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect)) hneglect = h\_neglect
213   hneglect\_edge = 1.0e-10 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect\_edge)) hneglect\_edge = h\_neglect\_edge
214 
215   \textcolor{keyword}{call }build\_reconstructions\_1d( cs, n0, h0, u0, ppoly\_r\_coefs, ppoly\_r\_e, ppoly\_r\_s, imethod, &
216                                  hneglect, hneglect\_edge )
217 
218   \textcolor{keywordflow}{if} (cs%check\_reconstruction) \textcolor{keyword}{call }check\_reconstructions\_1d(n0, h0, u0, cs%degree, &
219                                    cs%boundary\_extrapolation, ppoly\_r\_coefs, ppoly\_r\_e, ppoly\_r\_s)
220 
221 
222   \textcolor{keyword}{call }remap\_via\_sub\_cells( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, n1, h1, imethod, &
223                             cs%force\_bounds\_in\_subcell, u1, uh\_err )
224 
225   \textcolor{keywordflow}{if} (cs%check\_remapping) \textcolor{keywordflow}{then}
226     \textcolor{comment}{! Check errors and bounds}
227     \textcolor{keyword}{call }measure\_input\_bounds( n0, h0, u0, ppoly\_r\_e, h0tot, h0err, u0tot, u0err, u0min, u0max )
228     \textcolor{keyword}{call }measure\_output\_bounds( n1, h1, u1, h1tot, h1err, u1tot, u1err, u1min, u1max )
229     \textcolor{keywordflow}{if} (imethod<5) \textcolor{keywordflow}{then} \textcolor{comment}{! We except PQM until we've debugged it}
230     \textcolor{keywordflow}{if} ( (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err .and. abs(h1tot-h0tot)<h0err+h1err) &
231         .or. (u1min<u0min .or. u1max>u0max) ) \textcolor{keywordflow}{then}
232       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'iMethod = '},imethod
233       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H: h0tot='},h0tot,\textcolor{stringliteral}{'h1tot='},h1tot,\textcolor{stringliteral}{'dh='},h1tot-h0tot,\textcolor{stringliteral}{'h0err='},h0err,\textcolor{stringliteral}{'h1err='},h1err
234       \textcolor{keywordflow}{if} (abs(h1tot-h0tot)>h0err+h1err) &
235         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H non-conservation difference='},h1tot-h0tot,\textcolor{stringliteral}{'allowed err='},h0err+h1err,\textcolor{stringliteral}{' <-----!'}
236       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'UH: u0tot='},u0tot,\textcolor{stringliteral}{'u1tot='},u1tot,\textcolor{stringliteral}{'duh='},u1tot-u0tot,\textcolor{stringliteral}{'u0err='},u0err,\textcolor{stringliteral}{'u1err='},u1err,\textcolor{stringliteral}{
      'uh\_err='},uh\_err
237       \textcolor{keywordflow}{if} (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err) &
238         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U non-conservation difference='},u1tot-u0tot,\textcolor{stringliteral}{'allowed err='},u0err+u1err+uh\_err,\textcolor{stringliteral}{'
       <-----!'}
239       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0min='},u0min,\textcolor{stringliteral}{'u1min='},u1min
240       \textcolor{keywordflow}{if} (u1min<u0min) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U minimum overshoot='},u1min-u0min,\textcolor{stringliteral}{' <-----!'}
241       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0max='},u0max,\textcolor{stringliteral}{'u1max='},u1max
242       \textcolor{keywordflow}{if} (u1max>u0max) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U maximum overshoot='},u1max-u0max,\textcolor{stringliteral}{' <-----!'}
243       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,6a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'h0'},\textcolor{stringliteral}{'left edge'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'right edge'},\textcolor{stringliteral}{'h1'},\textcolor{stringliteral}{'u1'}
244       \textcolor{keywordflow}{do} k = 1, max(n0,n1)
245         \textcolor{keywordflow}{if} (k<=min(n0,n1)) \textcolor{keywordflow}{then}
246           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16)'}) k,h0(k),ppoly\_r\_e(k,1),u0(k),ppoly\_r\_e(k,2),h1(k),u1(k)
247         \textcolor{keywordflow}{elseif} (k>n0) \textcolor{keywordflow}{then}
248           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,96x,1p2e24.16)'}) k,h1(k),u1(k)
249         \textcolor{keywordflow}{else}
250           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p4e24.16)'}) k,h0(k),ppoly\_r\_e(k,1),u0(k),ppoly\_r\_e(k,2)
251 \textcolor{keywordflow}{        endif}
252 \textcolor{keywordflow}{      enddo}
253       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,2a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'Polynomial coefficients'}
254       \textcolor{keywordflow}{do} k = 1, n0
255         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16)'}) k,u0(k),ppoly\_r\_coefs(k,:)
256 \textcolor{keywordflow}{      enddo}
257       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_remapping, remapping\_core\_h: '}//&
258              \textcolor{stringliteral}{'Remapping result is inconsistent!'} )
259 \textcolor{keywordflow}{    endif}
260 \textcolor{keywordflow}{    endif} \textcolor{comment}{! method<5}
261 \textcolor{keywordflow}{  endif}
262 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a38bd02a8643f4a984bc3985f34106d9a}\label{namespacemom__remapping_a38bd02a8643f4a984bc3985f34106d9a}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!remapping\+\_\+core\+\_\+w@{remapping\+\_\+core\+\_\+w}}
\index{remapping\+\_\+core\+\_\+w@{remapping\+\_\+core\+\_\+w}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{remapping\+\_\+core\+\_\+w()}{remapping\_core\_w()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::remapping\+\_\+core\+\_\+w (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(in)}]{CS,  }\item[{integer, intent(in)}]{n0,  }\item[{real, dimension(n0), intent(in)}]{h0,  }\item[{real, dimension(n0), intent(in)}]{u0,  }\item[{integer, intent(in)}]{n1,  }\item[{real, dimension(n1+1), intent(in)}]{dx,  }\item[{real, dimension(n1), intent(out)}]{u1,  }\item[{real, intent(in), optional}]{h\+\_\+neglect,  }\item[{real, intent(in), optional}]{h\+\_\+neglect\+\_\+edge }\end{DoxyParamCaption})}



Remaps column of values u0 on grid h0 to implied grid h1 where the interfaces of h1 differ from those of h0 by dx. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em cs} & Remapping control structure\\
\hline
\mbox{\tt in}  & {\em n0} & Number of cells on source grid\\
\hline
\mbox{\tt in}  & {\em h0} & Cell widths on source grid\\
\hline
\mbox{\tt in}  & {\em u0} & Cell averages on source grid\\
\hline
\mbox{\tt in}  & {\em n1} & Number of cells on target grid\\
\hline
\mbox{\tt in}  & {\em dx} & Cell widths on target grid\\
\hline
\mbox{\tt out}  & {\em u1} & Cell averages on target grid\\
\hline
\mbox{\tt in}  & {\em h\+\_\+neglect} & A negligibly small width for the purpose of cell reconstructions 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 in the same units as h0. \\
\hline
\end{DoxyParams}


Definition at line 268 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
268   \textcolor{keywordtype}{type}(remapping\_CS),  \textcolor{keywordtype}{intent(in)}  :: CS\textcolor{comment}{ !< Remapping control structure}
269   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}  :: n0\textcolor{comment}{ !< Number of cells on source grid}
270   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)}, \textcolor{keywordtype}{intent(in)}  :: h0\textcolor{comment}{ !< Cell widths on source grid}
271   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0)}, \textcolor{keywordtype}{intent(in)}  :: u0\textcolor{comment}{ !< Cell averages on source grid}
272   \textcolor{keywordtype}{integer},             \textcolor{keywordtype}{intent(in)}  :: n1\textcolor{comment}{ !< Number of cells on target grid}
273   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1+1)}, \textcolor{keywordtype}{intent(in)} :: dx\textcolor{comment}{ !< Cell widths on target grid}
274   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1)}, \textcolor{keywordtype}{intent(out)} :: u1\textcolor{comment}{ !< Cell averages on target grid}
275   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},      \textcolor{keywordtype}{intent(in)}  :: h\_neglect\textcolor{comment}{ !< A negligibly small width for the}
276 \textcolor{comment}{                                         !! purpose of cell reconstructions}
277 \textcolor{comment}{                                         !! in the same units as h0.}
278   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{optional},      \textcolor{keywordtype}{intent(in)}  :: h\_neglect\_edge\textcolor{comment}{ !< A negligibly small width}
279 \textcolor{comment}{                                         !! for the purpose of edge value}
280 \textcolor{comment}{                                         !! calculations in the same units as h0.}
281   \textcolor{comment}{! Local variables}
282   \textcolor{keywordtype}{integer} :: iMethod
283   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)}           :: ppoly\_r\_E            \textcolor{comment}{!Edge value of polynomial}
284   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,2)}           :: ppoly\_r\_S            \textcolor{comment}{!Edge slope of polynomial}
285   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n0,CS%degree+1)} :: ppoly\_r\_coefs \textcolor{comment}{!Coefficients of polynomial}
286   \textcolor{keywordtype}{integer} :: k
287   \textcolor{keywordtype}{real} :: eps, h0tot, h0err, h1tot, h1err
288   \textcolor{keywordtype}{real} :: u0tot, u0err, u0min, u0max, u1tot, u1err, u1min, u1max, uh\_err
289   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n1)} :: h1\textcolor{comment}{ !< Cell widths on target grid}
290   \textcolor{keywordtype}{real} :: hNeglect, hNeglect\_edge
291 
292   hneglect = 1.0e-30 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect)) hneglect = h\_neglect
293   hneglect\_edge = 1.0e-10 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(h\_neglect\_edge)) hneglect\_edge = h\_neglect\_edge
294 
295   \textcolor{keyword}{call }build\_reconstructions\_1d( cs, n0, h0, u0, ppoly\_r\_coefs, ppoly\_r\_e, ppoly\_r\_s, imethod,&
296                                   hneglect, hneglect\_edge )
297 
298   \textcolor{keywordflow}{if} (cs%check\_reconstruction) \textcolor{keyword}{call }check\_reconstructions\_1d(n0, h0, u0, cs%degree, &
299                                    cs%boundary\_extrapolation, ppoly\_r\_coefs, ppoly\_r\_e, ppoly\_r\_s)
300 
301   \textcolor{comment}{! This is a temporary step prior to switching to remapping\_core\_h()}
302   \textcolor{keywordflow}{do} k = 1, n1
303     \textcolor{keywordflow}{if} (k<=n0) \textcolor{keywordflow}{then}
304       h1(k) = max( 0., h0(k) + ( dx(k+1) - dx(k) ) )
305     \textcolor{keywordflow}{else}
306       h1(k) = max( 0., dx(k+1) - dx(k) )
307 \textcolor{keywordflow}{    endif}
308 \textcolor{keywordflow}{  enddo}
309   \textcolor{keyword}{call }remap\_via\_sub\_cells( n0, h0, u0, ppoly\_r\_e, ppoly\_r\_coefs, n1, h1, imethod, &
310                             cs%force\_bounds\_in\_subcell,u1, uh\_err )
311 \textcolor{comment}{! call remapByDeltaZ( n0, h0, u0, ppoly\_r\_E, ppoly\_r\_coefs, n1, dx, iMethod, u1, hNeglect )}
312 \textcolor{comment}{! call remapByProjection( n0, h0, u0, CS%ppoly\_r, n1, h1, iMethod, u1, hNeglect )}
313 
314   \textcolor{keywordflow}{if} (cs%check\_remapping) \textcolor{keywordflow}{then}
315     \textcolor{comment}{! Check errors and bounds}
316     \textcolor{keyword}{call }measure\_input\_bounds( n0, h0, u0, ppoly\_r\_e, h0tot, h0err, u0tot, u0err, u0min, u0max )
317     \textcolor{keyword}{call }measure\_output\_bounds( n1, h1, u1, h1tot, h1err, u1tot, u1err, u1min, u1max )
318     \textcolor{keywordflow}{if} (imethod<5) \textcolor{keywordflow}{then} \textcolor{comment}{! We except PQM until we've debugged it}
319     \textcolor{keywordflow}{if} ( (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err .and. abs(h1tot-h0tot)<h0err+h1err) &
320         .or. (u1min<u0min .or. u1max>u0max) ) \textcolor{keywordflow}{then}
321       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'iMethod = '},imethod
322       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H: h0tot='},h0tot,\textcolor{stringliteral}{'h1tot='},h1tot,\textcolor{stringliteral}{'dh='},h1tot-h0tot,\textcolor{stringliteral}{'h0err='},h0err,\textcolor{stringliteral}{'h1err='},h1err
323       \textcolor{keywordflow}{if} (abs(h1tot-h0tot)>h0err+h1err) &
324         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'H non-conservation difference='},h1tot-h0tot,\textcolor{stringliteral}{'allowed err='},h0err+h1err,\textcolor{stringliteral}{' <-----!'}
325       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'UH: u0tot='},u0tot,\textcolor{stringliteral}{'u1tot='},u1tot,\textcolor{stringliteral}{'duh='},u1tot-u0tot,\textcolor{stringliteral}{'u0err='},u0err,\textcolor{stringliteral}{'u1err='},u1err,\textcolor{stringliteral}{
      'uh\_err='},uh\_err
326       \textcolor{keywordflow}{if} (abs(u1tot-u0tot)>(u0err+u1err)+uh\_err) &
327         \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U non-conservation difference='},u1tot-u0tot,\textcolor{stringliteral}{'allowed err='},u0err+u1err+uh\_err,\textcolor{stringliteral}{'
       <-----!'}
328       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0min='},u0min,\textcolor{stringliteral}{'u1min='},u1min
329       \textcolor{keywordflow}{if} (u1min<u0min) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U minimum overshoot='},u1min-u0min,\textcolor{stringliteral}{' <-----!'}
330       \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U: u0max='},u0max,\textcolor{stringliteral}{'u1max='},u1max
331       \textcolor{keywordflow}{if} (u1max>u0max) \textcolor{keyword}{write}(0,*) \textcolor{stringliteral}{'U maximum overshoot='},u1max-u0max,\textcolor{stringliteral}{' <-----!'}
332       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,6a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'h0'},\textcolor{stringliteral}{'left edge'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'right edge'},\textcolor{stringliteral}{'h1'},\textcolor{stringliteral}{'u1'}
333       \textcolor{keywordflow}{do} k = 1, max(n0,n1)
334         \textcolor{keywordflow}{if} (k<=min(n0,n1)) \textcolor{keywordflow}{then}
335           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16)'}) k,h0(k),ppoly\_r\_e(k,1),u0(k),ppoly\_r\_e(k,2),h1(k),u1(k)
336         \textcolor{keywordflow}{elseif} (k>n0) \textcolor{keywordflow}{then}
337           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,96x,1p2e24.16)'}) k,h1(k),u1(k)
338         \textcolor{keywordflow}{else}
339           \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p4e24.16)'}) k,h0(k),ppoly\_r\_e(k,1),u0(k),ppoly\_r\_e(k,2)
340 \textcolor{keywordflow}{        endif}
341 \textcolor{keywordflow}{      enddo}
342       \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(a3,2a24)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'u0'},\textcolor{stringliteral}{'Polynomial coefficients'}
343       \textcolor{keywordflow}{do} k = 1, n0
344         \textcolor{keyword}{write}(0,\textcolor{stringliteral}{'(i3,1p6e24.16)'}) k,u0(k),ppoly\_r\_coefs(k,:)
345 \textcolor{keywordflow}{      enddo}
346       \textcolor{keyword}{call }mom\_error( fatal, \textcolor{stringliteral}{'MOM\_remapping, remapping\_core\_w: '}//&
347              \textcolor{stringliteral}{'Remapping result is inconsistent!'} )
348 \textcolor{keywordflow}{    endif}
349 \textcolor{keywordflow}{    endif} \textcolor{comment}{! method<5}
350 \textcolor{keywordflow}{  endif}
351 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a50e96a4a1083bb1fae3ca0130b6a2c11}\label{namespacemom__remapping_a50e96a4a1083bb1fae3ca0130b6a2c11}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!remapping\+\_\+set\+\_\+param@{remapping\+\_\+set\+\_\+param}}
\index{remapping\+\_\+set\+\_\+param@{remapping\+\_\+set\+\_\+param}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{remapping\+\_\+set\+\_\+param()}{remapping\_set\_param()}}
{\footnotesize\ttfamily subroutine, public mom\+\_\+remapping\+::remapping\+\_\+set\+\_\+param (\begin{DoxyParamCaption}\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(inout)}]{CS,  }\item[{character(len=$\ast$), intent(in), optional}]{remapping\+\_\+scheme,  }\item[{logical, intent(in), optional}]{boundary\+\_\+extrapolation,  }\item[{logical, intent(in), optional}]{check\+\_\+reconstruction,  }\item[{logical, intent(in), optional}]{check\+\_\+remapping,  }\item[{logical, intent(in), optional}]{force\+\_\+bounds\+\_\+in\+\_\+subcell,  }\item[{logical, intent(in), optional}]{answers\+\_\+2018 }\end{DoxyParamCaption})}



Set parameters within remapping object. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in,out}  & {\em cs} & Remapping control structure\\
\hline
\mbox{\tt in}  & {\em remapping\+\_\+scheme} & Remapping scheme to use\\
\hline
\mbox{\tt in}  & {\em boundary\+\_\+extrapolation} & Indicate to extrapolate in boundary cells\\
\hline
\mbox{\tt in}  & {\em check\+\_\+reconstruction} & Indicate to check reconstructions\\
\hline
\mbox{\tt in}  & {\em check\+\_\+remapping} & Indicate to check results of remapping\\
\hline
\mbox{\tt in}  & {\em force\+\_\+bounds\+\_\+in\+\_\+subcell} & Force subcells values to be bounded\\
\hline
\mbox{\tt in}  & {\em answers\+\_\+2018} & If true use older, less acccurate expressions. \\
\hline
\end{DoxyParams}


Definition at line 92 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
92   \textcolor{keywordtype}{type}(remapping\_CS),         \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Remapping control structure}
93   \textcolor{keywordtype}{character(len=*)}, \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)}    :: remapping\_scheme\textcolor{comment}{ !< Remapping scheme to use}
94   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: boundary\_extrapolation\textcolor{comment}{ !< Indicate to extrapolate in
       boundary cells}
95   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: check\_reconstruction\textcolor{comment}{ !< Indicate to check reconstructions}
96   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: check\_remapping\textcolor{comment}{ !< Indicate to check results of remapping}
97   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: force\_bounds\_in\_subcell\textcolor{comment}{ !< Force subcells values to be
       bounded}
98   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{optional},          \textcolor{keywordtype}{intent(in)}    :: answers\_2018\textcolor{comment}{ !< If true use older, less acccurate
       expressions.}
99 
100   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(remapping\_scheme)) \textcolor{keywordflow}{then}
101     \textcolor{keyword}{call }setreconstructiontype( remapping\_scheme, cs )
102 \textcolor{keywordflow}{  endif}
103   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(boundary\_extrapolation)) \textcolor{keywordflow}{then}
104     cs%boundary\_extrapolation = boundary\_extrapolation
105 \textcolor{keywordflow}{  endif}
106   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(check\_reconstruction)) \textcolor{keywordflow}{then}
107     cs%check\_reconstruction = check\_reconstruction
108 \textcolor{keywordflow}{  endif}
109   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(check\_remapping)) \textcolor{keywordflow}{then}
110     cs%check\_remapping = check\_remapping
111 \textcolor{keywordflow}{  endif}
112   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(force\_bounds\_in\_subcell)) \textcolor{keywordflow}{then}
113     cs%force\_bounds\_in\_subcell = force\_bounds\_in\_subcell
114 \textcolor{keywordflow}{  endif}
115   \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(answers\_2018)) \textcolor{keywordflow}{then}
116     cs%answers\_2018 = answers\_2018
117 \textcolor{keywordflow}{  endif}
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a5849f564453d5ed76fb4feffd41eca26}\label{namespacemom__remapping_a5849f564453d5ed76fb4feffd41eca26}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!remapping\+\_\+unit\+\_\+tests@{remapping\+\_\+unit\+\_\+tests}}
\index{remapping\+\_\+unit\+\_\+tests@{remapping\+\_\+unit\+\_\+tests}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{remapping\+\_\+unit\+\_\+tests()}{remapping\_unit\_tests()}}
{\footnotesize\ttfamily logical function, public mom\+\_\+remapping\+::remapping\+\_\+unit\+\_\+tests (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose }\end{DoxyParamCaption})}



Runs unit tests on remapping functions. Should only be called from a single/root thread Returns True if a test fails, otherwise False. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em verbose} & If true, write results to stdout \\
\hline
\end{DoxyParams}


Definition at line 1617 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1617   \textcolor{keywordtype}{logical}, \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}
1618   \textcolor{comment}{! Local variables}
1619   \textcolor{keywordtype}{integer}, \textcolor{keywordtype}{parameter} :: n0 = 4, n1 = 3, n2 = 6
1620   \textcolor{keywordtype}{real} :: h0(n0), x0(n0+1), u0(n0)
1621   \textcolor{keywordtype}{real} :: h1(n1), x1(n1+1), u1(n1), hn1(n1), dx1(n1+1)
1622   \textcolor{keywordtype}{real} :: h2(n2), x2(n2+1), u2(n2), hn2(n2), dx2(n2+1)
1623   \textcolor{keyword}{data} u0 /9., 3., -3., -9./   \textcolor{comment}{! Linear profile, 4 at surface to -4 at bottom}
1624   \textcolor{keyword}{data} h0 /4*0.75/ \textcolor{comment}{! 4 uniform layers with total depth of 3}
1625   \textcolor{keyword}{data} h1 /3*1./   \textcolor{comment}{! 3 uniform layers with total depth of 3}
1626   \textcolor{keyword}{data} h2 /6*0.5/  \textcolor{comment}{! 6 uniform layers with total depth of 3}
1627   \textcolor{keywordtype}{type}(remapping\_CS) :: CS\textcolor{comment}{ !< Remapping control structure}
1628   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{allocatable}, \textcolor{keywordtype}{dimension(:,:)} :: ppoly0\_E, ppoly0\_S, ppoly0\_coefs
1629   \textcolor{keywordtype}{logical} :: answers\_2018 \textcolor{comment}{!  If true use older, less acccurate expressions.}
1630   \textcolor{keywordtype}{integer} :: i
1631   \textcolor{keywordtype}{real} :: err, h\_neglect, h\_neglect\_edge
1632   \textcolor{keywordtype}{logical} :: thisTest, v
1633 
1634   v = verbose
1635   answers\_2018 = .false. \textcolor{comment}{! .true.}
1636   h\_neglect = hneglect\_dflt
1637   h\_neglect\_edge = hneglect\_dflt ; \textcolor{keywordflow}{if} (answers\_2018) h\_neglect\_edge = 1.0e-10
1638 
1639   \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'==== MOM\_remapping: remapping\_unit\_tests ================='}
1640   remapping\_unit\_tests = .false. \textcolor{comment}{! Normally return false}
1641 
1642   thistest = .false.
1643   \textcolor{keyword}{call }buildgridfromh(n0, h0, x0)
1644   \textcolor{keywordflow}{do} i=1,n0+1
1645     err=x0(i)-0.75*\textcolor{keywordtype}{real}(i-1)
1646     \textcolor{keywordflow}{if} (abs(err)>\textcolor{keywordtype}{real}(i-1)*epsilon(err)) thisTest = .true.
1647 \textcolor{keywordflow}{  enddo}
1648   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed buildGridFromH() 1'}
1649   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1650   \textcolor{keyword}{call }buildgridfromh(n1, h1, x1)
1651   \textcolor{keywordflow}{do} i=1,n1+1
1652     err=x1(i)-\textcolor{keywordtype}{real}(i-1)
1653     \textcolor{keywordflow}{if} (abs(err)>\textcolor{keywordtype}{real}(i-1)*epsilon(err)) thisTest = .true.
1654 \textcolor{keywordflow}{  enddo}
1655   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed buildGridFromH() 2'}
1656   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1657 
1658   thistest = .false.
1659   \textcolor{keyword}{call }initialize\_remapping(cs, \textcolor{stringliteral}{'PPM\_H4'}, answers\_2018=answers\_2018)
1660   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'h0 (test data)'}
1661   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n0,h0,x0,u0)
1662 
1663   \textcolor{keyword}{call }dzfromh1h2( n0, h0, n1, h1, dx1 )
1664   \textcolor{keyword}{call }remapping\_core\_w( cs, n0, h0, u0, n1, dx1, u1, h\_neglect, h\_neglect\_edge)
1665   \textcolor{keywordflow}{do} i=1,n1
1666     err=u1(i)-8.*(0.5*\textcolor{keywordtype}{real}(1+n1)-\textcolor{keywordtype}{real}(i))
1667     \textcolor{keywordflow}{if} (abs(err)>\textcolor{keywordtype}{real}(n1-1)*epsilon(err)) thisTest = .true.
1668 \textcolor{keywordflow}{  enddo}
1669   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'h1 (by projection)'}
1670   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n1,h1,x1,u1)
1671   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed remapping\_core\_w()'}
1672   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1673 
1674   thistest = .false.
1675   \textcolor{keyword}{allocate}(ppoly0\_e(n0,2))
1676   \textcolor{keyword}{allocate}(ppoly0\_s(n0,2))
1677   \textcolor{keyword}{allocate}(ppoly0\_coefs(n0,cs%degree+1))
1678 
1679   ppoly0\_e(:,:) = 0.0
1680   ppoly0\_s(:,:) = 0.0
1681   ppoly0\_coefs(:,:) = 0.0
1682 
1683   \textcolor{keyword}{call }edge\_values\_explicit\_h4( n0, h0, u0, ppoly0\_e, h\_neglect=1e-10, answers\_2018=answers\_2018 )
1684   \textcolor{keyword}{call }ppm\_reconstruction( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, h\_neglect, answers\_2018=answers\_2018 )
1685   \textcolor{keyword}{call }ppm\_boundary\_extrapolation( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, h\_neglect )
1686   u1(:) = 0.
1687   \textcolor{keyword}{call }remapbyprojection( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, &
1688                           n1, h1, integration\_ppm, u1, h\_neglect )
1689   \textcolor{keywordflow}{do} i=1,n1
1690     err=u1(i)-8.*(0.5*\textcolor{keywordtype}{real}(1+n1)-\textcolor{keywordtype}{real}(i))
1691     \textcolor{keywordflow}{if} (abs(err)>2.*epsilon(err)) thistest = .true.
1692 \textcolor{keywordflow}{  enddo}
1693   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed remapByProjection()'}
1694   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1695 
1696   thistest = .false.
1697   u1(:) = 0.
1698   \textcolor{keyword}{call }remapbydeltaz( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, &
1699                       n1, x1-x0(1:n1+1), &
1700                       integration\_ppm, u1, hn1, h\_neglect )
1701   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'h1 (by delta)'}
1702   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n1,h1,x1,u1)
1703   hn1=hn1-h1
1704   \textcolor{keywordflow}{do} i=1,n1
1705     err=u1(i)-8.*(0.5*\textcolor{keywordtype}{real}(1+n1)-\textcolor{keywordtype}{real}(i))
1706     \textcolor{keywordflow}{if} (abs(err)>2.*epsilon(err)) thistest = .true.
1707 \textcolor{keywordflow}{  enddo}
1708   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed remapByDeltaZ() 1'}
1709   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1710 
1711   thistest = .false.
1712   \textcolor{keyword}{call }buildgridfromh(n2, h2, x2)
1713   dx2(1:n0+1) = x2(1:n0+1) - x0
1714   dx2(n0+2:n2+1) = x2(n0+2:n2+1) - x0(n0+1)
1715   \textcolor{keyword}{call }remapbydeltaz( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, &
1716                       n2, dx2, &
1717                       integration\_ppm, u2, hn2, h\_neglect )
1718   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'h2'}
1719   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n2,h2,x2,u2)
1720   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'hn2'}
1721   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n2,hn2,x2,u2)
1722 
1723   \textcolor{keywordflow}{do} i=1,n2
1724     err=u2(i)-8./2.*(0.5*\textcolor{keywordtype}{real}(1+n2)-\textcolor{keywordtype}{real}(i))
1725     \textcolor{keywordflow}{if} (abs(err)>2.*epsilon(err)) thistest = .true.
1726 \textcolor{keywordflow}{  enddo}
1727   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed remapByDeltaZ() 2'}
1728   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1729 
1730   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'Via sub-cells'}
1731   thistest = .false.
1732   \textcolor{keyword}{call }remap\_via\_sub\_cells( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, &
1733                             n2, h2, integration\_ppm, .false., u2, err )
1734   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(n2,h2,x2,u2)
1735 
1736   \textcolor{keywordflow}{do} i=1,n2
1737     err=u2(i)-8./2.*(0.5*\textcolor{keywordtype}{real}(1+n2)-\textcolor{keywordtype}{real}(i))
1738     \textcolor{keywordflow}{if} (abs(err)>2.*epsilon(err)) thistest = .true.
1739 \textcolor{keywordflow}{  enddo}
1740   \textcolor{keywordflow}{if} (thistest) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'remapping\_unit\_tests: Failed remap\_via\_sub\_cells() 2'}
1741   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1742 
1743   \textcolor{keyword}{call }remap\_via\_sub\_cells( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, &
1744                             6, (/.125,.125,.125,.125,.125,.125/), integration\_ppm, .false., u2, err )
1745   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(6,h2,x2,u2)
1746 
1747   \textcolor{keyword}{call }remap\_via\_sub\_cells( n0, h0, u0, ppoly0\_e, ppoly0\_coefs, &
1748                             3, (/2.25,1.5,1./), integration\_ppm, .false., u2, err )
1749   \textcolor{keywordflow}{if} (verbose) \textcolor{keyword}{call }dumpgrid(3,h2,x2,u2)
1750 
1751   \textcolor{keywordflow}{if} (.not. remapping\_unit\_tests) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'Pass'}
1752 
1753   \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'===== MOM\_remapping: new remapping\_unit\_tests =================='}
1754 
1755   \textcolor{keyword}{deallocate}(ppoly0\_e, ppoly0\_s, ppoly0\_coefs)
1756   \textcolor{keyword}{allocate}(ppoly0\_coefs(5,6))
1757   \textcolor{keyword}{allocate}(ppoly0\_e(5,2))
1758   \textcolor{keyword}{allocate}(ppoly0\_s(5,2))
1759 
1760   \textcolor{keyword}{call }pcm\_reconstruction(3, (/1.,2.,4./), ppoly0\_e(1:3,:), &
1761                           ppoly0\_coefs(1:3,:) )
1762   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1763     test\_answer(v, 3, ppoly0\_e(:,1), (/1.,2.,4./), \textcolor{stringliteral}{'PCM: left edges'})
1764   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1765     test\_answer(v, 3, ppoly0\_e(:,2), (/1.,2.,4./), \textcolor{stringliteral}{'PCM: right edges'})
1766   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1767     test\_answer(v, 3, ppoly0\_coefs(:,1), (/1.,2.,4./), \textcolor{stringliteral}{'PCM: P0'})
1768 
1769   \textcolor{keyword}{call }plm\_reconstruction(3, (/1.,1.,1./), (/1.,3.,5./), ppoly0\_e(1:3,:), &
1770                           ppoly0\_coefs(1:3,:), h\_neglect )
1771   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1772     test\_answer(v, 3, ppoly0\_e(:,1), (/1.,2.,5./), \textcolor{stringliteral}{'Unlim PLM: left edges'})
1773   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1774     test\_answer(v, 3, ppoly0\_e(:,2), (/1.,4.,5./), \textcolor{stringliteral}{'Unlim PLM: right edges'})
1775   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1776     test\_answer(v, 3, ppoly0\_coefs(:,1), (/1.,2.,5./), \textcolor{stringliteral}{'Unlim PLM: P0'})
1777   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1778     test\_answer(v, 3, ppoly0\_coefs(:,2), (/0.,2.,0./), \textcolor{stringliteral}{'Unlim PLM: P1'})
1779 
1780   \textcolor{keyword}{call }plm\_reconstruction(3, (/1.,1.,1./), (/1.,2.,7./), ppoly0\_e(1:3,:), &
1781                           ppoly0\_coefs(1:3,:), h\_neglect )
1782   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1783     test\_answer(v, 3, ppoly0\_e(:,1), (/1.,1.,7./), \textcolor{stringliteral}{'Left lim PLM: left edges'})
1784   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1785     test\_answer(v, 3, ppoly0\_e(:,2), (/1.,3.,7./), \textcolor{stringliteral}{'Left lim PLM: right edges'})
1786   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1787     test\_answer(v, 3, ppoly0\_coefs(:,1), (/1.,1.,7./), \textcolor{stringliteral}{'Left lim PLM: P0'})
1788   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1789     test\_answer(v, 3, ppoly0\_coefs(:,2), (/0.,2.,0./), \textcolor{stringliteral}{'Left lim PLM: P1'})
1790 
1791   \textcolor{keyword}{call }plm\_reconstruction(3, (/1.,1.,1./), (/1.,6.,7./), ppoly0\_e(1:3,:), &
1792                           ppoly0\_coefs(1:3,:), h\_neglect )
1793   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1794     test\_answer(v, 3, ppoly0\_e(:,1), (/1.,5.,7./), \textcolor{stringliteral}{'Right lim PLM: left edges'})
1795   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1796     test\_answer(v, 3, ppoly0\_e(:,2), (/1.,7.,7./), \textcolor{stringliteral}{'Right lim PLM: right edges'})
1797   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1798     test\_answer(v, 3, ppoly0\_coefs(:,1), (/1.,5.,7./), \textcolor{stringliteral}{'Right lim PLM: P0'})
1799   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1800     test\_answer(v, 3, ppoly0\_coefs(:,2), (/0.,2.,0./), \textcolor{stringliteral}{'Right lim PLM: P1'})
1801 
1802   \textcolor{keyword}{call }plm\_reconstruction(3, (/1.,2.,3./), (/1.,4.,9./), ppoly0\_e(1:3,:), &
1803                           ppoly0\_coefs(1:3,:), h\_neglect )
1804   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1805     test\_answer(v, 3, ppoly0\_e(:,1), (/1.,2.,9./), \textcolor{stringliteral}{'Non-uniform line PLM: left edges'})
1806   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1807     test\_answer(v, 3, ppoly0\_e(:,2), (/1.,6.,9./), \textcolor{stringliteral}{'Non-uniform line PLM: right edges'})
1808   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1809     test\_answer(v, 3, ppoly0\_coefs(:,1), (/1.,2.,9./), \textcolor{stringliteral}{'Non-uniform line PLM: P0'})
1810   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1811     test\_answer(v, 3, ppoly0\_coefs(:,2), (/0.,4.,0./), \textcolor{stringliteral}{'Non-uniform line PLM: P1'})
1812 
1813   \textcolor{keyword}{call }edge\_values\_explicit\_h4( 5, (/1.,1.,1.,1.,1./), (/1.,3.,5.,7.,9./), ppoly0\_e, &
1814                                 h\_neglect=1e-10, answers\_2018=answers\_2018 )
1815   \textcolor{comment}{! The next two tests currently fail due to roundoff, but pass when given a reasonable tolerance.}
1816   thistest = test\_answer(v, 5, ppoly0\_e(:,1), (/0.,2.,4.,6.,8./), \textcolor{stringliteral}{'Line H4: left edges'}, tol=8.0e-15)
1817   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1818   thistest = test\_answer(v, 5, ppoly0\_e(:,2), (/2.,4.,6.,8.,10./), \textcolor{stringliteral}{'Line H4: right edges'}, tol=1.0e-14)
1819   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1820   ppoly0\_e(:,1) = (/0.,2.,4.,6.,8./)
1821   ppoly0\_e(:,2) = (/2.,4.,6.,8.,10./)
1822   \textcolor{keyword}{call }ppm\_reconstruction(5, (/1.,1.,1.,1.,1./), (/1.,3.,5.,7.,9./), ppoly0\_e(1:5,:), &
1823                               ppoly0\_coefs(1:5,:), h\_neglect, answers\_2018=answers\_2018 )
1824   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1825     test\_answer(v, 5, ppoly0\_coefs(:,1), (/1.,2.,4.,6.,9./), \textcolor{stringliteral}{'Line PPM: P0'})
1826   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1827     test\_answer(v, 5, ppoly0\_coefs(:,2), (/0.,2.,2.,2.,0./), \textcolor{stringliteral}{'Line PPM: P1'})
1828   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1829     test\_answer(v, 5, ppoly0\_coefs(:,3), (/0.,0.,0.,0.,0./), \textcolor{stringliteral}{'Line PPM: P2'})
1830 
1831   \textcolor{keyword}{call }edge\_values\_explicit\_h4( 5, (/1.,1.,1.,1.,1./), (/1.,1.,7.,19.,37./), ppoly0\_e, &
1832                                 h\_neglect=1e-10, answers\_2018=answers\_2018 )
1833   \textcolor{comment}{! The next two tests are now passing when answers\_2018 = .false., but otherwise only work to roundoff.}
1834   thistest = test\_answer(v, 5, ppoly0\_e(:,1), (/3.,0.,3.,12.,27./), \textcolor{stringliteral}{'Parabola H4: left edges'}, tol=2.7e-14)
1835   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1836   thistest = test\_answer(v, 5, ppoly0\_e(:,2), (/0.,3.,12.,27.,48./), \textcolor{stringliteral}{'Parabola H4: right edges'}, tol=4.8e-1
      4)
1837   remapping\_unit\_tests = remapping\_unit\_tests .or. thistest
1838   ppoly0\_e(:,1) = (/0.,0.,3.,12.,27./)
1839   ppoly0\_e(:,2) = (/0.,3.,12.,27.,48./)
1840   \textcolor{keyword}{call }ppm\_reconstruction(5, (/1.,1.,1.,1.,1./), (/0.,1.,7.,19.,37./), ppoly0\_e(1:5,:), &
1841                           ppoly0\_coefs(1:5,:), h\_neglect, answers\_2018=answers\_2018 )
1842   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1843     test\_answer(v, 5, ppoly0\_e(:,1), (/0.,0.,3.,12.,37./), \textcolor{stringliteral}{'Parabola PPM: left edges'})
1844   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1845     test\_answer(v, 5, ppoly0\_e(:,2), (/0.,3.,12.,27.,37./), \textcolor{stringliteral}{'Parabola PPM: right edges'})
1846   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1847     test\_answer(v, 5, ppoly0\_coefs(:,1), (/0.,0.,3.,12.,37./), \textcolor{stringliteral}{'Parabola PPM: P0'})
1848   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1849     test\_answer(v, 5, ppoly0\_coefs(:,2), (/0.,0.,6.,12.,0./), \textcolor{stringliteral}{'Parabola PPM: P1'})
1850   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1851     test\_answer(v, 5, ppoly0\_coefs(:,3), (/0.,3.,3.,3.,0./), \textcolor{stringliteral}{'Parabola PPM: P2'})
1852 
1853   ppoly0\_e(:,1) = (/0.,0.,6.,10.,15./)
1854   ppoly0\_e(:,2) = (/0.,6.,12.,17.,15./)
1855   \textcolor{keyword}{call }ppm\_reconstruction(5, (/1.,1.,1.,1.,1./), (/0.,5.,7.,16.,15./), ppoly0\_e(1:5,:), &
1856                           ppoly0\_coefs(1:5,:), h\_neglect, answers\_2018=answers\_2018 )
1857   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1858     test\_answer(v, 5, ppoly0\_e(:,1), (/0.,3.,6.,16.,15./), \textcolor{stringliteral}{'Limits PPM: left edges'})
1859   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1860     test\_answer(v, 5, ppoly0\_e(:,2), (/0.,6.,9.,16.,15./), \textcolor{stringliteral}{'Limits PPM: right edges'})
1861   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1862     test\_answer(v, 5, ppoly0\_coefs(:,1), (/0.,3.,6.,16.,15./), \textcolor{stringliteral}{'Limits PPM: P0'})
1863   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1864     test\_answer(v, 5, ppoly0\_coefs(:,2), (/0.,6.,0.,0.,0./), \textcolor{stringliteral}{'Limits PPM: P1'})
1865   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1866     test\_answer(v, 5, ppoly0\_coefs(:,3), (/0.,-3.,3.,0.,0./), \textcolor{stringliteral}{'Limits PPM: P2'})
1867 
1868   \textcolor{keyword}{call }plm\_reconstruction(4, (/0.,1.,1.,0./), (/5.,4.,2.,1./), ppoly0\_e(1:4,:), &
1869                           ppoly0\_coefs(1:4,:), h\_neglect )
1870   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1871     test\_answer(v, 4, ppoly0\_e(1:4,1), (/5.,5.,3.,1./), \textcolor{stringliteral}{'PPM: left edges h=0110'})
1872   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1873     test\_answer(v, 4, ppoly0\_e(1:4,2), (/5.,3.,1.,1./), \textcolor{stringliteral}{'PPM: right edges h=0110'})
1874   \textcolor{keyword}{call }remap\_via\_sub\_cells( 4, (/0.,1.,1.,0./), (/5.,4.,2.,1./), ppoly0\_e(1:4,:), &
1875                             ppoly0\_coefs(1:4,:), &
1876                             2, (/1.,1./), integration\_plm, .false., u2, err )
1877   remapping\_unit\_tests = remapping\_unit\_tests .or. &
1878     test\_answer(v, 2, u2, (/4.,2./), \textcolor{stringliteral}{'PLM: remapped  h=0110->h=11'})
1879 
1880   \textcolor{keyword}{deallocate}(ppoly0\_e, ppoly0\_s, ppoly0\_coefs)
1881 
1882   \textcolor{keywordflow}{if} (.not. remapping\_unit\_tests) \textcolor{keyword}{write}(*,*) \textcolor{stringliteral}{'Pass'}
1883 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a41a89ac62578250500b7a450d5fdfae7}\label{namespacemom__remapping_a41a89ac62578250500b7a450d5fdfae7}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!setreconstructiontype@{setreconstructiontype}}
\index{setreconstructiontype@{setreconstructiontype}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{setreconstructiontype()}{setreconstructiontype()}}
{\footnotesize\ttfamily subroutine mom\+\_\+remapping\+::setreconstructiontype (\begin{DoxyParamCaption}\item[{character(len=$\ast$), intent(in)}]{string,  }\item[{type(\mbox{\hyperlink{structmom__remapping_1_1remapping__cs}{remapping\+\_\+cs}}), intent(inout)}]{CS }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Changes the method of reconstruction Use this routine to parse a string parameter specifying the reconstruction and re-\/allocates work arrays appropriately. It is called from initialize\+\_\+remapping but can be called from an external module too. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em string} & String to parse for method\\
\hline
\mbox{\tt in,out}  & {\em cs} & Remapping control structure \\
\hline
\end{DoxyParams}


Definition at line 1572 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1572   \textcolor{keywordtype}{character(len=*)},   \textcolor{keywordtype}{intent(in)}    :: string\textcolor{comment}{ !< String to parse for method}
1573   \textcolor{keywordtype}{type}(remapping\_CS), \textcolor{keywordtype}{intent(inout)} :: CS\textcolor{comment}{ !< Remapping control structure}
1574   \textcolor{comment}{! Local variables}
1575   \textcolor{keywordtype}{integer} :: degree
1576   degree = -99
1577   \textcolor{keywordflow}{select case} ( uppercase(trim(string)) )
1578     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PCM"})
1579       cs%remapping\_scheme = remapping\_pcm
1580       degree = 0
1581     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PLM"})
1582       cs%remapping\_scheme = remapping\_plm
1583       degree = 1
1584     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PPM\_H4"})
1585       cs%remapping\_scheme = remapping\_ppm\_h4
1586       degree = 2
1587     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PPM\_IH4"})
1588       cs%remapping\_scheme = remapping\_ppm\_ih4
1589       degree = 2
1590     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PQM\_IH4IH3"})
1591       cs%remapping\_scheme = remapping\_pqm\_ih4ih3
1592       degree = 4
1593     \textcolor{keywordflow}{case} (\textcolor{stringliteral}{"PQM\_IH6IH5"})
1594       cs%remapping\_scheme = remapping\_pqm\_ih6ih5
1595       degree = 4
1596 \textcolor{keywordflow}{    case default}
1597       \textcolor{keyword}{call }mom\_error(fatal, \textcolor{stringliteral}{"setReconstructionType: "}//&
1598        \textcolor{stringliteral}{"Unrecognized choice for REMAPPING\_SCHEME ("}//trim(string)//\textcolor{stringliteral}{")."})
1599 \textcolor{keywordflow}{  end select}
1600 
1601   cs%degree = degree
1602 
\end{DoxyCode}
\mbox{\Hypertarget{namespacemom__remapping_a3235506c107c81b116cec92952dd8cbb}\label{namespacemom__remapping_a3235506c107c81b116cec92952dd8cbb}} 
\index{mom\+\_\+remapping@{mom\+\_\+remapping}!test\+\_\+answer@{test\+\_\+answer}}
\index{test\+\_\+answer@{test\+\_\+answer}!mom\+\_\+remapping@{mom\+\_\+remapping}}
\subsubsection{\texorpdfstring{test\+\_\+answer()}{test\_answer()}}
{\footnotesize\ttfamily logical function mom\+\_\+remapping\+::test\+\_\+answer (\begin{DoxyParamCaption}\item[{logical, intent(in)}]{verbose,  }\item[{integer, intent(in)}]{n,  }\item[{real, dimension(n), intent(in)}]{u,  }\item[{real, dimension(n), intent(in)}]{u\+\_\+true,  }\item[{character(len=$\ast$), intent(in)}]{label,  }\item[{real, intent(in), optional}]{tol }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [private]}}



Returns true if any cell of u and u\+\_\+true are not identical. Returns false otherwise. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\tt in}  & {\em verbose} & If true, write results to stdout\\
\hline
\mbox{\tt in}  & {\em n} & Number of cells in u\\
\hline
\mbox{\tt in}  & {\em u} & Values to test\\
\hline
\mbox{\tt in}  & {\em u\+\_\+true} & Values to test against (correct answer)\\
\hline
\mbox{\tt in}  & {\em label} & Message\\
\hline
\mbox{\tt in}  & {\em tol} & The tolerance for differences between u and u\+\_\+true \\
\hline
\end{DoxyParams}


Definition at line 1888 of file M\+O\+M\+\_\+remapping.\+F90.


\begin{DoxyCode}
1888   \textcolor{keywordtype}{logical},            \textcolor{keywordtype}{intent(in)} :: verbose\textcolor{comment}{ !< If true, write results to stdout}
1889   \textcolor{keywordtype}{integer},            \textcolor{keywordtype}{intent(in)} :: n\textcolor{comment}{      !< Number of cells in u}
1890   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n)}, \textcolor{keywordtype}{intent(in)} :: u\textcolor{comment}{      !< Values to test}
1891   \textcolor{keywordtype}{real}, \textcolor{keywordtype}{dimension(n)}, \textcolor{keywordtype}{intent(in)} :: u\_true\textcolor{comment}{ !< Values to test against (correct answer)}
1892   \textcolor{keywordtype}{character(len=*)},   \textcolor{keywordtype}{intent(in)} :: label\textcolor{comment}{  !< Message}
1893   \textcolor{keywordtype}{real},     \textcolor{keywordtype}{optional}, \textcolor{keywordtype}{intent(in)} :: tol\textcolor{comment}{    !< The tolerance for differences between u and u\_true}
1894   \textcolor{comment}{! Local variables}
1895   \textcolor{keywordtype}{real} :: tolerance \textcolor{comment}{! The tolerance for differences between u and u\_true}
1896   \textcolor{keywordtype}{integer} :: k
1897 
1898   tolerance = 0.0 ; \textcolor{keywordflow}{if} (\textcolor{keyword}{present}(tol)) tolerance = tol
1899   test\_answer = .false.
1900   \textcolor{keywordflow}{do} k = 1, n
1901     \textcolor{keywordflow}{if} (abs(u(k) - u\_true(k)) > tolerance) test\_answer = .true.
1902 \textcolor{keywordflow}{  enddo}
1903   \textcolor{keywordflow}{if} (test\_answer .or. verbose) \textcolor{keywordflow}{then}
1904     \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(a4,2a24,x,a)'}) \textcolor{stringliteral}{'k'},\textcolor{stringliteral}{'Calculated value'},\textcolor{stringliteral}{'Correct value'},label
1905     \textcolor{keywordflow}{do} k = 1, n
1906       \textcolor{keywordflow}{if} (abs(u(k) - u\_true(k)) > tolerance) \textcolor{keywordflow}{then}
1907         \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(i4,1p2e24.16,a,1pe24.16,a)'}) k,u(k),u\_true(k),\textcolor{stringliteral}{' err='},u(k)-u\_true(k),\textcolor{stringliteral}{' < wrong'}
1908         \textcolor{keyword}{write}(stderr,\textcolor{stringliteral}{'(i4,1p2e24.16,a,1pe24.16,a)'}) k,u(k),u\_true(k),\textcolor{stringliteral}{' err='},u(k)-u\_true(k),\textcolor{stringliteral}{' < wrong'}
1909       \textcolor{keywordflow}{else}
1910         \textcolor{keyword}{write}(stdout,\textcolor{stringliteral}{'(i4,1p2e24.16)'}) k,u(k),u\_true(k)
1911 \textcolor{keywordflow}{      endif}
1912 \textcolor{keywordflow}{    enddo}
1913 \textcolor{keywordflow}{  endif}
1914 
\end{DoxyCode}
