Ejemplo n.º 1
0
def build_xbeach(diroutmain,
                 nf,
                 sigma,
                 variable_name,
                 interp_fn_orig,
                 l_max,
                 l_min=1):

    total_length_x = 1250

    # set up parameters for XBeach input
    p = dict(
        #processes
        order=1,
        bedfriccoef=55,
        flow=1,
        sedtrans=0,
        morphology=0,
        avalanching=0,
        cyclic=0,
        wavemodel='nonh',
        #grid
        dx=total_length_x / nf,
        dy=0,
        vardx=1,
        posdwn=0,
        xfile='x.txt',
        xori=0,
        yori=0,
        Hrms=2.5,
        Trep=10,
        dir0=270,
        instat='stat',
        front='nonh_1d',
        #output
        outputformat='netcdf',
        tintg=200,
        tintm=200,
        tstop=200,
        nglobalvar=['zb', 'zs', 'hh'],
        nmeanvar=['zs', 'u'])
    #nx = 2**6)

    b = dict(height=2, length_x=total_length_x)

    logger = logging.getLogger(__name__)
    logger.info('setup.py is called for')

    # create directory where XBeach will run
    path = os.path.join(diroutmain, 'test')
    if not os.path.exists(path):
        os.makedirs(path)
    # if less than minimum level considered in algorithm, return 0
    if nf <= l_min:
        maximum_surge = 0
        return maximum_surge

    if variable_name == 'bed_slope':
        xb = XBeachModel(**p)
        bp = b.copy()
        bp.update(p)
        bathy = Bathymetry(**bp)
        bed_slope = sigma
        bathy.mc_slope(b['length_x'] / (l_max), 0.6, bed_slope)
        interp_fn = interpolate.interp1d(bathy.x, bathy.z)
        dx = b['length_x'] / nf
        x = np.arange(0, b['length_x'] + dx, dx)
        z = interp_fn(x)
    else:
        bed_slope = 0.15
        exec("p['" + variable_name + "'] = " + str(sigma))
        dx = b['length_x'] / nf
        x = np.arange(0, b['length_x'] + dx, dx)
        z = interp_fn_orig(x)
        xb = XBeachModel(**p)
        bp = b.copy()
        bp.update(p)
        bathy = Bathymetry(**bp)

    XBbathy = XBeachBathymetry(x, z)

    logger.debug(XBbathy)

    xb['bathymetry'] = XBbathy

    os.chdir(path)

    xb.write(path)

    # run XBeach
    subprocess.check_call(
        "/rds/general/user/mc4117/home/trunk/src/xbeach/xbeach > /dev/null",
        shell=True)

    # collect output
    dataset = Dataset('xboutput.nc')

    x_array = dataset.variables['globalx'][0]

    a = (dataset.variables['zs_max'][0] -
         dataset.variables['zb'][0]).data[0][0:len(x_array) - 1]

    # find point at which the water level stops being above the bed level
    count = len(a[a > 0.00000001])

    maximum_surge = x_array[count - 1] / total_length_x

    return maximum_surge
Ejemplo n.º 2
0
M = 2 # integer factor that meshsize is refined by at each level
Lmin = 2  # minimum refinement level
Lmax = 12  # maximum refinement level
L = 7

# list of all levels considered
l_element = []
for i in range(Lmin, Lmax+1):
    l_element.append(i)

bathy = Bathymetry()

bathy.length_x = 1250
bathy.dx = bathy.length_x/M**(Lmax+1)

bathy.mc_slope(bathy.dx, 0.6, 0.15)

# interpolation function used to generate bed on new x and y grid
interp_orig_fn = interpolate.interp1d(bathy.x, bathy.z)

# epsilon values - for CDF calculation this should be set to epsilon = [0.0002]
epsilon = [0.0002, 0.0005, 0.0008, 0.0012, 0.002, 0.003]
N0 = 750 # number of samples used in preliminary run

# set the function which builds XBeach inputs, runs XBeach and records output
build_output = bd_fns.build_xbeach
no_runs = 1
no_parallel_processes = 48 # should be equal to number of cores

# directory where XBeach files will be dumped and code will run - this needs to be changed to reflect name of folder
path_stem = '/rds/general/user/mc4117/home/MLMC_Code/slope_1d_interp/'