def execute(self): # FAST version specific initialization if self.FAST_ver.lower() == 'fast7': reader = InputReader_FAST7(FAST_ver=self.FAST_ver) writer = InputWriter_FAST7(FAST_ver=self.FAST_ver) elif self.FAST_ver.lower() in ['fast8','openfast']: reader = InputReader_OpenFAST(FAST_ver=self.FAST_ver) writer = InputWriter_OpenFAST(FAST_ver=self.FAST_ver) wrapper = FastWrapper(FAST_ver=self.FAST_ver, debug_level=self.debug_level) # Read input model, FAST files or Yaml if self.fst_vt == {}: if self.read_yaml: reader.FAST_yamlfile = self.FAST_yamlfile_in reader.read_yaml() else: reader.FAST_InputFile = self.FAST_InputFile reader.FAST_directory = self.FAST_directory reader.execute() # Initialize writer variables with input model writer.fst_vt = reader.fst_vt else: writer.fst_vt = self.fst_vt writer.FAST_runDirectory = self.FAST_runDirectory writer.FAST_namingOut = self.FAST_namingOut # Make any case specific variable changes if self.case: writer.update(fst_update=self.case) # Modify any specified output channels if self.channels: writer.update_outlist(self.channels) # Write out FAST model writer.execute() if self.write_yaml: writer.FAST_yamlfile = self.FAST_yamlfile_out writer.write_yaml() # Run FAST wrapper.FAST_exe = self.FAST_exe wrapper.FAST_InputFile = os.path.split(writer.FAST_InputFileOut)[1] wrapper.FAST_directory = os.path.split(writer.FAST_InputFileOut)[0] FAST_Output = os.path.join(wrapper.FAST_directory, wrapper.FAST_InputFile[:-3]+'outb') FAST_Output_txt = os.path.join(wrapper.FAST_directory, wrapper.FAST_InputFile[:-3]+'out') #check if OpenFAST is set not to overwrite existing output files, TODO: move this further up in the workflow for minor computation savings if self.overwrite_outfiles or (not self.overwrite_outfiles and not (os.path.exists(FAST_Output) or os.path.exists(FAST_Output_txt))): wrapper.execute() else: if self.debug_level>0: print('OpenFAST not execute: Output file "%s" already exists. To overwrite this output file, set "overwrite_outfiles = True".'%FAST_Output) return FAST_Output
def execute(self): # FAST version specific initialization if self.FAST_ver.lower() == 'fast7': reader = InputReader_FAST7(FAST_ver=self.FAST_ver) writer = InputWriter_FAST7(FAST_ver=self.FAST_ver) elif self.FAST_ver.lower() in ['fast8','openfast']: reader = InputReader_OpenFAST(FAST_ver=self.FAST_ver) writer = InputWriter_OpenFAST(FAST_ver=self.FAST_ver) # Read input model, FAST files or Yaml if self.fst_vt == {}: if self.read_yaml: reader.FAST_yamlfile = self.FAST_yamlfile_in reader.read_yaml() else: reader.FAST_InputFile = self.FAST_InputFile reader.FAST_directory = self.FAST_directory reader.execute() # Initialize writer variables with input model writer.fst_vt = self.fst_vt = reader.fst_vt else: writer.fst_vt = self.fst_vt writer.FAST_runDirectory = self.FAST_runDirectory writer.FAST_namingOut = self.FAST_namingOut # Make any case specific variable changes if self.case: writer.update(fst_update=self.case) # Modify any specified output channels if self.channels: writer.update_outlist(self.channels) # Write out FAST model writer.execute() if self.write_yaml: writer.FAST_yamlfile = self.FAST_yamlfile_out writer.write_yaml() FAST_directory = os.path.split(writer.FAST_InputFileOut)[0] input_file_name = create_string_buffer(os.path.abspath(writer.FAST_InputFileOut).encode('utf-8')) t_max = c_double(self.fst_vt['Fst']['TMax']) orig_dir = os.getcwd() os.chdir(FAST_directory) openfastlib = FastLibAPI(self.FAST_lib, input_file_name, t_max) openfastlib.fast_run() output_dict = {} for i, channel in enumerate(openfastlib.output_channel_names): output_dict[channel] = openfastlib.output_values[:,i] del(openfastlib) output = OpenFASTOutput.from_dict(output_dict, self.FAST_namingOut, magnitude_channels=magnitude_channels) if self.fst_vt['Fst']['TStart'] > 0.0: output.trim_data(tmin=self.fst_vt['Fst']['TStart'], tmax=self.fst_vt['Fst']['TMax']) case_name, sum_stats, extremes, dels = la._process_output(output) # if save_file: write_fast os.chdir(orig_dir) if not self.keep_time: output_dict = None return case_name, sum_stats, extremes, dels, output_dict