One-sided 4th-order polynomial fit of the cell averages u to the
four boundary layers dz (thicknesses, must be positive), returning
the four coefficients csys of the fit (White & Adcroft 2008,
appendix; roundoff-safe closed form). csys(1) is the edge VALUE at
the boundary interface and csys(2) is the edge SLOPE there.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=wp), | intent(in) | :: | dz(4) |
Thicknesses of the 4 boundary layers, starting at the edge |
||
| real(kind=wp), | intent(in) | :: | u(4) |
Cell averages of the 4 boundary layers, starting at the edge |
||
| real(kind=wp), | intent(out) | :: | csys(4) |
Coefficients of the 4th-order fit polynomial in z |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| real(kind=wp), | private | :: | du1 | ||||
| real(kind=wp), | private | :: | du2 | ||||
| real(kind=wp), | private | :: | du3 | ||||
| real(kind=wp), | private | :: | h1 | ||||
| real(kind=wp), | private | :: | h12 | ||||
| real(kind=wp), | private | :: | h123 | ||||
| real(kind=wp), | private | :: | h1234 | ||||
| real(kind=wp), | private | :: | h2 | ||||
| real(kind=wp), | private | :: | h23 | ||||
| real(kind=wp), | private | :: | h234 | ||||
| real(kind=wp), | private | :: | h3 | ||||
| real(kind=wp), | private | :: | h34 | ||||
| real(kind=wp), | private | :: | h4 | ||||
| real(kind=wp), | private | :: | i_denb3 | ||||
| real(kind=wp), | private | :: | i_denom | ||||
| real(kind=wp), | private | :: | i_h12 | ||||
| real(kind=wp), | private | :: | i_h123 | ||||
| real(kind=wp), | private | :: | i_h1234 | ||||
| real(kind=wp), | private | :: | i_h23 | ||||
| real(kind=wp), | private | :: | i_h234 | ||||
| real(kind=wp), | private | :: | i_h34 | ||||
| real(kind=wp), | private | :: | wt(3,4) |
pure subroutine pqm_end_value_h4(dz, u, csys) !$acc routine seq !! One-sided 4th-order polynomial fit of the cell averages `u` to the !! four boundary layers `dz` (thicknesses, must be positive), returning !! the four coefficients `csys` of the fit (White & Adcroft 2008, !! appendix; roundoff-safe closed form). `csys(1)` is the edge VALUE at !! the boundary interface and `csys(2)` is the edge SLOPE there. real(wp), intent(in) :: dz(4) !! Thicknesses of the 4 boundary layers, starting at the edge real(wp), intent(in) :: u(4) !! Cell averages of the 4 boundary layers, starting at the edge real(wp), intent(out) :: csys(4) !! Coefficients of the 4th-order fit polynomial in z real(wp) :: wt(3, 4) real(wp) :: h1, h2, h3, h4 real(wp) :: h12, h23, h34, h123, h234, h1234 real(wp) :: i_h12, i_h23, i_h34, i_h123, i_h234, i_h1234 real(wp) :: i_denom, i_denb3 real(wp) :: du1, du2, du3 h1 = dz(1) h2 = dz(2) h3 = dz(3) h4 = dz(4) ! Bound the thickness ratios so property differences at the level of ! roundoff are not amplified to order one. if ((h2 + h3) < PQM_MIN_FRAC*h1) h3 = PQM_MIN_FRAC*h1 - h2 if ((h3 + h4) < PQM_MIN_FRAC*h1) h4 = PQM_MIN_FRAC*h1 - h3 h12 = h1 + h2 h23 = h2 + h3 h34 = h3 + h4 h123 = h12 + h3 h234 = h2 + h34 h1234 = h12 + h34 ! Three reciprocals from a single division each, for efficiency. i_denb3 = 1.0_wp/(h123*h12*h23) i_h12 = (h123*h23)*i_denb3 i_h23 = (h12*h123)*i_denb3 i_h123 = (h12*h23)*i_denb3 i_denom = 1.0_wp/(h1234*(h234*h34)) i_h34 = (h1234*h234)*i_denom i_h234 = (h1234*h34)*i_denom i_h1234 = (h234*h34)*i_denom wt(1, 1) = -h1*(i_h1234 + i_h123 + i_h12) wt(2, 1) = h1*h12*(i_h234*i_h1234 + i_h23*(i_h234 + i_h123)) wt(3, 1) = -h1*h12*h123*i_denom wt(1, 2) = 2.0_wp*(i_h12*(1.0_wp + (h1 + h12)*(i_h1234 + i_h123)) + h1*i_h1234*i_h123) wt(2, 2) = -2.0_wp*((h1*h12*i_h1234)*(i_h23*(i_h234 + i_h123)) + & (h1 + h12)*(i_h1234*i_h234 + i_h23*(i_h234 + i_h123))) wt(3, 2) = 2.0_wp*((h1 + h12)*h123 + h1*h12)*i_denom wt(1, 3) = -3.0_wp*i_h12*i_h123*(1.0_wp + i_h1234*((h1 + h12) + h123)) wt(2, 3) = 3.0_wp*i_h23*(i_h123 + i_h1234*((h1 + h12) + h123)*(i_h123 + i_h234)) wt(3, 3) = -3.0_wp*((h1 + h12) + h123)*i_denom wt(1, 4) = 4.0_wp*i_h1234*i_h123*i_h12 wt(2, 4) = -4.0_wp*i_h1234*(i_h23*(i_h123 + i_h234)) wt(3, 4) = 4.0_wp*i_denom du1 = u(2) - u(1) du2 = u(3) - u(2) du3 = u(4) - u(3) csys(1) = ((u(1) + (wt(1, 1)*du1)) + (wt(2, 1)*du2)) + (wt(3, 1)*du3) csys(2) = ((wt(1, 2)*du1) + (wt(2, 2)*du2)) + (wt(3, 2)*du3) csys(3) = ((wt(1, 3)*du1) + (wt(2, 3)*du2)) + (wt(3, 3)*du3) csys(4) = ((wt(1, 4)*du1) + (wt(2, 4)*du2)) + (wt(3, 4)*du3) end subroutine pqm_end_value_h4