def readConfig(self): ''' Read VAMPzeros configuration parameters. Command line arguments overwrite the configurations in the toolspecific part. ''' TIXIHandle = tixiLib.openTIXI(self.cpacsIn) if self.args.d != None: self.config['deviationAmplitude'] = float(self.args.d) else: devFactor = 0.0 devFactorStr = tixiLib.getText(TIXIHandle,'/cpacs/toolspecific/vampZero/toolSettings/deviationAmplitude') if devFactorStr != None: devFactor = float(devFactorStr) self.config['deviationAmplitude'] = devFactor # read configuration for extended output self.config['extendedOutput'] = True extendedOutput = tixiLib.getText(TIXIHandle,'/cpacs/toolspecific/vampZero/toolSettings/extendedOutput') if extendedOutput in ('False', 'false', '0.0', '0.', '0'): self.config['extendedOutput'] = False # read sensitivity configuration self.config['calcSensitivities'] = False calcSensitivities = tixiLib.getText(TIXIHandle,'/cpacs/toolspecific/vampZero/toolSettings/calcSensitivities') if calcSensitivities in ('True', 'true', '1.0', '1.', '1'): self.config['calcSensitivities'] = True # read not converging behavior self.config['notConvergingAction'] = 'exit' not_converging_action = tixiLib.getText(TIXIHandle,'/cpacs/toolspecific/vampZero/toolSettings/notConvergingAction') if not_converging_action in ('exit', 'copyInput', 'errorXML'): self.config['notConvergingAction'] = not_converging_action tixiLib.closeXML(TIXIHandle)
def resultToolspecExport(component, path): ''' Exports marked parameters into VAMPzeros toolspecific results node. @param component: should be the aircraft component ''' log = zeroLogger('resultToolspecExport') log.info('') log.info( "##############################################################################" ) log.info("VAMPzero Result Toolspecific Export to %s" % (path)) log.info( "##############################################################################" ) #reset outfile TIXIHandle = tixiLib.openTIXI(path) for para in component.getParameters(): if not para['exportTS']: continue # try to get componentNode compPathBase = '/cpacs/toolspecific/vampZero/results/components/component' compPath = compPathBase + '[name="%s"]' % para.parent.id discPathBase = compPath + '/disciplines/discipline' discPath = discPathBase + '[name="%s"]' % para["discipline"] paraPathBase = discPath + '/parameters/parameter' paraPath = paraPathBase + '[name="%s"]' % para.getName() # try to get component node exists = tixiLib.checkElement(TIXIHandle, compPath) if not exists: # create it tixiLib.buildTree(TIXIHandle, compPath + '/name') tixiLib.addText(TIXIHandle, compPathBase + '[last()]/name', para.parent.id) # try to get discipline node exists = tixiLib.checkElement(TIXIHandle, discPath) if not exists: # create it tixiLib.buildTree(TIXIHandle, discPath + '/name') tixiLib.addText(TIXIHandle, discPathBase + '[last()]/name', para["discipline"]) # try to get parameter node exists = tixiLib.checkElement(TIXIHandle, paraPath) if not exists: # create it tixiLib.buildTree(TIXIHandle, paraPath + '/name') tixiLib.addText(TIXIHandle, paraPathBase + '[last()]/name', para.getName()) tixiLib.setText(TIXIHandle, paraPath + '/value', para.getValue()) tixiLib.saveXML(path, TIXIHandle) tixiLib.closeXML(TIXIHandle) log.info("VAMPzero RESULT TOOLSPECIFIC EXPORT: done.")
def cpacsImport(self, path='.\\cpacs.xml'): ''' Looks for parameter.CPACSPath in CPACSFilse defined by Path Transfers Value is possible Input Values will be set to 'fix' ''' self.log.info('') self.log.info( "##############################################################################" ) self.log.info("VAMPzero CPACS Import from %s" % path) self.log.info("trying to import and fix parameters") self.log.info( "##############################################################################" ) TIXIHandle = openTIXI(path) modelUID = getText(TIXIHandle, '/cpacs/toolspecific/vampZero/aircraftModelUID') if modelUID is None: self.log.info( "VAMPzero IMPORT: No modelUID specified in the toolspecific Block" ) try: modelUID = self.modelUID.getValue() self.log.info("VAMPzero IMPORT: loaded modelUID from VAMPzero") except AttributeError: modelUID = None self.log.info( "VAMPzero IMPORT: could not load modelUID from VAMPzero") if modelUID is not None: TIGLHandle = openTIGL(TIXIHandle, modelUID) if TIGLHandle is not None: self.log.debug( "VAMPzero IMPORT: Opened TIXI and TIGL in Component") else: TIGLHandle = None self.log.debug( "VAMPzero IMPORT: Opened only TIXI in Component as no modelUID was specified" ) self.importer(path, TIXIHandle, TIGLHandle) self.log.info("VAMPzero IMPORT: done.") closeXML(TIXIHandle)
def resultToolspecExport(component, path): """ Exports marked parameters into VAMPzeros toolspecific results node. @param component: should be the aircraft component """ log = zeroLogger("resultToolspecExport") log.info("") log.info("##############################################################################") log.info("VAMPzero Result Toolspecific Export to %s" % (path)) log.info("##############################################################################") # reset outfile TIXIHandle = tixiLib.openTIXI(path) for para in component.getParameters(): if not para["exportTS"]: continue # try to get componentNode compPathBase = "/cpacs/toolspecific/vampZero/results/components/component" compPath = compPathBase + '[name="%s"]' % para.parent.id discPathBase = compPath + "/disciplines/discipline" discPath = discPathBase + '[name="%s"]' % para["discipline"] paraPathBase = discPath + "/parameters/parameter" paraPath = paraPathBase + '[name="%s"]' % para.getName() # try to get component node exists = tixiLib.checkElement(TIXIHandle, compPath) if not exists: # create it tixiLib.buildTree(TIXIHandle, compPath + "/name") tixiLib.addText(TIXIHandle, compPathBase + "[last()]/name", para.parent.id) # try to get discipline node exists = tixiLib.checkElement(TIXIHandle, discPath) if not exists: # create it tixiLib.buildTree(TIXIHandle, discPath + "/name") tixiLib.addText(TIXIHandle, discPathBase + "[last()]/name", para["discipline"]) # try to get parameter node exists = tixiLib.checkElement(TIXIHandle, paraPath) if not exists: # create it tixiLib.buildTree(TIXIHandle, paraPath + "/name") tixiLib.addText(TIXIHandle, paraPathBase + "[last()]/name", para.getName()) tixiLib.setText(TIXIHandle, paraPath + "/value", para.getValue()) tixiLib.saveXML(path, TIXIHandle) tixiLib.closeXML(TIXIHandle) log.info("VAMPzero RESULT TOOLSPECIFIC EXPORT: done.")
def readConfig(self): ''' Read VAMPzeros configuration parameters. Command line arguments overwrite the configurations in the toolspecific part. ''' TIXIHandle = tixiLib.openTIXI(self.cpacsIn) if self.args.d != None: self.config['deviationAmplitude'] = float(self.args.d) else: devFactor = 0.0 devFactorStr = tixiLib.getText( TIXIHandle, '/cpacs/toolspecific/vampZero/toolSettings/deviationAmplitude') if devFactorStr != None: devFactor = float(devFactorStr) self.config['deviationAmplitude'] = devFactor # read configuration for extended output self.config['extendedOutput'] = True extendedOutput = tixiLib.getText( TIXIHandle, '/cpacs/toolspecific/vampZero/toolSettings/extendedOutput') if extendedOutput in ('False', 'false', '0.0', '0.', '0'): self.config['extendedOutput'] = False # read sensitivity configuration self.config['calcSensitivities'] = False calcSensitivities = tixiLib.getText( TIXIHandle, '/cpacs/toolspecific/vampZero/toolSettings/calcSensitivities') if calcSensitivities in ('True', 'true', '1.0', '1.', '1'): self.config['calcSensitivities'] = True # read not converging behavior self.config['notConvergingAction'] = 'exit' not_converging_action = tixiLib.getText( TIXIHandle, '/cpacs/toolspecific/vampZero/toolSettings/notConvergingAction') if not_converging_action in ('exit', 'copyInput', 'errorXML'): self.config['notConvergingAction'] = not_converging_action tixiLib.closeXML(TIXIHandle)
def cpacsImport(self, path='.\\cpacs.xml'): ''' Looks for parameter.CPACSPath in CPACSFilse defined by Path Transfers Value is possible Input Values will be set to 'fix' ''' self.log.info('') self.log.info("##############################################################################") self.log.info("VAMPzero CPACS Import from %s" % path) self.log.info("trying to import and fix parameters") self.log.info("##############################################################################") TIXIHandle = openTIXI(path) modelUID = getText(TIXIHandle, '/cpacs/toolspecific/vampZero/aircraftModelUID') if modelUID is None: self.log.info("VAMPzero IMPORT: No modelUID specified in the toolspecific Block") try: modelUID = self.modelUID.getValue() self.log.info("VAMPzero IMPORT: loaded modelUID from VAMPzero") except AttributeError: modelUID = None self.log.info("VAMPzero IMPORT: could not load modelUID from VAMPzero") if modelUID is not None: TIGLHandle = openTIGL(TIXIHandle, modelUID) if TIGLHandle is not None: self.log.debug("VAMPzero IMPORT: Opened TIXI and TIGL in Component") else: TIGLHandle = None self.log.debug("VAMPzero IMPORT: Opened only TIXI in Component as no modelUID was specified") self.importer(path, TIXIHandle, TIGLHandle) self.log.info("VAMPzero IMPORT: done.") closeXML(TIXIHandle)
class Vampzero(object): ''' This class implements a convenience interface to setup a VAMPzero run. ''' def __init__(self, cpacsIn=None, cpacsOut=None, resultFile=None, resultOnErrorFile=None): ''' Initialize VAMPzero with standard properties. ''' if cpacsIn == None: cpacsIn = "./ToolInput/toolInput.xml" self.cpacsIn = cpacsIn if cpacsOut == None: cpacsOut = "./ToolOutput/toolOutput.xml" self.cpacsOut = cpacsOut if resultFile == None: resultFile = "./ReturnDirectory/VAMPzero.m" self.resultFile = resultFile if resultOnErrorFile == None: resultOnErrorFile = "./ReturnDirectory/ResultOnError.m" self.resultOnErrorFile = resultOnErrorFile self.args = None self.config = {} self.aircraft = aircraftLib.aircraft() self.initParser() def readConfig(self): ''' Read VAMPzeros configuration parameters. Command line arguments overwrite the configurations in the toolspecific part. ''' TIXIHandle = tixiLib.openTIXI(self.cpacsIn) if self.args.d != None: self.config['deviationAmplitude'] = float(self.args.d) else: devFactor = 0.0 devFactorStr = tixiLib.getText( TIXIHandle, '/cpacs/toolspecific/vampZero/toolSettings/deviationAmplitude') if devFactorStr != None: devFactor = float(devFactorStr) self.config['deviationAmplitude'] = devFactor # read configuration for extended output self.config['extendedOutput'] = True extendedOutput = tixiLib.getText( TIXIHandle, '/cpacs/toolspecific/vampZero/toolSettings/extendedOutput') if extendedOutput in ('False', 'false', '0.0', '0.', '0'): self.config['extendedOutput'] = False # read sensitivity configuration self.config['calcSensitivities'] = False calcSensitivities = tixiLib.getText( TIXIHandle, '/cpacs/toolspecific/vampZero/toolSettings/calcSensitivities') if calcSensitivities in ('True', 'true', '1.0', '1.', '1'): self.config['calcSensitivities'] = True # read not converging behavior self.config['notConvergingAction'] = 'exit' not_converging_action = tixiLib.getText( TIXIHandle, '/cpacs/toolspecific/vampZero/toolSettings/notConvergingAction') if not_converging_action in ('exit', 'copyInput', 'errorXML'): self.config['notConvergingAction'] = not_converging_action tixiLib.closeXML(TIXIHandle) def initParser(self): ''' Initializes the argument parser to process command line arguments. ''' #usage = "usage: %prog [options] arg1 arg2\n\ttype '%prog --help' for help" self.parser = argparse.ArgumentParser(prog='VAMPzero') self.parser.add_argument('-m', action='store_true', help='import Matlab') self.parser.add_argument('-d', default=None, help='calculate deviation') # self.parser.add_argument('--no_plots', action='store_false', help='deactivates plotting') def run(self, argv=None): ''' Runs VAMPzero. ''' if argv is None: argv = sys.argv try: generalLib.printHeader() print argv self.args = self.parser.parse_args() self.readConfig() ################################################################################################### ##VAMPzero Initialize ################################################################################################### self.aircraft.engine.sfcCR.calc = self.aircraft.engine.sfcCR.calcOverallEff self.setFixed() ################################################################################################### ##VAMPzero Imports ################################################################################################### if self.args.m: importMatlabLib.importMatlab(self.aircraft) else: guiLib.importGUI(self.aircraft, self.cpacsIn) tixiHandle = tixiLib.openTIXI(self.cpacsIn) hasModel = tixiLib.checkElement(tixiHandle, '/cpacs/vehicles/aircraft/model') if hasModel: self.aircraft.cpacsImport(self.cpacsIn) self.aircraft.atmosphere.hCR.setValueFix( self.aircraft.altCR.getValue()) self.aircraft.atmosphere.MaCR.setValueFix( self.aircraft.machCR.getValue()) self.calc() self.finish() self.setUIDs() self.exportToolspecific( ) # needs to be called after the last use of cpacsLib (otherwise all nodes not in the schema will be removed) generalLib.printFooter() return 0 except (argparse.ArgumentError), err: print >> sys.stderr, err self.parser.print_help() return 2 except (NotConvergingError), err: # write output to help with debugging exportLib.resultExport(self.aircraft, self.resultOnErrorFile, componentWise=True) if self.config['notConvergingAction'] in ('copyInput'): shutil.copyfile(self.cpacsIn, self.cpacsOut) TIXIHandle = tixiLib.openTIXI(self.cpacsOut) tixiLib.addText( TIXIHandle, '/cpacs/toolspecific/vampZero/toolSettings/exitCondition', 'NOT CONVERGED') tixiLib.saveXML(self.cpacsOut, TIXIHandle) tixiLib.closeXML(TIXIHandle) elif self.config['notConvergingAction'] in ('errorXML'): with open(self.cpacsOut, 'w') as outfile: outfile.write( '<cpacs><exitCondition>NOT CONVERGING</exitCondition></cpacs>' ) elif self.config['notConvergingAction'] in ('tryExportLastState'): self.finish() self.setUIDs() self.exportToolspecific() sys.exit() #@note: enter exit code here