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'))
def test_get_value_copy(): model = BmiHeat() model.initialize() z0 = model.get_value("plate_surface__temperature") z1 = model.get_value("plate_surface__temperature") assert z0 is not z1 assert_array_almost_equal(z0, z1)
def test_get_value_copy(): model = BmiHeat() model.initialize() z0 = model.get_value('plate_surface__temperature') z1 = model.get_value('plate_surface__temperature') assert_is_not(z0, z1) assert_array_almost_equal(z0, z1)
def test_get_value_copy(): model = BmiHeat() model.initialize() dest0 = np.empty(model.get_grid_size(0), dtype=float) dest1 = np.empty(model.get_grid_size(0), dtype=float) z0 = model.get_value("plate_surface__temperature", dest0) z1 = model.get_value("plate_surface__temperature", dest1) assert z0 is not z1 assert_array_almost_equal(z0, z1)
def test_get_value_pointer(): model = BmiHeat() model.initialize() z0 = model.get_value_ptr("plate_surface__temperature") z1 = model.get_value("plate_surface__temperature") assert z0 is not z1 assert_array_almost_equal(z0, z1) for _ in range(10): model.update() assert z0 is model.get_value_ptr("plate_surface__temperature")
def test_get_value_reference(): model = BmiHeat() model.initialize() z0 = model.get_value_ref('plate_surface__temperature') z1 = model.get_value('plate_surface__temperature') assert_is_not(z0, z1) assert_array_almost_equal(z0, z1) for _ in range(10): model.update() assert_is(z0, model.get_value_ref('plate_surface__temperature'))
def test_get_value_reference(): model = BmiHeat() model.initialize() z0 = model.get_value_ref('plate_surface__temperature') z1 = model.get_value('plate_surface__temperature') assert_is_not(z0, z1) assert_array_almost_equal(z0, z1) for _ in xrange(10): model.update() assert_is(z0, model.get_value_ref('plate_surface__temperature'))
def test_get_value_pointer(): model = BmiHeat() model.initialize() dest1 = np.empty(model.get_grid_size(0), dtype=float) z0 = model.get_value_ptr("plate_surface__temperature") z1 = model.get_value("plate_surface__temperature", dest1) assert z0 is not z1 assert_array_almost_equal(z0.flatten(), z1) for _ in range(10): model.update() assert z0 is model.get_value_ptr("plate_surface__temperature")
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 # Write it to the expected file. with open(sys.argv[2], "w") as fp: fp.write(str(rmse))