Search in sources :

Example 1 with VariableSymbolTable

use of cbit.vcell.parser.VariableSymbolTable in project vcell by virtualcell.

the class RowColumnResultSet method createResultSetSymbolTable.

/**
 * Insert the method's description here.
 * Creation date: (2/19/2003 4:32:00 PM)
 * @return cbit.vcell.parser.SymbolTable
 */
private VariableSymbolTable createResultSetSymbolTable(boolean bIncludeFunctions) {
    // 
    // create symbol table for binding expression against data columns and functions (of data columns)
    // 
    VariableSymbolTable resultSetSymbolTable = new VariableSymbolTable();
    for (int i = 0; i < getColumnDescriptionsCount(); i++) {
        ColumnDescription colDesc = getColumnDescriptions(i);
        if (colDesc instanceof ODESolverResultSetColumnDescription) {
            Domain domain = null;
            VolVariable vVar = new VolVariable(colDesc.getName(), domain);
            vVar.setIndex(i);
            resultSetSymbolTable.addVar(vVar);
        } else if (bIncludeFunctions && colDesc instanceof FunctionColumnDescription) {
            FunctionColumnDescription funcColDesc = (FunctionColumnDescription) colDesc;
            Domain domain = null;
            Function func = new Function(funcColDesc.getName(), new Expression(funcColDesc.getExpression()), domain);
            func.setIndex(i);
            resultSetSymbolTable.addVar(func);
        }
    }
    return resultSetSymbolTable;
}
Also used : Expression(cbit.vcell.parser.Expression) ColumnDescription(cbit.vcell.util.ColumnDescription) VariableSymbolTable(cbit.vcell.parser.VariableSymbolTable) Domain(cbit.vcell.math.Variable.Domain)

Example 2 with VariableSymbolTable

use of cbit.vcell.parser.VariableSymbolTable in project vcell by virtualcell.

the class DataSetControllerImpl method fieldFunctionSubstitution.

private Expression fieldFunctionSubstitution(OutputContext outputContext, final VCDataIdentifier vcdID, Expression functionExpression) throws ExpressionException, DataAccessException, IOException, MathException {
    SimResampleInfoProvider simResampleInfoProvider = null;
    Expression origExpression = new Expression(functionExpression);
    if (vcdID instanceof VCSimulationDataIdentifier) {
        simResampleInfoProvider = ((VCSimulationDataIdentifier) vcdID);
    } else if (vcdID instanceof VCSimulationDataIdentifierOldStyle) {
        simResampleInfoProvider = ((VCSimulationDataIdentifierOldStyle) vcdID);
    } else if (vcdID instanceof ExternalDataIdentifier) {
        simResampleInfoProvider = ((ExternalDataIdentifier) vcdID);
    } else {
        return origExpression;
    }
    FieldFunctionArguments[] fieldfuncArgumentsArr = FieldUtilities.getFieldFunctionArguments(origExpression);
    if (fieldfuncArgumentsArr == null || fieldfuncArgumentsArr.length == 0) {
        return origExpression;
    }
    String[] origSymbols = origExpression.getSymbols();
    Vector<SymbolTableEntry> originalSymbolTablEntrryV = new Vector<SymbolTableEntry>();
    for (int i = 0; origSymbols != null && i < origSymbols.length; i++) {
        if (!originalSymbolTablEntrryV.contains(origExpression.getSymbolBinding(origSymbols[i]))) {
            originalSymbolTablEntrryV.add(origExpression.getSymbolBinding(origSymbols[i]));
        }
    }
    Expression exp = new Expression(origExpression);
    // 
    // Handle Field Data Function field(...)
    // 
    double[][] resampledFieldDatas = null;
    HashMap<String, Integer> substSymbolIndexH = new HashMap<String, Integer>();
    // if(fieldfuncArgumentsArr != null && fieldfuncArgumentsArr.length > 0){
    FieldDataIdentifierSpec[] fieldDataIdentifierSpecArr = getFieldDataIdentifierSpecs(fieldfuncArgumentsArr, simResampleInfoProvider.getOwner());
    // Substitute Field Data Functions for simple symbols for lookup-------
    for (int i = 0; i < fieldfuncArgumentsArr.length; i += 1) {
        for (int j = 0; j < fieldDataIdentifierSpecArr.length; j++) {
            if (fieldfuncArgumentsArr[i].equals(fieldDataIdentifierSpecArr[j].getFieldFuncArgs())) {
                String substFieldName = fieldfuncArgumentsArr[i].getFieldName() + "_" + fieldfuncArgumentsArr[i].getVariableName() + "_" + fieldfuncArgumentsArr[i].getTime().evaluateConstant();
                substFieldName = TokenMangler.fixTokenStrict(substFieldName);
                if (exp.hasSymbol(substFieldName)) {
                    throw new DataAccessException("Substitute Field data name is not unique");
                }
                String fieldFuncString = SimulationData.createCanonicalFieldFunctionSyntax(fieldDataIdentifierSpecArr[j].getExternalDataIdentifier().getName(), fieldfuncArgumentsArr[i].getVariableName(), fieldfuncArgumentsArr[i].getTime().evaluateConstant(), fieldfuncArgumentsArr[i].getVariableType().getTypeName());
                exp.substituteInPlace(new Expression(fieldFuncString), new Expression(substFieldName));
                substSymbolIndexH.put(substFieldName, i);
                break;
            }
        }
    }
    // ----------------------------------------------------------------------
    boolean[] bResample = new boolean[fieldDataIdentifierSpecArr.length];
    Arrays.fill(bResample, true);
    writeFieldFunctionData(outputContext, fieldDataIdentifierSpecArr, bResample, getMesh(simResampleInfoProvider), simResampleInfoProvider, getMesh(simResampleInfoProvider).getNumMembraneElements(), FVSolverStandalone.HESM_KEEP_AND_CONTINUE);
    resampledFieldDatas = new double[fieldfuncArgumentsArr.length][];
    for (int i = 0; i < fieldfuncArgumentsArr.length; i += 1) {
        // File resampledFile =
        // new File(getUserDir(vcsdID.getOwner()),
        // vcsdID.getID()+
        // FieldDataIdentifierSpec.getDefaultFieldDataFileNameForSimulation(fieldfuncArgumentsArr[i])
        // );
        // File resampledFile = new File(getPrimaryUserDir(simResampleInfoProvider.getOwner(), true),
        // SimulationData.createCanonicalResampleFileName(
        // simResampleInfoProvider, fieldfuncArgumentsArr[i]));
        File resampledFile = ((SimulationData) getVCData(simResampleInfoProvider)).getFieldDataFile(simResampleInfoProvider, fieldfuncArgumentsArr[i]);
        resampledFieldDatas[i] = DataSet.fetchSimData(fieldfuncArgumentsArr[i].getVariableName(), resampledFile);
    }
    // }
    // Rebind all the symbols
    String[] dependentIDs = exp.getSymbols();
    VariableSymbolTable varSymbolTable = new VariableSymbolTable();
    for (int i = 0; dependentIDs != null && i < dependentIDs.length; i++) {
        SymbolTableEntry newSymbolTableEntry = null;
        for (int j = 0; j < originalSymbolTablEntrryV.size(); j++) {
            if (originalSymbolTablEntrryV.elementAt(j).getName().equals(dependentIDs[i])) {
                newSymbolTableEntry = originalSymbolTablEntrryV.elementAt(j);
                break;
            }
        }
        if (newSymbolTableEntry == null) {
            if (substSymbolIndexH.containsKey(dependentIDs[i])) {
                int resampledDataIndex = substSymbolIndexH.get(dependentIDs[i]).intValue();
                FieldDataParameterVariable fieldDataParameterVariable = new FieldDataParameterVariable(dependentIDs[i], resampledFieldDatas[resampledDataIndex]);
                newSymbolTableEntry = fieldDataParameterVariable;
            }
        }
        if (newSymbolTableEntry == null) {
            throw new DataAccessException("Field Data Couldn't find substituted expression while evaluating function");
        }
        varSymbolTable.addVar(newSymbolTableEntry);
    }
    exp.bindExpression(varSymbolTable);
    return exp;
}
Also used : HashMap(java.util.HashMap) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VariableSymbolTable(cbit.vcell.parser.VariableSymbolTable) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException) FieldDataParameterVariable(cbit.vcell.field.FieldDataParameterVariable) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) SimResampleInfoProvider(org.vcell.util.document.SimResampleInfoProvider) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) Expression(cbit.vcell.parser.Expression) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) VCSimulationDataIdentifierOldStyle(cbit.vcell.solver.VCSimulationDataIdentifierOldStyle) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 3 with VariableSymbolTable

use of cbit.vcell.parser.VariableSymbolTable in project vcell by virtualcell.

the class OdeFileWriter method createSymbolTable.

/**
 * OdeFileCoder constructor comment.
 * @throws Exception
 */
private void createSymbolTable() throws Exception {
    // 
    // Create symbol table for binding sensitivity variable expressions. (Cannot bind to simulation,
    // since it does not have the sensitivity variables corresponding to the volume variables).
    // 
    varsSymbolTable = new VariableSymbolTable();
    // SymbolTableEntry.index doesn't matter ... just code generating binding by var names not index.
    varsSymbolTable.addVar(ReservedVariable.TIME);
    int count = 0;
    Variable[] variables = simTask.getSimulationJob().getSimulationSymbolTable().getVariables();
    for (int i = 0; i < variables.length; i++) {
        if (variables[i] instanceof VolVariable) {
            VolVariable vVar = (VolVariable) variables[i];
            vVar.setIndex(count);
            varsSymbolTable.addVar(vVar);
            count++;
        } else if (variables[i] instanceof Function) {
            Function func = (Function) variables[i];
            func.setIndex(count);
            varsSymbolTable.addVar(func);
            count++;
        } else if (variables[i] instanceof Constant) {
            Constant constant = (Constant) variables[i];
            constant.setIndex(count);
            varsSymbolTable.addVar(constant);
            count++;
        } else if (variables[i] instanceof ParameterVariable) {
            ParameterVariable param = (ParameterVariable) variables[i];
            param.setIndex(count);
            varsSymbolTable.addVar(param);
            count++;
        }
    }
    // Get the vector of sensVariables, needed for creating SensStateVariables
    Vector<SensStateVariable> sensVars = new Vector<SensStateVariable>();
    for (int i = 0; i < getStateVariableCount(); i++) {
        if (simTask.getSimulation().getSolverTaskDescription().getSensitivityParameter() != null) {
            if (getStateVariable(i) instanceof SensStateVariable) {
                sensVars.addElement((SensStateVariable) getStateVariable(i));
            }
        }
    }
    for (int j = count; j < (count + sensVars.size()); j++) {
        SensVariable sVar = (SensVariable) (sensVars.elementAt(j - count).getVariable());
        sVar.setIndex(j);
        varsSymbolTable.addVar(sVar);
    }
}
Also used : Function(cbit.vcell.math.Function) ReservedVariable(cbit.vcell.math.ReservedVariable) ParameterVariable(cbit.vcell.math.ParameterVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) VolVariable(cbit.vcell.math.VolVariable) Constant(cbit.vcell.math.Constant) VariableSymbolTable(cbit.vcell.parser.VariableSymbolTable) ParameterVariable(cbit.vcell.math.ParameterVariable) Vector(java.util.Vector)

Aggregations

VariableSymbolTable (cbit.vcell.parser.VariableSymbolTable)3 Expression (cbit.vcell.parser.Expression)2 Vector (java.util.Vector)2 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)1 FieldDataParameterVariable (cbit.vcell.field.FieldDataParameterVariable)1 FieldFunctionArguments (cbit.vcell.field.FieldFunctionArguments)1 Constant (cbit.vcell.math.Constant)1 Function (cbit.vcell.math.Function)1 ParameterVariable (cbit.vcell.math.ParameterVariable)1 ReservedVariable (cbit.vcell.math.ReservedVariable)1 Variable (cbit.vcell.math.Variable)1 Domain (cbit.vcell.math.Variable.Domain)1 VolVariable (cbit.vcell.math.VolVariable)1 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)1 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)1 VCSimulationDataIdentifierOldStyle (cbit.vcell.solver.VCSimulationDataIdentifierOldStyle)1 ColumnDescription (cbit.vcell.util.ColumnDescription)1 File (java.io.File)1 HashMap (java.util.HashMap)1 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)1