use of cbit.vcell.math.SubDomain in project vcell by virtualcell.
the class StochFileWriter method write.
/**
* Write the model to a text file which serves as an input for Stochastic simulation engine.
* Creation date: (6/22/2006 5:37:26 PM)
*/
public void write(String[] parameterNames) throws Exception, ExpressionException {
Simulation simulation = simTask.getSimulation();
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
initialize();
if (bUseMessaging) {
writeJMSParamters();
}
// Write control information
printWriter.println("<control>");
cbit.vcell.solver.SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
cbit.vcell.solver.TimeBounds timeBounds = solverTaskDescription.getTimeBounds();
cbit.vcell.solver.OutputTimeSpec outputTimeSpec = solverTaskDescription.getOutputTimeSpec();
ErrorTolerance errorTolerance = solverTaskDescription.getErrorTolerance();
NonspatialStochSimOptions stochOpt = solverTaskDescription.getStochOpt();
printWriter.println("STARTING_TIME" + "\t" + timeBounds.getStartingTime());
printWriter.println("ENDING_TIME " + "\t" + timeBounds.getEndingTime());
// pw.println("MAX_ITERATION"+"\t"+outputTimeSpec.getKeepAtMost());
printWriter.println("TOLERANCE " + "\t" + errorTolerance.getAbsoluteErrorTolerance());
if (outputTimeSpec.isDefault()) {
printWriter.println("SAMPLE_INTERVAL" + "\t" + ((DefaultOutputTimeSpec) outputTimeSpec).getKeepEvery());
printWriter.println("MAX_SAVE_POINTS" + "\t" + ((DefaultOutputTimeSpec) outputTimeSpec).getKeepAtMost());
} else if (outputTimeSpec.isUniform()) {
printWriter.println("SAVE_PERIOD" + "\t" + ((UniformOutputTimeSpec) outputTimeSpec).getOutputTimeStep());
}
printWriter.println("NUM_TRIAL" + "\t" + solverTaskDescription.getStochOpt().getNumOfTrials());
if (stochOpt.isUseCustomSeed()) {
printWriter.println("SEED" + "\t" + stochOpt.getCustomSeed());
} else {
// we generate our own random seed
RandomDataGenerator rdg = new RandomDataGenerator();
int randomSeed = rdg.nextInt(1, Integer.MAX_VALUE);
printWriter.println("SEED" + "\t" + randomSeed);
}
printWriter.println("</control>");
printWriter.println();
// write model information
// Model info. will be extracted from subDomain of mathDescription
Enumeration<SubDomain> e = simulation.getMathDescription().getSubDomains();
SubDomain subDomain = null;
if (e.hasMoreElements()) {
subDomain = e.nextElement();
}
if (subDomain != null) {
printWriter.println("<model>");
// variables
printWriter.println("<discreteVariables>");
// Species iniCondition (if in concentration) is sampled from a poisson distribution(which has a mean of the current iniExp value)
// There is only one subDomain for compartmental model
List<VarIniCondition> varInis = subDomain.getVarIniConditions();
if ((varInis != null) && (varInis.size() > 0)) {
RandomDataGenerator dist = new RandomDataGenerator();
if (simulation.getSolverTaskDescription().getStochOpt().isUseCustomSeed()) {
Integer randomSeed = simulation.getSolverTaskDescription().getStochOpt().getCustomSeed();
if (randomSeed != null) {
dist.reSeed(randomSeed);
}
}
printWriter.println("TotalVars" + "\t" + varInis.size());
for (VarIniCondition varIniCondition : varInis) {
try {
Expression iniExp = varIniCondition.getIniVal();
iniExp.bindExpression(simSymbolTable);
iniExp = simSymbolTable.substituteFunctions(iniExp).flatten();
double expectedCount = iniExp.evaluateConstant();
// 1000 mill
final Integer limit = 1000000000;
if (limit < expectedCount) {
String eMessage = "The Initial count for Species '" + varIniCondition.getVar().getName() + "' is " + BigDecimal.valueOf(expectedCount).toBigInteger() + "\n";
eMessage += "which is higher than the internal vCell limit of " + limit + ".\n";
eMessage += "Please reduce the Initial Condition value for this Species or reduce the compartment size.";
throw new MathFormatException(eMessage);
}
long varCount = 0;
if (varIniCondition instanceof VarIniCount) {
varCount = (long) expectedCount;
} else {
if (expectedCount > 0) {
varCount = dist.nextPoisson(expectedCount);
}
}
// System.out.println("expectedCount: " + expectedCount + ", varCount: " + varCount);
printWriter.println(varIniCondition.getVar().getName() + "\t" + varCount);
} catch (ExpressionException ex) {
ex.printStackTrace();
throw new MathFormatException("variable " + varIniCondition.getVar().getName() + "'s initial condition is required to be a constant.");
}
}
} else
printWriter.println("TotalVars" + "\t" + "0");
printWriter.println("</discreteVariables>");
printWriter.println();
// jump processes
printWriter.println("<jumpProcesses>");
List<JumpProcess> jumpProcesses = subDomain.getJumpProcesses();
if ((jumpProcesses != null) && (jumpProcesses.size() > 0)) {
printWriter.println("TotalProcesses" + "\t" + jumpProcesses.size());
for (int i = 0; i < jumpProcesses.size(); i++) {
printWriter.println(jumpProcesses.get(i).getName());
}
} else
printWriter.println("TotalProcesses" + "\t" + "0");
printWriter.println("</jumpProcesses>");
printWriter.println();
// process description
printWriter.println("<processDesc>");
if ((jumpProcesses != null) && (jumpProcesses.size() > 0)) {
printWriter.println("TotalDescriptions" + "\t" + jumpProcesses.size());
for (int i = 0; i < jumpProcesses.size(); i++) {
JumpProcess temProc = (JumpProcess) jumpProcesses.get(i);
// jump process name
printWriter.println("JumpProcess" + "\t" + temProc.getName());
Expression probExp = temProc.getProbabilityRate();
try {
probExp.bindExpression(simSymbolTable);
probExp = simSymbolTable.substituteFunctions(probExp).flatten();
if (!isValidProbabilityExpression(probExp)) {
throw new MathFormatException("probability rate in jump process " + temProc.getName() + " has illegal symbols(should only contain variable names).");
}
} catch (cbit.vcell.parser.ExpressionException ex) {
ex.printStackTrace();
throw new cbit.vcell.parser.ExpressionException("Binding math description error in probability rate in jump process " + temProc.getName() + ". Some symbols can not be resolved.");
}
// Expression temp = replaceVarIniInProbability(probExp);
// Propensity
printWriter.println("\t" + "Propensity" + "\t" + probExp.infix());
// effects
printWriter.println("\t" + "Effect" + "\t" + temProc.getActions().size());
for (int j = 0; j < temProc.getActions().size(); j++) {
printWriter.print("\t\t" + ((Action) temProc.getActions().get(j)).getVar().getName() + "\t" + ((Action) temProc.getActions().get(j)).getOperation());
printWriter.println("\t" + ((Action) temProc.getActions().get(j)).evaluateOperand());
printWriter.println();
}
// dependencies
Vector<String> dependencies = getDependencies(temProc, jumpProcesses);
if ((dependencies != null) && (dependencies.size() > 0)) {
printWriter.println("\t" + "DependentProcesses" + "\t" + dependencies.size());
for (int j = 0; j < dependencies.size(); j++) printWriter.println("\t\t" + dependencies.elementAt(j));
} else
printWriter.println("\t" + "DependentProcesses" + "\t" + "0");
printWriter.println();
}
} else
printWriter.println("TotalDescriptions" + "\t" + "0");
printWriter.println("</processDesc>");
printWriter.println("</model>");
}
// if (subDomain != null)
}
use of cbit.vcell.math.SubDomain in project vcell by virtualcell.
the class MathTestingUtilities method constructOdesForSensitivity.
//
// This method is used to solve for sensitivity of variables to a given parameter.
// The mathDescription and the sensitivity parameter are passed as arguments.
// New variables and ODEs are constructed according to the rule listed below and are added to the mathDescription.
// The method returns the modified mathDescription.
//
public static MathDescription constructOdesForSensitivity(MathDescription mathDesc, Constant sensParam) throws ExpressionException, MathException, MappingException {
//
// For each ODE :
//
// dX/dt = F(X, P)
//
// (where P is the sensitivity parameter)
//
// we create two other ODEs :
//
// dX_1/dt = F(X_1, P_1) and
//
// dX_2/dt = F(X_2, P_2)
//
// where P_1 = P + epsilon, and
// P_2 = P - epsilon.
//
// We keep the initial conditions for both the new ODEs to be the same,
// i.e., X_1_init = X_2_init.
//
// Then, solving for X_1 & X_2, sensitivity of X wrt P can be computed as :
//
// dX = (X_1 - X_2)
// -- ----------- .
// dP (P_1 - P_2)
//
//
// REMOVE PRINTS AFTER CHECKING !!!
System.out.println(" \n\n------------ Old Math Description -----------------");
System.out.println(mathDesc.getVCML_database());
if (mathDesc.getGeometry().getDimension() > 0) {
throw new RuntimeException("Suppport for Spatial systems not yet implemented.");
}
VariableHash varHash = new VariableHash();
Enumeration<Variable> enumVar = mathDesc.getVariables();
while (enumVar.hasMoreElements()) {
varHash.addVariable(enumVar.nextElement());
}
//
// Get 2 values of senstivity parameter (P + epsilon) & (P - epsilon)
//
Constant epsilon = new Constant("epsilon", new Expression(sensParam.getConstantValue() * 1e-3));
Constant sensParam1 = new Constant(sensParam.getName() + "_1", new Expression(sensParam.getConstantValue() + epsilon.getConstantValue()));
Constant sensParam2 = new Constant(sensParam.getName() + "_2", new Expression(sensParam.getConstantValue() - epsilon.getConstantValue()));
//
// Iterate through each subdomain (only 1 in compartmental case), and each equation in the subdomain
//
Enumeration<SubDomain> subDomainEnum = mathDesc.getSubDomains();
//
// Create a vector of equations to store the 2 equations for each ODE variable in the subdomain.
// Later, add it to the equations list in the subdomain.
//
Vector<Equation> equnsVector = new Vector<Equation>();
Vector<Variable> varsVector = new Vector<Variable>();
Vector<Variable> var1s = new Vector<Variable>();
Vector<Variable> var2s = new Vector<Variable>();
while (subDomainEnum.hasMoreElements()) {
SubDomain subDomain = subDomainEnum.nextElement();
Enumeration<Equation> equationEnum = subDomain.getEquations();
Domain domain = new Domain(subDomain);
while (equationEnum.hasMoreElements()) {
Equation equation = equationEnum.nextElement();
if (equation instanceof OdeEquation) {
OdeEquation odeEquation = (OdeEquation) equation;
// Similar to substituteWithExactSolutions, to bind and substitute functions in the ODE
Expression substitutedRateExp = substituteFunctions(odeEquation.getRateExpression(), mathDesc);
String varName = odeEquation.getVariable().getName();
VolVariable var = new VolVariable(varName, domain);
varsVector.addElement(var);
//
// Create the variable var1, and get the initExpr and rateExpr from the original ODE.
// Substitute the new vars (var1 and param1) in the old initExpr and rateExpr and create a new ODE
//
String varName1 = new String("__" + varName + "_1");
Expression initExpr1 = odeEquation.getInitialExpression();
Expression rateExpr1 = new Expression(substitutedRateExp);
rateExpr1.substituteInPlace(new Expression(varName), new Expression(varName1));
rateExpr1.substituteInPlace(new Expression(sensParam.getName()), new Expression(sensParam1.getName()));
VolVariable var1 = new VolVariable(varName1, domain);
var1s.addElement(var1);
OdeEquation odeEqun1 = new OdeEquation(var1, initExpr1, rateExpr1);
equnsVector.addElement(odeEqun1);
//
// Create the variable var2, and get the initExpr and rateExpr from the original ODE.
// Substitute the new vars (var2 and param2) in the old initExpr and rateExpr and create a new ODE
//
String varName2 = new String("__" + varName + "_2");
Expression initExpr2 = odeEquation.getInitialExpression();
Expression rateExpr2 = new Expression(substitutedRateExp);
rateExpr2.substituteInPlace(new Expression(varName), new Expression(varName2));
rateExpr2.substituteInPlace(new Expression(sensParam.getName()), new Expression(sensParam2.getName()));
VolVariable var2 = new VolVariable(varName2, domain);
var2s.addElement(var2);
OdeEquation odeEqun2 = new OdeEquation(var2, initExpr2, rateExpr2);
equnsVector.addElement(odeEqun2);
//
// Create a function for the sensitivity function expression (X1-X2)/(P1-P2), and save in varHash
//
Expression diffVar = Expression.add(new Expression(var1.getName()), Expression.negate(new Expression(var2.getName())));
Expression diffParam = Expression.add(new Expression(sensParam1.getName()), Expression.negate(new Expression(sensParam2.getName())));
Expression sensitivityExpr = Expression.mult(diffVar, Expression.invert(diffParam));
Function sens_Func = new Function("__sens" + varName + "_wrt_" + sensParam.getName(), sensitivityExpr, domain);
varHash.addVariable(epsilon);
varHash.addVariable(sensParam1);
varHash.addVariable(sensParam2);
varHash.addVariable(var1);
varHash.addVariable(var2);
varHash.addVariable(sens_Func);
} else {
// sensitivity not implemented for PDEs or other equation types.
throw new RuntimeException("SolverTest.constructedExactMath(): equation type " + equation.getClass().getName() + " not yet implemented");
}
}
//
// Need to substitute the new variables in the new ODEs.
// i.e., if Rate Expr for ODE_1 for variable X_1 contains variable Y, variable Z, etc.
// Rate Expr is already substituted with X_1, but it also needs substitute Y with Y_1, Z with Z_1, etc.
// So get the volume variables, from the vectors for vars, var_1s and var_2s
// Substitute the rate expressions for the newly added ODEs in equnsVector.
//
Variable[] vars = (Variable[]) BeanUtils.getArray(varsVector, Variable.class);
Variable[] var_1s = (Variable[]) BeanUtils.getArray(var1s, Variable.class);
Variable[] var_2s = (Variable[]) BeanUtils.getArray(var2s, Variable.class);
Vector<Equation> newEqunsVector = new Vector<Equation>();
for (int i = 0; i < equnsVector.size(); i++) {
Equation equn = equnsVector.elementAt(i);
Expression initEx = equn.getInitialExpression();
Expression rateEx = equn.getRateExpression();
for (int j = 0; j < vars.length; j++) {
if (equn.getVariable().getName().endsWith("_1")) {
rateEx.substituteInPlace(new Expression(vars[j].getName()), new Expression(var_1s[j].getName()));
} else if (equn.getVariable().getName().endsWith("_2")) {
rateEx.substituteInPlace(new Expression(vars[j].getName()), new Expression(var_2s[j].getName()));
}
}
OdeEquation odeEqun = new OdeEquation(equn.getVariable(), initEx, rateEx);
newEqunsVector.addElement(odeEqun);
}
//
for (int i = 0; i < newEqunsVector.size(); i++) {
mathDesc.getSubDomain(subDomain.getName()).addEquation((Equation) newEqunsVector.elementAt(i));
}
//
// FAST SYSTEM
// If the subdomain has a fast system, create a new fast system by substituting the high-low variables/parameters
// in the expressions for the fastInvariants and fastRates and adding them to the fast system.
//
Vector<FastInvariant> invarsVector = new Vector<FastInvariant>();
Vector<FastRate> ratesVector = new Vector<FastRate>();
Enumeration<FastInvariant> fastInvarsEnum = null;
Enumeration<FastRate> fastRatesEnum = null;
// Get the fast invariants and fast rates in the system.
FastSystem fastSystem = subDomain.getFastSystem();
if (fastSystem != null) {
fastInvarsEnum = fastSystem.getFastInvariants();
fastRatesEnum = fastSystem.getFastRates();
//
while (fastInvarsEnum.hasMoreElements()) {
FastInvariant fastInvar = fastInvarsEnum.nextElement();
Expression fastInvarExpr = fastInvar.getFunction();
fastInvarExpr = MathUtilities.substituteFunctions(fastInvarExpr, mathDesc);
Expression fastInvarExpr1 = new Expression(fastInvarExpr);
Expression fastInvarExpr2 = new Expression(fastInvarExpr);
for (int i = 0; i < vars.length; i++) {
fastInvarExpr1.substituteInPlace(new Expression(vars[i].getName()), new Expression(var_1s[i].getName()));
fastInvarExpr2.substituteInPlace(new Expression(vars[i].getName()), new Expression(var_2s[i].getName()));
}
fastInvarExpr1.substituteInPlace(new Expression(sensParam.getName()), new Expression(sensParam1.getName()));
FastInvariant fastInvar1 = new FastInvariant(fastInvarExpr1);
invarsVector.addElement(fastInvar1);
fastInvarExpr2.substituteInPlace(new Expression(sensParam.getName()), new Expression(sensParam2.getName()));
FastInvariant fastInvar2 = new FastInvariant(fastInvarExpr2);
invarsVector.addElement(fastInvar2);
}
// Add the newly created fast invariants to the existing list of fast invariants in the fast system.
for (int i = 0; i < invarsVector.size(); i++) {
FastInvariant inVar = (FastInvariant) invarsVector.elementAt(i);
fastSystem.addFastInvariant(inVar);
}
//
while (fastRatesEnum.hasMoreElements()) {
FastRate fastRate = fastRatesEnum.nextElement();
Expression fastRateExpr = fastRate.getFunction();
fastRateExpr = MathUtilities.substituteFunctions(fastRateExpr, mathDesc);
Expression fastRateExpr1 = new Expression(fastRateExpr);
Expression fastRateExpr2 = new Expression(fastRateExpr);
for (int i = 0; i < vars.length; i++) {
fastRateExpr1.substituteInPlace(new Expression(vars[i].getName()), new Expression(var_1s[i].getName()));
fastRateExpr2.substituteInPlace(new Expression(vars[i].getName()), new Expression(var_2s[i].getName()));
}
fastRateExpr1.substituteInPlace(new Expression(sensParam.getName()), new Expression(sensParam1.getName()));
FastRate fastRate1 = new FastRate(fastRateExpr1);
ratesVector.addElement(fastRate1);
fastRateExpr2.substituteInPlace(new Expression(sensParam.getName()), new Expression(sensParam2.getName()));
FastRate fastRate2 = new FastRate(fastRateExpr2);
ratesVector.addElement(fastRate2);
}
// Add the newly created fast rates to the existing list of fast rates in the fast system.
for (int i = 0; i < ratesVector.size(); i++) {
FastRate rate = (FastRate) ratesVector.elementAt(i);
fastSystem.addFastRate(rate);
}
}
}
// Reset all variables in mathDesc.
mathDesc.setAllVariables(varHash.getAlphabeticallyOrderedVariables());
// REMOVE PRINTS AFTER CHECKING
System.out.println(" \n\n------------ New Math Description -----------------");
System.out.println(mathDesc.getVCML_database());
return mathDesc;
}
use of cbit.vcell.math.SubDomain in project vcell by virtualcell.
the class ConstructedSolutionTemplate method initialize.
/**
* Insert the method's description here.
* Creation date: (5/12/2003 11:04:13 AM)
* @param mathDesc cbit.vcell.math.MathDescription
*/
private void initialize(cbit.vcell.math.MathDescription mathDesc) {
//
// for all valid combinations of variables/domains ... add a solution template with a default solution.
//
java.util.Vector solutionTemplateList = new java.util.Vector();
Enumeration enumSubDomains = mathDesc.getSubDomains();
while (enumSubDomains.hasMoreElements()) {
SubDomain subDomain = (SubDomain) enumSubDomains.nextElement();
Enumeration enumEquations = subDomain.getEquations();
while (enumEquations.hasMoreElements()) {
Equation equation = (Equation) enumEquations.nextElement();
Variable var = equation.getVariable();
String baseName = " " + var.getName() + "_" + subDomain.getName();
String amplitudeName = baseName + "_A";
String tau1Name = baseName + "_tau1";
String tau2Name = baseName + "_tau2";
if (equation instanceof OdeEquation) {
try {
Expression exp = new Expression(amplitudeName + " * (1.0 + exp(-t/" + tau1Name + ")*sin(2*" + Math.PI + "/" + tau2Name + "*t))");
solutionTemplateList.add(new SolutionTemplate(equation.getVariable().getName(), subDomain.getName(), exp));
} catch (cbit.vcell.parser.ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
} else if (equation instanceof PdeEquation) {
try {
Expression exp = new Expression(amplitudeName + " * (1.0 + exp(-t/" + tau1Name + ") + " + tau2Name + "*x)");
solutionTemplateList.add(new SolutionTemplate(equation.getVariable().getName(), subDomain.getName(), exp));
} catch (cbit.vcell.parser.ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
}
}
this.solutionTemplates = (SolutionTemplate[]) org.vcell.util.BeanUtils.getArray(solutionTemplateList, SolutionTemplate.class);
}
use of cbit.vcell.math.SubDomain in project vcell by virtualcell.
the class SimulationWorkspace method getEstimatedNumTimePointsForStoch.
private static long getEstimatedNumTimePointsForStoch(SimulationSymbolTable simSymbolTable) {
Simulation sim = simSymbolTable.getSimulation();
SolverTaskDescription solverTaskDescription = sim.getSolverTaskDescription();
TimeBounds tb = solverTaskDescription.getTimeBounds();
double startTime = tb.getStartingTime();
double endTime = tb.getEndingTime();
OutputTimeSpec tSpec = solverTaskDescription.getOutputTimeSpec();
// hybrid G_E and G_M are fixed time step methods using uniform output time spec
if (tSpec.isUniform()) {
double outputTimeStep = ((UniformOutputTimeSpec) tSpec).getOutputTimeStep();
return (long) ((endTime - startTime) / outputTimeStep);
}
double maxProbability = 0;
SubDomain subDomain = sim.getMathDescription().getSubDomains().nextElement();
List<VarIniCondition> varInis = subDomain.getVarIniConditions();
// get all the probability expressions
ArrayList<Expression> probList = new ArrayList<Expression>();
for (JumpProcess jp : subDomain.getJumpProcesses()) {
probList.add(jp.getProbabilityRate());
}
// loop through probability expressions
for (int i = 0; i < probList.size(); i++) {
try {
Expression pExp = new Expression(probList.get(i));
pExp.bindExpression(simSymbolTable);
pExp = simSymbolTable.substituteFunctions(pExp);
pExp = pExp.flatten();
String[] symbols = pExp.getSymbols();
// substitute stoch vars with it's initial condition expressions
if (symbols != null) {
for (int j = 0; symbols != null && j < symbols.length; j++) {
for (int k = 0; k < varInis.size(); k++) {
if (symbols[j].equals(varInis.get(k).getVar().getName())) {
pExp.substituteInPlace(new Expression(symbols[j]), new Expression(varInis.get(k).getIniVal()));
break;
}
}
}
}
pExp = simSymbolTable.substituteFunctions(pExp);
pExp = pExp.flatten();
double val = pExp.evaluateConstant();
if (maxProbability < val) {
maxProbability = val;
}
} catch (ExpressionBindingException e) {
System.out.println("Cannot estimate the total time points for stochastic simulation!! Due to the reason below...");
e.printStackTrace();
} catch (ExpressionException ex) {
System.out.println("Cannot estimate the total time points for stochastic simulation!! Due to the reason below...");
ex.printStackTrace();
} catch (MathException e) {
System.out.println("Cannot estimate the total time points for stochastic simulation!! Due to the reason below...");
e.printStackTrace();
}
}
int keepEvery = 1;
if (tSpec.isDefault()) {
keepEvery = ((DefaultOutputTimeSpec) tSpec).getKeepEvery();
}
// points = (endt-startt)/(t*keepEvery) = (endt - startt)/(keepEvery*1/prob)
long estimatedPoints = Math.round((tb.getEndingTime() - tb.getStartingTime()) * maxProbability / keepEvery) + 1;
return estimatedPoints;
}
use of cbit.vcell.math.SubDomain in project vcell by virtualcell.
the class MathDescriptionCellRenderer method getTreeCellRendererComponent.
/**
* Insert the method's description here.
* Creation date: (7/27/2000 6:41:57 PM)
* @return java.awt.Component
*/
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
JLabel component = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
boolean bLoaded = false;
//
try {
if (value instanceof BioModelNode) {
BioModelNode node = (BioModelNode) value;
if (node.getUserObject() instanceof PdeEquation) {
PdeEquation pdeEquation = (PdeEquation) node.getUserObject();
Variable var = pdeEquation.getVariable();
component.setToolTipText("PDE Equation");
// \u2207 = nabla ... del operator
// \u2219 = dot
String DEL = "\u2207";
// "\u2202"; // '\u2202' is partial differentiation 'd' is regular diff
String PARTIAL_DIFF = "d";
String Super2 = "\u00b2";
String DOT = "\u2219";
// String diffusionTerm = DEL+" "+DOT+" "+"("+pdeEquation.getDiffusionExpression()+" "+DEL+" "+var.getName()+")";
String diffusionTerm = "";
if (pdeEquation.getVelocityX() != null || pdeEquation.getVelocityY() != null || pdeEquation.getVelocityZ() != null) {
if (pdeEquation.getDiffusionExpression().isZero()) {
// reaction/advection
diffusionTerm = "- " + DEL + " " + DOT + "( velocity " + var.getName() + " )";
} else {
// reaction/diffusion/advection
diffusionTerm = DEL + " " + DOT + " (" + pdeEquation.getDiffusionExpression().infix() + " " + DEL + " " + var.getName() + " - velocity " + var.getName() + ")";
}
} else {
diffusionTerm = "(" + pdeEquation.getDiffusionExpression().infix() + ") " + DEL + Super2 + " " + var.getName();
}
String gradTerm = "";
if (pdeEquation.getGradientX() != null && !pdeEquation.getGradientX().isZero()) {
gradTerm += " + " + PARTIAL_DIFF + "[" + pdeEquation.getGradientX().infix() + "]/" + PARTIAL_DIFF + "x";
}
if (pdeEquation.getGradientY() != null && !pdeEquation.getGradientY().isZero()) {
gradTerm += " + " + PARTIAL_DIFF + "[" + pdeEquation.getGradientY().infix() + "]/" + PARTIAL_DIFF + "y";
}
if (pdeEquation.getGradientZ() != null && !pdeEquation.getGradientZ().isZero()) {
gradTerm += " + " + PARTIAL_DIFF + "[" + pdeEquation.getGradientZ().infix() + "]/" + PARTIAL_DIFF + "z";
}
String sourceTerm = pdeEquation.getRateExpression().infix();
if (!sourceTerm.equals("0.0")) {
component.setText(PARTIAL_DIFF + "[" + var.getName() + "]/" + PARTIAL_DIFF + "t = " + diffusionTerm + gradTerm + " + " + sourceTerm);
} else {
component.setText(PARTIAL_DIFF + "[" + var.getName() + "]/" + PARTIAL_DIFF + "t = " + diffusionTerm + gradTerm);
}
} else if (node.getUserObject() instanceof OdeEquation) {
OdeEquation odeEquation = (OdeEquation) node.getUserObject();
Variable var = odeEquation.getVariable();
component.setToolTipText("ODE Equation");
component.setText("d[" + var.getName() + "]/dt = " + odeEquation.getRateExpression().infix());
} else if (node.getUserObject() instanceof MembraneRegionEquation) {
MembraneRegionEquation membraneRegionEquation = (MembraneRegionEquation) node.getUserObject();
Variable var = membraneRegionEquation.getVariable();
component.setToolTipText("Membrane Region Equation");
component.setText("Membrane Region Equation for " + var.getName());
} else if (node.getUserObject() instanceof JumpCondition) {
JumpCondition jumpCondition = (JumpCondition) node.getUserObject();
Variable var = jumpCondition.getVariable();
component.setToolTipText("Jump Condition");
component.setText("Flux for " + var.getName());
} else if (node.getUserObject() instanceof Constant) {
Constant constant = (Constant) node.getUserObject();
component.setToolTipText("Constant");
component.setText(constant.getName() + " = " + constant.getExpression().infix());
} else if (node.getUserObject() instanceof Function) {
Function function = (Function) node.getUserObject();
component.setToolTipText("Function");
component.setText(function.getName() + " = " + function.getExpression().infix());
} else if (node.getUserObject() instanceof SubDomain) {
SubDomain subDomain = (SubDomain) node.getUserObject();
component.setToolTipText("SubDomain");
component.setText(subDomain.getName());
} else if (node.getUserObject() instanceof FastSystem) {
component.setToolTipText("Fast System");
component.setText("Fast System");
} else if (node.getUserObject() instanceof FastInvariant) {
FastInvariant fi = (FastInvariant) node.getUserObject();
component.setToolTipText("Fast Invariant");
component.setText("fast invariant: " + fi.getFunction().infix());
} else if (node.getUserObject() instanceof FastRate) {
FastRate fr = (FastRate) node.getUserObject();
component.setToolTipText("Fast Rate");
component.setText("fast rate: " + fr.getFunction().infix());
} else if (node.getUserObject() instanceof Annotation) {
Annotation annotation = (Annotation) node.getUserObject();
component.setToolTipText("Annotation");
component.setText("\"" + annotation + "\"");
} else {
}
if (selectedFont == null && component.getFont() != null) {
selectedFont = component.getFont().deriveFont(Font.BOLD);
}
if (unselectedFont == null && component.getFont() != null) {
unselectedFont = component.getFont().deriveFont(Font.PLAIN);
}
if (bLoaded) {
component.setFont(selectedFont);
} else {
component.setFont(unselectedFont);
}
}
} catch (Throwable e) {
e.printStackTrace(System.out);
}
//
return component;
}
Aggregations