Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up and simplify some things #437

Merged
merged 2 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions floris/simulation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from typing import Any, Dict, Final

import attrs
from attrs import define

from floris.type_dec import FromDictMixin
from floris.logging_manager import LoggerBase
Expand Down Expand Up @@ -63,15 +62,6 @@ class BaseModel(BaseClass, ABC):

NUM_EPS: Final[float] = 0.001 # This is a numerical epsilon to prevent divide by zeros

@property
def model_string(self):
return self.model_string

@model_string.setter
@abstractmethod
def model_string(self, string):
raise NotImplementedError("BaseModel.model_string")

@abstractmethod
def prepare_function() -> dict:
raise NotImplementedError("BaseModel.prepare_function")
Expand Down
3 changes: 1 addition & 2 deletions floris/simulation/farm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from attrs import define, field
import numpy as np
from pathlib import Path
import os
import copy

from floris.type_dec import (
Expand Down Expand Up @@ -83,7 +82,7 @@ def check_turbine_type(self, instance: attrs.Attribute, value: Any) -> None:
if type(val) is str:
_floris_dir = Path(__file__).parent.parent
fname = _floris_dir / "turbine_library" / f"{val}.yaml"
if not os.path.isfile(fname):
if not Path.is_file(fname):
raise ValueError("User-selected turbine definition `{}` does not exist in pre-defined turbine library.".format(val))
self.turbine_definitions[i] = load_yaml(fname)

Expand Down
1 change: 0 additions & 1 deletion floris/simulation/floris.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
Farm,
WakeModelManager,
FlowField,
Turbine,
Grid,
TurbineGrid,
FlowFieldGrid,
Expand Down
2 changes: 1 addition & 1 deletion floris/simulation/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from attrs import define, field
import numpy as np

from floris.utilities import Vec3, rotate_coordinates_rel_west, cosd, sind
from floris.utilities import Vec3, rotate_coordinates_rel_west
from floris.type_dec import (
floris_float_type,
floris_array_converter,
Expand Down
1 change: 0 additions & 1 deletion floris/simulation/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import sys

from floris.simulation import Farm
from floris.simulation import Turbine
from floris.simulation import TurbineGrid, FlowFieldGrid
from floris.simulation import Ct, axial_induction
from floris.simulation import FlowField
Expand Down
2 changes: 0 additions & 2 deletions floris/simulation/wake_combination/fls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class FLS(BaseModel):
deficits to the freestream flow field.
"""

model_string = "fls"

def prepare_function(self) -> dict:
pass

Expand Down
2 changes: 0 additions & 2 deletions floris/simulation/wake_combination/max.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class MAX(BaseModel):
:keyprefix: max-
"""

model_string = "max"

def prepare_function(self) -> dict:
pass

Expand Down
2 changes: 0 additions & 2 deletions floris/simulation/wake_combination/sosfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class SOSFS(BaseModel):
wake velocity deficits to the base flow field.
"""

model_string = "sosfs"

def prepare_function(self) -> dict:
pass

Expand Down
72 changes: 0 additions & 72 deletions floris/simulation/wake_deflection/curl.py

This file was deleted.

3 changes: 1 addition & 2 deletions floris/simulation/wake_deflection/gauss.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from floris.simulation import FlowField
from floris.simulation import Grid
from floris.simulation import Turbine
from floris.utilities import cosd, sind, tand
from floris.utilities import cosd, sind


@define
Expand Down Expand Up @@ -79,7 +79,6 @@ class GaussVelocityDeflection(BaseModel):
dm: float = field(converter=float, default=1.0)
eps_gain: float = field(converter=float, default=0.2)
use_secondary_steering: bool = field(converter=bool, default=True)
model_string = "gauss"

def prepare_function(
self,
Expand Down
1 change: 0 additions & 1 deletion floris/simulation/wake_deflection/jimenez.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class JimenezVelocityDeflection(BaseModel):
kd: float = field(default=0.05)
ad: float = field(default=0.0)
bd: float = field(default=0.0)
model_string = "jimenez"

def prepare_function(
self,
Expand Down
1 change: 0 additions & 1 deletion floris/simulation/wake_deflection/none.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class NoneVelocityDeflection(BaseModel):
The None deflection model is a placeholder code that simple ignores any
deflection and returns an array of zeroes.
"""
model_string = "none"

def prepare_function(
self,
Expand Down
3 changes: 1 addition & 2 deletions floris/simulation/wake_turbulence/crespo_hernandez.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from floris.simulation import FlowField
from floris.simulation import Grid
from floris.simulation import Turbine
from floris.utilities import cosd, sind, tand
from floris.utilities import cosd, sind


@define
Expand Down Expand Up @@ -57,7 +57,6 @@ class CrespoHernandez(BaseModel):
constant: float = field(converter=float, default=0.9)
ai: float = field(converter=float, default=0.8)
downstream: float = field(converter=float, default=-0.32)
model_string = "crespo_hernandez"

def prepare_function(self) -> dict:
pass
Expand Down
2 changes: 0 additions & 2 deletions floris/simulation/wake_turbulence/none.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class NoneWakeTurbulence(BaseModel):
any wake turbulence and just returns an array of the ambient TIs.
"""

model_string = "none"

def prepare_function(self) -> dict:
pass

Expand Down
6 changes: 1 addition & 5 deletions floris/simulation/wake_velocity/cumulative_gauss_curl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@
from typing import Any, Dict

from attrs import define, field
import numexpr as ne
import numpy as np
from numpy import newaxis as na
from scipy.special import gamma

from floris.simulation import BaseModel
from floris.simulation import Farm
from floris.simulation import FlowField
from floris.simulation import Grid
from floris.simulation import Turbine
from floris.utilities import cosd, sind, tand, pshape
from floris.utilities import cosd, sind, tand


@define
Expand All @@ -38,8 +36,6 @@ class CumulativeGaussCurlVelocityDeficit(BaseModel):
c_f: float = field(default=2.41)
alpha_mod: float = field(default=1.0)

model_string = "cumulative_gauss_curl"

def prepare_function(
self,
grid: Grid,
Expand Down
1 change: 0 additions & 1 deletion floris/simulation/wake_velocity/gauss.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class GaussVelocityDeficit(BaseModel):
beta: float = field(default=0.077)
ka: float = field(default=0.38)
kb: float = field(default=0.004)
model_string = "gauss"

def prepare_function(
self,
Expand Down
1 change: 0 additions & 1 deletion floris/simulation/wake_velocity/jensen.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class JensenVelocityDeficit(BaseModel):
"""

we: float = field(converter=float, default=0.05)
model_string = "jensen"

def prepare_function(
self,
Expand Down
2 changes: 0 additions & 2 deletions floris/simulation/wake_velocity/none.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ class NoneVelocityDeficit(BaseModel):
wake wind speed deficits and returns an array of zeroes.
"""

model_string = "none"

def prepare_function(
self,
grid: Grid,
Expand Down
5 changes: 3 additions & 2 deletions floris/simulation/wake_velocity/turbopark.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
from scipy import integrate
from scipy.interpolate import RegularGridInterpolator
import scipy.io
import os

from floris.simulation import BaseModel
from floris.simulation import Farm
from floris.simulation import FlowField
from floris.simulation import Grid
from floris.simulation import Turbine
from floris.utilities import cosd, sind, tand


@define
Expand All @@ -36,7 +38,6 @@ class TurbOParkVelocityDeficit(BaseModel):
A: float = field(default=0.04)
sigma_max_rel: float = field(default=4.0)
overlap_gauss_interp: RegularGridInterpolator = field(init=False)
model_string = "turbopark"

def __attrs_post_init__(self) -> None:
lookup_table_matlab_file = Path(__file__).parent / "turbopark_lookup_table.mat"
Expand Down
23 changes: 4 additions & 19 deletions floris/tools/floris_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,18 @@

from __future__ import annotations

import copy
from typing import Any, Tuple
from typing import Tuple
from pathlib import Path
from itertools import repeat, product
from multiprocessing import cpu_count
from multiprocessing.pool import Pool

import numpy as np
import pandas as pd
import numpy.typing as npt
import matplotlib.pyplot as plt
from scipy.stats import norm
from scipy.interpolate import LinearNDInterpolator, NearestNDInterpolator
from numpy.lib.arraysetops import unique

from floris.utilities import Vec3
from floris.type_dec import NDArrayFloat
from floris.simulation import Farm, Floris, FlowField, WakeModelManager, farm, floris, flow_field
from floris.simulation import Floris
from floris.logging_manager import LoggerBase
from floris.tools.cut_plane import get_plane_from_flow_data
# from floris.tools.flow_data import FlowData
from floris.simulation.turbine import Ct, power, axial_induction, average_velocity
from floris.tools.interface_utilities import get_params, set_params, show_params
from floris.tools.cut_plane import CutPlane, change_resolution, get_plane_from_flow_data

# from .visualization import visualize_cut_plane
# from .layout_functions import visualize_layout, build_turbine_loc
from floris.tools.cut_plane import CutPlane


class FlorisInterface(LoggerBase):
Expand Down Expand Up @@ -70,7 +55,7 @@ def __init__(self, configuration: dict | str | Path, het_map=None):
self.floris = Floris.from_dict(self.configuration)

else:
raise TypeError("The Floris `configuration` must of type 'dict', 'str', or 'Path'.")
raise TypeError("The Floris `configuration` must be of type 'dict', 'str', or 'Path'.")

# Store the heterogeneous map for use after reinitailization
self.het_map = het_map
Expand Down
23 changes: 15 additions & 8 deletions tests/base_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,35 @@
# See https://floris.readthedocs.io for documentation


import attr
import pytest

from attr import define, field

from floris.simulation import BaseClass, BaseModel


@attr.s(auto_attribs=True)
class ClassTest(BaseClass):
x: int = attr.ib(default=1, converter=int)
model_string: str = attr.ib(default="test", converter=str)
@define
class ClassTest(BaseModel):
x: int = field(default=1, converter=int)
a_string: str = field(default="abc", converter=str)

def prepare_function() -> dict:
return {}

def function() -> None:
return None


def test_get_model_defaults():
defaults = ClassTest.get_model_defaults()
assert len(defaults) == 2
assert defaults["x"] == 1
assert defaults["model_string"] == "test"
assert defaults["a_string"] == "abc"


def test_get_model_values():
cls = ClassTest(x=4, model_string="new")
cls = ClassTest(x=4, a_string="xyz")
values = cls._get_model_dict()
assert len(values) == 2
assert values["x"] == 4
assert values["model_string"] == "new"
assert values["a_string"] == "xyz"