def test_ghost_zone_extrapolation():
    ds = fake_random_ds(16)

    g = ds.index.grids[0]
    for i, ax in enumerate('xyz'):
        xc = g[ax]

        xv = g.get_vertex_centered_data(ax, no_ghost=True)
        tf = lin.TrilinearFieldInterpolator(xc,
                (g.LeftEdge[0] + g.dds[0]/2.0,
                    g.RightEdge[0] - g.dds[0]/2.0,
                 g.LeftEdge[1] + g.dds[1]/2.0,
                    g.RightEdge[1] - g.dds[1]/2.0,
                 g.LeftEdge[2] + g.dds[2]/2.0,
                    g.RightEdge[2] - g.dds[2]/2.0),
                ["x", "y", "z"], truncate = True)

        lx,ly,lz = np.mgrid[g.LeftEdge[0]:g.RightEdge[0]:(g.ActiveDimensions[0]+1)*1j,
                            g.LeftEdge[1]:g.RightEdge[1]:(g.ActiveDimensions[1]+1)*1j,
                            g.LeftEdge[2]:g.RightEdge[2]:(g.ActiveDimensions[2]+1)*1j]
        xi  = tf({'x':lx, 'y':ly, 'z':lz})

        xz = np.zeros(g.ActiveDimensions+1)
        ghost_zone_interpolate(1, xc, np.array([0.5, 0.5, 0.5], dtype="f8"),
                                  xz, np.array([0.0, 0.0, 0.0], dtype="f8"))

        ii = (lx, ly, lz)[i]
        yield assert_array_equal, ii, xv
        yield assert_array_equal, ii, xi
        yield assert_array_equal, ii, xz
Esempio n. 2
0
    def get_vertex_centered_data(self, field, smoothed=True, no_ghost=False):
        new_field = np.zeros(self.ActiveDimensions + 1, dtype='float64')

        if no_ghost:
            # Ensure we have the native endianness in this array.  Avoid making
            # a copy if possible.
            old_field = np.asarray(self[field], dtype="=f8")
            # We'll use the ghost zone routine, which will naturally
            # extrapolate here.
            input_left = np.array([0.5, 0.5, 0.5], dtype="float64")
            output_left = np.array([0.0, 0.0, 0.0], dtype="float64")
            # rf = 1 here
            ghost_zone_interpolate(1, old_field, input_left,
                                   new_field, output_left)
        else:
            cg = self.retrieve_ghost_zones(1, field, smoothed=smoothed)
            np.add(new_field, cg[field][1: ,1: ,1: ], new_field)
            np.add(new_field, cg[field][:-1,1: ,1: ], new_field)
            np.add(new_field, cg[field][1: ,:-1,1: ], new_field)
            np.add(new_field, cg[field][1: ,1: ,:-1], new_field)
            np.add(new_field, cg[field][:-1,1: ,:-1], new_field)
            np.add(new_field, cg[field][1: ,:-1,:-1], new_field)
            np.add(new_field, cg[field][:-1,:-1,1: ], new_field)
            np.add(new_field, cg[field][:-1,:-1,:-1], new_field)
            np.multiply(new_field, 0.125, new_field)

        return new_field
    def get_vertex_centered_data(self, field, smoothed=True, no_ghost=False):
        new_field = np.zeros(self.ActiveDimensions + 1, dtype="float64")

        if no_ghost:
            # Ensure we have the native endianness in this array.  Avoid making
            # a copy if possible.
            old_field = np.asarray(self[field], dtype="=f8")
            # We'll use the ghost zone routine, which will naturally
            # extrapolate here.
            input_left = np.array([0.5, 0.5, 0.5], dtype="float64")
            output_left = np.array([0.0, 0.0, 0.0], dtype="float64")
            # rf = 1 here
            ghost_zone_interpolate(1, old_field, input_left, new_field, output_left)
        else:
            cg = self.retrieve_ghost_zones(1, field, smoothed=smoothed)
            np.add(new_field, cg[field][1:, 1:, 1:], new_field)
            np.add(new_field, cg[field][:-1, 1:, 1:], new_field)
            np.add(new_field, cg[field][1:, :-1, 1:], new_field)
            np.add(new_field, cg[field][1:, 1:, :-1], new_field)
            np.add(new_field, cg[field][:-1, 1:, :-1], new_field)
            np.add(new_field, cg[field][1:, :-1, :-1], new_field)
            np.add(new_field, cg[field][:-1, :-1, 1:], new_field)
            np.add(new_field, cg[field][:-1, :-1, :-1], new_field)
            np.multiply(new_field, 0.125, new_field)

        return new_field