def test_that_is_incompressible_projection(): N = 128 L = 2 * np.pi vt = VectorTool(N, L) u = np.random.random((2, N, N)) u = vt.dealias(vt.div_free_proj(u)) assert vt.is_incompressible(u)
def test_dealias_of_velocity_with_components_equal_to_sinkx_where_k_is_above_two_thirds_dealias_boundary_is_zero( ): L = 2.0 * np.pi N = 128 vt = VectorTool(N, L) kabove = np.ceil(vt.kmax_dealias) + 1 v = np.zeros((2, N, N)) v[0] = np.sin(2. * np.pi / L * kabove * vt.X[0]) v[0] = np.sin(2. * np.pi / L * kabove * vt.X[1]) z = np.zeros(v.shape) assert np.allclose(vt.dealias(v), z) def test_dealias_of_velocity_with_components_equal_to_sinkx_where_k_is_below_two_thirds_dealias_boundary_is_zero( ): L = 2.0 * np.pi N = 128 vt = VectorTool(N, L) kabove = np.floor(vt.kmax_dealias) - 1 v = np.zeros((2, N, N)) v[0] = np.sin(2. * np.pi / L * kabove * vt.X[0]) v[0] = np.sin(2. * np.pi / L * kabove * vt.X[1]) z = np.zeros(v.shape) assert np.allclose(vt.dealias(v), z)
def test_h1norm_of_sin_flow(): N = 128 L = 2.0 vt = VectorTool(N, L) X = np.mgrid[:N, :N].astype(float) * (L / N) u = np.zeros((2, N, N)) u[0] = np.sin(2. * np.pi / L * X[1]) assert np.isclose(vt.h1norm(u)**2., 2. * np.pi**2.)
def test_that_l2norm_of_vector_with_siny_for_xcomponent_equals_sqrt_of_half_of_Lsq( ): L = 2.0 * np.pi N = 128 vt = VectorTool(N, L) X = np.mgrid[:N, :N].astype(float) * (L / N) u = np.zeros((2, N, N)) u[0] = np.sin(2.0 * np.pi * X[1] / L) assert np.isclose(vt.l2norm(u), (0.5 * L**2)**0.5)
def test_subtract_mean_of_velocity(): L = 2.0 N = 128 vt = VectorTool(N, L) u = np.zeros((2, N, N)) sinkx = np.sin((2 * np.pi / L) * vt.X[0]) u[0] = sinkx + 2.0 u[1] = sinkx + 1.0 assert np.allclose(vt.subtract_mean(u), np.array([sinkx, sinkx]))
def test_that_is_incompressible_function_returns_true_for_cellular_flow(): N = 128 L = 2 * np.pi vt = VectorTool(N, L) u = np.zeros((2, N, N)) u[0] = np.sin((2.0 * np.pi / L) * vt.X[0]) * \ np.sin((2.0 * np.pi / L) * vt.X[1]) u[1] = np.cos((2.0 * np.pi / L) * vt.X[0]) * \ np.cos((2.0 * np.pi / L) * vt.X[1]) assert vt.is_incompressible(u)
def test_ifft_of_fft_equals_original_vector_function(): L = 10.5 N = 128 k = 2.0 * np.pi / L X = np.mgrid[:N, :N].astype(float) * (L / N) u = np.zeros((2, N, N)) u[0] = np.sin(k * X[1]) u[1] = np.cos(k * X[0]) vt = VectorTool(N, L) assert np.allclose(vt.ifft(vt.fft(u)), u)
def test_lap_invlap_of_u_is_u_minus_mean_value(): L = 2.0 * np.pi N = 128 vt = VectorTool(N, L) u = np.zeros((2, N, N)) # Compressible flow u[0] = np.sin((2.0 * np.pi / L) * vt.X[0]) * \ np.sin((2.0 * np.pi / L) * vt.X[1]) + 2.0 u[1] = -np.cos((2.0 * np.pi / L) * vt.X[0]) * \ np.cos((2.0 * np.pi / L) * vt.X[1]) + 1.0 assert np.allclose(vt.lap(vt.invlap(u)), vt.subtract_mean(u))
def test_curl_is_equal_to_curl_computed_with_grad_function(): N = 128 L = 2.0 kappa = 0.0 gamma = 1.0 v = np.random.random((2, N, N)) # print(np.shape(v)) st = ScalarTool(N, L) vt = VectorTool(N, L) v = vt.div_free_proj(v) v = vt.dealias(v) c = st.grad(v[1])[0] - st.grad(v[0])[1] assert np.allclose(c, vt.curl(v))
def test_that_div_free_projector_converts_a_compressible_flow_to_incompressible( ): N = 128 L = 2 * np.pi vt = VectorTool(N, L) u = np.zeros((2, N, N)) # Compressible flow u[0] = np.sin((2.0 * np.pi / L) * vt.X[0]) * \ np.sin((2.0 * np.pi / L) * vt.X[1]) u[1] = -np.cos((2.0 * np.pi / L) * vt.X[0]) * \ np.cos((2.0 * np.pi / L) * vt.X[1]) w = np.zeros((2, N, N)) w[0] = np.sin((2.0 * np.pi / L) * vt.X[0]) * \ np.sin((2.0 * np.pi / L) * vt.X[1]) w[1] = np.cos((2.0 * np.pi / L) * vt.X[0]) * \ np.cos((2.0 * np.pi / L) * vt.X[1]) u = u + 0.1 * w assert vt.is_incompressible(vt.div_free_proj(u))
def test_validate_div_free_projector(): L = 2.0 * np.pi N = 128 st = ScalarTool(N, L) vt = VectorTool(N, L) u = np.zeros((2, N, N)) # Compressible flow u[0] = np.sin((2.0 * np.pi / L) * vt.X[0]) * \ np.sin((2.0 * np.pi / L) * vt.X[1]) u[1] = -np.cos((2.0 * np.pi / L) * vt.X[0]) * \ np.cos((2.0 * np.pi / L) * vt.X[1]) w = np.zeros((2, N, N)) w[0] = np.sin((2.0 * np.pi / L) * vt.X[0]) * \ np.sin((2.0 * np.pi / L) * vt.X[1]) w[1] = np.cos((2.0 * np.pi / L) * vt.X[0]) * \ np.cos((2.0 * np.pi / L) * vt.X[1]) u = u + 0.1 * w projection_alt = u - st.grad_invlap(vt.div(u)) print(np.amax(abs(projection_alt - vt.div_free_proj(u)))) assert np.allclose(projection_alt, vt.div_free_proj(u))
def test_h1normsq_of_vector_is_spatial_integral_neg_lapvec_times_vec(): N = 128 L = 2.0 kappa = 0.0 gamma = 1.0 v = np.random.random((2, N, N)) st = ScalarTool(N, L) vt = VectorTool(N, L) v = vt.div_free_proj(v) v = vt.dealias(v) a = vt.h1norm(v)**2 b = st.sint(np.sum(-vt.lap(v) * v, 0)) assert np.allclose(a, b)
def test_l2norm_squared_of_curl_of_vector_is_spatial_integral_of_neg_vector_times_lap_vector( ): N = 128 L = 2.0 kappa = 0.0 gamma = 1.0 v = np.random.random((2, N, N)) # print(np.shape(v)) st = ScalarTool(N, L) vt = VectorTool(N, L) v = vt.div_free_proj(v) v = vt.dealias(v) curl = vt.curl(v) a = st.l2norm(curl)**2. b = st.sint(np.sum(-vt.lap(v) * v, 0)) assert np.allclose(a, b)