Пример #1
0
def maketopo():
    """
    Output topography file for the entire domain
    """
    nxpoints=200
    nypoints=200
    xupper=2.e0
    yupper=2.e0
    xlower = -2.e0
    ylower = -2.e0
    outfile= "bowl.topotype2"
    topography = Topography(topo_func=topo)
    topography.x = linspace(xlower,xupper,nxpoints)
    topography.y = linspace(ylower,yupper,nypoints)
    topography.write(outfile, topo_type=2, Z_format="%22.15e")
Пример #2
0
def makeqinit():
    """
    Create qinit data file
    """
    nxpoints = 101
    nypoints = 101
    xlower = -100.e0
    xupper = 100.e0
    yupper = 100.e0
    ylower = -100.e0
    outfile= "hump.xyz"     

    topography = Topography(topo_func=qinit)
    topography.x = linspace(xlower,xupper,nxpoints)
    topography.y = linspace(ylower,yupper,nypoints)
    topography.write(outfile, topo_type=1)
Пример #3
0
def maketopo2():
    """
    Another topo file for testing
    """
    nxpoints=21
    nypoints=51
    xlower = -0.5
    xupper= -0.3
    ylower = -0.1
    yupper= 0.4
    outfile= "topo2.topotype2"
    topography = Topography(topo_func=topo2)
    topography.x = numpy.linspace(xlower,xupper,nxpoints)
    topography.y = numpy.linspace(ylower,yupper,nypoints)
    topography.write(outfile, topo_type=2, Z_format="%22.15e")
    dx = (xupper-xlower)/(nxpoints-1)
    dy = (yupper-ylower)/(nypoints-1)
    print "==> topo2 has dx = %g, dy = %g" % (dx,dy)
Пример #4
0
def maketopo():
    """
    Output topography file for the entire domain
    """
    nxpoints=201
    nypoints=201
    xlower = -10e0
    xupper= 10e0
    ylower = -10e0
    yupper= 10e0
    outfile= "topo1.topotype2"
    topography = Topography(topo_func=topo)
    topography.x = numpy.linspace(xlower,xupper,nxpoints)
    topography.y = numpy.linspace(ylower,yupper,nypoints)
    topography.write(outfile, topo_type=2, Z_format="%22.15e")
    dx = (xupper-xlower)/(nxpoints-1)
    dy = (yupper-ylower)/(nypoints-1)
    print "==> topo1 has dx = %g, dy = %g" % (dx,dy)
Пример #5
0
    def generate(self, topo_func):
        from clawpack.geoclaw.topotools import Topography

        topography = Topography(topo_func=topo_func)
        topography.x = np.linspace(self.xlower, self.xupper, self.nxpoints)
        topography.y = np.linspace(self.ylower, self.yupper, self.nypoints)
        topography.write(self.outfile,
                         topo_type=self.topo_type,
                         Z_format="%22.15e")
Пример #6
0
def maketopo():
    """
    Output topography file for the entire domain
    """
    nxpoints = 200
    nypoints = 200
    xupper = 2.e0
    yupper = 2.e0
    xlower = -2.e0
    ylower = -2.e0
    outfile = "bowl.topotype2"
    topography = Topography(topo_func=topo)
    topography.x = linspace(xlower, xupper, nxpoints)
    topography.y = linspace(ylower, yupper, nypoints)
    topography.write(outfile, topo_type=2, Z_format="%22.15e")
Пример #7
0
def maketopo():
    """
    Output topography file for the entire domain
    """
    nxpoints = 201
    nypoints = 241
    xlower = 0.e0
    xupper = 100.e0
    ylower = 0.e0
    yupper = 50.e0
    outfile = "island.tt3"

    topography = Topography(topo_func=topo)
    topography.x = linspace(xlower, xupper, nxpoints)
    topography.y = linspace(ylower, yupper, nypoints)
    topography.write(outfile, topo_type=3, Z_format="%22.15e")
Пример #8
0
def makeqinit():
    """
    Create qinit data file
    """
    nxpoints = 101
    nypoints = 101
    xlower = -50.e0
    xupper = 50.e0
    yupper = 50.e0
    ylower = -50.e0
    outfile = "hump.xyz"

    topography = Topography(topo_func=qinit)
    topography.x = linspace(xlower, xupper, nxpoints)
    topography.y = linspace(ylower, yupper, nypoints)
    topography.write(outfile, topo_type=1)
Пример #9
0
def maketopo():
    """
    Output topography file for the entire domain
    """
    nxpoints=600
    nypoints=15
    xupper=domain_x
    yupper=domain_y/2.0
    xlower = 0.e0
    ylower = -domain_y/2.0
    outfile= "channel.topotype2"

    topography = Topography(topo_func=topo)
    topography.x = linspace(xlower,xupper,nxpoints)
    topography.y = linspace(ylower,yupper,nypoints)
    topography.write(outfile, topo_type=2, Z_format="%22.15e")
Пример #10
0
def maketopo2():
    """
    Another topo file for testing
    """
    nxpoints = 21
    nypoints = 51
    xlower = -0.5
    xupper = -0.3
    ylower = -0.1
    yupper = 0.4
    outfile = "topo2.topotype2"
    topography = Topography(topo_func=topo2)
    topography.x = numpy.linspace(xlower, xupper, nxpoints)
    topography.y = numpy.linspace(ylower, yupper, nypoints)
    topography.write(outfile, topo_type=2, Z_format="%22.15e")
    dx = (xupper - xlower) / (nxpoints - 1)
    dy = (yupper - ylower) / (nypoints - 1)
    print("==> topo2 has dx = %g, dy = %g" % (dx, dy))
Пример #11
0
def maketopo():
    """
    Output topography file for the entire domain
    """
    nxpoints = 201
    nypoints = 201
    xlower = -10e0
    xupper = 10e0
    ylower = -10e0
    yupper = 10e0
    outfile = "topo1.topotype2"
    topography = Topography(topo_func=topo)
    topography.x = numpy.linspace(xlower, xupper, nxpoints)
    topography.y = numpy.linspace(ylower, yupper, nypoints)
    topography.write(outfile, topo_type=2, Z_format="%22.15e")
    dx = (xupper - xlower) / (nxpoints - 1)
    dy = (yupper - ylower) / (nypoints - 1)
    print("==> topo1 has dx = %g, dy = %g" % (dx, dy))
Пример #12
0
def integral_topotool(func, mfile, funcflag):
    r"""
    integral_topotool is used for testing a set of functions which compute
    cell integrals and cell averages in topotools.py.
    
    :Input:
     - *func* (function).
     - *mfile* (int) The number of the topo objects.
     - *funcflag* (bool) Whether the function, "func" is discontinuous.
    """

    dx = []
    data = []
    topo = []
    mtopoorder = []

    # Set boundary for the coarsest topo
    xlow = 5
    xhi = 8
    xarray = numpy.linspace(xlow, xhi, mfile * 5)
    ylow = 2
    yhi = 5
    yarray = numpy.linspace(ylow, yhi, mfile * 5)

    # Set a set of topo data
    for i in range(mfile):
        if i == 0:

            # Set the topo data set which covers the whole patch
            x = xarray
            y = yarray
            dx.append(x[1] - x[0])
        else:

            # Set x coordinate of the topo data set
            n1 = int(3 * i)
            n2 = int(3 * i + 1.2 * mfile)
            x1 = xarray[n1]
            x2 = xarray[n2]
            dx.append(dx[i - 1] - 0.0012)
            mx = int((x2 - x1) / dx[i])
            x2 = x1 + dx[i] * (mx - 1)
            x = numpy.linspace(x1, x2, mx)

            # Set y coordinate of the topo data set
            m1 = int(3 * i)
            m2 = int(3 * i + 1.2 * mfile)
            y1 = yarray[m1]
            y2 = yarray[m2]
            my = int((y2 - y1) / dx[i])
            y2 = y1 + dx[i] * (my - 1)
            y = numpy.linspace(y1, y2, my)

        # Set Topography objects parameters
        topo1 = Topography()

        # Whether the function is discontinuous function
        if funcflag:
            z = numpy.empty((len(x), len(y)))
            for m in range(len(x)):
                for n in range(len(y)):
                    z[m][n] = func(x[m], y[n])
            topo1.Z = z
        else:
            topo_x, topo_y = numpy.meshgrid(x, y)
            topo1.Z = func(topo_x, topo_y)
        topo1.x = x
        topo1.y = y
        mtopoorder.append(mfile - 1 - i)
        topo.append(topo1)

    # Set patch data
    patch_x = numpy.linspace(xlow + 0.1, xhi - 0.1, 5)
    patch_y = numpy.linspace(ylow + 0.1, yhi - 0.1, 4)
    patch = {'x': patch_x, 'y': patch_y}

    # Accurate cell value
    real_value = numpy.empty((len(patch['y']) - 1, len(patch['x']) - 1))
    for i in range(len(patch['y']) - 1):
        for j in range(len(patch['x']) - 1):
            area = (patch['x'][j + 1] - patch['x'][j]) * (patch['y'][i + 1] -
                                                          patch['y'][i])
            if funcflag:
                options = {'limit': 1000}
                real_value[i][j] = nquad(
                    func=func,
                    ranges=[[patch['x'][j], patch['x'][j + 1]],
                            [patch['y'][i], patch['y'][i + 1]]],
                    args=None,
                    opts=[options, options])[0] / float(area)
            else:
                real_value[i][j] = dblquad(
                    func=func,
                    a=patch['y'][i],
                    b=patch['y'][i + 1],
                    gfun=patch['x'][j],
                    hfun=patch['x'][j + 1])[0] / float(area)

    # Cell value calculated by functions
    calculated_value = topotools.cell_average_patch(patch, mtopoorder, mfile,
                                                    topo)

    # Whether calculated value achieve the expected resolution
    npt.assert_almost_equal(real_value, calculated_value, decimal=3)
    return None