Exemplo n.º 1
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}"
Exemplo n.º 2
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}"
dt = 0.1
tmax = 1.0
while t < tmax:

    # Tell the swd object current application time...
    swd.update_time(t)

    # Application coordinate where we need kinematics...
    x = 4.3
    y = 5.4
    z = -1.7

    # Current set of provided kinematic quantities...

    # Velocity potential
    print("phi = ", swd.phi(x, y, z))

    # Stream function
    print("varphi = ", swd.stream(x, y, z))

    # partial(phi) / partial t
    print("phi_t = ", swd.phi_t(x, y, z))

    # particle velocity
    print("grad_phi = ", swd.grad_phi(x, y, z))

    # 2nd order gradients of phi
    print("phi_xx, phi_xy, phi_xz, phi_yy, phi_yz, phi_zz = ",
          swd.grad_phi_2nd(x, y, z))

    # Local (Euler) acceleration