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