The following customization script creates calculations (Calculator components) for these equations and integrates them into the simulation process flow: # CREATE CALCULATOR COMPONENTS FOR ALL EQUATIONS: #---------------------------------------------------------------- --------------- # PREPARATIONS: # [make some short aliases for various constants] type = EsiTypes.REAL role = Variable.ROLE_PARAMETER imode = Variable.MODE_INPUT omode = Variable.MODE_OUTPUT calcMMName = "com.engineous.component.Calculator" # Initially this MonteCarlo component has random variables but no responses. # Get the random variables before creating responses so they can be cloned in # all of the Calculations created for the workflow: # [Note: Component also has an output: MonteCarlo Results. Must filter] inputsList = [] for var in component.getParameterList(): if var.getMode() == Variable.MODE_INOUT: inputsList.append(var) # [The API supplies a scratch Plan object which must be stored when done: component_api.initialize(component) plan = component_api.getMonteCarloPlan() #---------------------------------------------------------------- --------------- # READ THE EQUATIONS FROM THE FORMULAE FILE PARAMETER: from java.io import InputStreamReader from java.io import BufferedReader problemDef = VariableUtil.openFileVariableInputStream(data.get("Spring Formulae")) lineReader = BufferedReader(InputStreamReader(problemDef)) nresp = 0 while lineReader.ready(): # GET THE NEXT FORMULA: formula = lineReader.readLine().lstrip() if formula is None: break if formula == "" or formula.strip().find('#') == 0: continue # ADD THE RHS VAR OF THE FORMULA AS AN MCS RESPONSE: assert formula.find('=') > 1, "Not an assignment : " + formula respName = (formula.split('='))[0].strip() response = DtModelManager.createScalarVariable(respName,type,role,omode, None,None) component.addParameter(response) plan.addResponse(VariableReference(response)) # INSERT A CALCULATION FOR THIS FORMULA IN THE WORKFLOW: calcName = "Calculate " + respName calcComp = DtModelManager.createComponent(calcMMName,calcName) component.addComponent(calcComp) component.addControlFlow(DtModelManager.createControlFlow(None,ca lcComp)) component.addControlFlow(DtModelManager.createControlFlow(calcCom p,None)) # FINISH DEFINING THE CALCULATION FROM THE FORMULA: for randVar in inputsList: calcInput = randVar.clone() calcInput.setMode(imode) calcComp.addParameter(calcInput) component.addDataFlow(DtModelManager.createDataFlow(randVar,calcI nput)) calcOutput = response.clone() calcComp.addParameter(calcOutput) component.addDataFlow(DtModelManager.createDataFlow(calcOutput,re sponse)) calcComp.getProperty("expression").getValueObj().setValue(formula ) nresp += 1 lineReader.close() assert nresp > 0, "Customization file Spring Formulae was empty" # THE MCS PLAN IS NOT CONFIGURED UNTIL THIS CALL IS MADE: component_api.apply() The Monte Carlo script results are shown below. The script also gets the named outputs from the equations and creates
output parameters of those names, marking them as Note:
Since there are no dependencies between the equations,
it is easiest to construct a parallel simulation process flow.
|