Exemple #1
0
def make_waves(request, tmp_path_factory):
    # Setup code
    field = fields[request.param['field']]
    grav = field['grav']
    depth = field['depth']
    amps = np.array(field['amps'])
    dirs = np.array(field['dirs']) * np.pi / 180.0
    phases = np.array(field['phases']) * np.pi / 180.0
    Twaves = field['Twaves']
    kwaves = [airy.omega2kwave((2 * np.pi / T), depth, grav) for T in Twaves]
    norder = request.param['norder']
    x0 = request.param['x0']
    y0 = request.param['y0']
    t0 = request.param['t0']
    beta = request.param['beta']
    mysys = corsys.CorSys(x0, y0, t0, beta)
    swd_anal = shape_6.Shape6(amps, dirs, phases, kwaves, depth, norder, grav,
                              mysys)
    swd_anal.tmpdir = str(tmp_path_factory.mktemp("swd"))
    file_swd = os.path.join(swd_anal.tmpdir, "shp_6.swd")
    swd_anal.write_swd(file_swd)
    swd_num = SpectralWaveData(file_swd,
                               x0,
                               y0,
                               t0,
                               beta,
                               rho=1025.0,
                               impl=0,
                               norder=norder,
                               dc_bias=True)

    yield swd_anal, swd_num

    # Teardown code
    swd_num.close()
def make_waves(request, tmp_path_factory):
    # Setup code
    dkx = request.param['dkx']
    dky = request.param['dky']
    nx = request.param['nx']
    ny = request.param['ny']
    impl = 1
    ipol = request.param['ipol']
    seed = request.param['seed']
    norder = request.param['norder']
    x0 = request.param['x0']
    y0 = request.param['y0']
    t0 = request.param['t0']
    beta = request.param['beta']
    mysys = corsys.CorSys(x0, y0, t0, beta)
    cfuns, hfuns = tfun.create_Tfuns_2d(nx, ny, ipol, seed)
    swd_anal = shape_5.Shape5(dkx, dky, nx, ny, d, cfuns, hfuns, norder, mysys)
    swd_anal.tmpdir = str(tmp_path_factory.mktemp("swd"))
    file_swd = os.path.join(swd_anal.tmpdir, "shp_5.swd")
    file_swd_fail = file_swd[:-4] + '_FAIL.swd'
    swd_anal.write_swd(file_swd, dt=dt_swd, nsteps=nsteps)
    swd_anal.write_swd(file_swd_fail, dt=dt_swd, nsteps=nsteps, too_short_file=True)
    swd_num = SpectralWaveData(file_swd=file_swd, x0=x0, y0=y0, t0=t0, beta=beta,
                               rho=1025.0, nsumx=-1, nsumy=-1, impl=impl, ipol=ipol,
                               norder=norder, dc_bias=True)
    swd_num_fail = SpectralWaveData(file_swd=file_swd_fail, x0=x0, y0=y0, t0=t0, beta=beta,
                                    rho=1025.0, nsumx=-1, nsumy=-1, impl=impl, ipol=ipol,
                                    norder=norder, dc_bias=True)
    # Inject class variables
    yield swd_anal, swd_num, swd_num_fail
    # Teardown code
    swd_num.close()
    swd_num_fail.close()
Exemple #3
0
def make_waves(request, tmp_path_factory):
    # Setup code
    impl = request.param['impl']
    dk = request.param['dk']
    d = request.param['d']
    ipol = request.param['ipol']
    nswd = request.param['nswd']
    seed = request.param['seed']
    norder = request.param['norder']
    x0 = request.param['x0']
    y0 = request.param['y0']
    t0 = request.param['t0']
    beta = request.param['beta']
    mysys = corsys.CorSys(x0, y0, t0, beta)
    cfuns, hfuns = tfun.create_Tfuns_1d(nswd, ipol, seed)
    swd_anal = shape_2.Shape2(dk, nswd, d, cfuns, hfuns, norder, mysys)
    file_swd = 'impl_%i_dk_%.4f_nswd_%i_ipol_%i_norder_%i_x0_%.3f_y0_%.3f_t0_%.3f_beta_%.2f_seed_%i.swd' % \
               (impl, dk, nswd, ipol, norder, x0, y0, t0, beta, seed)
    swd_anal.tmpdir = str(tmp_path_factory.mktemp("swd"))
    file_swd = os.path.join(swd_anal.tmpdir, file_swd)
    file_swd_fail = os.path.join(swd_anal.tmpdir, file_swd[:-4] + '_FAIL.swd')
    swd_anal.write_swd(file_swd, dt=dt_swd, nsteps=nsteps)
    swd_anal.write_swd(file_swd_fail,
                       dt=dt_swd,
                       nsteps=nsteps,
                       too_short_file=True)
    swd_num = SpectralWaveData(file_swd=file_swd,
                               x0=x0,
                               y0=y0,
                               t0=t0,
                               beta=beta,
                               rho=1025.0,
                               nsumx=-1,
                               nsumy=-1,
                               impl=impl,
                               ipol=ipol,
                               norder=norder,
                               dc_bias=True)
    swd_num_fail = SpectralWaveData(file_swd=file_swd_fail,
                                    x0=x0,
                                    y0=y0,
                                    t0=t0,
                                    beta=beta,
                                    rho=1025.0,
                                    nsumx=-1,
                                    nsumy=-1,
                                    impl=impl,
                                    ipol=ipol,
                                    norder=norder,
                                    dc_bias=True)
    # Inject class variables
    yield swd_anal, swd_num, swd_num_fail
    # Teardown code
    swd_num.close()
    swd_num_fail.close()
def make_waves(request, tmp_path_factory):
    # Setup code
    impl = request.param['impl']
    dk = request.param['dk']
    nsf = request.param['nsf']
    ipol = request.param['ipol']
    nswd = request.param['nswd']
    seed = request.param['seed']
    norder = request.param['norder']
    x0 = request.param['x0']
    y0 = request.param['y0']
    t0 = request.param['t0']
    beta = request.param['beta']
    mysys = corsys.CorSys(x0, y0, t0, beta)
    cfuns, hfuns = tfun.create_Tfuns_1d(nswd, ipol, seed)
    mytmpdir = str(tmp_path_factory.mktemp("swd"))
    file_swd = os.path.join(mytmpdir, "shp.swd")
    file_swd_fail = file_swd[:-4] + '_FAIL.swd'
    isf = 0
    if nsf == 0:
        nh = -1
        chfuns = []
        xsf = []
        zsf = []
        swd_anal = shape_3.Shape3(dk, nswd, nh, isf, nsf, xsf, zsf, cfuns, chfuns, hfuns, norder, mysys)
        swd_anal.write_swd1(file_swd, dt=dt_swd, nsteps=nsteps)
        swd_anal.write_swd1(file_swd_fail, dt=dt_swd, nsteps=nsteps, too_short_file=True)
    elif nsf == 1:
        nh = nswd
        chfuns = [] # Will be constructed based on flat bottom requirement
        xsf = [0.0]
        zsf = [-3.0]  # Water depth = 3m
        swd_anal = shape_3.Shape3(dk, nswd, nh, isf, nsf, xsf, zsf, cfuns, chfuns, hfuns, norder, mysys)
        swd_anal.write_swd2(file_swd, dt=dt_swd, nsteps=nsteps)
        swd_anal.write_swd2(file_swd_fail, dt=dt_swd, nsteps=nsteps, too_short_file=True)
    else:
        nh = nswd - 1 # To check difference in loop counters
        chfuns, __ = tfun.create_Tfuns_1d(nh, ipol, seed + 1)
        xsf = np.linspace(0.0, 2*np.pi/dk, nsf)
        zsf = [-4.0 - 0.8 * i**2 for i in range(nsf)]
        swd_anal = shape_3.Shape3(dk, nswd, nh, isf, nsf, xsf, zsf, cfuns, chfuns, hfuns, norder, mysys)
        swd_anal.write_swd3(file_swd, dt=dt_swd, nsteps=nsteps)
        swd_anal.write_swd3(file_swd_fail, dt=dt_swd, nsteps=nsteps, too_short_file=True)
    swd_anal.tmpdir = mytmpdir
    swd_num = SpectralWaveData(file_swd=file_swd, x0=x0, y0=y0, t0=t0, beta=beta,
                               rho=1025.0, nsumx=-1, nsumy=-1, impl=impl, ipol=ipol,
                               norder=norder, dc_bias=True)
    swd_num_fail = SpectralWaveData(file_swd=file_swd_fail, x0=x0, y0=y0, t0=t0, beta=beta,
                                    rho=1025.0, nsumx=-1, nsumy=-1, impl=impl, ipol=ipol,
                                    norder=norder, dc_bias=True)
    # Inject class variables
    yield swd_anal, swd_num, swd_num_fail
    # Teardown code
    swd_num.close()
    swd_num_fail.close()
Exemple #5
0
def make_waves(request, tmp_path_factory):
    # Setup code
    dkx = request.param['dkx']
    dky = request.param['dky']
    nx = request.param['nx']
    ny = request.param['ny']
    ipol = request.param['ipol']
    seed = request.param['seed']
    norder = request.param['norder']
    x0 = request.param['x0']
    y0 = request.param['y0']
    t0 = request.param['t0']
    beta = request.param['beta']
    mysys = corsys.CorSys(x0, y0, t0, beta)
    cfuns, hfuns = tfun.create_Tfuns_2d(nx, ny, ipol, seed)
    swd_anal = shape_4.Shape4(dkx, dky, nx, ny, cfuns, hfuns, norder, mysys)
    swd_anal.tmpdir = str(tmp_path_factory.mktemp("swd"))
    file_swd = os.path.join(swd_anal.tmpdir, "shp_4.swd")
    swd_anal.write_swd(file_swd, dt=0.1, nsteps=11)
    # gfortran-9 does not allow a file to be concurrently opened twice...
    file_swd_copy = os.path.join(swd_anal.tmpdir, "shp_4_copy.swd")
    shutil.copy(file_swd, file_swd_copy)
    swd_nums = []
    for impl in [1, 2]:
        if impl == 1 or (impl == 2 and nx == ny and abs(dkx - dky) < 0.00001):
            # This trick of copy file should be removed when gfortran-10 is released
            if impl == 1:
                path = file_swd
            else:
                path = file_swd_copy
            swd_num = SpectralWaveData(path,
                                       x0,
                                       y0,
                                       t0,
                                       beta,
                                       rho=1025.0,
                                       impl=impl,
                                       dc_bias=True)
            swd_nums.append((impl, swd_num))

    yield swd_anal, swd_nums

    # Teardown code
    for impl, swd in swd_nums:
        swd.close()
def make_waves(request, tmp_path_factory):
    # Setup code
    impl = request.param['impl']
    dk = request.param['dk']
    ipol = request.param['ipol']
    nswd = request.param['nswd']
    seed = request.param['seed']
    norder = request.param['norder']
    x0 = request.param['x0']
    y0 = request.param['y0']
    t0 = request.param['t0']
    beta = request.param['beta']
    mysys = corsys.CorSys(x0, y0, t0, beta)
    cfuns, hfuns = tfun.create_Tfuns_1d(nswd, ipol, seed)
    swd_anal = shape_1.Shape1(dk, nswd, cfuns, hfuns, norder, mysys)
    file_swd = 'impl_%i_dk_%.4f_nswd_%i_ipol_%i_norder_%i_x0_%.3f_y0_%.3f_t0_%.3f_beta_%.2f_seed_%i.swd' % \
               (impl, dk, nswd, ipol, norder, x0, y0, t0, beta, seed)
    swd_anal.tmpdir = str(tmp_path_factory.mktemp("swd"))
    file_swd = os.path.join(swd_anal.tmpdir, file_swd)
    #print('file_swd = ', file_swd)
    #swd_anal.dump_spectral_fun(j=0, dt=0.01, tmax=1.0)
    #swd_anal.dump_spectral_fun(j=1, dt=0.01, tmax=1.0)
    #swd_anal.dump_spectral_fun(j=2, dt=0.01, tmax=1.0)
    #swd_anal.dump_spectral_fun(j=3, dt=0.01, tmax=1.0)
    swd_anal.write_swd(file_swd, dt=0.1, nsteps=11)
    swd_num = SpectralWaveData(file_swd,
                               x0,
                               y0,
                               t0,
                               beta,
                               rho=1025.0,
                               impl=impl,
                               dc_bias=True)
    # Inject class variables
    #request.cls.swd_num = swd_num
    #request.cls.swd_anal = swd_anal
    yield swd_anal, swd_num
    # Teardown code
    #print('CLOSE: ', file_swd)
    swd_num.close()
def make_waves(request, tmp_path_factory):
    # Setup code
    dkx = request.param['dkx']
    dky = request.param['dky']
    nx = request.param['nx']
    ny = request.param['ny']
    d = request.param['d']
    ipol = request.param['ipol']
    seed = request.param['seed']
    norder = request.param['norder']
    x0 = request.param['x0']
    y0 = request.param['y0']
    t0 = request.param['t0']
    beta = request.param['beta']
    mysys = corsys.CorSys(x0, y0, t0, beta)
    cfuns, hfuns = tfun.create_Tfuns_2d(nx, ny, ipol, seed)
    swd_anal = shape_5.Shape5(dkx, dky, nx, ny, d, cfuns, hfuns, norder, mysys)
    swd_anal.tmpdir = str(tmp_path_factory.mktemp("swd"))
    file_swd = os.path.join(swd_anal.tmpdir, "shp_5.swd")
    swd_anal.write_swd(file_swd, dt=0.1, nsteps=11)
    swd_nums = []
    #for impl in [1, 2]:  # Later we will also implement impl=2
    for impl in [1]:
        if impl == 1 or (impl == 2 and nx == ny and abs(dkx - dky) < 0.00001):
            swd_num = SpectralWaveData(file_swd,
                                       x0,
                                       y0,
                                       t0,
                                       beta,
                                       rho=1025.0,
                                       impl=impl,
                                       dc_bias=True)
            swd_nums.append((impl, swd_num))

    yield swd_anal, swd_nums

    # Teardown code
    for impl, swd in swd_nums:
        swd.close()
Exemple #8
0
def make_waves(request, tmp_path_factory):
    # Setup code
    impl = request.param['impl']
    dk = request.param['dk']
    nsf = request.param['nsf']
    ipol = request.param['ipol']
    nswd = request.param['nswd']
    seed = request.param['seed']
    norder = request.param['norder']
    x0 = request.param['x0']
    y0 = request.param['y0']
    t0 = request.param['t0']
    beta = request.param['beta']
    mysys = corsys.CorSys(x0, y0, t0, beta)
    cfuns, hfuns = tfun.create_Tfuns_1d(nswd, ipol, seed)
    isf = 0
    if nsf == 0:
        nh = -1
        chfuns = []
        xsf = []
        zsf = []
        swd_anal = shape_3.Shape3(dk, nswd, nh, isf, nsf, xsf, zsf, cfuns,
                                  chfuns, hfuns, norder, mysys)
    elif nsf == 1:
        nh = nswd
        chfuns = []  # Will be constructed based on flat bottom requirement
        xsf = [0.0]
        zsf = [-3.0]  # Water depth = 3m
        swd_anal = shape_3.Shape3(dk, nswd, nh, isf, nsf, xsf, zsf, cfuns,
                                  chfuns, hfuns, norder, mysys)
    else:
        nh = nswd - 1  # To check difference in loop counters
        chfuns, __ = tfun.create_Tfuns_1d(nh, ipol, seed + 1)
        xsf = np.linspace(0.0, 2 * np.pi / dk, nsf)
        zsf = [-4.0 - 0.8 * i**2 for i in range(nsf)]
        swd_anal = shape_3.Shape3(dk, nswd, nh, isf, nsf, xsf, zsf, cfuns,
                                  chfuns, hfuns, norder, mysys)
    swd_anal.tmpdir = str(tmp_path_factory.mktemp("swd"))
    file_swd1 = os.path.join(swd_anal.tmpdir, "shp1.swd")
    file_swd2 = os.path.join(swd_anal.tmpdir, "shp2.swd")
    file_swd3 = os.path.join(swd_anal.tmpdir, "shp3.swd")

    if nsf == 0:
        swd_anal.write_swd1(file_swd1, dt=0.1, nsteps=11)
        swd_num1 = SpectralWaveData(file_swd1,
                                    x0,
                                    y0,
                                    t0,
                                    beta,
                                    rho=1025.0,
                                    impl=impl,
                                    dc_bias=True)
    else:
        swd_num1 = None
    if nsf == 1:
        swd_anal.write_swd2(file_swd2, dt=0.1, nsteps=11)
        swd_num2 = SpectralWaveData(file_swd2,
                                    x0,
                                    y0,
                                    t0,
                                    beta,
                                    rho=1025.0,
                                    impl=impl,
                                    dc_bias=True)
    else:
        swd_num2 = None

    swd_anal.write_swd3(file_swd3, dt=0.1, nsteps=11)
    swd_num3 = SpectralWaveData(file_swd3,
                                x0,
                                y0,
                                t0,
                                beta,
                                rho=1025.0,
                                impl=impl,
                                dc_bias=True)

    yield swd_anal, swd_num1, swd_num2, swd_num3, nsf

    # Teardown code
    if nsf == 0:
        #print("CLOSE: ", file_swd1)
        swd_num1.close()
    if nsf == 1:
        #print("CLOSE: ", file_swd2)
        swd_num2.close()
    #print("CLOSE: ", file_swd3)
    swd_num3.close()