Пример #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()
Пример #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()
Пример #5
0
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()
Пример #6
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()
Пример #7
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']
    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()
Пример #8
0
def main():

    narg = len(sys.argv)
    if narg != 2:
        print("Usage: swd_meta my.swd")
        sys.exit()
    file_swd = sys.argv[-1]

    try:
        swd = SpectralWaveData(file_swd, x0=0.0, y0=0.0, t0=0.0, beta=0.0)
    except SwdFileCantOpenError as e:
        print("Not able to open: %s" % file_swd)
        sys.exit()
    except SwdFileBinaryError as e:
        print("This SWD file don't have the correct binary convention: %s" %
              file_swd)
        sys.exit()
    except SwdFileBinaryError as e:
        print("This file don't look like a SWD-file: %s" % file_swd)
        sys.exit()

    def write(tag):
        print('%-8s %s' % (tag + ':', swd[tag]))

    write('version')
    write('prog')
    write('date')
    write('fmt')
    write('shp')
    write('amp')
    write('tmax')
    write('dt')
    write('nsteps')
    write('nstrip')
    write('order')
    write('d')

    shp = swd['shp']
    if shp in [1, 2, 3]:
        # Long-crested seas
        write('n')
        if shp == 3:
            write('nh')
        write('sizex')
        write('lmax')
        write('lmin')
        write('dk')

    if shp in [4, 5]:
        # Short-crested seas
        write('nx')
        write('ny')
        write('sizex')
        write('sizey')
        write('lmax')
        write('lmin')
        write('dkx')
        write('dky')

    if shp in [6]:
        # Airy waves
        write('n')

    write('cid')
Пример #9
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()
Пример #10
0
def test_waves(make_waves):
    swd_anal, swd_num1, swd_num2, swd_num3, nsf = make_waves

    #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)

    for t in ts:

        if swd_num1 is not None:
            swd_num1.update_time(t)
        if swd_num2 is not None:
            swd_num2.update_time(t)
        swd_num3.update_time(t)

        for x in xs:
            for y in ys:
                for z in zs:

                    phi_anal = swd_anal.phi(x, y, z, t)
                    phi_num3 = swd_num3.phi(x, y, z)
                    assert math.isclose(phi_num3,
                                        phi_anal,
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        phi_num1 = swd_num1.phi(x, y, z)
                        assert math.isclose(phi_num1,
                                            phi_num3,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        phi_num2 = swd_num2.phi(x, y, z)
                        assert math.isclose(phi_num2,
                                            phi_num3,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    stream_anal = swd_anal.stream(x, y, z, t)
                    stream_num3 = swd_num3.stream(x, y, z)
                    assert math.isclose(stream_num3,
                                        stream_anal,
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        stream_num1 = swd_num1.stream(x, y, z)
                        assert math.isclose(stream_num1,
                                            stream_num3,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        stream_num2 = swd_num2.stream(x, y, z)
                        assert math.isclose(stream_num2,
                                            stream_num3,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    phi_t_anal = swd_anal.phi_t(x, y, z, t)
                    phi_t_num3 = swd_num3.phi_t(x, y, z)
                    assert math.isclose(phi_t_num3,
                                        phi_t_anal,
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        phi_t_num1 = swd_num1.phi_t(x, y, z)
                        assert math.isclose(phi_t_num1,
                                            phi_t_num3,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        phi_t_num2 = swd_num2.phi_t(x, y, z)
                        assert math.isclose(phi_t_num2,
                                            phi_t_num3,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    grad_phi_anal = swd_anal.grad_phi(x, y, z, t)
                    grad_phi_num3 = swd_num3.grad_phi(x, y, z)
                    assert math.isclose(grad_phi_num3.x,
                                        grad_phi_anal['x'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(grad_phi_num3.y,
                                        grad_phi_anal['y'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(grad_phi_num3.z,
                                        grad_phi_anal['z'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        grad_phi_num1 = swd_num1.grad_phi(x, y, z)
                        assert math.isclose(grad_phi_num1.x,
                                            grad_phi_num3.x,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_phi_num1.y,
                                            grad_phi_num3.y,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_phi_num1.z,
                                            grad_phi_num3.z,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        grad_phi_num2 = swd_num2.grad_phi(x, y, z)
                        assert math.isclose(grad_phi_num2.x,
                                            grad_phi_num3.x,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_phi_num2.y,
                                            grad_phi_num3.y,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_phi_num2.z,
                                            grad_phi_num3.z,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    g2nd_anal = swd_anal.grad_phi_2nd(x, y, z, t)
                    g2nd_num3 = swd_num3.grad_phi_2nd(x, y, z)
                    assert math.isclose(g2nd_num3.xx,
                                        g2nd_anal['xx'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(g2nd_num3.xy,
                                        g2nd_anal['xy'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(g2nd_num3.xz,
                                        g2nd_anal['xz'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(g2nd_num3.yy,
                                        g2nd_anal['yy'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(g2nd_num3.yz,
                                        g2nd_anal['yz'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(g2nd_num3.zz,
                                        g2nd_anal['zz'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        g2nd_num1 = swd_num1.grad_phi_2nd(x, y, z)
                        assert math.isclose(g2nd_num1.xx,
                                            g2nd_num3.xx,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num1.xy,
                                            g2nd_num3.xy,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num1.xz,
                                            g2nd_num3.xz,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num1.yy,
                                            g2nd_num3.yy,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num1.yz,
                                            g2nd_num3.yz,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num1.zz,
                                            g2nd_num3.zz,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        g2nd_num2 = swd_num2.grad_phi_2nd(x, y, z)
                        assert math.isclose(g2nd_num2.xx,
                                            g2nd_num3.xx,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num2.xy,
                                            g2nd_num3.xy,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num2.xz,
                                            g2nd_num3.xz,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num2.yy,
                                            g2nd_num3.yy,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num2.yz,
                                            g2nd_num3.yz,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num2.zz,
                                            g2nd_num3.zz,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    acc_euler_anal = swd_anal.acc_euler(x, y, z, t)
                    acc_euler_num3 = swd_num3.acc_euler(x, y, z)
                    assert math.isclose(acc_euler_num3.x,
                                        acc_euler_anal['x'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(acc_euler_num3.y,
                                        acc_euler_anal['y'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(acc_euler_num3.z,
                                        acc_euler_anal['z'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        acc_euler_num1 = swd_num1.acc_euler(x, y, z)
                        assert math.isclose(acc_euler_num1.x,
                                            acc_euler_num3.x,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(acc_euler_num1.y,
                                            acc_euler_num3.y,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(acc_euler_num1.z,
                                            acc_euler_num3.z,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        acc_euler_num2 = swd_num2.acc_euler(x, y, z)
                        assert math.isclose(acc_euler_num2.x,
                                            acc_euler_num3.x,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(acc_euler_num2.y,
                                            acc_euler_num3.y,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(acc_euler_num2.z,
                                            acc_euler_num3.z,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    acc_particle_anal = swd_anal.acc_particle(x, y, z, t)
                    acc_particle_num3 = swd_num3.acc_particle(x, y, z)
                    assert math.isclose(acc_particle_num3.x,
                                        acc_particle_anal['x'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(acc_particle_num3.y,
                                        acc_particle_anal['y'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(acc_particle_num3.z,
                                        acc_particle_anal['z'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        acc_particle_num1 = swd_num1.acc_particle(x, y, z)
                        assert math.isclose(acc_particle_num1.x,
                                            acc_particle_num3.x,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(acc_particle_num1.y,
                                            acc_particle_num3.y,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(acc_particle_num1.z,
                                            acc_particle_num3.z,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        acc_particle_num2 = swd_num2.acc_particle(x, y, z)
                        assert math.isclose(acc_particle_num2.x,
                                            acc_particle_num3.x,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(acc_particle_num2.y,
                                            acc_particle_num3.y,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(acc_particle_num2.z,
                                            acc_particle_num3.z,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    prs_anal = swd_anal.pressure(x,
                                                 y,
                                                 z,
                                                 t,
                                                 rho=1025.0,
                                                 grav=9.81)
                    prs_num3 = swd_num3.pressure(x, y, z)
                    assert math.isclose(prs_num3, prs_anal, rel_tol=1e-03)
                    if swd_num1 is not None:
                        prs_num1 = swd_num1.pressure(x, y, z)
                        assert math.isclose(prs_num1, prs_num3, rel_tol=1e-03)
                    if swd_num2 is not None:
                        prs_num2 = swd_num2.pressure(x, y, z)
                        assert math.isclose(prs_num2, prs_num3, rel_tol=1e-03)

                    elev_anal = swd_anal.elev(x, y, t)
                    elev_num3 = swd_num3.elev(x, y)
                    assert math.isclose(elev_num3,
                                        elev_anal,
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        elev_num1 = swd_num1.elev(x, y)
                        assert math.isclose(elev_num1,
                                            elev_num3,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        elev_num2 = swd_num2.elev(x, y)
                        assert math.isclose(elev_num2,
                                            elev_num3,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    elev_t_anal = swd_anal.elev_t(x, y, t)
                    elev_t_num3 = swd_num3.elev_t(x, y)
                    assert math.isclose(elev_t_num3,
                                        elev_t_anal,
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        elev_t_num1 = swd_num1.elev_t(x, y)
                        assert math.isclose(elev_t_num1,
                                            elev_t_num3,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        elev_t_num2 = swd_num2.elev_t(x, y)
                        assert math.isclose(elev_t_num2,
                                            elev_t_num3,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    grad_elev_anal = swd_anal.grad_elev(x, y, t)
                    grad_elev_num3 = swd_num3.grad_elev(x, y)
                    assert math.isclose(grad_elev_num3.x,
                                        grad_elev_anal['x'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(grad_elev_num3.y,
                                        grad_elev_anal['y'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(grad_elev_num3.z,
                                        grad_elev_anal['z'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        grad_elev_num1 = swd_num1.grad_elev(x, y)
                        assert math.isclose(grad_elev_num1.x,
                                            grad_elev_num3.x,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_elev_num1.y,
                                            grad_elev_num3.y,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_elev_num1.z,
                                            grad_elev_num3.z,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        grad_elev_num2 = swd_num2.grad_elev(x, y)
                        assert math.isclose(grad_elev_num2.x,
                                            grad_elev_num3.x,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_elev_num2.y,
                                            grad_elev_num3.y,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_elev_num2.z,
                                            grad_elev_num3.z,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    g2nd_elev_anal = swd_anal.grad_elev_2nd(x, y, t)
                    g2nd_elev_num3 = swd_num3.grad_elev_2nd(x, y)
                    assert math.isclose(g2nd_elev_num3.xx,
                                        g2nd_elev_anal['xx'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(g2nd_elev_num3.xy,
                                        g2nd_elev_anal['xy'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    assert math.isclose(g2nd_elev_num3.yy,
                                        g2nd_elev_anal['yy'],
                                        rel_tol=1e-04,
                                        abs_tol=1e-04)
                    if swd_num1 is not None:
                        g2nd_elev_num1 = swd_num1.grad_elev_2nd(x, y)
                        assert math.isclose(g2nd_elev_num1.xx,
                                            g2nd_elev_num3.xx,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_elev_num1.xy,
                                            g2nd_elev_num3.xy,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_elev_num1.yy,
                                            g2nd_elev_num3.yy,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                    if swd_num2 is not None:
                        g2nd_elev_num2 = swd_num2.grad_elev_2nd(x, y)
                        assert math.isclose(g2nd_elev_num2.xx,
                                            g2nd_elev_num3.xx,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_elev_num2.xy,
                                            g2nd_elev_num3.xy,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_elev_num2.yy,
                                            g2nd_elev_num3.yy,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    if abs(swd_anal.sys.t0 -
                           0.34) < 1.0e-6 and abs(t - 0.52) < 1.0e-6:
                        # Check if strip method produce a swd file with consistent kinematic results.
                        file_swd_strip = os.path.join(swd_anal.tmpdir,
                                                      'stripped.swd')
                        swd_num3.strip(tmin=0.31,
                                       tmax=0.61,
                                       file_swd=file_swd_strip)
                        swd_num3_strip = SpectralWaveData(
                            file_swd_strip,
                            x0=swd_anal.sys.x0,
                            y0=swd_anal.sys.y0,
                            t0=0.0,
                            beta=swd_anal.sys.beta,
                            rho=1025.0,
                            impl=impl,
                            dc_bias=True)
                        nstrip = swd_num3_strip.get('nstrip')
                        assert nstrip > 0

                        t_strip = (
                            swd_anal.sys.t0 + t
                        ) - nstrip * 0.1  # dt=0.1 in swd file, nstrip includes t=0.0
                        swd_num3_strip.update_time(t_strip)

                        phi_num3_strip = swd_num3_strip.phi(x, y, z)
                        assert math.isclose(phi_num3,
                                            phi_num3_strip,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                        elev_t_num3_strip = swd_num3_strip.elev_t(x, y)
                        assert math.isclose(elev_t_num3,
                                            elev_t_num3_strip,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                        swd_num3_strip.close()

                    file_convergence = os.path.join(swd_anal.tmpdir,
                                                    'file_convergence.csv')
                    swd_num3.convergence(x, y, z, csv=file_convergence)
                    with open(file_convergence, 'r') as f:
                        lines = f.read().splitlines()
                        words = lines[-1].split(',')

                    phi_x_convergence = float(words[1])
                    phi_y_convergence = float(words[2])
                    phi_z_convergence = float(words[3])
                    assert math.isclose(grad_phi_num3.x,
                                        phi_x_convergence,
                                        rel_tol=1e-07,
                                        abs_tol=1e-04)
                    assert math.isclose(grad_phi_num3.y,
                                        phi_y_convergence,
                                        rel_tol=1e-07,
                                        abs_tol=1e-04)
                    assert math.isclose(grad_phi_num3.z,
                                        phi_z_convergence,
                                        rel_tol=1e-07,
                                        abs_tol=1e-04)

                    elev_convergence = float(words[4])
                    assert math.isclose(elev_num3,
                                        elev_convergence,
                                        rel_tol=1e-07,
                                        abs_tol=1e-04)

                    prs_convergence = float(words[5])
                    assert math.isclose(prs_num3,
                                        prs_convergence,
                                        rel_tol=1e-07,
                                        abs_tol=1e-04)

        depth_anal = swd_anal.bathymetry(x_app=3.4, y_app=-5.3)
        depth_num3 = swd_num3.bathymetry(x=3.4, y=-5.3)
        if depth_anal < 0:
            assert depth_num3 < 0
        else:
            assert math.isclose(depth_num3, depth_anal, rel_tol=1e-5)

        nvec_floor_anal = swd_anal.bathymetry_nvec(x_app=3.4, y_app=-5.3)
        nvec_floor_num3 = swd_num3.bathymetry_nvec(x=3.4, y=-5.3)
        assert math.isclose(nvec_floor_anal['x'],
                            nvec_floor_num3.x,
                            abs_tol=1e-5)
        assert math.isclose(nvec_floor_anal['y'],
                            nvec_floor_num3.y,
                            abs_tol=1e-5)
        assert math.isclose(nvec_floor_anal['z'],
                            nvec_floor_num3.z,
                            rel_tol=1e-5)

        nswd_file = swd_num3.get('n')
        assert isinstance(nswd_file, int)
        assert nswd_file == 3

        dt_swd = swd_num3.get('dt')
        assert isinstance(dt_swd, float)
        assert math.isclose(dt_swd, 0.1, rel_tol=1e-5)

        cid = swd_num3.get('cid')
        assert isinstance(cid, str)
        assert cid == "{'ole':1, 'dole':2, 'doffen':3}"
Пример #11
0
def test_waves(make_waves):
    swd_anal, swd_nums = make_waves

    nx = swd_anal.nx
    ny = swd_anal.ny

    for jx in range(nx + 1):
        for jy in range(ny, ny + 1):
            swd_anal.dump_spectral_fun(jx, jy, dt=0.01, tmax=1.0)

    for t in ts:

        for impl, swd in swd_nums:
            swd.update_time(t)

        for x in xs:
            for y in ys:
                for z in zs:

                    phi_anal = swd_anal.phi(x, y, z, t)
                    for impl, swd in swd_nums:
                        phi_num = swd.phi(x, y, z)
                        assert math.isclose(phi_anal,
                                            phi_num,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    stream_anal = swd_anal.stream(x, y, z, t)
                    for impl, swd in swd_nums:
                        stream_num = swd.stream(x, y, z)
                        assert math.isclose(stream_anal,
                                            stream_num,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    phi_t_anal = swd_anal.phi_t(x, y, z, t)
                    for impl, swd in swd_nums:
                        phi_t_num = swd.phi_t(x, y, z)
                        assert math.isclose(phi_t_anal,
                                            phi_t_num,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    grad_phi_anal = swd_anal.grad_phi(x, y, z, t)
                    for impl, swd in swd_nums:
                        grad_phi_num = swd.grad_phi(x, y, z)
                        assert math.isclose(grad_phi_num.x,
                                            grad_phi_anal['x'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_phi_num.y,
                                            grad_phi_anal['y'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_phi_num.z,
                                            grad_phi_anal['z'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    g2nd_anal = swd_anal.grad_phi_2nd(x, y, z, t)
                    for impl, swd in swd_nums:
                        g2nd_num = swd.grad_phi_2nd(x, y, z)
                        assert math.isclose(g2nd_num.xx,
                                            g2nd_anal['xx'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num.xy,
                                            g2nd_anal['xy'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num.xz,
                                            g2nd_anal['xz'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num.yy,
                                            g2nd_anal['yy'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num.yz,
                                            g2nd_anal['yz'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_num.zz,
                                            g2nd_anal['zz'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    acc_euler_anal = swd_anal.acc_euler(x, y, z, t)
                    for impl, swd in swd_nums:
                        acc_euler_num = swd.acc_euler(x, y, z)
                        assert math.isclose(acc_euler_num.x,
                                            acc_euler_anal['x'],
                                            rel_tol=1e-03,
                                            abs_tol=1e-03)
                        assert math.isclose(acc_euler_num.y,
                                            acc_euler_anal['y'],
                                            rel_tol=1e-03,
                                            abs_tol=1e-03)
                        assert math.isclose(acc_euler_num.z,
                                            acc_euler_anal['z'],
                                            rel_tol=1e-03,
                                            abs_tol=1e-03)

                    acc_particle_anal = swd_anal.acc_particle(x, y, z, t)
                    for impl, swd in swd_nums:
                        acc_particle_num = swd.acc_particle(x, y, z)
                        assert math.isclose(acc_particle_num.x,
                                            acc_particle_anal['x'],
                                            rel_tol=1e-03,
                                            abs_tol=1e-03)
                        assert math.isclose(acc_particle_num.y,
                                            acc_particle_anal['y'],
                                            rel_tol=1e-03,
                                            abs_tol=1e-03)
                        assert math.isclose(acc_particle_num.z,
                                            acc_particle_anal['z'],
                                            rel_tol=1e-03,
                                            abs_tol=1e-03)

                    prs_anal = swd_anal.pressure(x,
                                                 y,
                                                 z,
                                                 t,
                                                 rho=1025.0,
                                                 grav=9.81)
                    for impl, swd in swd_nums:
                        prs_num = swd.pressure(x, y, z)
                        assert math.isclose(prs_num, prs_anal, rel_tol=1e-03)

                    elev_anal = swd_anal.elev(x, y, t)
                    for impl, swd in swd_nums:
                        elev_num = swd.elev(x, y)
                        assert math.isclose(elev_num,
                                            elev_anal,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    elev_t_anal = swd_anal.elev_t(x, y, t)
                    for impl, swd in swd_nums:
                        elev_t_num = swd.elev_t(x, y)
                        assert math.isclose(elev_t_num,
                                            elev_t_anal,
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    grad_elev_anal = swd_anal.grad_elev(x, y, t)
                    for impl, swd in swd_nums:
                        grad_elev_num = swd.grad_elev(x, y)
                        assert math.isclose(grad_elev_num.x,
                                            grad_elev_anal['x'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_elev_num.y,
                                            grad_elev_anal['y'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_elev_num.z,
                                            grad_elev_anal['z'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    g2nd_elev_anal = swd_anal.grad_elev_2nd(x, y, t)
                    for impl, swd in swd_nums:
                        g2nd_elev_num = swd.grad_elev_2nd(x, y)
                        assert math.isclose(g2nd_elev_num.xx,
                                            g2nd_elev_anal['xx'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_elev_num.xy,
                                            g2nd_elev_anal['xy'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)
                        assert math.isclose(g2nd_elev_num.yy,
                                            g2nd_elev_anal['yy'],
                                            rel_tol=1e-04,
                                            abs_tol=1e-04)

                    if abs(swd_anal.sys.t0 -
                           0.34) < 1.0e-6 and abs(t - 0.52) < 1.0e-6:
                        # Check if strip method produce a swd file with consistent kinematic results.
                        for impl, swd in swd_nums:
                            file_swd_strip = os.path.join(
                                swd_anal.tmpdir, 'stripped.swd')
                            swd.strip(tmin=0.31,
                                      tmax=0.61,
                                      file_swd=file_swd_strip)
                            swd_num_strip = SpectralWaveData(
                                file_swd_strip,
                                x0=swd_anal.sys.x0,
                                y0=swd_anal.sys.y0,
                                t0=0.0,
                                beta=swd_anal.sys.beta,
                                rho=1025.0,
                                impl=impl,
                                dc_bias=True)
                            nstrip = swd_num_strip.get('nstrip')
                            assert nstrip > 0

                            t_strip = (
                                swd_anal.sys.t0 + t
                            ) - nstrip * 0.1  # dt=0.1 in swd file, nstrip includes t=0.0
                            swd_num_strip.update_time(t_strip)

                            phi_num_strip = swd_num_strip.phi(x, y, z)
                            assert math.isclose(phi_num,
                                                phi_num_strip,
                                                rel_tol=1e-04,
                                                abs_tol=1e-04)

                            elev_t_num_strip = swd_num_strip.elev_t(x, y)
                            assert math.isclose(elev_t_num,
                                                elev_t_num_strip,
                                                rel_tol=1e-04,
                                                abs_tol=1e-04)

                            swd_num_strip.close()

                    file_convergence = os.path.join(swd_anal.tmpdir,
                                                    'file_convergence.csv')
                    for impl, swd in swd_nums:
                        swd.convergence(x, y, z, csv=file_convergence)
                        with open(file_convergence, 'r') as f:
                            lines = f.read().splitlines()
                            words = lines[-1].split(',')

                        phi_x_convergence = float(words[1])
                        phi_y_convergence = float(words[2])
                        phi_z_convergence = float(words[3])
                        assert math.isclose(grad_phi_num.x,
                                            phi_x_convergence,
                                            rel_tol=1e-07,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_phi_num.y,
                                            phi_y_convergence,
                                            rel_tol=1e-07,
                                            abs_tol=1e-04)
                        assert math.isclose(grad_phi_num.z,
                                            phi_z_convergence,
                                            rel_tol=1e-07,
                                            abs_tol=1e-04)

                        elev_convergence = float(words[4])
                        assert math.isclose(elev_num,
                                            elev_convergence,
                                            rel_tol=1e-07,
                                            abs_tol=1e-04)

                        prs_convergence = float(words[5])
                        assert math.isclose(prs_num,
                                            prs_convergence,
                                            rel_tol=1e-07,
                                            abs_tol=1e-04)

        depth_anal = swd_anal.bathymetry(x_app=3.4, y_app=-5.3)
        nvec_floor_anal = swd_anal.bathymetry_nvec(x_app=3.4, y_app=-5.3)
        for impl, swd in swd_nums:
            depth_num = swd.bathymetry(x=3.4, y=-5.3)
            if depth_anal < 0:
                assert depth_num < 0
            else:
                assert math.isclose(depth_num, depth_anal, rel_tol=1e-5)
            nvec_floor_num = swd.bathymetry_nvec(x=3.4, y=-5.3)
            assert math.isclose(nvec_floor_anal['x'],
                                nvec_floor_num.x,
                                abs_tol=1e-5)
            assert math.isclose(nvec_floor_anal['y'],
                                nvec_floor_num.y,
                                abs_tol=1e-5)
            assert math.isclose(nvec_floor_anal['z'],
                                nvec_floor_num.z,
                                rel_tol=1e-5)

        for impl, swd in swd_nums:
            # Check the get method for int, float and strings arguments
            nx_file = swd.get('nx')
            assert isinstance(nx_file, int)
            assert nx_file == swd_anal.nx

            dt_swd = swd.get('dt')
            assert isinstance(dt_swd, float)
            assert math.isclose(dt_swd, 0.1, rel_tol=1e-5)

            cid = swd.get('cid')
            assert isinstance(cid, str)
            assert cid == "{'ole':1, 'dole':2, 'doffen':3}"
ipol = 0  # C^2 continous

# Optional: Select expansion order for calculating kinematics above z=0
norder = 0  # Apply same order as specified in SWD file

# Optional: Control handling of zero-frequency components in SWD file
dc_bias = False  # Suppress contributions from zero-frequency

# Constructor
try:
    swd = SpectralWaveData('stokesTest_shallowWater.swd',
                           x0,
                           y0,
                           t0,
                           beta,
                           rho=rho,
                           nsumx=nsumx,
                           nsumy=nsumy,
                           impl=impl,
                           ipol=ipol,
                           norder=norder,
                           dc_bias=dc_bias)
except SwdError as e:
    print(str(e))
    # Do whatever necessary...
    raise

# Time domain simulation...
t = 0.0
dt = 0.1
tmax = 1.0
while t < tmax: