Exemplo n.º 1
0
def example(owExe):

    debug = False
    start_once = False
    modify_turbine = False
    opt_log = 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 == '-help':
            sys.stderr.write('USAGE: python openWindAcComponent.py [-once] [-debug]\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 True so that we can use our optimizing routines
    
    acutils.owIniSet(owExe, extVal=True, debug=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 + 'owacScript.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 OWACcomp component
    ow = OWACcomp(owExe=owExe, debug=debug, scriptFile=owXMLname, 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)
        
    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()
Exemplo n.º 2
0
def example(owExe):

    debug = False
    start_once = False
    modify_turbine = False
    opt_log = 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 == '-help':
            sys.stderr.write(
                'USAGE: python openWindAcComponent.py [-once] [-debug]\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 True so that we can use our optimizing routines

    acutils.owIniSet(owExe, extVal=True, debug=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 + 'owacScript.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 OWACcomp component
    ow = OWACcomp(owExe=owExe,
                  debug=debug,
                  scriptFile=owXMLname,
                  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)

    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()
Exemplo n.º 3
0
def example(owExe):

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

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

    # set the external optimiser flag to True so that we can use our optimizing routines
    
    acutils.owIniSet(owExe, extVal=True, debug=True)
    
    testPath = '../templates/'
    #workbook_path = testPath + 'VA_test.blb'
    workbook_path = testPath + 'owTestWkbkExtend.blb'
    
    script_file = testPath + 'owacScript.xml' # optimize operation
    if modify_turbine:
        script_file = testPath + 'rtopScript.xml' # replace turbine, optimize
        #script_file = testPath + 'rtecScript.xml' # replace turbine, energy capture
        if debug:
            sys.stderr.write('Turbine will be modified\n')

    if not os.path.isfile(script_file):
        sys.stderr.write('OpenWind script file "{:}" not found\n'.format(script_file))
        exit()
  
    # ----- Run OpenWind once to get initial turbine positions
    
    if debug:
        sys.stderr.write('\n--------- Running OpenWind to get turbine positions --------------\n')
    wt_positions, ttypes = getworkbookvals.getTurbPos(workbook_path, owExe, delFiles=False)
    if debug:
        sys.stderr.write('Initial turbine positions from workbook {:}\n'.format(workbook_path))
        for i in range(len(wt_positions)):
            sys.stderr.write("  Turb{:2d} {:.1f} {:.1f} '{:}'\n".format(i,
              wt_positions[i][0],wt_positions[i][1], ttypes[i]))
        sys.stderr.write('--------- Finished Running OpenWind to get turbine positions --------------\n\n')

    # ----- Create OW_assembly object
    
    #turbine_name = 'Alstom Haliade 150m 6MW' # should match default turbine in workbook
    #machine_rating = 6000000.0 # machine_rating and power_rating are in W
    
    turbine_name = ttypes[0] # should match default turbine in workbook
    # How to get machine_rating for this turbine?
    #   - could search all *owtg files for matching name, then get rating
    fname, machine_rating = turbfuncs.findOWTG(testPath, turbine_name)
    
    # should check for existence of both owExe and workbook_path before
    #   trying to run openwind
    
    owAsy = openwindAC_assembly(owExe, workbook_path, 
                             script_file=script_file,
                             wt_positions=wt_positions,
                             turbine_name=turbine_name, 
                             machine_rating=machine_rating,
                             start_once=start_once,
                             debug=debug) 
    
    #owAsy.configure()
    
    owAsy.updateAssyRptPath('newReport.txt', 'newTestScript.xml')
    #owAsy.updateRptPath('newReport.txt', 'newTestScript.xml')
    
    # Originally, there was a turbine power/ct/rpm definition here, but that's not
    # part of an owAsy, so that code is now in C:/SystemsEngr/test/pcrvtst.py
    
    if True:
        owa = set_as_top(owAsy)
        if debug:
            sys.stderr.write('\n*** Running top-level assembly\n')
        owa.run()
    
    else:
        owAsy.execute() # run the openWind process

    # ----- Summary
    
    print 'openwindAC_assembly results:'
    print '  Gross {:.4f} mWh'.format(owAsy.gross_aep*0.001)
    print '  Net   {:.4f} mWh'.format(owAsy.net_aep*0.001)
    print '  Total losses {:.2f} %'.format(owAsy.total_losses*100.0)
    print '  CF    {:.2f} %'.format(owAsy.capacity_factor*100.0)
    print '  Using {:} turbines with power rating of {:.3f} MW'.format(
          len(owAsy.wt_layout.wt_positions), owAsy.machine_rating/1000000.0)