recon1d_plm_wls module reference
Piecewise Linear Method using Weighted Conservative Least Squares 1D reconstruction.
Data Types
PLM reconstruction using Weighted Least Squares constrained to conserve for central cell. |
Functions/Subroutines
Initialize a 1D PLM reconstruction for n cells. |
|
Calculate a 1D PLM_WLS reconstruction based on h(:) and u(:) |
|
Value of PLM_WLS reconstruction at a point in cell k [A]. |
|
Derivative of PLM_WLS reconstruction at a point in cell k [A]. |
|
Average between xa and xb for cell k of a 1D PLM reconstruction [A]. |
|
Deallocate the PLM reconstruction. |
|
Checks the PLM_WLS reconstruction for consistency. |
|
Returns local least squares error for a particular cell. |
|
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
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
We use volume weighting in the loss
When solving for \(b_k\), we solve \(dG/db = 0\) where
and where \(< a > = \frac{1}{2} ( a_{k-1} + a_{k+1} )\). Thus
When evaluating the loss, \(G\), some rearrangement is necessary to reduce truncation errors. Since
then
If we denote the value of b that yields the minimum value as \(b^*\) then
Let
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 recon1d_plm_wls/plm_wls
PLM reconstruction using Weighted Least Squares constrained to conserve for central cell.
- Type fields:
% ul ::
real, dimension(:), allocatable, privateLeft edge value [A].% ur ::
real, dimension(:), allocatable, privateRight edge value [A].% slp ::
real, dimension(:), allocatable, private, privateDifference across cell, ur - ul [A]. This is redundant with ul and ur and not used in any evaluations, but is needed for testing.% init ::
procedure, privateImplementation of the PLM_WLS initialization.% reconstruct ::
procedure, privateImplementation of the PLM_WLS reconstruction.% average ::
procedure, privateImplementation of the PLM_WLS average over an interval [A].% f ::
procedure, privateImplementation of evaluating the PLM_WLS reconstruction at a point [A].% dfdx ::
procedure, privateImplementation of the derivative of the PLM_WLS reconstruction at a point [A].% destroy ::
procedure, privateImplementation of deallocation for PLM_WLS.% check_reconstruction ::
procedure, privateImplementation of check reconstruction for the PLM_WLS reconstruction.% unit_tests ::
procedure, privateImplementation of unit tests for the PLM_WLS reconstruction.% init_parent ::
procedure, privateDuplicate interface to% reconstruct_parent ::
procedure, privateDuplicate interface to
Function/Subroutine Documentation
- subroutine recon1d_plm_wls/init(this, n, h_neglect, check)
Initialize a 1D PLM reconstruction for n cells.
- Parameters:
this ::
this[out] This reconstructionn ::
n[in] Number of cells in this columnh_neglect ::
h_neglect[in] A negligibly small width used in cell reconstructions [H]check ::
check[in] If true, enable some consistency checking
- subroutine recon1d_plm_wls/reconstruct(this, h, u)
Calculate a 1D PLM_WLS reconstruction based on h(:) and u(:)
- Parameters:
this ::
this[inout] This reconstructionh ::
h[in] Grid spacing (thickness) [typically H]u ::
u[in] Cell mean values [A]
- function recon1d_plm_wls/f(this, k, x)
Value of PLM_WLS reconstruction at a point in cell k [A].
- Parameters:
this ::
this[in] This reconstructionk ::
k[in] Cell numberx ::
x[in] Non-dimensional position within element [nondim]
- function recon1d_plm_wls/dfdx(this, k, x)
Derivative of PLM_WLS reconstruction at a point in cell k [A].
- Parameters:
this ::
this[in] This reconstructionk ::
k[in] Cell numberx ::
x[in] Non-dimensional position within element [nondim]
- function recon1d_plm_wls/average(this, k, xa, xb)
Average between xa and xb for cell k of a 1D PLM reconstruction [A].
- Parameters:
this ::
this[in] This reconstructionk ::
k[in] Cell numberxa ::
xa[in] Start of averaging interval on element (0 to 1)xb ::
xb[in] End of averaging interval on element (0 to 1)
- subroutine recon1d_plm_wls/destroy(this)
Deallocate the PLM reconstruction.
- Parameters:
this ::
this[inout] This reconstruction
- function recon1d_plm_wls/check_reconstruction(this, h, u)
Checks the PLM_WLS reconstruction for consistency.
- Parameters:
this ::
this[in] This reconstructionh ::
h[in] Grid spacing (thickness) [typically H]u ::
u[in] Cell mean values [A]
- Call to:
- function recon1d_plm_wls/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 ::
this[in] This reconstructionk ::
k[in] Cell numberh ::
h[in] Grid spacing (thickness) [typically H]u ::
u[in] Cell mean values [A]
- Called from:
- function recon1d_plm_wls/unit_tests(this, verbose, stdout, stderr)
Runs PLM_WLS reconstruction unit tests and returns True for any fails, False otherwise.
- Parameters:
this ::
this[inout] This reconstructionverbose ::
verbose[in] True, if verbosestdout ::
stdout[in] I/O channel for stdoutstderr ::
stderr[in] I/O channel for stderr
- Call to: