use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class Jacobian 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 variableList = new Vector();
enum1 = mathDesc.getVariables();
while (enum1.hasMoreElements()) {
Variable var = (Variable) enum1.nextElement();
if (var instanceof VolVariable) {
variableList.addElement(var);
}
}
if (equationList.size() != variableList.size()) {
throw new MathException("there are " + equationList.size() + " equations and " + variableList.size() + " variables");
}
numVariables = variableList.size();
rates = new Expression[numVariables];
vars = new VolVariable[numVariables];
for (int i = 0; i < numVariables; i++) {
OdeEquation odeEqu = (OdeEquation) equationList.elementAt(i);
rates[i] = odeEqu.getRateExpression();
vars[i] = (VolVariable) odeEqu.getVariable();
}
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class SundialsSolver method getODESolverResultSet.
/**
* This method was created in VisualAge.
* @return double[]
* @param vectorIndex int
*/
public ODESolverResultSet getODESolverResultSet() {
//
// read .ida file
//
ODESolverResultSet odeSolverResultSet = getStateVariableResultSet();
if (odeSolverResultSet == null) {
return null;
}
//
// add appropriate Function columns to result set
//
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
Function[] functions = simSymbolTable.getFunctions();
for (int i = 0; i < functions.length; i++) {
if (SimulationSymbolTable.isFunctionSaved(functions[i])) {
Expression exp1 = new Expression(functions[i].getExpression());
try {
exp1 = simSymbolTable.substituteFunctions(exp1);
} catch (MathException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
}
try {
FunctionColumnDescription cd = new FunctionColumnDescription(exp1.flatten(), functions[i].getName(), null, functions[i].getName(), false);
odeSolverResultSet.addFunctionColumn(cd);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
}
}
if (getSensitivityParameter() != null) {
try {
if (odeSolverResultSet.findColumn(getSensitivityParameter().getName()) == -1) {
FunctionColumnDescription fcd = new FunctionColumnDescription(new Expression(getSensitivityParameter().getConstantValue()), getSensitivityParameter().getName(), null, getSensitivityParameter().getName(), false);
odeSolverResultSet.addFunctionColumn(fcd);
}
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) {
FunctionColumnDescription cd = new FunctionColumnDescription(depSensFnExpr.flatten(), depSensFnName, getSensitivityParameter().getName(), depSensFnName, false);
odeSolverResultSet.addFunctionColumn(cd);
}
}
}
} 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 odeSolverResultSet;
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class SundialsSolver method createStateVariables.
/*
This method was created in Visual Age
*/
private StateVariable[] createStateVariables() throws MathException, ExpressionException {
Vector<StateVariable> stateVariables = new Vector<StateVariable>();
// get Ode's from MathDescription and create ODEStateVariables
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
MathDescription mathDescription = simSymbolTable.getSimulation().getMathDescription();
Enumeration<Equation> enum1 = ((SubDomain) mathDescription.getSubDomains().nextElement()).getEquations();
while (enum1.hasMoreElements()) {
Equation equation = (Equation) enum1.nextElement();
if (equation instanceof OdeEquation) {
stateVariables.addElement(new ODEStateVariable((OdeEquation) equation, simSymbolTable));
} else {
throw new MathException("encountered non-ode equation, unsupported");
}
}
// Get sensitivity variables
Variable[] variables = simSymbolTable.getVariables();
Vector<SensVariable> sensVariables = 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());
sensVariables.addElement(sv);
}
}
}
if (rateSensitivity == null) {
rateSensitivity = new RateSensitivity(mathDescription, mathDescription.getSubDomains().nextElement());
}
if (jacobian == null) {
jacobian = new Jacobian(mathDescription, mathDescription.getSubDomains().nextElement());
}
for (int v = 0; v < sensVariables.size(); v++) {
stateVariables.addElement(new SensStateVariable((SensVariable) sensVariables.elementAt(v), rateSensitivity, jacobian, sensVariables, simSymbolTable));
}
if (stateVariables.size() == 0) {
throw new MathException("there are no equations defined");
}
StateVariable[] stateVars = (StateVariable[]) BeanUtils.getArray(stateVariables, StateVariable.class);
return (stateVars);
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class OdeFileWriter method createStateVariables.
private void createStateVariables() throws Exception {
Simulation simulation = simTask.getSimulation();
MathDescription mathDescription = simulation.getMathDescription();
SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
// get Ode's from MathDescription and create ODEStateVariables
Enumeration<Equation> enum1 = mathDescription.getSubDomains().nextElement().getEquations();
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
while (enum1.hasMoreElements()) {
Equation equation = enum1.nextElement();
if (equation instanceof OdeEquation) {
fieldStateVariables.addElement(new ODEStateVariable((OdeEquation) equation, simSymbolTable));
} else {
throw new MathException("encountered non-ode equation, unsupported");
}
}
// Get sensitivity variables
Variable[] variables = simSymbolTable.getVariables();
Vector<SensVariable> sensVariables = new Vector<SensVariable>();
Constant sensitivityParameter = solverTaskDescription.getSensitivityParameter();
if (sensitivityParameter != null) {
Constant origSensParam = sensitivityParameter;
Constant overriddenSensParam = (Constant) simSymbolTable.getVariable(origSensParam.getName());
for (int i = 0; i < variables.length; i++) {
if (variables[i] instanceof VolVariable) {
VolVariable volVariable = (VolVariable) variables[i];
SensVariable sv = new SensVariable(volVariable, overriddenSensParam);
sensVariables.addElement(sv);
}
}
}
if (rateSensitivity == null) {
rateSensitivity = new RateSensitivity(mathDescription, mathDescription.getSubDomains().nextElement());
}
if (jacobian == null) {
jacobian = new Jacobian(mathDescription, mathDescription.getSubDomains().nextElement());
}
// get Jacobian and RateSensitivities from MathDescription and create SensStateVariables
for (int v = 0; v < sensVariables.size(); v++) {
fieldStateVariables.addElement(new SensStateVariable(sensVariables.elementAt(v), rateSensitivity, jacobian, sensVariables, simSymbolTable));
}
}
use of cbit.vcell.math.Variable in project vcell by virtualcell.
the class MovingBoundaryFileWriter method flattenExpression.
private Expression flattenExpression(Expression ex, VariableDomain varDomain) throws ExpressionException, MathException {
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
Variable normalX = new Variable("normalX", null) {
public boolean compareEqual(Matchable object, boolean bIgnoreMissingDomains) {
return false;
}
public String getVCML() throws MathException {
return null;
}
};
Variable normalY = new Variable("normalY", null) {
public boolean compareEqual(Matchable object, boolean bIgnoreMissingDomains) {
return false;
}
public String getVCML() throws MathException {
return null;
}
};
SymbolTable augmentedSymbolTable = new SymbolTable() {
@Override
public SymbolTableEntry getEntry(String identifierString) {
if (identifierString.equals(normalX.getName())) {
return normalX;
}
if (identifierString.equals(normalY.getName())) {
return normalY;
}
return simSymbolTable.getEntry(identifierString);
}
@Override
public void getEntries(Map<String, SymbolTableEntry> entryMap) {
simSymbolTable.getEntries(entryMap);
entryMap.put(normalX.getName(), normalX);
entryMap.put(normalY.getName(), normalY);
}
};
ex = new Expression(ex);
ex.bindExpression(augmentedSymbolTable);
Expression flattended = MathUtilities.substituteFunctions(ex, augmentedSymbolTable).flatten();
Expression substituted = SolverUtilities.substituteSizeAndNormalFunctions(flattended, varDomain).flatten();
return substituted;
// return simSymbolTable.substituteFunctions(ex).flatten().infix();
}
Aggregations