use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class MergedData method functionBindAndSubstitute.
private void functionBindAndSubstitute(AnnotatedFunction function) throws ExpressionException {
// attempt to bind function and substitute
Expression simExp = function.getExpression();
if (simExp == null) {
Expression exp = new Expression(function.getExpression());
exp.bindExpression(this);
String[] symbols = exp.getSymbols();
if (symbols != null) {
for (int i = 0; i < symbols.length; i++) {
Expression oldExp = new Expression(symbols[i]);
Expression newExp = null;
SymbolTableEntry ste = getEntry(symbols[i]);
if (ste != null) {
if (!(ste instanceof DataSetIdentifier)) {
continue;
}
DataSetIdentifier dsi = (DataSetIdentifier) ste;
if (!dsi.isFunction()) {
continue;
}
for (int j = 0; j < annotatedFunctionList.size(); j++) {
AnnotatedFunction mathFunction = (AnnotatedFunction) annotatedFunctionList.elementAt(j);
if (mathFunction.getName().equals(symbols[i])) {
newExp = mathFunction.getExpression();
break;
}
}
}
if (ste == null || newExp == null) {
throw new RuntimeException("dependencies for function '" + function + "' not found");
}
exp.substituteInPlace(oldExp, newExp);
}
}
simExp = exp.flatten();
function.setExpression(simExp);
}
simExp.bindExpression(this);
function.getExpression().bindExpression(this);
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class SimulationData method simplifyFunction.
public AnnotatedFunction simplifyFunction(AnnotatedFunction function) throws ExpressionException {
// attempt to bind function and substitute
AnnotatedFunction simpleFunction = null;
try {
simpleFunction = (AnnotatedFunction) BeanUtils.cloneSerializable(function);
Expression exp = simpleFunction.getExpression();
exp = SolverUtilities.substituteSizeAndNormalFunctions(exp, function.getFunctionType().getVariableDomain());
exp.bindExpression(this);
String[] symbols = exp.getSymbols();
if (symbols != null) {
for (int i = 0; i < symbols.length; i++) {
Expression oldExp = new Expression(symbols[i]);
Expression newExp = null;
SymbolTableEntry ste = getEntry(symbols[i]);
if (ste != null) {
if (!(ste instanceof DataSetIdentifier)) {
continue;
}
DataSetIdentifier dsi = (DataSetIdentifier) ste;
if (!dsi.isFunction()) {
continue;
}
for (int j = 0; j < annotatedFunctionList.size(); j++) {
AnnotatedFunction mathFunction = (AnnotatedFunction) annotatedFunctionList.elementAt(j);
if (mathFunction.getName().equals(symbols[i])) {
newExp = mathFunction.getExpression();
break;
}
}
}
if (ste == null || newExp == null) {
throw new RuntimeException("dependencies for function '" + function + "' not found");
}
exp.substituteInPlace(oldExp, newExp);
}
}
exp = exp.flatten();
exp.bindExpression(this);
simpleFunction.setExpression(exp);
} catch (Exception ex) {
ex.printStackTrace(System.out);
throw new ExpressionException(ex.getMessage());
}
return simpleFunction;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class SimulationData method getEntry.
/**
* Insert the method's description here.
* Creation date: (10/11/00 1:34:51 PM)
* @return cbit.vcell.parser.SymbolTableEntry
* @param identifier java.lang.String
*/
public SymbolTableEntry getEntry(String identifier) {
SymbolTableEntry entry = null;
entry = ReservedMathSymbolEntries.getEntry(identifier, false);
if (entry != null) {
return entry;
}
entry = getDataSetIdentifier(identifier);
if (entry != null) {
return entry;
}
if (identifier.endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX) || identifier.endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
int index = identifier.lastIndexOf("_");
String realvar = identifier.substring(0, index);
DataSetIdentifier dsi = getDataSetIdentifier(realvar);
if (dsi != null) {
DataSetIdentifier adsi = new DataSetIdentifier(identifier, dsi.getVariableType(), dsi.getDomain(), dsi.isFunction());
dataSetIdentifierList.addElement(adsi);
return adsi;
}
}
return null;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class OutputFunctionContext method getAutoCompleteSymbolFilter.
public AutoCompleteSymbolFilter getAutoCompleteSymbolFilter() {
AutoCompleteSymbolFilter stef = new AutoCompleteSymbolFilter() {
public boolean accept(SymbolTableEntry ste) {
MathDescription math = getSimulationOwner().getMathDescription();
Variable var = math.getVariable(ste.getName());
return (!(var instanceof InsideVariable || var instanceof OutsideVariable));
}
public boolean acceptFunction(String funcName) {
return true;
}
};
return stef;
}
use of cbit.vcell.parser.SymbolTableEntry in project vcell by virtualcell.
the class OutputFunctionContext method getEntries.
// public abstract void validateNamingConflicts(String symbolDescription, Class<?> newSymbolClass, String newSymbolName, PropertyChangeEvent e) throws PropertyVetoException ;
public void getEntries(Map<String, SymbolTableEntry> entryMap) {
// add all valid entries (variables) from mathdescription
MathDescription mathDescription = simulationOwner.getMathDescription();
if (mathDescription != null) {
Enumeration<Variable> varEnum = mathDescription.getVariables();
while (varEnum.hasMoreElements()) {
Variable var = varEnum.nextElement();
if (!(var instanceof PseudoConstant) && !(var instanceof Constant)) {
entryMap.put(var.getName(), var);
}
}
for (DataGenerator dataGenerator : mathDescription.getPostProcessingBlock().getDataGeneratorList()) {
entryMap.put(dataGenerator.getName(), dataGenerator);
}
}
entryMap.put(ReservedVariable.TIME.getName(), ReservedVariable.TIME);
int dimension = mathDescription.getGeometry().getDimension();
if (dimension > 0) {
entryMap.put(ReservedVariable.X.getName(), ReservedVariable.X);
if (dimension > 1) {
entryMap.put(ReservedVariable.Y.getName(), ReservedVariable.Y);
if (dimension > 2) {
entryMap.put(ReservedVariable.Z.getName(), ReservedVariable.Z);
}
}
}
// then add list of output functions.
for (SymbolTableEntry ste : outputFunctionsList) {
entryMap.put(ste.getName(), ste);
}
}
Aggregations