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

cleaner code: #17.1 decouple manual data from _setRotorParameters #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
75 changes: 50 additions & 25 deletions openfast_toolbox/fastfarm/FASTFarmCaseCreation.py
Original file line number Diff line number Diff line change
@@ -182,7 +182,7 @@ def __init__(self,


if self.verbose>0: print(f'Checking inputs...', end='\r')
self._checkInputs()
self._checkInputs()
if self.verbose>0: print(f'Checking inputs... Done.')


@@ -1224,32 +1224,57 @@ def _rotate_wts(self):
}

self.wts_rot_ds = pd.DataFrame.from_dict(wts_rot, orient='index').to_xarray().rename({'level_0':'inflow_deg','level_1':'turbine'})



def _get_rotor_parameters(self, diameter):
"""Retrieve rotor parameters based on turbine diameter."""
# Dictionary to hold rotor parameters for different turbines
rotor_parameters = {
220: { # 12 MW turbine
'WaveHs': [1.429, 1.429], # 1.429 comes from Matt's hydrodyn input file
'WaveTp': [7.073, 7.073], # 7.073 comes from Matt's hydrodyn input file
'RotSpeed': [4.0, 4.0], # 4 rpm comes from Matt's ED input file
'BlPitch': [0.0, 0.0], # 0 deg comes from Matt's ED input file
'coords': [10, 15]

},
240: { # IEA 15 MW
'WaveHs': [1.172, 1.323, 1.523, 1.764, 2.255], # higher values on default input from the repository (4.52)
'WaveTp': [7.287, 6.963, 7.115, 6.959, 7.067], # higher values on default input from the repository (9.45)
'RotSpeed': [4.995, 6.087, 7.557, 7.557, 7.557],
'BlPitch': [0.315, 0, 0.645, 7.6, 13.8],
'wspd': [6.6, 8.6, 10.6, 12.6, 15]
}
}

# Check if the diameter exists in the dictionary
if diameter not in rotor_parameters:
raise ValueError(f"Unknown turbine with diameter {diameter}. Add values to the rotor parameters. (the `_setRotorParameters` function.)")

return rotor_parameters[diameter]

def _setRotorParameters(self):

if self.D == 220: # 12 MW turbine
self.bins = xr.Dataset({'WaveHs': (['wspd'], [ 1.429, 1.429]), # 1.429 comes from Matt's hydrodyn input file
'WaveTp': (['wspd'], [ 7.073, 7.073]), # 7.073 comes from Matt's hydrodyn input file
'RotSpeed': (['wspd'], [ 4.0, 4.0]), # 4 rpm comes from Matt's ED input file
'BlPitch': (['wspd'], [ 0.0, 0.0]), # 0 deg comes from Matt's ED input file
#'WvHiCOffD': (['wspd'], [0, 0]), # 2nd order wave info. Unused for now
#'WvLowCOffS': (['wspd'], [0, 0]), # 2nd order wave info. Unused for now
}, coords={'wspd': [10, 15]} ) # 15 m/s is 'else', since method='nearest' is used on the variable `bins`

elif self.D == 240: # IEA 15 MW
self.bins = xr.Dataset({'WaveHs': (['wspd'], [1.172, 1.323, 1.523, 1.764, 2.255]), # higher values on default input from the repository (4.52)
'WaveTp': (['wspd'], [7.287, 6.963, 7.115, 6.959, 7.067]), # higher values on default input from the repository (9.45)
'RotSpeed': (['wspd'], [4.995, 6.087, 7.557, 7.557, 7.557]),
'BlPitch': (['wspd'], [0.315, 0, 0.645, 7.6, 13.8 ]),
#'WvHiCOffD': (['wspd'], [0, 0, 0, 0, 0 ]), # 2nd order wave info. Unused for now. 3.04292 from repo; 0.862 from KS
#'WvLowCOffS': (['wspd'], [0, 0, 0, 0, 0 ]), # 2nd order wave info. Unused for now 0.314159 from repo; 0.862 from KS
}, coords={'wspd': [6.6, 8.6, 10.6, 12.6, 15]} ) # 15 m/s is 'else', since method='nearest' is used on the variable `bins`
else:
raise ValueError(f'Unknown turbine with diameter {self.D}. Add values to the `_setRotorParameters` function.')
"""Set rotor parameters dynamically."""
try:
params = self._get_rotor_parameters(self.D)

# Create the xarray Dataset from the parameters
self.bins = xr.Dataset(
{
'WaveHs': (['wspd'], params['WaveHs']),
'WaveTp': (['wspd'], params['WaveTp']),
'RotSpeed': (['wspd'], params['RotSpeed']),
'BlPitch': (['wspd'], params['BlPitch']),
#'WvHiCOffD': (['wspd'], [0, 0]), # 2nd order wave info. Unused for now
#'WvLowCOffS': (['wspd'], [0, 0]), # 2nd order wave info. Unused for now
},
coords={'wspd': params['wspd']} # 15 m/s is 'else', since method='nearest' is used on the variable `bins`
)
#'WvHiCOffD': (['wspd'], [0, 0, 0, 0, 0 ]), # 2nd order wave info. Unused for now. 3.04292 from repo; 0.862 from KS
#'WvLowCOffS': (['wspd'], [0, 0, 0, 0, 0 ]), # 2nd order wave info. Unused for now 0.314159 from repo; 0.862 from KS
except ValueError as e:
print(e)
raise