Пример #1
0
def nodeToUQModel(name, node):
    '''
		This function converts a node model to a UQ model for UQ analysis.  This is temporary solution.
		The extra python calculations that are include in a node are not converted, just the simulation.
	'''
    uqModel = Model()
    uqModel.setName(name)
    uqModel.setRunType(Model.GATEWAY)  #Basically run through John's stuff
    keys = list(node.inVars.keys())
    typ = []  # Type for each input (Fixed or Variable)
    val = []  # Current value of inputs in the node
    min = []  # minimums for inputs
    max = []  # maximums for inputs
    default = []  # defaults for inputs
    for key in keys:  # key is input variable name, make lists
        #if node.inVars[key].uqVar:
        typ.append(Model.VARIABLE)
        #else:
        #    typ.append( Model.FIXED )
        val.append(node.inVars[key].value)
        min.append(node.inVars[key].min)
        max.append(node.inVars[key].max)
        default.append(node.inVars[key].default)
    # Set input values
    uqModel.setInputNames(['%s.%s' % (name, key) for key in keys])
    uqModel.setInputTypes(typ)
    uqModel.setInputMins(min)
    uqModel.setInputMaxs(max)
    uqModel.setInputDefaults(default)
    # Set output names and set all outputs as selected
    keys = list(node.outVars.keys())
    uqModel.setOutputNames(['%s.%s' % (name, key) for key in keys])
    uqModel.setSelectedOutputs(list(range(len(keys))))
    return uqModel
Пример #2
0
def flowsheetToUQModel(gr):
    '''
        This function converts a node model to a UQ model for UQ analysis.  This is temporary solution.
        The extra python calculations that are include in a node are not converted, just the simulation.
    '''
    uqModel = Model()
    uqModel.setName('Flowsheet')
    uqModel.setRunType(Model.GATEWAY)  #Basically run through John's stuff
    uqModel.setNamesIncludeNodes(True)
    keys = gr.input.compoundNames()
    names = []
    typ = []  # Type for each input (Fixed or Variable)
    val = []  # Current value of inputs in the node
    mins = []  # minimums for inputs
    maxs = []  # maximums for inputs
    dists = []
    default = []  # defaults for inputs
    flowsheetFixed = []
    gr.generateGlobalVariables()
    for key in keys:  # key is input variable name, make lists
        if not gr.input.get(key).con:
            names.append(key)
            typ.append(Model.VARIABLE)
            val.append(gr.input.get(key).value)
            mins.append(gr.input.get(key).min)
            maxs.append(gr.input.get(key).max)
            default.append(gr.input.get(key).default)
            dists.append(gr.input.get(key).dist)
            flowsheetFixed.append(False)
    # Set input values
    uqModel.setInputNames(names)
    uqModel.setInputTypes(typ)
    uqModel.setInputMins(mins)
    uqModel.setInputMaxs(maxs)
    uqModel.setInputDistributions(dists)
    uqModel.setInputDefaults(default)
    uqModel.setInputFlowsheetFixed(flowsheetFixed)
    # Set output names and set all outputs as selected
    keys = gr.output.compoundNames()
    uqModel.setOutputNames(keys)
    uqModel.setSelectedOutputs(list(range(len(keys))))
    return uqModel