def test_as_tuple(): """ Coordinate return its x and y coordinates as a tuple """ test_class = CoordinateTest() coordinate = Coordinate(test_class.x, test_class.y) assert coordinate.as_tuple() == tuple([test_class.x, test_class.y])
def __init__(self): self.sample_inputs = SampleInputs() self.coordinates = [ Coordinate(0.0, 0.0), Coordinate(100.0, 0.0) ] self.turbine_map_dict = self._build_turbine_map_dict() self.instance = self._build_instance()
def test_rotation_on_z(): """ Coordinate at 1, 1 rotated 90 degrees around z axis should result in 1,-1 """ test_class = CoordinateTest() coordinate = Coordinate(test_class.x, test_class.y) coordinate.rotate_z(np.pi / 2.0) assert pytest.approx(coordinate.xprime) == -1.0 and pytest.approx( coordinate.yprime) == 1.0
def test_rotated(): """ The class should rotate a turbine when given an angle and center of rotation The resulting map should contain turbines at (0, 0) and (-100, 0) when the sample map is rotated by pi about (0, 0). """ test_class = TurbineMapTest() rotated_map = test_class.instance.rotated(np.pi, Coordinate(0, 0)) baseline_coordinates = [ Coordinate(0.0, 0.0), Coordinate(-100.0, 0.0) ] for i, coordinate in enumerate(rotated_map.coords): assert pytest.approx(coordinate == baseline_coordinates[i])
def _add_turbine_marker(self, turbine, coords, wind_direction): a = Coordinate(coords.x, coords.y - turbine.rotor_radius) b = Coordinate(coords.x, coords.y + turbine.rotor_radius) a.rotate_z(turbine.yaw_angle - wind_direction, coords.as_tuple()) b.rotate_z(turbine.yaw_angle - wind_direction, coords.as_tuple()) plt.plot([a.xprime, b.xprime], [a.yprime, b.yprime], 'k', linewidth=1)
def power_objective_func(x, floris, variables, data): turbines = [turbine for _, turbine in floris.farm.flow_field.turbine_map.items()] num_turbines, num_variables = len(turbines), len(variables) set_turbine_attr_vec(np.repeat(range(num_turbines), num_variables), np.repeat(turbines, num_variables), \ np.repeat(range(num_variables), num_turbines, axis=0), np.repeat(variables, num_turbines, axis=0), \ x, num_turbines) try: v = variables.index('layout_x') new_turbine_dict = {Coordinate(x[t + (v * num_turbines)], x[t + ((v + 1) * num_turbines)]):\ turbines[t] \ for t in range(num_turbines)} floris.farm.layout_x, floris.farm.layout_y = x[(v * num_turbines):((v + 1) * num_turbines)],\ x[((v + 1) * num_turbines):((v + 2) * num_turbines)] #print('1', x) # data[v + 2] contains updating turbine_map floris.farm.turbine_map = floris.farm.flow_field.turbine_map = copy.deepcopy(TurbineMap(new_turbine_dict)) #data[v + 2].append(copy.deepcopy(floris.farm.turbine_map)) except ValueError: pass floris.farm.flow_field.calculate_wake() power = -calc_power(floris) # data[0] contains iteration number, data[1] contains power output data[1].append(data[1][-1] + 1) data[2].append(-power/(10**6)) data[3].append(x) return power
def test_string_format(): """ Coordinate should print its coordinates wrapped in parenthesis when cast to string """ test_class = CoordinateTest() coordinate = Coordinate(test_class.x, test_class.y) assert str(coordinate) == "({}, {})".format(test_class.x, test_class.y)
def __init__(self, flowfield, grid_resolution=(100, 100, 25)): self.figure_count = 0 self.flowfield = flowfield self.grid_resolution = Coordinate(grid_resolution[0], grid_resolution[1], grid_resolution[2]) self._initialize_flowfield_for_plotting()
def test_sorted_in_x_as_list(): """ The class should sort its Turbines in ascending order based on the x-component of their associated Coordinate. The returned object should be [(Coordinate, Turbine)]. The resulting list should be ordered as [(0.0, 0.0), (100.0, 0.0)] when the sample data is sorted. """ test_class = TurbineMapTest() sorted_map = test_class.instance.sorted_in_x_as_list() baseline_coordinates = [ Coordinate(0.0, 0.0), Coordinate(-100.0, 0.0) ] for i, element in enumerate(sorted_map): coordinate = element[0] assert pytest.approx(coordinate == baseline_coordinates[i])
def _build_input_dict(self): wake = Wake(self.sample_inputs.wake) wake_combination = WakeCombination("sosfs") turbine = Turbine(self.sample_inputs.turbine) turbine_map = TurbineMap({ Coordinate(0.0, 0.0): turbine, Coordinate(100.0, 0.0): turbine, }) return { "wind_direction": 270.0, "wind_speed": 8.0, "wind_shear": 0.0, "wind_veer": 0.0, "turbulence_intensity": 1.0, "wake": wake, "wake_combination": wake_combination, "turbine_map": turbine_map }
def test_instantiation_with_xy(): """ The class should initialize with the standard inputs """ test_class = CoordinateTest() coordinate = Coordinate(test_class.x, test_class.y) assert coordinate is not None and \ coordinate.x == test_class.x and \ coordinate.y == test_class.y and \ coordinate.z == 0 and \ coordinate.xprime == test_class.x and \ coordinate.yprime == test_class.y and \ coordinate.zprime == 0
def test_map_coordinate_to_index_xmax(): """ Map a domain coordinate to an index in the field matrix. The field matrices are a constant size of (100, 100, 50) starting with a 0 index. xmax should map to index 199 """ test_class = FlowFieldTest() test_instance = test_class.instance rotor_diameter = 126.0 # xmax should be index 199 xi, _, __ = test_instance._map_coordinate_to_index( Coordinate(100 + 10 * rotor_diameter, 0)) assert xi == 99