def bump_const_inflow_pressure_speed_outflow(Nx=49, Ny=17, num_timesteps=10, dt=0.1): X, Y = get_bump_grid(N) grid = MultiblockGrid([(X, Y)]) sbp = MultiblockSBP(grid, accuracy=2) initu = np.array([np.ones(X.shape)]) initv = np.array([np.zeros(X.shape)]) initp = np.array([np.ones(X.shape)]) plt.quiver(X, Y, initu[0], initv[0]) plt.show() def spatial_op(state): S,J = euler_operator(sbp, state) + \ inflow_operator(sbp, state, 0, 'w', -1, 0) + \ outflow_operator(sbp, state, 0, 'e') + \ wall_operator(sbp, state, 0, 's') + \ wall_operator(sbp, state, 0, 'n') return S, J U, V, P = solve(grid, spatial_op, initu, initv, initp, dt, num_timesteps) return grid, U, V, P, dt
def circle_sector_cavity_flow(N=40, num_timesteps=30, dt=0.1, angle=0.5 * np.pi): (X, Y) = get_circle_sector_grid(N, 0.0, angle, 0.2, 1.0) grid = MultiblockGrid([(X, Y)]) sbp = MultiblockSBP(grid, accuracy=2) initu, initv, initp = get_gauss_initial_data(X, Y, 0.4, 0.4) plt.quiver(X, Y, initu[0], initv[0]) plt.show() def spatial_op(state): S,J = euler_operator(sbp, state) + \ wall_operator(sbp, state, 0, 'w') + \ wall_operator(sbp, state, 0, 'e') + \ wall_operator(sbp, state, 0, 's') + \ wall_operator(sbp, state, 0, 'n') return S, J U, V, P = solve(grid, spatial_op, initu, initv, initp, dt, num_timesteps) return grid, U, V, P, dt
def square_pressure_speed_outflow_everywhere(N=30, num_timesteps=10, dt=0.1): (X, Y) = np.meshgrid(np.linspace(0, 1, N), np.linspace(0, 1, N)) X = np.transpose(X) Y = np.transpose(Y) grid = MultiblockGrid([(X, Y)]) sbp = MultiblockSBP(grid, accuracy=2) initu, initv, initp = get_gauss_initial_data(X, Y, 0.5, 0.5) plt.quiver(X, Y, initu[0], initv[0]) plt.show() def spatial_op(state): S,J = euler_operator(sbp, state) + \ outflow_operator(sbp, state, 0, 'w') + \ outflow_operator(sbp, state, 0, 'e') + \ outflow_operator(sbp, state, 0, 's') + \ outflow_operator(sbp, state, 0, 'n') return S, J U, V, P = solve(grid, spatial_op, initu, initv, initp, dt, num_timesteps) return grid, U, V, P, dt
def bump_walls_and_pressure_speed_outflow(Nx=49, Ny=17, num_timesteps=10, dt=0.1): X, Y = get_bump_grid(N) grid = MultiblockGrid([(X, Y)]) sbp = MultiblockSBP(grid, accuracy=2) initu, initv, initp = get_gauss_initial_data(X, Y, -0.5, 0.4) plt.quiver(X, Y, initu[0], initv[0]) plt.show() def spatial_op(state): S,J = euler_operator(sbp, state) + \ wall_operator(sbp, state, 0, 'w') + \ outflow_operator(sbp, state, 0, 'e') + \ wall_operator(sbp, state, 0, 's') + \ wall_operator(sbp, state, 0, 'n') return S, J U, V, P = solve(grid, spatial_op, initu, initv, initp, dt, num_timesteps) return grid, U, V, P, dt
class TestJacobians(unittest.TestCase): (X, Y) = get_circle_sector_grid(3, 0.0, 3.14 / 2, 0.2, 1.0) grid = MultiblockGrid([(X, Y)]) sbp = MultiblockSBP(grid) U = X V = Y P = X**2 + Y**2 state = np.array([U, V, P]).flatten() def test_euler_jacobian(self): S, J = euler_operator(self.sbp, self.state) for i, grad in enumerate(J): f = lambda x: euler_operator(self.sbp, x)[0][i] grad_approx = approx_fprime(self.state, f, 1e-8) grad_exact = J[i, :] err = np.linalg.norm(grad_approx - grad_exact, ord=np.inf) print("Euler OP, Gradient error = {:.2e}".format(err)) self.assertTrue(err < 1e-5) def test_wall_jacobian(self): S, J = wall_operator(self.sbp, self.state, 0, 'w') J = J.todense() for i, grad in enumerate(J): f = lambda x: wall_operator(self.sbp, x, 0, 'w')[0][i] grad_approx = approx_fprime(self.state, f, 1e-8) grad_exact = J[i, :] err = np.linalg.norm(grad_approx - grad_exact, ord=np.inf) print("Wall SAT, Gradient error = {:.2e}".format(err)) self.assertTrue(err < 1e-5) def test_pressure_jacobian(self): S, J = pressure_operator(self.sbp, self.state, 0, 'w') J = J.todense() for i, grad in enumerate(J): f = lambda x: pressure_operator(self.sbp, x, 0, 'w')[0][i] grad_approx = approx_fprime(self.state, f, 1e-8) grad_exact = J[i, :] err = np.linalg.norm(grad_approx - grad_exact, ord=np.inf) print("Pressure SAT, Gradient error = {:.2e}".format(err)) self.assertTrue(err < 1e-5) def test_inflow_jacobian(self): S, J = inflow_operator(self.sbp, self.state, 0, 'w', -1, 1) J = J.todense() for i, grad in enumerate(J): f = lambda x: inflow_operator(self.sbp, x, 0, 'w', -1, 1)[0][i] grad_approx = approx_fprime(self.state, f, 1e-8) grad_exact = J[i, :] err = np.linalg.norm(grad_approx - grad_exact, ord=np.inf) print("Inflow SAT, Gradient error = {:.2e}".format(err)) self.assertTrue(err < 1e-5) def test_outflow_jacobian(self): S, J = outflow_operator(self.sbp, self.state, 0, 'w') J = J.todense() for i, grad in enumerate(J): f = lambda x: outflow_operator(self.sbp, x, 0, 'w')[0][i] grad_approx = approx_fprime(self.state, f, 1e-8) grad_exact = J[i, :] err = np.linalg.norm(grad_approx - grad_exact, ord=np.inf) print("Outflow SAT, Gradient error = {:.2e}".format(err)) self.assertTrue(err < 1e-5)