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
def sample():
    np.random.seed()
    return (np.random.uniform(0.035, 0.5, 1))[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
Ejemplo n.º 3
0
def sample():
    np.random.seed()
    return (np.random.uniform(0.035, 0.5, 1))[0]


M = 2  # integer factor that meshsize is refined by at each level
Lmin = 2  # minimum refinement level
Lmax = 8  # 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.length_y = 1000
bathy.dx = bathy.length_x / M**Lmax
bathy.dy = bathy.length_y / M**Lmax
bathy.mc_slope_test(bathy.dx, bathy.dy, 0.6, 0.15, 0.15)

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

# epsilon values - for CDF calculation this should be set to epsilon = [0.001]
epsilon = [0.001, 0.0017, 0.0025, 0.0035, 0.005, 0.006]
N0 = 500  # number of samples used in preliminary run

# set the function which builds XBeach inputs, runs XBeach and records output
Ejemplo n.º 4
0
# set the function which builds XBeach inputs, runs XBeach and records output
build_output = bd_fns.build_xbeach
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_mc/1/'

variable_name = 'bed_slope'  # name of uncertain variable

M = 2  # integer factor that meshsize is refined by at each level

t1 = time.time()

L_eps = 13  # fineness of grid

bathy = Bathymetry()

bathy.length_x = 1250
bathy.dx = bathy.length_x / M**L_eps

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)

# run monte carlo algorithm
outputf, real_soln, file_name = mc_fn.monte_carlo_main(2000, M**L_eps,
                                                       build_output, path_stem,
                                                       sample, variable_name,
                                                       no_parallel_processes,
                                                       interp_orig_fn)
Ejemplo n.º 5
0
            elif runs[k] in ['m1n3']:
                p['mmpi'] = 1
                p['nmpi'] = 3
                nprocesses = 3

            elif runs[k] in ['m3n3']:
                p['mmpi'] = 3
                p['nmpi'] = 3
                nprocesses = 9

###MAKING THE BATHYMETRIES AND CREATING THE XBEACH INPUT FILES###
            xb = XBeachModel(**p)
            bp = b.copy()
            bp.update(p)
            bathy = Bathymetry(**bp)

            if runs[k] in ['m1', 'm3']:
                if b['shape'][i] in ['flat']:
                    bathy.flat_1d()
                elif b['shape'][i] in ['dune']:
                    bathy.dune_1d()
                XBbathy = XBeachBathymetry(bathy.x, bathy.z)

            else:
                if b['shape'][i] in ['flat']:
                    bathy.flat_2d()
                elif b['shape'][i] in ['dune']:
                    bathy.dune_2d()
                XBbathy = XBeachBathymetry(bathy.x, bathy.y, bathy.z)