Skip to main content

Convergence testing the 1st-order acoustic example

In this notebook, Schism’s immersed boundary implementation for the free surface with the 1st-order acoustic wave equation against the previously presented exact solution.

from convergence_1st_order import calculate_error

refinements = [0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55,
               0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95,
               1.0]
errs_max = []

for refinement in refinements:
    max_err = calculate_error(refinement)
    errs_max.append(max_err)
Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 0.62 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 4.14 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 1.27 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 2.59 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 13.16 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 15.08 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 48.36 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 22.40 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 22.50 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 27.83 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 34.76 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 42.36 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 51.60 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 60.17 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 72.86 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 87.00 s

Operator `normals` ran in 0.01 s
Generating stencils for Derivative(p(t, x, y), x)
Generating stencils for Derivative(p(t, x, y), y)
Generating stencils for Derivative(v_x(t + dt, x + h_x/2, y), x)
Generating stencils for Derivative(v_y(t + dt, x, y + h_y/2), y)
Operator `Kernel` ran in 93.06 s

Plotting the convergence, we can see we have an approximately fourth-order trend, and a knee at a grid increment of around \(\Delta x = 0.02\), after which the order of convergence drops off somewhat.

import matplotlib.pyplot as plt
import numpy as np

plt.loglog(2*np.pi/(240*np.array(refinements)), errs_max, 'kx')
plt.loglog(2*np.pi/(240*np.array(refinements)), errs_max, 'k')
plt.title("Convergence of the 4th-order scheme")
plt.xlabel("Grid increment")
plt.ylabel("Maximum error")
plt.savefig("convergence_plot_1st_order")
plt.show()

Finding the convergence gradient in the upper section of the curve, it is observed that the scheme attains just short of 4th-order.

grad_upper = np.polyfit(np.log10(2*np.pi/(240*np.array(refinements[:6]))),
                        np.log10(errs_max[:6]), 1)[0]
assert np.isclose(grad_upper, 3.728974340323545, rtol=1e-4)
grad_lower = np.polyfit(np.log10(2*np.pi/(240*np.array(refinements[6:]))),
                        np.log10(errs_max[6:]), 1)[0]
print(grad_lower)
assert np.isclose(grad_lower, 1.6489894599122552, rtol=1e-4)
1.6489222581534682
Back to top