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;
}
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]);
}
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);
}
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");
}
}
}
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;
}
Aggregations