コード例 #1
0
    def execute(self):
        """ Executes our file-wrapped component. """

        if self.debug:
            sys.stderr.write("  In {0}.execute()...\n".format(self.__class__))

        # Prepare input file here
        #   - write a new script file?
        #   - write a new turbine file to overwrite the one referenced
        #       in the existing script_file?

        # Execute the component
        self.command[1] = self.script_file
        super(OWwrapped, self).execute()

        if self.debug:
            sys.stderr.write(
                'Ran openWindExtCode: dummyVbl {:} returnCode {:}\n'.format(
                    self.dummyVbl, self.return_code))

        # Parse output file
        dscr = rdScript(self.command[1],
                        debug=self.debug)  # get output file name from script
        rptpath = dscr['rptpath']

        self.gross_aep, self.array_aep, self.net_aep, owTurbs = utils.rdReport(
            rptpath, debug=self.debug)
        self.turbine_number = len(owTurbs)

        # Set the output variables
        self.array_efficiency = self.array_aep / self.gross_aep
        self.gross_aep = self.gross_aep * 1000000.0  # gWh to kWh
        self.array_aep = self.array_aep * 1000000.0
        self.net_aep = self.net_aep * 1000000.0

        # find net aep (not using openwind for these since they may be inputs from other models)
        self.net_aep = self.net_aep * self.availability * (1 -
                                                           self.other_losses)

        # find array efficiency
        self.array_losses = 1 - (self.array_aep / self.gross_aep)
コード例 #2
0
    def execute(self):
        """ Executes our file-wrapped component. """

        if self.debug:
            sys.stderr.write("  In {0}.execute()...\n".format(self.__class__))

        # Prepare input file here
        #   - write a new script file?
        #   - write a new turbine file to overwrite the one referenced
        #       in the existing script_file?

        # Execute the component
        self.command[1] = self.script_file
        super(OWwrapped, self).execute()
        
        if self.debug:
            sys.stderr.write('Ran openWindExtCode: dummyVbl {:} returnCode {:}\n'.format(self.dummyVbl,self.return_code))

        # Parse output file
        dscr = rdScript(self.command[1], debug=self.debug) # get output file name from script
        rptpath = dscr['rptpath']
        
        self.gross_aep, self.array_aep, self.net_aep, owTurbs = utils.rdReport(rptpath, debug=self.debug) 
        self.turbine_number = len(owTurbs)
        
        # Set the output variables
        self.array_efficiency = self.array_aep / self.gross_aep        
        self.gross_aep = self.gross_aep * 1000000.0 # gWh to kWh
        self.array_aep = self.array_aep * 1000000.0
        self.net_aep   = self.net_aep   * 1000000.0

        # find net aep (not using openwind for these since they may be inputs from other models)
        self.net_aep = self.net_aep * self.availability * (1-self.other_losses)

        # find array efficiency
        self.array_losses = 1 - (self.array_aep/self.gross_aep)
コード例 #3
0
    def __init__(self,
                 owExe,
                 scriptFile=None,
                 extOpt=False,
                 debug=False,
                 stopOW=True,
                 start_once=False,
                 opt_log=False):
        """ Constructor for the OWwrapped component """

        self.debug = debug
        if self.debug:
            sys.stderr.write('\nIn {:}.__init__()\n'.format(self.__class__))
        super(OWcomp, self).__init__()

        # public variables

        self.input_file = 'myinput.txt'
        self.output_file = 'myoutput.txt'
        self.stderr = 'myerror.log'

        # external_files : member of Component class = list of FileMetadata objects
        self.external_files = [
            FileMetadata(path=self.output_file),
            FileMetadata(path=self.stderr),
        ]

        self.stopOW = stopOW
        self.start_once = start_once
        self.replace_turbine = False
        self.opt_log = opt_log
        self.extOpt = extOpt

        self.resname = ''  # start with empty string

        self.script_file = scriptFile
        self.scriptOK = False
        if scriptFile is not None:

            # Check script file for validity and extract some path information
            self.scriptOK = self.parse_scriptFile()
            if not self.scriptOK:
                raise ValueError
                return

            self.scriptDict = rwScriptXML.rdScript(self.script_file,
                                                   self.debug)
            if self.debug:
                sys.stderr.write('Script File Contents:\n')
                for k in self.scriptDict.keys():
                    sys.stderr.write('  {:12s} {:}\n'.format(
                        k, self.scriptDict[k]))

        # Log all optimization settings?
        if self.opt_log:
            self.olname = 'owOptLog.txt'
            self.olfh = open(self.olname, 'w')
            if self.debug:
                sys.stderr.write('Logging optimization params to {:}\n'.format(
                    self.olname))

        # Set the version of OpenWind that we want to use
        self.command = [owExe, self.script_file]

        # Keep the initial value of rotor diam so we can
        # see if it (or other turb param) has changed
        self.rtr_diam_init = self.rotor_diameter
        #  ... other params ....

        # Try starting OpenWind here (if self.start_once is True)
        if self.start_once:
            self.proc = subprocess.Popen(self.command)
            self.pid = self.proc.pid
            if self.debug:
                sys.stderr.write('Started OpenWind with pid {:}\n'.format(
                    self.pid))
                sys.stderr.write('  OWComp: dummyVbl {:}\n'.format(
                    self.dummyVbl))

        if self.debug:
            sys.stderr.write('\nLeaving {:}.__init__()\n\n'.format(
                self.__class__))
コード例 #4
0
def example(owExe):

    debug = True  # set True so user sees final 'break' message
    start_once = False
    modify_turbine = False
    opt_log = False
    extOpt = False

    for arg in sys.argv[1:]:
        if arg == '-debug':
            debug = True
        if arg == '-once':
            start_once = True
        if arg == '-log':
            opt_log = True
        if arg == '-modturb':
            modify_turbine = True
        if arg == '-extopt':
            extOpt = True
        if arg == '-help':
            sys.stderr.write(
                'USAGE: python openWindComponent.py [-once] [-debug] [-modturb] [-extopt]\n'
            )
            exit()

    # Find OpenWind executable
    if not os.path.isfile(owExe):
        sys.stderr.write(
            'OpenWind executable file "{:}" not found\n'.format(owExe))
        exit()

    # set the external optimiser flag to extOpt:
    #    True : can use our optimizing routines
    acutils.owIniSet(owExe, extVal=extOpt, debug=True)

    # If we are not externally optimizing, we can start OW once and let it run to completion

    if not extOpt:
        start_once = True

    # Set OpenWind script name
    testpath = 'templates/'
    #owXMLname = testpath + 'rtecScript.xml' # replace turb, energy capture #KLD - this script does not work for me with this component
    owXMLname = testpath + 'owScript.xml'  # optimize operation
    #owXMLname = testpath + 'rtopScript.xml' # replace turb, optimize

    if modify_turbine:
        owXMLname = testpath + 'rtopScript.xml'  # replace turb, optimize

    if not os.path.isfile(owXMLname):
        sys.stderr.write(
            'OpenWind script file "{:}" not found\n'.format(owXMLname))
        exit()

    dscript = rwScriptXML.rdScript(owXMLname,
                                   debug=debug)  # Show our operations
    workbook = dscript['workbook']

    # default turbine positions and size of translation

    wt_positions = [[456000.00, 4085000.00], [456500.00, 4085000.00]]
    deltaX = 3000.0
    deltaY = -2000.0
    #deltaX =  200.0
    #deltaY = -200.0
    deltaX = 3.000
    deltaY = -2.000

    # Read turbine positions from workbook
    if debug:
        sys.stderr.write(
            'Getting turbine positions from {:}\n'.format(workbook))
    wb = acutils.WTWkbkFile(wkbk=workbook, owexe=owExe)
    wt_positions = wb.xy
    if debug:
        sys.stderr.write('Got {:} turbine positions\n'.format(
            len(wt_positions)))

    # Initialize OWcomp component
    ow = OWcomp(owExe=owExe,
                debug=debug,
                scriptFile=owXMLname,
                extOpt=extOpt,
                start_once=start_once,
                opt_log=opt_log)  #, stopOW=False)

    if not ow.scriptOK:
        sys.stderr.write("\n*** ERROR found in script file\n\n")
        exit()

    # starting point for turbine mods
    #wt_list_elem = dummy_wt_list()
    base_turbine_file = testpath + 'NREL5MW.owtg'
    wt_list_elem = turbfuncs.owtg_to_wtpc(base_turbine_file)

    if not extOpt:
        # If we're not optimizing externally, run ow and return

        ow.execute()

        print '\nFinal values'
        owd = ow.dump()
        print '  {:}'.format(owd)
        print '-' * 40, '\n'

        return

    # external optimization

    ow.wt_layout.wt_list = [wt_list_elem for i in range(len(wt_positions))]
    if debug:
        sys.stderr.write('Initialized {:} turbines in wt_layout\n'.format(
            len(wt_positions)))

    # With each iteration
    #   move turbines farther offshore
    #   possibly modify the turbine rotor diam and power curve and replace turbine

    if debug:
        ofh = open('wtp.txt', 'w')

    for irun in range(1, 4):
        for i in range(len(wt_positions)):
            wt_positions[i][0] += deltaX
            wt_positions[i][1] += deltaY
            if debug:
                ofh.write('{:2d} {:3d} {:.1f} {:.1f}\n'.format(
                    irun, i, wt_positions[i][0], wt_positions[i][1]))
        ow.wt_layout.wt_positions = wt_positions

        # modify the turbine
        ow.rotor_diameter += 1.0
        if ow.replace_turbine:
            wt_list_elem = ow.wt_layout.wt_list[0]
            wt_list_elem.power_rating *= 1.05
            for i in range(len(wt_list_elem.power_curve)):
                wt_list_elem.power_curve[i][1] *= 1.05
            ow.wt_layout.wt_list = [
                wt_list_elem for i in range(len(ow.wt_layout.wt_list))
            ]
            if debug:
                ofh.write('Updated {:} turbines with:\n'.format(
                    len(ow.wt_layout.wt_list)))
                ofh.write(turbfuncs.wtpc_dump(ow.wt_layout.wt_list[0]))

        ow.execute()  # run the openWind process

        print '\nFinal values'
        owd = ow.dump()
        print '  {:}'.format(owd)
        print '-' * 40, '\n'

    if start_once:
        ow.terminateOW()
コード例 #5
0
    def __init__(self, owExe, scriptFile=None, extOpt=False, debug=False, 
      stopOW=True, start_once=False, opt_log=False):

        """ Constructor for the OWwrapped component """

        self.debug = debug
        if self.debug:
            sys.stderr.write('\nIn {:}.__init__()\n'.format(self.__class__))
        super(OWcomp, self).__init__()

        # public variables
        
        self.input_file = 'myinput.txt'
        self.output_file = 'myoutput.txt'
        self.stderr = 'myerror.log'
        
        # external_files : member of Component class = list of FileMetadata objects
        self.external_files = [
            FileMetadata(path=self.output_file),
            FileMetadata(path=self.stderr),
        ]
        
        self.stopOW = stopOW
        self.start_once = start_once
        self.replace_turbine = False
        self.opt_log = opt_log
        self.extOpt = extOpt
        
        self.resname = '' # start with empty string
        
        self.script_file = scriptFile
        self.scriptOK = False
        if scriptFile is not None:

            # Check script file for validity and extract some path information
            self.scriptOK = self.parse_scriptFile()
            if not self.scriptOK:
                raise ValueError
                return
                
            self.scriptDict = rwScriptXML.rdScript(self.script_file, self.debug)
            if self.debug:
                sys.stderr.write('Script File Contents:\n')
                for k in self.scriptDict.keys():
                    sys.stderr.write('  {:12s} {:}\n'.format(k,self.scriptDict[k]))
        
        # Log all optimization settings?
        if self.opt_log:
            self.olname = 'owOptLog.txt'
            self.olfh = open(self.olname, 'w')
            if self.debug:
                sys.stderr.write('Logging optimization params to {:}\n'.format(self.olname))
                
        # Set the version of OpenWind that we want to use
        self.command = [owExe, self.script_file]
        
        # Keep the initial value of rotor diam so we can
        # see if it (or other turb param) has changed
        self.rtr_diam_init = self.rotor_diameter
        #  ... other params ....
        
        # Try starting OpenWind here (if self.start_once is True)
        if self.start_once:
            self.proc = subprocess.Popen(self.command)
            self.pid = self.proc.pid
            if self.debug:
                sys.stderr.write('Started OpenWind with pid {:}\n'.format(self.pid))
                sys.stderr.write('  OWComp: dummyVbl {:}\n'.format(self.dummyVbl))
        
        if self.debug:
            sys.stderr.write('\nLeaving {:}.__init__()\n\n'.format(self.__class__))
コード例 #6
0
def example(owExe):

    debug = True  # set True so user sees final 'break' message
    start_once = False
    modify_turbine = False
    opt_log = False
    extOpt = False
    
    for arg in sys.argv[1:]:
        if arg == '-debug':
            debug = True
        if arg == '-once':
            start_once = True
        if arg == '-log':
            opt_log = True
        if arg == '-modturb':
            modify_turbine = True
        if arg == '-extopt':
            extOpt = True
        if arg == '-help':
            sys.stderr.write('USAGE: python openWindComponent.py [-once] [-debug] [-modturb] [-extopt]\n')
            exit()
    
    # Find OpenWind executable
    if not os.path.isfile(owExe):
        sys.stderr.write('OpenWind executable file "{:}" not found\n'.format(owExe))
        exit()

    # set the external optimiser flag to extOpt:
    #    True : can use our optimizing routines
    acutils.owIniSet(owExe, extVal=extOpt, debug=True)
    
    # If we are not externally optimizing, we can start OW once and let it run to completion
    
    if not extOpt:
        start_once = True
        
    # Set OpenWind script name
    testpath = 'templates/'
    #owXMLname = testpath + 'rtecScript.xml' # replace turb, energy capture #KLD - this script does not work for me with this component
    owXMLname = testpath + 'owScript.xml' # optimize operation
    #owXMLname = testpath + 'rtopScript.xml' # replace turb, optimize
    
    if modify_turbine:
        owXMLname = testpath + 'rtopScript.xml' # replace turb, optimize
        
    if not os.path.isfile(owXMLname):
        sys.stderr.write('OpenWind script file "{:}" not found\n'.format(owXMLname))
        exit()
    
    dscript = rwScriptXML.rdScript(owXMLname,debug=debug) # Show our operations
    workbook = dscript['workbook']
    
    # default turbine positions and size of translation
    
    wt_positions = [[456000.00,4085000.00],
                    [456500.00,4085000.00]]
    deltaX =  3000.0
    deltaY = -2000.0
    #deltaX =  200.0
    #deltaY = -200.0
    deltaX =  3.000
    deltaY = -2.000
    
    # Read turbine positions from workbook
    if debug:
        sys.stderr.write('Getting turbine positions from {:}\n'.format(workbook))        
    wb = acutils.WTWkbkFile(wkbk=workbook, owexe=owExe)
    wt_positions = wb.xy
    if debug:
        sys.stderr.write('Got {:} turbine positions\n'.format(len(wt_positions)))        
    
    # Initialize OWcomp component
    ow = OWcomp(owExe=owExe, debug=debug, scriptFile=owXMLname, 
                extOpt=extOpt,
                start_once=start_once, opt_log=opt_log) #, stopOW=False)

    if not ow.scriptOK:
        sys.stderr.write("\n*** ERROR found in script file\n\n")
        exit()
    
    # starting point for turbine mods
    #wt_list_elem = dummy_wt_list()    
    base_turbine_file = testpath + 'NREL5MW.owtg'
    wt_list_elem = turbfuncs.owtg_to_wtpc(base_turbine_file)
    
    if not extOpt:
        # If we're not optimizing externally, run ow and return
        
        ow.execute()
        
        print '\nFinal values'
        owd = ow.dump()
        print '  {:}'.format(owd)
        print '-' * 40, '\n'
        
        return
    
    # external optimization
            
    ow.wt_layout.wt_list = [ wt_list_elem for i in range(len(wt_positions)) ]
    if debug:
        sys.stderr.write('Initialized {:} turbines in wt_layout\n'.format(len(wt_positions)))
    
    # With each iteration
    #   move turbines farther offshore 
    #   possibly modify the turbine rotor diam and power curve and replace turbine
    
    if debug:
        ofh = open('wtp.txt', 'w')
        
    for irun in range(1,4):
        for i in range(len(wt_positions)):
            wt_positions[i][0] += deltaX
            wt_positions[i][1] += deltaY
            if debug:
                ofh.write('{:2d} {:3d} {:.1f} {:.1f}\n'.format(irun, i, wt_positions[i][0], wt_positions[i][1]))
        ow.wt_layout.wt_positions = wt_positions
        
        # modify the turbine
        ow.rotor_diameter += 1.0
        if ow.replace_turbine:
            wt_list_elem = ow.wt_layout.wt_list[0]
            wt_list_elem.power_rating *= 1.05
            for i in range(len(wt_list_elem.power_curve)):
                wt_list_elem.power_curve[i][1] *= 1.05
            ow.wt_layout.wt_list = [wt_list_elem for i in range(len(ow.wt_layout.wt_list)) ]
            if debug:
                ofh.write('Updated {:} turbines with:\n'.format(len(ow.wt_layout.wt_list)))
                ofh.write(turbfuncs.wtpc_dump(ow.wt_layout.wt_list[0]))
        
        ow.execute() # run the openWind process
        
        print '\nFinal values'
        owd = ow.dump()
        print '  {:}'.format(owd)
        print '-' * 40, '\n'

    if start_once:
        ow.terminateOW()