Search in sources :

Example 6 with MeshSpecification

use of cbit.vcell.solver.MeshSpecification in project vcell by virtualcell.

the class SimulationEditor method prepareToEdit.

/**
 * Comment
 * @param simulation not null
 * @param parent
 * @throws ChomboInvalidGeometryException
 * @throws NullPointerException
 */
public void prepareToEdit(Simulation simulation, Component parent) throws ChomboInvalidGeometryException {
    Objects.requireNonNull(simulation);
    try {
        Simulation clonedSimulation = (Simulation) BeanUtils.cloneSerializable(simulation);
        clonedSimulation.refreshDependencies();
        getMathOverridesPanel1().setMathOverrides(clonedSimulation == null ? null : clonedSimulation.getMathOverrides());
        getMeshTabPanel().setSimulation(parent, clonedSimulation);
        SolverTaskDescriptionAdvancedPanel stdap = getSolverTaskDescriptionAdvancedPanel1();
        {
            SimulationOwner so = simulation.getSimulationOwner();
            UnitInfo unitInfo = so.getUnitInfo();
            stdap.setUnitInfo(unitInfo);
        }
        stdap.setSolverTaskDescription(clonedSimulation == null ? null : clonedSimulation.getSolverTaskDescription());
        boolean shouldMeshBeEnabled = false;
        MeshSpecification meshSpec = clonedSimulation.getMeshSpecification();
        if (meshSpec != null && meshSpec.getGeometry() != null && meshSpec.getGeometry().getDimension() > 0) {
            shouldMeshBeEnabled = true;
        }
        if (!shouldMeshBeEnabled) {
            getJTabbedPane1().remove(getMeshTabPanel());
        }
        setClonedSimulation(clonedSimulation);
    } catch (ChomboInvalidGeometryException exc) {
        // if this happens, sim is not allowed to edit
        exc.printStackTrace(System.out);
        throw exc;
    } catch (Throwable exc) {
        exc.printStackTrace(System.out);
        JOptionPane.showMessageDialog(this, "Could not initialize simulation editor\n" + exc.getMessage(), "Error:", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : SimulationOwner(cbit.vcell.solver.SimulationOwner) UnitInfo(cbit.vcell.solver.SimulationOwner.UnitInfo) Simulation(cbit.vcell.solver.Simulation) SolverTaskDescriptionAdvancedPanel(cbit.vcell.solver.ode.gui.SolverTaskDescriptionAdvancedPanel) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException) MeshSpecification(cbit.vcell.solver.MeshSpecification)

Example 7 with MeshSpecification

use of cbit.vcell.solver.MeshSpecification in project vcell by virtualcell.

the class RunSims method run.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
    ClientSimManager clientSimManager = (ClientSimManager) hashTable.get("clientSimManager");
    // DocumentManager documentManager = (DocumentManager)hashTable.get(CommonTask.DOCUMENT_MANAGER.name);
    JobManager jobManager = (JobManager) hashTable.get("jobManager");
    Simulation[] simulations = (Simulation[]) hashTable.get("simulations");
    Hashtable<Simulation, Throwable> failures = new Hashtable<Simulation, Throwable>();
    if (simulations != null && simulations.length > 0) {
        // we need to get the new ones if a save occurred...
        if (hashTable.containsKey(SaveDocument.DOC_KEY)) {
            VCDocument savedDocument = (VCDocument) hashTable.get(SaveDocument.DOC_KEY);
            Simulation[] allSims = null;
            if (savedDocument instanceof BioModel) {
                allSims = ((BioModel) savedDocument).getSimulations();
            } else if (savedDocument instanceof MathModel) {
                allSims = ((MathModel) savedDocument).getSimulations();
            }
            Vector<Simulation> v = new Vector<Simulation>();
            for (int i = 0; i < simulations.length; i++) {
                for (int j = 0; j < allSims.length; j++) {
                    if (simulations[i].getName().equals(allSims[j].getName())) {
                        v.add(allSims[j]);
                        break;
                    }
                }
            }
            simulations = (Simulation[]) BeanUtils.getArray(v, Simulation.class);
        }
        for (Simulation sim : simulations) {
            try {
                int dimension = sim.getMathDescription().getGeometry().getDimension();
                if (clientSimManager.getSimulationStatus(sim).isCompleted()) {
                    // completed
                    String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_1, sim.getName());
                    String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                    if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                        continue;
                    }
                }
                DataProcessingInstructions dataProcessingInstructions = sim.getDataProcessingInstructions();
                try {
                    if (dataProcessingInstructions != null) {
                        dataProcessingInstructions.getSampleImageFieldData(sim.getVersion().getOwner());
                    }
                } catch (Exception ex) {
                    DialogUtils.showErrorDialog(documentWindowManager.getComponent(), "Problem found in simulation '" + sim.getName() + "':\n" + ex.getMessage());
                    continue;
                }
                if (dimension > 0) {
                    MeshSpecification meshSpecification = sim.getMeshSpecification();
                    boolean bCellCentered = sim.hasCellCenteredMesh();
                    if (meshSpecification != null && !meshSpecification.isAspectRatioOK(bCellCentered)) {
                        String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_2, sim.getName(), "\u0394x=" + meshSpecification.getDx(bCellCentered) + "\n" + "\u0394y=" + meshSpecification.getDy(bCellCentered) + (dimension < 3 ? "" : "\n\u0394z=" + meshSpecification.getDz(bCellCentered)));
                        String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                        if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                            continue;
                        }
                    }
                    if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.Smoldyn)) {
                        if (!isSmoldynTimeStepOK(sim)) {
                            double s = smoldynTimestepVars.getSpatialResolution();
                            double dMax = smoldynTimestepVars.getMaxDiffusion();
                            double condn = (s * s) / (2.0 * dMax);
                            String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_3, Double.toString(s), Double.toString(dMax), Double.toString(condn));
                            DialogUtils.showErrorDialog(documentWindowManager.getComponent(), warningMessage);
                            continue;
                        }
                    }
                    // check the number of regions if the simulation mesh is coarser.
                    Geometry mathGeometry = sim.getMathDescription().getGeometry();
                    ISize newSize = meshSpecification.getSamplingSize();
                    ISize defaultSize = mathGeometry.getGeometrySpec().getDefaultSampledImageSize();
                    if (!sim.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
                        int defaultTotalVolumeElements = mathGeometry.getGeometrySurfaceDescription().getVolumeSampleSize().getXYZ();
                        int newTotalVolumeElements = meshSpecification.getSamplingSize().getXYZ();
                        if (defaultTotalVolumeElements > newTotalVolumeElements) {
                            // coarser
                            Geometry resampledGeometry = (Geometry) BeanUtils.cloneSerializable(mathGeometry);
                            GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
                            geoSurfaceDesc.setVolumeSampleSize(newSize);
                            geoSurfaceDesc.updateAll();
                            if (mathGeometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
                                mathGeometry.getGeometrySurfaceDescription().updateAll();
                            }
                            int defaultNumGeometricRegions = mathGeometry.getGeometrySurfaceDescription().getGeometricRegions().length;
                            int numGeometricRegions = geoSurfaceDesc.getGeometricRegions().length;
                            if (numGeometricRegions != defaultNumGeometricRegions) {
                                String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_4, newSize.getX() + (dimension > 1 ? " x " + newSize.getY() : "") + (dimension > 2 ? " x " + newSize.getZ() : ""), sim.getName(), numGeometricRegions, defaultNumGeometricRegions);
                                String result = PopupGenerator.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                                if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                                    continue;
                                }
                            }
                        }
                        if (mathGeometry.getGeometrySpec().hasImage()) {
                            // if it's an image.
                            if (defaultSize.getX() + 1 < newSize.getX() || defaultSize.getY() + 1 < newSize.getY() || defaultSize.getZ() + 1 < newSize.getZ()) {
                                // finer
                                String defaultSizeString = (defaultSize.getX() + 1) + (dimension > 1 ? " x " + (defaultSize.getY() + 1) : "") + (dimension > 2 ? " x " + (defaultSize.getZ() + 1) : "");
                                String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_5, newSize.getX() + (dimension > 1 ? " x " + newSize.getY() : "") + (dimension > 2 ? " x " + newSize.getZ() : ""), sim.getName(), defaultSizeString, defaultSizeString);
                                String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                                if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                                    continue;
                                }
                            }
                        }
                    }
                    boolean bGiveWarning = false;
                    for (int i = 0; i < sim.getScanCount(); i++) {
                        if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.SundialsPDE)) {
                            SimulationJob simJob = new SimulationJob(sim, i, null);
                            if (simJob.getSimulationSymbolTable().hasTimeVaryingDiffusionOrAdvection()) {
                                bGiveWarning = true;
                                break;
                            }
                        }
                    }
                    if (bGiveWarning) {
                        String warningMessage = VCellErrorMessages.RunSims_6;
                        String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                        if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                            continue;
                        }
                    }
                }
                SimulationInfo simInfo = sim.getSimulationInfo();
                if (simInfo != null) {
                    // 
                    // translate to common ancestral simulation (oldest mathematically equivalent simulation)
                    // 
                    SimulationStatus simulationStatus = jobManager.startSimulation(simInfo.getAuthoritativeVCSimulationIdentifier(), sim.getScanCount());
                    // updateStatus
                    clientSimManager.updateStatusFromStartRequest(sim, simulationStatus);
                } else {
                    // this should really not happen...
                    throw new RuntimeException(">>>>>>>>>> trying to run an unsaved simulation...");
                }
            } catch (Throwable exc) {
                exc.printStackTrace(System.out);
                failures.put(sim, exc);
            }
        }
    }
    // we deal with individual request failures here, passing down only other things (that break the whole thing down) to dispatcher
    if (!failures.isEmpty()) {
        Enumeration<Simulation> en = failures.keys();
        while (en.hasMoreElements()) {
            Simulation sim = en.nextElement();
            Throwable exc = (Throwable) failures.get(sim);
            // // updateStatus
            // SimulationStatus simulationStatus = clientSimManager.updateStatusFromStartRequest(sim, true, exc.getMessage());
            // notify user
            PopupGenerator.showErrorDialog(documentWindowManager, "Failed to start simulation'" + sim.getName() + "'\n" + exc.getMessage());
        }
    }
}
Also used : ClientSimManager(cbit.vcell.client.ClientSimManager) MathModel(cbit.vcell.mathmodel.MathModel) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) ISize(org.vcell.util.ISize) JobManager(cbit.vcell.client.server.JobManager) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) Vector(java.util.Vector) SimulationJob(cbit.vcell.solver.SimulationJob) VCDocument(org.vcell.util.document.VCDocument) Hashtable(java.util.Hashtable) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) MeshSpecification(cbit.vcell.solver.MeshSpecification) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) SimulationStatus(cbit.vcell.server.SimulationStatus) BioModel(cbit.vcell.biomodel.BioModel) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Example 8 with MeshSpecification

use of cbit.vcell.solver.MeshSpecification in project vcell by virtualcell.

the class SmoldynFileWriter method writeInitialConcentration.

private int writeInitialConcentration(ParticleInitialConditionConcentration initialConcentration, SubDomain subDomain, Variable variable, String variableName, StringBuilder sb) throws ExpressionException, MathException {
    SimpleSymbolTable simpleSymbolTable = new SimpleSymbolTable(new String[] { ReservedVariable.X.getName(), ReservedVariable.Y.getName(), ReservedVariable.Z.getName() });
    Expression disExpression = new Expression(initialConcentration.getDistribution());
    disExpression.bindExpression(simulationSymbolTable);
    disExpression = simulationSymbolTable.substituteFunctions(disExpression).flatten();
    disExpression.bindExpression(simpleSymbolTable);
    double[] values = new double[3];
    if (dimension == 1) {
        if (disExpression.getSymbolBinding(ReservedVariable.Y.getName()) != null || disExpression.getSymbolBinding(ReservedVariable.Z.getName()) != null) {
            throw new MathException(VCellErrorMessages.getSmoldynWrongCoordinates("'y' or 'z'", dimension, variable, disExpression));
        }
    } else if (dimension == 2) {
        if (disExpression.getSymbolBinding(ReservedVariable.Z.getName()) != null) {
            throw new MathException(VCellErrorMessages.getSmoldynWrongCoordinates("'z'", dimension, variable, disExpression));
        }
    }
    int totalCount = 0;
    StringBuilder localsb = new StringBuilder();
    if (subDomain instanceof CompartmentSubDomain) {
        MeshSpecification meshSpecification = simulation.getMeshSpecification();
        ISize sampleSize = meshSpecification.getSamplingSize();
        int numX = sampleSize.getX();
        int numY = dimension < 2 ? 1 : sampleSize.getY();
        int numZ = dimension < 3 ? 1 : sampleSize.getZ();
        boolean bCellCentered = simulation.hasCellCenteredMesh();
        double dx = meshSpecification.getDx(bCellCentered);
        double dy = meshSpecification.getDy(bCellCentered);
        double dz = meshSpecification.getDz(bCellCentered);
        Origin origin = resampledGeometry.getGeometrySpec().getOrigin();
        double ox = origin.getX();
        double oy = origin.getY();
        double oz = origin.getZ();
        Extent extent = resampledGeometry.getExtent();
        double ex = extent.getX();
        double ey = extent.getY();
        double ez = extent.getZ();
        int offset = 0;
        for (int k = 0; k < numZ; k++) {
            double centerz = oz + k * dz;
            double loz = Math.max(oz, centerz - dz / 2);
            double hiz = Math.min(oz + ez, centerz + dz / 2);
            double lz = hiz - loz;
            values[2] = centerz;
            for (int j = 0; j < numY; j++) {
                double centery = oy + j * dy;
                double loy = Math.max(oy, centery - dy / 2);
                double hiy = Math.min(oy + ey, centery + dy / 2);
                values[1] = centery;
                double ly = hiy - loy;
                for (int i = 0; i < numX; i++) {
                    int regionIndex = resampledGeometry.getGeometrySurfaceDescription().getRegionImage().getRegionInfoFromOffset(offset).getRegionIndex();
                    offset++;
                    GeometricRegion region = resampledGeometry.getGeometrySurfaceDescription().getGeometricRegions(regionIndex);
                    if (region instanceof VolumeGeometricRegion) {
                        if (!((VolumeGeometricRegion) region).getSubVolume().getName().equals(subDomain.getName())) {
                            continue;
                        }
                    }
                    double centerx = ox + i * dx;
                    double lox = Math.max(ox, centerx - dx / 2);
                    double hix = Math.min(ox + ex, centerx + dx / 2);
                    double lx = hix - lox;
                    values[0] = centerx;
                    double volume = lx;
                    if (dimension > 1) {
                        volume *= ly;
                        if (dimension > 2) {
                            volume *= lz;
                        }
                    }
                    double expectedCount = disExpression.evaluateVector(values) * volume;
                    if (expectedCount <= 0) {
                        continue;
                    }
                    long count = dist.nextPoisson(expectedCount);
                    if (count <= 0) {
                        continue;
                    }
                    totalCount += count;
                    localsb.append(SmoldynVCellMapper.SmoldynKeyword.mol + " " + count + " " + variableName + " " + (float) lox + "-" + (float) hix);
                    if (lg.isDebugEnabled()) {
                        lg.debug("Component subdomain " + variableName + " count " + count);
                    }
                    if (dimension > 1) {
                        localsb.append(" " + loy + "-" + hiy);
                        if (dimension > 2) {
                            localsb.append(" " + loz + "-" + hiz);
                        }
                    }
                    localsb.append("\n");
                }
            }
        }
        // otherwise we append the distributed molecules in different small boxes
        try {
            subsituteFlattenToConstant(disExpression);
            sb.append(SmoldynVCellMapper.SmoldynKeyword.compartment_mol);
            sb.append(" " + totalCount + " " + variableName + " " + subDomain.getName() + "\n");
        } catch (// can not be evaluated to a constant
        Exception e) {
            sb.append(localsb);
        }
    } else if (subDomain instanceof MembraneSubDomain) {
        ArrayList<TrianglePanel> trianglePanelList = membraneSubdomainTriangleMap.get(subDomain);
        for (TrianglePanel trianglePanel : trianglePanelList) {
            Triangle triangle = trianglePanel.triangle;
            switch(dimension) {
                case 1:
                    values[0] = triangle.getNodes(0).getX();
                    break;
                case 2:
                    {
                        double centroidX = triangle.getNodes(0).getX();
                        double centroidY = triangle.getNodes(0).getY();
                        if (triangle.getNodes(0).getX() == triangle.getNodes(1).getX() && triangle.getNodes(0).getY() == triangle.getNodes(1).getY()) {
                            centroidX += triangle.getNodes(2).getX();
                            centroidY += triangle.getNodes(2).getY();
                        } else {
                            centroidX += triangle.getNodes(1).getX();
                            centroidY += triangle.getNodes(1).getY();
                        }
                        values[0] = centroidX / 2;
                        values[1] = centroidY / 2;
                        break;
                    }
                case 3:
                    {
                        double centroidX = triangle.getNodes(0).getX() + triangle.getNodes(1).getX() + triangle.getNodes(2).getX();
                        double centroidY = triangle.getNodes(0).getY() + triangle.getNodes(1).getY() + triangle.getNodes(2).getY();
                        double centroidZ = triangle.getNodes(0).getZ() + triangle.getNodes(1).getZ() + triangle.getNodes(2).getZ();
                        values[0] = centroidX / 3;
                        values[1] = centroidY / 3;
                        values[2] = centroidZ / 3;
                        break;
                    }
            }
            double expectedCount = disExpression.evaluateVector(values) * triangle.getArea();
            if (expectedCount <= 0) {
                continue;
            }
            long count = dist.nextPoisson(expectedCount);
            if (count <= 0) {
                continue;
            }
            totalCount += count;
            if (lg.isDebugEnabled()) {
                lg.debug("Membrane subdomain " + subDomain.getName() + ' ' + variableName + " count " + count);
            }
            localsb.append(SmoldynVCellMapper.SmoldynKeyword.surface_mol + " " + count + " " + variableName + " " + subDomain.getName() + " " + SmoldynVCellMapper.SmoldynKeyword.tri + " " + trianglePanel.name + "\n");
        }
        // otherwise we append the distributed molecules in different small boxes
        try {
            subsituteFlattenToConstant(disExpression);
            sb.append(SmoldynVCellMapper.SmoldynKeyword.surface_mol);
            sb.append(" " + totalCount + " " + variableName + " " + subDomain.getName() + " " + SmoldynVCellMapper.SmoldynKeyword.all + " " + SmoldynVCellMapper.SmoldynKeyword.all + "\n");
        } catch (// can not be evaluated to a constant
        Exception e) {
            sb.append(localsb);
        }
    }
    if (lg.isDebugEnabled()) {
        lg.debug("Subdomain " + subDomain.getName() + ' ' + variableName + " total count " + totalCount);
    }
    return totalCount;
}
Also used : Origin(org.vcell.util.Origin) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ArrayList(java.util.ArrayList) Triangle(cbit.vcell.geometry.surface.Triangle) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) MeshSpecification(cbit.vcell.solver.MeshSpecification) 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) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain)

Example 9 with MeshSpecification

use of cbit.vcell.solver.MeshSpecification in project vcell by virtualcell.

the class SimulationTable method getSimulation.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.math.MathDescription
 * @param user cbit.vcell.server.User
 * @param rset java.sql.ResultSet
 */
public Simulation getSimulation(QueryHashtable dbc, ResultSet rset, Connection con, User user, MathDescriptionDbDriver mathDB, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException, PropertyVetoException {
    // 
    // get TaskDescription Data into parsable form
    // 
    // 
    // String taskDescriptionString = new String(solverTaskDescData);
    // 
    // System.out.println("taskDescriptionString '"+taskDescriptionString+"'");
    String taskDescriptionString = rset.getString(SimulationTable.table.taskDescription.getUnqualifiedColName());
    taskDescriptionString = TokenMangler.getSQLRestoredString(taskDescriptionString);
    CommentStringTokenizer solverTaskDescTokens = new CommentStringTokenizer(taskDescriptionString);
    // 
    // get MathOverride Data (language) (MUST BE READ FIRST)
    // 
    /*
	byte[] mathOverridesData = null;
	mathOverridesData = rset.getBytes(SimulationTable.table.mathOverrides.toString());
	if (rset.wasNull() || mathOverridesData==null || mathOverridesData.length==0){
		throw new DataAccessException("no data stored for MathOverrides");
	}
	String mathOverridesString = new String(mathOverridesData);
	*/
    // 
    CommentStringTokenizer mathOverrideTokens = getMathOverridesTokenizer(rset, dbSyntax);
    String dataProcessingInstructionString = rset.getString(dataProcInstr.getUnqualifiedColName());
    DataProcessingInstructions dpi = null;
    if (!rset.wasNull() && dataProcessingInstructionString != null && dataProcessingInstructionString.length() > 0) {
        dataProcessingInstructionString = TokenMangler.getSQLRestoredString(dataProcessingInstructionString);
        dpi = DataProcessingInstructions.fromDbXml(dataProcessingInstructionString);
    }
    // 
    // Get Version
    // 
    java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
    SimulationVersion simulationVersion = (SimulationVersion) getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
    java.math.BigDecimal bigD = rset.getBigDecimal(SimulationTable.table.mathRef.toString());
    KeyValue mathKey = null;
    if (!rset.wasNull()) {
        mathKey = new KeyValue(bigD);
    } else {
        throw new DataAccessException("Error:  MathDescription Reference Cannot be Null for Simulation");
    }
    MathDescription mathDesc = (MathDescription) mathDB.getVersionable(dbc, con, user, VersionableType.MathDescription, mathKey);
    Simulation simulation = new Simulation(simulationVersion, mathDesc, mathOverrideTokens, solverTaskDescTokens);
    simulation.setDataProcessingInstructions(dpi);
    // MeshSpec (Is This Correct?????)
    if (mathDesc != null && mathDesc.getGeometry() != null && mathDesc.getGeometry().getDimension() > 0) {
        int msX = rset.getInt(SimulationTable.table.meshSpecX.getUnqualifiedColName());
        int msY = rset.getInt(SimulationTable.table.meshSpecY.getUnqualifiedColName());
        int msZ = rset.getInt(SimulationTable.table.meshSpecZ.getUnqualifiedColName());
        MeshSpecification meshSpec = new MeshSpecification(simulation.getMathDescription().getGeometry());
        meshSpec.setSamplingSize(new ISize(msX, msY, msZ));
        simulation.getMeshSpecification().copyFrom(meshSpec);
    }
    return simulation;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) MathDescription(cbit.vcell.math.MathDescription) ISize(org.vcell.util.ISize) MeshSpecification(cbit.vcell.solver.MeshSpecification) BigDecimal(java.math.BigDecimal) SimulationVersion(org.vcell.util.document.SimulationVersion) Simulation(cbit.vcell.solver.Simulation) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) CommentStringTokenizer(org.vcell.util.CommentStringTokenizer) DataAccessException(org.vcell.util.DataAccessException)

Example 10 with MeshSpecification

use of cbit.vcell.solver.MeshSpecification in project vcell by virtualcell.

the class SimulationTable method getSQLValueList.

/**
 * This method was created in VisualAge.
 * @return java.lang.String
 * @param key KeyValue
 * @param modelName java.lang.String
 */
public String getSQLValueList(Simulation simulation, KeyValue mathKey, Version version, DatabaseSyntax dbSyntax) {
    SolverTaskDescription solverTD = simulation.getSolverTaskDescription();
    String mathOverrides = simulation.getMathOverrides().getVCML();
    StringBuffer buffer = new StringBuffer();
    switch(dbSyntax) {
        case ORACLE:
            {
                buffer.append("(");
                buffer.append(getVersionGroupSQLValue(version) + ",");
                buffer.append(mathKey + ",");
                // MathOverridesOrig keep for compatibility with old VCell
                buffer.append("EMPTY_CLOB()" + ",");
                break;
            }
        case POSTGRES:
            {
                buffer.append("(");
                buffer.append(getVersionGroupSQLValue(version) + ",");
                buffer.append(mathKey + ",");
                // MathOverridesOrig keep for compatibility with old VCell
                buffer.append("null" + ",");
                break;
            }
        default:
            {
                throw new RuntimeException("unexpected DatabaseSyntax " + dbSyntax);
            }
    }
    if (DbDriver.varchar2_CLOB_is_Varchar2_OK(mathOverrides)) {
        buffer.append("null" + "," + DbDriver.INSERT_VARCHAR2_HERE + ",");
    } else {
        buffer.append(DbDriver.INSERT_CLOB_HERE + "," + "null" + ",");
    }
    buffer.append((solverTD != null ? "'" + TokenMangler.getSQLEscapedString(solverTD.getVCML()) + "'" : "null") + ",");
    if (simulation.getMathDescription() != null && simulation.getMathDescription().getGeometry() != null && simulation.getMathDescription().getGeometry().getDimension() > 0) {
        MeshSpecification meshSpec = simulation.getMeshSpecification();
        buffer.append(meshSpec.getSamplingSize().getX() + "," + meshSpec.getSamplingSize().getY() + "," + meshSpec.getSamplingSize().getZ());
    } else {
        buffer.append("null,null,null");
    }
    if (simulation.getDataProcessingInstructions() != null) {
        buffer.append(",'" + TokenMangler.getSQLEscapedString(simulation.getDataProcessingInstructions().getDbXml()) + "'");
    } else {
        buffer.append(",null");
    }
    buffer.append(")");
    return buffer.toString();
}
Also used : SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) MeshSpecification(cbit.vcell.solver.MeshSpecification)

Aggregations

MeshSpecification (cbit.vcell.solver.MeshSpecification)10 ISize (org.vcell.util.ISize)6 Geometry (cbit.vcell.geometry.Geometry)4 Simulation (cbit.vcell.solver.Simulation)4 SolverTaskDescription (cbit.vcell.solver.SolverTaskDescription)3 GeometricRegion (cbit.vcell.geometry.surface.GeometricRegion)2 SurfaceGeometricRegion (cbit.vcell.geometry.surface.SurfaceGeometricRegion)2 VolumeGeometricRegion (cbit.vcell.geometry.surface.VolumeGeometricRegion)2 Expression (cbit.vcell.parser.Expression)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 DataProcessingInstructions (cbit.vcell.solver.DataProcessingInstructions)2 DefaultOutputTimeSpec (cbit.vcell.solver.DefaultOutputTimeSpec)2 PropertyVetoException (java.beans.PropertyVetoException)2 ArrayList (java.util.ArrayList)2 DataAccessException (org.vcell.util.DataAccessException)2 ImageException (cbit.image.ImageException)1 BioModel (cbit.vcell.biomodel.BioModel)1 ClientSimManager (cbit.vcell.client.ClientSimManager)1 DocumentWindowManager (cbit.vcell.client.DocumentWindowManager)1 JobManager (cbit.vcell.client.server.JobManager)1