Search in sources :

Example 1 with DivideByZeroException

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

the class ODETimePlotMultipleScansPanel method initialize.

/**
 * Insert the method's description here.
 * Creation date: (10/17/2005 11:37:52 PM)
 * @exception org.vcell.util.DataAccessException The exception description.
 */
private void initialize() {
    setLayout(new BorderLayout());
    int scanCount = simulation.getScanCount();
    plotPane = new PlotPane();
    add(plotPane, BorderLayout.CENTER);
    JPanel parameterPanel = new JPanel();
    parameterPanel.setLayout(new BorderLayout());
    JLabel label = new JLabel();
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.setText("<html><b><u>Choose one or more Parameter Value Sets </u></b></html>");
    label.setBorder(BorderFactory.createEmptyBorder(10, 4, 10, 4));
    parameterPanel.add(label, BorderLayout.NORTH);
    String[] scanParams = simulation.getMathOverrides().getScannedConstantNames();
    Arrays.sort(scanParams);
    class ScanChoicesTableModel extends javax.swing.table.AbstractTableModel {

        String[] columnNames;

        Double[][] rowData;

        ScanChoicesTableModel(Double[][] argData, String[] argNames) {
            columnNames = argNames;
            rowData = argData;
        }

        public String getColumnName(int column) {
            if (column == 0) {
                return JOB_PLOT_NAME;
            }
            return columnNames[column - 1].toString();
        }

        public int getRowCount() {
            return rowData.length;
        }

        public int getColumnCount() {
            return columnNames.length + 1;
        }

        public Object getValueAt(int row, int col) {
            if (col == 0) {
                return new Integer(row);
            }
            return rowData[row][col - 1];
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            return Number.class;
        }
    }
    ;
    Double[][] values = new Double[scanCount][scanParams.length];
    for (int i = 0; i < scanCount; i++) {
        for (int j = 0; j < scanParams.length; j++) {
            Expression scanConstantExp = simulation.getMathOverrides().getActualExpression(scanParams[j], i);
            try {
                values[i][j] = scanConstantExp.evaluateConstant();
            } catch (DivideByZeroException e1) {
                e1.printStackTrace();
            } catch (ExpressionException e1) {
                e1.printStackTrace();
            }
        }
    }
    ScanChoicesTableModel tm = new ScanChoicesTableModel(values, scanParams);
    scanChoiceTable = new JTable(tm);
    scanChoiceTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    JScrollPane scr = new JScrollPane(scanChoiceTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scr.setPreferredSize(new java.awt.Dimension(100, Math.min(150, scanChoiceTable.getPreferredSize().height + scanChoiceTable.getTableHeader().getPreferredSize().height + 5)));
    parameterPanel.add(scr, BorderLayout.CENTER);
    parameterPanel.setBorder(BorderFactory.createEtchedBorder());
    TableColumn col = scanChoiceTable.getColumnModel().getColumn(0);
    int width = 50;
    col.setMinWidth(width);
    col.setMaxWidth(width);
    col.setPreferredWidth(width);
    // put things together
    add(parameterPanel, BorderLayout.SOUTH);
    scanChoiceTable.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() {

        public void valueChanged(javax.swing.event.ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                updateScanParamChoices();
            }
        }
    });
// scanChoiceTable.getSelectionModel().setSelectionInterval(0,0);
}
Also used : JPanel(javax.swing.JPanel) ExpressionException(cbit.vcell.parser.ExpressionException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) BorderLayout(java.awt.BorderLayout) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) TableColumn(javax.swing.table.TableColumn) Expression(cbit.vcell.parser.Expression) JTable(javax.swing.JTable) PlotPane(cbit.plot.gui.PlotPane)

Example 2 with DivideByZeroException

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

the class RowColumnResultSet method extractColumn.

/**
 * getVariableNames method comment.
 *  If column is empty, return null or an empty array?
 *  For now, null...
 */
public synchronized double[] extractColumn(int c) throws ExpressionException {
    double[] values = null;
    if (getRowCount() > 0) {
        ColumnDescription colDescription = getColumnDescriptions(c);
        if (colDescription instanceof FunctionColumnDescription) {
            Expression exp = ((FunctionColumnDescription) colDescription).getExpression();
            // 
            // must rebind expression due to transient nature of expression binding (see ASTIdNode.symbolTableEntry)
            // 
            exp.bindExpression(getResultSetSymbolTableWithoutFunction());
            values = new double[getRowCount()];
            for (int r = 0; r < getRowCount(); r++) {
                try {
                    values[r] = exp.evaluateVector(getRow(r));
                } catch (DivideByZeroException e) {
                    e.printStackTrace(System.out);
                    values[r] = Double.NaN;
                } catch (FunctionDomainException e) {
                    e.printStackTrace(System.out);
                    values[r] = Double.NaN;
                }
            }
        } else {
            values = new double[getRowCount()];
            for (int r = 0; r < getRowCount(); r++) {
                values[r] = getRow(r)[c];
            }
        }
    }
    return (values);
}
Also used : DivideByZeroException(cbit.vcell.parser.DivideByZeroException) Expression(cbit.vcell.parser.Expression) FunctionDomainException(cbit.vcell.parser.FunctionDomainException) ColumnDescription(cbit.vcell.util.ColumnDescription)

Example 3 with DivideByZeroException

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

the class DataSetControllerImpl method evaluateFunction.

/**
 * Insert the method's description here.
 * Creation date: (10/13/00 9:13:52 AM)
 * @return cbit.vcell.simdata.SimDataBlock
 * @param user cbit.vcell.server.User
 * @param simResults cbit.vcell.simdata.SimResults
 * @param function cbit.vcell.math.Function
 * @param time double
 */
private SimDataBlock evaluateFunction(OutputContext outputContext, final VCDataIdentifier vcdID, VCData simData, AnnotatedFunction function, double time) throws ExpressionException, DataAccessException, IOException, MathException {
    Expression exp = new Expression(function.getExpression());
    exp = SolverUtilities.substituteSizeAndNormalFunctions(exp, function.getFunctionType().getVariableDomain());
    exp.bindExpression(simData);
    exp = fieldFunctionSubstitution(outputContext, vcdID, exp);
    // 
    // get Dependent datasets
    // 
    // variables are indexed by a number, t=0, x=1, y=2, z=3, a(i) = 4+i where a's are other variables
    // these variables
    // 
    CartesianMesh mesh = null;
    if (function.getFunctionType().equals(VariableType.POSTPROCESSING)) {
        mesh = ((SimulationData) simData).getPostProcessingMesh(function.getName(), outputContext);
    }
    if (mesh == null) {
        mesh = getMesh(vcdID);
    }
    String[] dependentIDs = exp.getSymbols();
    Vector<SimDataHolder> dataSetList = new Vector<SimDataHolder>();
    Vector<DataSetIdentifier> dependencyList = new Vector<DataSetIdentifier>();
    int varIndex = TXYZ_OFFSET;
    int dataLength = 0;
    long lastModified = 0;
    VariableType variableType = function.getFunctionType();
    if (variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.POSTPROCESSING)) {
        dataLength = mesh.getNumVolumeElements();
    } else if (variableType.equals(VariableType.MEMBRANE)) {
        dataLength = mesh.getNumMembraneElements();
    } else if (variableType.equals(VariableType.VOLUME_REGION)) {
        dataLength = mesh.getNumVolumeRegions();
    } else if (variableType.equals(VariableType.MEMBRANE_REGION)) {
        dataLength = mesh.getNumMembraneRegions();
    }
    VariableType computedVariableType = null;
    int computedDataLength = 0;
    for (int i = 0; dependentIDs != null && i < dependentIDs.length; i++) {
        SymbolTableEntry ste = exp.getSymbolBinding(dependentIDs[i]);
        if (ste instanceof DataSetIdentifier) {
            DataSetIdentifier dsi = (DataSetIdentifier) ste;
            dependencyList.addElement(dsi);
            dsi.setIndex(varIndex++);
            if (dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX) || dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                String volVarName = dsi.getName().substring(0, dsi.getName().lastIndexOf("_"));
                SimDataBlock simDataBlock = getSimDataBlock(outputContext, vcdID, volVarName, time);
                lastModified = simDataBlock.getPDEDataInfo().getTimeStamp();
                // 
                if (simDataBlock.getVariableType().equals(VariableType.VOLUME)) {
                    computedVariableType = VariableType.MEMBRANE;
                    computedDataLength = mesh.getMembraneElements().length;
                // 
                // if inside/outside volume element dependent, then can only be a membrane type
                // 
                } else if (simDataBlock.getVariableType().equals(VariableType.VOLUME_REGION) && variableType == null) {
                    computedVariableType = VariableType.MEMBRANE_REGION;
                    computedDataLength = mesh.getNumMembraneRegions();
                }
                dataSetList.addElement(simDataBlock);
            } else {
                SimDataBlock simDataBlock = getSimDataBlock(outputContext, vcdID, dsi.getName(), time);
                if (variableType == null || simDataBlock.getVariableType().isExpansionOf(variableType)) {
                    lastModified = simDataBlock.getPDEDataInfo().getTimeStamp();
                    computedDataLength = simDataBlock.getData().length;
                    computedVariableType = simDataBlock.getVariableType();
                }
                dataSetList.addElement(simDataBlock);
            }
        } else if (ste instanceof ReservedVariable) {
            ReservedVariable rv = (ReservedVariable) ste;
            if (rv.isTIME()) {
                rv.setIndex(0);
            } else if (rv.isX()) {
                rv.setIndex(1);
            } else if (rv.isY()) {
                rv.setIndex(2);
            } else if (rv.isZ()) {
                rv.setIndex(3);
            }
        } else if (ste instanceof FieldDataParameterVariable) {
            // Field Data
            ((FieldDataParameterVariable) ste).setIndex(varIndex++);
            final double[] steResampledFieldData = ((FieldDataParameterVariable) ste).getResampledFieldData();
            final VariableType newVariableType = (steResampledFieldData.length == mesh.getNumVolumeElements() ? VariableType.VOLUME : (steResampledFieldData.length == mesh.getNumMembraneElements() ? VariableType.MEMBRANE : null));
            if (newVariableType == null) {
                throw new DataAccessException("Couldn't determine VariableType for FieldData");
            }
            if (variableType != null && !variableType.equals(newVariableType)) {
                throw new DataAccessException("Incompatible VariableType for FieldData");
            }
            SimDataHolder newSimDataHolder = new SimDataHolder() {

                public double[] getData() {
                    return steResampledFieldData;
                }

                public VariableType getVariableType() {
                    return newVariableType;
                }
            };
            dataSetList.addElement(newSimDataHolder);
            dependencyList.add(new DataSetIdentifier(ste.getName(), newVariableType, ((FieldDataParameterVariable) ste).getDomain()));
            if (variableType == null) {
                computedVariableType = newVariableType;
                computedDataLength = newSimDataHolder.getData().length;
            }
        }
    }
    if (computedDataLength <= 0) {
        if (lg.isWarnEnabled())
            lg.warn("dependencies for function '" + function + "' not found, assuming datalength of volume");
        computedDataLength = mesh.getDataLength(VariableType.VOLUME);
        computedVariableType = VariableType.VOLUME;
    // try {
    // computedDataLength = mesh.getDataLength(VariableType.VOLUME);
    // computedVariableType = VariableType.VOLUME;
    // }catch (MathException e){
    // lg.error(e.getMessage(), e);
    // throw new RuntimeException("MathException, cannot determine domain for function '"+function+"'");
    // }catch (FileNotFoundException e){
    // lg.error(e.getMessage(), e);
    // throw new RuntimeException("Mesh not found, cannot determine domain for function '"+function+"'");
    // }
    }
    if (!variableType.equals(computedVariableType)) {
        System.err.println("function [" + function.getName() + "] variable type [" + variableType.getTypeName() + "] is not equal to computed variable type [" + computedVariableType.getTypeName() + "].");
    }
    if (dataLength == 0) {
        dataLength = computedDataLength;
        variableType = computedVariableType;
    }
    // 
    // Gradient Info for special processing
    // 
    boolean isGrad = hasGradient(exp);
    if (isGrad && !variableType.equals(VariableType.VOLUME)) {
        throw new DataAccessException("Gradient function is not implemented for datatype " + variableType.getTypeName());
    }
    double[] args = new double[varIndex + (isGrad ? 12 * varIndex : 0)];
    double[] data = new double[dataLength];
    // time
    args[0] = time;
    // x
    args[1] = 0.0;
    // y
    args[2] = 0.0;
    // z
    args[3] = 0.0;
    String dividedByZeroMsg = "";
    for (int i = 0; i < dataLength; i++) {
        // 
        if (variableType.equals(VariableType.VOLUME) || variableType.equals(VariableType.POSTPROCESSING)) {
            Coordinate coord = mesh.getCoordinateFromVolumeIndex(i);
            args[1] = coord.getX();
            args[2] = coord.getY();
            args[3] = coord.getZ();
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                SimDataHolder simDataHolder = dataSetList.elementAt(j);
                if (simDataHolder.getVariableType().equals(VariableType.VOLUME) || simDataHolder.getVariableType().equals(VariableType.POSTPROCESSING)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[i];
                } else if (simDataHolder.getVariableType().equals(VariableType.VOLUME_REGION)) {
                    int volumeIndex = mesh.getVolumeRegionIndex(i);
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[volumeIndex];
                } else if (simDataHolder.getVariableType().equals(VariableType.POINT_VARIABLE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[0];
                }
            }
            if (isGrad) {
                getSpatialNeighborData(mesh, i, varIndex, time, dataSetList, args);
            }
        } else if (variableType.equals(VariableType.VOLUME_REGION)) {
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                SimDataHolder simDataHolder = dataSetList.elementAt(j);
                if (simDataHolder.getVariableType().equals(VariableType.VOLUME_REGION)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[i];
                } else if (simDataHolder.getVariableType().equals(VariableType.POINT_VARIABLE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[0];
                }
            }
        } else if (variableType.equals(VariableType.MEMBRANE)) {
            Coordinate coord = mesh.getCoordinateFromMembraneIndex(i);
            args[1] = coord.getX();
            args[2] = coord.getY();
            args[3] = coord.getZ();
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
                SimDataHolder simDataHolder = dataSetList.elementAt(j);
                if (simDataHolder.getVariableType().equals(VariableType.VOLUME)) {
                    if (mesh.isChomboMesh()) {
                        String varName = dsi.getName();
                        if (dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                            varName = varName.substring(0, varName.lastIndexOf(InsideVariable.INSIDE_VARIABLE_SUFFIX));
                        } else if (dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                            varName = varName.substring(0, varName.lastIndexOf(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX));
                        }
                        args[TXYZ_OFFSET + j] = getChomboExtrapolatedValues(vcdID, varName, time).getData()[i];
                    } else {
                        if (dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                            args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, true, false);
                        } else if (dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                            args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, false, false);
                        } else {
                            args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, dsi.getDomain(), i, simDataHolder, false);
                        }
                    }
                } else if (simDataHolder.getVariableType().equals(VariableType.VOLUME_REGION)) {
                    if (dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                        args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, true, true);
                    } else if (dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                        args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, false, true);
                    } else {
                        args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, dsi.getDomain(), i, simDataHolder, true);
                    }
                } else if (simDataHolder.getVariableType().equals(VariableType.MEMBRANE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[i];
                } else if (simDataHolder.getVariableType().equals(VariableType.MEMBRANE_REGION)) {
                    int memRegionIndex = mesh.getMembraneRegionIndex(i);
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[memRegionIndex];
                } else if (simDataHolder.getVariableType().equals(VariableType.POINT_VARIABLE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[0];
                }
            }
        } else if (variableType.equals(VariableType.MEMBRANE_REGION)) {
            for (int j = 0; j < varIndex - TXYZ_OFFSET; j++) {
                DataSetIdentifier dsi = (DataSetIdentifier) dependencyList.elementAt(j);
                SimDataHolder simDataHolder = dataSetList.elementAt(j);
                if (simDataHolder.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                    // 
                    for (int k = 0; k < mesh.getMembraneElements().length; k++) {
                        if (mesh.getMembraneRegionIndex(k) == i) {
                            args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, true, true);
                            break;
                        }
                    }
                } else if (simDataHolder.getVariableType().equals(VariableType.VOLUME_REGION) && dsi.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                    // 
                    for (int k = 0; k < mesh.getMembraneElements().length; k++) {
                        if (mesh.getMembraneRegionIndex(k) == i) {
                            args[TXYZ_OFFSET + j] = interpolateVolDataValToMemb(mesh, i, simDataHolder, false, true);
                            break;
                        }
                    }
                } else if (simDataHolder.getVariableType().equals(VariableType.MEMBRANE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[i];
                } else if (simDataHolder.getVariableType().equals(VariableType.MEMBRANE_REGION)) {
                    int memRegionIndex = i;
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[memRegionIndex];
                } else if (simDataHolder.getVariableType().equals(VariableType.POINT_VARIABLE)) {
                    args[TXYZ_OFFSET + j] = simDataHolder.getData()[0];
                }
            }
        }
        try {
            data[i] = exp.evaluateVector(args);
        // if(time ==0){
        // System.out.print("non-multi evalFunction ");
        // for (int m = 0; m < args.length; m++) {
        // System.out.print(args[m]);
        // }
        // System.out.println(" "+(args[args.length-2]/args[args.length-1]));
        // }
        } catch (DivideByZeroException e) {
            dividedByZeroMsg = e.getMessage();
            data[i] = Double.POSITIVE_INFINITY;
        }
    }
    if (dividedByZeroMsg.length() != 0) {
        System.out.println("DataSetControllerImpl.evaluateFunction(): DivideByZero " + dividedByZeroMsg);
    }
    PDEDataInfo pdeDataInfo = new PDEDataInfo(vcdID.getOwner(), vcdID.getID(), function.getName(), time, lastModified);
    return new SimDataBlock(pdeDataInfo, data, variableType);
}
Also used : VariableType(cbit.vcell.math.VariableType) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) Expression(cbit.vcell.parser.Expression) Coordinate(org.vcell.util.Coordinate) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException) FieldDataParameterVariable(cbit.vcell.field.FieldDataParameterVariable)

Example 4 with DivideByZeroException

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

the class SmoldynFileWriter method writeRuntimeCommands.

// uncomment for debug
/*private void writeGraphicsLegend() throws MathException{
	try {
		java.awt.image.BufferedImage cmapImage = new java.awt.image.BufferedImage(200, particleVariableList.size()*30,java.awt.image.BufferedImage.TYPE_INT_RGB);
		Graphics g = cmapImage.getGraphics();
		for (int i = 0; i < particleVariableList.size(); i ++) {
			Color c = colors[i];
			System.out.println("color for legend: " + "red--"+ c.getRed() + "  green--" + c.getGreen() + "  blue--" + c.getBlue());
			String variableName = getVariableName(particleVariableList.get(i),null);
			g.setColor(c);
			g.drawString(variableName, 5, 30*i + 20);
			g.fillRect(105, 30*i + 10, 20, 10);
		}
		g.dispose();
		File tmpFile = File.createTempFile("legend", ".jpg");

		FileOutputStream fios = null;
		try {
			printWriter.println("# legend file: " + tmpFile.getAbsolutePath());
			fios = new FileOutputStream(tmpFile);
			ImageIO.write(cmapImage,"jpg",fios);
		}  finally {
			if(fios != null) {fios.close();}
		}
	} catch (Exception e) {
		e.printStackTrace();
		throw new MathException(e.getMessage());
	}
}*/
private void writeRuntimeCommands() throws SolverException, DivideByZeroException, DataAccessException, IOException, MathException, ExpressionException {
    printWriter.println("# " + SmoldynVCellMapper.SmoldynKeyword.killmolincmpt + " runtime command to kill molecules misplaced during initial condtions");
    for (ParticleVariable pv : particleVariableList) {
        CompartmentSubDomain varDomain = mathDesc.getCompartmentSubDomain(pv.getDomain().getName());
        if (varDomain == null) {
            continue;
        }
        boolean bkillMol = false;
        ArrayList<ParticleInitialCondition> iniConditionList = varDomain.getParticleProperties(pv).getParticleInitialConditions();
        for (ParticleInitialCondition iniCon : iniConditionList) {
            if (iniCon instanceof ParticleInitialConditionConcentration) {
                try {
                    subsituteFlattenToConstant(((ParticleInitialConditionConcentration) iniCon).getDistribution());
                } catch (// can not be evaluated to a constant
                Exception e) {
                    bkillMol = true;
                    break;
                }
            }
        }
        if (bkillMol) {
            Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
            while (subDomainEnumeration.hasMoreElements()) {
                SubDomain subDomain = subDomainEnumeration.nextElement();
                if (subDomain instanceof CompartmentSubDomain && varDomain != subDomain) {
                    printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + SmoldynVCellMapper.SmoldynKeyword.killmolincmpt + " " + pv.getName() + "(" + SmoldynVCellMapper.SmoldynKeyword.all + ") " + subDomain.getName());
                }
            }
        }
    }
    printWriter.println();
    // write command to kill molecules on membrane for adsortption to nothing
    printWriter.println("# kill membrane molecues that are absorbed (to nothing)");
    for (String killMolCmd : killMolCommands) {
        printWriter.println(killMolCmd);
    }
    printWriter.println();
    printWriter.println("# runtime command");
    printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.E + " " + VCellSmoldynKeyword.vcellPrintProgress);
    if (outputFile != null && cartesianMesh != null) {
        OutputTimeSpec ots = simulation.getSolverTaskDescription().getOutputTimeSpec();
        if (ots.isUniform()) {
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.output_files + " " + outputFile.getName());
            ISize sampleSize = simulation.getMeshSpecification().getSamplingSize();
            TimeStep timeStep = simulation.getSolverTaskDescription().getTimeStep();
            int n = (int) Math.round(((UniformOutputTimeSpec) ots).getOutputTimeStep() / timeStep.getDefaultTimeStep());
            if (simulation.getSolverTaskDescription().getSmoldynSimulationOptions().isSaveParticleLocations()) {
                printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + SmoldynVCellMapper.SmoldynKeyword.incrementfile + " " + outputFile.getName());
                printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + SmoldynVCellMapper.SmoldynKeyword.listmols + " " + outputFile.getName());
            }
            // DON'T CHANGE THE ORDER HERE.
            // DataProcess must be before vcellWriteOutput
            writeDataProcessor();
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " begin");
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " " + VCellSmoldynKeyword.dimension + " " + dimension);
            printWriter.print(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " " + VCellSmoldynKeyword.sampleSize + " " + sampleSize.getX());
            if (dimension > 1) {
                printWriter.print(" " + sampleSize.getY());
                if (dimension > 2) {
                    printWriter.print(" " + sampleSize.getZ());
                }
            }
            printWriter.println();
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " " + VCellSmoldynKeyword.numMembraneElements + " " + cartesianMesh.getNumMembraneElements());
            for (ParticleVariable pv : particleVariableList) {
                String type = pv instanceof MembraneParticleVariable ? VCellSmoldynKeyword.membrane.name() : VCellSmoldynKeyword.volume.name();
                printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " " + VCellSmoldynKeyword.variable + " " + pv.getName() + " " + type + " " + pv.getDomain().getName());
            }
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.N + " " + n + " " + VCellSmoldynKeyword.vcellWriteOutput + " end");
        } else {
            throw new SolverException(SolverDescription.Smoldyn.getDisplayLabel() + " only supports uniform output.");
        }
    }
    printWriter.println();
}
Also used : ParticleInitialConditionConcentration(cbit.vcell.math.ParticleProperties.ParticleInitialConditionConcentration) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) ISize(org.vcell.util.ISize) ProgrammingException(org.vcell.util.ProgrammingException) GeometryException(cbit.vcell.geometry.GeometryException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) ImageException(cbit.image.ImageException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) SolverException(cbit.vcell.solver.SolverException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) TimeStep(cbit.vcell.solver.TimeStep) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) ParticleInitialCondition(cbit.vcell.math.ParticleProperties.ParticleInitialCondition) SolverException(cbit.vcell.solver.SolverException)

Aggregations

DivideByZeroException (cbit.vcell.parser.DivideByZeroException)4 Expression (cbit.vcell.parser.Expression)3 ExpressionException (cbit.vcell.parser.ExpressionException)2 DataAccessException (org.vcell.util.DataAccessException)2 ImageException (cbit.image.ImageException)1 PlotPane (cbit.plot.gui.PlotPane)1 FieldDataParameterVariable (cbit.vcell.field.FieldDataParameterVariable)1 GeometryException (cbit.vcell.geometry.GeometryException)1 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)1 MathException (cbit.vcell.math.MathException)1 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)1 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)1 ParticleInitialCondition (cbit.vcell.math.ParticleProperties.ParticleInitialCondition)1 ParticleInitialConditionConcentration (cbit.vcell.math.ParticleProperties.ParticleInitialConditionConcentration)1 ParticleVariable (cbit.vcell.math.ParticleVariable)1 ReservedVariable (cbit.vcell.math.ReservedVariable)1 SubDomain (cbit.vcell.math.SubDomain)1 VariableType (cbit.vcell.math.VariableType)1 VolumeParticleVariable (cbit.vcell.math.VolumeParticleVariable)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1