def test_set_value():
    model = BmiHeat()
    model.initialize()

    z0 = model.get_value_ref('plate_surface__temperature')
    z1 = np.zeros_like(z0) - 1

    model.set_value('plate_surface__temperature', z1)

    new_z = model.get_value_ref('plate_surface__temperature')

    assert_is(new_z, z0)
    assert_is_not(new_z, z1)
    assert_array_almost_equal(new_z, z1)
Example #2
0
def test_set_value():
    model = BmiHeat()
    model.initialize()

    z0 = model.get_value_ptr("plate_surface__temperature")
    z1 = np.zeros_like(z0) - 1

    model.set_value("plate_surface__temperature", z1)

    new_z = model.get_value_ptr("plate_surface__temperature")

    assert new_z is z0
    assert new_z is not z1
    assert_array_almost_equal(new_z, z1)
kappa: {kappa}
k: {k}
Qm: {Qm}
""".format(
        kappa=kappa, k=k, Qm=Qm, nrow=nrow, dz=dz,
    )
)

# 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],