Recon1d_PLM_WLS module reference

Piecewise Linear Method using Weighted Conservative Least Squares 1D reconstruction

Data Types

PLM_WLS

PLM reconstruction using Weighted Least Squares constrained to conserve for central cell

Functions/Subroutines

init

Initialize a 1D PLM reconstruction for n cells

reconstruct

Calculate a 1D PLM_WLS reconstruction based on h(:) and u(:)

f

Value of PLM_WLS reconstruction at a point in cell k [A]

dfdx

Derivative of PLM_WLS reconstruction at a point in cell k [A]

average

Average between xa and xb for cell k of a 1D PLM reconstruction [A]

destroy

Deallocate the PLM reconstruction

check_reconstruction

Checks the PLM_WLS reconstruction for consistency

LS_error

Returns local least squares error for a particular cell

unit_tests

Runs PLM_WLS reconstruction unit tests and returns True for any fails, False otherwise

Detailed Description

This implementation of PLM fits the slope using least squares, but retains conservation for the central cell by passing through the central value. Cell-wise reconstructions are NOT limited by neighbours. Thus, this reconstruction does not yield monotonic profiles needed for the general remapping problem.

The algorithm solves the least squares problem of fitting a straight line through the neighboring data. The line is constained to pass through the center cell, \((x_{k}, y_{k})\), so that the construction is conservative. The more general function \(f(x) = a_{k} + b_{k} x\) would not conserve for arbitrary data.

The unknown parameter \(b_{k}\) in the line

\begin{equation*} f(x) = y_{k} + b_{k} ( x - x_{k} ) / h_{k} \end{equation*}

is fit to neighbors \(x_{k-1}, y_{k-1}\) and \(x_{k+1}, y_{k+1}\).

Denoting \(y'_{k+j} = y_{k+j} - y_{k}\) and \(x'_{k+j} = x_{k+j} - x_{k}\) the local error is

\begin{equation*} \begin{aligned} e_{k+j} &= b_k \frac{ x_{k+j} - x_{k} }{ h_{k} } + y_{k} - y_{k+j} \\ &= b_k \frac{ x'_{k+j} }{ h_{k} } - y'_{k+j} \;\; . \end{aligned} \end{equation*}

We use volume weighting in the loss

\begin{equation*} G(b) = h_{k-1} e_{k-1}^2 + h_{k+1} e_{k+1}^2 \;\; . \end{equation*}

When solving for \(b_k\), we solve \(dG/db = 0\) where

\begin{equation*} \begin{aligned} dG/db &= 2 h_{k-1} e_{k-1} \frac{ de_{k-1} }{db} + 2 h_{k+1} e_{k+1} \frac{ de_{k+1} }{db} \\ &= 2 h_{k-1} ( b_k \frac{ x'_{k-1} }{ h_{k} } - \frac{ y'_{k-1} ) x'_{k-1} }{ h_{k} } + 2 h_{k+1} ( b_k \frac{ x'_{k+1} }{ h_{k} } - \frac{ y'_{k+1} ) x'_{k+1} }{ h_{k} } \\ &= 4 b_k \frac{ < h x'^2 > }{ h_{k}^2 } - 4 \frac{ < h x' y' > }{ h_{k} } \end{aligned} \end{equation*}

and where \(< a > = \frac{1}{2} ( a_{k-1} + a_{k+1} )\). Thus

\begin{equation*} b_k = \frac{ h_{k} < h x' y' > }{ < h x'^2 > } \;\; . \end{equation*}

When evaluating the loss, \(G\), some rearrangement is necessary to reduce truncation errors. Since

\begin{equation*} \begin{aligned} e_{k+j}^2 &= \left( b \frac{ x'_{k+j} }{ h_{k} } - y'_{k+j} \right)^2 \\ &= b^2 \frac{ {x'}_{k+j}^2 }{ h_{k}^2 } - 2 b \frac{ x'_{k+j} y'_{k+j} }{ h_{k} } + {y'}_{k+j}^2 \end{aligned} \end{equation*}

then

\begin{equation*} \begin{aligned} G(b) &= 2 < h e^2 > \\ &= 2 b^2 \frac{ < h {x'}^2 > }{ h_{k}^2 } - 4 b \frac{ < h x' y' > }{ h_{k} } + 2 < h {y'}^2 > \;\; . \end{aligned} \end{equation*}

If we denote the value of b that yields the minimum value as \(b^*\) then

\begin{equation*} G(b^*) = 2 < h {y'}^2 > - \frac{ 2 < h x' y' >^2 }{ < h {x'}^2 > } \;\; . \end{equation*}

Let

\begin{equation*} \begin{aligned} G''(b) &= G(b) - G(b^*) \\ &= 2 b^2 \frac{ < h {x'}^2 > }{ h_{k}^2 } - 4 b \frac{ < h x' y' > }{ h_{k} } + 2 \frac{ < h x' y' >^2 }{ < h {x'}^2 > } \\ &= 2 \frac{ \left( b < h {x'}^2 > - h_{k} < h x' y' > \right)^2 }{ h_{k} < h {x'}^2 > } \;\; . \end{aligned} \end{equation*}

Minimizing \(G''(b)\) is equivalent to minimizing \(G(b)\) for the same data. \(G''(b^*)=0\) so evaluation with the last form, in the vicinity of \(b^*\), avoids large cancelling terms.

Type Documentation

type, extends(Recon1d) :: PLM_WLS

PLM reconstruction using Weighted Least Squares constrained to conserve for central cell

The source for the methods ultimately used by this class are:

  • init() *locally defined

  • reconstruct() *locally defined

  • average() *locally defined

  • f() *locally defined

  • dfdx() *locally defined

  • x() -> recon1d_type.x()

  • check_reconstruction() *locally defined

  • unit_tests() *locally defined

  • destroy() *locally defined

  • remap_to_sub_grid() -> recon1d_type.remap_to_sub_grid()

  • init_parent() -> init()

  • reconstruct_parent() -> reconstruct()

Parameters
  • ul

    Left edge value [A]

  • ur

    Right edge value [A]

  • slp

    Difference across cell, ur - ul [A]. This is redundant with ul and ur and not used in any evaluations, but is needed for testing.

Functions/Subroutine Documentation

subroutine init(this, n, h_neglect, check)

Initialize a 1D PLM reconstruction for n cells

Parameters
  • this [out]

    This reconstruction

  • n [in]

    Number of cells in this column

  • h_neglect [in]

    A negligibly small width used in cell reconstructions [H]

  • check [in]

    If true, enable some consistency checking

subroutine reconstruct(this, h, u)

Calculate a 1D PLM_WLS reconstruction based on h(:) and u(:)

Parameters
  • this [inout]

    This reconstruction

  • h [in]

    Grid spacing (thickness) [typically H]

  • u [in]

    Cell mean values [A]

real function f(this, k, x)

Value of PLM_WLS reconstruction at a point in cell k [A]

Parameters
  • this [in]

    This reconstruction

  • k [in]

    Cell number

  • x [in]

    Non-dimensional position within element [nondim]

real function dfdx(this, k, x)

Derivative of PLM_WLS reconstruction at a point in cell k [A]

Parameters
  • this [in]

    This reconstruction

  • k [in]

    Cell number

  • x [in]

    Non-dimensional position within element [nondim]

real function average(this, k, xa, xb)

Average between xa and xb for cell k of a 1D PLM reconstruction [A]

Parameters
  • this [in]

    This reconstruction

  • k [in]

    Cell number

  • xa [in]

    Start of averaging interval on element (0 to 1)

  • xb [in]

    End of averaging interval on element (0 to 1)

subroutine destroy(this)

Deallocate the PLM reconstruction

Parameters
  • this [inout]

    This reconstruction

logical function check_reconstruction(this, h, u)

Checks the PLM_WLS reconstruction for consistency

Parameters
  • this [in]

    This reconstruction

  • h [in]

    Grid spacing (thickness) [typically H]

  • u [in]

    Cell mean values [A]

  • perturbed

    A perturbed reconstruction

Callees call graph
Callees of recon1d_plm_wls::check_reconstruction calls cluster_recon1d_plm_wls Recon1d_PLM_WLS recon1d_plm_wls::check_reconstruction check_reconstruction [private/internal] recon1d_plm_wls::ls_error LS_error [private/internal] recon1d_plm_wls::check_reconstruction->recon1d_plm_wls::ls_error
Text view
real function LS_error(this, k, h, u)

Returns local least squares error for a particular cell

Note that this is the error relative to the minimum of the loss function so that at the true solution this function returns zero. See module documentation.

Parameters
  • this [in]

    This reconstruction

  • k [in]

    Cell number

  • h [in]

    Grid spacing (thickness) [typically H]

  • u [in]

    Cell mean values [A]

Callers call graph
Callers of recon1d_plm_wls::ls_error calls cluster_recon1d_plm_wls Recon1d_PLM_WLS recon1d_plm_wls::check_reconstruction check_reconstruction [private/internal] recon1d_plm_wls::ls_error LS_error [private/internal] recon1d_plm_wls::check_reconstruction->recon1d_plm_wls::ls_error recon1d_plm_wls::unit_tests unit_tests [private/internal] recon1d_plm_wls::unit_tests->recon1d_plm_wls::ls_error
Text view
logical function unit_tests(this, verbose, stdout, stderr)

Runs PLM_WLS reconstruction unit tests and returns True for any fails, False otherwise

Parameters
  • this [inout]

    This reconstruction

  • verbose [in]

    True, if verbose

  • stdout [in]

    I/O channel for stdout

  • stderr [in]

    I/O channel for stderr

Callees call graph
Callees of recon1d_plm_wls::unit_tests calls cluster_recon1d_plm_wls Recon1d_PLM_WLS recon1d_plm_wls::ls_error LS_error [private/internal] recon1d_plm_wls::unit_tests unit_tests [private/internal] recon1d_plm_wls::unit_tests->recon1d_plm_wls::ls_error
Text view
API generated with Flint · Rendered from reStructuredText