Search in sources :

Example 11 with FastInvariant

use of cbit.vcell.math.FastInvariant 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;
}
Also used : JumpCondition(cbit.vcell.math.JumpCondition) Variable(cbit.vcell.math.Variable) Constant(cbit.vcell.math.Constant) JLabel(javax.swing.JLabel) FastRate(cbit.vcell.math.FastRate) BioModelNode(cbit.vcell.desktop.BioModelNode) FastInvariant(cbit.vcell.math.FastInvariant) Annotation(cbit.vcell.desktop.Annotation) PdeEquation(cbit.vcell.math.PdeEquation) SubDomain(cbit.vcell.math.SubDomain) Function(cbit.vcell.math.Function) OdeEquation(cbit.vcell.math.OdeEquation) FastSystem(cbit.vcell.math.FastSystem) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation)

Example 12 with FastInvariant

use of cbit.vcell.math.FastInvariant in project vcell by virtualcell.

the class MathDescriptionTreeModel method createBaseTree.

/**
 * Insert the method's description here.
 * Creation date: (11/28/00 1:06:51 PM)
 * @return cbit.vcell.desktop.BioModelNode
 * @param docManager cbit.vcell.clientdb.DocumentManager
 */
private BioModelNode createBaseTree() {
    if (getMathDescription() == null) {
        return new BioModelNode(" ", false);
    }
    // 
    // make root node
    // 
    BioModelNode rootNode = new BioModelNode("math description", true);
    // 
    // create subTree of Constants
    // 
    BioModelNode constantRootNode = new BioModelNode("constants", true);
    Enumeration<Constant> enum1 = getMathDescription().getConstants();
    while (enum1.hasMoreElements()) {
        Constant constant = enum1.nextElement();
        BioModelNode constantNode = new BioModelNode(constant, false);
        constantRootNode.add(constantNode);
    }
    if (constantRootNode.getChildCount() > 0) {
        rootNode.add(constantRootNode);
    }
    // 
    // create subTree of Functions
    // 
    BioModelNode functionRootNode = new BioModelNode("functions", true);
    Enumeration<Function> enum2 = getMathDescription().getFunctions();
    while (enum2.hasMoreElements()) {
        Function function = enum2.nextElement();
        BioModelNode functionNode = new BioModelNode(function, false);
        functionRootNode.add(functionNode);
    }
    if (functionRootNode.getChildCount() > 0) {
        rootNode.add(functionRootNode);
    }
    // 
    // create subTree of VolumeSubDomains and MembraneSubDomains
    // 
    BioModelNode volumeRootNode = new BioModelNode("volume domains", true);
    BioModelNode membraneRootNode = new BioModelNode("membrane domains", true);
    Enumeration<SubDomain> enum3 = getMathDescription().getSubDomains();
    while (enum3.hasMoreElements()) {
        SubDomain subDomain = enum3.nextElement();
        if (subDomain instanceof cbit.vcell.math.CompartmentSubDomain) {
            CompartmentSubDomain volumeSubDomain = (CompartmentSubDomain) subDomain;
            BioModelNode volumeSubDomainNode = new BioModelNode(volumeSubDomain, true);
            if (// stochastic subtree
            getMathDescription().isNonSpatialStoch()) {
                // add stoch variable initial conditions
                BioModelNode varIniConditionNode = new BioModelNode("variable_initial_conditions", true);
                for (VarIniCondition varIni : volumeSubDomain.getVarIniConditions()) {
                    BioModelNode varIniNode = new BioModelNode(varIni, false);
                    varIniConditionNode.add(varIniNode);
                }
                volumeSubDomainNode.add(varIniConditionNode);
                // add jump processes
                for (JumpProcess jp : volumeSubDomain.getJumpProcesses()) {
                    BioModelNode jpNode = new BioModelNode(jp, true);
                    // add probability rate.
                    String probRate = "P_" + jp.getName();
                    BioModelNode prNode = new BioModelNode("probability_rate = " + probRate, false);
                    jpNode.add(prNode);
                    // add Actions
                    Enumeration<Action> actions = Collections.enumeration(jp.getActions());
                    while (actions.hasMoreElements()) {
                        Action action = actions.nextElement();
                        BioModelNode actionNode = new BioModelNode(action, false);
                        jpNode.add(actionNode);
                    }
                    volumeSubDomainNode.add(jpNode);
                }
            } else // non-stochastic subtree
            {
                // 
                // add equation children
                // 
                Enumeration<Equation> eqnEnum = volumeSubDomain.getEquations();
                while (eqnEnum.hasMoreElements()) {
                    Equation equation = eqnEnum.nextElement();
                    BioModelNode equationNode = new BioModelNode(equation, false);
                    volumeSubDomainNode.add(equationNode);
                }
                // 
                // add fast system
                // 
                FastSystem fastSystem = volumeSubDomain.getFastSystem();
                if (fastSystem != null) {
                    BioModelNode fsNode = new BioModelNode(fastSystem, true);
                    Enumeration<FastInvariant> enumFI = fastSystem.getFastInvariants();
                    while (enumFI.hasMoreElements()) {
                        FastInvariant fi = enumFI.nextElement();
                        fsNode.add(new BioModelNode(fi, false));
                    }
                    Enumeration<FastRate> enumFR = fastSystem.getFastRates();
                    while (enumFR.hasMoreElements()) {
                        FastRate fr = enumFR.nextElement();
                        fsNode.add(new BioModelNode(fr, false));
                    }
                    volumeSubDomainNode.add(fsNode);
                }
            }
            volumeRootNode.add(volumeSubDomainNode);
        } else if (subDomain instanceof MembraneSubDomain) {
            MembraneSubDomain membraneSubDomain = (MembraneSubDomain) subDomain;
            BioModelNode membraneSubDomainNode = new BioModelNode(membraneSubDomain, true);
            // 
            // add equation children
            // 
            Enumeration<Equation> eqnEnum = membraneSubDomain.getEquations();
            while (eqnEnum.hasMoreElements()) {
                Equation equation = eqnEnum.nextElement();
                BioModelNode equationNode = new BioModelNode(equation, false);
                membraneSubDomainNode.add(equationNode);
            }
            // 
            // add jump condition children
            // 
            Enumeration<JumpCondition> jcEnum = membraneSubDomain.getJumpConditions();
            while (jcEnum.hasMoreElements()) {
                JumpCondition jumpCondition = jcEnum.nextElement();
                BioModelNode jcNode = new BioModelNode(jumpCondition, false);
                membraneSubDomainNode.add(jcNode);
            }
            // 
            // add fast system
            // 
            FastSystem fastSystem = membraneSubDomain.getFastSystem();
            if (fastSystem != null) {
                BioModelNode fsNode = new BioModelNode(fastSystem, true);
                Enumeration<FastInvariant> enumFI = fastSystem.getFastInvariants();
                while (enumFI.hasMoreElements()) {
                    FastInvariant fi = enumFI.nextElement();
                    fsNode.add(new BioModelNode(fi, false));
                }
                Enumeration<FastRate> enumFR = fastSystem.getFastRates();
                while (enumFR.hasMoreElements()) {
                    FastRate fr = enumFR.nextElement();
                    fsNode.add(new BioModelNode(fr, false));
                }
                membraneSubDomainNode.add(fsNode);
            }
            membraneRootNode.add(membraneSubDomainNode);
        }
    }
    if (volumeRootNode.getChildCount() > 0) {
        rootNode.add(volumeRootNode);
    }
    if (membraneRootNode.getChildCount() > 0) {
        rootNode.add(membraneRootNode);
    }
    return rootNode;
}
Also used : JumpCondition(cbit.vcell.math.JumpCondition) VarIniCondition(cbit.vcell.math.VarIniCondition) Action(cbit.vcell.math.Action) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Enumeration(java.util.Enumeration) Constant(cbit.vcell.math.Constant) Equation(cbit.vcell.math.Equation) FastRate(cbit.vcell.math.FastRate) BioModelNode(cbit.vcell.desktop.BioModelNode) FastInvariant(cbit.vcell.math.FastInvariant) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Function(cbit.vcell.math.Function) FastSystem(cbit.vcell.math.FastSystem) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) JumpProcess(cbit.vcell.math.JumpProcess)

Example 13 with FastInvariant

use of cbit.vcell.math.FastInvariant in project vcell by virtualcell.

the class FastSystemAnalyzer method refreshFastVarList.

/**
 * @return java.util.Vector
 */
private void refreshFastVarList() throws MathException, ExpressionException {
    fastVarList.clear();
    // 
    // get list of unique (VolVariables and MemVariables) in fastRate expressions
    // 
    Enumeration<FastRate> fastRatesEnum = fastSystem.getFastRates();
    while (fastRatesEnum.hasMoreElements()) {
        FastRate fr = fastRatesEnum.nextElement();
        Expression exp = fr.getFunction();
        Enumeration<Variable> enum1 = MathUtilities.getRequiredVariables(exp, this);
        while (enum1.hasMoreElements()) {
            Variable var = enum1.nextElement();
            if (var instanceof VolVariable || var instanceof MemVariable) {
                if (!fastVarList.contains(var)) {
                    fastVarList.addElement(var);
                // System.out.println("FastSystemImplicit.refreshFastVarList(), FAST RATE VARIABLE: "+var.getName());
                }
            }
        }
    }
    // 
    // get list of all variables used in invariant expressions that are not used in fast rates
    // 
    Enumeration<FastInvariant> fastInvariantsEnum = fastSystem.getFastInvariants();
    while (fastInvariantsEnum.hasMoreElements()) {
        FastInvariant fi = (FastInvariant) fastInvariantsEnum.nextElement();
        Expression exp = fi.getFunction();
        // System.out.println("FastSystemImplicit.refreshFastVarList(), ORIGINAL FAST INVARIANT: "+exp);
        Enumeration<Variable> enum1 = MathUtilities.getRequiredVariables(exp, this);
        while (enum1.hasMoreElements()) {
            Variable var = enum1.nextElement();
            if (var instanceof VolVariable || var instanceof MemVariable) {
                if (!fastVarList.contains(var)) {
                    fastVarList.addElement(var);
                }
            }
        }
    }
    // 
    // verify that there are N equations (rates+invariants) and N unknowns (fastVariables)
    // 
    int numBoundFunctions = fastSystem.getNumFastInvariants() + fastSystem.getNumFastRates();
    if (fastVarList.size() != numBoundFunctions) {
        throw new MathException("FastSystem.checkDimension(), there are " + fastVarList.size() + " variables and " + numBoundFunctions + " FastInvariant's & FastRates");
    }
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) MemVariable(cbit.vcell.math.MemVariable) MemVariable(cbit.vcell.math.MemVariable) Expression(cbit.vcell.parser.Expression) VolVariable(cbit.vcell.math.VolVariable) MathException(cbit.vcell.math.MathException) FastRate(cbit.vcell.math.FastRate) FastInvariant(cbit.vcell.math.FastInvariant)

Example 14 with FastInvariant

use of cbit.vcell.math.FastInvariant in project vcell by virtualcell.

the class FastSystemAnalyzer method refreshInvarianceMatrix.

/**
 */
private void refreshInvarianceMatrix() throws MathException, ExpressionException {
    // 
    // the invariance's are expressed in matrix form
    // 
    // |a a a a a -1  0  0|   |x1|   |0|
    // |a a a a a  0 -1  0| * |x2| = |0|
    // |a a a a a  0  0 -1|   |x3|   |0|
    // |x4|
    // |x5|
    // |c1|
    // |c2|
    // |c3|
    // 
    Variable[] vars = new Variable[fastVarList.size()];
    fastVarList.copyInto(vars);
    int numVars = fastVarList.size();
    int rows = fastSystem.getNumFastInvariants();
    int cols = numVars + fastSystem.getNumFastInvariants();
    RationalExpMatrix matrix = new RationalExpMatrix(rows, cols);
    Enumeration<FastInvariant> fastInvariantsEnum = fastSystem.getFastInvariants();
    for (int i = 0; i < rows && fastInvariantsEnum.hasMoreElements(); i++) {
        FastInvariant fi = (FastInvariant) fastInvariantsEnum.nextElement();
        Expression function = fi.getFunction();
        for (int j = 0; j < numVars; j++) {
            Variable var = (Variable) fastVarList.elementAt(j);
            Expression exp = function.differentiate(var.getName());
            exp.bindExpression(null);
            exp = exp.flatten();
            RationalExp coeffRationalExp = RationalExpUtils.getRationalExp(exp);
            matrix.set_elem(i, j, coeffRationalExp);
        }
        matrix.set_elem(i, numVars + i, -1);
    }
    // Print
    System.out.println("origMatrix");
    matrix.show();
    // 
    // gaussian elimination on the matrix give the following representation
    // note that some column pivoting (variable re-ordering) is sometimes required to
    // determine N-r dependent vars
    // 
    // |10i0iccc|
    // |01i0iccc|  where (c)'s are the coefficients for constants of invariances
    // |00i1iccc|        (i)'s are the coefficients for dependent vars in terms of independent vars
    // 
    // Print
    System.out.println("reducedMatrix");
    if (rows > 0) {
        try {
            matrix.gaussianElimination(new RationalExpMatrix(rows, rows));
        } catch (MatrixException e) {
            e.printStackTrace(System.out);
            throw new MathException(e.getMessage());
        }
    }
    matrix.show();
    for (int i = 0; i < vars.length; i++) {
        System.out.print(vars[i].getName() + "  ");
    }
    System.out.println("");
    // 
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < rows; j++) {
            RationalExp rexp = matrix.get(i, j).simplify();
            matrix.set_elem(i, j, rexp);
        }
    }
    for (int i = 0; i < rows; i++) {
        // 
        if (!matrix.get(i, i).isConstant() || matrix.get(i, i).getConstant().doubleValue() != 1) {
            for (int j = i + 1; j < numVars; j++) {
                if (matrix.get(i, j).isConstant() && matrix.get(i, j).getConstant().doubleValue() == 1.0) {
                    for (int ii = 0; ii < rows; ii++) {
                        RationalExp temp = matrix.get(ii, i);
                        matrix.set_elem(ii, i, matrix.get(ii, j));
                        matrix.set_elem(ii, j, temp);
                    }
                    Variable tempVar = vars[i];
                    vars[i] = vars[j];
                    vars[j] = tempVar;
                    break;
                }
            }
        }
    }
    // Print
    for (int i = 0; i < vars.length; i++) {
        System.out.print(vars[i].getName() + "  ");
    }
    System.out.println("");
    matrix.show();
    // 
    // separate into dependent and indepent variables, and chop off identity matrix (left N-r columns)
    // 
    // T       |iiccc|                   T
    // [x1 x2 x4] = -1 * |iiccc| * [x3 x5 c1 c2 c3]
    // |iiccc|
    // 
    // 
    int numInvariants = fastSystem.getNumFastInvariants();
    dependentVarList.removeAllElements();
    for (int i = 0; i < numInvariants; i++) {
        dependentVarList.addElement(vars[i]);
    }
    independentVarList.removeAllElements();
    for (int i = numInvariants; i < vars.length; i++) {
        independentVarList.addElement(vars[i]);
    }
    int new_cols = independentVarList.size() + numInvariants;
    dependencyMatrix = new RationalExpMatrix(rows, new_cols);
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < new_cols; j++) {
            RationalExp rexp = matrix.get(i, j + dependentVarList.size()).simplify().minus();
            dependencyMatrix.set_elem(i, j, rexp);
        }
    }
    // Print
    System.out.println("\n\nDEPENDENCY MATRIX");
    dependencyMatrix.show();
    System.out.print("dependent vars: ");
    for (int i = 0; i < dependentVarList.size(); i++) {
        System.out.print(((Variable) dependentVarList.elementAt(i)).getName() + "  ");
    }
    System.out.println("");
    System.out.print("independent vars: ");
    for (int i = 0; i < independentVarList.size(); i++) {
        System.out.print(((Variable) independentVarList.elementAt(i)).getName() + "  ");
    }
    System.out.println("");
}
Also used : MatrixException(cbit.vcell.matrix.MatrixException) ReservedVariable(cbit.vcell.math.ReservedVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) MemVariable(cbit.vcell.math.MemVariable) RationalExpMatrix(cbit.vcell.matrix.RationalExpMatrix) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) RationalExp(cbit.vcell.matrix.RationalExp) FastInvariant(cbit.vcell.math.FastInvariant)

Example 15 with FastInvariant

use of cbit.vcell.math.FastInvariant in project vcell by virtualcell.

the class FastSystemAnalyzer method refreshSubstitutedRateExps.

/**
 */
private void refreshSubstitutedRateExps() throws MathException, ExpressionException {
    // 
    // refresh PseudoConstants (temp constants involved with fastInvariants)
    // 
    pseudoConstantList.removeAllElements();
    Enumeration<FastInvariant> enum_fi = fastSystem.getFastInvariants();
    while (enum_fi.hasMoreElements()) {
        FastInvariant fi = enum_fi.nextElement();
        fi.getFunction().bindExpression(this);
        PseudoConstant pc = new PseudoConstant(getAvailablePseudoConstantName(), fi.getFunction(), MathMapping_4_8.nullDomain);
        pseudoConstantList.addElement(pc);
    // System.out.println("FastSystem.refreshSubstitutedRateExps() __C"+i+" = "+fi.getFunction());
    }
    // 
    // build expressions for dependent variables in terms of independent vars
    // and pseudoConstants
    // 
    dependencyExpList.removeAllElements();
    for (int row = 0; row < dependentVarList.size(); row++) {
        Expression exp = new Expression("0.0;");
        // 
        for (int col = 0; col < independentVarList.size(); col++) {
            Variable indepVar = (Variable) independentVarList.elementAt(col);
            RationalExp coefExp = dependencyMatrix.get(row, col).simplify();
            if (!coefExp.isZero()) {
                exp = Expression.add(exp, new Expression(coefExp.infixString() + "*" + indepVar.getName()));
            }
        }
        // 
        for (int col = independentVarList.size(); col < dependencyMatrix.getNumCols(); col++) {
            PseudoConstant pc = (PseudoConstant) pseudoConstantList.elementAt(col - independentVarList.size());
            RationalExp coefExp = dependencyMatrix.get(row, col);
            if (!coefExp.isZero()) {
                exp = Expression.add(exp, new Expression(coefExp.infixString() + "*" + pc.getName()));
            }
        }
        exp.bindExpression(null);
        exp = exp.flatten();
        exp.bindExpression(this);
        // System.out.println("FastSystem.refreshSubstitutedRateExps() "+((Variable)dependentVarList.elementAt(row)).getName()+" = "+exp.toString()+";");
        dependencyExpList.addElement(exp);
    }
    // 
    // flatten functions, then substitute expressions for dependent vars into rate expressions
    // 
    fastRateExpList.removeAllElements();
    // VariableSymbolTable combinedSymbolTable = getCombinedSymbolTable();
    Enumeration<FastRate> enum_fr = fastSystem.getFastRates();
    while (enum_fr.hasMoreElements()) {
        FastRate fr = enum_fr.nextElement();
        Expression exp = new Expression(MathUtilities.substituteFunctions(new Expression(fr.getFunction()), this));
        // System.out.println("FastSystem.refreshSubstitutedRateExps() fast rate before substitution = "+exp.toString());
        for (int j = 0; j < dependentVarList.size(); j++) {
            Variable depVar = (Variable) dependentVarList.elementAt(j);
            Expression subExp = new Expression((Expression) dependencyExpList.elementAt(j));
            exp.substituteInPlace(new Expression(depVar.getName()), subExp);
        }
        exp.bindExpression(null);
        exp = exp.flatten();
        // System.out.println("FastSystem.refreshSubstitutedRateExps() fast rate after substitution  = "+exp.toString());
        exp.bindExpression(this);
        fastRateExpList.addElement(exp);
    }
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) MemVariable(cbit.vcell.math.MemVariable) Expression(cbit.vcell.parser.Expression) PseudoConstant(cbit.vcell.math.PseudoConstant) FastRate(cbit.vcell.math.FastRate) RationalExp(cbit.vcell.matrix.RationalExp) FastInvariant(cbit.vcell.math.FastInvariant)

Aggregations

FastInvariant (cbit.vcell.math.FastInvariant)17 FastRate (cbit.vcell.math.FastRate)13 Variable (cbit.vcell.math.Variable)13 Expression (cbit.vcell.parser.Expression)13 MemVariable (cbit.vcell.math.MemVariable)11 VolVariable (cbit.vcell.math.VolVariable)11 MathException (cbit.vcell.math.MathException)9 ReservedVariable (cbit.vcell.math.ReservedVariable)9 FastSystem (cbit.vcell.math.FastSystem)7 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)5 Constant (cbit.vcell.math.Constant)5 Equation (cbit.vcell.math.Equation)5 SubDomain (cbit.vcell.math.SubDomain)5 RationalExp (cbit.vcell.matrix.RationalExp)5 Function (cbit.vcell.math.Function)4 JumpCondition (cbit.vcell.math.JumpCondition)4 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)4 OdeEquation (cbit.vcell.math.OdeEquation)4 PdeEquation (cbit.vcell.math.PdeEquation)4 MathDescription (cbit.vcell.math.MathDescription)3