use of cbit.vcell.math.OdeEquation in project vcell by virtualcell.
the class XmlReader method getOdeEquation.
/**
* This method returns an OdeEquation from a XML Element.
* Creation date: (5/17/2001 3:52:40 PM)
* @return cbit.vcell.math.OdeEquation
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
private OdeEquation getOdeEquation(Element param, MathDescription mathDesc) throws XmlParseException {
// get attributes
String varname = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
// find reference in the dictionnary
// try as a VolVariable
Variable varref = mathDesc.getVariable(varname);
// Make sure that the reference is not empty!!!
if (varref == null) {
throw new XmlParseException("The reference to the variable " + varname + " in a OdeEquation could not be resolved!");
}
// get Initial condition
String temp = param.getChildText(XMLTags.InitialTag, vcNamespace);
Expression initialexp = null;
if (temp != null && temp.length() > 0) {
initialexp = unMangleExpression(temp);
}
// Get Rate condition
temp = param.getChildText(XMLTags.RateTag, vcNamespace);
Expression rateexp = null;
if (temp != null && temp.length() > 0) {
rateexp = unMangleExpression((temp));
}
// --- Create the OdeEquation object ---
OdeEquation odeEquation = new OdeEquation(varref, initialexp, rateexp);
// add specific solutions expressions
String solType = param.getAttributeValue(XMLTags.SolutionTypeTag);
if (solType.equalsIgnoreCase(XMLTags.ExactTypeTag)) {
String solutionExp = param.getChildText(XMLTags.SolutionExpressionTag, vcNamespace);
if (solutionExp != null && solutionExp.length() > 0) {
Expression expression = unMangleExpression(solutionExp);
odeEquation.setExactSolution(expression);
}
}
return odeEquation;
}
use of cbit.vcell.math.OdeEquation in project vcell by virtualcell.
the class XmlReader method getMembraneSubDomain.
/**
* This method returns a MembraneSubDomain object from a XML Element.
* Creation date: (5/18/2001 4:23:30 PM)
* @return cbit.vcell.math.MembraneSubDomain
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
@SuppressWarnings("unchecked")
private MembraneSubDomain getMembraneSubDomain(Element param, MathDescription mathDesc) throws XmlParseException {
// no need to do anything with the 'Name' attribute : constructor of MembraneSubDomain creates name from inside/outside compartmentSubDomains.
// String msdName = unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
// if ( msdName != null) {
// }
// get compartmentSubDomain references
// inside
String name = unMangle(param.getAttributeValue(XMLTags.InsideCompartmentTag));
CompartmentSubDomain insideRef = (CompartmentSubDomain) mathDesc.getCompartmentSubDomain(name);
if (insideRef == null) {
throw new XmlParseException("The reference to the inside CompartmentSubDomain " + name + ", could not be resolved!");
}
// outside
name = unMangle(param.getAttributeValue(XMLTags.OutsideCompartmentTag));
CompartmentSubDomain outsideRef = (CompartmentSubDomain) mathDesc.getCompartmentSubDomain(name);
if (outsideRef == null) {
throw new XmlParseException("The reference to the outside CompartmentSubDomain " + name + ", could not be resolved!");
}
// *** create new Membrane SubDomain ***
SubVolume insideSubVolume = mathDesc.getGeometry().getGeometrySpec().getSubVolume(insideRef.getName());
SubVolume outsideSubVolume = mathDesc.getGeometry().getGeometrySpec().getSubVolume(outsideRef.getName());
SurfaceClass surfaceClass = mathDesc.getGeometry().getGeometrySurfaceDescription().getSurfaceClass(insideSubVolume, outsideSubVolume);
MembraneSubDomain subDomain = new MembraneSubDomain(insideRef, outsideRef, surfaceClass.getName());
transcribeComments(param, subDomain);
// Process BoundaryConditions
Iterator<Element> iterator = param.getChildren(XMLTags.BoundaryTypeTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempelement = (Element) iterator.next();
// create BoundaryConditionType
String temp = tempelement.getAttributeValue(XMLTags.BoundaryTypeAttrTag);
BoundaryConditionType bType = new BoundaryConditionType(temp);
// Process Xm
if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueXm)) {
subDomain.setBoundaryConditionXm(bType);
} else if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueXp)) {
// Process Xp
subDomain.setBoundaryConditionXp(bType);
} else if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueYm)) {
// Process Ym
subDomain.setBoundaryConditionYm(bType);
} else if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueYp)) {
// Process Yp
subDomain.setBoundaryConditionYp(bType);
} else if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueZm)) {
// Process Zm
subDomain.setBoundaryConditionZm(bType);
} else if (tempelement.getAttributeValue(XMLTags.BoundaryAttrTag).equalsIgnoreCase(XMLTags.BoundaryAttrValueZp)) {
// Process Zp
subDomain.setBoundaryConditionZp(bType);
} else {
// If not indentified throw an exception!!
throw new XmlParseException("Unknown BoundaryConditionType: " + tempelement.getAttributeValue(XMLTags.BoundaryAttrTag));
}
}
// Add OdeEquations
iterator = param.getChildren(XMLTags.OdeEquationTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempElement = (Element) iterator.next();
OdeEquation odeEquation = getOdeEquation(tempElement, mathDesc);
try {
subDomain.addEquation(odeEquation);
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding an OdeEquation to a MembraneSubDomain!", e);
}
}
// process PdeEquations
iterator = param.getChildren(XMLTags.PdeEquationTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempElement = (Element) iterator.next();
try {
subDomain.addEquation(getPdeEquation(tempElement, mathDesc));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding an PdeEquation to the MembraneSubDomain " + name, e);
}
}
// Add JumpConditions
iterator = param.getChildren(XMLTags.JumpConditionTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempElement = (Element) iterator.next();
try {
subDomain.addJumpCondition(getJumpCondition(tempElement, mathDesc));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding a JumpCondition to a MembraneSubDomain!", e);
}
}
// Add the FastSystem (if any)
Element tempElement = param.getChild(XMLTags.FastSystemTag, vcNamespace);
if (tempElement != null) {
subDomain.setFastSystem(getFastSystem(tempElement, mathDesc));
}
// add MembraneRegionEquation
iterator = param.getChildren(XMLTags.MembraneRegionEquationTag, vcNamespace).iterator();
while (iterator.hasNext()) {
tempElement = (Element) iterator.next();
try {
subDomain.addEquation(getMembraneRegionEquation(tempElement, mathDesc));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding a MembraneRegionEquation to a MEmbraneSubDomain!", e);
}
}
iterator = param.getChildren(XMLTags.ParticleJumpProcessTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempelement = (Element) iterator.next();
try {
subDomain.addParticleJumpProcess(getParticleJumpProcess(tempelement, mathDesc));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding a jump process to the MembraneSubDomain " + name, e);
}
}
iterator = param.getChildren(XMLTags.ParticlePropertiesTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempelement = (Element) iterator.next();
try {
subDomain.addParticleProperties(getParticleProperties(tempelement, mathDesc));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding a jump process to the MembraneSubDomain " + name, e);
}
}
// process ComputeNormal "equations"
iterator = param.getChildren(XMLTags.ComputeNormalTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempelement = (Element) iterator.next();
try {
subDomain.addEquation(getComputeNormal(tempelement, mathDesc));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding an ComputeNormal 'equation' to the MembraneSubDomain " + name, e);
}
}
Element velElem = param.getChild(XMLTags.VelocityTag, vcNamespace);
setMembraneSubdomainVelocity(velElem, XMLTags.XAttrTag, subDomain::setVelocityX);
setMembraneSubdomainVelocity(velElem, XMLTags.YAttrTag, subDomain::setVelocityY);
return subDomain;
}
use of cbit.vcell.math.OdeEquation in project vcell by virtualcell.
the class CellQuanVCTranslator method addCompartmentSubDomain.
/**
* addCompartmentSubDomain : we pick the variable name by reading through the mathML.
* Redundancy in variable name with the volume variable?
*/
protected void addCompartmentSubDomain() throws Exception {
String csdName = sRoot.getAttributeValue(CELLMLTags.name, sAttNamespace);
CompartmentSubDomain csd = new CompartmentSubDomain(csdName, CompartmentSubDomain.NON_SPATIAL_PRIORITY);
Iterator<?> compElementIter = sRoot.getChildren(CELLMLTags.COMPONENT, sNamespace).iterator();
// JDOMTreeWalker walker = new JDOMTreeWalker(sRoot, new ElementFilter(CELLMLTags.COMPONENT));
Element comp, math;
String compName, varName, mangledName;
while (compElementIter.hasNext()) {
comp = (Element) compElementIter.next();
compName = comp.getAttributeValue(CELLMLTags.name, sAttNamespace);
@SuppressWarnings("unchecked") Iterator<Element> mathIter = comp.getChildren(CELLMLTags.MATH, mathns).iterator();
while (mathIter.hasNext()) {
math = mathIter.next();
Element apply, apply2, apply3, ci;
// allow multiple 'apply' children.
@SuppressWarnings("unchecked") Iterator<Element> applyIter = math.getChildren(MathMLTags.APPLY, mathns).iterator();
while (applyIter.hasNext()) {
apply = applyIter.next();
@SuppressWarnings("unchecked") ArrayList<Element> list = new ArrayList<Element>(apply.getChildren());
if (list.size() < 3)
continue;
if (!(list.get(0)).getName().equals(MathMLTags.EQUAL))
continue;
apply2 = list.get(1);
if (!apply2.getName().equals(MathMLTags.APPLY))
continue;
@SuppressWarnings("unchecked") ArrayList<Element> list2 = new ArrayList<Element>(apply2.getChildren());
if (list2.size() < 3)
continue;
if (!(list2.get(0)).getName().equals(MathMLTags.DIFFERENTIAL))
continue;
// skip the time variable
ci = list2.get(2);
varName = ci.getTextTrim();
// can be a constant
apply3 = list.get(2);
mangledName = nm.getMangledName(compName, varName);
Element trimmedMath = new Element(CELLMLTags.MATH, mathns).addContent(apply3.detach());
fixMathMLBug(trimmedMath);
Expression rateExp = null;
try {
rateExp = (new ExpressionMathMLParser(null)).fromMathML(trimmedMath);
rateExp = processMathExp(comp, rateExp);
rateExp = rateExp.flatten();
nl.mangleString(rateExp.infix());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
Expression initExp = new Expression(getInitial(comp, varName));
Domain domain = null;
OdeEquation ode = new OdeEquation(new VolVariable(mangledName, domain), initExp, rateExp);
csd.addEquation(ode);
}
}
}
mathDescription.addSubDomain(csd);
}
use of cbit.vcell.math.OdeEquation 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.OdeEquation in project vcell by virtualcell.
the class RateSensitivity 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 constantList = new Vector();
enum1 = mathDesc.getVariables();
while (enum1.hasMoreElements()) {
Variable var = (Variable) enum1.nextElement();
if (var instanceof Constant) {
constantList.addElement(var);
}
}
numConstants = constantList.size();
numRates = equationList.size();
rates = new Expression[numRates];
vars = new Variable[numRates];
consts = new Constant[numConstants];
for (int i = 0; i < numRates; i++) {
OdeEquation odeEqu = (OdeEquation) equationList.elementAt(i);
rates[i] = odeEqu.getRateExpression();
vars[i] = odeEqu.getVariable();
}
for (int i = 0; i < numConstants; i++) {
consts[i] = (Constant) constantList.elementAt(i);
}
}
Aggregations