def full_focus(): focus = pygridgen.Focus() focus.add_focus(0.25, 'x', factor=3, extent=0.1) focus.add_focus(0.75, 'x', factor=2, extent=0.2) focus.add_focus(0.50, 'y', factor=2, extent=0.3) return focus
def test_gridgen_to_from_spec(use_focus): x = numpy.array([0.50, 2.00, 2.00, 3.50, 3.50, 2.00, 2.00, 0.50, 0.50]) y = numpy.array([0.50, 0.50, 1.75, 1.75, 2.25, 2.25, 3.50, 3.50, 0.50]) beta = numpy.array([1, 1, -1, 1, 1, -1, 1, 1, 0]) focus = None if use_focus: focus = pygridgen.Focus() focus.add_focus(0.50, 'y', factor=5, extent=0.25) focus.add_focus(0.50, 'x', factor=5, extent=0.25) grid1 = pygridgen.Gridgen(x, y, beta, shape=(20, 10), focus=focus) grid2 = pygridgen.grid.Gridgen.from_spec((grid1.to_spec())) # testing - using almost equal due to rounding issues with floats numpy.testing.assert_array_almost_equal(grid1.x, grid2.x) numpy.testing.assert_array_almost_equal(grid1.y, grid2.y)
def test_gridgen_to_from_spec(simple_grid, use_focus): x = numpy.array([0.50, 2.00, 2.00, 3.50, 3.50, 2.00, 2.00, 0.50, 0.50]) y = numpy.array([0.50, 0.50, 1.75, 1.75, 2.25, 2.25, 3.50, 3.50, 0.50]) beta = numpy.array([1, 1, -1, 1, 1, -1, 1, 1, 0]) if use_focus: focus = pygridgen.Focus() focus.add_focus(0.50, 'y', factor=5, extent=0.25) focus.add_focus(0.50, 'x', factor=5, extent=0.25) simple_grid.focus = focus simple_grid.generate_grid() grid2 = pygridgen.grid.Gridgen.from_spec((simple_grid.to_spec())) # testing - using almost equal due to rounding issues with floats numpy.testing.assert_array_almost_equal(simple_grid.x, grid2.x) numpy.testing.assert_array_almost_equal(simple_grid.y, grid2.y)
def make_focus(): focus = pygridgen.Focus() focus.add_focus(0.50, 'x', factor=2.0, extent=3.0) focus.add_focus(0.75, 'y', factor=0.5, extent=2.0) return focus
def setup(self): self.x = [0.0, 1.0, 2.0, 1.0, 0.0] self.y = [0.0, 0.0, 0.5, 1.0, 1.0] self.beta = [1.0, 1.0, 0.0, 1.0, 1.0] self.shape = (9, 9) focus = pygridgen.Focus() focus.add_focus_x(0.50, factor=2.0, Rx=3.0) focus.add_focus_y(0.75, factor=0.5, Ry=2.0) self.options = {'ul_idx': 0, 'focus': focus} self.grid = self.make_grid() self.known_x = np.array( [[1., 1.04, 1.12, 1.27, 2., 1.27, 1.12, 1.04, 1.], [0.95, 0.97, 1.02, 1.1, 1.15, 1.1, 1.02, 0.97, 0.95], [0.86, 0.87, 0.89, 0.92, 0.93, 0.92, 0.89, 0.87, 0.86], [0.73, 0.74, 0.75, 0.76, 0.76, 0.76, 0.75, 0.74, 0.73], [0.59, 0.59, 0.6, 0.6, 0.6, 0.6, 0.6, 0.59, 0.59], [0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45], [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3], [0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15], [0., 0., 0., 0., 0., 0., 0., 0., 0.]]) self.known_y = np.array( [[0., 0.02, 0.06, 0.14, 0.5, 0.86, 0.94, 0.98, 1.], [-0., 0.07, 0.16, 0.3, 0.5, 0.7, 0.84, 0.93, 1.], [-0., 0.1, 0.21, 0.35, 0.5, 0.65, 0.79, 0.9, 1.], [-0., 0.12, 0.24, 0.37, 0.5, 0.63, 0.76, 0.88, 1.], [-0., 0.12, 0.25, 0.37, 0.5, 0.63, 0.75, 0.88, 1.], [-0., 0.12, 0.25, 0.37, 0.5, 0.63, 0.75, 0.88, 1.], [-0., 0.13, 0.25, 0.38, 0.5, 0.62, 0.75, 0.87, 1.], [-0., 0.13, 0.25, 0.38, 0.5, 0.62, 0.75, 0.87, 1.], [-0., 0.13, 0.25, 0.38, 0.5, 0.62, 0.75, 0.87, 1.]]) self.known_x_psi = np.array( [[0.97, 1.02, 1.1, 1.15, 1.1, 1.02, 0.97], [0.87, 0.89, 0.92, 0.93, 0.92, 0.89, 0.87], [0.74, 0.75, 0.76, 0.76, 0.76, 0.75, 0.74], [0.59, 0.6, 0.6, 0.6, 0.6, 0.6, 0.59], [0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45], [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3], [0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15]]) self.known_y_psi = np.array([[0.07, 0.16, 0.3, 0.5, 0.7, 0.84, 0.93], [0.1, 0.21, 0.35, 0.5, 0.65, 0.79, 0.9], [0.12, 0.24, 0.37, 0.5, 0.63, 0.76, 0.88], [0.12, 0.25, 0.37, 0.5, 0.63, 0.75, 0.88], [0.12, 0.25, 0.37, 0.5, 0.63, 0.75, 0.88], [0.13, 0.25, 0.38, 0.5, 0.62, 0.75, 0.87], [0.13, 0.25, 0.38, 0.5, 0.62, 0.75, 0.87]]) self.known_x_rho = np.array( [[0.99, 1.04, 1.13, 1.38, 1.38, 1.13, 1.04, 0.99], [0.91, 0.94, 0.98, 1.02, 1.02, 0.98, 0.94, 0.91], [0.8, 0.81, 0.83, 0.84, 0.84, 0.83, 0.81, 0.8], [0.66, 0.67, 0.68, 0.68, 0.68, 0.68, 0.67, 0.66], [0.52, 0.52, 0.52, 0.53, 0.53, 0.52, 0.52, 0.52], [0.37, 0.37, 0.37, 0.37, 0.37, 0.37, 0.37, 0.37], [0.22, 0.22, 0.22, 0.22, 0.22, 0.22, 0.22, 0.22], [0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07]]) self.known_y_rho = np.array( [[0.02, 0.08, 0.16, 0.36, 0.64, 0.84, 0.92, 0.98], [0.04, 0.14, 0.26, 0.41, 0.59, 0.74, 0.86, 0.96], [0.05, 0.17, 0.29, 0.43, 0.57, 0.71, 0.83, 0.95], [0.06, 0.18, 0.3, 0.43, 0.57, 0.7, 0.82, 0.94], [0.06, 0.19, 0.31, 0.44, 0.56, 0.69, 0.81, 0.94], [0.06, 0.19, 0.31, 0.44, 0.56, 0.69, 0.81, 0.94], [0.06, 0.19, 0.31, 0.44, 0.56, 0.69, 0.81, 0.94], [0.06, 0.19, 0.31, 0.44, 0.56, 0.69, 0.81, 0.94]]) self.known_x_u = np.array([[1., 1.07, 1.19, 1.57, 1.19, 1.07, 1.], [0.92, 0.96, 1.01, 1.04, 1.01, 0.96, 0.92], [0.8, 0.82, 0.84, 0.85, 0.84, 0.82, 0.8], [0.66, 0.67, 0.68, 0.68, 0.68, 0.67, 0.66], [0.52, 0.52, 0.53, 0.53, 0.53, 0.52, 0.52], [0.37, 0.37, 0.37, 0.38, 0.37, 0.37, 0.37], [0.22, 0.22, 0.22, 0.22, 0.22, 0.22, 0.22], [0.07, 0.07, 0.07, 0.07, 0.07, 0.07, 0.07]]) self.known_x_v = np.array( [[0.96, 1., 1.06, 1.12, 1.12, 1.06, 1., 0.96], [0.86, 0.88, 0.9, 0.92, 0.92, 0.9, 0.88, 0.86], [0.73, 0.74, 0.75, 0.76, 0.76, 0.75, 0.74, 0.73], [0.59, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.59], [0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45], [0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3], [0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.15]]) self.known_y_u = np.array([[0.04, 0.11, 0.22, 0.5, 0.78, 0.89, 0.96], [0.09, 0.19, 0.32, 0.5, 0.68, 0.81, 0.91], [0.11, 0.23, 0.36, 0.5, 0.64, 0.77, 0.89], [0.12, 0.24, 0.37, 0.5, 0.63, 0.76, 0.88], [0.12, 0.25, 0.37, 0.5, 0.63, 0.75, 0.88], [0.13, 0.25, 0.37, 0.5, 0.63, 0.75, 0.87], [0.13, 0.25, 0.38, 0.5, 0.62, 0.75, 0.87], [0.13, 0.25, 0.38, 0.5, 0.62, 0.75, 0.87]]) self.known_y_v = np.array( [[0.04, 0.12, 0.23, 0.4, 0.6, 0.77, 0.88, 0.96], [0.05, 0.16, 0.28, 0.42, 0.58, 0.72, 0.84, 0.95], [0.06, 0.18, 0.3, 0.43, 0.57, 0.7, 0.82, 0.94], [0.06, 0.18, 0.31, 0.44, 0.56, 0.69, 0.82, 0.94], [0.06, 0.19, 0.31, 0.44, 0.56, 0.69, 0.81, 0.94], [0.06, 0.19, 0.31, 0.44, 0.56, 0.69, 0.81, 0.94], [0.06, 0.19, 0.31, 0.44, 0.56, 0.69, 0.81, 0.94]])