Esempio n. 1
0
def test_edge_coeffs():
    # make dx = dy = 1 so the normalization is trivial
    g = patch.Grid2d(4, 6, ng=2, xmax=4, ymax=6)

    # we'll fill ghost cells ourself
    b = np.arange(g.qx, dtype=np.float64)

    eta1 = g.scratch_array()
    eta1.d[:, :] = b[:, np.newaxis]

    e1 = edge_coeffs.EdgeCoeffs(g, eta1)

    assert_array_equal(e1.x.d[:, g.jc],
                       np.array([0., 0., 1.5, 2.5, 3.5, 4.5, 5.5, 0.]))

    b = np.arange(g.qy, dtype=np.float64)

    eta2 = g.scratch_array()
    eta2.d[:, :] = b[np.newaxis, :]

    e2 = edge_coeffs.EdgeCoeffs(g, eta2)

    assert_array_equal(
        e2.y.d[g.ic, :],
        np.array([0., 0., 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 0.]))
Esempio n. 2
0
    def __init__(self,
                 nx,
                 ny,
                 xmin=0.0,
                 xmax=1.0,
                 ymin=0.0,
                 ymax=1.0,
                 xl_BC_type="dirichlet",
                 xr_BC_type="dirichlet",
                 yl_BC_type="dirichlet",
                 yr_BC_type="dirichlet",
                 xl_BC=None,
                 xr_BC=None,
                 yl_BC=None,
                 yr_BC=None,
                 nsmooth=10,
                 nsmooth_bottom=50,
                 verbose=0,
                 coeffs=None,
                 true_function=None,
                 vis=0,
                 vis_title=""):
        """
        here, coeffs is a CCData2d object
        """

        # we'll keep a list of the beta coefficients averaged to the
        # interfaces on each level -- note: these will already be
        # scaled by 1/dx**2
        self.beta_edge = []

        # initialize the MG object with the auxillary fields
        MG.CellCenterMG2d.__init__(
            self,
            nx,
            ny,
            ng=1,
            xmin=xmin,
            xmax=xmax,
            ymin=ymin,
            ymax=ymax,
            xl_BC_type=xl_BC_type,
            xr_BC_type=xr_BC_type,
            yl_BC_type=yl_BC_type,
            yr_BC_type=yr_BC_type,
            xl_BC=xl_BC,
            xr_BC=xr_BC,
            yl_BC=yl_BC,
            yr_BC=yr_BC,
            alpha=0.0,
            beta=0.0,
            nsmooth=nsmooth,
            nsmooth_bottom=nsmooth_bottom,
            verbose=verbose,
            aux_field=["alpha", "beta", "gamma_x", "gamma_y"],
            aux_bc=[
                coeffs.BCs["alpha"], coeffs.BCs["beta"], coeffs.BCs["gamma_x"],
                coeffs.BCs["gamma_y"]
            ],
            true_function=true_function,
            vis=vis,
            vis_title=vis_title)

        # the coefficents come in a dictionary.  Set the coefficients
        # and restrict them down the hierarchy we only need to do this
        # once.  We need to hold the original coeffs in our grid so we
        # can do a ghost cell fill.
        for c in ["alpha", "beta", "gamma_x", "gamma_y"]:
            v = self.grids[self.nlevels - 1].get_var(c)
            v.v()[:, :] = coeffs.get_var(c).v()

            self.grids[self.nlevels - 1].fill_BC(c)

            n = self.nlevels - 2
            while n >= 0:
                f_patch = self.grids[n + 1]
                c_patch = self.grids[n]

                coeffs_c = c_patch.get_var(c)
                coeffs_c.v()[:, :] = f_patch.restrict(c).v()

                self.grids[n].fill_BC(c)
                n -= 1

        # put the beta coefficients on edges
        beta = self.grids[self.nlevels - 1].get_var("beta")
        self.beta_edge.insert(
            0, ec.EdgeCoeffs(self.grids[self.nlevels - 1].grid, beta))

        n = self.nlevels - 2
        while n >= 0:
            self.beta_edge.insert(0, self.beta_edge[0].restrict())
            n -= 1
Esempio n. 3
0
    def __init__(self, nx, ny, xmin=0.0, xmax=1.0, ymin=0.0, ymax=1.0,
                 xl_BC_type="dirichlet", xr_BC_type="dirichlet",
                 yl_BC_type="dirichlet", yr_BC_type="dirichlet",
                 nsmooth=10, nsmooth_bottom=50,
                 verbose=0,
                 coeffs=None, coeffs_bc=None,
                 true_function=None, vis=0, vis_title=""):

        # we'll keep a list of the coefficients averaged to the interfaces
        # on each level -- note: this will already be scaled by 1/dx**2
        self.edge_coeffs = []

        # initialize the MG object with the auxillary "coeffs" field
        MG.CellCenterMG2d.__init__(self, nx, ny, ng=1,
                                   xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
                                   xl_BC_type=xl_BC_type, xr_BC_type=xr_BC_type,
                                   yl_BC_type=yl_BC_type, yr_BC_type=yr_BC_type,
                                   alpha=0.0, beta=0.0,
                                   nsmooth=nsmooth, nsmooth_bottom=nsmooth_bottom,
                                   verbose=verbose,
                                   aux_field=["coeffs"], aux_bc=[coeffs_bc],
                                   true_function=true_function, vis=vis,
                                   vis_title=vis_title)


        # set the coefficients and restrict them down the hierarchy
        # we only need to do this once.  We need to hold the original
        # coeffs in our grid so we can do a ghost cell fill.
        c = self.grids[self.nlevels-1].get_var("coeffs")
        c.v()[:,:] = coeffs.v().copy()

        self.grids[self.nlevels-1].fill_BC("coeffs")

        # put the coefficients on edges
        self.edge_coeffs.insert(0, ec.EdgeCoeffs(self.grids[self.nlevels-1].grid, c))

        n = self.nlevels-2
        while n >= 0:

            # create the edge coefficients on level n by restricting from the
            # finer grid
            f_patch = self.grids[n+1]
            c_patch = self.grids[n]

            coeffs_c = c_patch.get_var("coeffs")
            coeffs_c.v()[:,:] = f_patch.restrict("coeffs").v()

            self.grids[n].fill_BC("coeffs")

            # put the coefficients on edges
            self.edge_coeffs.insert(0, self.edge_coeffs[0].restrict())  #_EdgeCoeffs(self.grids[n].grid, coeffs_c))

            # if we are periodic, then we should force the edge coefficents
            # to be periodic
            # if self.grids[n].BCs["coeffs"].xlb == "periodic":
            #     self.edge_coeffs[0].x[self.grids[n].grid.ihi+1,:] = \
            #         self.edge_coeffs[0].x[self.grids[n].grid.ilo,:]

            # if self.grids[n].BCs["coeffs"].ylb == "periodic":
            #     self.edge_coeffs[0].y[:,self.grids[n].grid.jhi+1] = \
            #         self.edge_coeffs[0].y[:,self.grids[n].grid.jlo]

            n -= 1