Example #1
0
def test_initialize_defaults():
    model = BmiHeat()
    model.initialize()

    assert_almost_equal(model.get_current_time(), 0.)
    assert_array_less(model.get_value('plate_surface__temperature'), 1.)
    assert_array_less(0., model.get_value('plate_surface__temperature'))
Example #2
0
def test_update():
    model = BmiHeat()
    model.initialize()

    for inc in xrange(10):
        model.update()
        assert_almost_equal(model.get_current_time(),
                            (inc + 1) * model.get_time_step())
Example #3
0
def test_initialize_defaults():
    model = BmiHeat()
    model.initialize()

    assert_almost_equal(model.get_current_time(), 0.0)
    z0 = model.get_value_ptr("plate_surface__temperature")
    assert_array_less(z0, 1.0)
    assert_array_less(0.0, z0)
Example #4
0
def test_update_until():
    model = BmiHeat()
    model.initialize()

    model.update_until(10.1)
    assert_almost_equal(model.get_current_time(), 10.1)
)

# Create an instance of the Heat model, initialize it from the file.
h = Heat()
h.initialize(file_like)

# set the initial temperature based on our linear fit.
model_z = np.arange(0, nrow * dz, dz)
T_init = fit.intercept_[0] + fit.coef_[0][0] * model_z
h.set_value("temperature", T_init)

# override the default timestep to use 1 day.
h.timestep = seconds_per_day

# run the model forward in time forced by the surface temperature.
while h.get_current_time() < duration_years * seconds_per_year:
    # calculate the time to run until.
    run_until = min([h.get_current_time() + seconds_per_year,
                     duration_years*seconds_per_year])
    # determine the current surface temperature
    current_time = h.get_current_time()/seconds_per_year
    current_temperature_change = surface_temperature_change(current_time)
    # set the surface temperature in the model.
    h.set_value_at_indices("temperature",
                           [0],
                           T_init[0] + current_temperature_change)
    # run forward in time.
    h.update_until(run_until)

#########################################
#                                       #