Search in sources :

Example 6 with FVSolverStandalone

use of cbit.vcell.solvers.FVSolverStandalone in project vcell by virtualcell.

the class FRAPStudy method runFVSolverStandalone_ref.

public static void runFVSolverStandalone_ref(File simulationDataDir, Simulation sim, ExternalDataIdentifier imageDataExtDataID, ExternalDataIdentifier roiExtDataID, ExternalDataIdentifier psfExtDataID, 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(imageDataExtDataID.getName())) {
            fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], imageDataExtDataID);
        } else if (fieldFunctionArgs[i].getFieldName().equals(roiExtDataID.getName())) {
            fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], roiExtDataID);
        } else if (fieldFunctionArgs[i].getFieldName().equals(psfExtDataID.getName())) {
            fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], psfExtDataID);
        } 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());
    // simJob.getSimulation().getSolverTaskDescription().setErrorTolerance(new ErrorTolerance(1e-6, 1e-2));
    }
    FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simulationDataDir, false);
    fvSolver.startSolver();
    SolverStatus status = fvSolver.getSolverStatus();
    while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED) {
        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) UserCancelException(org.vcell.util.UserCancelException)

Example 7 with FVSolverStandalone

use of cbit.vcell.solvers.FVSolverStandalone in project vcell by virtualcell.

the class RunSimulation2DOp method runFVSolverStandalone.

private static void runFVSolverStandalone(File simulationDataDir, Simulation sim, ClientTaskStatusSupport progressListener) throws Exception {
    int jobIndex = 0;
    SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, null), 0);
    SolverUtilities.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
    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) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob) FVSolverStandalone(cbit.vcell.solvers.FVSolverStandalone) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

SimulationTask (cbit.vcell.messaging.server.SimulationTask)7 SimulationJob (cbit.vcell.solver.SimulationJob)7 SolverStatus (cbit.vcell.solver.server.SolverStatus)7 FVSolverStandalone (cbit.vcell.solvers.FVSolverStandalone)7 UserCancelException (org.vcell.util.UserCancelException)6 ImageException (cbit.image.ImageException)4 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)4 FieldFunctionArguments (cbit.vcell.field.FieldFunctionArguments)4 IOException (java.io.IOException)3 File (java.io.File)2 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)2 MathModel (cbit.vcell.mathmodel.MathModel)1 DataOperationResults (cbit.vcell.simdata.DataOperationResults)1 ErrorTolerance (cbit.vcell.solver.ErrorTolerance)1 Simulation (cbit.vcell.solver.Simulation)1 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)1 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)1 XMLSource (cbit.vcell.xml.XMLSource)1 FileNotFoundException (java.io.FileNotFoundException)1 PrintWriter (java.io.PrintWriter)1