Skip to content

Solution verification indicators

solution_verification_indicators

Functions

compute_c

compute_c(e_q_j, gamma_j_1, gamma_j, beta)

Compute constant \(C\).

Parameters:

  • e_q_j

    The error expansion (\(q_{exact} - q_j\)) for grid j.

  • gamma_j_1

    The relative element size for grid j+1.

  • gamma_j

    The relative element size for grid j.

  • beta

    The convergence order.

Returns:

  • The constant \(C\).

Source code in src/vimseo/tools/verification/solution_verification_indicators.py
51
52
53
54
55
56
57
58
59
60
61
62
63
def compute_c(e_q_j, gamma_j_1, gamma_j, beta):
    r"""Compute constant $C$.

    Args:
        e_q_j: The error expansion ($q_{exact} - q_j$) for grid j.
        gamma_j_1: The relative element size for grid j+1.
        gamma_j: The relative element size for grid j.
        beta: The convergence order.

    Returns:
        The constant $C$.
    """
    return e_q_j / (-(gamma_j_1**beta) + gamma_j**beta)

compute_gci

compute_gci(fs, h, q, beta, starting_mesh_id)

The Grid Convergence Index.

Computed from the two finest meshes.

Parameters:

  • fs

    The safety factor.

  • h

    The element sizes, from coarse to fine.

  • q

    The output value corresponding to each element size.

  • beta

    The convergence order.

  • starting_mesh_id

    The GCI is computed based on q[starting_mesh_id] and

Returns:

  • A tuple where first element is the Grid Convergence Index, and second element is the GCI-based error band on the solution.

Source code in src/vimseo/tools/verification/solution_verification_indicators.py
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
def compute_gci(fs, h, q, beta, starting_mesh_id):
    """The Grid Convergence Index.

    Computed from the two finest meshes.

    Args:
        fs: The safety factor.
        h: The element sizes, from coarse to fine.
        q: The output value corresponding to each element size.
        beta: The convergence order.
        starting_mesh_id: The GCI is computed based on q[starting_mesh_id] and
        q[starting_mesh_id+1].

    Returns:
        A tuple where first element is the Grid Convergence Index,
        and second element is the GCI-based error band on the solution.
    """
    gci = (
        fs
        * abs((q[starting_mesh_id + 1] - q[starting_mesh_id]) / q[starting_mesh_id + 1])
        / ((h[starting_mesh_id] / h[starting_mesh_id + 1]) ** beta - 1)
    )
    return gci, [
        q[starting_mesh_id + 1] * (1 - abs(gci)),
        q[starting_mesh_id + 1] * (1 + abs(gci)),
    ]

compute_median

compute_median(q: ndarray, q_ref: float)

Estimate the extrapolated value at element size = 0.

The uncertainty is computed from the Median Absolute Deviation (MAD).

Parameters:

  • q (ndarray) –

    The model output values.

  • q_ref (float) –

    A reference value in which we have most confidence. The final

Returns:

  • A tuple where first element is the estimate of the extrapolated value, and second is the MAD.

Source code in src/vimseo/tools/verification/solution_verification_indicators.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def compute_median(q: ndarray, q_ref: float):
    """Estimate the extrapolated value at element size = 0.

    The uncertainty is computed from the Median Absolute Deviation (MAD).

    Args:
        q: The model output values.
        q_ref: A reference value in which we have most confidence. The final
        estimate for the extrapolated q is a weighted sum of the median and q_ref.

    Returns:
        A tuple where first element is the estimate of the extrapolated value,
        and second is the MAD.
    """
    q_median = median(q)
    w = 0.66
    q_final = q_ref * w + q_median * (1 - w)
    # Coefficient for a normal distribution:
    q_mad = 1.4826 * median(absolute(q - q_final))
    return q_final, q_mad

compute_q_extrap

compute_q_extrap(j, c, q, gamma, beta)

Compute the extrapolated value at element size = 0.

Parameters:

  • j

    The grid index.

  • c

    The \(C\) constant.

  • q

    The model solution array indexed for j.

  • gamma

    The relative element size array indexed for j.

  • beta

    The convergence order.

Returns:

  • The extrapolated value of the model solution at element size = 0.

Source code in src/vimseo/tools/verification/solution_verification_indicators.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def compute_q_extrap(j, c, q, gamma, beta):
    r"""Compute the extrapolated value at element size = 0.

    Args:
        j: The grid index.
        c: The $C$ constant.
        q: The model solution array indexed for j.
        gamma: The relative element size array indexed for j.
        beta: The convergence order.

    Returns:
        The extrapolated value of the model solution at element size = 0.
    """
    return q[j] + c * gamma[j] ** beta

compute_rde

compute_rde(fs, h, q, q_extrap, beta, i)

The Relative Discretisation Index (RDE).

Computed from the two finest meshes.

Parameters:

  • fs

    The safety factor.

  • h

    The element sizes, from coarse to fine.

  • q

    The output value corresponding to each element size.

  • beta

    The convergence order.

  • q_extrap

    The Richardson extrapolation.

  • i

    The index at which RDE is computed, from fine to coarse.

Returns:

  • A tuple where first element is the RDE, and second element is the RDE-based error band on the solution for the finest grid.

Source code in src/vimseo/tools/verification/solution_verification_indicators.py
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
def compute_rde(fs, h, q, q_extrap, beta, i):
    """The Relative Discretisation Index (RDE).

    Computed from the two finest meshes.

    Args:
        fs: The safety factor.
        h: The element sizes, from coarse to fine.
        q: The output value corresponding to each element size.
        beta: The convergence order.
        q_extrap: The Richardson extrapolation.
        i: The index at which RDE is computed, from fine to coarse.

    Returns:
        A tuple where first element is the RDE,
        and second element is the RDE-based error band on the solution for the finest
        grid.
    """
    q_fine_to_coarse = q[::-1]
    h_fine_to_coarse = h[::-1]
    rde = (q_fine_to_coarse[i + 1] - q_fine_to_coarse[i]) / (
        q_extrap * ((h_fine_to_coarse[i + 1] / h_fine_to_coarse[i]) ** beta - 1)
    )
    rde_band = (
        fs / ((h_fine_to_coarse[i + 1] / h_fine_to_coarse[i]) ** beta - 1)
    ) * abs((q_fine_to_coarse[i + 1] - q_fine_to_coarse[i]) / q_extrap)
    return rde, [q[i + 1] - 0.5 * rde_band, q[i + 1] + 0.5 * rde_band]

compute_richardson

compute_richardson(h, q)

Compute Richardson extrapolation.

Parameters:

  • h

    The array of element sizes.

  • q

    The array of model solutions.

Returns:

  • The Richardson extrapolation of q at element size = 0.

Source code in src/vimseo/tools/verification/solution_verification_indicators.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
def compute_richardson(h, q):
    r"""Compute Richardson extrapolation.

    Args:
        h: The array of element sizes.
        q: The array of model solutions.

    Returns:
        The Richardson extrapolation of q at element size = 0.
    """
    # Arbitrary coefficient > 1 to define a base h value $h_0$.
    h_0 = h[0] * 1.1
    # Solve equation for $\beta$:
    beta, _infos, status, _msg = fsolve(
        beta_func,
        1.0,
        args=(
            q[1] - q[0],
            q[2] - q[1],
            h[0] / h_0,
            h[1] / h_0,
            h[2] / h_0,
        ),
        full_output=True,
    )
    beta = beta[0]
    if status == 1 and beta >= 0:
        c = compute_c(q[1] - q[0], h[1] / h_0, h[0] / h_0, beta)
        q_extrap = compute_q_extrap(0, c, q, h / h_0, beta)
        return beta, q_extrap
    return np.nan, np.nan