def test_order(problem): mesh_sizes = [8, 16] hmax, u_errors, p_errors = numpy.array( [compute_error(problem, mesh_size) for mesh_size in mesh_sizes]).T # compute numerical orders of convergence u_order = compute_numerical_order_of_convergence(hmax, u_errors)[0] p_order = compute_numerical_order_of_convergence(hmax, p_errors)[0] assert u_order > 1.9 assert p_order > 1.9 return
def _show_order_info(problem, mesh_sizes): """Performs consistency check for the given problem/method combination and show some information about it. Useful for debugging. """ errors, hmax = _compute_errors(problem, mesh_sizes) order = helpers.compute_numerical_order_of_convergence(hmax, errors) # Print the data print() print("hmax ||u - u_h|| conv. order") print("{:e} {:e}".format(hmax[0], errors[0])) for j in range(len(errors) - 1): print(32 * " " + "{:2.5f}".format(order[j])) print("{:e} {:e}".format(hmax[j + 1], errors[j + 1])) # Plot the actual data. for mesh_size in mesh_sizes: plt.loglog(hmax, errors, "-o", label=mesh_size) # Compare with order curves. plt.autoscale(False) e0 = errors[0] for order in range(4): plt.loglog([hmax[0], hmax[-1]], [e0, e0 * (hmax[-1] / hmax[0])**order], color="0.7") plt.xlabel("hmax") plt.ylabel("||u-u_h||") plt.legend() plt.show() return
def _show_order_info(problem, mesh_sizes, stabilization): """Performs consistency check for the given problem/method combination and show some information about it. Useful for debugging. """ errors, hmax = _compute_errors(problem, mesh_sizes, stabilization) order = helpers.compute_numerical_order_of_convergence(hmax, errors) # Print the data print() print("hmax ||u - u_h|| conv. order") print("{:e} {:e}".format(hmax[0], errors[0])) for j in range(len(errors) - 1): print(32 * " " + "{:2.5f}".format(order[j])) print("{:e} {:e}".format(hmax[j + 1], errors[j + 1])) # Plot the actual data. plt.loglog(hmax, errors, "-o") # Compare with order curves. plt.autoscale(False) e0 = errors[0] for order in range(4): plt.loglog( [hmax[0], hmax[-1]], [e0, e0 * (hmax[-1] / hmax[0]) ** order], color="0.7" ) plt.xlabel("hmax") plt.ylabel("||u-u_h||") plt.show() return
def assert_time_order(problem, method, mesh_sizes, Dt): errors = compute_time_errors(problem, method, mesh_sizes, Dt) orders = { key: compute_numerical_order_of_convergence(Dt, errors[key].T).T for key in errors } # The test is considered passed if the numerical order of convergence # matches the expected order in at least the first step in the coarsest # spatial discretization, and is not getting worse as the spatial # discretizations are refining. assert (orders['u'][:, 0] > method.order['velocity'] - 0.1).all() assert (orders['p'][:, 0] > method.order['pressure'] - 0.1).all() return
def show_timeorder_info(Dt, mesh_sizes, errors): '''Performs consistency check for the given problem/method combination and show some information about it. Useful for debugging. ''' # Compute the numerical order of convergence. orders = { key: compute_numerical_order_of_convergence(Dt, errors[key].T).T for key in errors } # Print the data to the screen for i, mesh_size in enumerate(mesh_sizes): print() print('Mesh size %d:' % mesh_size) print('dt = %e' % Dt[0]) for label, e in errors.items(): print(' err_%s = %e' % (label, e[i][0])) print() for j in range(len(Dt) - 1): print(' ') for label, o in orders.items(): print(' ord_%s = %e' % (label, o[i][j])) print() print('dt = %e' % Dt[j + 1]) for label, e in errors.items(): print(' err_%s = %e' % (label, e[i][j + 1])) print() # Create a figure for label, err in errors.items(): plt.figure() # ax = plt.axes() # Plot the actual data. for i, mesh_size in enumerate(mesh_sizes): plt.loglog(Dt, err[i], '-o', label=mesh_size) # Compare with order curves. plt.autoscale(False) e0 = err[-1][0] for o in range(7): plt.loglog([Dt[0], Dt[-1]], [e0, e0 * (Dt[-1] / Dt[0])**o], color='0.7') plt.xlabel('dt') plt.ylabel('||%s-%s_h||' % (label, label)) # plt.title('Method: %s' % method['name']) plt.legend() plt.show() return
def test_order(problem): """Assert the correct discretization order. """ mesh_sizes = [16, 32, 64] errors, hmax = _compute_errors(problem, mesh_sizes) # Compute the numerical order of convergence. order = helpers.compute_numerical_order_of_convergence(hmax, errors) # The test is considered passed if the numerical order of convergence # matches the expected order in at least the first step in the coarsest # spatial discretization, and is not getting worse as the spatial # discretizations are refining. tol = 0.1 expected_order = 1 assert (order > expected_order - tol).all() return
def test_order(problem, stabilization): """Assert the correct discretization order. """ mesh_sizes = [16, 32, 64] errors, hmax = _compute_errors(problem, mesh_sizes, stabilization) # Compute the numerical order of convergence. order = helpers.compute_numerical_order_of_convergence(hmax, errors) # The test is considered passed if the numerical order of convergence # matches the expected order in at least the first step in the coarsest # spatial discretization, and is not getting worse as the spatial # discretizations are refining. tol = 0.1 expected_order = 2.0 assert (order > expected_order - tol).all() return
def test_temporal_order(problem, method): # TODO add test for spatial order mesh_sizes = [16, 32, 64] Dt = [1.0e-3, 0.5e-3] errors = _compute_time_errors(problem, method, mesh_sizes, Dt) # Error bounds are of the form # # ||E|| < C t_n (C1 dt^k + C2 dh^l). # # Hence, divide the error by t_n (=dt in this case). errors /= Dt # numerical orders of convergence orders = helpers.compute_numerical_order_of_convergence(Dt, errors.T).T # The test is considered passed if the numerical order of convergence # matches the expected order in at least the first step in the coarsest # spatial discretization, and is not getting worse as the spatial # discretizations are refining. tol = 0.1 assert (orders[:, 0] > method.order - tol).all() return