chk = DumbCheckpoint(inputdir + "/viscosity", mode=FILE_CREATE)
with timed_stage('initialising viscosity'):
    h_viscosity = Function(V, name="viscosity")
    h_viscosity.interpolate(Max(1., 1000 * (1. - u / 2e4)))
    chk.store(h_viscosity, name="viscosity")
    File(outputdir + '/viscosity.pvd').write(h_viscosity)


# Testing conditional statements
def zbedf(bathy, distance):
    zbed = conditional(ge(bathy, 25 * (1. - distance / 10000.)), bathy,
                       25 * (1. - distance / 10000.))
    return zbed


bath = bathymetry.get_bathymetry(inputs.input_file_paths.bathymetry_file, mesh)

bath.assign(bath + lat)
bathymetry.smoothen_bathymetry(bath)
bath.interpolate(Max(zbedf(bath, u), -50.))  # testing conditional statements

print("Swansea Lagoon boundary bathymetries")

L = 1e3
# 4 is the boundary id of the inlet
# 3 is the inlet of the basin - I'm letting the distance function there start at 1e5
# Set up hydraulic structures
bc2 = [
    DirichletBC(V, 0.0, 6),
    DirichletBC(V, 0.0, 7),  # Double check that
    DirichletBC(V, 0.0, 8),
示例#2
0
def test_interpolator():
    """
    Test NCOM 3d interpolator.

    .. note::
        The following NCOM output files must be present:
        ./forcings/ncom/model_h.nc
        ./forcings/ncom/model_lat.nc
        ./forcings/ncom/model_ang.nc
        ./forcings/ncom/model_lon.nc
        ./forcings/ncom/model_zm.nc
        ./forcings/ncom/2006/s3d/s3d.glb8_2f_2006050100.nc
        ./forcings/ncom/2006/s3d/s3d.glb8_2f_2006050200.nc
        ./forcings/ncom/2006/t3d/t3d.glb8_2f_2006050100.nc
        ./forcings/ncom/2006/t3d/t3d.glb8_2f_2006050200.nc
        ./forcings/ncom/2006/u3d/u3d.glb8_2f_2006050100.nc
        ./forcings/ncom/2006/u3d/u3d.glb8_2f_2006050200.nc
        ./forcings/ncom/2006/v3d/v3d.glb8_2f_2006050100.nc
        ./forcings/ncom/2006/v3d/v3d.glb8_2f_2006050200.nc
        ./forcings/ncom/2006/ssh/ssh.glb8_2f_2006050100.nc
        ./forcings/ncom/2006/ssh/ssh.glb8_2f_2006050200.nc
    """

    # load and extrude mesh
    from bathymetry import get_bathymetry, smooth_bathymetry, smooth_bathymetry_at_bnd
    nlayers, surf_elem_height, max_z_stretch = (9, 5.0, 4.0)
    mesh2d = Mesh('mesh_cre-plume_03_normal.msh')

    # interpolate bathymetry and smooth it
    bathymetry_2d = get_bathymetry('bathymetry_utm_large.nc', mesh2d, project=False)
    bathymetry_2d = smooth_bathymetry(
        bathymetry_2d, delta_sigma=1.0, bg_diff=0,
        alpha=1e2, exponent=2.5,
        minimum_depth=3.5, niter=30)
    bathymetry_2d = smooth_bathymetry_at_bnd(bathymetry_2d, [2, 7])

    # 3d mesh vertical stretch factor
    z_stretch_fact_2d = Function(bathymetry_2d.function_space(), name='z_stretch')
    # 1.0 (sigma mesh) in shallow areas, 4.0 in deep ocean
    z_stretch_fact_2d.project(-ln(surf_elem_height/bathymetry_2d)/ln(nlayers))
    z_stretch_fact_2d.dat.data[z_stretch_fact_2d.dat.data < 1.0] = 1.0
    z_stretch_fact_2d.dat.data[z_stretch_fact_2d.dat.data > max_z_stretch] = max_z_stretch

    extrude_options = {
        'z_stretch_fact': z_stretch_fact_2d,
    }
    mesh = extrude_mesh_sigma(mesh2d, nlayers, bathymetry_2d,
                              **extrude_options)
    p1_2d = get_functionspace(mesh2d, 'CG', 1)
    p1 = get_functionspace(mesh, 'CG', 1)

    # make functions
    salt = Function(p1, name='salinity')
    temp = Function(p1, name='temperature')
    uvel = Function(p1, name='u-velocity')
    vvel = Function(p1, name='v-velocity')
    elev = Function(p1_2d, name='elevation')

    sim_tz = timezone.FixedTimeZone(-8, 'PST')
    init_date = datetime.datetime(2006, 5, 1, tzinfo=sim_tz)
    interp = NCOMInterpolator(
        p1_2d, p1, [salt, temp, uvel, vvel, elev],
        ['Salinity', 'Temperature', 'U_Velocity', 'V_Velocity', 'Surface_Elevation'],
        ['s3d', 't3d', 'u3d', 'v3d', 'ssh'],
        to_latlon, 'forcings/ncom',
        '{year:04d}/{fieldstr:}/{fieldstr:}.glb8_2f_{year:04d}{month:02d}{day:02d}00.nc',
        init_date, COORDSYS, verbose=True
    )
    interp.set_fields(0.0)
    salt_fn = 'tmp/salt.pvd'
    temp_fn = 'tmp/temp.pvd'
    uvel_fn = 'tmp/uvel.pvd'
    vvel_fn = 'tmp/vvel.pvd'
    elev_fn = 'tmp/elev.pvd'
    print('Saving output to {:} {:} {:} {:} {:}'.format(salt_fn, temp_fn, uvel_fn, vvel_fn, elev_fn))
    out_salt = File(salt_fn)
    out_temp = File(temp_fn)
    out_uvel = File(uvel_fn)
    out_vvel = File(vvel_fn)
    out_elev = File(elev_fn)

    out_salt.write(salt)
    out_temp.write(temp)
    out_uvel.write(uvel)
    out_vvel.write(vvel)
    out_elev.write(elev)

    dt = 3*3600.
    for i in range(8):
        print('Time step {:}'.format(i))
        interp.set_fields(i*dt)
        out_salt.write(salt)
        out_temp.write(temp)
        out_uvel.write(uvel)
        out_vvel.write(vvel)
        out_elev.write(elev)
示例#3
0
def test_interpolator():
    """
    Test ROMS 3d interpolator.

    .. note::
        The following ROMS output files must be present:
        ./forcings/liveocean/f2015.05.16/ocean_his_0009.nc
        ./forcings/liveocean/f2015.05.16/ocean_his_0010.nc
        ./forcings/liveocean/f2015.05.16/ocean_his_0011.nc
    """

    # load and extrude mesh
    from bathymetry import get_bathymetry, smooth_bathymetry, smooth_bathymetry_at_bnd
    nlayers, surf_elem_height, max_z_stretch = (9, 5.0, 4.0)
    mesh2d = Mesh('mesh_cre-plume_03_normal.msh')

    # interpolate bathymetry and smooth it
    bathymetry_2d = get_bathymetry('bathymetry_utm_large.nc', mesh2d, project=False)
    bathymetry_2d = smooth_bathymetry(
        bathymetry_2d, delta_sigma=1.0, bg_diff=0,
        alpha=1e2, exponent=2.5,
        minimum_depth=3.5, niter=30)
    bathymetry_2d = smooth_bathymetry_at_bnd(bathymetry_2d, [2, 7])

    # 3d mesh vertical stretch factor
    z_stretch_fact_2d = Function(bathymetry_2d.function_space(), name='z_stretch')
    # 1.0 (sigma mesh) in shallow areas, 4.0 in deep ocean
    z_stretch_fact_2d.project(-ln(surf_elem_height/bathymetry_2d)/ln(nlayers))
    z_stretch_fact_2d.dat.data[z_stretch_fact_2d.dat.data < 1.0] = 1.0
    z_stretch_fact_2d.dat.data[z_stretch_fact_2d.dat.data > max_z_stretch] = max_z_stretch

    extrude_options = {
        'z_stretch_fact': z_stretch_fact_2d,
    }
    mesh = extrude_mesh_sigma(mesh2d, nlayers, bathymetry_2d,
                              **extrude_options)
    p1 = get_functionspace(mesh, 'CG', 1)

    # make functions
    salt = Function(p1, name='salinity')
    temp = Function(p1, name='temperature')

    sim_tz = timezone.FixedTimeZone(-8, 'PST')
    init_date = datetime.datetime(2015, 5, 16, tzinfo=sim_tz)
    interp = LiveOceanInterpolator(p1,
                                   [salt, temp],
                                   ['salt', 'temp'],
                                   'forcings/liveocean/f2015.*/ocean_his_*.nc',
                                   init_date, to_latlon)
    interp.set_fields(0.0)
    salt_fn = 'tmp/salt_roms.pvd'
    temp_fn = 'tmp/temp_roms.pvd'
    print('Saving output to {:} {:}'.format(salt_fn, temp_fn))
    out_salt = File(salt_fn)
    out_temp = File(temp_fn)

    out_salt.write(salt)
    out_temp.write(temp)

    dt = 900.
    for i in range(8):
        print('Time step {:}'.format(i))
        interp.set_fields(i*dt)
        out_salt.write(salt)
        out_temp.write(temp)
示例#4
0
outputdir = 'outputs_{:}'.format(reso_str)
mesh2d = Mesh(meshfile[reso_str])
print_output('Loaded mesh ' + mesh2d.name)

nnodes = comm.allreduce(mesh2d.topology.num_vertices(), MPI.SUM)
ntriangles = comm.allreduce(mesh2d.topology.num_cells(), MPI.SUM)
nprisms = ntriangles * nlayers

sim_tz = timezone.FixedTimeZone(-8, 'PST')
init_date = datetime.datetime(2015, 5, 16, tzinfo=sim_tz)

t_end = 10 * 24 * 3600.
t_export = 900.

# interpolate bathymetry and smooth it
bathymetry_2d = get_bathymetry('bathymetry_300m.npz', mesh2d, project=False)
bathymetry_2d = smooth_bathymetry(bathymetry_2d,
                                  delta_sigma=1.0,
                                  bg_diff=0,
                                  alpha=5e6,
                                  exponent=1,
                                  minimum_depth=3.5,
                                  niter=20)
bathymetry_2d = smooth_bathymetry_at_bnd(bathymetry_2d, [1, 3])

# 3d mesh vertical stretch factor
z_stretch_fact_2d = Function(bathymetry_2d.function_space(), name='z_stretch')
# 1.0 (sigma mesh) in shallow areas, 4.0 in deep ocean
z_stretch_fact_2d.project(-ln(surf_elem_height / bathymetry_2d) / ln(nlayers))
z_stretch_fact_2d.dat.data[z_stretch_fact_2d.dat.data < 1.0] = 1.0
z_stretch_fact_2d.dat.data[
示例#5
0
# set physical constants
physical_constants['rho0'].assign(1000.0)
physical_constants['z0_friction'].assign(0.005)

nlayers = 15
mesh2d = Mesh('mesh_cre-plume_03_normal.msh')
print_output('Loaded mesh ' + mesh2d.name)

dt = 7.0
t_end = 10 * 24 * 3600.
t_export = 900.

# bathymetry
bathymetry_2d = get_bathymetry('bathymetry_utm_large.nc',
                               mesh2d,
                               project=False)
print('bath min: {:} max: {:}'.format(bathymetry_2d.dat.data.min(),
                                      bathymetry_2d.dat.data.max()))

new_bathymetry_2d = smooth_bathymetry(bathymetry_2d,
                                      delta_sigma=1.0,
                                      bg_diff=0,
                                      alpha=1e2,
                                      exponent=2.5,
                                      minimum_depth=3.5,
                                      niter=30)

out = File('bath.pvd')
out.write(bathymetry_2d)
out.write(new_bathymetry_2d)