Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
 def __init__(self):
     self.sample_inputs = SampleInputs()
     self.coordinates = [
         [0.0, 10.0],   # layout x
         [10.0, 20.0]  # layout y
     ]
     self.turbines = [
         copy.deepcopy(Turbine(self.sample_inputs.turbine)),
         copy.deepcopy(Turbine(self.sample_inputs.turbine))
     ]
     self.instance = self._build_instance()
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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 )
Ejemplo n.º 5
0
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])
Ejemplo n.º 6
0
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
Ejemplo n.º 7
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
Ejemplo n.º 8
0
 def _build_input_dict(self):
     wake = Wake(self.sample_inputs.wake)
     turbine = Turbine(self.sample_inputs.turbine)
     turbine_map = TurbineMap(
         [0.0, 100.0], [0.0, 0.0],
         [copy.deepcopy(turbine),
          copy.deepcopy(turbine)])
     return {
         "wind_direction": 270.0,
         "wind_speed": 8.0,
         "wind_shear": 0.0,
         "wind_veer": 0.0,
         "turbulence_intensity": 1.0,
         "air_density": 1.225,
         "wake": wake,
         "turbine_map": turbine_map
     }
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
def flow_field_fixture(sample_inputs_fixture):
    wake = Wake(sample_inputs_fixture.wake)
    turbine = Turbine(sample_inputs_fixture.turbine)
    turbine_map = TurbineMap(
        [0.0, 100.0], [0.0, 0.0], [copy.deepcopy(turbine), copy.deepcopy(turbine)]
    )
    farm_prop = sample_inputs_fixture.farm["properties"]
    wind_map = WindMap(
        wind_speed=farm_prop["wind_speed"],
        layout_array=(farm_prop["layout_x"], farm_prop["layout_y"]),
        wind_layout=(farm_prop["wind_x"], farm_prop["wind_y"]),
        turbulence_intensity=farm_prop["turbulence_intensity"],
        wind_direction=farm_prop["wind_direction"],
    )
    return FlowField(
        farm_prop["wind_shear"],
        farm_prop["wind_veer"],
        farm_prop["air_density"],
        wake,
        turbine_map,
        wind_map,
        farm_prop["specified_wind_height"],
    )
Ejemplo n.º 11
0
 def construct_turbine_map(self):
     self.turbine_map = [Turbine.from_dict(turb) for turb in self.turbine_definitions]
Ejemplo n.º 12
0
def turbine_map_fixture(sample_inputs_fixture):
    return TurbineMap(
        sample_inputs_fixture.farm["properties"]["layout_x"],
        sample_inputs_fixture.farm["properties"]["layout_y"],
        3 * [Turbine(sample_inputs_fixture.turbine)],
    )