def test_interal_2d_1(): frequency = 400.0 # frequency [Hz] ( k, interior_points, interior_incident_phi, solver, boundary_incidence, ) = initialize(frequency) # Test Problem 1 # Dirichlet boundary condition with phi = sin(k/sqrt(2)*x) * sin(k/sqrt(2)*y) # boundary_condition = solver.dirichlet_boundary_condition() boundary_condition.f[:] = np.sin( k / np.sqrt(2.0) * solver.centers[:, 0]) * np.sin( k / np.sqrt(2.0) * solver.centers[:, 1]) boundary_solution = solver.solve_boundary(k, boundary_condition, boundary_incidence) sample_solution = boundary_solution.solve_samples(interior_incident_phi, interior_points) phi_golden = [ 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.1595e-01 + 0.0000e00j, 0.4777e-01 + 0.0000e00j, 0.7940e-01 + 0.0000e00j, 0.1107e00 + 0.0000e00j, 0.1415e00 + 0.0000e00j, 0.1718e00 + 0.0000e00j, 0.2013e00 + 0.0000e00j, 0.2300e00 + 0.0000e00j, 0.2300e00 + 0.0000e00j, 0.2013e00 + 0.0000e00j, 0.1718e00 + 0.0000e00j, 0.1415e00 + 0.0000e00j, 0.1107e00 + 0.0000e00j, 0.7940e-01 + 0.0000e00j, 0.4777e-01 + 0.0000e00j, 0.1595e-01 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, 0.0000e00 + 0.0000e00j, ] assert_almost_equal(phi_golden, boundary_solution.phis, 0.0001)
def test_internal_rad_2(): frequency = 40.0 # frequency [Hz] k, interior_points, interior_incident_phi, solver, boundary_incidence = initialize( frequency) # Test Problem 2 # von Neumann boundary condition such that phi = sin(k/sqrt(2) * x) * sin(k/sqrt(2) * y) # Differentiate with respect to x and y to obtain outward normal boundary_condition = solver.neumann_boundary_condition() centers = solver.geometry.centers() normals = solver.geometry.normals() for i in range(centers.shape[0]): z = centers[i, 1] n = -normals[i] boundary_condition.f[i] = k * np.cos(k * z) * n[1] boundary_solution = solver.solve_boundary(k, boundary_condition, boundary_incidence) sample_solution = boundary_solution.solve_samples(interior_incident_phi, interior_points) phi_golden = [ 0.6564e00 + 0.2434e-02j, 0.6397e00 + 0.2398e-02j, 0.6063e00 + 0.2226e-02j, 0.5555e00 + 0.1963e-02j, 0.4870e00 + 0.1653e-02j, 0.4012e00 + 0.1298e-02j, 0.2996e00 + 0.9183e-03j, 0.1854e00 + 0.5598e-03j, 0.6281e-01 + 0.1946e-03j, -0.6281e-01 - 0.1946e-03j, -0.1854e00 - 0.5598e-03j, -0.2996e00 - 0.9183e-03j, -0.4012e00 - 0.1298e-02j, -0.4870e00 - 0.1653e-02j, -0.5555e00 - 0.1963e-02j, -0.6063e00 - 0.2226e-02j, -0.6397e00 - 0.2398e-02j, -0.6564e00 - 0.2434e-02j, ] assert_almost_equal(phi_golden, boundary_solution.phis, 0.001) phi_golden = [ 0.2234e-07 - 0.1671e-07j, 0.3536e00 + 0.9056e-03j, -0.3536e00 - 0.9056e-03j, 0.2128e-07 - 0.1615e-07j, ] assert_almost_equal(phi_golden, sample_solution.phis, 0.0001)
def test_internal_rad_1(): frequency = 40.0 # frequency [Hz] k, interior_points, interior_incident_phi, solver, boundary_incidence = initialize( frequency) # Test Problem 1 # Dirichlet boundary condition with phi = sin(k*z) # boundary_condition = solver.dirichlet_boundary_condition() boundary_condition.f[:] = np.sin(k * solver.centers[:, 1]) boundary_solution = solver.solve_boundary(k, boundary_condition, boundary_incidence) sample_solution = boundary_solution.solve_samples(interior_incident_phi, interior_points) phi_golden = [ 0.6632e00 + 0.0000e0j, 0.6467e00 + 0.0000e0j, 0.6129e00 + 0.0000e0j, 0.5615e00 + 0.0000e0j, 0.4923e00 + 0.0000e0j, 0.4055e00 + 0.0000e0j, 0.3028e00 + 0.0000e0j, 0.1874e00 + 0.0000e0j, 0.6352e-01 + 0.0000e0j, -0.6352e-01 + 0.0000e0j, -0.1874e00 + 0.0000e0j, -0.3028e00 + 0.0000e0j, -0.4055e00 + 0.0000e0j, -0.4923e00 + 0.0000e0j, -0.5615e00 + 0.0000e0j, -0.6129e00 + 0.0000e0j, -0.6467e00 + 0.0000e0j, -0.6632e00 + 0.0000e0j, ] assert_almost_equal(phi_golden, boundary_solution.phis, 0.0001) phi_golden = [ 0.2826e-08 + -0.5606e-09j, 0.3574e00 + -0.3513e-03j, -0.3574e00 + 0.3513e-03j, 0.2897e-08 + -0.7412e-09j, ] assert_almost_equal(phi_golden, sample_solution.phis, 0.0001)
def test_internal_2d_3(): # Test Problem 3 # The test problem computes the field produced by a unit source at # the point (0.5,0.25) within the square with a rigid boundary. # The rigid boundary implies the boundary condition v=0. # The test problem computes the field produced by a unit source at # the point (0.5,0.25) within the square with a rigid boundary. # The incident velocity potential is given by {\phi}_inc=i*h0(kr)/4 # where r is the distance from the point (0.5,0.25) frequency = 400.0 # frequency [Hz] k, interior_points, interior_incident_phi, solver, boundary_incidence = initialize( frequency) boundary_condition = solver.neumann_boundary_condition() boundary_condition.f.fill(0.0) p = np.array([0.05, 0.025], dtype=np.float32) for i in range(solver.centers.shape[0]): r = solver.centers[i] - p R = norm(r) boundary_incidence.phi[i] = 0.25j * hankel1(0, k * R) if solver.centers[i, 0] < 1e-7: boundary_incidence.v[i] = -0.25j * k * hankel1(1, k * R) * (-r[0] / R) elif solver.centers[i, 0] > 0.1 - 1e-7: boundary_incidence.v[i] = -0.25j * k * hankel1(1, k * R) * (r[0] / R) elif solver.centers[i, 1] < 1e-7: boundary_incidence.v[i] = -0.25j * k * hankel1(1, k * R) * (-r[1] / R) elif solver.centers[i, 1] > 0.1 - 1e-7: boundary_incidence.v[i] = -0.25j * k * hankel1(1, k * R) * (r[1] / R) else: assert False, "All cases must be handled above." for i in range(interior_incident_phi.size): r = interior_points[i] - p R = norm(r) interior_incident_phi[i] = 0.25j * hankel1(0, k * R) boundary_solution = solver.solve_boundary(k, boundary_condition, boundary_incidence) sample_solution = boundary_solution.solve_samples(interior_incident_phi, interior_points) print("Test3 boundary solution") print(boundary_solution) print("Test3 sample solution") print(sample_solution) phi_golden = [ -0.1813e01 + 0.3210e-03j, -0.1827e01 + 0.2720e-03j, -0.1855e01 + 0.2822e-03j, -0.1895e01 + 0.3356e-03j, -0.1938e01 + 0.4039e-03j, -0.1976e01 + 0.4646e-03j, -0.2004e01 + 0.5079e-03j, -0.2019e01 + 0.5301e-03j, -0.2020e01 + 0.4892e-03j, -0.2018e01 + 0.4470e-03j, -0.2016e01 + 0.4173e-03j, -0.2014e01 + 0.4012e-03j, -0.2014e01 + 0.4012e-03j, -0.2016e01 + 0.4173e-03j, -0.2018e01 + 0.4470e-03j, -0.2020e01 + 0.4892e-03j, -0.2019e01 + 0.5301e-03j, -0.2004e01 + 0.5079e-03j, -0.1976e01 + 0.4646e-03j, -0.1938e01 + 0.4039e-03j, -0.1895e01 + 0.3356e-03j, -0.1855e01 + 0.2822e-03j, -0.1827e01 + 0.2720e-03j, -0.1813e01 + 0.3210e-03j, -0.1810e01 + 0.4337e-03j, -0.1782e01 + 0.3972e-03j, -0.1731e01 + 0.2555e-03j, -0.1681e01 + 0.3855e-04j, -0.1681e01 + 0.3855e-04j, -0.1731e01 + 0.2555e-03j, -0.1782e01 + 0.3972e-03j, -0.1810e01 + 0.4337e-03j, ] assert_almost_equal(phi_golden, boundary_solution.phis, 0.00001)
def test_internal_2d_2(): # Test Problem 2 # von Neumann boundary condition such that phi = sin(k/sqrt(2) * x) * sin(k/sqrt(2) * y) # Differentiate with respect to x and y to obtain outward normal: # dPhi/dX = k/sqrt(2) * cos(k/sqrt(2) * x) * sin(k/sqrt(2) * y) # dPhi/dY = k/sqrt(2) * sin(k/sqrt(2) * x) * cos(k/sqrt(2) * y) frequency = 400.0 # frequency [Hz] ( k, interior_points, interior_incident_phi, solver, boundary_incidence, ) = initialize(frequency) boundary_condition = solver.neumann_boundary_condition() w = k / np.sqrt(2.0) for i in range(solver.centers.shape[0]): x = solver.centers[i, 0] y = solver.centers[i, 1] if x < 1e-7: boundary_condition.f[i] = -w * np.cos(w * x) * np.sin(w * y) elif x > 0.1 - 1e-7: boundary_condition.f[i] = w * np.cos(w * x) * np.sin(w * y) elif y < 1e-7: boundary_condition.f[i] = -w * np.sin(w * x) * np.cos(w * y) else: boundary_condition.f[i] = w * np.sin(w * x) * np.cos(w * y) boundary_solution = solver.solve_boundary(k, boundary_condition, boundary_incidence) sample_solution = boundary_solution.solve_samples(interior_incident_phi, interior_points) phi_golden = [ -0.3647e-03 + 0.8013e-03j, -0.3205e-03 + 0.8641e-03j, -0.2681e-03 + 0.9276e-03j, -0.1668e-03 + 0.9850e-03j, 0.3219e-04 + 0.1031e-02j, 0.4063e-03 + 0.1060e-02j, 0.1118e-02 + 0.1066e-02j, 0.2859e-02 + 0.1050e-02j, 0.1937e-01 + 0.9291e-03j, 0.4881e-01 + 0.1150e-02j, 0.7902e-01 + 0.1426e-02j, 0.1092e00 + 0.1723e-02j, 0.1388e00 + 0.2028e-02j, 0.1677e00 + 0.2333e-02j, 0.1954e00 + 0.2627e-02j, 0.2205e00 + 0.2877e-02j, 0.2205e00 + 0.2877e-02j, 0.1954e00 + 0.2627e-02j, 0.1677e00 + 0.2333e-02j, 0.1388e00 + 0.2028e-02j, 0.1092e00 + 0.1723e-02j, 0.7902e-01 + 0.1426e-02j, 0.4881e-01 + 0.1150e-02j, 0.1937e-01 + 0.9291e-03j, 0.2859e-02 + 0.1050e-02j, 0.1118e-02 + 0.1066e-02j, 0.4063e-03 + 0.1060e-02j, 0.3219e-04 + 0.1031e-02j, -0.1668e-03 + 0.9850e-03j, -0.2681e-03 + 0.9276e-03j, -0.3205e-03 + 0.8641e-03j, -0.3647e-03 + 0.8013e-03j, ] assert_almost_equal(phi_golden, boundary_solution.phis, 0.0001)
def test_internal_3d_2(): # Test Problem 2 # Neumann boundary condition with v = cos(k*z) # frequency = 20.0 # frequency [Hz] k, interior_points, boundary_incidence, solver, interior_incident_phi = initialize( frequency) boundary_condition = solver.neumann_boundary_condition() for i in range(solver.len()): a, b, c = solver.geometry.triangle_vertices(i) normal = ab.normal_3d(a, b, c) boundary_condition.f[i] = k * np.cos( k * solver.centers[i, 2]) * normal[2] boundary_solution = solver.solve_boundary(k, boundary_condition, boundary_incidence) sample_solution = boundary_solution.solve_samples(interior_incident_phi, interior_points) phi_golden = [ 0.2543e00 + 0.5479e-02j, 0.2543e00 + 0.5477e-02j, 0.2543e00 + 0.5479e-02j, 0.2543e00 + 0.5479e-02j, 0.2543e00 + 0.5477e-02j, 0.2543e00 + 0.5479e-02j, 0.1439e00 + 0.4738e-02j, 0.6877e-01 + 0.3551e-02j, 0.1439e00 + 0.4748e-02j, 0.6877e-01 + 0.3551e-02j, 0.1439e00 + 0.4738e-02j, 0.6877e-01 + 0.3554e-02j, 0.1439e00 + 0.4738e-02j, 0.6877e-01 + 0.3551e-02j, 0.1439e00 + 0.4748e-02j, 0.6877e-01 + 0.3551e-02j, 0.1439e00 + 0.4738e-02j, 0.6877e-01 + 0.3554e-02j, -0.1439e00 - 0.4738e-02j, -0.6877e-01 - 0.3551e-02j, -0.1439e00 - 0.4748e-02j, -0.6877e-01 - 0.3551e-02j, -0.1439e00 - 0.4738e-02j, -0.6877e-01 - 0.3554e-02j, -0.1439e00 - 0.4738e-02j, -0.6877e-01 - 0.3551e-02j, -0.1439e00 - 0.4748e-02j, -0.6877e-01 - 0.3551e-02j, -0.1439e00 - 0.4738e-02j, -0.6877e-01 - 0.3554e-02j, -0.2543e00 - 0.5479e-02j, -0.2543e00 - 0.5477e-02j, -0.2543e00 - 0.5479e-02j, -0.2543e00 - 0.5479e-02j, -0.2543e00 - 0.5477e-02j, -0.2543e00 - 0.5479e-02j, ] assert_almost_equal(phi_golden, boundary_solution.phis, 0.0001) phi_golden = [ -0.7286e-16 - 0.6075e-15j, 0.3205e-02 + 0.5491e-04j, 0.8002e-01 + 0.1338e-02j, 0.1586e00 + 0.2495e-02j, 0.2377e00 + 0.3530e-02j, ] assert_almost_equal(phi_golden, sample_solution.phis, 0.0001)
def test_internal_3d_1(): # Test Problem 1 # Dirichlet boundary condition with phi = sin(k*z) # frequency = 20.0 # frequency [Hz] k, interior_points, boundary_incidence, solver, interior_incident_phi = initialize( frequency) boundary_condition = solver.dirichlet_boundary_condition() boundary_condition.f[:] = np.sin(k * solver.centers[:, 2]) boundary_solution = solver.solve_boundary(k, boundary_condition, boundary_incidence) sample_solution = boundary_solution.solve_samples(interior_incident_phi, interior_points) phi_golden = [ 0.2804e00 + 0.0000e00j, 0.2804e00 + 0.0000e00j, 0.2804e00 + 0.0000e00j, 0.2804e00 + 0.0000e00j, 0.2804e00 + 0.0000e00j, 0.2804e00 + 0.0000e00j, 0.1617e00 + 0.0000e00j, 0.8113e-01 + 0.0000e00j, 0.1617e00 + 0.0000e00j, 0.8113e-01 + 0.0000e00j, 0.1617e00 + 0.0000e00j, 0.8113e-01 + 0.0000e00j, 0.1617e00 + 0.0000e00j, 0.8113e-01 + 0.0000e00j, 0.1617e00 + 0.0000e00j, 0.8113e-01 + 0.0000e00j, 0.1617e00 + 0.0000e00j, 0.8113e-01 + 0.0000e00j, -0.1617e00 + 0.0000e00j, -0.8113e-01 + 0.0000e00j, -0.1617e00 + 0.0000e00j, -0.8113e-01 + 0.0000e00j, -0.1617e00 + 0.0000e00j, -0.8113e-01 + 0.0000e00j, -0.1617e00 + 0.0000e00j, -0.8113e-01 + 0.0000e00j, -0.1617e00 + 0.0000e00j, -0.8113e-01 + 0.0000e00j, -0.1617e00 + 0.0000e00j, -0.8113e-01 + 0.0000e00j, -0.2804e00 + 0.0000e00j, -0.2804e00 + 0.0000e00j, -0.2804e00 + 0.0000e00j, -0.2804e00 + 0.0000e00j, -0.2804e00 + 0.0000e00j, -0.2804e00 + 0.0000e00j, ] assert_almost_equal(phi_golden, boundary_solution.phis, 0.0001) phi_golden = [ -0.1032e-15 - 0.5254e-16j, 0.3568e-02 - 0.3302e-04j, 0.8894e-01 - 0.8015e-03j, 0.1757e00 - 0.1477e-02j, 0.2623e00 - 0.1966e-02j, ] assert_almost_equal(phi_golden, sample_solution.phis, 0.00001)
def test_internal_3d_3(): # Test Problem 3 # Neumann boundary condition with v = cos(k*z) # frequency = 20.0 # frequency [Hz] k, interior_points, boundary_incidence, solver, interior_incident_phi = initialize( frequency) boundary_condition = solver.neumann_boundary_condition() p = np.array([0.0, 0.0, 0.0], dtype=np.float32) for i in range(solver.len()): q = solver.centers[i, :] r = p - q R = norm(r) boundary_incidence.phi[i] = np.exp(1.0j * k * R) / (4.0 * np.pi * R) a, b, c = solver.geometry.triangle_vertices(i) normal = ab.normal_3d(a, b, c) drbdn = -np.dot(r, normal) / R boundary_incidence.v[i] = (drbdn * np.exp(1.0j * k * R) * (1.0j * k * R - 1.0) / (4.0 * np.pi * R * R)) for i in range(interior_points.shape[0]): q = interior_points[i, :] r = p - q R = norm(r) interior_incident_phi[i] = np.exp(1.0j * k * R) / (4.0 * np.pi * R) boundary_solution = solver.solve_boundary(k, boundary_condition, boundary_incidence) sample_solution = boundary_solution.solve_samples(interior_incident_phi, interior_points) phi_golden = [ -0.1398e01 + -0.5759e00j, -0.1398e01 + -0.5759e00j, -0.1398e01 + -0.5759e00j, -0.1398e01 + -0.5759e00j, -0.1398e01 + -0.5759e00j, -0.1398e01 + -0.5759e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1399e01 + -0.5779e00j, -0.1389e01 + -0.5760e00j, -0.1398e01 + -0.5759e00j, -0.1398e01 + -0.5759e00j, -0.1398e01 + -0.5759e00j, -0.1398e01 + -0.5759e00j, -0.1398e01 + -0.5759e00j, -0.1398e01 + -0.5759e00j, ] assert_almost_equal(phi_golden, boundary_solution.phis, 0.001) phi_golden = [ -0.1291e01 - 0.5891e00j, 0.6496e01 - 0.5949e00j, -0.1143e01 - 0.5941e00j, -0.1296e01 - 0.5904e00j, -0.1372e01 - 0.5989e00j, ] assert_almost_equal(phi_golden, sample_solution.phis, 0.001)
def test_internal_rad_3(): frequency = 40.0 # frequency [Hz] k, interior_points, interior_incident_phi, solver, boundary_incidence = initialize( frequency) # Test Problem 3 # Dirichlet boundary condition, such that phi = sin(k/ sqrt(2) * x) * sin(k/sqrt(2) * y) # Differentiate with respect to x and y to obtain outward normal boundary_condition = solver.neumann_boundary_condition() boundary_condition.alpha.fill(1.0) boundary_condition.beta.fill(0.0) centers = solver.geometry.centers() normals = solver.geometry.normals() zp = 0.25 for i in range(centers.shape[0]): r = centers[i, 0] z = centers[i, 1] # make input complex so proper sqrt is called rpq = np.sqrt(0.0j + r**2 + (z - zp)**2) boundary_condition.f[i] = np.exp(1j * k * rpq) / (4.0 * np.pi * rpq) boundary_incidence.phi[i] = np.exp(1j * k * rpq) / (4.0 * np.pi * rpq) n = -normals[i] drbdn = (r * n[0] + (z - zp) * n[1]) / rpq boundary_incidence.v[i] = (drbdn * np.exp(1j * k * rpq) * (1j * k * rpq - 1.0) / (4.0 * np.pi * rpq * rpq)) for i in range(interior_points.shape[0]): r = interior_points[i, 0] z = interior_points[i, 1] # make input complex so proper sqrt is called rpq = np.sqrt(0.0j + r**2 + (zp - z)**2) interior_incident_phi[i] = np.exp(1j * k * rpq) / (4.0 * np.pi * rpq) boundary_solution = solver.solve_boundary(k, boundary_condition, boundary_incidence) sample_solution = boundary_solution.solve_samples(interior_incident_phi, interior_points) phi_golden = [ 0.9096e-01 + 0.5529e-01j, 0.8933e-01 + 0.5521e-01j, 0.8636e-01 + 0.5507e-01j, 0.8234e-01 + 0.5485e-01j, 0.7766e-01 + 0.5457e-01j, 0.7273e-01 + 0.5424e-01j, 0.6779e-01 + 0.5387e-01j, 0.6306e-01 + 0.5346e-01j, 0.5870e-01 + 0.5305e-01j, 0.5473e-01 + 0.5262e-01j, 0.5120e-01 + 0.5220e-01j, 0.4816e-01 + 0.5181e-01j, 0.4557e-01 + 0.5145e-01j, 0.4342e-01 + 0.5113e-01j, 0.4173e-01 + 0.5086e-01j, 0.4046e-01 + 0.5065e-01j, 0.3962e-01 + 0.5051e-01j, 0.3921e-01 + 0.5044e-01j, ] assert_almost_equal(phi_golden, boundary_solution.phis, 0.00001) phi_golden = [ 0.3118e00 + 0.5882e-01j, 0.3116e00 + 0.5901e-01j, 0.8958e-01 + 0.5608e-01j, 0.1295e00 + 0.5751e-01j, ] assert_almost_equal(phi_golden, sample_solution.phis, 0.0001)