Search in sources :

Example 16 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class ODESimData method readNFSIMDataFile.

public static ODESimData readNFSIMDataFile(VCDataIdentifier vcdId, File dataFile, File functionsFile) throws DataAccessException, IOException {
    System.out.println("reading NetCDF file : " + dataFile);
    ODESimData odeSimData = new ODESimData();
    odeSimData.formatID = NETCDF_DATA_FORMAT_ID;
    odeSimData.mathName = vcdId.getID();
    String file = dataFile.getPath();
    BufferedReader reader = new BufferedReader(new FileReader(file));
    String firstLine = reader.readLine();
    StringTokenizer st = new StringTokenizer(firstLine);
    // #
    st.nextToken();
    // time
    st.nextToken();
    // first column will be time t.
    odeSimData.addDataColumn(new ODESolverResultSetColumnDescription("t"));
    int count = st.countTokens();
    String varName = new String();
    for (int i = 0; i < count; i++) {
        varName = st.nextToken();
        odeSimData.addDataColumn(new ODESolverResultSetColumnDescription(varName));
    }
    // Read data
    // String         ls = System.getProperty("line.separator");
    // StringBuilder  stringBuilder = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
        double[] values = new double[odeSimData.getDataColumnCount()];
        st = new StringTokenizer(line);
        count = st.countTokens();
        String sData = new String();
        for (int i = 0; i < count; i++) {
            sData = st.nextToken();
            double dData = Double.parseDouble(sData);
            values[i] = dData;
        }
        odeSimData.addRow(values);
    }
    if (!odeSimData.getColumnDescriptions(0).getName().equals(SimDataConstants.HISTOGRAM_INDEX_NAME)) {
        Vector<AnnotatedFunction> funcList;
        try {
            funcList = FunctionFileGenerator.readFunctionsFile(functionsFile, vcdId.getID());
            for (AnnotatedFunction func : funcList) {
                try {
                    Expression expression = new Expression(func.getExpression());
                    odeSimData.addFunctionColumn(new FunctionColumnDescription(expression, func.getName(), null, func.getName(), false));
                } catch (ExpressionException e) {
                    throw new RuntimeException("Could not add function " + func.getName() + " to annotatedFunctionList");
                }
            }
        } catch (FileNotFoundException e1) {
            e1.printStackTrace(System.out);
            throw new DataAccessException(e1.getMessage());
        } catch (IOException e1) {
            e1.printStackTrace(System.out);
            throw new DataAccessException(e1.getMessage());
        }
    }
    return odeSimData;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) StringTokenizer(java.util.StringTokenizer) Expression(cbit.vcell.parser.Expression) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription) FunctionColumnDescription(cbit.vcell.math.FunctionColumnDescription) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 17 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class MergedData method getFunctions.

/**
 * Insert the method's description here.
 * Creation date: (10/11/00 5:16:06 PM)
 * @return cbit.vcell.math.Function
 * @param name java.lang.String
 */
public AnnotatedFunction[] getFunctions(OutputContext outputContext) {
    try {
        getFunctionDataIdentifiers(outputContext);
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
    }
    ArrayList<AnnotatedFunction> functionsArr = new ArrayList<>();
    // Get the functions in annotatedFunctionsList
    for (int i = 0; i < annotatedFunctionList.size(); i++) {
        // AnnotatedFunction annotatedFunc = (AnnotatedFunction)annotatedFunctionList.elementAt(i);
        // functions[i] = new Function(annotatedFunc.getName(), annotatedFunc.getExpression());
        functionsArr.add((AnnotatedFunction) annotatedFunctionList.elementAt(i));
    }
    for (int i = 0; i < datasetsIDList.length; i++) {
        VCDataIdentifier vcdid = datasetsIDList[i];
        try {
            AnnotatedFunction[] myFuncs = getDatasetControllerImpl().getFunctions(outputContext, vcdid);
            for (int j = 0; j < myFuncs.length; j++) {
                AnnotatedFunction myfunc = new AnnotatedFunction(dataSetPrefix[i] + "." + myFuncs[j].getName(), myFuncs[j].getExpression(), myFuncs[j].getDomain(), myFuncs[j].getErrorString(), myFuncs[j].getFunctionType(), myFuncs[j].getFunctionCatogery());
                functionsArr.add(myfunc);
            }
        } catch (ExpressionBindingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (DataAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return functionsArr.toArray(new AnnotatedFunction[0]);
}
Also used : ArrayList(java.util.ArrayList) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) FileNotFoundException(java.io.FileNotFoundException) MathException(cbit.vcell.math.MathException) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 18 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction 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 19 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class SimulationData method readFunctions.

/**
 * Insert the method's description here.
 * Creation date: (1/15/2004 11:48:25 AM)
 */
private void readFunctions(OutputContext outputContext) throws FileNotFoundException, IOException {
    File firstJobFunctionsFile = getFirstJobFunctionsFile();
    File jobFunctionsFile = getJobFunctionsFile();
    // only dataset functions
    Vector<AnnotatedFunction> annotatedFuncsVector = FunctionFileGenerator.readFunctionsFile(jobFunctionsFile, vcDataId.getID());
    /* not required as long as we are skipping any legacy user-defined functions from the functions file */
    if (!firstJobFunctionsFile.equals(jobFunctionsFile)) {
        Vector<AnnotatedFunction> f1 = FunctionFileGenerator.readFunctionsFile(firstJobFunctionsFile, vcDataId.getID());
        for (AnnotatedFunction f : f1) {
            if (f.isOldUserDefined()) {
                annotatedFuncsVector.add(f);
            }
        }
    }
    // add user-defined functions from output context, if any
    if (outputContext != null) {
        for (int i = 0; i < outputContext.getOutputFunctions().length; i++) {
            annotatedFuncsVector.add(outputContext.getOutputFunctions()[i]);
        }
    }
    // 
    // Convert this annotatedfunctionsVector into the field annotatedFunctionsList.
    // 
    annotatedFunctionList.clear();
    for (int i = 0; i < annotatedFuncsVector.size(); i++) {
        AnnotatedFunction annotatedFunction = (AnnotatedFunction) annotatedFuncsVector.elementAt(i);
        try {
            addFunctionToList(annotatedFunction);
        } catch (ExpressionException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("Could not add function " + annotatedFunction.getName() + " to annotatedFunctionList");
        }
    }
}
Also used : ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) ExpressionException(cbit.vcell.parser.ExpressionException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 20 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction 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)

Aggregations

AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)61 DataAccessException (org.vcell.util.DataAccessException)21 ExpressionException (cbit.vcell.parser.ExpressionException)20 Expression (cbit.vcell.parser.Expression)17 ArrayList (java.util.ArrayList)17 Simulation (cbit.vcell.solver.Simulation)15 IOException (java.io.IOException)15 OutputContext (cbit.vcell.simdata.OutputContext)14 MathException (cbit.vcell.math.MathException)12 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)12 SimulationContext (cbit.vcell.mapping.SimulationContext)11 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)10 DataIdentifier (cbit.vcell.simdata.DataIdentifier)9 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)9 FileNotFoundException (java.io.FileNotFoundException)8 Domain (cbit.vcell.math.Variable.Domain)7 VariableType (cbit.vcell.math.VariableType)7 XmlParseException (cbit.vcell.xml.XmlParseException)7 PropertyVetoException (java.beans.PropertyVetoException)7 File (java.io.File)7