use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class SimulationSymbolTable method getVariables.
/**
* Insert the method's description here.
* Creation date: (5/25/01 11:34:08 AM)
* @return cbit.vcell.math.Variable[]
*/
public Variable[] getVariables() {
Vector<Variable> varList = new Vector<Variable>();
//
// get all variables from MathDescription, but replace MathOverrides
//
Enumeration<Variable> enum1 = simulation.getMathDescription().getVariables();
while (enum1.hasMoreElements()) {
Variable mathDescriptionVar = enum1.nextElement();
//
if (mathDescriptionVar instanceof Constant) {
try {
Constant overriddenConstant = getLocalConstant((Constant) mathDescriptionVar);
varList.addElement(overriddenConstant);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("local Constant " + mathDescriptionVar.getName() + " not found for Simulation");
}
//
// replace all Functions with local Functions that are bound to this Simulation
//
} else if (mathDescriptionVar instanceof Function) {
try {
Function overriddenFunction = getLocalFunction((Function) mathDescriptionVar);
varList.addElement(overriddenFunction);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("local Function " + mathDescriptionVar.getName() + " not found for Simulation");
}
//
// pass all other Variables through
//
} else {
varList.addElement(mathDescriptionVar);
}
}
Variable[] variables = (Variable[]) BeanUtils.getArray(varList, Variable.class);
return variables;
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class SimulationSymbolTable method applyOverrides.
public void applyOverrides(MathDescription newMath) throws ExpressionException, MappingException, MathException {
//
// replace original constants with "Simulation" constants
//
Variable[] newVarArray = (Variable[]) BeanUtils.getArray(newMath.getVariables(), Variable.class);
for (int i = 0; i < newVarArray.length; i++) {
if (newVarArray[i] instanceof Constant) {
Constant origConstant = (Constant) newVarArray[i];
Constant simConstant = getLocalConstant(origConstant);
newVarArray[i] = new Constant(origConstant.getName(), new Expression(simConstant.getExpression()));
}
}
newMath.setAllVariables(newVarArray);
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class DefaultODESolver method createIdentifiers.
/**
* This method was created in VisualAge.
*/
private Vector<Variable> createIdentifiers() throws MathException, ExpressionException {
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
// create list of possible identifiers (including reserved x,y,z,t)
Vector<Variable> identifiers = new Vector<Variable>();
// add reserved variables x,y,z,t
identifiers.addElement(ReservedVariable.TIME);
identifiers.addElement(ReservedVariable.X);
identifiers.addElement(ReservedVariable.Y);
identifiers.addElement(ReservedVariable.Z);
// add regular variables
Variable[] variables = simSymbolTable.getVariables();
for (int i = 0; i < variables.length; i++) {
if (variables[i] instanceof VolVariable) {
identifiers.addElement(variables[i]);
}
}
// Add sensitivity variables (for sensitivity equations)...
fieldSensVariables = new Vector<SensVariable>();
if (getSensitivityParameter() != null) {
for (int i = 0; i < variables.length; i++) {
if (variables[i] instanceof VolVariable) {
VolVariable volVariable = (VolVariable) variables[i];
SensVariable sv = new SensVariable(volVariable, getSensitivityParameter());
identifiers.addElement(sv);
}
}
}
// Add pseudoConstants for fast system (if necessary)...
if (getFastAlgebraicSystem() != null) {
Enumeration<PseudoConstant> enum1 = fieldFastAlgebraicSystem.getPseudoConstants();
while (enum1.hasMoreElements()) {
identifiers.addElement(enum1.nextElement());
}
}
// Assign indices...
for (int i = 0; i < identifiers.size(); i++) {
Variable variable = (Variable) identifiers.elementAt(i);
variable.setIndex(i);
}
return (identifiers);
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class RateSensitivity method parseMathDesc.
/**
* This method was created by a SmartGuide.
* @exception java.lang.Exception The exception description.
*/
private void parseMathDesc() throws MathException {
Vector equationList = new Vector();
Enumeration enum1 = subDomain.getEquations();
while (enum1.hasMoreElements()) {
Equation equ = (Equation) enum1.nextElement();
if (equ instanceof OdeEquation) {
equationList.addElement(equ);
} else {
throw new MathException("encountered non-ode equation, unsupported");
}
}
Vector constantList = new Vector();
enum1 = mathDesc.getVariables();
while (enum1.hasMoreElements()) {
Variable var = (Variable) enum1.nextElement();
if (var instanceof Constant) {
constantList.addElement(var);
}
}
numConstants = constantList.size();
numRates = equationList.size();
rates = new Expression[numRates];
vars = new Variable[numRates];
consts = new Constant[numConstants];
for (int i = 0; i < numRates; i++) {
OdeEquation odeEqu = (OdeEquation) equationList.elementAt(i);
rates[i] = odeEqu.getRateExpression();
vars[i] = odeEqu.getVariable();
}
for (int i = 0; i < numConstants; i++) {
consts[i] = (Constant) constantList.elementAt(i);
}
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class SundialsSolver method createFunctionList.
public Vector<AnnotatedFunction> createFunctionList() {
//
// add appropriate Function columns to result set
//
Vector<AnnotatedFunction> funcList = super.createFunctionList();
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
if (getSensitivityParameter() != null) {
try {
AnnotatedFunction saf = new AnnotatedFunction(getSensitivityParameter().getName(), new Expression(getSensitivityParameter().getConstantValue()), getSensitivityParameter().getDomain(), "", VariableType.NONSPATIAL, FunctionCategory.PREDEFINED);
if (!funcList.contains(saf)) {
funcList.add(saf);
}
Variable[] variables = simSymbolTable.getVariables();
StateVariable[] stateVars = createStateVariables();
for (int i = 0; i < variables.length; i++) {
if (variables[i] instanceof Function && SimulationSymbolTable.isFunctionSaved((Function) variables[i])) {
Function depSensFunction = (Function) variables[i];
Expression depSensFnExpr = new Expression(depSensFunction.getExpression());
depSensFnExpr = simSymbolTable.substituteFunctions(depSensFnExpr);
depSensFnExpr = getFunctionSensitivity(depSensFnExpr, getSensitivityParameter(), stateVars);
// depSensFnExpr = depSensFnExpr.flatten(); // already bound and flattened in getFunctionSensitivity, no need here.....
String depSensFnName = new String("sens_" + depSensFunction.getName() + "_wrt_" + getSensitivityParameter().getName());
if (depSensFunction != null) {
AnnotatedFunction af = new AnnotatedFunction(depSensFnName, depSensFnExpr.flatten(), variables[i].getDomain(), "", VariableType.NONSPATIAL, FunctionCategory.PREDEFINED);
funcList.add(af);
}
}
}
} catch (MathException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding function to resultSet: " + e.getMessage());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error adding function to resultSet: " + e.getMessage());
}
}
return funcList;
}
Aggregations