Beispiel #1
0
def plot_fgmax_transects():

    # === Transect on x-axis:
    fg = fgmax_tools.FGmaxGrid()
    fg.read_fgmax_grids_data(fgno=3)
    fg.read_output()

    plt.figure(3)
    plt.clf()

    surface = ma.masked_where(fg.h < dry_tolerance, fg.B + fg.h)
    sea_level = 0.
    surface_original = ma.masked_where(fg.B > 0,
                                       sea_level * numpy.ones(fg.B.shape))

    # distance along transect:
    xi = numpy.sqrt((fg.X - fg.X[0])**2 + (fg.Y - fg.Y[0])**2)

    plt.plot(xi, fg.B, 'g')  # topography
    plt.plot(xi, surface_original, 'k')
    plt.plot(xi, surface, 'b', label="along x-axis")

    # === Transect on diagonal:
    fg = fgmax_tools.FGmaxGrid()
    fg.read_fgmax_grids_data(fgno=4)
    fg.read_output()

    surface = ma.masked_where(fg.h < dry_tolerance, fg.B + fg.h)

    xi = numpy.sqrt((fg.X - fg.X[0])**2 + (fg.Y - fg.Y[0])**2)
    plt.plot(xi, surface, 'r', label="along diagonal")
    plt.legend(loc="lower right")

    plt.title("Max elevation along transects vs distance")

    # === Along shoreline:
    fg = fgmax_tools.FGmaxGrid()
    fg.read_fgmax_grids_data(fgno=5)
    fg.read_output()
    plt.figure(5)
    theta = numpy.arctan(fg.Y / fg.X)
    plt.plot(theta, fg.h, 'b')
    plt.xlim(-numpy.pi / 4, numpy.pi / 2)
    plt.ylim(1.7, 2.3)
    plt.grid(True)
    plt.title("Max elevation along shore (radius 90 m) vs angle\n" \
              + "only captured on Level 4 grids")
    plt.xticks([0, numpy.pi / 4.], ['0', 'pi/4'])
    plt.xlabel('theta')
    plt.ylabel('meters')
Beispiel #2
0
def plot_fgmax_grid(fname, fgno, xl, xu, yl, yu):
    """Plots the fg_max data using clawpack and creates a figure in the _plots directory"""
    xlower = xl
    xupper = xu
    ylower = yl
    yupper = yu

    fg = fgmax_tools.FGmaxGrid()
    fg.read_fgmax_grids_data(3)
    fg.read_output(fgno=fgno)

    clines_zeta = [0.01] + list(np.linspace(0.25, 6, 24))
    colors = geoplot.discrete_cmap_1(clines_zeta)
    zeta = np.where(fg.B > 0, fg.h, fg.h + fg.B)  # surface elevation in ocean

    fig, ax = gearth_fig(llcrnrlon=xlower,
                         llcrnrlat=ylower,
                         urcrnrlon=xupper,
                         urcrnrlat=yupper,
                         pixels=1024)

    ax.contourf(fg.X, fg.Y, zeta, clines_zeta, colors=colors, alpha=.90)
    ax.contour(fg.X, fg.Y, fg.B, [0.], colors='k')  # coastline
    # fix axes:
    ax.ticklabel_format(style='plain', useOffset=False)
    plt.xticks(rotation=20)
    plt.gca().set_aspect(1. / np.cos(fg.Y.mean() * np.pi / 180.))
    plt.title("Maximum amplitude")
    cs = ax.contourf(fg.X, fg.Y, zeta, clines_zeta, colors=colors)
    return (cs)
Beispiel #3
0
def plot_fgmax_grid():

    fg = fgmax_tools.FGmaxGrid()
    fg.read_fgmax_grids_data(fgno=1)
    fg.read_output()

    clines_zeta = [0.01] + list(numpy.linspace(0.05, 0.3,
                                               6)) + [0.5, 1.0, 10.0]
    colors = geoplot.discrete_cmap_1(clines_zeta)
    plt.figure(1)
    plt.clf()
    zeta = numpy.where(fg.B > 0, fg.h,
                       fg.h + fg.B)  # surface elevation in ocean
    plt.contourf(fg.X, fg.Y, zeta, clines_zeta, colors=colors)
    plt.colorbar()
    plt.contour(fg.X, fg.Y, fg.B, [0.], colors='k')  # coastline

    # plot arrival time contours and label:
    arrival_t = fg.arrival_time / 3600.  # arrival time in hours
    clines_t = numpy.linspace(0, 8, 17)  # hours
    clines_t_label = clines_t[2::2]  # which ones to label
    clines_t_colors = ([.5, .5, .5], )
    con_t = plt.contour(fg.X,
                        fg.Y,
                        arrival_t,
                        clines_t,
                        colors=clines_t_colors)
    plt.clabel(con_t, clines_t_label)

    # fix axes:
    plt.ticklabel_format(style='plain', useOffset=False)
    plt.xticks(rotation=20)
    plt.gca().set_aspect(1. / numpy.cos(fg.Y.mean() * numpy.pi / 180.))
    plt.title("Maximum amplitude / arrival times")
Beispiel #4
0
    def check_fgmax(self, save=False):
        r"""Basic test to assert fgmax equality
        Currently just records sum of fg.h and of fg.s.

        :Input:
         - *save* (bool) - If *True* will save the output from this test to 
           the file *regresion_data.txt*.  Default is *False*.
        """

        from clawpack.geoclaw import fgmax_tools

        fg = fgmax_tools.FGmaxGrid()
        fname = os.path.join(self.temp_path, 'fgmax1.txt')
        fg.read_input_data(fname)
        fg.read_output(outdir=self.temp_path)

        data_sum = numpy.array([fg.h.sum(), fg.s.sum()])

        # Get (and save) regression comparison data
        regression_data_file = os.path.join(self.test_path, "regression_data",
                "regression_data_fgmax.txt")
        if save:
            numpy.savetxt(regression_data_file, data_sum)
        regression_sum = numpy.loadtxt(regression_data_file)

        # Compare data
        tolerance = 1e-14
        assert numpy.allclose(data_sum, regression_sum, tolerance), \
                "\n data: %s, \n expected: %s" % (data_sum, regression_sum)
Beispiel #5
0
def plot_fgmax_grid(fgno):

    fg = fgmax_tools.FGmaxGrid()
    fname = 'fgmax_grid%s.txt' % fgno
    fg.read_input_data(fname)
    fg.read_output(fgno)

    clines_zeta = [0.01] + list(numpy.linspace(.3, 2.1, 7))
    colors = geoplot.discrete_cmap_1(clines_zeta)
    plt.figure(fgno)
    plt.clf()

    # set zeta = max depth on shore, max surface elevation offshore:
    zeta = numpy.where(fg.B > 0, fg.h, fg.h + fg.B)

    plt.contourf(fg.X, fg.Y, zeta, clines_zeta, colors=colors, extend='max')
    plt.colorbar(extend='max')
    #plt.contour(fg.X,fg.Y,fg.B,[0.],colors='k')  # coastline

    # plot original coastline extending beyond fgmax region:
    theta = numpy.linspace(-numpy.pi / 8., 3 / 8. * numpy.pi, 1000)
    plt.plot(90 * numpy.cos(theta), 90 * numpy.sin(theta), 'k')

    # fix axes:
    plt.ticklabel_format(format='plain', useOffset=False)
    plt.xticks(rotation=20)
    plt.gca().set_aspect(1. / numpy.cos(fg.Y.mean() * numpy.pi / 180.))
    plt.title("Zeta = max depth or surface elevation")
    plt.axis('scaled')
    if fgno == 1:
        plt.axis([85, 95, -5, 5])
    else:
        plt.axis([59, 69, 59, 69])
def make_fgmax_grid():
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2  # will specify a 2d grid of points
    fg.x1 = 32.
    fg.x2 = 42.
    fg.y1 = -6.
    fg.y2 = 3.
    fg.dx = 0.025
    fg.tstart_max = 25.  # when to start monitoring max values
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 0.05  # target time (sec) increment between updating
    # max values
    fg.min_level_check = 4  # which levels to monitor max on
    fg.arrival_tol = 1.e-2  # tolerance for flagging arrival

    fg.input_file_name = 'fgmax_grid.txt'
    fg.write_input_data()
def make_fgmax_grid():
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2       # will specify a 2d grid of points
    fg.x1 = 204.91 
    fg.x2 = 204.95
    fg.y1 = 19.72
    fg.y2 = 19.75
    fg.dx = 1./3600.    # 1 arcsecond
    fg.tstart_max =  1.5*3600.  # when to start monitoring max values
    fg.tend_max = 1.e10       # when to stop monitoring max values
    fg.dt_check = 10.         # target time (sec) increment between updating 
                               # max values
    fg.min_level_check = 2    # which levels to monitor max on
    fg.arrival_tol = 1.e-2    # tolerance for flagging arrival

    fg.input_file_name = 'fgmax_grid.txt'
    fg.write_input_data()
def make_fgmax_grid1(datadir):
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2  # will specify a 2d grid of points
    fg.x1 = -2.
    fg.x2 = 2.
    fg.y1 = -2.
    fg.y2 = 2.
    fg.dx = 0.1
    fg.tstart_max = 0.  # when to start monitoring max values
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 0.1  # target time (sec) increment between updating
    # max values
    fg.min_level_check = 2  # which levels to monitor max on
    fg.arrival_tol = 1.e-2  # tolerance for flagging arrival

    fg.input_file_name = os.path.join(datadir, 'fgmax1.txt')
    fg.write_input_data()
Beispiel #9
0
def make_fgmax_grid1():
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2  # will specify a 2d grid of points
    fg.x1 = 203.515
    fg.x2 = 203.545
    fg.y1 = 20.885
    fg.y2 = 20.905
    fg.dx = 1. / (3600.)  # 1 arcssecond grid
    fg.tstart_max = 7.9 * 3600.  # when to start monitoring max values
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 30.  # target time (sec) increment between updating
    # max values
    fg.min_level_check = 6  # which levels to monitor max on
    fg.arrival_tol = 1.e-2  # tolerance for flagging arrival

    fg.input_file_name = 'fgmax1.txt'
    fg.write_input_data()
Beispiel #10
0
def make_fgmax_grid():
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2  # will specify a 2d grid of points
    fg.x1 = -123.48  # west
    fg.x2 = -123.34  #east
    fg.y1 = 48.103  # south
    fg.y2 = 48.146  #north
    fg.dx = 0.000700  #resolution in degrees
    fg.tstart_max = 0  # when to start monitoring max values
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 0  # target time (sec) increment between updating
    # max values
    fg.min_level_check = 4  # which levels to monitor max on
    fg.arrival_tol = 1.e-2  # tolerance for flagging arrival

    fg.input_file_name = 'InundationMap.txt'  #White House
    fg.write_input_data()
Beispiel #11
0
def plot_fgmax_grid():

    fg = fgmax_tools.FGmaxGrid()
    fg.read_input_data('fgmax_grid1.txt')
    fg.read_output()

    #clines_zeta = [0.01] + list(numpy.linspace(0.05,0.3,6)) + [0.5,1.0,10.0]
    clines_zeta = [0.001] + list(numpy.linspace(0.05, 0.25, 10))
    colors = geoplot.discrete_cmap_1(clines_zeta)
    plt.figure(1)
    plt.clf()
    zeta = numpy.where(fg.B > 0, fg.h,
                       fg.h + fg.B)  # surface elevation in ocean
    plt.contourf(fg.X, fg.Y, zeta, clines_zeta, colors=colors)
    plt.colorbar()
    plt.contour(fg.X, fg.Y, fg.B, [0.], colors='k')  # coastline

    # draw better land
    import clawpack.geoclaw.topotools as tt
    topo = tt.Topography(path='../bathy/atlantic_2min.tt3')
    shore = topo.make_shoreline_xy()
    plt.plot(shore[:, 0], shore[:, 1], 'k', linewidth=10)

    # plot arrival time contours and label:
    arrival_t = fg.arrival_time / 3600.  # arrival time in hours
    #clines_t = numpy.linspace(0,8,17)  # hours
    clines_t = numpy.linspace(0, 2, 5)  # hours
    #clines_t_label = clines_t[::2]  # which ones to label
    clines_t_label = clines_t[::1]  # which ones to label
    clines_t_colors = ([.5, .5, .5], )
    con_t = plt.contour(fg.X,
                        fg.Y,
                        arrival_t,
                        clines_t,
                        colors=clines_t_colors)
    plt.clabel(con_t, clines_t_label)

    # fix axes:
    plt.ticklabel_format(format='plain', useOffset=False)
    plt.xticks(rotation=20)
    plt.gca().set_aspect(1. / numpy.cos(fg.Y.mean() * numpy.pi / 180.))
    plt.title("Maximum amplitude / arrival times (hrs)")
Beispiel #12
0
    times.append(t)
times.sort()
print('Output times found: ', times)
if len(times) > 0:
    t_hours = times[-1] / 3600.
    print(
        '\nfgmax results are presumably from final time: %.1f seconds = %.2f hours'
        % (times[-1], t_hours))
else:
    t_hours = nan

# In[8]:

# Read fgmax data:
fgno = 1
fg = fgmax_tools.FGmaxGrid()
fg.read_fgmax_grids_data(fgno)

fg.read_output(outdir=outdir)

# In[9]:

zmin = -60.
zmax = 20.
land_cmap = colormaps.make_colormap({
    0.0: [0.1, 0.4, 0.0],
    0.25: [0.0, 1.0, 0.0],
    0.5: [0.8, 1.0, 0.5],
    1.0: [0.8, 0.5, 0.2]
})
Beispiel #13
0
def setgeo(rundata):
    #-------------------
    """
    Set GeoClaw specific runtime parameters.
    For documentation see ....
    """

    try:
        geo_data = rundata.geo_data
    except:
        print("*** Error, this rundata has no geo_data attribute")
        raise AttributeError("Missing geo_data attribute")

    # == Physics ==
    geo_data.gravity = 9.81
    geo_data.coordinate_system = 1
    geo_data.earth_radius = 6367.5e3

    # == Forcing Options
    geo_data.coriolis_forcing = False

    # == Algorithm and Initial Conditions ==
    geo_data.sea_level = 0.0
    geo_data.dry_tolerance = 1.e-3
    geo_data.friction_forcing = True
    geo_data.manning_coefficient = 0.025
    geo_data.friction_depth = 20.0

    # Refinement data
    refinement_data = rundata.refinement_data
    refinement_data.wave_tolerance = 1.e-2
    refinement_data.deep_depth = 1e2
    refinement_data.max_level_deep = 3
    refinement_data.variable_dt_refinement_ratios = True

    # == settopo.data values ==
    topo_data = rundata.topo_data
    # for topography, append lines of the form
    #    [topotype, minlevel, maxlevel, t1, t2, fname]
    topo_data.topofiles.append([2, 1, 1, 0., 1.e10, 'bowl.topotype2'])

    # == setdtopo.data values ==
    dtopo_data = rundata.dtopo_data
    # for moving topography, append lines of the form :   (<= 1 allowed for now!)
    #   [topotype, minlevel,maxlevel,fname]

    # == setqinit.data values ==
    rundata.qinit_data.qinit_type = 4
    rundata.qinit_data.qinitfiles = []
    # for qinit perturbations, append lines of the form: (<= 1 allowed for now!)
    #   [minlev, maxlev, fname]
    rundata.qinit_data.qinitfiles.append([1, 2, 'hump.xyz'])

    # == fgmax_grids.data values ==
    # NEW STYLE STARTING IN v5.7.0

    # set num_fgmax_val = 1 to save only max depth,
    #                     2 to also save max speed,
    #                     5 to also save max hs,hss,hmin
    rundata.fgmax_data.num_fgmax_val = 1  # Save depth

    fgmax_grids = rundata.fgmax_data.fgmax_grids  # empty list to start

    # Now append to this list objects of class fgmax_tools.FGmaxGrid
    # specifying any fgmax grids.

    # For illustration, set up several fgmax grids of different types:

    # Default values (might be changed below)
    tstart_max = 4.  # when to start monitoring max values
    tend_max = 1.e10  # when to stop monitoring max values
    dt_check = 0.1  # target time (sec) increment between updating
    # max values
    min_level_check = 4  # which levels to monitor max on
    arrival_tol = 1.e-2  # tolerance for flagging arrival
    interp_method = 0  # pw constant in FV cell, not interpolated

    # ========================
    # Lat-Long grid on x-axis:

    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2  # will specify a 2d grid of points
    fg.nx = 100
    fg.ny = 80
    fg.x1 = 88.
    fg.y1 = -2.
    fg.x2 = 93.
    fg.y2 = 2.
    fg.tstart_max = tstart_max
    fg.tend_max = tend_max
    fg.dt_check = dt_check
    fg.min_level_check = min_level_check
    fg.arrival_tol = arrival_tol
    fg.interp_method = interp_method
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    # ===============================
    # Quadrilateral grid on diagonal:

    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 3  # will specify a 2d grid of points
    fg.n12 = 100
    fg.n23 = 80

    # rotate grid1 from above by pi/4 to place on diagonal:
    x1 = 88.
    y1 = -2.
    x2 = 93.
    y2 = -2.
    x3 = 93.
    y3 = 2.
    x4 = 88.
    y4 = 2.
    c = numpy.cos(numpy.pi / 4.)
    s = numpy.sin(numpy.pi / 4.)
    fg.x1 = c * x1 - s * y1
    fg.y1 = s * x1 + c * y1
    fg.x2 = c * x2 - s * y2
    fg.y2 = s * x2 + c * y2
    fg.x3 = c * x3 - s * y3
    fg.y3 = s * x3 + c * y3
    fg.x4 = c * x4 - s * y4
    fg.y4 = s * x4 + c * y4

    fg.tstart_max = tstart_max
    fg.tend_max = tend_max
    fg.dt_check = dt_check
    fg.min_level_check = min_level_check
    fg.arrival_tol = arrival_tol
    fg.interp_method = interp_method
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    # ===============================
    # Transect on x-axis:

    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 1  # will specify a 1d grid of points
    fg.npts = 100
    fg.x1 = 85.
    fg.y1 = 0.
    fg.x2 = 93.
    fg.y2 = 0.
    fg.tstart_max = tstart_max
    fg.tend_max = tend_max
    fg.dt_check = dt_check
    fg.min_level_check = min_level_check
    fg.arrival_tol = arrival_tol
    fg.interp_method = interp_method
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    # ===============================
    # Transect on diagonal:

    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 1  # will specify a 1d grid of points
    fg.npts = 100
    fg.x1 = 60.
    fg.y1 = 60.
    fg.x2 = 66.
    fg.y2 = 66.
    fg.tstart_max = tstart_max
    fg.tend_max = tend_max
    fg.dt_check = dt_check
    fg.min_level_check = min_level_check
    fg.arrival_tol = arrival_tol
    fg.interp_method = interp_method
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    # ===============================
    # Points along shoreline:
    # Around circle in first quadrant at 90 meters from center

    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 0  # will specify a list of points
    fg.npts = 500

    from numpy import pi
    theta = numpy.linspace(-pi / 8., 3 * pi / 8, fg.npts)
    fg.X = 90. * numpy.cos(theta)
    fg.Y = 90. * numpy.sin(theta)

    fg.tstart_max = tstart_max
    fg.tend_max = tend_max
    fg.dt_check = dt_check
    fg.min_level_check = min_level_check
    fg.arrival_tol = arrival_tol
    fg.interp_method = interp_method
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    return rundata
Beispiel #14
0
def setplot(plotdata=None):
    """"""

    if plotdata is None:
        from clawpack.visclaw.data import ClawPlotData
        plotdata = ClawPlotData()

    # clear any old figures,axes,items data
    plotdata.clearfigures()
    plotdata.format = 'binary'

    # Load data from output
    clawdata = clawutil.ClawInputData(2)
    clawdata.read(os.path.join(plotdata.outdir, 'claw.data'))
    physics = geodata.GeoClawData()
    physics.read(os.path.join(plotdata.outdir, 'geoclaw.data'))
    surge_data = geodata.SurgeData()
    surge_data.read(os.path.join(plotdata.outdir, 'surge.data'))
    friction_data = geodata.FrictionData()
    friction_data.read(os.path.join(plotdata.outdir, 'friction.data'))

    # Load storm track
    track = surgeplot.track_data(os.path.join(plotdata.outdir, 'fort.track'))

    # Set afteraxes function
    def surge_afteraxes(cd):
        surgeplot.surge_afteraxes(cd,
                                  track,
                                  plot_direction=False,
                                  kwargs={"markersize": 4})

    # Color limits
    surface_range = 5.0
    eta = physics.sea_level
    if not isinstance(eta, list):
        eta = [eta]
    surface_limits = [eta[0] - surface_range, eta[0] + surface_range]
    speed_limits = [0.0, 3.0]
    wind_limits = [0, 64]
    pressure_limits = [935, 1013]
    friction_bounds = [0.01, 0.04]

    def friction_after_axes(cd):
        plt.title(r"Manning's $n$ Coefficient")

    # ==========================================================================
    #   Plot specifications
    # ==========================================================================
    regions = {
        "Entire Region": {
            "xlimits": (clawdata.lower[0], clawdata.upper[0]),
            "ylimits": (clawdata.lower[1], clawdata.upper[1]),
            "figsize": (13, 10)
        },
        "Caribbean Sub-region": {
            "xlimits": (-86, -58.0),
            "ylimits": (9, 28),
            "figsize": (16, 6)
        },
    }

    for (name, region_dict) in regions.items():

        # Surface Figure
        plotfigure = plotdata.new_plotfigure(name="Surface - %s" % name)
        plotfigure.kwargs = {"figsize": region_dict['figsize']}
        plotaxes = plotfigure.new_plotaxes()
        plotaxes.title = "Surface"
        plotaxes.xlimits = region_dict["xlimits"]
        plotaxes.ylimits = region_dict["ylimits"]
        plotaxes.afteraxes = surge_afteraxes

        surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
        surgeplot.add_land(plotaxes)
        plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

        # Speed Figure
        plotfigure = plotdata.new_plotfigure(name="Currents - %s" % name)
        plotfigure.kwargs = {"figsize": region_dict['figsize']}
        plotaxes = plotfigure.new_plotaxes()
        plotaxes.title = "Currents"
        plotaxes.xlimits = region_dict["xlimits"]
        plotaxes.ylimits = region_dict["ylimits"]
        plotaxes.afteraxes = surge_afteraxes

        surgeplot.add_speed(plotaxes, bounds=speed_limits)
        surgeplot.add_land(plotaxes)
        plotaxes.plotitem_dict['speed'].amr_patchedges_show = [0] * 10
        plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10
    #
    # Friction field
    #
    plotfigure = plotdata.new_plotfigure(name='Friction')
    plotfigure.show = friction_data.variable_friction and False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Entire Region']['xlimits']
    plotaxes.ylimits = regions['Entire Region']['ylimits']
    # plotaxes.title = "Manning's N Coefficient"
    plotaxes.afteraxes = friction_after_axes
    plotaxes.scaled = True

    surgeplot.add_friction(plotaxes, bounds=friction_bounds, shrink=0.9)
    plotaxes.plotitem_dict['friction'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['friction'].colorbar_label = "$n$"

    #
    #  Hurricane Forcing fields
    #
    # Pressure field
    plotfigure = plotdata.new_plotfigure(name='Pressure')
    plotfigure.show = surge_data.pressure_forcing and False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Entire Region']['xlimits']
    plotaxes.ylimits = regions['Entire Region']['ylimits']
    plotaxes.title = "Pressure Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    surgeplot.add_pressure(plotaxes, bounds=pressure_limits)
    surgeplot.add_land(plotaxes)

    # Wind field
    plotfigure = plotdata.new_plotfigure(name='Wind Speed')
    plotfigure.show = surge_data.wind_forcing and False

    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = regions['Entire Region']['xlimits']
    plotaxes.ylimits = regions['Entire Region']['ylimits']
    plotaxes.title = "Wind Field"
    plotaxes.afteraxes = surge_afteraxes
    plotaxes.scaled = True
    surgeplot.add_wind(plotaxes, bounds=wind_limits)
    surgeplot.add_land(plotaxes)

    # ========================================================================
    #  Figures for gauges
    # ========================================================================
    plotfigure = plotdata.new_plotfigure(name='Gauge Surfaces',
                                         figno=300,
                                         type='each_gauge')
    plotfigure.show = True
    plotfigure.clf_each_gauge = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.xlimits = [-2, 1]
    # plotaxes.xlabel = "Days from landfall"
    # plotaxes.ylabel = "Surface (m)"
    plotaxes.ylimits = [-1, 5]
    plotaxes.title = 'Surface'

    def gauge_afteraxes(cd):

        axes = plt.gca()
        surgeplot.plot_landfall_gauge(cd.gaugesoln, axes)

        # Fix up plot - in particular fix time labels
        axes.set_title('Station %s' % cd.gaugeno)
        axes.set_xlabel('Days relative to landfall')
        axes.set_ylabel('Surface (m)')
        axes.set_xlim([-2, 1])
        axes.set_ylim([-1, 5])
        axes.set_xticks([-2, -1, 0, 1])
        axes.set_xticklabels([r"$-2$", r"$-1$", r"$0$", r"$1$"])
        axes.grid(True)

    plotaxes.afteraxes = gauge_afteraxes

    # Plot surface as blue curve:
    plotitem = plotaxes.new_plotitem(plot_type='1d_plot')

    # plotitem.plot_var = 3
    # plotitem.plotstyle = 'b-'

    #
    #  Gauge Location Plot
    #
    def gauge_location_afteraxes(cd):
        plt.subplots_adjust(left=0.12, bottom=0.06, right=0.97, top=0.97)
        surge_afteraxes(cd)
        gaugetools.plot_gauge_locations(cd.plotdata,
                                        gaugenos='all',
                                        format_string='ko',
                                        add_labels=True)

    plotfigure = plotdata.new_plotfigure(name="Gauge Locations")
    plotfigure.show = True

    # Set up for axes in this figure:
    plotaxes = plotfigure.new_plotaxes()
    plotaxes.title = 'Gauge Locations'
    plotaxes.scaled = True
    plotaxes.xlimits = [clawdata.lower[0], clawdata.upper[0]]
    plotaxes.ylimits = [clawdata.lower[1], clawdata.upper[1]]
    plotaxes.afteraxes = gauge_location_afteraxes
    surgeplot.add_surface_elevation(plotaxes, bounds=surface_limits)
    surgeplot.add_land(plotaxes)
    plotaxes.plotitem_dict['surface'].amr_patchedges_show = [0] * 10
    plotaxes.plotitem_dict['land'].amr_patchedges_show = [0] * 10

    #-----------------------------------------
    # Figures for fgmax plots
    #-----------------------------------------

    from clawpack.geoclaw import fgmax_tools
    fgmax_plotdir = '_plots'
    os.system('mkdir -p %s' % fgmax_plotdir)
    # Read fgmax data:
    fgno = 1
    while (True):
        fg = fgmax_tools.FGmaxGrid()
        try:
            fg.read_fgmax_grids_data(fgno)

            fg.read_output(outdir=plotdata.outdir)

            fg.B0 = fg.B  # no seafloor deformation in this problem
            fg.h_onshore = np.ma.masked_where(fg.B0 < 0., fg.h)
            plt.figure(figsize=(20, 20))

            pc = plt.pcolormesh(fg.X, fg.Y, fg.h_onshore, cmap='hot_r')
            cb = plt.colorbar(pc, extend='max', shrink=0.7)
            cb.set_label('meters')
            plt.contour(fg.X, fg.Y, fg.B, [0], colors='g')

            plt.gca().set_aspect(1. / np.cos(48 * np.pi / 180.))
            plt.ticklabel_format(useOffset=False)
            plt.xticks(rotation=20)
            plt.title('Maximum Onshore flow depth\nfgmax grid {fgno}')
            img_name = f'fgmax{str(fgno).zfill(4)}_h_onshore.png'
            plt.savefig(fname=f'{fgmax_plotdir}/{img_name}')
            otherfigure = plotdata.new_otherfigure(
                name=f'max depth on fgmax grid {fgno}', fname=img_name)
            fgno = fgno + 1
        except:
            break

    # -----------------------------------------
    # Parameters used only when creating html and/or latex hardcopy
    # e.g., via pyclaw.plotters.frametools.printframes:

    plotdata.printfigs = True  # print figures
    plotdata.print_format = 'png'  # file format
    plotdata.print_framenos = 'all'  # list of frames to print
    plotdata.print_gaugenos = 'all'  # list of gauges to print
    plotdata.print_fignos = 'all'  # list of figures to print
    plotdata.html = True  # create html files of plots?
    plotdata.latex = False  # create latex file of plots?
    plotdata.latex_figsperline = 2  # layout of plots
    plotdata.latex_framesperline = 1  # layout of plots
    plotdata.latex_makepdf = False  # also run pdflatex?
    plotdata.parallel = True  # parallel plotting

    return plotdata
Beispiel #15
0
def setrun(claw_pkg='geoclaw'):
#------------------------------

    """
    Define the parameters used for running Clawpack.

    INPUT:
        claw_pkg expected to be "geoclaw" for this setrun.

    OUTPUT:
        rundata - object of class ClawRunData

    """

    from clawpack.clawutil import data

    assert claw_pkg.lower() == 'geoclaw',  "Expected claw_pkg = 'geoclaw'"

    num_dim = 2
    rundata = data.ClawRunData(claw_pkg, num_dim)

    #------------------------------------------------------------------
    # GeoClaw specific parameters:
    #------------------------------------------------------------------
    rundata = setgeo(rundata)

    #------------------------------------------------------------------
    # Standard Clawpack parameters to be written to claw.data:
    #   (or to amr2ez.data for AMR)
    #------------------------------------------------------------------
    clawdata = rundata.clawdata  # initialized when rundata instantiated


    # Set single grid parameters first.
    # See below for AMR parameters.


    # ---------------
    # Spatial domain:
    # ---------------

    # Number of space dimensions:
    clawdata.num_dim = num_dim

    #Addons
    import AddSetrun
    import AddZoom
    
    # Lower and upper edge of computational domain:
    clawdata.lower[0] = AddSetrun.xmin
    clawdata.upper[0] = AddSetrun.xmax

    clawdata.lower[1] = AddSetrun.ymin
    clawdata.upper[1] = AddSetrun.ymax
	 
	 

    # Number of grid cells: Coarsest grid
    clawdata.num_cells[0] = AddSetrun.nx
    clawdata.num_cells[1] = AddSetrun.ny 

    # ---------------
    # Size of system:
    # ---------------

    # Number of equations in the system:
    clawdata.num_eqn = 3

    # Number of auxiliary variables in the aux array (initialized in setaux)
    clawdata.num_aux = 1

    # Index of aux array corresponding to capacity function, if there is one:
    clawdata.capa_index = 0

    
    
    # -------------
    # Initial time:
    # -------------

    clawdata.t0 = 0.0


    # Restart from checkpoint file of a previous run?
    # If restarting, t0 above should be from original run, and the
    # restart_file 'fort.chkNNNNN' specified below should be in 
    # the OUTDIR indicated in Makefile.

    clawdata.restart = False               # True to restart from prior results
    clawdata.restart_file = 'fort.chk00006'  # File to use for restart data

    # -------------
    # Output times:
    #--------------

    # Specify at what times the results should be written to fort.q files.
    # Note that the time integration stops after the final output time.
    # The solution at initial time t0 is always written in addition.

    clawdata.output_style = 1

    if clawdata.output_style==1:
        # Output nout frames at equally spaced times up to tfinal:
        clawdata.num_output_times = AddSetrun.nsim
        clawdata.tfinal = AddSetrun.tmax
        clawdata.output_t0 = True  # output at initial (or restart) time?

    elif clawdata.output_style == 2:
        # Specify a list of output times.
        clawdata.output_times = [0.5, 1.0]

    elif clawdata.output_style == 3:
        # Output every iout timesteps with a total of ntot time steps:
        clawdata.output_step_interval = 1
        clawdata.total_steps = 1
        clawdata.output_t0 = True
        

    clawdata.output_format = 'ascii'      # 'ascii' or 'binary' 

    clawdata.output_q_components = 'all'   # could be list such as [True,True]
    clawdata.output_aux_components = [True]  # could be list
    clawdata.output_aux_onlyonce = True    # output aux arrays only at t0



    # ---------------------------------------------------
    # Verbosity of messages to screen during integration:
    # ---------------------------------------------------

    # The current t, dt, and cfl will be printed every time step
    # at AMR levels <= verbosity.  Set verbosity = 0 for no printing.
    #   (E.g. verbosity == 2 means print only on levels 1 and 2.)
    clawdata.verbosity = 2



    # --------------
    # Time stepping:
    # --------------

    # if dt_variable==1: variable time steps used based on cfl_desired,
    # if dt_variable==0: fixed time steps dt = dt_initial will always be used.
    clawdata.dt_variable = True

    # Initial time step for variable dt.
    # If dt_variable==0 then dt=dt_initial for all steps:
    clawdata.dt_initial = AddSetrun.dt_init

    # Max time step to be allowed if variable dt used:
    clawdata.dt_max = 1e+99

    # Desired Courant number if variable dt used, and max to allow without
    # retaking step with a smaller dt:
    clawdata.cfl_desired = AddSetrun.cfl_desired
    clawdata.cfl_max = 0.95

    # Maximum number of time steps to allow between output times:
    clawdata.steps_max = AddSetrun.nb_max_iter




    # ------------------
    # Method to be used:
    # ------------------

    # Order of accuracy:  1 => Godunov,  2 => Lax-Wendroff plus limiters
    clawdata.order = 2
    
    # Use dimensional splitting? (not yet available for AMR)
    clawdata.dimensional_split = 'unsplit'
    
    # For unsplit method, transverse_waves can be 
    #  0 or 'none'      ==> donor cell (only normal solver used)
    #  1 or 'increment' ==> corner transport of waves
    #  2 or 'all'       ==> corner transport of 2nd order corrections too
    clawdata.transverse_waves = 2

    # Number of waves in the Riemann solution:
    clawdata.num_waves = 3
    
    # List of limiters to use for each wave family:  
    # Required:  len(limiter) == num_waves
    # Some options:
    #   0 or 'none'     ==> no limiter (Lax-Wendroff)
    #   1 or 'minmod'   ==> minmod
    #   2 or 'superbee' ==> superbee
    #   3 or 'mc'       ==> MC limiter
    #   4 or 'vanleer'  ==> van Leer
    clawdata.limiter = ['mc', 'mc', 'mc']

    clawdata.use_fwaves = True    # True ==> use f-wave version of algorithms
    
    # Source terms splitting:
    #   src_split == 0 or 'none'    ==> no source term (src routine never called)
    #   src_split == 1 or 'godunov' ==> Godunov (1st order) splitting used, 
    #   src_split == 2 or 'strang'  ==> Strang (2nd order) splitting used,  not recommended.
    clawdata.source_split = 'godunov'


    # --------------------
    # Boundary conditions:
    # --------------------

    # Number of ghost cells (usually 2)
    clawdata.num_ghost = 2

    # Choice of BCs at xlower and xupper:
    #   0 => user specified (must modify bcN.f to use this option)
    #   1 => extrapolation (non-reflecting outflow)
    #   2 => periodic (must specify this at both boundaries)
    #   3 => solid wall for systems where q(2) is normal velocity

    clawdata.bc_lower[0] = 'extrap'
    clawdata.bc_upper[0] = 'extrap'

    clawdata.bc_lower[1] = 'extrap'
    clawdata.bc_upper[1] = 'extrap'

    # Specify when checkpoint files should be created that can be
    # used to restart a computation.

    clawdata.checkpt_style = 0

    if clawdata.checkpt_style == 0:
        # Do not checkpoint at all
        pass

    elif np.abs(clawdata.checkpt_style) == 1:
        # Checkpoint only at tfinal.
        pass

    elif np.abs(clawdata.checkpt_style) == 2:
        # Specify a list of checkpoint times.  
        clawdata.checkpt_times = [0.1,0.15]

    elif np.abs(clawdata.checkpt_style) == 3:
        # Checkpoint every checkpt_interval timesteps (on Level 1)
        # and at the final time.
        clawdata.checkpt_interval = 5

    # ---------------
    # AMR parameters:
    # ---------------
    amrdata = rundata.amrdata

    # max number of refinement levels:
    amrdata.amr_levels_max = AddSetrun.refinement

    # List of refinement ratios at each level (length at least mxnest-1)
    amrdata.refinement_ratios_x = [2,4,8]
    amrdata.refinement_ratios_y = [2,4,8]
    amrdata.refinement_ratios_t = [2,4,8]


    # Specify type of each aux variable in amrdata.auxtype.
    # This must be a list of length maux, each element of which is one of:
    #   'center',  'capacity', 'xleft', or 'yleft'  (see documentation).

    amrdata.aux_type = ['center']


    # Flag using refinement routine flag2refine rather than richardson error
    amrdata.flag_richardson = False    # use Richardson?
    amrdata.flag2refine = True

    # steps to take on each level L between regriddings of level L+1:
    amrdata.regrid_interval = 3

    # width of buffer zone around flagged points:
    # (typically the same as regrid_interval so waves don't escape):
    amrdata.regrid_buffer_width  = 2

    # clustering alg. cutoff for (# flagged pts) / (total # of cells refined)
    # (closer to 1.0 => more small grids may be needed to cover flagged cells)
    amrdata.clustering_cutoff = 0.700000

    # print info about each regridding up to this level:
    amrdata.verbosity_regrid = 0  


    #  ----- For developers ----- 
    # Toggle debugging print statements:
    amrdata.dprint = False      # print domain flags
    amrdata.eprint = False      # print err est flags
    amrdata.edebug = False      # even more err est flags
    amrdata.gprint = False      # grid bisection/clustering
    amrdata.nprint = False      # proper nesting output
    amrdata.pprint = False      # proj. of tagged points
    amrdata.rprint = False      # print regridding summary
    amrdata.sprint = False      # space/memory output
    amrdata.tprint = False      # time step reporting each level
    amrdata.uprint = False      # update/upbnd reporting
    
    # More AMR parameters can be set -- see the defaults in pyclaw/data.py

    # == setregions.data values ==
    regions = rundata.regiondata.regions
    # to specify regions of refinement append lines of the form
    #  [minlevel,maxlevel,t1,t2,x1,x2,y1,y2]
    #regions.append([1, 1, 0., 1.e10, 925720,927160., 6451140.,6452155.])
    if AddSetrun.refinement_area == 1:
       regions.append([1, 2, 0., 1.e10, AddSetrun.xmin, \
       AddSetrun.xmax, AddSetrun.ymin, AddSetrun.ymax])
    elif AddSetrun.refinement_area == 2:
       regions.append([1, 2, 0., 1.e10, AddZoom.x_zoom_min, \
       AddZoom.x_zoom_max, AddZoom.y_zoom_min, AddZoom.y_zoom_max])    
       
 
       
    #regions.append([2, 3, 3., 1.e10,   52., 72.,   52., 72.])
    #regions.append([2, 3, 3., 1.e10,   75., 95.,   -10.,  10.])
    #regions.append([2, 4, 3.4, 1.e10,   57., 68.,   57., 68.])
    #regions.append([2, 4, 3.4, 1.e10,   83., 92.,   -4.,  4.])
 

    # == setgauges.data values ==
    # for gauges append lines of the form  [gaugeno, x, y, t1, t2]
    # rundata.gaugedata.add_gauge()

    # gauges along x-axis:
    # gaugeno = 0
    # for r in np.linspace(-10, 10., 10):
    #     gaugeno = gaugeno+1
    #     x = r + .001  # shift a bit away from cell corners
    #     y = .001
     #    rundata.gaugedata.gauges.append([gaugeno, x, y, 0., 1e10])

    # Points on a uniform 2d grid:

    if AddZoom.zooming == True:
       from clawpack.geoclaw import fgmax_tools
       fg = fgmax_tools.FGmaxGrid()
       fg.point_style = 2  # uniform rectangular x-y grid
       fg.x1 = AddZoom.x_zoom_min
       fg.x2 = AddZoom.x_zoom_max
       fg.y1 = AddZoom.y_zoom_min
       fg.y2 = AddZoom.y_zoom_max
       fg.dx = AddZoom.dx  # desired resolution of fgmax grid
       fg.dy = AddZoom.dy
       fg.min_level_check = amrdata.amr_levels_max # which levels to monitor max on
       fg.tstart_max = AddZoom.tstart  # just before wave arrives
       fg.tend_max = AddZoom.tmax    # when to stop monitoring max values
       fg.dt_check = AddZoom.dt      # how often to update max values
       fg.interp_method = 0   # 0 ==> pw const in cells, recommended
       rundata.fgmax_data.fgmax_grids.append(fg)  # written to fgmax_grids.data
       rundata.fgmax_data.num_fgmax_val = 5
    

    return rundata
Beispiel #16
0
    xlabel('Longitude', fontsize=15)
    ylabel('meters', fontsize=15)
    fname = '%s_topo' % trname
    save_figure(fname)


# Transect at ylat=44.2:

plotdir = '_transects_44_2_new'
trname = 'Transect_44_2'
ylat = 44.2
xcutoff = -124.175

os.system('mkdir -p %s' % plotdir)

fg2 = fgmax_tools.FGmaxGrid()
fg2.read_input_data('fgmax_transect_2.txt')
fg2.read_output(fgno=2, outdir='_output')

frameno = 1
plot_transect(ylat, frameno, fg2, xcutoff, trname, plotdir)

frameno = 2
plot_transect(ylat, frameno, fg2, xcutoff, trname, plotdir)

frameno = 4
plot_transect(ylat, frameno, fg2, xcutoff, trname, plotdir)

plot_topo(fg2, trname, plotdir)

# Transect at ylat=44.4:
Beispiel #17
0
def setgeo(rundata):
#-------------------
    """
    Set GeoClaw specific runtime parameters.
    For documentation see ....
    """

    try:
        geo_data = rundata.geo_data
    except:
        print("*** Error, this rundata has no geo_data attribute")
        raise AttributeError("Missing geo_data attribute")

       
    # == Physics ==
    geo_data.gravity = 9.81
    geo_data.coordinate_system = 1
    geo_data.earth_radius = 6367.5e3

    # == Forcing Options
    geo_data.coriolis_forcing = False

    # == Algorithm and Initial Conditions ==
    geo_data.sea_level = -10.0
    geo_data.dry_tolerance = 1.e-3
    geo_data.friction_forcing = False
    geo_data.manning_coefficient = 0.0
    geo_data.friction_depth = 1.e6

    # Refinement data
    refinement_data = rundata.refinement_data
    refinement_data.wave_tolerance = 1.e-2
    refinement_data.deep_depth = 1e2
    refinement_data.max_level_deep = 3
    refinement_data.variable_dt_refinement_ratios = True

    # == settopo.data values ==
    topo_data = rundata.topo_data
    # for topography, append lines of the form
    #    [topotype, minlevel, maxlevel, t1, t2, fname]
    topo_data.topofiles.append([2, 1, 10, 0., 1.e10, 'bowl.topotype2'])

    # == setdtopo.data values ==
    dtopo_data = rundata.dtopo_data
    # for moving topography, append lines of the form :   (<= 1 allowed for now!)
    #   [topotype, minlevel,maxlevel,fname]

    # == setqinit.data values ==
    rundata.qinit_data.qinit_type = 0
    rundata.qinit_data.qinitfiles = []
    # for qinit perturbations, append lines of the form: (<= 1 allowed for now!)
    #   [minlev, maxlev, fname]

    # == setfixedgrids.data values ==
    fixedgrids = rundata.fixed_grid_data
    # for fixed grids append lines of the form
    # [t1,t2,noutput,x1,x2,y1,y2,xpoints,ypoints,\
    #  ioutarrivaltimes,ioutsurfacemax]
    
    # == fgmax.data values ==
    rundata.fgmax_data.num_fgmax_val = 2
    fgmax_grids = rundata.fgmax_data.fgmax_grids  # empty list to start
    # Now append to this list objects of class fgmax_tools.FGmaxGrid
    # specifying any fgmax grids.

    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2       # will specify a 2d grid of points
    fg.x1 = -2.
    fg.x2 = 2.
    fg.y1 = -2.
    fg.y2 = 2.
    fg.dx = 0.1
    fg.tstart_max = 0.        # when to start monitoring max values
    fg.tend_max = 1.e10       # when to stop monitoring max values
    fg.dt_check = 0.1         # target time (sec) increment between updating
                               # max values
    fg.min_level_check = 2    # which levels to monitor max on
    fg.arrival_tol = 1.e-2    # tolerance for flagging arrival

    fgmax_grids.append(fg)  # written to fgmax_grids.data
    
    #fgmax_files.append('fgmax1.txt')  # no longer used in v5.7.0

    return rundata
Beispiel #18
0
def setrun(claw_pkg='geoclaw'):
    #------------------------------
    """ 
    Define the parameters used for running Clawpack.

    INPUT:
        claw_pkg expected to be "geoclaw" for this setrun.

    OUTPUT:
        rundata - object of class ClawRunData 
    
    """

    from clawpack.clawutil import data

    assert claw_pkg.lower() == 'geoclaw', "Expected claw_pkg = 'geoclaw'"

    num_dim = 2
    rundata = data.ClawRunData(claw_pkg, num_dim)

    #------------------------------------------------------------------
    # Problem-specific parameters to be written to setprob.data:
    #------------------------------------------------------------------
    theta_island = 220.
    probdata = rundata.new_UserData(name='probdata', fname='setprob.data')
    probdata.add_param('theta_island', theta_island, 'angle to island')

    #------------------------------------------------------------------
    # Standard Clawpack parameters to be written to claw.data:
    #------------------------------------------------------------------

    clawdata = rundata.clawdata  # initialized when rundata instantiated

    # Set single grid parameters first.
    # See below for AMR parameters.

    # ---------------
    # Spatial domain:
    # ---------------

    # Number of space dimensions:
    clawdata.num_dim = num_dim

    # Lower and upper edge of computational domain:
    clawdata.lower[0] = -20.0  # xlower
    clawdata.upper[0] = 20.0  # xupper
    clawdata.lower[1] = 20.0  # ylower
    clawdata.upper[1] = 60.0  # yupper

    # Number of grid cells:
    clawdata.num_cells[0] = 40  # mx
    clawdata.num_cells[1] = 40  # my

    # ---------------
    # Size of system:
    # ---------------

    # Number of equations in the system:
    clawdata.num_eqn = 3

    # Number of auxiliary variables in the aux array (initialized in setaux)
    clawdata.num_aux = 3

    # Index of aux array corresponding to capacity function, if there is one:
    clawdata.capa_index = 2

    # -------------
    # Initial time:
    # -------------

    clawdata.t0 = 0.0

    # Restart from checkpoint file of a previous run?
    # Note: If restarting, you must also change the Makefile to set:
    #    RESTART = True
    # If restarting, t0 above should be from original run, and the
    # restart_file 'fort.chkNNNNN' specified below should be in
    # the OUTDIR indicated in Makefile.

    clawdata.restart = False  # True to restart from prior results
    clawdata.restart_file = 'fort.chk00006'  # File to use for restart data

    # -------------
    # Output times:
    #--------------

    # Specify at what times the results should be written to fort.q files.
    # Note that the time integration stops after the final output time.

    clawdata.output_style = 1

    if clawdata.output_style == 1:
        # Output ntimes frames at equally spaced times up to tfinal:
        # Can specify num_output_times = 0 for no output
        clawdata.num_output_times = 7
        clawdata.tfinal = 14000.
        clawdata.output_t0 = True  # output at initial (or restart) time?

    elif clawdata.output_style == 2:
        # Specify a list or numpy array of output times:
        # Include t0 if you want output at the initial time.
        clawdata.output_times = [0., 0.1]

    elif clawdata.output_style == 3:
        # Output every step_interval timesteps over total_steps timesteps:
        clawdata.output_step_interval = 2
        clawdata.total_steps = 4
        clawdata.output_t0 = True  # output at initial (or restart) time?

    clawdata.output_format = 'binary'  # 'ascii', 'binary'

    clawdata.output_q_components = 'all'  # could be list such as [True,True]
    clawdata.output_aux_components = 'none'  # could be list
    clawdata.output_aux_onlyonce = True  # output aux arrays only at t0

    # ---------------------------------------------------
    # Verbosity of messages to screen during integration:
    # ---------------------------------------------------

    # The current t, dt, and cfl will be printed every time step
    # at AMR levels <= verbosity.  Set verbosity = 0 for no printing.
    #   (E.g. verbosity == 2 means print only on levels 1 and 2.)
    clawdata.verbosity = 1

    # --------------
    # Time stepping:
    # --------------

    # if dt_variable==True:  variable time steps used based on cfl_desired,
    # if dt_variable==Falseixed time steps dt = dt_initial always used.
    clawdata.dt_variable = True

    # Initial time step for variable dt.
    # (If dt_variable==0 then dt=dt_initial for all steps)
    clawdata.dt_initial = 16.0

    # Max time step to be allowed if variable dt used:
    clawdata.dt_max = 1e+99

    # Desired Courant number if variable dt used
    clawdata.cfl_desired = 0.75
    # max Courant number to allow without retaking step with a smaller dt:
    clawdata.cfl_max = 1.0

    # Maximum number of time steps to allow between output times:
    clawdata.steps_max = 5000

    # ------------------
    # Method to be used:
    # ------------------

    # Order of accuracy:  1 => Godunov,  2 => Lax-Wendroff plus limiters
    clawdata.order = 2

    # Use dimensional splitting? (not yet available for AMR)
    clawdata.dimensional_split = 'unsplit'

    # For unsplit method, transverse_waves can be
    #  0 or 'none'      ==> donor cell (only normal solver used)
    #  1 or 'increment' ==> corner transport of waves
    #  2 or 'all'       ==> corner transport of 2nd order corrections too
    clawdata.transverse_waves = 2

    # Number of waves in the Riemann solution:
    clawdata.num_waves = 3

    # List of limiters to use for each wave family:
    # Required:  len(limiter) == num_waves
    # Some options:
    #   0 or 'none'     ==> no limiter (Lax-Wendroff)
    #   1 or 'minmod'   ==> minmod
    #   2 or 'superbee' ==> superbee
    #   3 or 'vanleer'  ==> van Leer
    #   4 or 'mc'       ==> MC limiter
    clawdata.limiter = ['vanleer', 'vanleer', 'vanleer']

    clawdata.use_fwaves = True  # True ==> use f-wave version of algorithms

    # Source terms splitting:
    #   src_split == 0 or 'none'    ==> no source term (src routine never called)
    #   src_split == 1 or 'godunov' ==> Godunov (1st order) splitting used,
    #   src_split == 2 or 'strang'  ==> Strang (2nd order) splitting used,  not recommended.
    clawdata.source_split = 1

    # --------------------
    # Boundary conditions:
    # --------------------

    # Number of ghost cells (usually 2)
    clawdata.num_ghost = 2

    # Choice of BCs at xlower and xupper:
    #   0 or 'user'     => user specified (must modify bcNamr.f to use this option)
    #   1 or 'extrap'   => extrapolation (non-reflecting outflow)
    #   2 or 'periodic' => periodic (must specify this at both boundaries)
    #   3 or 'wall'     => solid wall for systems where q(2) is normal velocity

    clawdata.bc_lower[0] = 'extrap'  # at xlower
    clawdata.bc_upper[0] = 'extrap'  # at xupper

    clawdata.bc_lower[1] = 'extrap'  # at ylower
    clawdata.bc_upper[1] = 'extrap'  # at yupper

    # ---------------
    # Gauges:
    # ---------------
    gauges = rundata.gaugedata.gauges
    # for gauges append lines of the form  [gaugeno, x, y, t1, t2]

    gaugeno = 0
    for d in [1570e3, 1590e3, 1610e3, 1630e3]:
        gaugeno = gaugeno + 1
        x, y = latlong(d, theta_island, 40., Rearth)
        gauges.append([gaugeno, x, y, 0., 1e10])

    # --------------
    # Checkpointing:
    # --------------

    # Specify when checkpoint files should be created that can be
    # used to restart a computation.

    clawdata.checkpt_style = 1

    if clawdata.checkpt_style == 0:
        # Do not checkpoint at all
        pass

    elif clawdata.checkpt_style == 1:
        # Checkpoint only at tfinal.
        pass

    elif clawdata.checkpt_style == 2:
        # Specify a list of checkpoint times.
        clawdata.checkpt_times = [0.1, 0.15]

    elif clawdata.checkpt_style == 3:
        # Checkpoint every checkpt_interval timesteps (on Level 1)
        # and at the final time.
        clawdata.checkpt_interval = 5

    # ---------------
    # AMR parameters:   (written to amr.data)
    # ---------------
    amrdata = rundata.amrdata

    # max number of refinement levels:
    amrdata.amr_levels_max = 5

    # List of refinement ratios at each level (length at least amr_level_max-1)
    amrdata.refinement_ratios_x = [4, 3, 5, 4]
    amrdata.refinement_ratios_y = [4, 3, 5, 4]
    amrdata.refinement_ratios_t = [1, 1, 1, 1]

    # Specify type of each aux variable in amrdata.auxtype.
    # This must be a list of length num_aux, each element of which is one of:
    #   'center',  'capacity', 'xleft', or 'yleft'  (see documentation).
    amrdata.aux_type = ['center', 'capacity', 'yleft']

    # Flag for refinement based on Richardson error estimater:
    amrdata.flag_richardson = False  # use Richardson?
    amrdata.flag_richardson_tol = 1.0  # Richardson tolerance

    # Flag for refinement using routine flag2refine:
    amrdata.flag2refine = True  # use this?
    amrdata.flag2refine_tol = 0.5  # tolerance used in this routine
    # Note: in geoclaw the refinement tolerance is set as wave_tolerance below
    # and flag2refine_tol is unused!

    # steps to take on each level L between regriddings of level L+1:
    amrdata.regrid_interval = 3

    # width of buffer zone around flagged points:
    # (typically the same as regrid_interval so waves don't escape):
    amrdata.regrid_buffer_width = 2

    # clustering alg. cutoff for (# flagged pts) / (total # of cells refined)
    # (closer to 1.0 => more small grids may be needed to cover flagged cells)
    amrdata.clustering_cutoff = 0.7

    # print info about each regridding up to this level:
    amrdata.verbosity_regrid = 0

    # ---------------
    # Regions:
    # ---------------
    regions = rundata.regiondata.regions
    # to specify regions of refinement append lines of the form
    #  [minlevel,maxlevel,t1,t2,x1,x2,y1,y2]

    regions.append([1, 3, 0., 5000., -5., 20., 35., 55.])
    regions.append([1, 2, 5000., 6900., -5., 20., 35., 55.])
    regions.append([1, 3, 5000., 6900., 10., 20., 45., 55.])
    regions.append([1, 2, 6900., 9000., 10., 20., 47., 52.])

    # Force refinement near the island as the wave approaches:

    (xisland, yisland) = latlong(1600.e3, theta_island, 40., Rearth)
    x1 = xisland - 1.
    x2 = xisland + 1.
    y1 = yisland - 1.
    y2 = yisland + 1.
    regions.append([4, 4, 7000., 1.e10, x1, x2, y1, y2])

    x1 = xisland - 0.2
    x2 = xisland + 0.2
    y1 = yisland - 0.2
    y2 = yisland + 0.2
    regions.append([4, 5, 8000., 1.e10, x1, x2, y1, y2])

    # -----------------------------------------------
    # GeoClaw specific parameters:

    try:
        geo_data = rundata.geo_data
    except:
        print("*** Error, this rundata has no geo_data attribute")
        raise AttributeError("Missing geo_data attribute")

    # == Physics ==
    geo_data.gravity = 9.81
    geo_data.coordinate_system = 2
    geo_data.earth_radius = 6367500.0

    # == Forcing Options
    geo_data.coriolis_forcing = False

    # == Algorithm and Initial Conditions ==
    geo_data.sea_level = 0.0
    geo_data.dry_tolerance = 0.001
    geo_data.friction_forcing = True
    geo_data.manning_coefficient = 0.025
    geo_data.friction_depth = 1000000.0

    # Refinement settings
    refinement_data = rundata.refinement_data
    refinement_data.variable_dt_refinement_ratios = True
    refinement_data.wave_tolerance = 0.01
    refinement_data.deep_depth = 100.0
    refinement_data.max_level_deep = 3

    # == settopo.data values ==
    topofiles = rundata.topo_data.topofiles
    # for topography, append lines of the form
    #    [topotype, minlevel, maxlevel, t1, t2, fname]
    topofiles.append([3, 1, 1, 0.0, 10000000000.0, 'ocean.tt3'])
    topofiles.append([3, 1, 1, 0.0, 10000000000.0, 'island.tt3'])

    # == setdtopo.data values ==
    rundata.dtopo_data.dtopofiles = []
    dtopofiles = rundata.dtopo_data.dtopofiles
    # for moving topography, append lines of the form :
    #   [topotype, minlevel,maxlevel,fname]

    # == setqinit.data values ==
    rundata.qinit_data.qinit_type = 4
    qinitfiles = rundata.qinit_data.qinitfiles
    # for qinit perturbations, append lines of the form: (<= 1 allowed for now!)
    #   [minlev, maxlev, fname]
    rundata.qinit_data.qinitfiles = [[1, 2, 'hump.xyz']]

    # == fgmax_grids.data values ==
    # NEW STYLE STARTING IN v5.7.0

    # set num_fgmax_val = 1 to save only max depth,
    #                     2 to also save max speed,
    #                     5 to also save max hs,hss,hmin
    rundata.fgmax_data.num_fgmax_val = 2  # Save depth and speed

    fgmax_grids = rundata.fgmax_data.fgmax_grids  # empty list to start

    # Now append to this list objects of class fgmax_tools.FGmaxGrid
    # specifying any fgmax grids.

    # Here several different ones are specified to illustrate:

    tstart_max = 8000.  # when to start monitoring fgmax grids

    # Points on a uniform 2d grid:
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2  # uniform rectangular x-y grid
    fg.x1 = 14.25
    fg.x2 = 14.65
    fg.y1 = 50.10
    fg.y2 = 50.35
    fg.dx = 15 / 3600.  # desired resolution of fgmax grid
    fg.min_level_check = amrdata.amr_levels_max  # which levels to monitor max on
    fg.tstart_max = tstart_max  # just before wave arrives
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 20.  # how often to update max values
    fg.interp_method = 0  # 0 ==> pw const in cells, recommended
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    # Points on a 1d transect from (x1,y1) to (x2,y2):
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 1  # equally spaced points on a transect
    fg.x1 = 14.25
    fg.x2 = 14.65
    fg.y1 = 50.10
    fg.y2 = 50.35
    fg.npts = 50
    fg.min_level_check = amrdata.amr_levels_max  # which levels to monitor max on
    fg.tstart_max = tstart_max  # just before wave arrives
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 20.  # how often to update max values
    fg.interp_method = 0  # 0 ==> pw const in cells, recommended
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    # fgmax grid point_style==4 means grid specified as topo_type==3 file:
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 4
    fg.min_level_check = amrdata.amr_levels_max  # which levels to monitor max on
    fg.tstart_max = tstart_max  # just before wave arrives
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 20.  # how often to update max values
    fg.interp_method = 0  # 0 ==> pw const in cells, recommended
    fg.xy_fname = 'fgmax_pts_island.data'  # file of 0/1 values in tt3 format
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    # fgmax grid point_style==0 means list of points:
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 0
    fg.min_level_check = amrdata.amr_levels_max  # which levels to monitor max on
    fg.tstart_max = tstart_max  # just before wave arrives
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 20.  # how often to update max values
    fg.interp_method = 0  # 0 ==> pw const in cells, recommended
    # can set list of points here:
    fg.npts = 2
    fg.X = np.array([14.4, 14.5])
    fg.Y = np.array([50.13, 50.13])
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    # fgmax grid point_style==0 means list of points:
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 0
    fg.min_level_check = amrdata.amr_levels_max  # which levels to monitor max on
    fg.tstart_max = tstart_max  # just before wave arrives
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 20.  # how often to update max values
    fg.interp_method = 0  # 0 ==> pw const in cells, recommended
    # can specify that list of points is in a different file:
    fg.npts = 0
    fg.xy_fname = 'fgmax_ps0.txt'
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    #  ----- For developers -----
    # Toggle debugging print statements:
    amrdata.dprint = False  # print domain flags
    amrdata.eprint = False  # print err est flags
    amrdata.edebug = False  # even more err est flags
    amrdata.gprint = False  # grid bisection/clustering
    amrdata.nprint = False  # proper nesting output
    amrdata.pprint = False  # proj. of tagged points
    amrdata.rprint = False  # print regridding summary
    amrdata.sprint = False  # space/memory output
    amrdata.tprint = False  # time step reporting each level
    amrdata.uprint = False  # update/upbnd reporting

    return rundata
Beispiel #19
0
def setgeo(rundata):
    #-------------------
    """
    Set GeoClaw specific runtime parameters.
    For documentation see ....
    """

    try:
        geo_data = rundata.geo_data
    except:
        print("*** Error, this rundata has no geo_data attribute")
        raise AttributeError("Missing geo_data attribute")

    # == Physics ==
    geo_data.gravity = 9.80
    geo_data.coordinate_system = 2  # lonlat
    #geo_data.coordinate_system = 1 # XY
    geo_data.earth_radius = 6367.5e3
    geo_data.rho = 1025.0
    geo_data.rho_air = 1.15
    geo_data.ambient_pressure = 101.3e3  # Nominal atmos pressure

    # == Forcing Options
    geo_data.coriolis_forcing = True
    geo_data.friction_forcing = True
    geo_data.manning_coefficient = 0.025  # Overridden below
    geo_data.friction_depth = 1e10

    # == Algorithm and Initial Conditions ==
    geo_data.sea_level = 0.0
    geo_data.dry_tolerance = 1.e-2

    # Refinement Criteria
    refine_data = rundata.refinement_data
    refine_data.wave_tolerance = 0.20
    refine_data.speed_tolerance = [0.25, 0.50, 0.75, 1.00]

    refine_data.deep_depth = 1.0e3
    refine_data.max_level_deep = 1
    refine_data.variable_dt_refinement_ratios = True

    # == settopo.data values ==
    topo_data = rundata.topo_data
    topo_data.topofiles = []
    # for topography, append lines of the form
    #   [topotype, minlevel, maxlevel, t1, t2, fname]
    # See regions for control over these regions, need better bathy data for the
    # smaller domains
    topo_data.topofiles.append([
        3, 1, 3, rundata.clawdata.t0, rundata.clawdata.tfinal,
        os.path.join(topodir, topoflist['flat'])
    ])

    # == setdtopo.data values ==
    dtopo_data = rundata.dtopo_data
    dtopo_data.dtopofiles = []
    # for moving topography, append lines of the form :   (<= 1 allowed for now!)
    #   [topotype, minlevel,maxlevel,fname]

    # == setqinit.data values ==
    rundata.qinit_data.qinit_type = 0
    rundata.qinit_data.qinitfiles = []
    # for qinit perturbations, append lines of the form: (<= 1 allowed for now!)
    #   [minlev, maxlev, fname]

    # NEW feature to force dry land some locations below sea level:

    # == setfixedgrids.data values ==
    rundata.fixed_grid_data.fixedgrids = []
    # for fixed grids append lines of the form
    # [t1,t2,noutput,x1,x2,y1,y2,xpoints,ypoints,\
    #  ioutarrivaltimes,ioutsurfacemax]

    # == fgmax.data values ==
    fgmax_files = rundata.fgmax_data.fgmax_files
    # Points on a uniform 2d grid:

    # Domain 4
    topo_file = topotools.Topography(os.path.join(topodir, topoflist['flat']),
                                     topo_type=3)
    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2  # uniform rectangular x-y grid
    fg.dx = topo_file.delta[0]  # desired resolution of fgmax grid
    fg.x1 = topo_file.x[0]
    fg.x2 = topo_file.x[-1]
    fg.y1 = topo_file.y[0]
    fg.y2 = topo_file.y[-1]
    fg.min_level_check = 1  # which levels to monitor max on
    fg.arrival_tol = 1.0e-1
    fg.tstart_max = 0.0  # just before wave arrives
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 1.0  # how often to update max values
    fg.interp_method = 0  # 0 ==> pw const in cells, recommended
    rundata.fgmax_data.fgmax_grids.append(fg)  # written to fgmax_grids.data

    # num_fgmax_val
    rundata.fgmax_data.num_fgmax_val = 5  # 1 to save depth, 2 to save depth and speed, and 5 to Save depth, speed, momentum, momentum flux and hmin

    # ================
    #  Set Surge Data
    # ================
    data = rundata.surge_data

    # Source term controls - These are currently not respected
    data.wind_forcing = True
    #data.drag_law = 1
    data.drag_law = 4  # Mitsuyasu & Kusaba no limit drag coeff
    data.pressure_forcing = True

    # AMR parameters
    #data.wind_refine = [10.0, 20.0, 30.0, 40.0] # m/s
    #data.R_refine = [200.0e3, 100.0e3, 50.0e3, 25.0e3]  # m
    data.wind_refine = False  # m/s
    data.R_refine = False  # m

    # Storm parameters
    #data.storm_type = 1 # Type of storm
    data.storm_type = -1  # Explicit storm fields. See ./wrf_storm_module.f90
    data.storm_specification_type = 'WRF'
    data.display_landfall_time = True

    # Storm type 2 - Idealized storm track
    data.storm_file = os.path.join(os.getcwd(), 'forcing/')

    # =======================
    #  Set Variable Friction
    # =======================
    data = rundata.friction_data

    # Variable friction
    data.variable_friction = True

    # Region based friction
    # Entire domain
    data.friction_regions.append([
        rundata.clawdata.lower, rundata.clawdata.upper,
        [np.infty, 0.0, -np.infty], [0.030, 0.022]
    ])

    return rundata
Beispiel #20
0
def setrun(claw_pkg='geoclaw'):
    """
    Define the parameters used for running Clawpack.

    INPUT:
        claw_pkg expected to be "geoclaw" for this setrun.

    OUTPUT:
        rundata - object of class ClawRunData

    """

    from clawpack.clawutil import data

    assert claw_pkg.lower() == 'geoclaw', "Expected claw_pkg = 'geoclaw'"

    num_dim = 2
    rundata = data.ClawRunData(claw_pkg, num_dim)

    # ------------------------------------------------------------------
    # Standard Clawpack parameters to be written to claw.data:
    #   (or to amr2ez.data for AMR)
    # ------------------------------------------------------------------
    clawdata = rundata.clawdata  # initialized when rundata instantiated

    # Set single grid parameters first.
    # See below for AMR parameters.

    # ---------------
    # Spatial domain:
    # ---------------

    # Number of space dimensions:
    clawdata.num_dim = num_dim

    # Lower and upper edge of computational domain:
    clawdata.lower[0] = -88.0  # west longitude
    clawdata.upper[0] = -45.0  # east longitude

    clawdata.lower[1] = 9.0  # south latitude
    clawdata.upper[1] = 31.0  # north latitude

    # Number of grid cells:
    degree_factor = 4  # (0.25 deg,0.25 deg) ~ (25237.5 m, 27693.2 m) resolution
    clawdata.num_cells[0] = int(clawdata.upper[0] - clawdata.lower[0]) \
        * degree_factor
    clawdata.num_cells[1] = int(clawdata.upper[1] - clawdata.lower[1]) \
        * degree_factor

    # ---------------
    # Size of system:
    # ---------------

    # Number of equations in the system:
    clawdata.num_eqn = 3

    # Number of auxiliary variables in the aux array (initialized in setaux)
    # First three are from shallow GeoClaw, fourth is friction and last 3 are
    # storm fields
    clawdata.num_aux = 3 + 1 + 3

    # Index of aux array corresponding to capacity function, if there is one:
    clawdata.capa_index = 2

    # -------------
    # Initial time:
    # -------------
    clawdata.t0 = -days2seconds(1)

    # Restart from checkpoint file of a previous run?
    # If restarting, t0 above should be from original run, and the
    # restart_file 'fort.chkNNNNN' specified below should be in
    # the OUTDIR indicated in Makefile.

    clawdata.restart = False  # True to restart from prior results
    clawdata.restart_file = 'fort.chk00006'  # File to use for restart data

    # -------------
    # Output times:
    # --------------

    # Specify at what times the results should be written to fort.q files.
    # Note that the time integration stops after the final output time.
    # The solution at initial time t0 is always written in addition.

    clawdata.output_style = 1

    if clawdata.output_style == 1:
        # Output nout frames at equally spaced times up to tfinal:
        clawdata.tfinal = days2seconds(8)
        recurrence = 4
        clawdata.num_output_times = int(
            (clawdata.tfinal - clawdata.t0) * recurrence / (60**2 * 24))

        clawdata.output_t0 = True  # output at initial (or restart) time?

    elif clawdata.output_style == 2:
        # Specify a list of output times.
        clawdata.output_times = [0.5, 1.0]

    elif clawdata.output_style == 3:
        # Output every iout timesteps with a total of ntot time steps:
        clawdata.output_step_interval = 1
        clawdata.total_steps = 1
        clawdata.output_t0 = True

    clawdata.output_format = 'binary'  # 'ascii' or 'binary'
    clawdata.output_q_components = 'all'  # could be list such as [True,True]
    clawdata.output_aux_components = 'all'
    clawdata.output_aux_onlyonce = False  # output aux arrays only at t0

    # ---------------------------------------------------
    # Verbosity of messages to screen during integration:
    # ---------------------------------------------------

    # The current t, dt, and cfl will be printed every time step
    # at AMR levels <= verbosity.  Set verbosity = 0 for no printing.
    #   (E.g. verbosity == 2 means print only on levels 1 and 2.)
    clawdata.verbosity = 0

    # --------------
    # Time stepping:
    # --------------

    # if dt_variable==1: variable time steps used based on cfl_desired,
    # if dt_variable==0: fixed time steps dt = dt_initial will always be used.
    clawdata.dt_variable = True

    # Initial time step for variable dt.
    # If dt_variable==0 then dt=dt_initial for all steps:
    clawdata.dt_initial = 0.016

    # Max time step to be allowed if variable dt used:
    clawdata.dt_max = 1e+99

    # Desired Courant number if variable dt used, and max to allow without
    # retaking step with a smaller dt:
    clawdata.cfl_desired = 0.75
    clawdata.cfl_max = 1.0

    # Maximum number of time steps to allow between output times:
    clawdata.steps_max = 500000

    # ------------------
    # Method to be used:
    # ------------------

    # Order of accuracy:  1 => Godunov,  2 => Lax-Wendroff plus limiters
    clawdata.order = 1

    # Use dimensional splitting? (not yet available for AMR)
    clawdata.dimensional_split = 'unsplit'

    # For unsplit method, transverse_waves can be
    #  0 or 'none'      ==> donor cell (only normal solver used)
    #  1 or 'increment' ==> corner transport of waves
    #  2 or 'all'       ==> corner transport of 2nd order corrections too
    clawdata.transverse_waves = 1

    # Number of waves in the Riemann solution:
    clawdata.num_waves = 3

    # List of limiters to use for each wave family:
    # Required:  len(limiter) == num_waves
    # Some options:
    #   0 or 'none'     ==> no limiter (Lax-Wendroff)
    #   1 or 'minmod'   ==> minmod
    #   2 or 'superbee' ==> superbee
    #   3 or 'mc'       ==> MC limiter
    #   4 or 'vanleer'  ==> van Leer
    clawdata.limiter = ['mc', 'mc', 'mc']

    clawdata.use_fwaves = True  # True ==> use f-wave version of algorithms

    # Source terms splitting:
    #   src_split == 0 or 'none'
    #      ==> no source term (src routine never called)
    #   src_split == 1 or 'godunov'
    #      ==> Godunov (1st order) splitting used,
    #   src_split == 2 or 'strang'
    #      ==> Strang (2nd order) splitting used,  not recommended.
    clawdata.source_split = 'godunov'

    # --------------------
    # Boundary conditions:
    # --------------------

    # Number of ghost cells (usually 2)
    clawdata.num_ghost = 2

    # Choice of BCs at xlower and xupper:
    #   0 => user specified (must modify bcN.f to use this option)
    #   1 => extrapolation (non-reflecting outflow)
    #   2 => periodic (must specify this at both boundaries)
    #   3 => solid wall for systems where q(2) is normal velocity

    clawdata.bc_lower[0] = 'extrap'
    clawdata.bc_upper[0] = 'extrap'

    clawdata.bc_lower[1] = 'extrap'
    clawdata.bc_upper[1] = 'extrap'

    # Specify when checkpoint files should be created that can be
    # used to restart a computation.

    clawdata.checkpt_style = 0

    if clawdata.checkpt_style == 0:
        # Do not checkpoint at all
        pass

    elif np.abs(clawdata.checkpt_style) == 1:
        # Checkpoint only at tfinal.
        pass

    elif np.abs(clawdata.checkpt_style) == 2:
        # Specify a list of checkpoint times.
        clawdata.checkpt_times = [0.1, 0.15]

    elif np.abs(clawdata.checkpt_style) == 3:
        # Checkpoint every checkpt_interval timesteps (on Level 1)
        # and at the final time.
        clawdata.checkpt_interval = 5

    # ---------------
    # AMR parameters:
    # ---------------
    amrdata = rundata.amrdata

    # max number of refinement levels:
    amrdata.amr_levels_max = 7  # up to 7

    # List of refinement ratios at each level (length at least mxnest-1)
    amrdata.refinement_ratios_x = [2, 2, 2, 2, 4, 2]  # 200 m
    amrdata.refinement_ratios_y = [2, 2, 2, 2, 4, 2]
    amrdata.refinement_ratios_t = [2, 2, 2, 2, 4, 2]
    # amrdata.refinement_ratios_x = [2, 2, 2, 2, 4, 8] # 50 m
    # amrdata.refinement_ratios_y = [2, 2, 2, 2, 4, 8]
    # amrdata.refinement_ratios_t = [2, 2, 2, 2, 4, 8]

    # 1 / (4*2*2*2*2*4*8) degrees
    # Note: 1 degree = 10 km

    # Specify type of each aux variable in amrdata.auxtype.
    # This must be a list of length maux, each element of which is one of:
    #   'center',  'capacity', 'xleft', or 'yleft'  (see documentation).

    amrdata.aux_type = [
        'center', 'capacity', 'yleft', 'center', 'center', 'center', 'center'
    ]

    # Flag using refinement routine flag2refine rather than richardson error
    amrdata.flag_richardson = False  # use Richardson?
    amrdata.flag2refine = True

    # steps to take on each level L between regriddings of level L+1:
    amrdata.regrid_interval = 3

    # width of buffer zone around flagged points:
    # (typically the same as regrid_interval so waves don't escape):
    amrdata.regrid_buffer_width = 2

    # clustering alg. cutoff for (# flagged pts) / (total # of cells refined)
    # (closer to 1.0 => more small grids may be needed to cover flagged cells)
    amrdata.clustering_cutoff = 0.700000

    # print info about each regridding up to this level:
    amrdata.verbosity_regrid = 0

    #  ----- For developers -----
    # Toggle debugging print statements:
    amrdata.dprint = False  # print domain flags
    amrdata.eprint = False  # print err est flags
    amrdata.edebug = False  # even more err est flags
    amrdata.gprint = False  # grid bisection/clustering
    amrdata.nprint = False  # proper nesting output
    amrdata.pprint = False  # proj. of tagged points
    amrdata.rprint = False  # print regridding summary
    amrdata.sprint = False  # space/memory output
    amrdata.tprint = False  # time step reporting each level
    amrdata.uprint = False  # update/upbnd reporting

    # More AMR parameters can be set -- see the defaults in pyclaw/data.py

    # == Gauges == *
    gauges = rundata.gaugedata.gauges

    # Gauges from PLSMSL Stations https://www.psmsl.org/products/gloss/glossmap.html
    # 203: Port of Spain Trinidad and Tobago, 1, -61.517, 10.650,
    gauges.append(
        [1, -61.517, 10.650, rundata.clawdata.t0, rundata.clawdata.tfinal])
    # Gauges from Sea Level Station Monitoring Facility
    # Prickley Bay, Grenada Station, 2, -61.764828, 12.005392
    gauges.append([
        2, -61.764828, 12.005392, rundata.clawdata.t0, rundata.clawdata.tfinal
    ])
    # Calliaqua Coast Guard Base, Saint Vincent & Grenadines, 3, -61.1955, 13.129912
    gauges.append(
        [3, -61.1955, 13.129912, rundata.clawdata.t0, rundata.clawdata.tfinal])
    # Ganter's Bay, Saint Lucia, 4,-60.997351, 14.016428
    gauges.append([
        4, -60.997351, 14.016428, rundata.clawdata.t0, rundata.clawdata.tfinal
    ])
    # Fort-de-France, Martinique2, 5,
    gauges.append([
        5, -61.063333, 14.601667, rundata.clawdata.t0, rundata.clawdata.tfinal
    ])
    # Roseau Dominica, 6, 61.3891833, 15.31385
    gauges.append([
        6, -61.3891833, 15.31385, rundata.clawdata.t0, rundata.clawdata.tfinal
    ])
    # Pointe a Pitre, Guadeloupe, 7, -61.531452, 16.224398
    gauges.append([
        7, -61.531452, 16.224398, rundata.clawdata.t0, rundata.clawdata.tfinal
    ])
    # Parham (Camp Blizard), Antigua, 8, -61.7833, 17.15
    gauges.append(
        [8, -61.7833, 17.15, rundata.clawdata.t0, rundata.clawdata.tfinal])
    # Blowing Point, Anguilla, 9, -63.0926167, 18.1710861
    gauges.append([
        9, -63.0926167, 18.1710861, rundata.clawdata.t0,
        rundata.clawdata.tfinal
    ])
    # Saint Croix, VI, 10, -64.69833, 17.74666
    gauges.append([
        10, -64.69833, 17.74666, rundata.clawdata.t0, rundata.clawdata.tfinal
    ])
    # San Juan, PR, 11, -66.1167, 18.4617
    gauges.append(
        [11, -66.1167, 18.4617, rundata.clawdata.t0, rundata.clawdata.tfinal])
    # Barahona, Dominican Republic, 12, -71.092154, 18.208137
    gauges.append([
        12, -71.092154, 18.208137, rundata.clawdata.t0, rundata.clawdata.tfinal
    ])
    # George Town, Cayman Islands, 13, -81.383484, 19.295065
    gauges.append([
        13, -81.383484, 19.295065, rundata.clawdata.t0, rundata.clawdata.tfinal
    ])
    # Settlement pt, Bahamas, 14, -78.98333, 26.6833324
    gauges.append([
        14, -78.98333, 26.6833324, rundata.clawdata.t0, rundata.clawdata.tfinal
    ])
    # Force the gauges to also record the wind and pressure fields
    aux_out_fields = [4, 5, 6]

    # == setregions.data values ==
    regions = rundata.regiondata.regions
    # to specify regions of refinement append lines of the form
    #  [minlevel,maxlevel,t1,t2,x1,x2,y1,y2]
    # Add gauge support
    dx = 1 / 3600
    for g in gauges:
        t1 = g[3]
        t2 = g[4]
        x = g[1]
        y = g[2]
        regions.append([
            amrdata.amr_levels_max, amrdata.amr_levels_max, t1, t2, x - dx,
            x + dx, y - dx, y + dx
        ])

    # == fgmax_grids.data values ==

    from clawpack.geoclaw import fgmax_tools
    # set num_fgmax_val = 1 to save only max depth,
    #                     2 to also save max speed,
    #                     5 to also save max hs,hss,hmin
    rundata.fgmax_data.num_fgmax_val = 1  # Save depth only
    # rundata.fgmax_data.num_fgmax_val = 2  # Save depth and speed

    fgmax_grids = rundata.fgmax_data.fgmax_grids  # empty list to start

    # Now append to this list objects of class fgmax_tools.FGmaxGrid
    # specifying any fgmax grids.
    # Note: 1 arcsec = 30 m
    # Make sure x1 < x2, y1 < y2
    fgmax_regions = [
        {
            'Name': 'Trinidad to Dominica; Winward Islands',
            'x1': -62.6056,
            'x2': -58.7494,
            'y1': 9.9042,
            'y2': 15.694,
        },
        {
            'Name': 'Guadeloupe to U.S. Virgin Islands; Leeward Islands',
            'x1': -65.6021,
            'x2': -60.6143,
            'y1': 15.7242,
            'y2': 18.8608,
        },
        {
            'Name': 'Virgin Islands, Puerto Rico and Hispaniola',
            'x1': -75.1355,
            'x2': -63.8306,
            'y1': 16.7706,
            'y2': 20.9674,
        },
        {
            'Name': 'Cuba, Jamaica, and the Cayman Islands',
            'x1': -85.3088,
            'x2': -73.9709,
            'y1': 17.6605,
            'y2': 23.3514,
        },
        {
            'Name': 'The Bahamas and The Turks and Caicos Islands',
            'x1': -79.3542,
            'x2': -70.1697,
            'y1': 20.1819,
            'y2': 27.5647,
        },
        # {'Name':'Turks and Caicos',
        # 'x1': -73.9819,
        # 'x2': -70.9058,
        # 'y1': 20.8603,
        # 'y2': 22.0853,
        # 'dx': 5/3600
        # },
        # {'Name':'Dominica',
        # 'x1': -61.6594,
        # 'x2': -61.1307,
        # 'y1': 15.1234,
        # 'y2': 15.6933,
        # 'dx': 1/3600
        # },
        # {'Name':'Antigua and Barbuda',
        # 'x1': -62.1744,
        # 'x2': -61.4822,
        # 'y1': 16.9093,
        # 'y2': 17.8075,
        # 'dx': 1/3600
        # },
    ]
    for fr in fgmax_regions:
        # Points on a uniform 2d grid:
        fg = fgmax_tools.FGmaxGrid()
        fg.point_style = 2  # uniform rectangular x-y grid
        fg.x1 = fr['x1']
        fg.x2 = fr['x2']
        fg.y1 = fr['y1']
        fg.y2 = fr['y2']
        # desired resolution of fgmax grid
        if 'dx' in fr.keys():
            fg.dx = fr['dx']
        else:
            fg.dx = 5 / 3600.
            # fg.dx = 10 / 3600.
        fg.min_level_check = amrdata.amr_levels_max  # which levels to monitor max on
        fg.tstart_max = clawdata.t0  # just before wave arrives
        fg.tend_max = clawdata.tfinal  # when to stop monitoring max values
        fg.dt_check = 60.  # how often to update max values
        fg.interp_method = 0  # 0 ==> pw const in cells, recommended
        fgmax_grids.append(fg)  # written to fgmax_grids.data
    # ------------------------------------------------------------------
    # GeoClaw specific parameters:
    # ------------------------------------------------------------------
    rundata = setgeo(rundata)

    return rundata
Beispiel #21
0
def setgeo(rundata):
    #-------------------
    """
    Set GeoClaw specific runtime parameters.
    For documentation see ....
    """

    try:
        geo_data = rundata.geo_data
    except:
        print("*** Error, this rundata has no geo_data attribute")
        raise AttributeError("Missing geo_data attribute")

    # == Physics ==
    geo_data.gravity = 9.81
    geo_data.coordinate_system = 2
    geo_data.earth_radius = 6367.5e3

    # == Forcing Options
    geo_data.coriolis_forcing = False

    # == Algorithm and Initial Conditions ==
    geo_data.sea_level = 0.0
    geo_data.dry_tolerance = 1.e-3
    geo_data.friction_forcing = True
    geo_data.manning_coefficient = .025
    geo_data.friction_depth = 1e6

    # Refinement settings
    refinement_data = rundata.refinement_data
    refinement_data.variable_dt_refinement_ratios = True
    refinement_data.wave_tolerance = 1.e-2
    refinement_data.deep_depth = 1e2
    refinement_data.max_level_deep = 3

    # == settopo.data values ==
    topo_data = rundata.topo_data
    # for topography, append lines of the form
    #    [topotype, minlevel, maxlevel, t1, t2, fname]
    topo_path = os.path.join(scratch_dir, 'etopo10min120W60W60S0S.asc')
    topo_data.topofiles.append([2, 1, 3, 0., 1.e10, topo_path])

    # == setdtopo.data values ==
    dtopo_data = rundata.dtopo_data
    # for moving topography, append lines of the form :   (<= 1 allowed for now!)
    #   [topotype, minlevel,maxlevel,fname]
    dtopo_path = os.path.join(scratch_dir, 'dtopo_usgs100227.tt3')
    dtopo_data.dtopofiles.append([3, 3, 3, dtopo_path])
    dtopo_data.dt_max_dtopo = 0.2

    # == setqinit.data values ==
    rundata.qinit_data.qinit_type = 0
    rundata.qinit_data.qinitfiles = []
    # for qinit perturbations, append lines of the form: (<= 1 allowed for now!)
    #   [minlev, maxlev, fname]

    # == setfixedgrids.data values ==
    fixed_grids = rundata.fixed_grid_data
    # for fixed grids append lines of the form
    # [t1,t2,noutput,x1,x2,y1,y2,xpoints,ypoints,\
    #  ioutarrivaltimes,ioutsurfacemax]

    # == fgmax_grids.data values ==
    # NEW STYLE STARTING IN v5.7.0

    # set num_fgmax_val = 1 to save only max depth,
    #                     2 to also save max speed,
    #                     5 to also save max hs,hss,hmin
    rundata.fgmax_data.num_fgmax_val = 2  # Save depth and speed

    fgmax_grids = rundata.fgmax_data.fgmax_grids  # empty list to start

    # Now append to this list objects of class fgmax_tools.FGmaxGrid
    # specifying any fgmax grids.

    # Points on a uniform 2d grid:
    dx_fine = 2. / (3. * 4.)  # grid resolution at finest level

    fg = fgmax_tools.FGmaxGrid()
    fg.point_style = 2  # uniform rectangular x-y grid
    fg.x1 = -120. + dx_fine / 2.
    fg.x2 = -60. - dx_fine / 2.
    fg.y1 = -60. + dx_fine / 2.
    fg.y2 = 0. - dx_fine / 2.
    fg.dx = dx_fine
    fg.tstart_max = 10.  # when to start monitoring max values
    fg.tend_max = 1.e10  # when to stop monitoring max values
    fg.dt_check = 60.  # target time (sec) increment between updating
    # max values
    fg.min_level_check = 3  # which levels to monitor max on
    fg.arrival_tol = 1.e-2  # tolerance for flagging arrival

    fg.interp_method = 0  # 0 ==> pw const in cells, recommended
    fgmax_grids.append(fg)  # written to fgmax_grids.data

    return rundata