use of cbit.vcell.parser.FunctionInvocation in project vcell by virtualcell.
the class SolverUtilities method substituteSizeAndNormalFunctions.
public static Expression substituteSizeAndNormalFunctions(Expression origExp, VariableDomain variableDomain) throws ExpressionException {
Expression exp = new Expression(origExp);
Set<FunctionInvocation> fiSet = SolverUtilities.getSizeFunctionInvocations(exp);
for (FunctionInvocation fi : fiSet) {
String functionName = fi.getFunctionName();
// the decision is based on variable domain
if (variableDomain.equals(VariableDomain.VARIABLEDOMAIN_VOLUME)) {
exp.substituteInPlace(fi.getFunctionExpression(), new Expression(functionName));
} else if (variableDomain.equals(VariableDomain.VARIABLEDOMAIN_MEMBRANE)) {
if (functionName.equals(MathFunctionDefinitions.Function_regionArea_current.getFunctionName())) {
exp.substituteInPlace(fi.getFunctionExpression(), new Expression(functionName));
} else {
String domainName = fi.getArguments()[0].infix();
// remove single quote
domainName = domainName.substring(1, domainName.length() - 1);
exp.substituteInPlace(fi.getFunctionExpression(), new Expression(functionName + "_" + domainName));
}
}
}
FunctionInvocation[] allFunctions = exp.getFunctionInvocations(null);
for (FunctionInvocation fi : allFunctions) {
if (fi.getFunctionName().equals(MathFunctionDefinitions.Function_normalX.getFunctionName())) {
exp.substituteInPlace(fi.getFunctionExpression(), new Expression("normalX"));
}
if (fi.getFunctionName().equals(MathFunctionDefinitions.Function_normalY.getFunctionName())) {
exp.substituteInPlace(fi.getFunctionExpression(), new Expression("normalY"));
}
}
return exp;
}
use of cbit.vcell.parser.FunctionInvocation 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