def test_asdict(sample_inputs_fixture: SampleInputs): turbine = Turbine.from_dict(sample_inputs_fixture.turbine) dict1 = turbine.as_dict() new_turb = Turbine.from_dict(dict1) dict2 = new_turb.as_dict() assert dict1 == dict2
def test_axial_induction(): N_TURBINES = 4 turbine_data = SampleInputs().turbine turbine = Turbine.from_dict(turbine_data) turbine_type_map = np.array(N_TURBINES * [turbine.turbine_type]) turbine_type_map = turbine_type_map[None, None, :] baseline_ai = 0.25116283939089806 # Single turbine wind_speed = 10.0 ai = axial_induction( velocities=wind_speed * np.ones((1, 1, 1, 3, 3)), yaw_angle=np.zeros((1, 1, 1)), fCt=np.array([(turbine.turbine_type, turbine.fCt_interp)]), turbine_type_map=turbine_type_map[0,0,0], ) np.testing.assert_allclose(ai, baseline_ai) # Multiple turbines with ix filter ai = axial_induction( velocities=np.ones((N_TURBINES, 3, 3)) * WIND_CONDITION_BROADCAST, # 3 x 4 x 4 x 3 x 3 yaw_angle=np.zeros((1, 1, N_TURBINES)), fCt=np.array([(turbine.turbine_type, turbine.fCt_interp)]), turbine_type_map=turbine_type_map, ix_filter=INDEX_FILTER, ) assert len(ai[0, 0]) == len(INDEX_FILTER) # Test the 10 m/s wind speed to use the same baseline as above np.testing.assert_allclose(ai[0,2], baseline_ai)
def test_power(): N_TURBINES = 4 AIR_DENSITY = 1.225 turbine_data = SampleInputs().turbine turbine = Turbine.from_dict(turbine_data) turbine_type_map = np.array(N_TURBINES * [turbine.turbine_type]) turbine_type_map = turbine_type_map[None, None, :] # Single turbine wind_speed = 10.0 p = power( air_density=AIR_DENSITY, velocities=wind_speed * np.ones((1, 1, 1, 3, 3)), yaw_angle=np.zeros((1, 1, 1)), pP=turbine.pP * np.ones((1, 1, 1)), power_interp=np.array([(turbine.turbine_type, turbine.fCp_interp)]), turbine_type_map=turbine_type_map[:,:,0] ) # calculate power again effective_velocity_trurth = ((AIR_DENSITY/1.225)**(1/3)) * wind_speed truth_index = turbine_data["power_thrust_table"]["wind_speed"].index(effective_velocity_trurth) cp_truth = turbine_data["power_thrust_table"]["power"][truth_index] power_truth = 0.5 * turbine.rotor_area * cp_truth * turbine.generator_efficiency * effective_velocity_trurth ** 3 np.testing.assert_allclose(p,cp_truth,power_truth )
def test_ct(): N_TURBINES = 4 turbine_data = SampleInputs().turbine turbine = Turbine.from_dict(turbine_data) turbine_type_map = np.array(N_TURBINES * [turbine.turbine_type]) turbine_type_map = turbine_type_map[None, None, :] # Single turbine # yaw angle / fCt are (n wind direction, n wind speed, n turbine) wind_speed = 10.0 thrust = Ct( velocities=wind_speed * np.ones((1, 1, 1, 3, 3)), yaw_angle=np.zeros((1, 1, 1)), fCt=np.array([(turbine.turbine_type, turbine.fCt_interp)]), turbine_type_map=turbine_type_map[:,:,0] ) truth_index = turbine_data["power_thrust_table"]["wind_speed"].index(wind_speed) np.testing.assert_allclose(thrust, turbine_data["power_thrust_table"]["thrust"][truth_index]) # Multiple turbines with index filter # 4 turbines with 3 x 3 grid arrays thrusts = Ct( velocities=np.ones((N_TURBINES, 3, 3)) * WIND_CONDITION_BROADCAST, # 3 x 4 x 4 x 3 x 3 yaw_angle=np.zeros((1, 1, N_TURBINES)), fCt=np.array([(turbine.turbine_type, turbine.fCt_interp)]), turbine_type_map=turbine_type_map, ix_filter=INDEX_FILTER, ) assert len(thrusts[0, 0]) == len(INDEX_FILTER) for i in range(len(INDEX_FILTER)): truth_index = turbine_data["power_thrust_table"]["wind_speed"].index(WIND_SPEEDS[0]) np.testing.assert_allclose(thrusts[0, 0, i], turbine_data["power_thrust_table"]["thrust"][truth_index])
def test_rotor_radius(): turbine_data = SampleInputs().turbine turbine = Turbine.from_dict(turbine_data) # Test that the radius is set correctly from the input file assert turbine.rotor_radius == turbine_data["rotor_diameter"] / 2.0 # Test the radius setter method since it actually sets the diameter turbine.rotor_radius = 200.0 assert turbine.rotor_diameter == 400.0 # Test the getter-method again assert turbine.rotor_radius == 200.0
def test_rotor_area(): turbine_data = SampleInputs().turbine turbine = Turbine.from_dict(turbine_data) # Test that the area is set correctly from the input file assert turbine.rotor_area == np.pi * (turbine_data["rotor_diameter"] / 2.0) ** 2 # Test the area setter method since it actually sets the radius and then the diameter turbine.rotor_area = np.pi assert turbine.rotor_radius == 1 assert turbine.rotor_diameter == 2 # Test the getter-method again assert turbine.rotor_area == np.pi
def test_turbine_init(): turbine_data = SampleInputs().turbine turbine = Turbine.from_dict(turbine_data) assert turbine.rotor_diameter == turbine_data["rotor_diameter"] assert turbine.hub_height == turbine_data["hub_height"] assert turbine.pP == turbine_data["pP"] assert turbine.pT == turbine_data["pT"] assert turbine.generator_efficiency == turbine_data["generator_efficiency"] pt_data = turbine_data["power_thrust_table"] assert isinstance(turbine.power_thrust_table, PowerThrustTable) np.testing.assert_allclose(turbine.power_thrust_table.power, np.array(pt_data["power"])) np.testing.assert_allclose(turbine.power_thrust_table.thrust, np.array(pt_data["thrust"])) np.testing.assert_allclose(turbine.power_thrust_table.wind_speed, np.array(pt_data["wind_speed"])) assert isinstance(turbine.fCp_interp, interp1d) assert isinstance(turbine.fCt_interp, interp1d) assert isinstance(turbine.power_interp, interp1d) assert turbine.rotor_radius == turbine_data["rotor_diameter"] / 2.0
def construct_turbine_map(self): self.turbine_map = [Turbine.from_dict(turb) for turb in self.turbine_definitions]