use of cbit.vcell.parser.Expression.FunctionFilter in project vcell by virtualcell.
the class MathFunctionDefinitions method fixFunctionSyntax.
public static Expression fixFunctionSyntax(Expression exp) throws ExpressionException {
FunctionInvocation[] functionInvocations = exp.getFunctionInvocations(new FunctionFilter() {
@Override
public boolean accept(String functionName, FunctionType functionType) {
return (functionName.equals(FunctionName_field_old) || functionName.equals(FunctionName_grad_old));
}
});
for (int i = 0; functionInvocations != null && i < functionInvocations.length; i++) {
Expression[] argExpressions = functionInvocations[i].getArguments();
if (functionInvocations[i].getFunctionName().equals(FunctionName_field_old)) {
if (argExpressions.length >= 2 && argExpressions.length <= 4) {
StringBuffer functionBuffer = new StringBuffer(FieldFunctionDefinition.FUNCTION_name + "(");
if (argExpressions[0].isIdentifier()) {
functionBuffer.append("'" + argExpressions[0].infix() + "'");
} else {
throw new ExpressionException("unexpected function format '" + functionInvocations[i].getFunctionExpression() + "'");
}
functionBuffer.append(",");
if (argExpressions[1].isIdentifier()) {
functionBuffer.append("'" + argExpressions[1].infix() + "'");
} else {
throw new ExpressionException("unexpected function format '" + functionInvocations[i].getFunctionExpression() + "'");
}
functionBuffer.append(",");
if (argExpressions.length >= 3) {
functionBuffer.append(argExpressions[2].infix());
} else {
functionBuffer.append("0.0");
}
functionBuffer.append(",");
if (argExpressions.length >= 4) {
if (argExpressions[3].isIdentifier()) {
VariableType varType = VariableType.getVariableTypeFromVariableTypeNameIgnoreCase(argExpressions[3].infix());
functionBuffer.append("'" + varType.getTypeName() + "'");
} else {
throw new ExpressionException("unexpected function format '" + functionInvocations[i].getFunctionExpression() + "'");
}
} else {
functionBuffer.append("'" + VariableType.VOLUME.getTypeName() + "'");
}
functionBuffer.append(")");
exp = exp.getSubstitutedExpression(functionInvocations[i].getFunctionExpression(), new Expression(functionBuffer.toString()));
}
} else if (functionInvocations[i].getFunctionName().equals(FunctionName_grad_old)) {
if (argExpressions.length == 2 && !argExpressions[1].isLiteral()) {
// grad(x,calcium) ==> vcGrad(calcium,'x') ... where x is [x y z m]
StringBuffer functionBuffer = new StringBuffer(GradientFunctionDefinition.FUNCTION_name + "(");
Expression componentArg = argExpressions[0];
Expression variableArg = argExpressions[1];
functionBuffer.append(variableArg.infix());
functionBuffer.append(",");
functionBuffer.append("'" + componentArg.infix() + "'");
functionBuffer.append(")");
exp = exp.getSubstitutedExpression(functionInvocations[i].getFunctionExpression(), new Expression(functionBuffer.toString()));
}
}
}
return exp;
}
use of cbit.vcell.parser.Expression.FunctionFilter in project vcell by virtualcell.
the class SolverUtilities method getSizeFunctionInvocations.
public static Set<FunctionInvocation> getSizeFunctionInvocations(Expression expression) {
if (expression == null) {
return null;
}
FunctionInvocation[] functionInvocations = expression.getFunctionInvocations(new FunctionFilter() {
@Override
public boolean accept(String functionName, FunctionType functionType) {
if (functionName.equals(MathFunctionDefinitions.Function_regionArea_current.getFunctionName()) || functionName.equals(MathFunctionDefinitions.Function_regionVolume_current.getFunctionName())) {
return true;
}
return false;
}
});
Set<FunctionInvocation> fiSet = new HashSet<FunctionInvocation>();
for (FunctionInvocation fi : functionInvocations) {
fiSet.add(fi);
}
return fiSet;
}
Aggregations