Search in sources :

Example 11 with FunctionInvocation

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;
}
Also used : FunctionInvocation(cbit.vcell.parser.FunctionInvocation) Expression(cbit.vcell.parser.Expression)

Example 12 with FunctionInvocation

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;
}
Also used : FunctionInvocation(cbit.vcell.parser.FunctionInvocation) FunctionFilter(cbit.vcell.parser.Expression.FunctionFilter) FunctionType(cbit.vcell.parser.ASTFuncNode.FunctionType) HashSet(java.util.HashSet)

Aggregations

FunctionInvocation (cbit.vcell.parser.FunctionInvocation)12 Expression (cbit.vcell.parser.Expression)9 FunctionFilter (cbit.vcell.parser.Expression.FunctionFilter)7 FunctionType (cbit.vcell.parser.ASTFuncNode.FunctionType)5 ExpressionException (cbit.vcell.parser.ExpressionException)4 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)3 FieldFunctionArguments (cbit.vcell.field.FieldFunctionArguments)2 VariableType (cbit.vcell.math.VariableType)2 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)2 SymbolTableFunctionEntry (cbit.vcell.parser.SymbolTableFunctionEntry)2 ArrayList (java.util.ArrayList)2 GradientFunctionDefinition (cbit.vcell.math.GradientFunctionDefinition)1 InconsistentDomainException (cbit.vcell.math.InconsistentDomainException)1 MathException (cbit.vcell.math.MathException)1 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)1 SubDomain (cbit.vcell.math.SubDomain)1 MatrixException (cbit.vcell.matrix.MatrixException)1 ModelFunction (cbit.vcell.model.Model.ModelFunction)1 ModelException (cbit.vcell.model.ModelException)1 VCUnitEvaluator (cbit.vcell.parser.VCUnitEvaluator)1