diff --git a/floris/simulation/farm.py b/floris/simulation/farm.py index 33c2cbff4..3d84bf36b 100644 --- a/floris/simulation/farm.py +++ b/floris/simulation/farm.py @@ -39,7 +39,7 @@ NDArrayFloat, NDArrayObject, ) -from floris.utilities import load_yaml, Vec3 +from floris.utilities import load_yaml default_turbine_library_path = Path(__file__).parents[1] / "turbine_library" diff --git a/floris/simulation/grid.py b/floris/simulation/grid.py index 9ee20deaa..7218ae83a 100644 --- a/floris/simulation/grid.py +++ b/floris/simulation/grid.py @@ -32,7 +32,6 @@ from floris.utilities import ( reverse_rotate_coordinates_rel_west, rotate_coordinates_rel_west, - Vec3, ) diff --git a/floris/simulation/wake_deflection/gauss.py b/floris/simulation/wake_deflection/gauss.py index 98eebc25d..8ba77ad7f 100644 --- a/floris/simulation/wake_deflection/gauss.py +++ b/floris/simulation/wake_deflection/gauss.py @@ -130,21 +130,7 @@ def function( for details on the methods used. Args: - x_locations (np.array): An array of floats that contains the - streamwise direction grid coordinates of the flow field - domain (m). - y_locations (np.array): An array of floats that contains the grid - coordinates of the flow field domain in the direction normal to - x and parallel to the ground (m). - z_locations (np.array): An array of floats that contains the grid - coordinates of the flow field domain in the vertical - direction (m). - turbine (:py:obj:`floris.simulation.turbine`): Object that - represents the turbine creating the wake. - coord (:py:obj:`floris.utilities.Vec3`): Object containing - the coordinate of the turbine creating the wake (m). - flow_field (:py:class:`floris.simulation.flow_field`): Object - containing the flow field information for the wind farm. + # TODO Returns: np.array: Deflection field for the wake. diff --git a/floris/utilities.py b/floris/utilities.py index f5854a603..5420c70e4 100644 --- a/floris/utilities.py +++ b/floris/utilities.py @@ -29,92 +29,6 @@ def pshape(array: np.ndarray, label: str = ""): print(label, np.shape(array)) -@define -class Vec3: - """ - Contains 3-component vector information. All arithmetic operators are - set so that Vec3 objects can operate on and with each other directly. - - Args: - components (list(numeric, numeric, numeric), numeric): All three vector - components. - """ - components: NDArrayFloat = field(converter=floris_array_converter) - - @components.validator - def _check_components(self, attribute, value) -> None: - if np.ndim(value) > 1: - raise ValueError( - f"Vec3 must contain exactly 1 dimension, {np.ndim(value)} were given." - ) - if np.size(value) != 3: - raise ValueError( - f"Vec3 must contain exactly 3 components, {np.size(value)} were given." - ) - - def __add__(self, arg): - if type(arg) is Vec3: - return Vec3(self.components + arg.components) - elif type(arg) is int or type(arg) is float: - return Vec3(self.components + arg) - else: - raise ValueError - - def __sub__(self, arg): - if type(arg) is Vec3: - return Vec3(self.components - arg.components) - elif type(arg) is int or type(arg) is float: - return Vec3(self.components - arg) - else: - raise ValueError - - def __mul__(self, arg): - if type(arg) is Vec3: - return Vec3(self.components * arg.components) - elif type(arg) is int or type(arg) is float: - return Vec3(self.components * arg) - else: - raise ValueError - - def __truediv__(self, arg): - if type(arg) is Vec3: - return Vec3(self.components / arg.components) - elif type(arg) is int or type(arg) is float: - return Vec3(self.components / arg) - else: - raise ValueError - - def __eq__(self, arg): - return False not in np.isclose([self.x1, self.x2, self.x3], [arg.x1, arg.x2, arg.x3]) - - def __hash__(self): - return hash((self.x1, self.x2, self.x3)) - - @property - def x1(self): - return self.components[0] - - @x1.setter - def x1(self, value): - self.components[0] = float(value) - - @property - def x2(self): - return self.components[1] - - @x2.setter - def x2(self, value): - self.components[1] = float(value) - - @property - def x3(self): - return self.components[2] - - @x3.setter - def x3(self, value): - self.components[2] = float(value) - - def cosd(angle): """ Cosine of an angle with the angle given in degrees. diff --git a/tests/conftest.py b/tests/conftest.py index 7047671e0..a5206b2a6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -25,7 +25,6 @@ PointsGrid, TurbineGrid, ) -from floris.utilities import Vec3 def turbines_to_array(turbine_list: list): @@ -108,10 +107,6 @@ def print_test_values( ## Unit test fixtures -@pytest.fixture -def vec3_fixture(): - return Vec3([4, 4, 0]) - @pytest.fixture def flow_field_fixture(sample_inputs_fixture): flow_field_dict = sample_inputs_fixture.flow_field @@ -144,7 +139,7 @@ def flow_field_grid_fixture(sample_inputs_fixture) -> FlowFieldGrid: @pytest.fixture def points_grid_fixture(sample_inputs_fixture) -> PointsGrid: - turbine_coordinates = [Vec3(c) for c in list(zip(X_COORDS, Y_COORDS, Z_COORDS))] + turbine_coordinates = np.array([np.array(c) for c in list(zip(X_COORDS, Y_COORDS, Z_COORDS))]) rotor_diameters = ROTOR_DIAMETER * np.ones( (N_WIND_DIRECTIONS, N_WIND_SPEEDS, N_TURBINES) ) points_x = [0.0, 10.0] points_y = [0.0, 0.0] diff --git a/tests/farm_unit_test.py b/tests/farm_unit_test.py index ce116dce9..64d1d405e 100644 --- a/tests/farm_unit_test.py +++ b/tests/farm_unit_test.py @@ -19,7 +19,7 @@ import pytest from floris.simulation import Farm -from floris.utilities import load_yaml, Vec3 +from floris.utilities import load_yaml from tests.conftest import ( N_TURBINES, N_WIND_DIRECTIONS, diff --git a/tests/turbine_grid_unit_test.py b/tests/turbine_grid_unit_test.py index 9d9309684..e0bfca3bd 100644 --- a/tests/turbine_grid_unit_test.py +++ b/tests/turbine_grid_unit_test.py @@ -85,11 +85,6 @@ def test_dynamic_properties(turbine_grid_fixture): assert turbine_grid_fixture.n_wind_speeds == N_WIND_SPEEDS assert turbine_grid_fixture.n_wind_directions == N_WIND_DIRECTIONS - # TODO: The following two lines break n_turbines since the validator is not run. - # Is this case ok? Do we enforce that turbine_coordinates must be set by =? - # turbine_grid_fixture.turbine_coordinates.append(Vec3([100.0, 200.0, 300.0])) - # assert turbine_grid_fixture.n_turbines == N_TURBINES + 1 - turbine_grid_fixture.turbine_coordinates = np.append( turbine_grid_fixture.turbine_coordinates, np.array([[100.0, 200.0, 300.0]]), diff --git a/tests/vec3_unit_test.py b/tests/vec3_unit_test.py deleted file mode 100644 index f8b624dd8..000000000 --- a/tests/vec3_unit_test.py +++ /dev/null @@ -1,132 +0,0 @@ -# Copyright 2021 NREL - -# Licensed under the Apache License, Version 2.0 (the "License"); you may not -# use this file except in compliance with the License. You may obtain a copy of -# the License at http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations under -# the License. - -# See https://floris.readthedocs.io for documentation - - -import numpy as np -import pytest - -from floris.utilities import Vec3 - - -def test_instantiation_with_list(): - """ - The class should initialize with a list of length 3. - The class should raise an exception if the length of - points is not 3. - """ - vec3 = Vec3([1, 2, 3]) - assert vec3.x1 == 1.0 - assert vec3.x2 == 2.0 - assert vec3.x3 == 3.0 - - with pytest.raises(Exception): - vec3 = Vec3([1, 2, 3, 4]) - - with pytest.raises(Exception): - vec3 = Vec3([1, 2]) - - -def test_add(vec3_fixture): - """ - The overloaded operator should accept a scalar value and apply it to - all components. - It should also accept a Vec3 value and perform an element-wise operation. - """ - scalar = vec3_fixture + 1 - assert scalar.x1 == vec3_fixture.x1 + 1 - assert scalar.x2 == vec3_fixture.x2 + 1 - assert scalar.x3 == vec3_fixture.x3 + 1 - - vector = vec3_fixture + Vec3([2, 3, 4]) - assert vector.x1 == vec3_fixture.x1 + 2 - assert vector.x2 == vec3_fixture.x2 + 3 - assert vector.x3 == vec3_fixture.x3 + 4 - - -def test_subtract(vec3_fixture): - """ - The overloaded operator should accept a scalar value and apply it to - all components. - It should also accept a Vec3 value and perform an element-wise operation. - """ - scalar = vec3_fixture - 1 - assert scalar.x1 == vec3_fixture.x1 - 1 - assert scalar.x2 == vec3_fixture.x2 - 1 - assert scalar.x3 == vec3_fixture.x3 - 1 - - vector = vec3_fixture - Vec3([2, 3, 4]) - assert vector.x1 == vec3_fixture.x1 - 2 - assert vector.x2 == vec3_fixture.x2 - 3 - assert vector.x3 == vec3_fixture.x3 - 4 - - -def test_multiply(vec3_fixture): - """ - The overloaded operator should accept a scalar value and apply it to - all components. - It should also accept a Vec3 value and perform an element-wise operation. - """ - scalar = vec3_fixture * 10 - assert scalar.x1 == vec3_fixture.x1 * 10 - assert scalar.x2 == vec3_fixture.x2 * 10 - assert scalar.x3 == vec3_fixture.x3 * 10 - - vector = vec3_fixture * Vec3([2, 3, 4]) - assert vector.x1 == vec3_fixture.x1 * 2 - assert vector.x2 == vec3_fixture.x2 * 3 - assert vector.x3 == vec3_fixture.x3 * 4 - - -def test_divide(vec3_fixture): - """ - The overloaded operator should accept a scalar value and apply it to - all components. - It should also accept a Vec3 value and perform an element-wise operation. - """ - scalar = vec3_fixture / 10.0 - np.testing.assert_allclose(scalar.x1, vec3_fixture.x1 / 10.0) - np.testing.assert_allclose(scalar.x2, vec3_fixture.x2 / 10.0) - np.testing.assert_allclose(scalar.x3, vec3_fixture.x3 / 10.0) - - vector = vec3_fixture / Vec3([10, 100, 1000]) - np.testing.assert_allclose(vector.x1, vec3_fixture.x1 / 10.0) - np.testing.assert_allclose(vector.x2, vec3_fixture.x2 / 100.0) - np.testing.assert_allclose(vector.x3, vec3_fixture.x3 / 1000.0) - - -def test_equality(vec3_fixture): - """ - The overloaded equality operator should compare each component to the - same components of the right-hand-side value. - """ - rhs = Vec3([vec3_fixture.x1, vec3_fixture.x2, vec3_fixture.x3]) - assert vec3_fixture == rhs - - rhs = Vec3([vec3_fixture.x1 + 1, vec3_fixture.x2, vec3_fixture.x3]) - assert vec3_fixture != rhs - - rhs = Vec3([vec3_fixture.x1, vec3_fixture.x2 + 1, vec3_fixture.x3]) - assert vec3_fixture != rhs - - rhs = Vec3([vec3_fixture.x1, vec3_fixture.x2, vec3_fixture.x3 + 1]) - assert vec3_fixture != rhs - - -def test_components_property(vec3_fixture): - """Ensure that the x1, x2, and x3 components match the expected values. - """ - x1, x2, x3 = vec3_fixture.components - assert 4.0 == x1 - assert 4.0 == x2 - assert 0.0 == x3