Search in sources :

Example 46 with SymbolTableEntry

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

Example 47 with SymbolTableEntry

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;
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) Expression(cbit.vcell.parser.Expression) FileNotFoundException(java.io.FileNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) ExpressionException(cbit.vcell.parser.ExpressionException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 48 with SymbolTableEntry

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

Example 49 with SymbolTableEntry

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;
}
Also used : AutoCompleteSymbolFilter(cbit.vcell.parser.AutoCompleteSymbolFilter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) OutsideVariable(cbit.vcell.math.OutsideVariable) InsideVariable(cbit.vcell.math.InsideVariable)

Example 50 with SymbolTableEntry

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);
    }
}
Also used : SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) Constant(cbit.vcell.math.Constant) PseudoConstant(cbit.vcell.math.PseudoConstant) PseudoConstant(cbit.vcell.math.PseudoConstant) DataGenerator(cbit.vcell.math.DataGenerator)

Aggregations

SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)115 Expression (cbit.vcell.parser.Expression)50 ExpressionException (cbit.vcell.parser.ExpressionException)20 Vector (java.util.Vector)20 ArrayList (java.util.ArrayList)19 SpeciesContext (cbit.vcell.model.SpeciesContext)18 ModelParameter (cbit.vcell.model.Model.ModelParameter)14 PropertyVetoException (java.beans.PropertyVetoException)14 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)13 Model (cbit.vcell.model.Model)12 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)11 HashMap (java.util.HashMap)11 SimulationContext (cbit.vcell.mapping.SimulationContext)10 Variable (cbit.vcell.math.Variable)10 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)9 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)9 Parameter (cbit.vcell.model.Parameter)9 SingleXPlot2D (cbit.plot.SingleXPlot2D)8 MathException (cbit.vcell.math.MathException)8 ReservedVariable (cbit.vcell.math.ReservedVariable)8