Skip to content

Commit

Permalink
Merge branch 'usflowt' of https://github.com/dzalkind/ROSCO into usflowt
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Zalkind committed Feb 28, 2024
2 parents 2ac9867 + fb99fd9 commit 1c0e878
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 22 deletions.
9 changes: 9 additions & 0 deletions rosco/toolbox/ofTools/case_gen/run_FAST.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def __init__(self):
self.controller_params = {}
self.fst_vt = {}
self.openfast_exe = 'openfast'
self.FAST_InputFile = None
self.FAST_directory = None

# Directories
self.tune_case_dir = ''
Expand Down Expand Up @@ -110,6 +112,13 @@ def run_FAST(self):
controller = ROSCO_controller.Controller(controller_params)

# Load turbine data from OpenFAST and rotor performance text file
# Overwrite input file if provided by user
if self.FAST_InputFile:
path_params['FAST_InputFile'] = self.FAST_InputFile

if self.FAST_directory:
path_params['FAST_directory'] = self.FAST_directory

tune_yaml_dir = os.path.split(self.tuning_yaml)[0]
cp_filename = os.path.join(
tune_yaml_dir,
Expand Down
37 changes: 22 additions & 15 deletions rosco/toolbox/ofTools/fast_io/FAST_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2757,23 +2757,30 @@ def read_MoorDyn(self, moordyn_file):

elif 'options' in data_line:

# MoorDyn lets options be written in any order
# Solver options
self.fst_vt['MoorDyn']['dtM'] = float_read(f.readline().split()[0])
self.fst_vt['MoorDyn']['kbot'] = float_read(f.readline().split()[0])
self.fst_vt['MoorDyn']['cbot'] = float_read(f.readline().split()[0])
self.fst_vt['MoorDyn']['dtIC'] = float_read(f.readline().split()[0])
self.fst_vt['MoorDyn']['TmaxIC'] = float_read(f.readline().split()[0])
self.fst_vt['MoorDyn']['CdScaleIC'] = float_read(f.readline().split()[0])
self.fst_vt['MoorDyn']['threshIC'] = float_read(f.readline().split()[0])
self.fst_vt['MoorDyn']['WaterKin'] = f.readline().split()[0]
f.readline()
self.fst_vt['MoorDyn']['options'] = [] # keep list of MoorDyn options

data = f.readline()
while data.split()[0] != 'END':
channels = data.strip().strip('"').strip("'")
channel_list = channels.split(',')
self.set_outlist(self.fst_vt['outlist']['MoorDyn'], channel_list)
data = f.readline()
string_options = ['WaterKin']

data_line = f.readline().strip().split()
while data_line[0] and data_line[0][:3] != '---': # OpenFAST searches for ---, so we'll do the same

raw_value = data_line[0]
option_name = data_line[1]

self.fst_vt['MoorDyn']['options'].append(option_name)
if option_name in string_options:
self.fst_vt['MoorDyn'][option_name] = raw_value
else:
self.fst_vt['MoorDyn'][option_name] = float(raw_value)

data_line = f.readline().strip().split()
data_line = ''.join(data_line) # re-join for reading next section uniformly

elif 'outputs' in data_line:

self.read_outlist(f,'MoorDyn')

f.close()
break
Expand Down
41 changes: 40 additions & 1 deletion rosco/toolbox/ofTools/fast_io/FAST_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ def write_MainInput(self):
f.write('{!s:<22} {:<11} {:}'.format(self.fst_vt['Fst']['VTK_fields'], 'VTK_fields', '- Write mesh fields to VTK data files? (flag) {true/false} [unused if WrVTK=0]\n'))
f.write('{:<22} {:<11} {:}'.format(self.fst_vt['Fst']['VTK_fps'], 'VTK_fps', '- Frame rate for VTK output (frames per second){will use closest integer multiple of DT} [used only if WrVTK=2]\n'))

f.flush()
os.fsync(f)
f.close()

def write_ElastoDyn(self):
Expand Down Expand Up @@ -431,6 +433,8 @@ def write_ElastoDyn(self):
f.write('END of input file (the word "END" must appear in the first 3 columns of this last OutList line)\n')

f.write('---------------------------------------------------------------------------------------\n')
f.flush()
os.fsync(f)
f.close()

def write_ElastoDynBlade(self):
Expand Down Expand Up @@ -482,6 +486,8 @@ def write_ElastoDynBlade(self):
f.write('{:<22} {:<11} {:}'.format(self.fst_vt['ElastoDynBlade']['BldEdgSh'][3], 'BldEdgSh(5)', '- , coeff of x^5\n'))
f.write('{:<22} {:<11} {:}'.format(self.fst_vt['ElastoDynBlade']['BldEdgSh'][4], 'BldEdgSh(6)', '- , coeff of x^6\n'))

f.flush()
os.fsync(f)
f.close()

def write_ElastoDynTower(self):
Expand Down Expand Up @@ -538,6 +544,8 @@ def write_ElastoDynTower(self):
f.write('{:<22} {:<11} {:}'.format(self.fst_vt['ElastoDynTower']['TwSSM2Sh'][3], 'TwSSM2Sh(5)', '- , coefficient of x^5 term\n'))
f.write('{:<22} {:<11} {:}'.format(self.fst_vt['ElastoDynTower']['TwSSM2Sh'][4], 'TwSSM2Sh(6)', '- , coefficient of x^6 term\n'))

f.flush()
os.fsync(f)
f.close()

def write_BeamDyn(self):
Expand Down Expand Up @@ -621,6 +629,8 @@ def write_BeamDyn(self):
f.write('END of input file (the word "END" must appear in the first 3 columns of this last OutList line)\n')

f.write('---------------------------------------------------------------------------------------')
f.flush()
os.fsync(f)
f.close()

# f.write('{:<22} {:<11} {:}'.format(self.fst_vt['BeamDyn'][''], '', '\n'))
Expand Down Expand Up @@ -740,6 +750,8 @@ def write_InflowWind(self):
f.write('END of input file (the word "END" must appear in the first 3 columns of this last OutList line)\n')
f.write('---------------------------------------------------------------------------------------\n')

f.flush()
os.fsync(f)
f.close()

def write_AeroDyn15(self):
Expand Down Expand Up @@ -873,6 +885,8 @@ def write_AeroDyn15(self):
f.write('END of input file (the word "END" must appear in the first 3 columns of this last OutList line)\n')

f.write('---------------------------------------------------------------------------------------\n')
f.flush()
os.fsync(f)
f.close()

def write_AeroDyn15Blade(self):
Expand All @@ -899,6 +913,8 @@ def write_AeroDyn15Blade(self):
for Spn, CrvAC, SwpAC, CrvAng, Twist, Chord, AFID in zip(BlSpn, BlCrvAC, BlSwpAC, BlCrvAng, BlTwist, BlChord, BlAFID):
f.write('{: 2.15e} {: 2.15e} {: 2.15e} {: 2.15e} {: 2.15e} {: 2.15e} {: 8d}\n'.format(Spn, CrvAC, SwpAC, CrvAng, Twist, Chord, int(AFID)))

f.flush()
os.fsync(f)
f.close()

def write_AeroDyn15Polar(self):
Expand Down Expand Up @@ -1043,6 +1059,8 @@ def write_AeroDyn15Polar(self):
for row in polar:
f.write(' '.join(['{: 2.14e}'.format(val) for val in row])+'\n')

f.flush()
os.fsync(f)
f.close()

def write_AeroDyn15Coord(self):
Expand All @@ -1069,6 +1087,9 @@ def write_AeroDyn15Coord(self):
f.write('! x/c y/c\n')
for row in coord:
f.write(' '.join(['{: 2.14e}'.format(val) for val in row])+'\n')

f.flush()
os.fsync(f)
f.close()

def write_AeroDyn14(self):
Expand Down Expand Up @@ -1144,6 +1165,8 @@ def write_AeroDyn14(self):
for r, t, dr, c, a, p in zip(rnodes, twist, drnodes, chord, nfoil, prnelm):
f.write('{: 2.15e}\t{: 2.15e}\t{: 2.15e}\t{: 2.15e}\t{:5}\t{:}\n'.format(r, t, dr, c, a, p))

f.flush()
os.fsync(f)
f.close()

def write_AeroDyn14Tower(self):
Expand All @@ -1167,6 +1190,8 @@ def write_AeroDyn14Tower(self):
for Re, CD in zip(self.fst_vt['AeroDynTower']['TwrRe'], self.fst_vt['AeroDynTower']['TwrCD']):
f.write('% 2.15e' %Re + ' '.join(['% 2.15e'%cdi for cdi in CD]) + '\n')

f.flush()
os.fsync(f)
f.close()

def write_AeroDyn14Polar(self, filename, a_i):
Expand Down Expand Up @@ -1197,6 +1222,8 @@ def write_AeroDyn14Polar(self, filename, a_i):
for a, cl, cd in zip(param['alpha'], param['cl'], param['cd']):
f.write('{: 6e} {: 6e} {: 6e}\n'.format(a, cl, cd))

f.flush()
os.fsync(f)
f.close()

def write_OLAF(self):
Expand Down Expand Up @@ -1253,6 +1280,8 @@ def write_OLAF(self):
f.write('--------------------------- ADVANCED OPTIONS --------------------------------------------------\n')
f.write('===============================================================================================\n')

f.flush()
os.fsync(f)
f.close()

def write_ServoDyn(self):
Expand Down Expand Up @@ -1381,10 +1410,12 @@ def write_ServoDyn(self):
f.write('END of input file (the word "END" must appear in the first 3 columns of this last OutList line)\n')
f.write('---------------------------------------------------------------------------------------\n')

f.flush()
os.fsync(f)
f.close()

def write_DISCON_in(self):
# Generate Bladed style Interface controller input file, intended for ROSCO https://github.com/NREL/rosco.toolbox
# Generate Bladed style Interface controller input file, intended for ROSCO https://github.com/NREL/ROSCO_toolbox

# Fill controller and turbine objects for ROSCO
# - controller
Expand Down Expand Up @@ -2022,6 +2053,8 @@ def write_SubDyn(self):
for i in range(len(channel_list)):
f.write('"' + channel_list[i] + '"\n')
f.write('END of output channels and end of file. (the word "END" must appear in the first 3 columns of this line)\n')
f.flush()
os.fsync(f)
f.close()

def write_MAP(self):
Expand Down Expand Up @@ -2083,6 +2116,8 @@ def write_MAP(self):
f.write('{:<11s}'.format('(-)')+'\n')
f.write("\n".join(self.fst_vt['MAP']['Option']).strip() + '\n')

f.flush()
os.fsync(f)
f.close()

def write_MoorDyn(self):
Expand Down Expand Up @@ -2224,6 +2259,8 @@ def write_MoorDyn(self):
f.write('END\n')
f.write('------------------------- need this line --------------------------------------\n')

f.flush()
os.fsync(f)
f.close()


Expand Down Expand Up @@ -2326,6 +2363,8 @@ def write_StC(self,StC_vt,StC_filename):
f.write('{!s:<22} {:<11} {:}'.format(StC_vt['PrescribedForcesFile'], 'PrescribedForcesFile', '- Time series force and moment (7 columns of time, FX, FY, FZ, MX, MY, MZ)\n'))
f.write('-------------------------------------------------------------------------------\n')

f.flush()
os.fsync(f)
f.close()

if __name__=="__main__":
Expand Down
15 changes: 9 additions & 6 deletions rosco/toolbox/ofTools/fast_io/update_discons.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ def update_discons(tune_to_test_map):
if not isinstance(tune_to_test_map[tuning_yaml],list):
tune_to_test_map[tuning_yaml] = [tune_to_test_map[tuning_yaml]]

# Handle relative directory to Cp file
yaml_dir = os.path.dirname(tuning_yaml)
cp_filename = os.path.relpath(
os.path.join(yaml_dir,path_params['rotor_performance_filename']),
os.path.join(yaml_dir,path_params['FAST_directory']))

discon_in_files = [f for f in tune_to_test_map[tuning_yaml]]
for discon in discon_in_files:

# Handle relative directory to Cp file
discon_dir = os.path.dirname(os.path.realpath(discon))

yaml_dir = os.path.dirname(tuning_yaml)
cp_filename = os.path.relpath(
os.path.join(yaml_dir,path_params['rotor_performance_filename']),
os.path.join(discon_dir))

write_DISCON(
turbine,controller,
param_file=discon,
Expand Down

0 comments on commit 1c0e878

Please sign in to comment.