def test_init_vals(self) -> None: field = self.initial_set() self.assertEqual(field.pdf.shape, self.init_pdf.shape) self.assertEqual(field.velocity.shape, self.init_vel.shape) self.assertEqual(field.density.shape, self.init_density.shape) self.assertAlmostEqual(abssum(field.pdf, self.init_pdf), 0.0, places=1) self.assertAlmostEqual(abssum(field.velocity, self.init_vel), 0.0, places=1) self.assertAlmostEqual(abssum(field.density, self.init_density), 0.0, places=1)
def test_sinusoidal_velocity(self) -> None: lattice_grid_shape = (3, 3) ans = np.array([0.0, 0.008660254037844387, -0.008660254037844384] * 3).reshape(lattice_grid_shape) ans = np.dstack([ans, np.zeros(lattice_grid_shape)]) density, vel = sinusoidal_velocity(lattice_grid_shape=(3, 3), epsilon=0.01) self.assertAlmostEqual(abssum(density, np.ones(lattice_grid_shape)), 0.0, places=1) self.assertAlmostEqual(abssum(vel, ans), 0.0, places=1)
def test_sinusoidal_density(self) -> None: lattice_grid_shape = (3, 3) ans = np.array([0.5, 0.50866025, 0.49133975] * 3).reshape(lattice_grid_shape).T density, vel = sinusoidal_density(lattice_grid_shape=(3, 3), epsilon=0.01, rho0=0.5) self.assertAlmostEqual(abssum(density, ans), 0.0, places=1) self.assertAlmostEqual(abssum(vel, np.zeros((*lattice_grid_shape, 2))), 0.0, places=1)
def test_lattice_boltzmann_step(self) -> None: field = self.initial_set() field.lattice_boltzmann_step() ans = TestOutputs.pdf_boltzmann self.assertEqual(field.pdf.shape, ans.shape) self.assertAlmostEqual(abssum(field.pdf, ans), 0.0, places=1)
def test_apply_local_equilibrium(self) -> None: field = self.initial_set() field._apply_local_equilibrium() ans = TestOutputs.pdf_eq_update self.assertEqual(field.pdf_eq.shape, ans.shape) self.assertAlmostEqual(abssum(field.pdf_eq, ans), 0.0, places=1)
def test_update_velocity(self) -> None: field = self.initial_set() field.update_density() field.update_velocity() ans = TestOutputs.velocity_update self.assertEqual(field.velocity.shape, ans.shape) self.assertAlmostEqual(abssum(field.velocity, ans), 0.0, places=1)
def test_periodic_boundary_conditions(self) -> None: field, _, _, pbc = self.initial_set() field.local_equilibrium_pdf_update() for _ in range(100): field.lattice_boltzmann_step( boundary_handling=pbc.boundary_handling) ans = TestOutputs.pdf_pbc self.assertEqual(field.pdf.shape, ans.shape) self.assertAlmostEqual(abssum(field.pdf, ans), 0.0, places=1)
def test_moving_wall(self) -> None: field, _, moving_wall, _ = self.initial_set() field.local_equilibrium_pdf_update() for _ in range(100): field.lattice_boltzmann_step( boundary_handling=moving_wall.boundary_handling) ans = TestOutputs.pdf_moving_wall self.assertEqual(field.pdf.shape, ans.shape) self.assertAlmostEqual(abssum(field.pdf, ans), 0.0, places=1)