use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class MathOverrides method verifyExpression.
/**
* Insert the method's description here.
* Creation date: (9/22/2005 3:24:36 PM)
*/
private void verifyExpression(Constant value, boolean checkScan) throws ExpressionBindingException {
Expression exp = value.getExpression();
String[] symbols = exp.getSymbols();
MathDescription mathDescription = getSimulation().getMathDescription();
exp.bindExpression(mathDescription);
if (symbols != null) {
for (int i = 0; i < symbols.length; i++) {
//
// expression must be a function of another Simulation parameter
//
Variable variable = mathDescription.getVariable(symbols[i]);
if (!(variable != null && variable instanceof Constant)) {
throw new ExpressionBindingException("identifier " + symbols[i] + " is not a constant. " + "Parameter overrides should only refer to constants.");
}
if (checkScan && isScan(symbols[i])) {
throw new ExpressionBindingException("Parameter overrides cannot depend on another scanned parameter " + symbols[i]);
}
//
if (symbols[i].equals(value.getName())) {
throw new ExpressionBindingException("Parameter overrides can not be recursive definition, can't use identifier " + value.getName() + " in expression for " + value.getName());
}
}
}
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class MathOverrides method gatherIssues.
/**
* This method was created in VisualAge.
* @return boolean
*/
public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
MathDescription mathDescription = getSimulation().getMathDescription();
//
// get list of names of constants in this math
//
Enumeration<Constant> enumeration = mathDescription.getConstants();
java.util.HashSet<String> mathDescriptionHash = new java.util.HashSet<String>();
while (enumeration.hasMoreElements()) {
Constant constant = enumeration.nextElement();
mathDescriptionHash.add(constant.getName());
}
//
// for any elements in this MathOverrides but not in the new MathDescription, add an "error" issue
//
Enumeration<String> mathOverrideNamesEnum = getOverridesHash().keys();
while (mathOverrideNamesEnum.hasMoreElements()) {
String name = mathOverrideNamesEnum.nextElement();
if (!mathDescriptionHash.contains(name)) {
Issue issue = new Issue(getSimulation(), issueContext, IssueCategory.Simulation_Override_NotFound, VCellErrorMessages.getErrorMessage(VCellErrorMessages.SIMULATION_OVERRIDE_NOTFOUND, name, getSimulation().getName()), Issue.SEVERITY_ERROR);
issueList.add(issue);
}
Variable var = mathDescription.getVariable(name);
if (getSimulation().getSimulationOwner() != null) {
Issue issue = getSimulation().getSimulationOwner().gatherIssueForMathOverride(issueContext, getSimulation(), name);
if (issue != null) {
issueList.add(issue);
}
}
}
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class OutputFunctionContext method propertyChange.
public void propertyChange(java.beans.PropertyChangeEvent event) {
if (event.getSource() == simulationOwner && event.getPropertyName().equals("mathDescription")) {
rebindAll();
}
if (event.getPropertyName().equals("geometry")) {
Geometry oldGeometry = (Geometry) event.getOldValue();
Geometry newGeometry = (Geometry) event.getNewValue();
// changing from ode to pde
if (oldGeometry != null && oldGeometry.getDimension() == 0 && newGeometry.getDimension() > 0) {
ArrayList<AnnotatedFunction> newFuncList = new ArrayList<AnnotatedFunction>();
for (AnnotatedFunction function : outputFunctionsList) {
try {
Expression newexp = new Expression(function.getExpression());
// making sure that output function is not direct function of constant.
newexp.bindExpression(this);
// here use math description as symbol table because we allow
// new expression itself to be function of constant.
MathDescription mathDescription = getSimulationOwner().getMathDescription();
newexp = MathUtilities.substituteFunctions(newexp, mathDescription).flatten();
VariableType newFuncType = VariableType.VOLUME;
String[] symbols = newexp.getSymbols();
if (symbols != null) {
// figure out the function type
VariableType[] varTypes = new VariableType[symbols.length];
for (int i = 0; i < symbols.length; i++) {
Variable var = mathDescription.getVariable(symbols[i]);
varTypes[i] = VariableType.getVariableType(var);
}
// check with flattened expression to find out the variable type of the new expression
Function flattenedFunction = new Function(function.getName(), newexp, function.getDomain());
newFuncType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, getSimulationOwner().getMathDescription(), symbols, varTypes, true);
}
AnnotatedFunction newFunc = new AnnotatedFunction(function.getName(), function.getExpression(), function.getDomain(), "", newFuncType, FunctionCategory.OUTPUTFUNCTION);
newFuncList.add(newFunc);
newFunc.bind(this);
} catch (ExpressionException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
} catch (InconsistentDomainException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
try {
setOutputFunctions0(newFuncList);
} catch (PropertyVetoException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
}
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class SimulationSymbolTable method getLocalConstant.
/**
* Insert the method's description here.
* Creation date: (6/6/2001 7:52:15 PM)
* @return cbit.vcell.math.Function
* @param functionName java.lang.String
*/
private Constant getLocalConstant(Constant referenceConstant) throws ExpressionException {
if (localVariableHash == null) {
localVariableHash = new HashMap<String, Variable>();
}
Variable var = localVariableHash.get(referenceConstant.getName());
if (var instanceof Constant) {
Constant localConstant = (Constant) var;
//
// make sure expression for localConstant is still up to date with MathOverrides table
//
Expression exp = simulation.getMathOverrides().getActualExpression(referenceConstant.getName(), index);
if (exp.compareEqual(localConstant.getExpression())) {
// localConstant.bind(this); // update bindings to latest mathOverrides
return localConstant;
} else {
//
// MathOverride's Expression changed for this Constant, remove and create new one
//
localVariableHash.remove(localConstant.getName());
}
} else if (var != null) {
throw new RuntimeException("Variable " + var + " expected to be a Constant");
}
//
// if local Constant not found, create new one, bind it to the Simulation (which ensures MathOverrides), and add to list
//
String name = referenceConstant.getName();
Constant newLocalConstant = new Constant(name, simulation.getMathOverrides().getActualExpression(name, index));
// newLocalConstant.bind(this);
localVariableHash.put(newLocalConstant.getName(), newLocalConstant);
return newLocalConstant;
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class SimulationSymbolTable method getLocalFunction.
/**
* Insert the method's description here.
* Creation date: (6/6/2001 7:52:15 PM)
* @return cbit.vcell.math.Function
* @param functionName java.lang.String
*/
private Function getLocalFunction(Function referenceFunction) throws ExpressionException {
if (localVariableHash == null) {
localVariableHash = new HashMap<String, Variable>();
}
Variable var = localVariableHash.get(referenceFunction.getName());
if (var instanceof Function) {
Function localFunction = (Function) var;
if (localFunction.compareEqual(referenceFunction)) {
// localFunction.bind(this); // update bindings to latest mathOverrides
return localFunction;
}
} else if (var != null) {
throw new RuntimeException("Variable " + var + " expected to be a Function");
}
//
// if local Function not found, create new one, bind it to the Simulation (which ensures MathOverrides), and add to list
//
Function newLocalFunction = new Function(referenceFunction.getName(), referenceFunction.getExpression(), referenceFunction.getDomain());
// newLocalFunction.bind(this);
localVariableHash.put(newLocalFunction.getName(), newLocalFunction);
return newLocalFunction;
}
Aggregations