def test_one_event(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        foo = PortEvent(port="air_port")

        with EventManager(((foo, 1.0),)) as mngr:
            assert_port_value_equal(foo._port, "air__density", 0.0)

            mngr.run(1.0)
            assert_port_value_equal(foo._port, "air__density", 1.0)

            mngr.run(1.0)
            assert_port_value_equal(foo._port, "air__density", 1.0)

            for time in np.arange(1.0, 2.0, 0.1):
                mngr.run(time)
            assert_port_value_equal(foo._port, "air__density", 1.0)

            mngr.run(2.0)
            assert_port_value_equal(foo._port, "air__density", 2.0)

            for time in np.arange(2.0, 5.0, 0.1):
                mngr.run(time)
            assert mngr.time == approx(4.9)
            assert_port_value_equal(foo._port, "air__density", 4.0)

        assert_port_value_equal(foo._port, "air__density", 0.0)
Exemplo n.º 2
0
def test_two_events():
    foo = PortEvent(port='air_port')
    bar = PortEvent(port='earth_port')

    with EventManager(((foo, 1.), (bar, 1.2))) as mngr:
        assert_port_value_equal(foo._port, 'air__density', 0.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 0.)

        mngr.run(1.)
        assert_port_value_equal(foo._port, 'air__density', 1.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 0.)

        mngr.run(1.)
        assert_port_value_equal(foo._port, 'air__density', 1.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 0.)

        mngr.run(1.3)
        assert_port_value_equal(foo._port, 'air__density', 1.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 1.2)

        mngr.run(2.)
        assert_port_value_equal(foo._port, 'air__density', 2.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 1.2)

        for time in np.arange(2., 5., .1):
            mngr.run(time)
        assert_almost_equal(mngr.time, 4.9)
        assert_port_value_equal(foo._port, 'air__density', 4.)
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 4.8)

    assert_port_value_equal(foo._port, 'air__density', 0.)
    assert_port_value_equal(bar._port, 'earth_surface__temperature', 0.)
Exemplo n.º 3
0
def test_chain():
    air = get_component_instance('air_port')
    earth = get_component_instance('earth_port')

    foo = ChainEvent([
        PortEvent(port=air),
        PortMapEvent(dst_port=air,
                     src_port=earth,
                     vars_to_map=[
                         ('air__density', 'earth_surface__temperature'),
                     ]),
    ])

    bar = PortEvent(port=earth)

    with EventManager((
        (foo, 1.),
        (bar, 1.2),
    )) as mngr:
        assert_port_value_equal(bar._port, 'earth_surface__temperature', 0.)
        assert_port_value_equal(air, 'air__density', 0.)

        mngr.run(1.)
        assert_port_value_equal(earth, 'earth_surface__temperature', 0.)
        assert_port_value_equal(air, 'air__density', 0.)

        mngr.run(2.)
        assert_port_value_equal(air, 'air__density', 1.2)
Exemplo n.º 4
0
def test_one_event():
    foo = PortEvent(port='air_port')

    with EventManager(((foo, 1.), )) as mngr:
        assert_port_value_equal(foo._port, 'air__density', 0.)

        mngr.run(1.)
        assert_port_value_equal(foo._port, 'air__density', 1.)

        mngr.run(1.)
        assert_port_value_equal(foo._port, 'air__density', 1.)

        for time in np.arange(1., 2., .1):
            mngr.run(time)
        assert_port_value_equal(foo._port, 'air__density', 1.)

        mngr.run(2.)
        assert_port_value_equal(foo._port, 'air__density', 2.)

        for time in np.arange(2., 5., .1):
            mngr.run(time)
        assert_almost_equal(mngr.time, 4.9)
        assert_port_value_equal(foo._port, 'air__density', 4.)

    assert_port_value_equal(foo._port, 'air__density', 0.)
Exemplo n.º 5
0
def test_chain(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        air = get_component_instance("air_port")
        earth = get_component_instance("earth_port")

        foo = ChainEvent([
            PortEvent(port=air),
            PortMapEvent(
                dst_port=air,
                src_port=earth,
                vars_to_map=[("air__density", "earth_surface__temperature")],
            ),
        ])

        bar = PortEvent(port=earth)

        with EventManager(((foo, 1.0), (bar, 1.2))) as mngr:
            assert_port_value_equal(bar._port, "earth_surface__temperature",
                                    0.0)
            assert_port_value_equal(air, "air__density", 0.0)

            mngr.run(1.0)
            assert_port_value_equal(earth, "earth_surface__temperature", 0.0)
            assert_port_value_equal(air, "air__density", 0.0)

            mngr.run(2.0)
            assert_port_value_equal(air, "air__density", 1.2)
def test_two_events(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        foo = PortEvent(port="air_port")
        bar = PortEvent(port="earth_port")

        with EventManager(((foo, 1.0), (bar, 1.2))) as mngr:
            assert_port_value_equal(foo._port, "air__density", 0.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 0.0)

            mngr.run(1.0)
            assert_port_value_equal(foo._port, "air__density", 1.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 0.0)

            mngr.run(1.0)
            assert_port_value_equal(foo._port, "air__density", 1.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 0.0)

            mngr.run(1.3)
            assert_port_value_equal(foo._port, "air__density", 1.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 1.2)

            mngr.run(2.0)
            assert_port_value_equal(foo._port, "air__density", 2.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 1.2)

            for time in np.arange(2.0, 5.0, 0.1):
                mngr.run(time)
            assert mngr.time == approx(4.9)
            assert_port_value_equal(foo._port, "air__density", 4.0)
            assert_port_value_equal(bar._port, "earth_surface__temperature", 4.8)

        assert_port_value_equal(foo._port, "air__density", 0.0)
        assert_port_value_equal(bar._port, "earth_surface__temperature", 0.0)
Exemplo n.º 7
0
def test_two_events():
    foo = PrintEvent(port='air_port', name='air__density', format='vtk')
    bar = PrintEvent(port='air_port', name='air__temperature', format='vtk')

    with EventManager(((foo, 1.), (bar, 1.2))) as mngr:
        mngr.run(1.)
        assert_isfile_and_remove('air__density_0000.vtu')

        mngr.run(2.)
        assert_isfile_and_remove('air__density_0001.vtu')
        assert_isfile_and_remove('air__temperature_0000.vtu')
        assert_equal(mngr.time, 2.)

        mngr.run(5.)
        assert_equal(mngr.time, 5.)

    assert_isfile_and_remove('air__density_0002.vtu')
    assert_isfile_and_remove('air__density_0003.vtu')
    assert_isfile_and_remove('air__density_0004.vtu')
    assert_false(os.path.exists('air__density_0005.vtu'))

    assert_isfile_and_remove('air__temperature_0001.vtu')
    assert_isfile_and_remove('air__temperature_0002.vtu')
    assert_isfile_and_remove('air__temperature_0003.vtu')
    assert_false(os.path.exists('air__temperature_0004.vtu'))
Exemplo n.º 8
0
def test_one_event():
    foo = PrintEvent(port='air_port', name='air__density', format='vtk')

    with EventManager(((foo, 1.), )) as mngr:
        assert_equal(mngr.time, 0.)

        mngr.run(1.)
        assert_equal(mngr.time, 1.)

        mngr.run(1.)
        assert_equal(mngr.time, 1.)

        for time in np.arange(1., 2., .1):
            mngr.run(time)
            assert_equal(mngr.time, time)

        mngr.run(2.)
        assert_equal(mngr.time, 2.)

        for time in np.arange(2., 5., .1):
            mngr.run(time)
            assert_equal(mngr.time, time)

    assert_isfile_and_remove('air__density_0000.vtu')
    assert_isfile_and_remove('air__density_0001.vtu')
    assert_isfile_and_remove('air__density_0002.vtu')
    assert_isfile_and_remove('air__density_0003.vtu')
Exemplo n.º 9
0
def test_one_event(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        foo = PrintEvent(port="air_port", name="air__density", format="netcdf")

        with EventManager(((foo, 1.0),)) as mngr:
            assert mngr.time == approx(0.0)

            mngr.run(1.0)
            assert mngr.time == approx(1.0)

            mngr.run(1.0)
            assert mngr.time == approx(1.0)

            for time in np.arange(1.0, 2.0, 0.1):
                mngr.run(time)
                assert mngr.time == approx(time)

            mngr.run(2.0)
            assert mngr.time == approx(2.0)

            for time in np.arange(2.0, 5.0, 0.1):
                mngr.run(time)
                assert mngr.time == approx(time)

        assert os.path.isfile("air__density.nc")
Exemplo n.º 10
0
def test_length_zero():
    foo = ChainEvent([])

    with EventManager(((foo, 1.0),)) as mngr:
        assert mngr.time == approx(0.0)

        mngr.run(2.0)
        assert mngr.time == approx(2.0)
Exemplo n.º 11
0
def test_length_zero():
    foo = ChainEvent([])

    with EventManager(((foo, 1.), )) as mngr:
        assert_equal(mngr.time, 0.)

        mngr.run(2.)
        assert_equal(mngr.time, 2.)
Exemplo n.º 12
0
def test_length_one(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        air = get_component_instance("air_port")
        foo = ChainEvent([PortEvent(port=air)])

        with EventManager(((foo, 1.0),)) as mngr:
            assert_port_value_equal(air, "air__density", 0.0)
            mngr.run(2.0)
            assert_port_value_equal(air, "air__density", 2.0)

        assert_port_value_equal(air, "air__density", 0.0)
Exemplo n.º 13
0
def test_length_one():
    air = get_component_instance('air_port')
    foo = ChainEvent([
        PortEvent(port=air),
    ])

    with EventManager(((foo, 1.), )) as mngr:
        assert_port_value_equal(air, 'air__density', 0.)
        mngr.run(2.)
        assert_port_value_equal(air, 'air__density', 2.)

    assert_port_value_equal(air, 'air__density', 0.)
Exemplo n.º 14
0
def test_one_event():
    foo = PortMapEvent(src_port='air_port',
                       dst_port='earth_port',
                       vars_to_map=[
                           ('earth_surface__temperature', 'air__density'),
                       ])

    foo._src.initialize()
    foo._dst.initialize()

    with EventManager(((foo, 1.), )) as mngr:
        assert_port_value_equal(foo._src, 'air__density', 0.)
        assert_port_value_equal(foo._dst, 'earth_surface__temperature', 0.)
Exemplo n.º 15
0
def test_one_event(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        foo = PortMapEvent(
            src_port="air_port",
            dst_port="earth_port",
            vars_to_map=[("earth_surface__temperature", "air__density")],
        )

        foo._src.initialize()
        foo._dst.initialize()

        with EventManager(((foo, 1.0), )):
            assert_port_value_equal(foo._src, "air__density", 0.0)
            assert_port_value_equal(foo._dst, "earth_surface__temperature",
                                    0.0)
Exemplo n.º 16
0
def test_two_events(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        foo = PrintEvent(port="air_port", name="air__density", format="nc")
        bar = PrintEvent(port="air_port", name="air__temperature", format="nc")

        with EventManager(((foo, 1.0), (bar, 1.2))) as mngr:
            mngr.run(1.0)
            assert os.path.isfile("air__density.nc")

            mngr.run(2.0)
            assert os.path.isfile("air__temperature.nc")
            assert mngr.time == approx(2.0)

            mngr.run(5.0)
            assert mngr.time == approx(5.0)
Exemplo n.º 17
0
def test_length_two(tmpdir, with_earth_and_air):
    with tmpdir.as_cwd():
        air = get_component_instance("air_port")
        earth = get_component_instance("earth_port")

        foo = ChainEvent([PortEvent(port=air), PortEvent(port=earth)])

        with EventManager([(foo, 1.2)]) as mngr:
            assert_port_value_equal(earth, "earth_surface__temperature", 0.0)
            assert_port_value_equal(air, "air__density", 0.0)

            mngr.run(1.0)
            assert_port_value_equal(earth, "earth_surface__temperature", 0.0)
            assert_port_value_equal(air, "air__density", 0.0)

            mngr.run(2.0)
            assert_port_value_equal(earth, "earth_surface__temperature", 1.2)
            assert_port_value_equal(air, "air__density", 1.2)
Exemplo n.º 18
0
def test_length_two():
    air = get_component_instance('air_port')
    earth = get_component_instance('earth_port')

    foo = ChainEvent([PortEvent(port=air), PortEvent(port=earth)])

    with EventManager([
        (foo, 1.2),
    ]) as mngr:
        assert_port_value_equal(earth, 'earth_surface__temperature', 0.)
        assert_port_value_equal(air, 'air__density', 0.)

        mngr.run(1.)
        assert_port_value_equal(earth, 'earth_surface__temperature', 0.)
        assert_port_value_equal(air, 'air__density', 0.)

        mngr.run(2.)
        assert_port_value_equal(earth, 'earth_surface__temperature', 1.2)
        assert_port_value_equal(air, 'air__density', 1.2)