use of cbit.vcell.math.MathDescription in project vcell by virtualcell.
the class OutputFunctionContext method propertyChange.
public void propertyChange(java.beans.PropertyChangeEvent event) {
if (event.getSource() == simulationOwner && event.getPropertyName().equals("mathDescription")) {
rebindAll();
}
if (event.getPropertyName().equals("geometry")) {
Geometry oldGeometry = (Geometry) event.getOldValue();
Geometry newGeometry = (Geometry) event.getNewValue();
// changing from ode to pde
if (oldGeometry != null && oldGeometry.getDimension() == 0 && newGeometry.getDimension() > 0) {
ArrayList<AnnotatedFunction> newFuncList = new ArrayList<AnnotatedFunction>();
for (AnnotatedFunction function : outputFunctionsList) {
try {
Expression newexp = new Expression(function.getExpression());
// making sure that output function is not direct function of constant.
newexp.bindExpression(this);
// here use math description as symbol table because we allow
// new expression itself to be function of constant.
MathDescription mathDescription = getSimulationOwner().getMathDescription();
newexp = MathUtilities.substituteFunctions(newexp, mathDescription).flatten();
VariableType newFuncType = VariableType.VOLUME;
String[] symbols = newexp.getSymbols();
if (symbols != null) {
// figure out the function type
VariableType[] varTypes = new VariableType[symbols.length];
for (int i = 0; i < symbols.length; i++) {
Variable var = mathDescription.getVariable(symbols[i]);
varTypes[i] = VariableType.getVariableType(var);
}
// check with flattened expression to find out the variable type of the new expression
Function flattenedFunction = new Function(function.getName(), newexp, function.getDomain());
newFuncType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, getSimulationOwner().getMathDescription(), symbols, varTypes, true);
}
AnnotatedFunction newFunc = new AnnotatedFunction(function.getName(), function.getExpression(), function.getDomain(), "", newFuncType, FunctionCategory.OUTPUTFUNCTION);
newFuncList.add(newFunc);
newFunc.bind(this);
} catch (ExpressionException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
} catch (InconsistentDomainException ex) {
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
try {
setOutputFunctions0(newFuncList);
} catch (PropertyVetoException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
}
}
}
}
use of cbit.vcell.math.MathDescription in project vcell by virtualcell.
the class OutputFunctionContext method getEntry.
public SymbolTableEntry getEntry(java.lang.String identifierString) {
//
// use MathDescription as the primary SymbolTable, just replace the Constants with the overrides.
//
SymbolTableEntry ste = null;
MathDescription mathDescription = simulationOwner.getMathDescription();
if (mathDescription != null) {
ste = mathDescription.getEntry(identifierString);
if (ste != null && !(ste instanceof PseudoConstant) && !(ste instanceof Constant)) {
return ste;
}
ste = mathDescription.getPostProcessingBlock().getDataGenerator(identifierString);
if (ste instanceof DataGenerator) {
return ste;
}
}
// see if it is an output function.
ste = getOutputFunction(identifierString);
return ste;
}
use of cbit.vcell.math.MathDescription in project vcell by virtualcell.
the class Simulation method propertyChange.
public void propertyChange(PropertyChangeEvent evt) {
MathDescription md = getMathDescription();
boolean bIsMath = evt.getSource() == md;
if (bIsMath && evt.getPropertyName().equals("geometry")) {
try {
refreshMeshSpec();
} catch (PropertyVetoException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}
}
use of cbit.vcell.math.MathDescription 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.math.MathDescription in project vcell by virtualcell.
the class OdeFileWriter method writeEvents.
private String writeEvents(HashMap<Discontinuity, String> discontinuityNameMap) throws ExpressionException {
Simulation simulation = simTask.getSimulation();
StringBuffer sb = new StringBuffer();
MathDescription mathDescription = simulation.getMathDescription();
Iterator<Event> iter = mathDescription.getEvents();
sb.append("EVENTS " + mathDescription.getNumEvents() + "\n");
while (iter.hasNext()) {
Event event = iter.next();
sb.append("EVENT " + event.getName() + "\n");
Expression triggerExpression = event.getTriggerExpression();
triggerExpression = MathUtilities.substituteFunctions(triggerExpression, varsSymbolTable).flatten();
Vector<Discontinuity> v = triggerExpression.getDiscontinuities();
for (Discontinuity od : v) {
od = getSubsitutedAndFlattened(od, varsSymbolTable);
String dname = discontinuityNameMap.get(od);
if (dname == null) {
dname = ROOT_VARIABLE_PREFIX + discontinuityNameMap.size();
discontinuityNameMap.put(od, dname);
}
triggerExpression.substituteInPlace(od.getDiscontinuityExp(), new Expression("(" + dname + "==1)"));
}
sb.append("TRIGGER " + triggerExpression.infix() + ";\n");
Delay delay = event.getDelay();
if (delay != null) {
Expression durationExpression = delay.getDurationExpression();
durationExpression = MathUtilities.substituteFunctions(durationExpression, varsSymbolTable).flatten();
sb.append("DELAY " + delay.useValuesFromTriggerTime() + " " + durationExpression.infix() + ";\n");
}
sb.append("EVENTASSIGNMENTS " + event.getNumEventAssignments() + "\n");
Iterator<EventAssignment> iter2 = event.getEventAssignments();
while (iter2.hasNext()) {
EventAssignment eventAssignment = iter2.next();
Expression assignmentExpression = eventAssignment.getAssignmentExpression();
assignmentExpression = MathUtilities.substituteFunctions(assignmentExpression, varsSymbolTable).flatten();
Variable assignmentTarget = eventAssignment.getVariable();
for (int i = 0; i < fieldStateVariables.size(); i++) {
if (assignmentTarget.getName().equals(fieldStateVariables.get(i).getVariable().getName())) {
sb.append(i + " " + assignmentExpression.infix() + ";\n");
break;
}
}
}
}
return sb.toString();
}
Aggregations