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

    model.set_value_at_indices("plate_surface__temperature", [0, 2, 4],
                               [-1, -1, -1])

    new_z = model.get_value_ptr("plate_surface__temperature")
    assert_array_almost_equal(new_z.take((0, 2, 4)), -1.0)
def test_set_value_at_indices():
    model = BmiHeat()
    model.initialize()

    z0 = model.get_value_ref('plate_surface__temperature')

    model.set_value_at_indices('plate_surface__temperature', [-1, -1, -1],
                               [0, 2, 4])

    new_z = model.get_value_ref('plate_surface__temperature')
    assert_array_almost_equal(new_z.take((0, 2, 4)), -1.)
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)

#########################################
#                                       #
#    Step 3: Write Output in format     #
#    Dakota expects                     #
#                                       #
#########################################

# Each of the metrics listed in the Dakota .in file needs to be written to
# the specified output file given by sys.argv[2]. This is how information is
# sent back to Dakota.