# ply_sampling_var_compute_elemdev Subroutine

## public subroutine ply_sampling_var_compute_elemdev(var, threshold, min_mean)

This routine computes for each element whether the solution in it is considered to be deviating from the mean above the given threshold or not. The logical result is stored in var%deviates for each element.

The total number of deviating elements is stored in var%nDeviating.

The variation is computed by the sum of the absolute values of all higher modes divided by the first mode. As we are using series of Legendre polynomials this also is a bounding estimation for the maximal (relative) deviation from the mean in this element.

A variation of 0.01 for example would imply that the state in the element is guaranteed to nowhere deviate from the mean by more than 1 percent. However, this is a very rough estimation and the actual maximal deviation from the mean is probably much lower (at least for sufficiently high polynomial degrees).

If the mean is too close to 0, we use epsilon for the normalization instead of the actual mean.

The computation is done for the current data found in var%dat, any previous computations of these flags will be discarded by this routine.

### Arguments

TypeIntentOptionalAttributesName
type(ply_sampling_var_type), intent(inout) :: var

Variable data to compute the deviation for.

real(kind=rk), intent(in) :: threshold

Relative threshold to use as decision whether an element has a high deviation or not.

If the absolute value of higher modes sums to a larger value than threshold times the first mode (integral mean), the element is marked as deviating.

real(kind=rk), intent(in) :: min_mean

A minimal mean value to use as comparison (to cut off changes that are too close to 0).

This should be small but has to be larger than 0.

## Variables

TypeVisibilityAttributesNameInitial
real(kind=rk), private :: variation
real(kind=rk), private :: absmean
integer, private :: iElem
integer, private :: nElems
integer, private :: ndofs