Search in sources :

Example 1 with JobManager

use of cbit.vcell.client.server.JobManager 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)

Aggregations

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 Geometry (cbit.vcell.geometry.Geometry)1 GeometrySurfaceDescription (cbit.vcell.geometry.surface.GeometrySurfaceDescription)1 MathModel (cbit.vcell.mathmodel.MathModel)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 SimulationStatus (cbit.vcell.server.SimulationStatus)1 DataProcessingInstructions (cbit.vcell.solver.DataProcessingInstructions)1 MeshSpecification (cbit.vcell.solver.MeshSpecification)1 Simulation (cbit.vcell.solver.Simulation)1 SimulationInfo (cbit.vcell.solver.SimulationInfo)1 SimulationJob (cbit.vcell.solver.SimulationJob)1 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)1 ISize (org.vcell.util.ISize)1 UserCancelException (org.vcell.util.UserCancelException)1 VCDocument (org.vcell.util.document.VCDocument)1