Search in sources :

Example 1 with SimpleSymbolTable

use of cbit.vcell.parser.SimpleSymbolTable in project vcell by virtualcell.

the class RefinementLevel method setRoiExpression.

public void setRoiExpression(String roiExp) throws ExpressionException {
    Expression exp = null;
    if (roiExp != null) {
        roiExp = roiExp.trim();
        if (roiExp.length() > 0) {
            exp = new Expression(roiExp);
            exp.bindExpression(new SimpleSymbolTable(new String[] { "x", "y", "z" }));
        }
    }
    this.roiExpression = exp;
}
Also used : SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Expression(cbit.vcell.parser.Expression)

Example 2 with SimpleSymbolTable

use of cbit.vcell.parser.SimpleSymbolTable in project vcell by virtualcell.

the class CurveFitting method bindExpressionToParametersAndTime.

private static void bindExpressionToParametersAndTime(Expression modelExp, Parameter[] parameters) throws ExpressionBindingException {
    ArrayList<String> symbols = new ArrayList<String>();
    symbols.add("t");
    for (Parameter p : parameters) {
        symbols.add(p.getName());
    }
    modelExp.bindExpression(new SimpleSymbolTable(symbols.toArray(new String[0])));
}
Also used : SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) ArrayList(java.util.ArrayList) Parameter(cbit.vcell.opt.Parameter)

Example 3 with SimpleSymbolTable

use of cbit.vcell.parser.SimpleSymbolTable in project vcell by virtualcell.

the class MathDescription method compareEquivalentCanonicalMath.

/**
 * This method was created in VisualAge.
 * @return boolean
 * @param mathDesc cbit.vcell.math.MathDescription
 */
private MathCompareResults compareEquivalentCanonicalMath(MathDescription newMathDesc) {
    try {
        MathDescription oldMathDesc = this;
        if (oldMathDesc.compareEqual(newMathDesc)) {
            return new MathCompareResults(Decision.MathEquivalent_FLATTENED);
        } else {
            // if (!bSilent) System.out.println("------NATIVE MATHS ARE DIFFERENT----------------------");
            if (!oldMathDesc.postProcessingBlock.compareEqual(newMathDesc.postProcessingBlock)) {
                return new MathCompareResults(Decision.MathDifferent_DIFFERENT_PostProcessingBlock, "Post processing block does not match");
            }
            Variable[] oldVars = (Variable[]) BeanUtils.getArray(oldMathDesc.getVariables(), Variable.class);
            Variable[] newVars = (Variable[]) BeanUtils.getArray(newMathDesc.getVariables(), Variable.class);
            if (oldVars.length != newVars.length) {
                // 
                return new MathCompareResults(Decision.MathDifferent_DIFFERENT_NUMBER_OF_VARIABLES);
            }
            if (!Compare.isEqual(oldVars, newVars)) {
                // 
                // variables are not strictly equal - must try to ignore domains and try again
                // 
                boolean bIgnoreMissingDomains = true;
                for (Variable oldVar : oldVars) {
                    boolean bFound = false;
                    for (Variable newVar : newVars) {
                        if (oldVar.compareEqual(newVar, bIgnoreMissingDomains)) {
                            bFound = true;
                            break;
                        }
                    }
                    if (!bFound) {
                        // 
                        return new MathCompareResults(Decision.MathDifferent_VARIABLES_DONT_MATCH, "variable '" + oldVar.getQualifiedName() + "' not matched");
                    }
                }
                for (Variable newVar : newVars) {
                    boolean bFound = false;
                    for (Variable oldVar : oldVars) {
                        if (newVar.compareEqual(oldVar, bIgnoreMissingDomains)) {
                            bFound = true;
                            break;
                        }
                    }
                    if (!bFound) {
                        // 
                        return new MathCompareResults(Decision.MathDifferent_VARIABLES_DONT_MATCH, "variable '" + newVar.getQualifiedName() + "' not matched");
                    }
                }
            }
            // 
            // go through the list of SubDomains, and compare equations one by one and "correct" new one if possible
            // 
            SubDomain[] subDomainsOld = (SubDomain[]) BeanUtils.getArray(oldMathDesc.getSubDomains(), SubDomain.class);
            SubDomain[] subDomainsNew = (SubDomain[]) BeanUtils.getArray(newMathDesc.getSubDomains(), SubDomain.class);
            if (subDomainsOld.length != subDomainsNew.length) {
                return new MathCompareResults(Decision.MathDifferent_DIFFERENT_NUMBER_OF_SUBDOMAINS);
            }
            for (int i = 0; i < subDomainsOld.length; i++) {
                // compare boundary type
                if (getGeometry().getDimension() > 0) {
                    if (subDomainsOld[i] instanceof CompartmentSubDomain && subDomainsNew[i] instanceof CompartmentSubDomain) {
                        CompartmentSubDomain csdOld = (CompartmentSubDomain) subDomainsOld[i];
                        CompartmentSubDomain csdNew = (CompartmentSubDomain) subDomainsNew[i];
                        if (!Compare.isEqualOrNull(csdOld.getBoundaryConditionXm(), csdNew.getBoundaryConditionXm()) || !Compare.isEqualOrNull(csdOld.getBoundaryConditionXp(), csdNew.getBoundaryConditionXp()) || !Compare.isEqualOrNull(csdOld.getBoundaryConditionYm(), csdNew.getBoundaryConditionYm()) || !Compare.isEqualOrNull(csdOld.getBoundaryConditionYp(), csdNew.getBoundaryConditionYp()) || !Compare.isEqualOrNull(csdOld.getBoundaryConditionZm(), csdNew.getBoundaryConditionZm()) || !Compare.isEqualOrNull(csdOld.getBoundaryConditionZp(), csdNew.getBoundaryConditionZp())) {
                            return new MathCompareResults(Decision.MathDifferent_DIFFERENT_BC_TYPE);
                        }
                    } else if (subDomainsOld[i] instanceof MembraneSubDomain && subDomainsNew[i] instanceof MembraneSubDomain) {
                        MembraneSubDomain msdOld = (MembraneSubDomain) subDomainsOld[i];
                        MembraneSubDomain msdNew = (MembraneSubDomain) subDomainsNew[i];
                        if (!Compare.isEqualOrNull(msdOld.getBoundaryConditionXm(), msdNew.getBoundaryConditionXm()) || !Compare.isEqualOrNull(msdOld.getBoundaryConditionXp(), msdNew.getBoundaryConditionXp()) || !Compare.isEqualOrNull(msdOld.getBoundaryConditionYm(), msdNew.getBoundaryConditionYm()) || !Compare.isEqualOrNull(msdOld.getBoundaryConditionYp(), msdNew.getBoundaryConditionYp()) || !Compare.isEqualOrNull(msdOld.getBoundaryConditionZm(), msdNew.getBoundaryConditionZm()) || !Compare.isEqualOrNull(msdOld.getBoundaryConditionZp(), msdNew.getBoundaryConditionZp())) {
                            return new MathCompareResults(Decision.MathDifferent_DIFFERENT_BC_TYPE);
                        }
                        if (!compareUpdate(msdNew.getVelocityX(), msdOld.getVelocityX(), msdNew::setVelocityX)) {
                            return new MathCompareResults(Decision.MathDifferent_DIFFERENT_VELOCITY, "x");
                        }
                        if (!compareUpdate(msdNew.getVelocityY(), msdOld.getVelocityY(), msdNew::setVelocityY)) {
                            return new MathCompareResults(Decision.MathDifferent_DIFFERENT_VELOCITY, "y");
                        }
                    }
                }
                for (int j = 0; j < oldVars.length; j++) {
                    // 
                    // test equation for this subdomain and variable
                    // 
                    {
                        Equation oldEqu = subDomainsOld[i].getEquation(oldVars[j]);
                        Equation newEqu = subDomainsNew[i].getEquation(oldVars[j]);
                        if (!Compare.isEqualOrNull(oldEqu, newEqu)) {
                            boolean bFoundDifference = false;
                            // 
                            if (oldEqu == null) {
                                // 
                                return new MathCompareResults(Decision.MathDifferent_EQUATION_ADDED, "only one mathDescription had equation for '" + oldVars[j].getQualifiedName() + "' in SubDomain '" + subDomainsOld[i].getName() + "'");
                            }
                            if (newEqu == null) {
                                // 
                                return new MathCompareResults(Decision.MathDifferent_EQUATION_REMOVED, "only one mathDescription had equation for '" + oldVars[j].getQualifiedName() + "' in SubDomain '" + subDomainsOld[i].getName() + "'");
                            }
                            ArrayList<Expression> oldExps = new ArrayList<Expression>();
                            ArrayList<Expression> newExps = new ArrayList<Expression>();
                            boolean bOdePdeMismatch = false;
                            if (oldEqu instanceof PdeEquation && newEqu instanceof OdeEquation && oldEqu.getExpressions(newMathDesc).size() == 3 && ((PdeEquation) oldEqu).getDiffusionExpression().isZero()) {
                                oldExps.add(oldEqu.getRateExpression());
                                oldExps.add(oldEqu.getInitialExpression());
                                newExps.add(newEqu.getRateExpression());
                                newExps.add(newEqu.getInitialExpression());
                                bOdePdeMismatch = true;
                            } else if (oldEqu instanceof OdeEquation && newEqu instanceof PdeEquation && newEqu.getExpressions(newMathDesc).size() == 3 && ((PdeEquation) newEqu).getDiffusionExpression().isZero()) {
                                oldExps.add(oldEqu.getRateExpression());
                                oldExps.add(oldEqu.getInitialExpression());
                                newExps.add(newEqu.getRateExpression());
                                newExps.add(newEqu.getInitialExpression());
                                bOdePdeMismatch = true;
                            } else {
                                oldExps.addAll(oldEqu.getExpressions(oldMathDesc));
                                newExps.addAll(newEqu.getExpressions(newMathDesc));
                            }
                            if (oldExps.size() != newExps.size()) {
                                return new MathCompareResults(Decision.MathDifferent_DIFFERENT_NUMBER_OF_EXPRESSIONS, "equations have different number of expressions");
                            }
                            for (int k = 0; k < oldExps.size(); k++) {
                                if (!oldExps.get(k).compareEqual(newExps.get(k))) {
                                    bFoundDifference = true;
                                    if (!ExpressionUtils.functionallyEquivalent(oldExps.get(k), newExps.get(k))) {
                                        // 
                                        return new MathCompareResults(Decision.MathDifferent_DIFFERENT_EXPRESSION, "expressions are different Old: '" + oldExps.get(k) + "'\n" + "expressions are different New: '" + newExps.get(k) + "'");
                                    } else {
                                    // if (!bSilent) System.out.println("expressions are equivalent Old: '"+oldExps[k]+"'\n"+
                                    // "expressions are equivalent New: '"+newExps[k]+"'");
                                    }
                                }
                            }
                            if (!oldEqu.getVariable().compareEqual(newEqu.getVariable())) {
                                bFoundDifference = true;
                                boolean bIgnoreMissingDomains = true;
                                if (!oldEqu.getVariable().compareEqual(newEqu.getVariable(), bIgnoreMissingDomains)) {
                                    return new MathCompareResults(Decision.MathDifferent_DIFFERENT_VARIABLE_IN_EQUATION, "var1='" + oldEqu.getVariable().getQualifiedName() + "', var2='" + newEqu.getVariable().getQualifiedName() + "'");
                                }
                            }
                            // 
                            if (bFoundDifference || bOdePdeMismatch) {
                                subDomainsNew[i].replaceEquation(oldEqu);
                            } else {
                                // 
                                return new MathCompareResults(Decision.MathDifferent_UNKNOWN_DIFFERENCE_IN_EQUATION, "couldn't find problem with equation for " + oldVars[j].getName() + " in compartment " + subDomainsOld[i].getName());
                            }
                        }
                    }
                    {
                        ParticleProperties oldPP = subDomainsOld[i].getParticleProperties(oldVars[j]);
                        ParticleProperties newPP = subDomainsNew[i].getParticleProperties(oldVars[j]);
                        if (!Compare.isEqualOrNull(oldPP, newPP)) {
                            return new MathCompareResults(Decision.MathDifferent_DIFFERENT_PARTICLE_PROPERTIES);
                        }
                    }
                    // 
                    if (subDomainsOld[i] instanceof MembraneSubDomain && oldVars[j] instanceof VolVariable) {
                        JumpCondition oldJumpCondition = ((MembraneSubDomain) subDomainsOld[i]).getJumpCondition((VolVariable) oldVars[j]);
                        JumpCondition newJumpCondition = ((MembraneSubDomain) subDomainsNew[i]).getJumpCondition((VolVariable) oldVars[j]);
                        if (!Compare.isEqualOrNull(oldJumpCondition, newJumpCondition)) {
                            boolean bFoundDifference = false;
                            // 
                            if (oldJumpCondition == null) {
                                // 
                                return new MathCompareResults(Decision.MathDifferent_EQUATION_ADDED);
                            }
                            if (newJumpCondition == null) {
                                // 
                                return new MathCompareResults(Decision.MathDifferent_EQUATION_REMOVED);
                            }
                            final Vector<Expression> oldJC = oldJumpCondition.getExpressions(oldMathDesc);
                            Expression[] oldExps = oldJC.toArray(new Expression[oldJC.size()]);
                            final Vector<Expression> newJC = newJumpCondition.getExpressions(newMathDesc);
                            Expression[] newExps = newJC.toArray(new Expression[newJC.size()]);
                            if (oldExps.length != newExps.length) {
                                return new MathCompareResults(Decision.MathDifferent_DIFFERENT_NUMBER_OF_EXPRESSIONS, "jump condition has different number of expressions");
                            }
                            for (int k = 0; k < oldExps.length; k++) {
                                if (!oldExps[k].compareEqual(newExps[k])) {
                                    bFoundDifference = true;
                                    if (!ExpressionUtils.functionallyEquivalent(oldExps[k], newExps[k])) {
                                        // 
                                        return new MathCompareResults(Decision.MathDifferent_DIFFERENT_EXPRESSION, "expressions are different Old: '" + oldExps[k] + "'\n" + "expressions are different New: '" + newExps[k] + "'");
                                    } else {
                                    // if (!bSilent) System.out.println("expressions are equivalent Old: '"+oldExps[k]+"'\n"+
                                    // "expressions are equivalent New: '"+newExps[k]+"'");
                                    }
                                }
                            }
                            // 
                            if (bFoundDifference) {
                                ((MembraneSubDomain) subDomainsNew[i]).replaceJumpCondition(oldJumpCondition);
                            } else {
                                // 
                                return new MathCompareResults(Decision.MathDifferent_UNKNOWN_DIFFERENCE_IN_EQUATION, "couldn't find problem with jumpCondition for " + oldVars[j].getName() + " in compartment " + subDomainsOld[i].getName());
                            }
                        }
                    }
                }
                // 
                // test fast system for subdomain
                // 
                FastSystem oldFastSystem = subDomainsOld[i].getFastSystem();
                FastSystem newFastSystem = subDomainsNew[i].getFastSystem();
                if (!Compare.isEqualOrNull(oldFastSystem, newFastSystem)) {
                    boolean bFoundDifference = false;
                    // 
                    if (oldFastSystem == null) {
                        // 
                        return new MathCompareResults(Decision.MathDifferent_EQUATION_ADDED);
                    }
                    if (newFastSystem == null) {
                        // 
                        return new MathCompareResults(Decision.MathDifferent_EQUATION_REMOVED);
                    }
                    Enumeration<Expression> oldFastInvExpEnum = oldFastSystem.getFastInvariantExpressions();
                    Enumeration<Expression> newFastInvExpEnum = newFastSystem.getFastInvariantExpressions();
                    Expression[] oldFastInvariantExps = (Expression[]) BeanUtils.getArray(oldFastInvExpEnum, Expression.class);
                    Expression[] newFastInvariantExps = (Expression[]) BeanUtils.getArray(newFastInvExpEnum, Expression.class);
                    if (oldFastInvariantExps.length != newFastInvariantExps.length) {
                        return new MathCompareResults(Decision.MathDifferent_DIFFERENT_NUMBER_OF_EXPRESSIONS, "fast invariants have different number of expressions");
                    }
                    for (int k = 0; k < oldFastInvariantExps.length; k++) {
                        if (!oldFastInvariantExps[k].compareEqual(newFastInvariantExps[k])) {
                            bFoundDifference = true;
                            if (!ExpressionUtils.functionallyEquivalent(oldFastInvariantExps[k], newFastInvariantExps[k])) {
                                // 
                                // difference couldn't be reconciled
                                // ... for fast invariants, it is ok if the two equations are different by a scale factor (e.g. if X+Y is conserved, so is 2*X+2*Y, or 2*(X+Y))
                                // 
                                // estimate proportionality factor (average of 5 evaluations)
                                // 
                                // ratio = old/new
                                // 
                                // then compare old with ratio*new.
                                // 
                                Expression ratioExp = Expression.mult(oldFastInvariantExps[k], Expression.invert(newFastInvariantExps[k]));
                                String[] symbols = ratioExp.getSymbols();
                                SimpleSymbolTable symbolTable = new SimpleSymbolTable(symbols);
                                double[] values = new double[symbols.length];
                                ratioExp.bindExpression(symbolTable);
                                Random random = new Random(0);
                                double ratioAccum = 0.0;
                                final int NUM_TRIALS = 5;
                                for (int m = 0; m < NUM_TRIALS; m++) {
                                    for (int j = 0; j < values.length; j++) {
                                        values[j] = random.nextDouble() + 1.0;
                                    }
                                    ratioAccum += ratioExp.evaluateVector(values);
                                }
                                double estimatedRatio = ratioAccum / NUM_TRIALS;
                                Expression scaled_newFastInvariantExp = Expression.mult(new Expression(estimatedRatio), newFastInvariantExps[k]);
                                System.out.println("MathDescription.compareEquivalent(): comparing " + oldFastInvariantExps[k].infix() + " with " + scaled_newFastInvariantExp.infix());
                                if (!ExpressionUtils.functionallyEquivalent(oldFastInvariantExps[k], scaled_newFastInvariantExp)) {
                                    return new MathCompareResults(Decision.MathDifferent_DIFFERENT_FASTINV_EXPRESSION, "fast invariant expressions are different Old: '" + oldFastInvariantExps[k] + "'\n" + "fast invariant expressions are different New: '" + newFastInvariantExps[k] + "'");
                                }
                            // if (!bSilent) System.out.println("fast invariant expressions are proportional Old: '"+oldFastInvariantExps[k]+"'\n"+
                            // "fast invariant expressions are proportional New: '"+newFastInvariantExps[k]+"'");
                            } else {
                            // if (!bSilent) System.out.println("expressions are equivalent Old: '"+oldExps[k]+"'\n"+
                            // "expressions are equivalent New: '"+newExps[k]+"'");
                            }
                        }
                    }
                    Enumeration<Expression> oldFastRateExpEnum = oldFastSystem.getFastRateExpressions();
                    Enumeration<Expression> newFastRateExpEnum = newFastSystem.getFastRateExpressions();
                    Expression[] oldFastRateExps = (Expression[]) BeanUtils.getArray(oldFastRateExpEnum, Expression.class);
                    Expression[] newFastRateExps = (Expression[]) BeanUtils.getArray(newFastRateExpEnum, Expression.class);
                    if (oldFastRateExps.length != newFastRateExps.length) {
                        return new MathCompareResults(Decision.MathDifferent_DIFFERENT_NUMBER_OF_EXPRESSIONS, "fast rates have different number of expressions");
                    }
                    for (int k = 0; k < oldFastRateExps.length; k++) {
                        if (!oldFastRateExps[k].compareEqual(newFastRateExps[k])) {
                            bFoundDifference = true;
                            if (!ExpressionUtils.functionallyEquivalent(oldFastRateExps[k], newFastRateExps[k])) {
                                // 
                                return new MathCompareResults(Decision.MathDifferent_DIFFERENT_FASTRATE_EXPRESSION, "fast rate expressions are different Old: '" + oldFastRateExps[k] + "'\n" + "fast rate expressions are different New: '" + newFastRateExps[k] + "'");
                            } else {
                            // if (!bSilent) System.out.println("expressions are equivalent Old: '"+oldExps[k]+"'\n"+
                            // "expressions are equivalent New: '"+newExps[k]+"'");
                            }
                        }
                    }
                    // 
                    if (bFoundDifference) {
                        subDomainsNew[i].setFastSystem(oldFastSystem);
                    } else {
                        // 
                        return new MathCompareResults(Decision.MathDifferent_UNKNOWN_DIFFERENCE_IN_EQUATION, "couldn't find problem with FastSystem for compartment " + subDomainsOld[i].getName());
                    }
                }
                List<ParticleJumpProcess> oldPjpList = subDomainsOld[i].getParticleJumpProcesses();
                List<ParticleJumpProcess> newPjpList = subDomainsNew[i].getParticleJumpProcesses();
                if (oldPjpList.size() != newPjpList.size()) {
                    return new MathCompareResults(Decision.MathDifferent_DIFFERENT_NUMBER_OF_PARTICLE_JUMP_PROCESS);
                }
                for (ParticleJumpProcess oldPjp : oldPjpList) {
                    boolean bEqual = false;
                    for (ParticleJumpProcess newPjp : newPjpList) {
                        if (oldPjp.getName().equals(newPjp.getName())) {
                            if (oldPjp.compareEqual(newPjp)) {
                                bEqual = true;
                            }
                            break;
                        }
                    }
                    if (!bEqual) {
                        return new MathCompareResults(Decision.MathDifferent_DIFFERENT_PARTICLE_JUMP_PROCESS);
                    }
                }
            }
            // 
            return oldMathDesc.compareInvariantAttributes(newMathDesc, true);
        }
    } catch (Throwable e) {
        e.printStackTrace(System.out);
        return new MathCompareResults(Decision.MathDifferent_FAILURE_UNKNOWN);
    }
}
Also used : ArrayList(java.util.ArrayList) Random(java.util.Random) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Expression(cbit.vcell.parser.Expression)

Example 4 with SimpleSymbolTable

use of cbit.vcell.parser.SimpleSymbolTable in project vcell by virtualcell.

the class PdeTimePlotMultipleVariablesPanel method initialize.

private void initialize() {
    VariableType varType = multiTimePlotHelper.getPdeDatacontext().getDataIdentifier().getVariableType();
    String varName = multiTimePlotHelper.getPdeDatacontext().getVariableName();
    String[] plotNames = new String[pointVector.size()];
    final SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[plotNames.length];
    DefaultListModel<String> pointListModel = new DefaultListModel<String>();
    for (int i = 0; i < pointVector.size(); i++) {
        Coordinate tp = null;
        if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
            SpatialSelectionVolume ssv = (SpatialSelectionVolume) pointVector.get(i);
            tp = ssv.getCurveSelectionInfo().getCurve().getBeginningCoordinate();
        } else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
            SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) pointVector.get(i);
            double midU = ssm.getCurveSelectionInfo().getCurveUfromSelectionU(.5);
            tp = ((SampledCurve) ssm.getCurveSelectionInfo().getCurve()).coordinateFromNormalizedU(midU);
        }
        plotNames[i] = varName + " at P[" + i + "]";
        String point = "P[" + i + "]  (" + niceCoordinateString(tp) + ")";
        pointListModel.addElement(point);
        if (multiTimePlotHelper.getsimulation() != null) {
            symbolTableEntries[0] = multiTimePlotHelper.getsimulation().getMathDescription().getEntry(varName);
        } else {
            System.out.println("PdeTimePlotMultipleVariablesPanel.initialize() adding artificial symbol table entries for field data");
            SimpleSymbolTable simpleSymbolTable = new SimpleSymbolTable(new String[] { varName });
            symbolTableEntries[0] = simpleSymbolTable.getEntry(varName);
        }
    }
    pointJList.setModel(pointListModel);
    pointJList.setForeground(variableJList.getForeground());
    pointJList.setVisibleRowCount(3);
    pointJList.setBackground(getBackground());
    pointJList.setSelectionBackground(getBackground());
    pointJList.setSelectionForeground(Color.black);
    plotPane = new PlotPane();
    double[][] plotDatas = tsJobResultsNoStats.getTimesAndValuesForVariable(varName);
    Plot2D plot2D = new SingleXPlot2D(symbolTableEntries, multiTimePlotHelper.getDataSymbolMetadataResolver(), ReservedVariable.TIME.getName(), plotNames, plotDatas, new String[] { "Time Plot", ReservedVariable.TIME.getName(), "" });
    plotPane.setPlot2D(plot2D);
    DataIdentifier[] dis = (multiTimePlotHelper.getCopyOfDisplayedDataIdentifiers() != null ? multiTimePlotHelper.getCopyOfDisplayedDataIdentifiers() : DataIdentifier.collectSortedSimilarDataTypes(multiTimePlotHelper.getVariableType(), multiTimePlotHelper.getPdeDatacontext().getDataIdentifiers()));
    Arrays.sort(dis, new Comparator<DataIdentifier>() {

        public int compare(DataIdentifier o1, DataIdentifier o2) {
            int bEqualIgnoreCase = o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
            if (bEqualIgnoreCase == 0) {
                return o1.getDisplayName().compareTo(o2.getDisplayName());
            }
            return bEqualIgnoreCase;
        }
    });
    variableJList.setListData(dis);
    initVariableListSelected(variableJList, multiTimePlotHelper.getPdeDatacontext().getDataIdentifier());
    variableJList.setCellRenderer(multiTimePlotHelper.getListCellRenderer());
    setLayout(new GridBagLayout());
    JLabel label = new JLabel("Selected Points");
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new java.awt.Insets(15, 10, 4, 4);
    add(label, gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    gbc.gridheight = 4;
    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.insets = new java.awt.Insets(0, 4, 0, 0);
    add(plotPane, gbc);
    JScrollPane sp = new JScrollPane(pointJList);
    sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.weighty = 0.5;
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    gbc.insets = new java.awt.Insets(4, 10, 4, 4);
    add(sp, gbc);
    label = new JLabel("Y Axis");
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new java.awt.Insets(4, 10, 4, 4);
    add(label, gbc);
    sp = new JScrollPane(variableJList);
    sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.weightx = 0.2;
    gbc.weighty = 1;
    gbc.insets = new java.awt.Insets(4, 10, 50, 4);
    gbc.fill = java.awt.GridBagConstraints.BOTH;
    add(sp, gbc);
    variableJList.addListSelectionListener(eventHandler);
    multiTimePlotHelper.addPropertyChangeListener(eventHandler);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) DataIdentifier(cbit.vcell.simdata.DataIdentifier) GridBagLayout(java.awt.GridBagLayout) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) DefaultListModel(javax.swing.DefaultListModel) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) JScrollPane(javax.swing.JScrollPane) SampledCurve(cbit.vcell.geometry.SampledCurve) VariableType(cbit.vcell.math.VariableType) JLabel(javax.swing.JLabel) SingleXPlot2D(cbit.plot.SingleXPlot2D) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Coordinate(org.vcell.util.Coordinate) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) PlotPane(cbit.plot.gui.PlotPane) SingleXPlot2D(cbit.plot.SingleXPlot2D) Plot2D(cbit.plot.Plot2D)

Example 5 with SimpleSymbolTable

use of cbit.vcell.parser.SimpleSymbolTable in project vcell by virtualcell.

the class MathTestingUtilities method comparePDEResultsWithExact.

/**
 * Insert the method's description here.
 * Creation date: (8/20/2003 12:58:10 PM)
 */
public static SimulationComparisonSummary comparePDEResultsWithExact(SimulationSymbolTable simSymbolTable, PDEDataManager dataManager, String type, double absErrorThreshold, double relErrorThreshold) throws DataAccessException, ExpressionException {
    java.util.Hashtable<String, DataErrorSummary> tempVarHash = new java.util.Hashtable<String, DataErrorSummary>();
    double[] timeArray = dataManager.getDataSetTimes();
    Variable[] vars = simSymbolTable.getVariables();
    CartesianMesh mesh = dataManager.getMesh();
    MathDescription mathDesc = simSymbolTable.getSimulation().getMathDescription();
    // Get volumeSubdomains from mathDesc/mesh and store in lookupTable
    int numVol = mesh.getSizeX() * mesh.getSizeY() * mesh.getSizeZ();
    CompartmentSubDomain[] volSubDomainLookup = new CompartmentSubDomain[numVol];
    for (int i = 0; i < numVol; i++) {
        int subVolumeIndex = mesh.getSubVolumeFromVolumeIndex(i);
        SubVolume subVolume = mathDesc.getGeometry().getGeometrySpec().getSubVolume(subVolumeIndex);
        CompartmentSubDomain compSubDomain = mathDesc.getCompartmentSubDomain(subVolume.getName());
        volSubDomainLookup[i] = compSubDomain;
    }
    // Get membraneSubdomains from mathDesc/mesh and store in lookupTable
    int numMem = mesh.getMembraneElements().length;
    MembraneSubDomain[] memSubDomainLookup = new MembraneSubDomain[numMem];
    for (int i = 0; i < numMem; i++) {
        int insideVolIndex = mesh.getMembraneElements()[i].getInsideVolumeIndex();
        int outsideVolIndex = mesh.getMembraneElements()[i].getOutsideVolumeIndex();
        MembraneSubDomain memSubDomain = mathDesc.getMembraneSubDomain(volSubDomainLookup[insideVolIndex], volSubDomainLookup[outsideVolIndex]);
        memSubDomainLookup[i] = memSubDomain;
    }
    double[] valueArray = new double[4];
    SimpleSymbolTable symbolTable = new SimpleSymbolTable(new String[] { "t", "x", "y", "z" });
    int tIndex = symbolTable.getEntry("t").getIndex();
    int xIndex = symbolTable.getEntry("x").getIndex();
    int yIndex = symbolTable.getEntry("y").getIndex();
    int zIndex = symbolTable.getEntry("z").getIndex();
    SimulationComparisonSummary simComparisonSummary = new SimulationComparisonSummary();
    String hashKey = new String("");
    long dataLength = 0;
    // for each var, do the following :
    for (int i = 0; i < vars.length; i++) {
        if (vars[i] instanceof VolVariable || vars[i] instanceof MemVariable || vars[i] instanceof FilamentVariable || vars[i] instanceof VolumeRegionVariable || vars[i] instanceof MembraneRegionVariable || vars[i] instanceof FilamentRegionVariable) {
            // for each time in timeArray,
            for (int j = 0; j < timeArray.length; j++) {
                if (type.equals(TestCaseNew.EXACT_STEADY)) {
                    if (j != (timeArray.length - 1)) {
                        continue;
                    }
                }
                // get data block from varName, data from datablock
                SimDataBlock simDataBlock = dataManager.getSimDataBlock(vars[i].getName(), timeArray[j]);
                double[] data = simDataBlock.getData();
                dataLength = data.length;
                SubDomain subDomain = null;
                Coordinate subDomainCoord = null;
                // for each point in data block ...
                for (int k = 0; k < dataLength; k++) {
                    // Get subdomain from mesh (from the lookupTable), get coordinates (x,y,z) from mesh, evaluate EXACT SOLN at that coord
                    if (vars[i] instanceof VolVariable) {
                        subDomain = volSubDomainLookup[k];
                        subDomainCoord = mesh.getCoordinateFromVolumeIndex(k);
                    } else if (vars[i] instanceof MemVariable) {
                        subDomain = memSubDomainLookup[k];
                        subDomainCoord = mesh.getCoordinateFromMembraneIndex(k);
                    } else {
                        throw new RuntimeException("Var " + vars[i].getName() + " not supported yet!");
                    }
                    hashKey = vars[i].getName() + ":" + subDomain.getName();
                    DataErrorSummary tempVar = (DataErrorSummary) tempVarHash.get(hashKey);
                    if (tempVar == null) {
                        Expression exp = new Expression(subDomain.getEquation(vars[i]).getExactSolution());
                        exp.bindExpression(simSymbolTable);
                        exp = MathUtilities.substituteFunctions(exp, simSymbolTable);
                        exp = exp.flatten();
                        exp.bindExpression(symbolTable);
                        tempVar = new DataErrorSummary(exp);
                        tempVarHash.put(hashKey, tempVar);
                    }
                    // time
                    valueArray[tIndex] = timeArray[j];
                    // x
                    valueArray[xIndex] = subDomainCoord.getX();
                    // y
                    valueArray[yIndex] = subDomainCoord.getY();
                    // z
                    valueArray[zIndex] = subDomainCoord.getZ();
                    // EXACT soln at coord subDomainCoord
                    double value = tempVar.getExactExp().evaluateVector(valueArray);
                    tempVar.addDataValues(value, data[k], timeArray[j], k, absErrorThreshold, relErrorThreshold);
                }
            // end for (k)
            }
        // end for (j)
        }
    // end - if (var)
    }
    // end for (i)
    Enumeration<String> enumKeys = tempVarHash.keys();
    while (enumKeys.hasMoreElements()) {
        String key = enumKeys.nextElement();
        DataErrorSummary tempVarSummary = tempVarHash.get(key);
        simComparisonSummary.addVariableComparisonSummary(new VariableComparisonSummary(key, tempVarSummary.getMinRef(), tempVarSummary.getMaxRef(), tempVarSummary.getMaxAbsoluteError(), tempVarSummary.getMaxRelativeError(), tempVarSummary.getL2Norm(), tempVarSummary.getTimeAtMaxAbsoluteError(), tempVarSummary.getIndexAtMaxAbsoluteError(), tempVarSummary.getTimeAtMaxRelativeError(), tempVarSummary.getIndexAtMaxRelativeError()));
    }
    return simComparisonSummary;
}
Also used : MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) SensVariable(cbit.vcell.solver.ode.SensVariable) FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) MemVariable(cbit.vcell.math.MemVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) MathDescription(cbit.vcell.math.MathDescription) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) MemVariable(cbit.vcell.math.MemVariable) SimDataBlock(cbit.vcell.simdata.SimDataBlock) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) VolVariable(cbit.vcell.math.VolVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Coordinate(org.vcell.util.Coordinate) Expression(cbit.vcell.parser.Expression) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentVariable(cbit.vcell.math.FilamentVariable)

Aggregations

SimpleSymbolTable (cbit.vcell.parser.SimpleSymbolTable)16 Expression (cbit.vcell.parser.Expression)11 ArrayList (java.util.ArrayList)6 Coordinate (org.vcell.util.Coordinate)3 ImageException (cbit.image.ImageException)2 Plot2D (cbit.plot.Plot2D)2 SingleXPlot2D (cbit.plot.SingleXPlot2D)2 PlotPane (cbit.plot.gui.PlotPane)2 ChildWindowManager (cbit.vcell.client.ChildWindowManager)2 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)2 SinglePoint (cbit.vcell.geometry.SinglePoint)2 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)2 MathException (cbit.vcell.math.MathException)2 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)2 VariableType (cbit.vcell.math.VariableType)2 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)2 DataIdentifier (cbit.vcell.simdata.DataIdentifier)2 SpatialSelectionMembrane (cbit.vcell.simdata.SpatialSelectionMembrane)2