Skip to content

Commit

Permalink
Fix paths, print outputs to pdf, add submit script
Browse files Browse the repository at this point in the history
  • Loading branch information
dzalkind committed Mar 5, 2021
1 parent b3ab9c6 commit 8cd8388
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
49 changes: 49 additions & 0 deletions ROSCO_testing/ROSCO_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from ROSCO_toolbox.ofTools.fast_io.FAST_reader import InputReader_OpenFAST
from ROSCO_toolbox.ofTools.case_gen.CaseGen_IEC import CaseGen_IEC
from ROSCO_toolbox.ofTools.case_gen.runFAST_pywrapper import runFAST_pywrapper_batch
from matplotlib.backends.backend_pdf import FigureCanvasPdf, PdfPages
from ROSCO_toolbox.ofTools.fast_io import output_processing
import matplotlib.pyplot as plt



Expand Down Expand Up @@ -238,6 +241,8 @@ def ROSCO_Test_lite(self, more_case_inputs={}, U=[]):
else:
fastBatch.run_serial()

self.print_results(outFileNames)


def ROSCO_Test_heavy(self, more_case_inputs={}, U=[]):
'''
Expand Down Expand Up @@ -401,6 +406,8 @@ def ROSCO_Test_heavy(self, more_case_inputs={}, U=[]):
else:
fastBatch.run_serial()

self.print_results(outFileNames)

def ROSCO_Controller_Comp(self, controller_paths, testtype='light', more_case_inputs={}, U=[]):
'''
Heavy or light testing for n controllers, n = len(controller_paths)
Expand Down Expand Up @@ -468,6 +475,48 @@ def ROSCO_DISCON_Comp(self, DISCON_filenames, testtype='light', more_case_inputs
self.runDir = run_dir_init
self.windDir = wind_dir_init

def print_results(self,outfiles):
print(outfiles)

op = output_processing.output_processing()
FAST_Output = op.load_fast_out(outfiles, tmin=0)

figs_fname = 'test_outputs.pdf'
with PdfPages(os.path.join(self.runDir,figs_fname)) as pdf:
for fast_out in FAST_Output:
if self.FAST_InputFile == 'NREL-5MW.fst':
plots2make = {'Baseline': ['Wind1VelX', 'GenPwr', 'RotSpeed', 'BldPitch1', 'GenTq']}
else:
plots2make = {'Baseline': ['Wind1VelX', 'GenPwr', 'RotSpeed', 'BldPitch1', 'GenTq','PtfmPitch']}

numplots = len(plots2make)
maxchannels = np.max([len(plots2make[key]) for key in plots2make.keys()])
fig = plt.figure(figsize=(8,6), constrained_layout=True)
gs_all = fig.add_gridspec(1, numplots)
for pnum, (gs, pname) in enumerate(zip(gs_all, plots2make.keys())):
gs0 = gs.subgridspec(len(plots2make[pname]),1)
for cid, channel in enumerate(plots2make[pname]):
subplt = fig.add_subplot(gs0[cid])
try:
subplt.plot(fast_out['Time'], fast_out[channel])
unit_idx = fast_out['meta']['channels'].index(channel)
subplt.set_ylabel('{:^} \n ({:^})'.format(
channel,
fast_out['meta']['attribute_units'][unit_idx]))
subplt.grid(True)
subplt.set_xlabel('Time (s)')
except:
print('Cannot plot {}'.format(channel))
if cid == 0:
subplt.set_title(pname)
if cid != len(plots2make[pname])-1:
subplt.axes.get_xaxis().set_visible(False)

plt.suptitle(fast_out['meta']['name'])
pdf.savefig(fig)
plt.close()


if __name__=='__main__':
rt = ROSCO_testing()

Expand Down
17 changes: 9 additions & 8 deletions ROSCO_testing/run_Testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def run_testing(turbine2test, testtype, rosco_binaries=[], discon_files=[], **kw
if turbine2test == 'NREL-5MW':
rt.Turbine_Class = 'I'
rt.Turbulence_Class = 'A'
rt.FAST_directory = os.path.join(os.path.dirname(__file__), '../Test_Cases/NREL-5MW')
rt.FAST_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../Test_Cases/NREL-5MW')
rt.FAST_InputFile = 'NREL-5MW.fst'
elif turbine2test == 'IEA-15MW':
rt.Turbine_Class = 'I'
rt.Turbulence_Class = 'B'
rt.FAST_directory = os.path.join(os.path.dirname(__file__), '../Test_Cases/IEA-15-240-RWT-UMaineSemi')
rt.FAST_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../Test_Cases/IEA-15-240-RWT-UMaineSemi')
rt.FAST_InputFile = 'IEA-15-240-RWT-UMaineSemi.fst'
else:
raise ValueError('{} is not an available turbine to test!'.format(turbine2test))
Expand All @@ -79,12 +79,12 @@ def run_testing(turbine2test, testtype, rosco_binaries=[], discon_files=[], **kw
if __name__ == "__main__":

# WEIS directory, for running openfast, etc.
this_dir = os.path.dirname(__file__)
this_dir = os.path.dirname(os.path.realpath(__file__))

# Setup ROSCO testing parameters
rt_kwargs = {}
rt_kwargs['runDir'] = os.path.join(this_dir,'results/') # directory for FAST simulations
rt_kwargs['namebase'] = 'lite_test' # Base name for FAST files
rt_kwargs['runDir'] = os.path.join(this_dir,'results/IEA-15MW') # directory for FAST simulations
rt_kwargs['namebase'] = 'heavy_test' # Base name for FAST files
rt_kwargs['FAST_exe'] = 'openfast' # OpenFAST executable path
rt_kwargs['Turbsim_exe']= 'turbsim' # Turbsim executable path
rt_kwargs['FAST_ver'] = 'OpenFAST' # FAST version
Expand All @@ -97,13 +97,14 @@ def run_testing(turbine2test, testtype, rosco_binaries=[], discon_files=[], **kw
rt_kwargs['outfile_fmt'] = 2 # 1 = .txt, 2 = binary, 3 = both

# ---- Define test type ----
turbine2test = 'NREL-5MW' # IEA-15MW or NREL-5MW
testtype = 'lite' # lite, heavy, binary-comp, discon-comp
turbine2test = 'IEA-15MW' # IEA-15MW or NREL-5MW
testtype = 'heavy' # lite, heavy, binary-comp, discon-comp

# Only fill one of these if comparing controllers
rosco_binaries = [glob.glob(os.path.join(this_dir,'../ROSCO/build/libdiscon.*'))[0]] # Differently named libdiscons to compare
discon_files = [] # Differently named DISCON.IN files to compare

print(rosco_binaries)
print(this_dir)

# Run testing
run_testing(turbine2test, testtype, rosco_binaries=rosco_binaries, discon_files=discon_files, **rt_kwargs)
26 changes: 26 additions & 0 deletions ROSCO_testing/submit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
#SBATCH --account=ssc
#SBATCH --time=1:00:00
#SBATCH --job-name=rosco_test
#SBATCH --nodes=1 # This should be nC/36 (36 cores on eagle)
#SBATCH --ntasks-per-node=36
#SBATCH --mail-user [email protected]
#SBATCH --mail-type BEGIN,END,FAIL
#SBATCH --output=output.%j.out
#SBATCH --partition=debug

nDV=1 # Number of design variables (x2 for central difference)
nOF=60 # Number of openfast runs per finite-difference evaluation
nC=$((nDV + nDV * nOF)) # Number of cores needed. Make sure to request an appropriate number of nodes = N / 36
## nC=72

source activate /home/dzalkind/.conda-envs/weis-env4
which python

# module purge
# module load conda
# module load comp-intel intel-mpi mkl


python run_Testing.py
# python weis_driver.py

0 comments on commit 8cd8388

Please sign in to comment.