use of cbit.vcell.math.VolVariable 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.VolVariable in project vcell by virtualcell.
the class Jacobian method show.
/**
* This method was created by a SmartGuide.
*/
public void show() throws MathException, ExpressionException {
refresh();
for (int rateIndex = 0; rateIndex < numVariables; rateIndex++) {
for (int varIndex = 0; varIndex < numVariables; varIndex++) {
Expression rateExp = rates[rateIndex];
VolVariable var = vars[varIndex];
Expression J = getJexp(rateIndex, varIndex);
System.out.println("Jacobian of " + vars[rateIndex].getName() + "' wrt " + vars[varIndex].getName() + " is " + J);
}
}
}
use of cbit.vcell.math.VolVariable 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);
}
}
use of cbit.vcell.math.VolVariable in project vcell by virtualcell.
the class SensStateVariable method init.
/**
* This method was created in VisualAge.
* @param rateSensitivity cbit.vcell.math.RateSensitivity
* @param jacobian cbit.vcell.math.Jacobian
*/
private void init(RateSensitivity rateSensitivity, Jacobian jacobian, SymbolTable symbolTable, Vector<SensVariable> sensVarArray) throws MathException, ExpressionException {
//
// order sensVars according to the jacobian (rate index)
//
sensVars = (Vector<SensVariable>) sensVarArray.clone();
for (int i = 0; i < sensVarArray.size(); i++) {
SensVariable sensVar = sensVarArray.elementAt(i);
int index = jacobian.getRateIndex(sensVar.getVolVariable());
sensVars.setElementAt(sensVar, index);
}
//
// given the system
//
//
// d Ci
// ------- = Fi(C1..Cn,P1..Pm)
// d t
//
// where: C's are variables and P's are parameters
//
// jacobian.show();
VolVariable var = ((SensVariable) variable).getVolVariable();
Constant parameter = ((SensVariable) variable).getParameter();
//
// get list of jacobian expressions for this var (Ci)
//
// d Fi
// ------ for all j
// d Cj
//
optimizedJacobianExps = new Expression[jacobian.getNumRates()];
int currIndex = jacobian.getRateIndex(var);
for (int i = 0; i < optimizedJacobianExps.length; i++) {
Expression exp = jacobian.getJexp(currIndex, i);
exp.bindExpression(symbolTable);
optimizedJacobianExps[i] = exp.flatten();
}
//
// get rate sensitivity for this variable (Ci) and the parameter under investigation (Pj)
//
// d Fi
// ------
// d Pj
//
//
Expression exp = rateSensitivity.getCPexp(var, parameter.getName());
exp.bindExpression(symbolTable);
optimizedRateSensExp = exp.flatten();
}
use of cbit.vcell.math.VolVariable in project vcell by virtualcell.
the class ModelOptimizationSpec method removeUncoupledParameters.
public void removeUncoupledParameters() {
try {
localIssueList.clear();
MathMapping mathMapping = getSimulationContext().createNewMathMapping();
MathDescription mathDesc = mathMapping.getMathDescription();
MathSystemHash mathSystemHash = fromMath(mathDesc);
Graph graph = mathSystemHash.getDependencyGraph(mathSystemHash.getSymbols());
Tree[] spanningTrees = graph.getSpanningForest();
//
for (int i = 0; i < spanningTrees.length; i++) {
Node[] treeNodes = spanningTrees[i].getNodes();
boolean bHasStateVariables = false;
for (int j = 0; j < treeNodes.length; j++) {
Node node = treeNodes[j];
Variable var = mathDesc.getVariable(node.getName());
if (var instanceof VolVariable || var instanceof MemVariable || var instanceof FilamentVariable || var instanceof VolumeRegionVariable || var instanceof MembraneRegionVariable || var instanceof FilamentRegionVariable) {
bHasStateVariables = true;
break;
}
}
if (!bHasStateVariables) {
spanningTrees = (Tree[]) BeanUtils.removeElement(spanningTrees, spanningTrees[i]);
i--;
}
}
//
// remove parameters not mapped to a surviving tree (not coupled to any state variables
//
ArrayList<ParameterMappingSpec> paramMappingSpecsList = new ArrayList<ParameterMappingSpec>();
paramMappingSpecsList.addAll(Arrays.asList(fieldParameterMappingSpecs));
for (int i = 0; i < paramMappingSpecsList.size(); i++) {
Parameter parameter = paramMappingSpecsList.get(i).getModelParameter();
String mathName = mathMapping.getMathSymbolMapping().getVariable(parameter).getName();
boolean bFoundInTree = false;
for (int j = 0; j < spanningTrees.length; j++) {
Node node = spanningTrees[j].getNode(mathName);
if (node != null) {
bFoundInTree = true;
}
}
if (!bFoundInTree) {
paramMappingSpecsList.remove(i);
i--;
}
}
ParameterMappingSpec[] parameterMappingSpecs = new ParameterMappingSpec[paramMappingSpecsList.size()];
paramMappingSpecsList.toArray(parameterMappingSpecs);
setParameterMappingSpecs(parameterMappingSpecs);
} catch (Exception e) {
e.printStackTrace(System.out);
localIssueList.add(new Issue(this, localIssueContext, IssueCategory.ParameterEstimationGeneralWarning, e.getMessage(), Issue.SEVERITY_WARNING));
// throw new RuntimeException(e.getMessage());
}
}
Aggregations