use of cbit.vcell.solver.SimulationSymbolTable in project vcell by virtualcell.
the class RunSims method isSmoldynTimeStepOK.
private boolean isSmoldynTimeStepOK(Simulation sim) {
for (int jobIndex = 0; jobIndex < sim.getScanCount(); jobIndex++) {
SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(sim, jobIndex);
double Dmax = 0;
MathDescription mathDesc = sim.getMathDescription();
Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
while (subDomainEnumeration.hasMoreElements()) {
SubDomain subDomain = subDomainEnumeration.nextElement();
// }
for (ParticleProperties particleProperties : subDomain.getParticleProperties()) {
try {
Expression newExp = new Expression(particleProperties.getDiffusion());
newExp.bindExpression(simSymbolTable);
newExp = simSymbolTable.substituteFunctions(newExp).flatten();
try {
double diffConstant = newExp.evaluateConstant();
Dmax = Math.max(Dmax, diffConstant);
} catch (ExpressionException ex) {
throw new ExpressionException("diffusion coefficient for variable " + particleProperties.getVariable().getQualifiedName() + " is not a constant. Constants are required for all diffusion coefficients");
}
} catch (Exception ex) {
}
}
}
double s = sim.getMeshSpecification().getDx(sim.hasCellCenteredMesh());
double dt = sim.getSolverTaskDescription().getTimeStep().getDefaultTimeStep();
if (dt >= s * s / (2 * Dmax)) {
smoldynTimestepVars = new SmoldynTimeStepVars(s, Dmax);
return false;
}
}
return true;
}
use of cbit.vcell.solver.SimulationSymbolTable 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.solver.SimulationSymbolTable in project vcell by virtualcell.
the class DefaultODESolver method getSensitivityParameter.
/**
* Gets the sensitivityParameter property (cbit.vcell.math.Constant) value.
* THIS IS ONLY A CONVENIENCE FUNCTION...AND IT WOULD BE GOOD TO GET RID OF IT
* EVENTUALLY...WHEN YOU HAVE TIME!!!
* @return The sensitivityParameter property value.
* @see #setSensitivityParameter
*/
public Constant getSensitivityParameter() {
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
Constant origSensParam = simSymbolTable.getSimulation().getSolverTaskDescription().getSensitivityParameter();
//
if (origSensParam != null) {
return (Constant) simSymbolTable.getVariable(origSensParam.getName());
} else {
return null;
}
}
use of cbit.vcell.solver.SimulationSymbolTable in project vcell by virtualcell.
the class DefaultODESolver method createStateVariables.
/**
* This method was created in VisualAge.
*/
private Vector<StateVariable> createStateVariables() throws MathException, ExpressionException {
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
Simulation sim = simSymbolTable.getSimulation();
Vector<StateVariable> stateVariables = new Vector<StateVariable>();
// get Ode's from MathDescription and create ODEStateVariables
Enumeration<Equation> enum1 = getSubDomain().getEquations();
while (enum1.hasMoreElements()) {
Equation equation = enum1.nextElement();
if (equation instanceof OdeEquation) {
stateVariables.addElement(new ODEStateVariable((OdeEquation) equation, simSymbolTable));
} else {
throw new MathException("encountered non-ode equation, unsupported");
}
}
MathDescription mathDescription = sim.getMathDescription();
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 < fieldSensVariables.size(); v++) {
stateVariables.addElement(new SensStateVariable(fieldSensVariables.elementAt(v), rateSensitivity, jacobian, fieldSensVariables, simSymbolTable));
}
if (stateVariables.size() == 0) {
throw new MathException("there are no equations defined");
}
return (stateVariables);
}
use of cbit.vcell.solver.SimulationSymbolTable 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