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

Improve/17.4: Create inflowType, inflowPath spec with options LES, TS replacing LESpath spec. #33

Merged
merged 7 commits into from
Feb 26, 2025
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
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""Initializes the package"""
"""Initialize package"""
44 changes: 25 additions & 19 deletions openfast_toolbox/fastfarm/FASTFarmCaseCreation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import pandas as pd
import numpy as np
import os, sys, shutil
import subprocess
import numpy as np
Expand Down Expand Up @@ -83,7 +82,8 @@ def __init__(self,
EDmodel = None,
nSeeds = 6,
seedValues = None,
LESpath = None,
inflowPath = None,
inflowType = None,
sweepYawMisalignment = False,
refTurb_rot = 0,
verbose = 0):
Expand Down Expand Up @@ -139,10 +139,13 @@ def __init__(self,
Number of seeds used for TurbSim simulations. If changing this value, give seedValues
seedValues: list of int
Seed value for each seed of requested TurbSim simulations if nSeeds!=6
LESpath: str or list of strings
inflowType: str
Inflow type (LES or TS) This variable will dictate whether it is a TurbSim-driven or LES-driven case
Choose 'LES' or 'TS' (no default is set)
inflowPath: str or list of strings
Full path of the LES data, if driven by LES. If None, the setup will be for TurbSim inflow.
LESpath can be a single path, or a list of paths of the same length as the sweep in conditions.
For example, if TIvalue=[8,10,12], then LESpath can be 3 paths, related to each condition.
inflowPath can be a single path, or a list of paths of the same length as the sweep in conditions.
For example, if TIvalue=[8,10,12], then inflowPath can be 3 paths, related to each condition.
sweepYawMisalignment: bool
Whether or not to perform a sweep with and without yaw misalignment perturbations
refTurb_rot: int
Expand Down Expand Up @@ -173,7 +176,8 @@ def __init__(self,
self.ADmodel = ADmodel
self.EDmodel = EDmodel
self.nSeeds = nSeeds
self.LESpath = LESpath
self.inflowPath = inflowPath
self.inflowType = inflowType
self.sweepYM = sweepYawMisalignment
self.seedValues = seedValues
self.refTurb_rot = refTurb_rot
Expand Down Expand Up @@ -205,7 +209,7 @@ def __repr__(self):
s = f'Requested parameters:\n'
s += f' - Case path: {self.path}\n'
s += f' - Wake model: {self.mod_wake} (1:Polar; 2:Curl; 3:Cartesian)\n'
if self.LESpath is None:
if self.inflowType == 'TS':
s += f' - Number of TurbSim seeds: {self.nSeeds}\n'
s += f' - End time: {self.tmax} s\n'
s += f'Requested farm:\n'
Expand Down Expand Up @@ -236,16 +240,16 @@ def __repr__(self):
s += f"\n\n"


if self.LESpath is None:
if self.inflowType == 'TS':
s += f'Turbulence boxes: TurbSim\n'
s += f'TurbSim turbulence boxes details:\n'
else:
s += f'Turbulence boxes: LES\n'
s += f'LES turbulence boxes details:\n'
s += f' Path: {self.LESpath}\n'
s += f' Path: {self.inflowPath}\n'


if self.TSlowBoxFilesCreatedBool or self.LESpath is not None:
if self.TSlowBoxFilesCreatedBool or self.inflowType == 'LES':
s += f' Low-resolution domain: \n'
s += f' - ds low: {self.ds_low_les} m\n'
s += f' - dt low: {self.dt_low_les} s\n'
Expand All @@ -255,7 +259,7 @@ def __repr__(self):
s += f'Low-res boxes not created yet.\n'


if self.TShighBoxFilesCreatedBool or self.LESpath is not None:
if self.TShighBoxFilesCreatedBool or self.inflowType == 'LES':
s += f' High-resolution domain: \n'
s += f' - ds high: {self.ds_high_les} m\n'
s += f' - dt high: {self.dt_high_les} s\n'
Expand Down Expand Up @@ -416,20 +420,22 @@ def _checkInputs(self):
f'to the number of seeds requested.')

# Check LES parameters
if self.LESpath is None:
if self.inflowType == 'TS':
self.inflowStr = 'TurbSim'
self.Mod_AmbWind = 3
else:
if isinstance(self.LESpath,str): self.LESpath = [self.LESpath]*len(self.vhub)
elif self.inflowType == 'LES':
if isinstance(self.inflowPath,str): self.inflowPath = [self.inflowPath]*len(self.vhub)
self.inflowStr = 'LES'
self.Mod_AmbWind = 1
for p in self.LESpath:
for p in self.inflowPath:
if not os.path.isdir(p):
raise ValueError (f'The LES path {p} does not exist')
# LES is requested, so domain limits must be given
if None in (self.dt_high_les, self.ds_high_les, self.dt_low_les, self.ds_low_les):
raise ValueError (f'An LES-driven case was requested, but one or more grid parameters were not given. '\
'Set `dt_high_les`, `ds_high_les`, `dt_low_les`, and `ds_low_les` based on your LES boxes.')
else:
raise ValueError (f"Inflow type `inflowType` should be 'TS' or 'LES'. Received {self.inflowType}.")


# Check the wake model (1:Polar; 2:Curl; 3:Cartesian)
Expand Down Expand Up @@ -1636,7 +1642,7 @@ def TS_high_slurm_submit(self, qos='normal', A=None, t=None, p=None):
if t is not None:
options += f'-t {t} '
if p is not None:
otions += f'-p {p} '
options += f'-p {p} '

sub_command = f"sbatch {options}{self.slurmfilename_high}"
print(f'Calling: {sub_command}')
Expand Down Expand Up @@ -1811,7 +1817,7 @@ def _FF_setup_LES(self, seedsToKeep=1):

# Low-res box
try:
src = os.path.join(self.LESpath[cond], 'Low')
src = os.path.join(self.inflowPath[cond], 'Low')
dst = os.path.join(self.path, self.condDirList[cond], self.caseDirList[case], f'Seed_{seed}', LESboxesDirName, 'Low')
os.symlink(src, dst)
except FileExistsError:
Expand All @@ -1820,7 +1826,7 @@ def _FF_setup_LES(self, seedsToKeep=1):
# High-res boxes
for t in range(self.nTurbines):
try:
src = os.path.join(self.LESpath[cond], f"HighT{t+1}_inflow{str(self.allCases.sel(case=case).inflow_deg.values).replace('-','m')}deg")
src = os.path.join(self.inflowPath[cond], f"HighT{t+1}_inflow{str(self.allCases.sel(case=case).inflow_deg.values).replace('-','m')}deg")
dst = os.path.join(self.path,self.condDirList[cond], self.caseDirList[case], f'Seed_{seed}', LESboxesDirName, f'HighT{t+1}')
os.symlink(src, dst)
except FileExistsError:
Expand Down Expand Up @@ -2189,7 +2195,7 @@ def FF_slurm_submit(self, qos='normal', A=None, t=None, p=None, delay=4):
if t is not None:
options += f'-t {t} '
if p is not None:
otions += f'-p {p} '
options += f'-p {p} '

sub_command = f"sbatch {options}{fname}"
print(f'Calling: {sub_command}')
Expand Down
20 changes: 11 additions & 9 deletions openfast_toolbox/fastfarm/examples/Ex3_FFarmCompleteSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def main():

# ----------- Execution parameters
ffbin = '/full/path/to/your/binary/.../bin/FAST.Farm'
# ----------- LES parameters. This variable will dictate whether it is a TurbSim-driven or LES-driven case
LESpath = '/full/path/to/the/LES/case'
#LESpath = None # set as None if TurbSim-driven is desired


# ----------- Inflow type (LES or TS)
inflowType = 'TS' # Choose 'LES' or 'TS'
# If LES, then set the inflowPath below
# inflowPath = '/full/path/to/LES/case'

# -----------------------------------------------------------------------------
# ----------- Template files
templatePath = '/full/path/where/template/files/are'
Expand Down Expand Up @@ -126,8 +126,10 @@ def main():
dt_high_les, ds_high_les, extent_high,
dt_low_les, ds_low_les, extent_low,
ffbin=ffbin, mod_wake=mod_wake, yaw_init=yaw_init,
nSeeds=nSeeds, LESpath=LESpath, refTurb_rot=refTurb_rot,
verbose=1)
nSeeds=nSeeds,
inflowType=inflowType,
#inflowPath=inflowPath, # if LES, uncomment this line
refTurb_rot=refTurb_rot, verbose=1)

case.setTemplateFilename(templatePath, EDfilename, SEDfilename, HDfilename, SrvDfilename, ADfilename,
ADskfilename, SubDfilename, IWfilename, BDfilepath, bladefilename, towerfilename,
Expand All @@ -141,7 +143,7 @@ def main():
case.copyTurbineFilesForEachCase()

# TurbSim setup
if LESpath is None:
if inflowType == 'TS':
case.TS_low_setup()
case.TS_low_slurm_prepare(slurm_TS_low)
#case.TS_low_slurm_submit()
Expand Down