示例#1
0
    def __init__(self,
                 inpParam=None,
                 outParam=None,
                 functionToCall=None,
                 findmin=0,
                 tolerance=1.0E-6,
                 maxLoops=400,
                 failValue=None):
        '''Initialize parameter properties
           
           @param inpParam: input parameter object (InputParam)
           @param outParam: output parameter object (OutputParam)
           @param functionToCall: function using InputParam to calc OutputParam (callable)
           @param findmin: findmin is a logic flag (1=minimize, 0=maximize) (int)
           @param tolerance: allowable error of OutputParam.val (float)
           @param maxLoops: maximum loops in root solver
           @param failValue: returned value if solution attempt fails, 
              (if not input use inpParam.minVal)
        '''
        self.inpParam = inpParam  #: InputParam object
        self.outParam = outParam  #: OutputParam object
        self.functionToCall = functionToCall  #: function using InputParam to calc OutputParam
        self.findmin = floatDammit(
            findmin)  #: flag to minimize or maximize OutputParam.val
        self.tolerance = floatDammit(
            tolerance)  #: allowable error of OutputParam.val
        self.maxLoops = intDammit(maxLoops)  #: maximum loops in root solver

        if failValue == None:
            failValue = inpParam.minVal
        self.failValue = failValue  #: returned value if solution attempt fails
示例#2
0
    def __init__(self,
                 name='a',
                 description='speed of sound',
                 units='ft/sec',
                 val=1.0,
                 loLimit=NEG_INF,
                 hiLimit=POS_INF):
        '''Initialize parameter properties
           
           @param name: simple name (str)
           @param description: long description (str)
           @param units:  physical units; Blank string if no units (str)
           @param val:  current numeric value (float)
           @param loLimit:  lower limit value (float)
           @param hiLimit:  upper limit value value (float)
        '''

        # if loLimit, hiLimit are reversed, correct them
        if loLimit > hiLimit:
            loLimit, hiLimit = hiLimit, loLimit

        self.name = name  #: simple name
        self.description = description  #: long description
        self.units = units  #: physical units; Blank string if no units
        self.val = floatDammit(val)  #: current numeric value
        self.loLimit = floatDammit(loLimit)  #: lower limit value
        self.hiLimit = floatDammit(hiLimit)  #: upper limit value
示例#3
0
 def __init__(self, inpParam=None, outParam=None, functionToCall=None,
     feasibleVal=0.0, tolerance=1.0E-6, maxLoops=40, failValue=None):
         
     '''Initialize parameter properties
        
        @param inpParam: input parameter object (InputParam)
        @param outParam: output parameter object (OutputParam)
        @param functionToCall: function using InputParam to calc OutputParam (callable)
        @param feasibleVal: feasible value that OutputParam Must have (float)
        @param tolerance: allowable error of OutputParam.val (float)
        @param maxLoops: maximum loops in root solver
        @param failValue: returned value if solution attempt fails, 
           (if not input use inpParam.minVal)
     '''
     self.inpParam = inpParam #: InputParam object
     self.outParam = outParam #: OutputParam object
     self.functionToCall = functionToCall #: function using InputParam to calc OutputParam
     self.feasibleVal = floatDammit(feasibleVal) #: feasable value of OutputParam.val
     self.tolerance = floatDammit(tolerance) #: allowable error of OutputParam.val
     self.maxLoops = intDammit(maxLoops) #: maximum loops in root solver
     
     if failValue==None:
         failValue = inpParam.minVal
     self.failValue = failValue #: returned value if solution attempt fails
     
     self.G = Goal(goalVal=feasibleVal, minX=inpParam.minVal, maxX=inpParam.maxVal, 
         funcOfX=self.feasibleFunc, tolerance=tolerance, maxLoops=maxLoops, failValue=failValue)
示例#4
0
    def __init__(self, name='a', description='speed of sound', units='ft/sec',
        val=1.0, minVal=0.0, maxVal=10.0, NSteps=10, stepVal=None, linear=1):
            
        '''Initialize parameter properties and calculate range list (rangeL)
           
           @param name: simple name (str)
           @param description: long description (str)
           @param units:  physical units; Blank string if no units (str)
           @param val:  current numeric value (float)
           @param minVal:  minimum value (float)
           @param maxVal:  maximum value (float)
           @param NSteps:  number of steps from minVal to maxVal in rangeL (int)
           @param stepVal:  if input, then step size from minVal to maxVal in rangeL (float)
           @param linear: linear/geometric flag for steps from minVal to maxVal (boolean or int)
        '''
        
        # if minVal, maxVal are reversed, correct them
        if minVal > maxVal:
            minVal, maxVal = maxVal, minVal
        
        self.name = name #: simple name
        self.description = description #: long description
        self.units = units #: physical units; Blank string if no units
        self.val = floatDammit(val) #: current numeric value
        self.savedVal = self.val #: temporary storage location for val
        self.InitialVal = self.val #: initial val (for possible reset)
        
        self.minVal = floatDammit(minVal) #: minimum value
        self.maxVal = floatDammit(maxVal) #: maximum value
        self.linear = intDammit(linear) #: linear/geometric flag for steps from minVal to maxVal
        
        if NSteps<1: NSteps=1
        
        if stepVal and linear: #use stepVal only if linear steps
            try:
                NSteps = int( (maxVal-minVal)/stepVal )
            except:
                stepVal = (maxVal-minVal)/float(NSteps)
        else:
            stepVal = (maxVal-minVal)/float(NSteps)
            
        self.NSteps = NSteps #: number of steps from minVal to maxVal in rangeL
        self.stepVal = stepVal #: if input, then step size from minVal to maxVal in rangeL
            
                
        if linear :
            self.buildLinearRange()
        else:
            try:
                self.buildGeometricRange()
                self.stepVal = None #: undefined if using geometric range
            except:
                # only annoy the user slightly with non-critical error
                print 'WARNING... Switched to linear range in parameters.InputParam for min/max=%g/%g'%(self.minVal,self.maxVal)
                self.buildLinearRange()

        # make scaleFactor for other modules to use (e.g. optimize)
        self.scaleFactor = (abs(self.minVal) + abs(self.maxVal)) / 2.0
示例#5
0
    def reCalc(self):
        '''calculate the value of inpParam.val that gives feasibleVal==outParam.val'''

        val, ierror = self.G()
        if ierror:
            self.inpParam.val = floatDammit(self.failValue)
        else:
            self.inpParam.val = val
示例#6
0
 def reCalc(self):
     '''calculate the value of inpParam.val that gives feasibleVal==outParam.val'''
     
     val, ierror = self.G()
     if ierror:
         self.inpParam.val = floatDammit(self.failValue)
     else:
         self.inpParam.val = val
示例#7
0
    def __init__(self,
                 inpParam=None,
                 outParam=None,
                 functionToCall=None,
                 feasibleVal=0.0,
                 tolerance=1.0E-6,
                 maxLoops=40,
                 failValue=None):
        '''Initialize parameter properties
           
           @param inpParam: input parameter object (InputParam)
           @param outParam: output parameter object (OutputParam)
           @param functionToCall: function using InputParam to calc OutputParam (callable)
           @param feasibleVal: feasible value that OutputParam Must have (float)
           @param tolerance: allowable error of OutputParam.val (float)
           @param maxLoops: maximum loops in root solver
           @param failValue: returned value if solution attempt fails, 
              (if not input use inpParam.minVal)
        '''
        self.inpParam = inpParam  #: InputParam object
        self.outParam = outParam  #: OutputParam object
        self.functionToCall = functionToCall  #: function using InputParam to calc OutputParam
        self.feasibleVal = floatDammit(
            feasibleVal)  #: feasable value of OutputParam.val
        self.tolerance = floatDammit(
            tolerance)  #: allowable error of OutputParam.val
        self.maxLoops = intDammit(maxLoops)  #: maximum loops in root solver

        if failValue == None:
            failValue = inpParam.minVal
        self.failValue = failValue  #: returned value if solution attempt fails

        self.G = Goal(goalVal=feasibleVal,
                      minX=inpParam.minVal,
                      maxX=inpParam.maxVal,
                      funcOfX=self.feasibleFunc,
                      tolerance=tolerance,
                      maxLoops=maxLoops,
                      failValue=failValue)
示例#8
0
 def __init__(self, name='a', description='speed of sound', units='ft/sec',
     val=1.0, loLimit=NEG_INF, hiLimit=POS_INF):
         
     '''Initialize parameter properties
        
        @param name: simple name (str)
        @param description: long description (str)
        @param units:  physical units; Blank string if no units (str)
        @param val:  current numeric value (float)
        @param loLimit:  lower limit value (float)
        @param hiLimit:  upper limit value value (float)
     '''
     
     # if loLimit, hiLimit are reversed, correct them
     if loLimit > hiLimit:
         loLimit, hiLimit = hiLimit, loLimit
     
     self.name = name #: simple name
     self.description = description #: long description
     self.units = units #: physical units; Blank string if no units
     self.val = floatDammit(val) #: current numeric value
     self.loLimit = floatDammit(loLimit) #: lower limit value
     self.hiLimit = floatDammit(hiLimit) #: upper limit value
示例#9
0
 def reCalc(self):
     '''calculate the value of inpParam.val that optimizes outParam.val
        Show non-convergence notification messages if applicable.
     '''
     
     val, fval, ierror, numFuncCalls = fminbound(self.optFunc, 
         self.inpParam.minVal, self.inpParam.maxVal, 
         args=(), xtol=self.tolerance, maxfun=self.maxLoops, full_output=1, disp=1)
     
     #print 'val, fval, ierror, numFuncCalls=',val, fval, ierror, numFuncCalls
     
     if ierror:
         self.inpParam.val = floatDammit(self.failValue)
     else:
         self.inpParam.val = val
示例#10
0
 def __init__(self, inpParam=None, outParam=None, functionToCall=None,
     findmin=0, tolerance=1.0E-6, maxLoops=400, failValue=None):
         
     '''Initialize parameter properties
        
        @param inpParam: input parameter object (InputParam)
        @param outParam: output parameter object (OutputParam)
        @param functionToCall: function using InputParam to calc OutputParam (callable)
        @param findmin: findmin is a logic flag (1=minimize, 0=maximize) (int)
        @param tolerance: allowable error of OutputParam.val (float)
        @param maxLoops: maximum loops in root solver
        @param failValue: returned value if solution attempt fails, 
           (if not input use inpParam.minVal)
     '''
     self.inpParam = inpParam #: InputParam object
     self.outParam = outParam #: OutputParam object
     self.functionToCall = functionToCall #: function using InputParam to calc OutputParam
     self.findmin = floatDammit(findmin) #: flag to minimize or maximize OutputParam.val
     self.tolerance = floatDammit(tolerance) #: allowable error of OutputParam.val
     self.maxLoops = intDammit(maxLoops) #: maximum loops in root solver
     
     if failValue==None:
         failValue = inpParam.minVal
     self.failValue = failValue #: returned value if solution attempt fails
示例#11
0
    def reCalc(self):
        '''calculate the value of inpParam.val that optimizes outParam.val
           Show non-convergence notification messages if applicable.
        '''

        val, fval, ierror, numFuncCalls = fminbound(self.optFunc,
                                                    self.inpParam.minVal,
                                                    self.inpParam.maxVal,
                                                    args=(),
                                                    xtol=self.tolerance,
                                                    maxfun=self.maxLoops,
                                                    full_output=1,
                                                    disp=1)

        #print 'val, fval, ierror, numFuncCalls=',val, fval, ierror, numFuncCalls

        if ierror:
            self.inpParam.val = floatDammit(self.failValue)
        else:
            self.inpParam.val = val
示例#12
0
    def __init__(self,
                 name='a',
                 description='speed of sound',
                 units='ft/sec',
                 val=1.0,
                 minVal=0.0,
                 maxVal=10.0,
                 NSteps=10,
                 stepVal=None,
                 linear=1):
        '''Initialize parameter properties and calculate range list (rangeL)
           
           @param name: simple name (str)
           @param description: long description (str)
           @param units:  physical units; Blank string if no units (str)
           @param val:  current numeric value (float)
           @param minVal:  minimum value (float)
           @param maxVal:  maximum value (float)
           @param NSteps:  number of steps from minVal to maxVal in rangeL (int)
           @param stepVal:  if input, then step size from minVal to maxVal in rangeL (float)
           @param linear: linear/geometric flag for steps from minVal to maxVal (boolean or int)
        '''

        # if minVal, maxVal are reversed, correct them
        if minVal > maxVal:
            minVal, maxVal = maxVal, minVal

        self.name = name  #: simple name
        self.description = description  #: long description
        self.units = units  #: physical units; Blank string if no units
        self.val = floatDammit(val)  #: current numeric value
        self.savedVal = self.val  #: temporary storage location for val
        self.InitialVal = self.val  #: initial val (for possible reset)

        self.minVal = floatDammit(minVal)  #: minimum value
        self.maxVal = floatDammit(maxVal)  #: maximum value
        self.linear = intDammit(
            linear)  #: linear/geometric flag for steps from minVal to maxVal

        if NSteps < 1: NSteps = 1

        if stepVal and linear:  #use stepVal only if linear steps
            try:
                NSteps = int((maxVal - minVal) / stepVal)
            except:
                stepVal = (maxVal - minVal) / float(NSteps)
        else:
            stepVal = (maxVal - minVal) / float(NSteps)

        self.NSteps = NSteps  #: number of steps from minVal to maxVal in rangeL
        self.stepVal = stepVal  #: if input, then step size from minVal to maxVal in rangeL

        if linear:
            self.buildLinearRange()
        else:
            try:
                self.buildGeometricRange()
                self.stepVal = None  #: undefined if using geometric range
            except:
                # only annoy the user slightly with non-critical error
                print 'WARNING... Switched to linear range in parameters.InputParam for min/max=%g/%g' % (
                    self.minVal, self.maxVal)
                self.buildLinearRange()

        # make scaleFactor for other modules to use (e.g. optimize)
        self.scaleFactor = (abs(self.minVal) + abs(self.maxVal)) / 2.0
示例#13
0
 def setDesignVar(self, dvStr, val):
     dv = self.desVarDict[dvStr]
     dv.val = floatDammit( val )