Search in sources :

Example 11 with FieldDataIdentifierSpec

use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.

the class RunRefSimulationOp method runFVSolverStandalone.

private static void runFVSolverStandalone(File simulationDataDir, Simulation sim, ExternalDataIdentifier initialConditionExtDataID, ClientTaskStatusSupport progressListener, boolean bCheckSteadyState) throws Exception {
    FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
    FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
    for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
        if (fieldFunctionArgs[i].getFieldName().equals(initialConditionExtDataID.getName())) {
            fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], initialConditionExtDataID);
        } else {
            throw new RuntimeException("failed to resolve field named " + fieldFunctionArgs[i].getFieldName());
        }
    }
    int jobIndex = 0;
    SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs), 0);
    SolverUtilities.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
    // if we need to check steady state, do the following two lines
    if (bCheckSteadyState) {
        simTask.getSimulation().getSolverTaskDescription().setStopAtSpatiallyUniformErrorTolerance(ErrorTolerance.getDefaultSpatiallyUniformErrorTolerance());
    }
    FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simulationDataDir, false);
    fvSolver.startSolver();
    // fvSolver.runSolver();
    SolverStatus status = fvSolver.getSolverStatus();
    while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED && status.getStatus() != SolverStatus.SOLVER_STOPPED) {
        if (progressListener != null) {
            progressListener.setProgress((int) (fvSolver.getProgress() * 100));
            if (progressListener.isInterrupted()) {
                fvSolver.stopSolver();
                throw UserCancelException.CANCEL_GENERIC;
            }
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
            ex.printStackTrace(System.out);
        // catch interrupted exception and ignore it, otherwise it will popup a dialog in user interface saying"sleep interrupted"
        }
        status = fvSolver.getSolverStatus();
    }
    if (status.getStatus() != SolverStatus.SOLVER_FINISHED) {
        throw new Exception("Sover did not finish normally." + status);
    }
}
Also used : SimulationTask(cbit.vcell.messaging.server.SimulationTask) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob) FVSolverStandalone(cbit.vcell.solvers.FVSolverStandalone) ImageException(cbit.image.ImageException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException)

Example 12 with FieldDataIdentifierSpec

use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.

the class SimulationDatabaseDirect method getFieldDataIdentifierSpecs.

@Override
public FieldDataIdentifierSpec[] getFieldDataIdentifierSpecs(Simulation sim) throws DataAccessException {
    try {
        KeyValue simKey = sim.getKey();
        if (lg.isTraceEnabled())
            lg.trace("Get FieldDataIdentifierSpec for [" + simKey + "]");
        FieldDataIdentifierSpec[] fieldDataIDSs = (FieldDataIdentifierSpec[]) simFieldDataIDMap.get(simKey);
        if (fieldDataIDSs != null) {
            return fieldDataIDSs;
        }
        FieldFunctionArguments[] fieldFuncArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
        if (fieldFuncArgs == null || fieldFuncArgs.length == 0) {
            fieldDataIDSs = new FieldDataIdentifierSpec[0];
            simFieldDataIDMap.put(simKey, fieldDataIDSs);
            return fieldDataIDSs;
        }
        fieldDataIDSs = new FieldDataIdentifierSpec[0];
        User owner = sim.getVersion().getOwner();
        FieldDataDBOperationSpec fieldDataDbOperationSpec = FieldDataDBOperationSpec.createGetExtDataIDsSpec(owner);
        FieldDataDBOperationResults fieldDataDBOperationResults = databaseServerImpl.fieldDataDBOperation(owner, fieldDataDbOperationSpec);
        ExternalDataIdentifier[] externalDataIDs = fieldDataDBOperationResults.extDataIDArr;
        if (externalDataIDs != null && externalDataIDs.length != 0 && fieldFuncArgs != null && fieldFuncArgs.length > 0) {
            Vector<FieldDataIdentifierSpec> fieldDataIdV = new Vector<FieldDataIdentifierSpec>();
            for (int j = 0; fieldFuncArgs != null && j < fieldFuncArgs.length; j += 1) {
                for (int i = 0; i < externalDataIDs.length; i += 1) {
                    if (externalDataIDs[i].getName().equals(fieldFuncArgs[j].getFieldName())) {
                        fieldDataIdV.add(new FieldDataIdentifierSpec(fieldFuncArgs[j], externalDataIDs[i]));
                        break;
                    }
                }
            }
            if (fieldDataIdV.size() > 0) {
                fieldDataIDSs = new FieldDataIdentifierSpec[fieldDataIdV.size()];
                fieldDataIdV.copyInto(fieldDataIDSs);
            }
        }
        simFieldDataIDMap.put(simKey, fieldDataIDSs);
        return fieldDataIDSs;
    } catch (Exception ex) {
        lg.error(ex.getMessage(), ex);
        throw new DataAccessException(ex.getMessage());
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) UpdateSynchronizationException(cbit.vcell.server.UpdateSynchronizationException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FieldDataDBOperationResults(cbit.vcell.field.FieldDataDBOperationResults) FieldDataDBOperationSpec(cbit.vcell.field.FieldDataDBOperationSpec) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException)

Example 13 with FieldDataIdentifierSpec

use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.

the class FRAPStudyPanel method refreshPDEDisplay.

protected void refreshPDEDisplay(DisplayChoice choice) throws Exception {
    Simulation sim = null;
    FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
    if (fStudy == null || fStudy.getBioModel() == null || fStudy.getBioModel().getSimulations() == null || fStudy.getBioModel().getSimulations().length < 1) {
        return;
    }
    sim = fStudy.getBioModel().getSimulations()[0];
    FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
    FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
    for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
        fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier());
    }
    PDEDataViewer flourViewer = getFlourDataViewer();
    PDEDataManager dataManager = null;
    if (choice == DisplayChoice.EXTTIMEDATA) {
        flourViewer.setSimulation(null);
        flourViewer.setPdeDataContext(null);
        flourViewer.setDataIdentifierFilter(new DataIdentifierFilter() {

            private String ALL_DATAIDENTIFIERS = "All";

            private String EXP_NORM_FLUOR = "Exp. Norm. Fluor";

            private String SIM_NORM_FLUOR = "Sim. Norm. Fluor";

            private String DEFAULT_VIEW = "Default View (more...)";

            private String[] filterSetNames = new String[] { ALL_DATAIDENTIFIERS, EXP_NORM_FLUOR, SIM_NORM_FLUOR, DEFAULT_VIEW };

            public boolean accept(String filterSetName, List<AnnotatedFunction> myFunctionList, DataIdentifier dataidentifier) {
                if (filterSetName.equals(ALL_DATAIDENTIFIERS)) {
                    return true;
                } else if (filterSetName.equals(EXP_NORM_FLUOR)) {
                    return dataidentifier.getName().indexOf(NORM_FLUOR_VAR) != -1;
                } else if (filterSetName.equals(SIM_NORM_FLUOR)) {
                    boolean a = (dataidentifier.getName().indexOf(REACTION_RATE_PREFIX) == -1) && ((dataidentifier.getName().indexOf(FRAPStudy.SPECIES_NAME_PREFIX_COMBINED) != -1) || (dataidentifier.getName().indexOf(FRAPStudy.SPECIES_NAME_PREFIX_IMMOBILE) != -1) || (dataidentifier.getName().indexOf(FRAPStudy.SPECIES_NAME_PREFIX_MOBILE) != -1) || (dataidentifier.getName().indexOf(FRAPStudy.SPECIES_NAME_PREFIX_SLOW_MOBILE) != -1));
                    return a;
                } else if (filterSetName.equals(DEFAULT_VIEW)) {
                    boolean a = (dataidentifier.getName().indexOf(REACTION_RATE_PREFIX) == -1) && ((dataidentifier.getName().indexOf(NORM_FLUOR_VAR) != -1) || (dataidentifier.getName().indexOf(NORM_SIM_VAR) != -1));
                    return a;
                }
                throw new IllegalArgumentException("DataIdentifierFilter: Unknown filterSetName " + filterSetName);
            }

            public String getDefaultFilterName() {
                return DEFAULT_VIEW;
            }

            public String[] getFilterSetNames() {
                return filterSetNames;
            }

            public boolean isAcceptAll(String filterSetName) {
                return filterSetName.equals(ALL_DATAIDENTIFIERS);
            }

            @Override
            public void setPostProcessingMode(boolean bPostProcessingMode) {
            // TODO Auto-generated method stub
            }

            @Override
            public boolean isPostProcessingMode() {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public ArrayList<DataIdentifier> accept(String filterSetName, List<AnnotatedFunction> myFunctionList, DataIdentifier[] dataidentifiers) {
                if (filterSetName.equals(DEFAULT_VIEW)) {
                    ArrayList<DataIdentifier> dataIds = new ArrayList<>();
                    if (dataidentifiers != null) {
                        for (int i = 0; i < dataidentifiers.length; i++) {
                            dataIds.add(dataidentifiers[i]);
                        }
                    }
                    return dataIds;
                }
                throw new RuntimeException("Not Implemented for FRAP");
            }
        });
        ExternalDataIdentifier timeSeriesExtDataID = fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier();
        ExternalDataIdentifier maskExtDataID = fStudy.getRoiExternalDataInfo().getExternalDataIdentifier();
        // add sim
        int jobIndex = 0;
        SimulationJob simJob = new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs);
        // add function to display normalized fluorence data
        Norm_Exp_Fluor = new Expression(Norm_Exp_Fluor_Str);
        SimulationSymbolTable simSymbolTable = simJob.getSimulationSymbolTable();
        if (// one diffusing component
        simSymbolTable.getVariable(FRAPStudy.SPECIES_NAME_PREFIX_SLOW_MOBILE) == null) {
            Norm_Sim = new Expression(Norm_Sim_One_Diff_Str);
        } else // two diffusing components
        {
            Norm_Sim = new Expression(Norm_Sim_Two_Diff_Str);
        }
        AnnotatedFunction[] func = { new AnnotatedFunction(NORM_FLUOR_VAR, Norm_Exp_Fluor, null, null, VariableType.VOLUME, FunctionCategory.OLDUSERDEFINED), new AnnotatedFunction(NORM_SIM_VAR, Norm_Sim, null, null, VariableType.VOLUME, FunctionCategory.OLDUSERDEFINED) };
        VCDataIdentifier[] dataIDs = new VCDataIdentifier[] { timeSeriesExtDataID, maskExtDataID, simJob.getVCDataIdentifier() };
        VCDataIdentifier vcDataId = new MergedDataInfo(LocalWorkspace.getDefaultOwner(), dataIDs, FRAPStudy.VFRAP_DS_PREFIX);
        outputContext = new OutputContext(func);
        dataManager = new PDEDataManager(outputContext, getLocalWorkspace().getVCDataManager(), vcDataId);
        ClientPDEDataContext pdeDataContext = new ClientPDEDataContext(dataManager);
        pdeDataContext.refreshIdentifiers();
        flourViewer.setSimulation(sim);
        flourViewer.setPdeDataContext(pdeDataContext);
        SimulationModelInfo simModelInfo = new SimulationWorkspaceModelInfo(fStudy.getBioModel().getSimulationContext(sim), sim.getName());
        flourViewer.setSimulationModelInfo(simModelInfo);
        getLocalWorkspace().getDataSetControllerImpl().addDataJobListener(flourViewer);
        ((VirtualFrapWindowManager) flourViewer.getDataViewerManager()).setLocalWorkSpace(getLocalWorkspace());
        // do now show post data processing for VFRAP
        flourViewer.setPostProcessingPanelVisible(false);
        flourViewer.repaint();
    }
}
Also used : ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ArrayList(java.util.ArrayList) MergedDataInfo(cbit.vcell.simdata.MergedDataInfo) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) SimulationJob(cbit.vcell.solver.SimulationJob) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) DataIdentifierFilter(cbit.vcell.client.data.DataIdentifierFilter) SimulationModelInfo(cbit.vcell.solver.SimulationModelInfo) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) Point(java.awt.Point) OutputContext(cbit.vcell.simdata.OutputContext) Simulation(cbit.vcell.solver.Simulation) PDEDataManager(cbit.vcell.simdata.PDEDataManager) Expression(cbit.vcell.parser.Expression) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) PDEDataViewer(cbit.vcell.client.data.PDEDataViewer)

Example 14 with FieldDataIdentifierSpec

use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.

the class FRAPStudyPanel method showMovie.

private void showMovie() {
    AsynchClientTask createMovieTask = new AsynchClientTask("Buffering movie data...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
            if (fStudy == null) {
                return;
            }
            if (fStudy.getMovieURLString() != null && fStudy.getMovieFileString() != null) {
                hashTable.put("FrapStudy", fStudy);
                return;
            }
            // create export specs
            Simulation sim = null;
            if (fStudy.getBioModel() == null || fStudy.getBioModel().getSimulations() == null || fStudy.getBioModel().getSimulations().length < 1) {
                return;
            } else {
                sim = fStudy.getBioModel().getSimulations()[0];
            }
            FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
            FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
            for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
                fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier());
            }
            ExternalDataIdentifier timeSeriesExtDataID = fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier();
            ExternalDataIdentifier maskExtDataID = fStudy.getRoiExternalDataInfo().getExternalDataIdentifier();
            // add sim
            int jobIndex = 0;
            SimulationJob simJob = new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs);
            VCDataIdentifier[] dataIDs = new VCDataIdentifier[] { timeSeriesExtDataID, maskExtDataID, simJob.getVCDataIdentifier() };
            VCDataIdentifier vcDataId = new MergedDataInfo(LocalWorkspace.getDefaultOwner(), dataIDs, FRAPStudy.VFRAP_DS_PREFIX);
            PDEDataManager dataManager = new PDEDataManager(null, getLocalWorkspace().getVCDataManager(), vcDataId);
            PDEDataContext pdeDataContext = new ClientPDEDataContext(dataManager);
            ExportFormat format = ExportFormat.QUICKTIME;
            String[] variableNames = new String[] { NORM_FLUOR_VAR, NORM_SIM_VAR };
            VariableSpecs variableSpecs = new VariableSpecs(variableNames, ExportConstants.VARIABLE_MULTI);
            // int endTimeIndex = (int)Math.round(sim.getSolverTaskDescription().getTimeBounds().getEndingTime()/((UniformOutputTimeSpec)sim.getSolverTaskDescription().getOutputTimeSpec()).getOutputTimeStep());
            int endTimeIndex = getFRAPSimDataViewerPanel().getOriginalDataViewer().getPdeDataContext().getTimePoints().length - 1;
            TimeSpecs timeSpecs = new TimeSpecs(0, endTimeIndex, pdeDataContext.getTimePoints(), ExportConstants.TIME_RANGE);
            int geoMode = ExportConstants.GEOMETRY_SLICE;
            GeometrySpecs geometrySpecs = new GeometrySpecs(null, Coordinate.Z_AXIS, 0, geoMode);
            // 10s
            double duration = 10000;
            DisplayPreferences pref1 = new DisplayPreferences("BlueRed", new Range(0.01, 1.1), DisplayAdapterService.createBlueRedSpecialColors());
            DisplayPreferences pref2 = new DisplayPreferences("BlueRed", new Range(0.01, 1.1), DisplayAdapterService.createBlueRedSpecialColors());
            DisplayPreferences[] displayPref = new DisplayPreferences[] { pref1, pref2 };
            int imageScale = 1;
            int membraneScale = 1;
            int scaleMode = ImagePaneModel.MESH_MODE;
            // the default setting in MediaSettingsPanel.
            int volVarMemOutlineThickness = 1;
            MovieSpecs mSpec = new MovieSpecs(duration, true, displayPref, ExportFormat.QUICKTIME, ExportConstants.NO_MIRRORING, volVarMemOutlineThickness, imageScale, membraneScale, scaleMode, FormatSpecificSpecs.CODEC_JPEG, 1.0f, /*lossless*/
            false, FormatSpecificSpecs.PARTICLE_NONE);
            // mSpec.setViewZoom(1);
            ExportSpecs exSpecs = new ExportSpecs(vcDataId, format, variableSpecs, timeSpecs, geometrySpecs, mSpec, fStudy.getName(), null);
            // pass the request
            ExportEvent exportEvt = ((VirtualFrapWindowManager) getFlourDataViewer().getDataViewerManager()).startExportMovie(exSpecs, outputContext, this.getClientTaskStatusSupport());
            hashTable.put("ExportEvt", exportEvt);
            hashTable.put("FrapStudy", fStudy);
        }
    };
    AsynchClientTask showMovieTask = new AsynchClientTask("Showing movie ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            ExportEvent exportEvt = (ExportEvent) hashTable.get("ExportEvt");
            FRAPStudy fStudy = (FRAPStudy) hashTable.get("FrapStudy");
            // show movie if successfully exported
            if (exportEvt != null) {
                final String fileURLString = System.getProperty(PropertyLoader.exportBaseURLProperty) + exportEvt.getJobID() + ".mov";
                final String fileString = System.getProperty(PropertyLoader.exportBaseDirInternalProperty) + exportEvt.getJobID() + ".mov";
                fStudy.setMovieURLString(fileURLString);
                fStudy.setMovieFileString(fileString);
            }
            showMovieInDialog(fStudy.getMovieURLString(), fStudy.getMovieFileString());
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { createMovieTask, showMovieTask }, true, true, null, true);
}
Also used : ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) PDEDataContext(cbit.vcell.simdata.PDEDataContext) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ExportSpecs(cbit.vcell.export.server.ExportSpecs) ExportEvent(cbit.rmi.event.ExportEvent) GeometrySpecs(cbit.vcell.export.server.GeometrySpecs) MergedDataInfo(cbit.vcell.simdata.MergedDataInfo) DisplayPreferences(cbit.image.DisplayPreferences) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) TimeSpecs(cbit.vcell.export.server.TimeSpecs) SimulationJob(cbit.vcell.solver.SimulationJob) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) Hashtable(java.util.Hashtable) ExportFormat(cbit.vcell.export.server.ExportFormat) Range(org.vcell.util.Range) Point(java.awt.Point) VariableSpecs(cbit.vcell.export.server.VariableSpecs) MovieSpecs(cbit.vcell.export.server.MovieSpecs) Simulation(cbit.vcell.solver.Simulation) PDEDataManager(cbit.vcell.simdata.PDEDataManager) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier)

Example 15 with FieldDataIdentifierSpec

use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.

the class ClientSimManager method runQuickSimulation.

public void runQuickSimulation(final Simulation originalSimulation, ViewerType viewerType) {
    Collection<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
    final SimulationOwner simulationOwner = simWorkspace.getSimulationOwner();
    // ----------- update math if it is from biomodel (simulationContext)
    if (simulationOwner instanceof SimulationContext) {
        Collection<AsynchClientTask> ut = ClientRequestManager.updateMath(documentWindowManager.getComponent(), ((SimulationContext) simulationOwner), false, NetworkGenerationRequirements.ComputeFullStandardTimeout);
        taskList.addAll(ut);
    }
    // ----------- run simulation(s)
    final File localSimDataDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
    AsynchClientTask runSimTask = new AsynchClientTask("running simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Simulation simulation = new TempSimulation(originalSimulation, false);
            SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
            Solver solver = createQuickRunSolver(localSimDataDir, simTask);
            if (solver == null) {
                throw new RuntimeException("null solver");
            }
            // check if spatial stochastic simulation (smoldyn solver) has data processing instructions with field data - need to access server for field data, so cannot do local simulation run.
            if (solver instanceof SmoldynSolver) {
                DataProcessingInstructions dpi = simulation.getDataProcessingInstructions();
                if (dpi != null) {
                    FieldDataIdentifierSpec fdis = dpi.getSampleImageFieldData(simulation.getVersion().getOwner());
                    if (fdis != null) {
                        throw new RuntimeException("Spatial Stochastic simulation '" + simulation.getName() + "' (Smoldyn solver) with field data (in data processing instructions) cannot be run locally at this time since field data needs to be retrieved from the VCell server.");
                    }
                }
            }
            solver.addSolverListener(new SolverListener() {

                public void solverStopped(SolverEvent event) {
                    getClientTaskStatusSupport().setMessage(event.getSimulationMessage().getDisplayMessage());
                }

                public void solverStarting(SolverEvent event) {
                    String displayMessage = event.getSimulationMessage().getDisplayMessage();
                    System.out.println(displayMessage);
                    getClientTaskStatusSupport().setMessage(displayMessage);
                    if (displayMessage.equals(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT.getDisplayMessage())) {
                        getClientTaskStatusSupport().setProgress(75);
                    } else if (displayMessage.equals(SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE.getDisplayMessage())) {
                        getClientTaskStatusSupport().setProgress(90);
                    }
                }

                public void solverProgress(SolverEvent event) {
                    getClientTaskStatusSupport().setMessage("Running...");
                    int progress = (int) (event.getProgress() * 100);
                    getClientTaskStatusSupport().setProgress(progress);
                }

                public void solverPrinted(SolverEvent event) {
                    getClientTaskStatusSupport().setMessage("Running...");
                }

                public void solverFinished(SolverEvent event) {
                    getClientTaskStatusSupport().setMessage(event.getSimulationMessage().getDisplayMessage());
                }

                public void solverAborted(SolverEvent event) {
                    getClientTaskStatusSupport().setMessage(event.getSimulationMessage().getDisplayMessage());
                }
            });
            solver.startSolver();
            while (true) {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                }
                if (getClientTaskStatusSupport().isInterrupted()) {
                    solver.stopSolver();
                    throw UserCancelException.CANCEL_GENERIC;
                }
                SolverStatus solverStatus = solver.getSolverStatus();
                if (solverStatus != null) {
                    if (solverStatus.getStatus() == SolverStatus.SOLVER_ABORTED) {
                        throw new RuntimeException(solverStatus.getSimulationMessage().getDisplayMessage());
                    }
                    if (solverStatus.getStatus() != SolverStatus.SOLVER_STARTING && solverStatus.getStatus() != SolverStatus.SOLVER_READY && solverStatus.getStatus() != SolverStatus.SOLVER_RUNNING) {
                        break;
                    }
                }
            }
            ArrayList<AnnotatedFunction> outputFunctionsList = getSimWorkspace().getSimulationOwner().getOutputFunctionContext().getOutputFunctionsList();
            OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
            Simulation[] simsArray = new Simulation[] { simulation };
            hashTable.put("outputContext", outputContext);
            hashTable.put("simsArray", simsArray);
        }
    };
    taskList.add(runSimTask);
    // --------- add tasks from showSimResults : retrieve data, display results
    AsynchClientTask[] showResultsTask = showSimulationResults0(true, viewerType);
    for (AsynchClientTask task : showResultsTask) {
        taskList.add(task);
    }
    // ------- dispatch
    AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
    taskList.toArray(taskArray);
    ClientTaskDispatcher.dispatch(documentWindowManager.getComponent(), new Hashtable<String, Object>(), taskArray, true, true, null);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) SmoldynSolver(org.vcell.solver.smoldyn.SmoldynSolver) Solver(cbit.vcell.solver.server.Solver) SimulationTask(cbit.vcell.messaging.server.SimulationTask) ArrayList(java.util.ArrayList) SimulationOwner(cbit.vcell.solver.SimulationOwner) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) SolverListener(cbit.vcell.solver.server.SolverListener) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) Hashtable(java.util.Hashtable) TempSimulation(cbit.vcell.solver.TempSimulation) SimulationContext(cbit.vcell.mapping.SimulationContext) OutputContext(cbit.vcell.simdata.OutputContext) SolverEvent(cbit.vcell.solver.server.SolverEvent) Simulation(cbit.vcell.solver.Simulation) TempSimulation(cbit.vcell.solver.TempSimulation) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SmoldynSolver(org.vcell.solver.smoldyn.SmoldynSolver) EventObject(java.util.EventObject) File(java.io.File)

Aggregations

FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)26 FieldFunctionArguments (cbit.vcell.field.FieldFunctionArguments)15 DataAccessException (org.vcell.util.DataAccessException)11 SimulationJob (cbit.vcell.solver.SimulationJob)10 File (java.io.File)10 Simulation (cbit.vcell.solver.Simulation)9 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)9 Expression (cbit.vcell.parser.Expression)8 SimulationTask (cbit.vcell.messaging.server.SimulationTask)7 VariableType (cbit.vcell.math.VariableType)6 ExpressionException (cbit.vcell.parser.ExpressionException)6 UserCancelException (org.vcell.util.UserCancelException)6 ImageException (cbit.image.ImageException)5 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)5 SolverStatus (cbit.vcell.solver.server.SolverStatus)5 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)5 SimDataBlock (cbit.vcell.simdata.SimDataBlock)4 CartesianMesh (cbit.vcell.solvers.CartesianMesh)4 IOException (java.io.IOException)4 StringTokenizer (java.util.StringTokenizer)4