Skip to content

Commit

Permalink
Remove the Vec3 class
Browse files Browse the repository at this point in the history
After switching the Grid coordinates from Vec3 to Numpy arrays, it turned out this wasn’t really used anymore.
  • Loading branch information
rafmudaf committed Dec 1, 2023
1 parent 6d6bb64 commit 2d695e5
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 247 deletions.
2 changes: 1 addition & 1 deletion floris/simulation/farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion floris/simulation/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from floris.utilities import (
reverse_rotate_coordinates_rel_west,
rotate_coordinates_rel_west,
Vec3,
)


Expand Down
16 changes: 1 addition & 15 deletions floris/simulation/wake_deflection/gauss.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
86 changes: 0 additions & 86 deletions floris/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 1 addition & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
PointsGrid,
TurbineGrid,
)
from floris.utilities import Vec3


def turbines_to_array(turbine_list: list):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion tests/farm_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions tests/turbine_grid_unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]),
Expand Down
132 changes: 0 additions & 132 deletions tests/vec3_unit_test.py

This file was deleted.

0 comments on commit 2d695e5

Please sign in to comment.