Package parasol :: Module parasol_main
[hide private]
[frames] | no frames]

Source Code for Module parasol.parasol_main

   1  try: 
   2      import psyco 
   3      psyco.full() 
   4      print 'NOTICE... psyco "speed-up" module IS ENABLED!!!' 
   5  except: 
   6      print 'NOTICE... could NOT import psyco "speed-up" module' 
   7   
   8  from parameters import InputParam, OutputParam, FeasiblePair, MinMaxPair, POS_INF, NEG_INF  
   9   
  10   
  11  from math import * 
  12  import sys, os 
  13  import time 
  14  import HTML_supt 
  15   
  16  import LikeDict 
  17  import traceback 
  18  from cast import floatDammit, intDammit 
  19  from Summary import Summary 
  20  import cPickle as pickle 
  21   
  22   
  23  __author__ = "Charlie Taylor (charlietaylor@sourceforge.net)" 
  24  __version__ = " 1.2 " 
  25  __date__ = "Jan 1, 2009" 
  26  __copyright__ = "Copyright (c) 2009 Charlie Taylor" 
  27  __license__ = "BSD" 
  28   
29 -def getVersion():
30 return __version__
31 32 33 splash ='Parametric Solutions\n'+\ 34 'parasol v'+getVersion() + '\n'+\ 35 'contact: C. Taylor, charlietaylor@sourceforge.net\n' 36 37 splashText = '------------------------------------------------------------\n'+\ 38 splash+\ 39 '------------------------------------------------------------' 40 41 # ------ check for user options (-w to make word doc, -p to make power point) 42 from optparse import OptionParser 43 44 _parser = OptionParser() 45 _parser.add_option("-x", "--excel", 46 action="store_true", dest="excel", default=False, 47 help="create output in a Microsoft Excel document") 48 _parser.add_option("-w", "--word", 49 action="store_true", dest="word", default=False, 50 help="create output in a Microsoft Word document") 51 _parser.add_option("-p", "--ppt", 52 action="store_true", dest="ppt", default=False, 53 help="create output in a Microsoft Power Point document") 54 _parser.add_option("-q", "--quiet", 55 action="store_false", dest="show", default=True, 56 help="don't show Word, Excel or PowerPoint docs") 57 _parser.add_option("-o", "--open", 58 action="store_true", dest="open", default=False, 59 help="leave Microsoft Word, Excel or PowerPoint Open") 60 _parser.add_option("-i", "--isize", action="store", 61 type="string", dest="imageSize", default="m", 62 help="(vs,s,m,l,vl)image size in Word or PowerPoint") 63 _parser.add_option("-f", "--font", action="store", 64 type="string", dest="fontName", default="c", 65 help="font in Word (c=Courier, l=Lucida, v=Vera, o=OCR, t=type)") 66 67 # each ParametricSoln object has a reference to _userOptions 68 (_userOptions, _userArgs) = _parser.parse_args() 69
70 -def win32Warning(appName):
71 print '\n=============================================================' 72 print "WARNING WARNING WARNING WARNING WARNING WARNING WARNING" 73 print '=============================================================\n' 74 print " Could NOT start ",appName 75 print ' make sure that you have installed "Python for Windows Extension"' 76 print ' from: http://starship.python.net/crew/mhammond/win32/\n' 77 print ' for python version:',sys.version.split()[0] 78 print '=============================================================' 79 raw_input('Hit Return to Continue w/o '+appName)
80 81 if _userOptions.excel: 82 try: 83 import Excel_wrapper 84 except: 85 _userOptions.excel = False 86 win32Warning('Microsoft Excel') 87 88 if _userOptions.word: 89 try: 90 import Word_wrapper 91 except: 92 _userOptions.word = False 93 win32Warning('Microsoft Word') 94 95 if _userOptions.ppt: 96 try: 97 import PPT_wrapper 98 except: 99 _userOptions.ppt = False 100 win32Warning('Microsoft PowerPoint') 101 102 # ----------------- 103
104 -def headerStr( hstr, fillCh, L ):
105 l2 = (L - len(hstr) - 2) / 2 106 s = fillCh*l2 + ' ' + hstr + ' ' 107 return s + fillCh*(L-len(s))
108 109
110 -class ParametricSoln( object ):
111 '''a parametric solution object for running a parametric model''' 112 113 __firstParametricSoln = None #: use to keep track of 1st instance of ParametricSoln 114 115 __numPOVRenders = 0 #: count number of render commands 116
117 - def getVersion(self):
118 return getVersion()
119
120 - def __getitem__(self, name):
121 '''return the value of design or result variable with name''' 122 if self.hasDesignVar( name ): 123 dv = self.desVarDict[name] 124 return dv.val 125 elif self.hasResultVar( name ): 126 rv = self.resultVarDict[name] 127 return rv.val 128 else: 129 return None
130
131 - def __setitem__(self, name, val):
132 '''set the value of design or result variable with name''' 133 if self.hasDesignVar( name ): 134 self.setDesignVar(name, val) 135 elif self.hasResultVar( name ): 136 self.setResultVar(name, val) 137 else: 138 print 'ERROR in ParametricSoln.__setitem__, %s is not recognized'%name
139
140 - def __call__(self, *varNames):
141 '''return the values of design and result variables in varNames list''' 142 resultL = [] 143 for name in varNames: 144 145 if self.hasDesignVar( name ): 146 dv = self.desVarDict[name] 147 resultL.append( dv.val ) 148 149 if self.hasResultVar( name ): 150 rv = self.resultVarDict[name] 151 resultL.append( rv.val ) 152 153 if len(resultL)==1: 154 return resultL[0] 155 else: 156 return resultL
157 158
159 - def __init__(self, subtaskName="simple model", taskName='System Study', 160 controlRoutine=None, author="", constraintTolerance=0.001, 161 renderControlRoutine=None, probDesc=None):
162 163 if len(author)==0: 164 author = 'anon' 165 166 self.userOptions = _userOptions 167 168 self.probDesc = probDesc 169 170 self.author = author 171 self.taskName = taskName 172 self.constraintTolerance = constraintTolerance 173 174 self.subtaskName = subtaskName 175 self.desVarDict = LikeDict.LikeDict() #: dictionary of design Variables in system 176 self.resultVarDict = LikeDict.LikeDict() #: dict of result variables in system 177 178 self.feasibleVarList = [] #: list of Feasible Pairs 179 self.minmaxVarList = [] #: list of MinMax Pairs 180 181 self.constraintList = [] #: Optimize.optimize might initialize 182 self.controlRoutine = controlRoutine #: will be called to set component design params 183 184 self.optimizeHistoryL = [] #: holds any optimization summary info as [title, summStr] 185 186 self.renderControlRoutine = renderControlRoutine #: will be called to make POV drawing, returns List 187 188 self.NumEvaluations = 0 #: count number of times the evaluate method is called 189 190 # make text output file in case's subdirectory 191 scriptName = os.path.split( sys.argv[0] )[-1] 192 scriptPath = os.path.abspath(scriptName)[:] 193 newDirPath = os.path.dirname( scriptPath ) + '\\' + scriptName[:-3] + '\\' 194 print "scriptName:",scriptName 195 print "scriptPath:",scriptPath 196 print "newDirPath:",newDirPath 197 198 if not os.path.isdir( newDirPath ): 199 os.mkdir( newDirPath ) 200 print "created new directory",newDirPath 201 202 self.scriptName = scriptName 203 self.outputPath = newDirPath 204 self.summFileName = newDirPath + scriptName[:-2] + 'summary' 205 206 # if multiple ParametricSoln objects, use same summFile 207 if ParametricSoln.__firstParametricSoln: 208 self.summFile = ParametricSoln.__firstParametricSoln.summFile 209 else: 210 self.summFile = open( self.summFileName, 'w' ) 211 212 self.summFile.write(splashText + '\n\n' ) 213 self.summFile.write( taskName + '\n by: '+author+'\n') 214 self.summFile.write(' date: '+ time.strftime('%A %B %d, %Y')+'\n\n') 215 216 # if multiple ParametricSoln objects, use same summaryObj 217 if ParametricSoln.__firstParametricSoln: 218 self.summaryObj = ParametricSoln.__firstParametricSoln.summaryObj 219 else: 220 self.summaryObj = Summary(summaryTitle=subtaskName, subTitle='system') 221 222 # may not use it, but make Pickle file name just in case 223 self.pickleFileName = newDirPath + scriptName[:-2] + 'pickle' 224 225 # may not use it, but make POV file name just in case 226 self.POVFileName = newDirPath + scriptName[:-2] + 'pov' 227 228 # now make HTML file in original script's directory 229 self.htmlFileName = os.path.dirname( scriptPath ) + \ 230 '\\' + scriptName[:-2] + 'htm' 231 print 'HTML file:',self.htmlFileName 232 233 # if multiple ParametricSoln objects, use same htmlFile 234 if ParametricSoln.__firstParametricSoln: 235 self.htmlFile = ParametricSoln.__firstParametricSoln.htmlFile 236 else: 237 self.htmlFile = open( self.htmlFileName, 'w' ) 238 239 # ============ if probDesc is input =================== 240 # set any variables due to probDesc 241 if probDesc: 242 for a in ["subtaskName", "taskName", "author", 243 "constraintTolerance", "renderControlRoutine"]: 244 # if the probDesc attribute exists and has a value, assign it to self 245 if hasattr(probDesc,a) and getattr(probDesc,a): 246 setattr(self, a, getattr(probDesc,a) ) 247 248 for row in probDesc.desVarL: 249 self.addDesVars( row ) 250 251 for row in probDesc.resVarL: 252 self.addResultVars( row ) 253 254 for name, row in probDesc.resVarLimitD.items(): 255 print 'name, row=',name, row 256 self.setResultVariableLimits( name=name, loLimit=row[0], hiLimit=row[1]) 257 258 if probDesc.controlRoutine: 259 self.setControlRoutine(probDesc.controlRoutine) 260 261 262 self.htmlFile.write( HTML_supt.getHead(\ 263 title=self.taskName, task=self.subtaskName, author=self.author, 264 date=time.strftime('%B %d, %Y'), version='ParametricSoln v'+getVersion())) 265 # ============ end of probDesc input =================== 266 267 if self.userOptions.excel: 268 # if multiple ParametricSoln objects, use same xlDoc 269 if ParametricSoln.__firstParametricSoln: 270 self.xlDoc = ParametricSoln.__firstParametricSoln.xlDoc 271 else: 272 if self.userOptions.show: 273 self.xlDoc = Excel_wrapper.ExcelWrap(Visible=1) 274 else: 275 self.xlDoc = Excel_wrapper.ExcelWrap(Visible=0) 276 277 self.xlSheetD = {} # make sure no sheet name duplicates 278 279 self.xlDocName = os.path.dirname( scriptPath ) + \ 280 '\\' + scriptName[:-2] + 'xls' 281 282 self.xlSigText = self.subtaskName + '\rParametricSoln v'+getVersion() +\ 283 '\rby: '+self.author +'\r' + time.strftime('%B %d, %Y') +\ 284 '\r' + self.taskName 285 286 287 if self.userOptions.ppt: 288 # if multiple ParametricSoln objects, use same pptDoc 289 if ParametricSoln.__firstParametricSoln: 290 self.pptDoc = ParametricSoln.__firstParametricSoln.pptDoc 291 else: 292 self.pptDoc = PPT_wrapper.PPTwrap() 293 if self.userOptions.show: 294 self.pptDoc.show() 295 296 self.pptDocName = os.path.dirname( scriptPath ) + \ 297 '\\' + scriptName[:-2] + 'ppt' 298 299 pptText = self.subtaskName + '\rParametricSoln v'+getVersion() +\ 300 '\rby: '+self.author +'\r' + time.strftime('%B %d, %Y') 301 self.pptDoc.addTextSlide( text=pptText, title=self.taskName) 302 303 304 if self.userOptions.word: 305 # if multiple ParametricSoln objects, use same wordDoc 306 if ParametricSoln.__firstParametricSoln: 307 self.wordDoc = ParametricSoln.__firstParametricSoln.wordDoc 308 else: 309 self.wordDoc = Word_wrapper.WordWrap() 310 if self.userOptions.show: 311 self.wordDoc.show() 312 else: 313 self.wordDoc.setFastOptions() 314 315 self.wordDocName = os.path.dirname( scriptPath ) + \ 316 '\\' + scriptName[:-2] + 'doc' 317 318 self.wordDoc.addText(' ') 319 tableStr = [(self.taskName,),(self.subtaskName, 'ParametricSoln v'+getVersion()), 320 ('by: '+self.author, time.strftime('%B %d, %Y'))] 321 wordTable1 = self.wordDoc.addTable( tableStr , Range=self.wordDoc.selectCharacter(-2), fullWidth=1 ) 322 self.wordDoc.mergeRow( wordTable1, NRow=1) 323 #self.wordDoc.mergeRow( wordTable1, NRow=2) 324 self.wordDoc.setCellStyle(wordTable1,1,1, just='c',bold=True, fontSize=18, bgcolor='15') 325 self.wordDoc.setCellStyle(wordTable1,2,2, just='r') 326 self.wordDoc.setCellStyle(wordTable1,3,2, just='r') 327 self.wordDoc.selectCharacter(-1) 328 self.wordDoc.addText(' ') 329 330 fontName = "Courier New" 331 if self.userOptions.fontName.lower() == "t": 332 fontName = "Lucida Sans Typewriter" 333 if self.userOptions.fontName.lower() == "l": 334 fontName = "Lucida Console" 335 if self.userOptions.fontName.lower() == "v": 336 fontName = "Bitstream Vera Sans Mono" 337 if self.userOptions.fontName.lower() == "v": 338 fontName = "OCR A Extended" 339 340 self.tblstyl = self.wordDoc.createTableStyle( name='myStyle', 341 font=fontName,size=8, borders=1, bold=0, keepTogether=1) 342 343 self.wordDocImagefracPage=0.5 344 if self.userOptions.imageSize.lower() == 'vs': 345 self.wordDocImagefracPage=0.3 346 if self.userOptions.imageSize.lower() == 's': 347 self.wordDocImagefracPage=0.4 348 if self.userOptions.imageSize.lower() == 'm': 349 self.wordDocImagefracPage=0.5 350 if self.userOptions.imageSize.lower() == 'l': 351 self.wordDocImagefracPage=0.6 352 if self.userOptions.imageSize.lower() == 'vl': 353 self.wordDocImagefracPage=0.8 354 355 # set flag to indicate that self.close() was not yet called 356 self._close_was_called = 0 357 358 if ParametricSoln.__firstParametricSoln==None: 359 ParametricSoln.__firstParametricSoln = self
360
361 - def __del__(self):
362 if not self._close_was_called: 363 self.close()
364
365 - def close(self):
366 # set flag to show self.close() was called 367 print 'Closing all open files' 368 self._close_was_called = 1 369 370 self.htmlFile.write('<table class="mytable">') 371 self.htmlFile.write('<tr><td nowrap>'+ '<pre>' + splash + '</pre>' ) 372 self.htmlFile.write('</td><td width="90%">&nbsp;</td></tr></table>') 373 374 self.htmlFile.write( HTML_supt.getFooter() ) 375 self.htmlFile.close() 376 self.summFile.close() 377 378 if self.userOptions.excel: 379 if self.optimizeHistoryL: 380 rs = [[' ']] 381 for row in self.optimizeHistoryL: 382 title, summStr = row 383 def addText(text): 384 text=text.replace('\r','\n') 385 spL = text.split('\n') 386 for s in spL: 387 rs.append( [s] )
388 addText( title ) 389 addText( summStr ) 390 addText( '\n\n' ) 391 392 sheetName="Optimization" 393 if not self.xlSheetD.has_key(sheetName): 394 print 'making excel sheet',sheetName 395 self.xlSheetD[sheetName] = sheetName 396 self.xlDoc.makeDataSheet( rs, sheetName=sheetName, autoFit=0, rowFormatL=None, 397 textFont='Courier New', textFontSize=10) 398 399 self.xlDoc.xlApp.ActiveWorkbook.SaveAs( self.xlDocName ) 400 if not self.userOptions.open: 401 self.xlDoc.close() 402 403 if self.userOptions.ppt: 404 self.pptDoc.saveAs( self.pptDocName ) 405 if not self.userOptions.open: 406 self.pptDoc.Quit() 407 408 if self.userOptions.word: 409 tableStr = [(splash,),] 410 wordTable1 = self.wordDoc.addTable( tableStr, Range=self.wordDoc.selectCharacter(-2) , fullWidth=1) 411 wordTable1.Style = self.tblstyl 412 self.wordDoc.selectCharacter(-1) 413 self.wordDoc.addText(' ') 414 415 416 417 self.wordDoc.saveAs(self.wordDocName) 418 if not self.userOptions.open: 419 self.wordDoc.Quit() 420 print splashText
421
422 - def setDesignVar(self, dvStr, val):
423 dv = self.desVarDict[dvStr] 424 dv.val = floatDammit( val )
425 #print "in setDesignVar, setting ",dvStr,"to",val 426
427 - def getDesignVar(self, dvStr):
428 dv = self.desVarDict[dvStr] 429 return dv.val
430
431 - def getDesVars(self, *dvItems):
432 '''handle either single design var or list of design vars''' 433 result = [] 434 for dvStr in dvItems: 435 if type(dvStr)==type([1,2]): 436 for s in dvStr: 437 result.append( self.getDesignVar( s ) ) 438 else: 439 result.append( self.getDesignVar( dvStr ) ) 440 441 if len(result)==1: 442 return result[0] 443 else: 444 return result
445 446
447 - def getDesignVarAxisLabel(self, dvStr):
448 dv = self.desVarDict[dvStr] 449 return self.getAxisLabel( dvStr, dv )
450
451 - def getControlDesVarStr(self,key):
452 453 feasStr = '' 454 if self.hasFeasibleControlVar( key ): 455 fv = self.getFeasibleVarWithControlVar( key ) 456 feasStr = '* -----> ' +\ 457 ' (%s varies to make %s = %g %s)'%(key, fv.outParam.name, fv.feasibleVal, fv.outParam.units) 458 459 460 minmaxStr = '' 461 if self.hasMinMaxControlVar( key ): 462 mmv = self.getMinMaxVarWithControlVar( key ) 463 if mmv.findmin: 464 oStr = 'minimize' 465 else: 466 oStr = 'maximize' 467 minmaxStr = '* -----> ' +\ 468 ' (%s varies to %s %s)'%(key, oStr, mmv.outParam.name) 469 return feasStr, minmaxStr
470
471 - def getDesVarShortSummary(self, *omitList):
472 473 sList = [] 474 for key,dv in self.desVarDict.items(): 475 if key in omitList: 476 continue 477 478 feasStr, minmaxStr = self.getControlDesVarStr(key) 479 480 # do NOT show control design variables in desVar... show them in resultVars 481 if not (feasStr or minmaxStr): 482 sList.append( "%s = %g %s"%(key, dv.val, dv.units ) ) 483 484 return '\n'.join( sList )
485
486 - def getDesVarSummary(self, *omitList):
487 488 oList = [( 'NAME','VALUE','MINIMUM','MAXIMUM','DESCRIPTION','','')] 489 490 for key,dv in self.desVarDict.items(): 491 if key in omitList: 492 continue 493 desc = dv.description 494 if len(dv.units) > 0: 495 desc += ' (%s)'%dv.units 496 497 feasStr, minmaxStr = self.getControlDesVarStr(key) 498 499 # do NOT show control design variables in desVar... show them in resultVars 500 if not (feasStr or minmaxStr): 501 oList.append( (key,'%g'%dv.val,'%g'%dv.minVal,'%g'%dv.maxVal, desc, feasStr, minmaxStr ) ) 502 nmax = 1 503 vmax = 1 504 mmax = 1 505 Mmax = 1 506 dmax = 1 507 for (n,v,m,M,d,f,mms) in oList: 508 nmax = max( len(n), nmax ) 509 vmax = max( len(v), vmax ) 510 mmax = max( len(m), mmax ) 511 Mmax = max( len(M), Mmax ) 512 dmax = max( len(d), dmax ) 513 514 sList = [] 515 for (n,v,m,M,d,f,mms) in oList: 516 sList.append( ' %s %s %s %s %s '%(n.rjust(nmax),v.rjust(vmax),m.rjust(mmax), 517 M.rjust(Mmax), d.ljust(dmax))) 518 519 if len(f)>0: 520 sList.append( '%s %s '%(' '.rjust(nmax),f) ) 521 522 if len(mms)>0: 523 sList.append( '%s %s '%(' '.rjust(nmax),mms) ) 524 525 ast = '='*len(sList[0]) 526 head = headerStr( 'Design Variables', '=', len(sList[0]) ) 527 return head + '\n'+\ 528 '\n'.join( sList ) + '\n' + ast + '\n'
529
530 - def getHTMLDesVarSummary(self, *omitList):
531 #print 'self.desVarDict.keys()=',self.desVarDict.keys() 532 #print 'omitList=',omitList 533 if len(omitList) + len(self.feasibleVarList)>=len(self.desVarDict.keys()): 534 return '' 535 536 summary = '<table class="mytable"><th colspan="4" bgcolor="#CCCCCC">Design Variables (nominal values)</th>' +\ 537 '<tr><td><b>Name</b></td><td><b>Value</b></td><td><b>Units</b></td><td><b>Description</b></td></tr>' 538 539 for key,dv in self.desVarDict.items(): 540 if key in omitList: 541 continue 542 543 desc = dv.description 544 if len(dv.units) > 0: 545 desc += ' (%s)'%dv.units 546 547 feasStr, minmaxStr = self.getControlDesVarStr(key) 548 if feasStr or minmaxStr: 549 continue # do NOT show control design variables in desVar... show them in resultVars 550 #specStr = '<br><b>* -----&gt;<b>' 551 #desc += '<br>' + feasStr[8:] + minmaxStr[8:] 552 else: 553 specStr = '' 554 555 summary += '<tr><td align="left" valign="top">%10s</td><td align="right" valign="top">%12g%s</td><td nowrap align="left" valign="top">%s</td><td nowrap align="left" valign="top">%s</td></tr>\n'%\ 556 (key,dv.val,specStr,dv.units, desc ) 557 558 return summary + '</table>'
559
560 - def getHTMLResultVarSummary(self):
561 summary = '<table class="mytable"><th colspan="6" bgcolor="#CCCCCC">Result Variables </th>' +\ 562 '<tr><td><b>Name</b></td><td><b>Value</b></td><td><b>Units</b></td><td><b>Description</b></td><td><b>Low Limit</b></td><td><b>High Limit</b></td></tr>' 563 564 565 # make local list of effective result variables (includes design control vars) 566 resultVarL = [] #: list of result var objects (rv) including design control vars 567 # resultVarL includes desVars that are control variables, (minmax or feasible) 568 569 for key,dv in self.desVarDict.items(): 570 if self.hasMinMaxControlVar(key) or self.hasFeasibleControlVar(key): 571 # control varaibles in minmax or feasible change like result vars 572 resultVarL.append(['contVar',key,dv]) 573 for key,rv in self.resultVarDict.items(): 574 resultVarL.append(['resVar',key,rv]) 575 576 577 578 for vType,key,rv in resultVarL: 579 desc = rv.description 580 581 conVal1 = '---' 582 if vType=='contVar': # a control variable 583 conVal1 = '>%g'%rv.minVal 584 elif rv.loLimit>NEG_INF: 585 conVal1 = '>%g'%rv.loLimit 586 587 conVal2 = '---' 588 if vType=='contVar': # a control variable 589 conVal2 = '<%g'%rv.maxVal 590 elif rv.hiLimit<POS_INF: 591 conVal2 = '<%g'%rv.hiLimit 592 593 if len(rv.units) > 0: 594 desc += ' (%s)'%rv.units 595 596 feasStr, minmaxStr = self.getControlDesVarStr(key) 597 if feasStr or minmaxStr: 598 specStr = '<br><b>* -----&gt;<b>' 599 desc += '<br>' + feasStr[8:] + minmaxStr[8:] 600 else: 601 specStr = '' 602 603 summary += '<tr><td align="left">%10s</td><td align="right">%12g%s</td><td nowrap align="left">%s</td><td nowrap align="left">%s</td><td nowrap align="right">%s</td><td nowrap align="right">%s</td></tr>\n'%\ 604 (key,rv.val,specStr,rv.units, desc, conVal1, conVal2 ) 605 606 return summary + '</table>'
607
608 - def saveDesVarSummary(self):
609 print 'saving Design Variable Summary to',os.path.split(self.summFileName)[-1] 610 self.summFile.write( self.getDesVarSummary() + '\n' ) 611 612 self.htmlFile.write('<center><table border="1" class="mytable">') 613 self.htmlFile.write('<th>Design Variable Summary</th>') 614 615 self.htmlFile.write('<tr><td nowrap>') 616 self.htmlFile.write( self.getHTMLDesVarSummary() ) 617 self.htmlFile.write( self.getHTMLResultVarSummary() ) 618 619 self.htmlFile.write('</td></tr></table></center>')
620 621
622 - def setControlRoutine(self, controlRoutine):
623 self.controlRoutine = controlRoutine 624 # call it to make sure all is initialized 625 self.evaluate()
626
627 - def setRenderControlRoutine(self, renderControlRoutine):
628 self.renderControlRoutine = renderControlRoutine
629 630
631 - def hasDesignVar(self, dvStr):
632 return self.desVarDict.has_key(dvStr)
633
634 - def addDesignVariable(self, name="desvar", InitialVal=0.0, 635 minVal=-1.0E300, maxVal=1.0E300, NSteps=10, 636 units='', desc='', step=None, linear=1):
637 638 639 dv = InputParam(name=name, description=desc, units=units, 640 val=InitialVal, minVal=minVal, maxVal=maxVal, NSteps=NSteps, 641 stepVal=None, linear=linear) 642 643 self.desVarDict[name] = dv 644 645 try: 646 if dv.NSteps>100: 647 print 'WARNING... more than 100 steps in design variable',name 648 print ' a large number of steps will increase run times' 649 except: 650 pass
651
652 - def addDesVars(self, *dvLists):
653 #must be entered as lists of design variables 654 for dvList in dvLists: 655 #print dvList 656 name,InitialVal,minVal,maxVal,NSteps,units,desc = dvList 657 658 self.addDesignVariable( name=name, InitialVal=InitialVal, 659 minVal=minVal, maxVal=maxVal, NSteps=NSteps, 660 units=units, desc=desc, step=None, linear=1)
661
662 - def hasFeasibleResultVar(self, fvStr):
663 ans = 0 664 for fv in self.feasibleVarList: 665 if fvStr.lower() == fv.outParam.name.lower(): 666 ans = 1 667 return ans
668
669 - def hasFeasibleControlVar(self, fvCVStr):
670 ans = 0 671 for fv in self.feasibleVarList: 672 if fvCVStr.lower() == fv.inpParam.name.lower(): 673 ans = 1 674 return ans
675 676
677 - def getFeasibleVarWithResultVar(self, fvStr):
678 ans = None 679 for fv in self.feasibleVarList: 680 if fvStr.lower() == fv.outParam.name.lower(): 681 ans = fv 682 return ans
683 684
685 - def getFeasibleVarWithControlVar(self, fvCVStr):
686 ans = 0 687 for fv in self.feasibleVarList: 688 if fvCVStr.lower() == fv.inpParam.name.lower(): 689 ans = fv 690 return ans
691 692
693 - def makeFeasiblePair(self, outName="feasvar", feasibleVal=0.0, 694 inpName='inpvar', 695 tolerance=1.0E-6, maxLoops=40, failValue=None):
696 697 IP = self.desVarDict[inpName] 698 OP = self.resultVarDict[outName] 699 700 # need to set functionToCall later, in case controlRoutine changes 701 fv = FeasiblePair( inpParam=IP, outParam=OP, functionToCall=None, 702 feasibleVal=feasibleVal, tolerance=tolerance, maxLoops=maxLoops, failValue=failValue) 703 704 self.feasibleVarList.append( fv )
705 706 # make min/max routines 707
708 - def hasMinMaxVar(self, mmvStr):
709 ans = 0 710 for mmv in self.minmaxVarList: 711 if mmvStr.lower() == mmv.name.lower(): 712 ans = 1 713 return ans
714
715 - def hasMinMaxControlVar(self, mmvCVStr):
716 ans = 0 717 for mmv in self.minmaxVarList: 718 if mmvCVStr.lower() == mmv.inpParam.name.lower(): 719 ans = 1 720 return ans
721 722
723 - def getMinMaxVar(self, mmvStr):
724 ans = None 725 for mmv in self.minmaxVarList: 726 if mmvStr.lower() == mmv.outParam.name.lower(): 727 ans = mmv 728 return ans
729 730
731 - def getMinMaxVarWithControlVar(self, mmvCVStr):
732 ans = 0 733 for mmv in self.minmaxVarList: 734 if mmvCVStr.lower() == mmv.inpParam.name.lower(): 735 ans = mmv 736 return ans
737 738
739 - def makeMinMaxPair(self, outName="feasvar", findmin=0, 740 inpName='inpvar', 741 tolerance=1.0E-6, maxLoops=400, failValue=None):
742 743 IP = self.desVarDict[inpName] 744 OP = self.resultVarDict[outName] 745 746 # need to set functionToCall later, in case controlRoutine changes 747 mmv = MinMaxPair( inpParam=IP, outParam=OP, functionToCall=None, 748 findmin=findmin, tolerance=tolerance, maxLoops=maxLoops, failValue=failValue) 749 750 self.minmaxVarList.append( mmv )
751
752 - def setResultVariableLimits(self, name="resultvar", 753 loLimit=NEG_INF, hiLimit=POS_INF):
754 755 if self.hasResultVar(name): 756 rv = self.resultVarDict[name] 757 rv.loLimit = loLimit 758 rv.hiLimit = hiLimit
759 760
761 - def addResultVariable(self, name="resultvar", units='', desc='', 762 loLimit=NEG_INF, hiLimit=POS_INF):
763 764 rv = OutputParam(name=name, description=desc, units=units, 765 val=0.0, loLimit=loLimit, hiLimit=hiLimit) 766 767 self.resultVarDict[name] = rv
768
769 - def addResultVars(self, *rvLists):
770 for rvList in rvLists: 771 #print rvList 772 if len(rvList)==3: 773 name,units,desc = rvList 774 self.addResultVariable(name,units,desc) 775 else: 776 name,units,desc,loLimit, hiLimit = rvList 777 self.addResultVariable(name,units,desc,loLimit, hiLimit)
778
779 - def hasResultVar(self, rvStr):
780 return self.resultVarDict.has_key(rvStr)
781
782 - def setResultVar(self, rvStr, val):
783 try: 784 rv = self.resultVarDict[rvStr] 785 rv.val = val 786 except: 787 print 'Ignore ERROR in setResultVar... No result variable "%s"'%str(rvStr)
788
789 - def getResultVar(self, rvStr):
790 # accept either result variables OR native attributes 791 if self.resultVarDict.has_key(rvStr): 792 rv = self.resultVarDict[rvStr] 793 return rv.val 794 elif self.hasMinMaxControlVar(rvStr) or self.hasFeasibleControlVar(rvStr) : 795 dv = self.desVarDict[rvStr] 796 return dv.val 797 else: # as last ditch effort assume an attribute of self 798 return getattr(self, rvStr )
799
800 - def getAxisLabel(self, key, var):
801 # accept either result variables OR native attributes 802 if len(var.description)==0: 803 if len(var.units)==0: 804 label = var.name 805 else: 806 label = var.name + ', ' + var.units 807 else: 808 if len(var.units)==0: 809 label = var.description + ' (' + var.name + ')' 810 else: 811 label = var.description + ', ' + var.units + ' (' + var.name + ')' 812 return label
813
814 - def getResultVarAxisLabel(self, rvStr):
815 # accept either result variables OR native attributes 816 if self.resultVarDict.has_key(rvStr): 817 rv = self.resultVarDict[rvStr] 818 return self.getAxisLabel( rvStr, rv ) 819 820 elif self.hasMinMaxControlVar(rvStr) or self.hasFeasibleControlVar(rvStr) : 821 dv = self.desVarDict[rvStr] 822 return self.getAxisLabel( rvStr, dv ) 823 824 else: 825 return rvStr
826
827 - def getResultVarSummary(self):
828 829 # make local list of effective result variables (includes design control vars) 830 resultVarL = [] #: list of result var objects (rv) including design control vars 831 # resultVarL includes desVars that are control variables, (minmax or feasible) 832 833 for key,dv in self.desVarDict.items(): 834 if self.hasMinMaxControlVar(key) or self.hasFeasibleControlVar(key): 835 # control varaibles in minmax or feasible change like result vars 836 resultVarL.append(['contVar',key,dv]) 837 for key,rv in self.resultVarDict.items(): 838 resultVarL.append(['resVar',key,rv]) 839 840 841 oList = [( 'NAME','VALUE','DESCRIPTION','LOW-LIMIT','HIGH-LIMIT','','')] 842 843 for vType,key,rv in resultVarL: 844 desc = rv.description 845 846 conVal1 = '---' 847 if vType=='contVar': # a control variable 848 conVal1 = '>%g'%rv.minVal 849 elif rv.loLimit>NEG_INF: 850 conVal1 = '>%g'%rv.loLimit 851 852 conVal2 = '---' 853 if vType=='contVar': # a control variable 854 conVal2 = '<%g'%rv.maxVal 855 elif rv.hiLimit<POS_INF: 856 conVal2 = '<%g'%rv.hiLimit 857 858 if len(rv.units) > 0: 859 desc += ' (%s)'%rv.units 860 861 feasStr, minmaxStr = self.getControlDesVarStr(key) 862 863 oList.append(('%s'%key,'%g'%rv.val, '%s'%desc, '%s'%conVal1, '%s'%conVal2, feasStr, minmaxStr )) 864 865 nmax = 1 866 vmax = 1 867 dmax = 1 868 cmax = 1 869 lmax = 1 870 for (n,v,d,c,l,f,mms) in oList: 871 nmax = max( len(n), nmax ) 872 vmax = max( len(v), vmax ) 873 dmax = max( len(d), dmax ) 874 cmax = max( len(c), cmax ) 875 lmax = max( len(l), lmax ) 876 877 sList = [] 878 for (n,v,d,c,l,f,mms) in oList: 879 sList.append( ' %s %s %s %s %s '%(n.rjust(nmax),v.rjust(vmax),d.ljust(dmax), 880 c.rjust(cmax),l.rjust(lmax))) 881 882 883 if len(f)>0: 884 sList.append( '%s %s '%(' '.rjust(nmax),f) ) 885 886 if len(mms)>0: 887 sList.append( '%s %s '%(' '.rjust(nmax),mms) ) 888 889 890 891 ast = '='*len(sList[0]) 892 head = headerStr( 'Result Variables', '=', len(sList[0]) ) 893 return head + '\n'+\ 894 '\n'.join( sList ) + '\n' + ast + '\n'
895
896 - def saveResultVarSummary(self):
897 print 'saving Result Variable Summary to',os.path.split(self.summFileName)[-1] 898 self.summFile.write( self.getResultVarSummary() + '\n' )
899
900 - def violatesResultConstraint(self):
901 vioList = [] 902 903 for key,rv in self.resultVarDict.items(): 904 # only handle inequality constraints, 905 # equality constraints handled by feasibility variables 906 907 # ignore violations in the nth decimal place 908 cMult = 1.0 + abs(self.constraintTolerance) 909 910 if rv.loLimit > rv.val*cMult: 911 vioList.append( key + ' < ' + str( rv.loLimit ) ) 912 if rv.hiLimit < rv.val/cMult: 913 vioList.append( key + ' > ' + str( rv.hiLimit ) ) 914 915 # now make sure no feasibility variables are violated 916 for fv in self.feasibleVarList: 917 rv = self.resultVarDict[fv.outParam.name] 918 # ignore violations in the 4th decimal place 919 epsilon = self.constraintTolerance * max(abs(rv.val), abs(fv.feasibleVal)) 920 921 if abs(rv.val-fv.feasibleVal) > epsilon: 922 vioList.append( rv.name + ' != ' + str( fv.feasibleVal ) ) 923 924 return vioList
925
926 - def firstEvaluateIfReqd(self):
927 if self.NumEvaluations==0: 928 self.evaluate()
929
930 - def evaluate(self):
931 932 self.NumEvaluations += 1 #: increment counter for each evaluate call 933 934 def paramCallBack(): 935 '''specialty parameter callback (feasible and minmax)''' 936 self.controlRoutine(self)
937 938 # do minmax params first 939 if len( self.minmaxVarList ) > 0: 940 for mmv in self.minmaxVarList: 941 mmv.functionToCall = paramCallBack 942 mmv.reCalc() # sets inpParam.val 943 944 # now do feasible params 945 if len( self.feasibleVarList ) > 0: 946 for fv in self.feasibleVarList: 947 fv.functionToCall = paramCallBack 948 fv.reCalc() # sets inpParam.val 949 950 # when done with "special" inputs, do final call to control routine 951 self.controlRoutine(self) # call control routine 952
953 - def reCalc(self): # why a synonym for evaluate? beats me.
954 self.evaluate() 955
956 - def addAssumption(self, label='generic param'):
957 self.summaryObj.assumptions.append( label )
958
959 - def addInput(self, label='generic param', value=0.0, units='xxx', format='%g'):
960 self.summaryObj.inputs.append( [label, value, units, format] )
961
962 - def addOutput(self, label='generic param', value=0.0, units='xxx', format='%g'):
963 self.summaryObj.outputs.append( [label, value, units, format] )
964
965 - def getAssumptions(self):
966 assumpL = self.summaryObj.getSummAssumptions() 967 assumpL.extend(self.summaryObj.getSummInputs()) 968 assumpL.extend(self.summaryObj.getSummOutputs()) 969 970 if assumpL: 971 return '\n' + '\n'.join(assumpL) 972 else: 973 return ''
974
975 - def getSummary(self):
976 return '''ParametricSoln: %s 977 '''%(self.subtaskName,) + self.getAssumptions()
978
979 - def saveSummary(self):
980 print 'saving Summary to',os.path.split(self.summFileName)[-1] 981 self.summFile.write( self.getSummary() + '\n' )
982
983 - def getShortSummary(self):
984 summary = self.getSummary() 985 986 return summary + '\n'
987
988 - def getShortHTMLSummary(self):
989 990 lastType = '' 991 summary = ['<center><table class="mytable">', 992 '<th colspan="4" bgcolor="#CCCCCC">Summary </th>'] 993 994 if self.getAssumptions(): 995 summary.append('<tr><td colspan="4"><hr></td><tr>') 996 assumpL = self.summaryObj.getSummAssumptions() 997 assumpL.extend(self.summaryObj.getSummInputs()) 998 assumpL.extend(self.summaryObj.getSummOutputs()) 999 for assump in assumpL: 1000 summary.append('<tr><td colspan="4">%s</td><tr>'%(str(assump),)) 1001 1002 summary.append('</table></center>') 1003 return '\n'.join( summary )
1004 1005 1006
1007 - def saveShortSummary(self):
1008 print 'saving Short Summary to',os.path.split(self.summFileName)[-1] 1009 self.summFile.write( self.getShortSummary() + '\n' ) 1010 1011 print 'saving Short Summary to',os.path.split(self.htmlFileName)[-1] 1012 self.htmlFile.write( self.getShortHTMLSummary() + '<br>\n' ) 1013 1014 if self.userOptions.excel: 1015 xlText = self.getShortSummary() 1016 text=xlText.replace('\r','\n') 1017 spL = text.split('\n') 1018 rs = [['Short Summary ']] 1019 for s in spL: 1020 eqL = s.split('=') 1021 if len( eqL )==2: 1022 #rs.append( [eqL[0],"'=",eqL[1]] ) 1023 if len( eqL[1].split() )>1: 1024 rs.append( [eqL[0],"'=", eqL[1].split()[0], ' '.join( eqL[1].split()[1:]) ] ) 1025 else: 1026 rs.append( [eqL[0],"'=", eqL[1] ] ) 1027 else: 1028 rs.append( [s] ) 1029 1030 sheetName="ShortSummary" 1031 if not self.xlSheetD.has_key(sheetName): 1032 print 'making sheet',sheetName 1033 self.xlSheetD[sheetName] = sheetName 1034 self.xlDoc.makeDataSheet( rs, sheetName=sheetName, autoFit=0, rowFormatL=None) 1035 1036 if self.userOptions.ppt: 1037 pptText = self.getShortSummary() 1038 self.pptDoc.addTextSlide( text=pptText.replace('\n','\r'), 1039 title='Summary',textFont='Courier New', textFontSize=14, 1040 noBullets=1) 1041 1042 if self.userOptions.word: 1043 tableStr = [(' Summary ',),(' ',)] 1044 wordTable1 = self.wordDoc.addTable( tableStr, Range=self.wordDoc.selectCharacter(-2) ) 1045 wordTable1.Style = self.tblstyl 1046 self.wordDoc.setCellStyle(wordTable1,1,1, just='c',bold=True, 1047 fontName='Arial', fontSize=14, bgcolor='15') 1048 self.wordDoc.setCellStyle( wordTable1, 2, 1, 1049 text= self.getShortSummary() ) 1050 self.wordDoc.selectCharacter(-1) 1051 self.wordDoc.addText(' ')
1052 1053 1054
1055 - def getFullSummary(self):
1056 1057 self.saveDesVarSummary() 1058 self.saveResultVarSummary() 1059 summary = '\n\n' \ 1060 '\n======================================' +\ 1061 '\n==========FULL SYSTEM SUMMARY=========' +\ 1062 '\n======================================\n' +\ 1063 self.getSummary() 1064 1065 return summary
1066 1067
1068 - def getFullHTMLSummary(self):
1069 1070 if self.getAssumptions(): 1071 summary = [self.summaryObj.getItemHTMLSummary()] 1072 else: 1073 summary = [] 1074 1075 1076 return ''.join(summary)
1077 1078
1079 - def saveFullSummary(self):
1080 print 'saving Full Summary to',os.path.split(self.summFileName)[-1] 1081 self.summFile.write( self.getFullSummary() + '\n' ) 1082 1083 print 'saving Full Summary to',os.path.split(self.htmlFileName)[-1] 1084 self.htmlFile.write( self.getFullHTMLSummary() + '<br>\n' )
1085 1086 1087
1088 - def saveComment(self, comment=''):
1089 print 'saving comment to file' 1090 1091 sOut = [] 1092 sOut.append('========================================') 1093 sOut.append( comment ) 1094 sOut.append('========================================') 1095 self.summFile.write( '\n'.join( sOut ) ) 1096 1097 sOut = [] 1098 sOut.append('<center><table class="mytable" width="680">') 1099 sOut.append( '<tr><td align="left">%s'%comment ) 1100 sOut.append( '</td></tr>' ) 1101 sOut.append('</table></center>') 1102 self.htmlFile.write( '\n'.join( sOut ) )
1103
1104 - def putImageInPPT( self, filename, title):
1105 print 'saving Image to',os.path.split(self.pptDocName)[-1] 1106 try: 1107 self.pptDoc.addImageSlide( imgFile=filename, title=title.replace('\n','\r')) 1108 except: 1109 print "ERROR... FAILED to put image in PowerPoint file" 1110 print traceback.print_exc()
1111 1112
1113 - def putImageInWord( self, filename):
1114 print 'saving Image to',os.path.split(self.wordDocName)[-1] 1115 tableStr = [(' ',),(' ',)] 1116 wordTable1 = self.wordDoc.addTable( tableStr, Range=self.wordDoc.selectCharacter(-2) ) 1117 wordTable1.Style = self.tblstyl 1118 self.wordDoc.addImage(filename, Range=wordTable1.Cell(1,1).Range, 1119 fracPage=self.wordDocImagefracPage ) 1120 self.wordDoc.setCellStyle( wordTable1, 1, 1, just='c') 1121 self.wordDoc.setCellStyle( wordTable1, 2, 1, text= self.getDesVarSummary() + self.getResultVarSummary() ) 1122 1123 self.wordDoc.selectCharacter(-1) 1124 self.wordDoc.addText(' ')
1125 1126
1127 - def render(self, view="front", ortho=0, width=480, height=360, makeHTML=1, 1128 clockX=None, clockY=None, clockZ=None, 1129 background="Black", viewMargin=1.06, lookAtOffset=None):
1130 if 1:#try: 1131 1132 ParametricSoln.__numPOVRenders += 1 1133 1134 if clockY or clockX or clockZ: 1135 filePrefix = '_render%i_%s_%s_%s.png'%(ParametricSoln.__numPOVRenders, 1136 str(clockX),str(clockY),str(clockZ)) 1137 else: 1138 filePrefix = '_render%i_%s_%i.png'%(ParametricSoln.__numPOVRenders,view,ortho) 1139 1140 print 'POV file:',self.POVFileName[:-4] + filePrefix 1141 1142 import POV_Scene, POV_Items 1143 scene = POV_Scene.POV_Scene(filePrefix=self.POVFileName[:-4] + filePrefix, ambient=0.3, 1144 background=background, viewMargin=viewMargin, lookAtOffset=lookAtOffset) 1145 povItemL = self.renderControlRoutine(self) 1146 #scene.addLight( [-10,-10,-20]) 1147 #scene.addLight( [10,10,0]) 1148 1149 scene.addItem( POV_Items.DeclaredItem(name='System', itemList=povItemL ) ) 1150 1151 scene.write(view=view, ortho=ortho, clockX=clockX, clockY=clockY, clockZ=clockZ) 1152 1153 if clockY or clockX or clockZ: 1154 pngFile = self.outputPath + self.scriptName[:-3] + '_render%i_%s_%s_%s.png'%(ParametricSoln.__numPOVRenders, 1155 str(clockX),str(clockY),str(clockZ)) 1156 else: 1157 pngFile = self.outputPath + self.scriptName[:-3] + '_render%i_%s_%i.png'%(ParametricSoln.__numPOVRenders, 1158 view,ortho) 1159 1160 scene.render( width=width, height=height, pngFile=pngFile ) 1161 1162 1163 if makeHTML: 1164 self.htmlFile.write('<center><table border="1" class="mytable"><tr><td>') 1165 #self.htmlFile.write( '<img src="file:///%s">'%(pngFile,) ) 1166 htmlPath = './%s/%s'%(self.scriptName[:-3],os.path.split(pngFile)[-1]) 1167 self.htmlFile.write( '<img src="%s">'%(htmlPath,) ) 1168 1169 self.htmlFile.write('</td></tr><tr><td nowrap>') 1170 self.htmlFile.write( self.getHTMLDesVarSummary() ) 1171 self.htmlFile.write('</td></tr></table></center>') 1172 1173 if self.userOptions.ppt: 1174 self.putImageInPPT( pngFile, self.subtaskName) 1175 1176 if self.userOptions.word: 1177 self.putImageInWord( pngFile ) 1178 1179 else:#except: 1180 print "WARNING... render routine FAILED."
1181
1182 - def pickleParametricSoln(self): # pickle all of the internal variables
1183 1184 itemL = [] 1185 1186 # now save ParametricSoln object 1187 print 'pickling object', self.__class__.__name__ 1188 itemD = {} 1189 itemD['className'] = self.__class__.__name__ 1190 for key,val in self.__dict__.items(): 1191 if type(val) in [type(1), type(1.1), type('s')]: # eliminated list type 1192 #print key,val 1193 itemD[key]=val 1194 1195 # save result and design variables 1196 for key,rv in self.resultVarDict.items(): 1197 itemD[key] = rv.val 1198 1199 1200 for key,dv in self.desVarDict.items(): 1201 itemD[key] = dv.val 1202 itemD[key+'_units'] = dv.units 1203 itemD[key+'_desc'] = dv.description 1204 1205 feasStr = '' 1206 if self.hasFeasibleControlVar( key ): 1207 fv = self.getFeasibleVarWithControlVar( key ) 1208 feasStr = '* -----> ' +\ 1209 ' (%s varies to make %s = %g %s)'%(key, fv.outParam.name, fv.feasibleVal, fv.outParam.units) 1210 itemD[key+'_feas'] = feasStr 1211 1212 1213 minmaxStr = '' 1214 if self.hasMinMaxControlVar( key ): 1215 mmv = self.getMinMaxVarWithControlVar( key ) 1216 if mmv.findmin: 1217 oStr = 'minimize' 1218 else: 1219 oStr = 'maximize' 1220 minmaxStr = '* -----> ' +\ 1221 ' (%s varies to %s %s)'%(key, oStr, mmv.outParam.name) 1222 itemD[key+'_minmax'] = minmaxStr 1223 1224 1225 # save ParametricSoln dictionary to List 1226 itemL.append( itemD ) 1227 1228 print 'Saving to Pickle file:',self.pickleFileName 1229 1230 fOut = file(self.pickleFileName, 'w') 1231 pickle.dump( itemL, fOut ) 1232 fOut.close() 1233 1234 1235 if __name__ == "__main__": #self test 1236 #import Plots 1237 #from Optimize import optimize 1238
1239 - def test_case():
1240 def myControlRoutine(PS): 1241 a,b = PS.getDesVars("a","b") 1242 1243 c = a * b 1244 1245 PS.setResultVar("c", c ) 1246 PS.setResultVar("sysMass", c*2. ) 1247 PS.setResultVar("sysVolume", c*20. )
1248 1249 1250 PS = ParametricSoln(author="C Taylor", subtaskName="simple system", 1251 controlRoutine=myControlRoutine, renderControlRoutine=None) 1252 1253 PS.addDesVars( 1254 ["a",2.0, 1.0, 10.0, 10, 'sec', 'First Number'], 1255 ["b",6.0, 0.0, 20.0, 10, 'ft', 'Second Number'] 1256 ) 1257 1258 PS.addResultVariable( name="c", units='ft-sec', desc='a * b',loLimit=1.0, hiLimit=10.0) 1259 1260 PS.addResultVars( 1261 ["sysMass", "lbm", "Total System Mass"], 1262 ["sysVolume", "cuin", "Total System Volume"] 1263 ) 1264 1265 PS.makeFeasiblePair( outName="sysMass", feasibleVal=50., inpName='b') 1266 1267 1268 print 1269 PS.evaluate() 1270 #PS.saveShortSummary() 1271 #PS.saveSummary() 1272 1273 #PS.saveDesVarSummary() 1274 #PS.saveResultVarSummary() 1275 1276 PS.saveFullSummary() 1277 1278 print PS.getShortSummary() 1279 #print Hetank.getSummary() 1280 1281 #PS.render() 1282 #optimize(PS, figureOfMerit="mass_lbm", desVars=["PHe"]) 1283 print PS.getShortSummary() 1284 #Plots.make2DPlot(PS, sysParam="mass_lbm", desVar="PHe") 1285 print 1286 print 'vioList' 1287 print PS.violatesResultConstraint() 1288 1289 PS.close() 1290 1291 if 1: 1292 test_case() 1293 else: 1294 import hotshot, hotshot.stats 1295 prof = hotshot.Profile("test_case.prof") 1296 prof.runcall(test_case) 1297 prof.close() 1298 1299 stats = hotshot.stats.load("test_case.prof") 1300 stats.strip_dirs() 1301 stats.sort_stats('time', 'calls') 1302 stats.print_stats(60) 1303