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

    model.update_until(10.1)
    assert_almost_equal(model.get_current_time(), 10.1)
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.

# Calculate the root mean squared error (rmse)
interp_T = np.interp(df.Depth.values, model_z, h.get_value("temperature"))
rmse = (np.mean((interp_T - df.Temperature.values) ** 2)) ** 0.5