示例#1
0
 def setUp(self):
     grid_size = 200
     self.grid = grids.Grid(grid_size, grid_size, 2 * np.pi / grid_size)
     self.finite_vol_eq = (
         advection_equations.FiniteVolumeAdvectionDiffusion(0.05))
     self.finite_diff_eq = (
         advection_equations.FiniteDifferenceAdvectionDiffusion(0.05))
     self.upwind_eq = (advection_equations.UpwindAdvectionDiffusion(0.05))
     self.base_vol_model = models.FiniteDifferenceModel(
         self.finite_vol_eq, self.grid)
     self.base_diff_model = models.FiniteDifferenceModel(
         self.finite_diff_eq, self.grid)
     self.base_upwind_model = models.FiniteDifferenceModel(
         self.upwind_eq, self.grid)
示例#2
0
    def test_integration_in_constant_velocity_field(self, equation, atol):
        grid = grids.Grid.from_period(100, length=100)
        model = models.FiniteDifferenceModel(equation, grid)

        initial_concentration = equations.symmetrized_gaussian(
            grid, 50, 50, gaussian_width=20)
        self.assertGreaterEqual(initial_concentration.min(), 0.0)
        self.assertLessEqual(initial_concentration.max(), 1.0 + 1e-7)

        initial_state = {
            'concentration': initial_concentration.astype(np.float32),
            'x_velocity': np.ones(grid.shape, np.float32),
            'y_velocity': np.zeros(grid.shape, np.float32)
        }
        steps = round(1 / equation.cfl_safety_factor) * np.arange(10)
        integrated = integrate.integrate_steps(model, initial_state, steps)
        actual = integrated['concentration'].numpy()
        expected = np.stack(
            [np.roll(initial_concentration, i, axis=0) for i in range(10)])
        np.testing.assert_allclose(actual, expected, atol=atol)
        if equation.METHOD is polynomials.Method.FINITE_VOLUME:
            np.testing.assert_allclose(actual[-1].sum(),
                                       actual[0].sum(),
                                       rtol=1e-7)
        else:
            np.testing.assert_allclose(actual[-1].sum(),
                                       actual[0].sum(),
                                       rtol=1e-3)
        if equation.MONOTONIC:
            self.assertGreaterEqual(actual[-1].min(), 0.0)
            self.assertLessEqual(actual[-1].max(), 1.0)
示例#3
0
 def coarse_model(self):
     return models.FiniteDifferenceModel(self.equation, self.output_grid)
示例#4
0
 def model(self):
     return models.FiniteDifferenceModel(self.equation,
                                         self.simulation_grid)