Skip to content

Commit

Permalink
Update nomenclature
Browse files Browse the repository at this point in the history
  • Loading branch information
paulf81 committed Mar 9, 2024
1 parent 3e4177b commit d351357
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 180 deletions.
28 changes: 14 additions & 14 deletions floris/floris_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import numpy as np
import pandas as pd

from floris.logging_manager import LoggingManager
from floris.core import Core, State
from floris.core.rotor_velocity import average_velocity
from floris.core.turbine.operation_models import (
Expand All @@ -20,17 +19,18 @@
thrust_coefficient,
)
from floris.cut_plane import CutPlane
from floris.wind_data import WindDataBase
from floris.logging_manager import LoggingManager
from floris.type_dec import (
floris_array_converter,
NDArrayBool,
NDArrayFloat,
)
from floris.wind_data import WindDataBase


class FlorisModel(LoggingManager):
"""
FlorisInterface provides a high-level user interface to many of the
FlorisModel provides a high-level user interface to many of the
underlying methods within the FLORIS framework. It is meant to act as a
single entry-point for the majority of users, simplifying the calls to
methods on objects within FLORIS.
Expand All @@ -42,7 +42,7 @@ class FlorisModel(LoggingManager):
- **farm**: See `floris.simulation.farm.Farm` for more details.
- **turbine**: See `floris.simulation.turbine.Turbine` for more details.
- **wake**: See `floris.simulation.wake.WakeManager` for more details.
- **logging**: See `floris.simulation.floris.Floris` for more details.
- **logging**: See `floris.simulation.core.core` for more details.
"""

def __init__(self, configuration: dict | str | Path):
Expand All @@ -53,7 +53,7 @@ def __init__(self, configuration: dict | str | Path):
self.core = Core.from_file(self.configuration)
except FileNotFoundError:
# If the file cannot be found, then attempt the configuration path relative to the
# file location from which FlorisInterface was attempted to be run. If successful,
# file location from which FlorisModel was attempted to be run. If successful,
# update self.configuration to an absolute, working file path and name.
base_fn = Path(inspect.stack()[-1].filename).resolve().parent
config = (base_fn / self.configuration).resolve()
Expand Down Expand Up @@ -108,7 +108,7 @@ def assign_hub_height_to_ref_height(self):
self.core.flow_field.reference_wind_height = unique_heights[0]

def copy(self):
"""Create an independent copy of the current FlorisInterface object"""
"""Create an independent copy of the current FlorisModel object"""
return FlorisModel(self.core.as_dict())

def set(
Expand Down Expand Up @@ -408,7 +408,7 @@ def get_plane_of_points(
):
"""
Calculates velocity values through the
:py:meth:`FlorisInterface.calculate_wake` method at points in plane
:py:meth:`FlorisModel.calculate_wake` method at points in plane
specified by inputs.
Args:
Expand Down Expand Up @@ -568,7 +568,7 @@ def calculate_horizontal_plane(
"z",
)

# Reset the fi object back to the turbine grid configuration
# Reset the fmodel object back to the turbine grid configuration
self.core = Core.from_dict(floris_dict)

# Run the simulation again for futher postprocessing (i.e. now we can get farm power)
Expand Down Expand Up @@ -650,7 +650,7 @@ def calculate_cross_plane(
# Compute the cutplane
cross_plane = CutPlane(df, y_resolution, z_resolution, "x")

# Reset the fi object back to the turbine grid configuration
# Reset the fmodel object back to the turbine grid configuration
self.core = Core.from_dict(floris_dict)

# Run the simulation again for futher postprocessing (i.e. now we can get farm power)
Expand Down Expand Up @@ -744,7 +744,7 @@ def calculate_y_plane(
# Compute the cutplane
y_plane = CutPlane(df, x_resolution, z_resolution, "y")

# Reset the fi object back to the turbine grid configuration
# Reset the fmodel object back to the turbine grid configuration
self.core = Core.from_dict(floris_dict)

# Run the simulation again for futher postprocessing (i.e. now we can get farm power)
Expand Down Expand Up @@ -775,8 +775,8 @@ def get_turbine_powers(self) -> NDArrayFloat:
# Confirm calculate wake has been run
if self.core.state is not State.USED:
raise RuntimeError(
"Can't run function `FlorisInterface.get_turbine_powers` without "
"first running `FlorisInterface.run`."
"Can't run function `FlorisModel.get_turbine_powers` without "
"first running `FlorisModel.run`."
)
# Check for negative velocities, which could indicate bad model
# parameters or turbines very closely spaced.
Expand Down Expand Up @@ -888,8 +888,8 @@ def get_farm_power(
# Confirm calculate wake has been run
if self.core.state is not State.USED:
raise RuntimeError(
"Can't run function `FlorisInterface.get_turbine_powers` without "
"first running `FlorisInterface.calculate_wake`."
"Can't run function `FlorisModel.get_turbine_powers` without "
"first running `FlorisModel.calculate_wake`."
)

if turbine_weights is None:
Expand Down
6 changes: 3 additions & 3 deletions floris/flow_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from matplotlib import rcParams
from scipy.spatial import ConvexHull

from floris import FlorisModel
from floris.core import Core
from floris.core.turbine.operation_models import POWER_SETPOINT_DEFAULT
from floris.cut_plane import CutPlane
from floris import FlorisModel
from floris.type_dec import (
floris_array_converter,
NDArrayFloat,
Expand Down Expand Up @@ -215,7 +215,7 @@ def visualize_heterogeneous_cut_plane(
Args:
cut_plane (:py:class:`~.tools.cut_plane.CutPlane`): 2D
plane through wind plant.
fmodel (:py:class:`~.floris.FlorisModel`): FlorisModel object.
fmodel (FlorisModel): FlorisModel object.
ax (:py:class:`matplotlib.pyplot.axes`): Figure axes. Defaults
to None.
vel_component (str, optional): The velocity component that the cut plane is
Expand Down Expand Up @@ -497,7 +497,7 @@ def calculate_horizontal_plane_with_turbines(
for models where the visualization capability is not yet available.
Args:
fmodel_in (:py:class:`~.floris.FlorisModel`): Preinitialized FlorisModel object.
fmodel_in (FlorisModel): Preinitialized FlorisModel object.
x_resolution (float, optional): Output array resolution. Defaults to 200 points.
y_resolution (float, optional): Output array resolution. Defaults to 200 points.
x_bounds (tuple, optional): Limits of output array (in m). Defaults to None.
Expand Down
18 changes: 11 additions & 7 deletions floris/layout_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def plot_turbine_points(
Plots turbine layout from a FlorisModel object.
Args:
fi (FlorisModel): The FlorisModel object containing layout data.
fmodel (FlorisModel): The FlorisModel object containing layout data.
ax (plt.Axes, optional): An existing axes object to plot on. If None,
a new figure and axes will be created. Defaults to None.
turbine_indices (List[int], optional): A list of turbine indices to plot.
Expand Down Expand Up @@ -96,7 +96,7 @@ def plot_turbine_labels(
Adds turbine labels to a turbine layout plot.
Args:
fi (FlorisModel): The FlorisModel object containing layout data.
fmodel (FlorisModel): The FlorisModel object containing layout data.
ax (plt.Axes, optional): An existing axes object to plot on. If None,
a new figure and axes will be created. Defaults to None.
turbine_names (List[str], optional): Custom turbine labels. If None,
Expand Down Expand Up @@ -133,7 +133,9 @@ def plot_turbine_labels(
# If turbine names not none, confirm has correct number of turbines
if turbine_names is not None:
if len(turbine_names) != len(fmodel.layout_x):
raise ValueError("Length of turbine_names not equal to number turbines in fi object")
raise ValueError(
"Length of turbine_names not equal to number turbines in fmodel object"
)
else:
# Assign simple default numbering
turbine_names = [f"{i:03d}" for i in range(len(fmodel.layout_x))]
Expand Down Expand Up @@ -198,7 +200,7 @@ def plot_turbine_rotors(
Plots wind turbine rotors on an existing axes, visually representing their yaw angles.
Args:
fi (FlorisModel): The FlorisModel object containing layout and turbine data.
fmodel (FlorisModel): The FlorisModel object containing layout and turbine data.
ax (plt.Axes, optional): An existing axes object to plot on. If None,
a new figure and axes will be created. Defaults to None.
color (str, optional): Color of the turbine rotor lines. Defaults to 'k' (black).
Expand Down Expand Up @@ -373,7 +375,7 @@ def plot_waking_directions(
Plots lines representing potential waking directions between wind turbines in a layout.
Args:
fi (FlorisModel): Instantiated FlorisModel object containing layout data.
fmodel (FlorisModel): Instantiated FlorisModel object containing layout data.
ax (plt.Axes, optional): An existing axes object to plot on. If None, a new
figure and axes will be created. Defaults to None.
turbine_indices (List[int], optional): Indices of turbines to include in the plot.
Expand Down Expand Up @@ -468,7 +470,9 @@ def plot_waking_directions(
# and i in layout_plotting_dict["turbine_indices"]
# and j in layout_plotting_dict["turbine_indices"]
):
(h,) = ax.plot(fmodel.layout_x[[i, j]], fmodel.layout_y[[i, j]], **wake_plotting_dict)
(h,) = ax.plot(fmodel.layout_x[[i, j]],
fmodel.layout_y[[i, j]],
**wake_plotting_dict)

# Only label in one direction
if ~label_exists[i, j]:
Expand Down Expand Up @@ -500,7 +504,7 @@ def plot_farm_terrain(fmodel: FlorisModel, ax: plt.Axes = None) -> None:
Creates a filled contour plot visualizing terrain-corrected wind turbine hub heights.
Args:
fi (FlorisModel): The FlorisModel object containing layout data.
fmodel (FlorisModel): The FlorisModel object containing layout data.
ax (plt.Axes, optional): An existing axes object to plot on. If None, a new
figure and axes will be created. Defaults to None.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LayoutOptimization(LoggingManager):
but should be subclassed by a specific optimization method.
Args:
fi (FlorisInterface): A FlorisInterface object.
fmodel (FlorisModel): A FlorisModel object.
boundaries (iterable(float, float)): Pairs of x- and y-coordinates
that represent the boundary's vertices (m).
wind_data (TimeSeries | WindRose): A TimeSeries or WindRose object
Expand All @@ -29,8 +29,8 @@ class LayoutOptimization(LoggingManager):
enable_geometric_yaw (bool, optional): If True, enables geometric yaw
optimization. Defaults to False.
"""
def __init__(self, fi, boundaries, wind_data, min_dist=None, enable_geometric_yaw=False):
self.fi = fi.copy()
def __init__(self, fmodel, boundaries, wind_data, min_dist=None, enable_geometric_yaw=False):
self.fmodel = fmodel.copy()
self.boundaries = boundaries
self.enable_geometric_yaw = enable_geometric_yaw

Expand Down Expand Up @@ -59,12 +59,12 @@ def __init__(self, fi, boundaries, wind_data, min_dist=None, enable_geometric_ya
# Establish geometric yaw class
if self.enable_geometric_yaw:
self.yaw_opt = YawOptimizationGeometric(
fi,
fmodel,
minimum_yaw_angle=-30.0,
maximum_yaw_angle=30.0,
)

self.initial_AEP = fi.get_farm_AEP_with_wind_data(self.wind_data)
self.initial_AEP = fmodel.get_farm_AEP_with_wind_data(self.wind_data)

def __str__(self):
return "layout"
Expand Down Expand Up @@ -137,9 +137,9 @@ def nturbs(self):
Returns:
nturbs (int): The number of turbines in the FLORIS object.
"""
self._nturbs = self.fi.floris.farm.n_turbines
self._nturbs = self.fmodel.core.farm.n_turbines
return self._nturbs

@property
def rotor_diameter(self):
return self.fi.floris.farm.rotor_diameters_sorted[0][0]
return self.fmodel.core.farm.rotor_diameters_sorted[0][0]
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class LayoutOptimizationBoundaryGrid(LayoutOptimization):
def __init__(
self,
fi,
fmodel,
boundaries,
start,
x_spacing,
Expand All @@ -27,7 +27,7 @@ def __init__(
n_boundary_turbines=None,
boundary_spacing=None,
):
self.fi = fi
self.fmodel = fmodel

self.boundary_x = np.array([val[0] for val in boundaries])
self.boundary_y = np.array([val[1] for val in boundaries])
Expand Down Expand Up @@ -612,13 +612,13 @@ def reinitialize_xy(self):
self.boundary_spacing,
)

self.fi.set(layout=(layout_x, layout_y))
self.fmodel.set(layout=(layout_x, layout_y))

def plot_layout(self):
plt.figure(figsize=(9, 6))
fontsize = 16

plt.plot(self.fi.layout_x, self.fi.layout_y, "ob")
plt.plot(self.fmodel.layout_x, self.fmodel.layout_y, "ob")
# plt.plot(locsx, locsy, "or")

plt.xlabel("x (m)", fontsize=fontsize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class LayoutOptimizationPyOptSparse(LayoutOptimization):
def __init__(
self,
fi,
fmodel,
boundaries,
wind_data,
min_dist=None,
Expand All @@ -21,11 +21,11 @@ def __init__(
hotStart=None,
enable_geometric_yaw=False,
):
super().__init__(fi, boundaries, wind_data=wind_data, min_dist=min_dist,
super().__init__(fmodel, boundaries, wind_data=wind_data, min_dist=min_dist,
enable_geometric_yaw=enable_geometric_yaw)

self.x0 = self._norm(self.fi.layout_x, self.xmin, self.xmax)
self.y0 = self._norm(self.fi.layout_y, self.ymin, self.ymax)
self.x0 = self._norm(self.fmodel.layout_x, self.xmin, self.xmax)
self.y0 = self._norm(self.fmodel.layout_y, self.ymin, self.ymax)

self.storeHistory = storeHistory
self.timeLimit = timeLimit
Expand Down Expand Up @@ -94,13 +94,13 @@ def _obj_func(self, varDict):
# Compute turbine yaw angles using PJ's geometric code (if enabled)
yaw_angles = self._get_geoyaw_angles()
# Update turbine map with turbine locations and yaw angles
self.fi.set(layout_x=self.x, layout_y=self.y, yaw_angles=yaw_angles)
self.fmodel.set(layout_x=self.x, layout_y=self.y, yaw_angles=yaw_angles)

# Compute the objective function
funcs = {}
funcs["obj"] = (

-1 * self.fi.get_farm_AEP_with_wind_data(self.wind_data)
-1 * self.fmodel.get_farm_AEP_with_wind_data(self.wind_data)
/ self.initial_AEP

)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class LayoutOptimizationPyOptSparse(LayoutOptimization):
def __init__(
self,
fi,
fmodel,
boundaries,
wind_data,
min_dist=None,
Expand All @@ -20,7 +20,7 @@ def __init__(
storeHistory='hist.hist',
hotStart=None
):
super().__init__(fi, boundaries, wind_data=wind_data, min_dist=min_dist)
super().__init__(fmodel, boundaries, wind_data=wind_data, min_dist=min_dist)
self._reinitialize(solver=solver, optOptions=optOptions)

self.storeHistory = storeHistory
Expand Down Expand Up @@ -88,8 +88,8 @@ def _obj_func(self, varDict):
self.parse_opt_vars(varDict)

# Update turbine map with turbince locations
# self.fi.reinitialize(layout=[self.x, self.y])
# self.fi.calculate_wake()
# self.fmodel.reinitialize(layout=[self.x, self.y])
# self.fmodel.calculate_wake()

# Compute the objective function
funcs = {}
Expand Down
Loading

0 comments on commit d351357

Please sign in to comment.