Search in sources :

Example 11 with DefaultOutputTimeSpec

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

the class SundialsSolver method writeLogFile.

private void writeLogFile() throws SolverException {
    String logFile = getBaseName() + LOGFILE_EXTENSION;
    String ideDataFileName = new File(getBaseName() + IDA_DATA_EXTENSION).getName();
    PrintWriter pw = null;
    try {
        pw = new PrintWriter(logFile);
        pw.println(IDA_DATA_IDENTIFIER);
        pw.println(IDA_DATA_FORMAT_ID);
        pw.println(ideDataFileName);
        OutputTimeSpec outputTimeSpec = simTask.getSimulation().getSolverTaskDescription().getOutputTimeSpec();
        if (outputTimeSpec.isDefault()) {
            pw.println(KEEP_MOST + " " + ((DefaultOutputTimeSpec) outputTimeSpec).getKeepAtMost());
        }
        pw.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        throw new SolverException(e.getMessage());
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}
Also used : DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) FileNotFoundException(java.io.FileNotFoundException) SolverException(cbit.vcell.solver.SolverException) File(java.io.File) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) PrintWriter(java.io.PrintWriter)

Example 12 with DefaultOutputTimeSpec

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

the class MovingBoundaryFileWriter method gettimeReport.

private Element gettimeReport() {
    Element e = new Element(MBTags.timeReport);
    Element e1 = null;
    OutputTimeSpec outTimeSpec = simTask.getSimulation().getSolverTaskDescription().getOutputTimeSpec();
    if (outTimeSpec instanceof UniformOutputTimeSpec) {
        UniformOutputTimeSpec uniformOutputTimeSpec = (UniformOutputTimeSpec) outTimeSpec;
        double interval = uniformOutputTimeSpec.getOutputTimeStep();
        // hard coded.
        double startTime = 0.0;
        e1 = new Element(MBTags.startTime);
        e1.setText("0");
        e.addContent(e1);
        e1 = new Element(MBTags.interval);
        e1.setText(interval + "");
        e.addContent(e1);
    } else if (outTimeSpec instanceof DefaultOutputTimeSpec) {
        DefaultOutputTimeSpec defaultOutputTimeSpec = (DefaultOutputTimeSpec) outTimeSpec;
        Integer step = defaultOutputTimeSpec.getKeepEvery();
        // hard code
        double startTime = 0.0;
        e1 = new Element(MBTags.startTime);
        e1.setText("0");
        e.addContent(e1);
        e1 = new Element(MBTags.step);
        e1.setText(step.toString());
        e.addContent(e1);
    }
    return e;
}
Also used : DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) Element(org.jdom.Element) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 13 with DefaultOutputTimeSpec

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

the class StochFileWriter method write.

/**
 * Write the model to a text file which serves as an input for Stochastic simulation engine.
 * Creation date: (6/22/2006 5:37:26 PM)
 */
public void write(String[] parameterNames) throws Exception, ExpressionException {
    Simulation simulation = simTask.getSimulation();
    SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
    initialize();
    if (bUseMessaging) {
        writeJMSParamters();
    }
    // Write control information
    printWriter.println("<control>");
    cbit.vcell.solver.SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
    cbit.vcell.solver.TimeBounds timeBounds = solverTaskDescription.getTimeBounds();
    cbit.vcell.solver.OutputTimeSpec outputTimeSpec = solverTaskDescription.getOutputTimeSpec();
    ErrorTolerance errorTolerance = solverTaskDescription.getErrorTolerance();
    NonspatialStochSimOptions stochOpt = solverTaskDescription.getStochOpt();
    printWriter.println("STARTING_TIME" + "\t" + timeBounds.getStartingTime());
    printWriter.println("ENDING_TIME " + "\t" + timeBounds.getEndingTime());
    // pw.println("MAX_ITERATION"+"\t"+outputTimeSpec.getKeepAtMost());
    printWriter.println("TOLERANCE " + "\t" + errorTolerance.getAbsoluteErrorTolerance());
    if (outputTimeSpec.isDefault()) {
        printWriter.println("SAMPLE_INTERVAL" + "\t" + ((DefaultOutputTimeSpec) outputTimeSpec).getKeepEvery());
        printWriter.println("MAX_SAVE_POINTS" + "\t" + ((DefaultOutputTimeSpec) outputTimeSpec).getKeepAtMost());
    } else if (outputTimeSpec.isUniform()) {
        printWriter.println("SAVE_PERIOD" + "\t" + ((UniformOutputTimeSpec) outputTimeSpec).getOutputTimeStep());
    }
    printWriter.println("NUM_TRIAL" + "\t" + solverTaskDescription.getStochOpt().getNumOfTrials());
    if (stochOpt.isUseCustomSeed()) {
        printWriter.println("SEED" + "\t" + stochOpt.getCustomSeed());
    } else {
        // we generate our own random seed
        RandomDataGenerator rdg = new RandomDataGenerator();
        int randomSeed = rdg.nextInt(1, Integer.MAX_VALUE);
        printWriter.println("SEED" + "\t" + randomSeed);
    }
    printWriter.println("</control>");
    printWriter.println();
    // write model information
    // Model info. will be extracted from subDomain of mathDescription
    Enumeration<SubDomain> e = simulation.getMathDescription().getSubDomains();
    SubDomain subDomain = null;
    if (e.hasMoreElements()) {
        subDomain = e.nextElement();
    }
    if (subDomain != null) {
        printWriter.println("<model>");
        // variables
        printWriter.println("<discreteVariables>");
        // Species iniCondition (if in concentration) is sampled from a poisson distribution(which has a mean of the current iniExp value)
        // There is only one subDomain for compartmental model
        List<VarIniCondition> varInis = subDomain.getVarIniConditions();
        if ((varInis != null) && (varInis.size() > 0)) {
            RandomDataGenerator dist = new RandomDataGenerator();
            if (simulation.getSolverTaskDescription().getStochOpt().isUseCustomSeed()) {
                Integer randomSeed = simulation.getSolverTaskDescription().getStochOpt().getCustomSeed();
                if (randomSeed != null) {
                    dist.reSeed(randomSeed);
                }
            }
            printWriter.println("TotalVars" + "\t" + varInis.size());
            for (VarIniCondition varIniCondition : varInis) {
                try {
                    Expression iniExp = varIniCondition.getIniVal();
                    iniExp.bindExpression(simSymbolTable);
                    iniExp = simSymbolTable.substituteFunctions(iniExp).flatten();
                    double expectedCount = iniExp.evaluateConstant();
                    // 1000 mill
                    final Integer limit = 1000000000;
                    if (limit < expectedCount) {
                        String eMessage = "The Initial count for Species '" + varIniCondition.getVar().getName() + "' is " + BigDecimal.valueOf(expectedCount).toBigInteger() + "\n";
                        eMessage += "which is higher than the internal vCell limit of " + limit + ".\n";
                        eMessage += "Please reduce the Initial Condition value for this Species or reduce the compartment size.";
                        throw new MathFormatException(eMessage);
                    }
                    long varCount = 0;
                    if (varIniCondition instanceof VarIniCount) {
                        varCount = (long) expectedCount;
                    } else {
                        if (expectedCount > 0) {
                            varCount = dist.nextPoisson(expectedCount);
                        }
                    }
                    // System.out.println("expectedCount: " + expectedCount + ", varCount: " + varCount);
                    printWriter.println(varIniCondition.getVar().getName() + "\t" + varCount);
                } catch (ExpressionException ex) {
                    ex.printStackTrace();
                    throw new MathFormatException("variable " + varIniCondition.getVar().getName() + "'s initial condition is required to be a constant.");
                }
            }
        } else
            printWriter.println("TotalVars" + "\t" + "0");
        printWriter.println("</discreteVariables>");
        printWriter.println();
        // jump processes
        printWriter.println("<jumpProcesses>");
        List<JumpProcess> jumpProcesses = subDomain.getJumpProcesses();
        if ((jumpProcesses != null) && (jumpProcesses.size() > 0)) {
            printWriter.println("TotalProcesses" + "\t" + jumpProcesses.size());
            for (int i = 0; i < jumpProcesses.size(); i++) {
                printWriter.println(jumpProcesses.get(i).getName());
            }
        } else
            printWriter.println("TotalProcesses" + "\t" + "0");
        printWriter.println("</jumpProcesses>");
        printWriter.println();
        // process description
        printWriter.println("<processDesc>");
        if ((jumpProcesses != null) && (jumpProcesses.size() > 0)) {
            printWriter.println("TotalDescriptions" + "\t" + jumpProcesses.size());
            for (int i = 0; i < jumpProcesses.size(); i++) {
                JumpProcess temProc = (JumpProcess) jumpProcesses.get(i);
                // jump process name
                printWriter.println("JumpProcess" + "\t" + temProc.getName());
                Expression probExp = temProc.getProbabilityRate();
                try {
                    probExp.bindExpression(simSymbolTable);
                    probExp = simSymbolTable.substituteFunctions(probExp).flatten();
                    if (!isValidProbabilityExpression(probExp)) {
                        throw new MathFormatException("probability rate in jump process " + temProc.getName() + " has illegal symbols(should only contain variable names).");
                    }
                } catch (cbit.vcell.parser.ExpressionException ex) {
                    ex.printStackTrace();
                    throw new cbit.vcell.parser.ExpressionException("Binding math description error in probability rate in jump process " + temProc.getName() + ". Some symbols can not be resolved.");
                }
                // Expression temp = replaceVarIniInProbability(probExp);
                // Propensity
                printWriter.println("\t" + "Propensity" + "\t" + probExp.infix());
                // effects
                printWriter.println("\t" + "Effect" + "\t" + temProc.getActions().size());
                for (int j = 0; j < temProc.getActions().size(); j++) {
                    printWriter.print("\t\t" + ((Action) temProc.getActions().get(j)).getVar().getName() + "\t" + ((Action) temProc.getActions().get(j)).getOperation());
                    printWriter.println("\t" + ((Action) temProc.getActions().get(j)).evaluateOperand());
                    printWriter.println();
                }
                // dependencies
                Vector<String> dependencies = getDependencies(temProc, jumpProcesses);
                if ((dependencies != null) && (dependencies.size() > 0)) {
                    printWriter.println("\t" + "DependentProcesses" + "\t" + dependencies.size());
                    for (int j = 0; j < dependencies.size(); j++) printWriter.println("\t\t" + dependencies.elementAt(j));
                } else
                    printWriter.println("\t" + "DependentProcesses" + "\t" + "0");
                printWriter.println();
            }
        } else
            printWriter.println("TotalDescriptions" + "\t" + "0");
        printWriter.println("</processDesc>");
        printWriter.println("</model>");
    }
// if (subDomain != null)
}
Also used : VarIniCondition(cbit.vcell.math.VarIniCondition) Action(cbit.vcell.math.Action) NonspatialStochSimOptions(cbit.vcell.solver.NonspatialStochSimOptions) MathFormatException(cbit.vcell.math.MathFormatException) ExpressionException(cbit.vcell.parser.ExpressionException) SubDomain(cbit.vcell.math.SubDomain) JumpProcess(cbit.vcell.math.JumpProcess) ErrorTolerance(cbit.vcell.solver.ErrorTolerance) RandomDataGenerator(org.apache.commons.math3.random.RandomDataGenerator) VarIniCount(cbit.vcell.math.VarIniCount) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) ExpressionException(cbit.vcell.parser.ExpressionException) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 14 with DefaultOutputTimeSpec

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

the class SimulationWorkspace method getEstimatedNumTimePointsForStoch.

private static long getEstimatedNumTimePointsForStoch(SimulationSymbolTable simSymbolTable) {
    Simulation sim = simSymbolTable.getSimulation();
    SolverTaskDescription solverTaskDescription = sim.getSolverTaskDescription();
    TimeBounds tb = solverTaskDescription.getTimeBounds();
    double startTime = tb.getStartingTime();
    double endTime = tb.getEndingTime();
    OutputTimeSpec tSpec = solverTaskDescription.getOutputTimeSpec();
    // hybrid G_E and G_M are fixed time step methods using uniform output time spec
    if (tSpec.isUniform()) {
        double outputTimeStep = ((UniformOutputTimeSpec) tSpec).getOutputTimeStep();
        return (long) ((endTime - startTime) / outputTimeStep);
    }
    double maxProbability = 0;
    SubDomain subDomain = sim.getMathDescription().getSubDomains().nextElement();
    List<VarIniCondition> varInis = subDomain.getVarIniConditions();
    // get all the probability expressions
    ArrayList<Expression> probList = new ArrayList<Expression>();
    for (JumpProcess jp : subDomain.getJumpProcesses()) {
        probList.add(jp.getProbabilityRate());
    }
    // loop through probability expressions
    for (int i = 0; i < probList.size(); i++) {
        try {
            Expression pExp = new Expression(probList.get(i));
            pExp.bindExpression(simSymbolTable);
            pExp = simSymbolTable.substituteFunctions(pExp);
            pExp = pExp.flatten();
            String[] symbols = pExp.getSymbols();
            // substitute stoch vars with it's initial condition expressions
            if (symbols != null) {
                for (int j = 0; symbols != null && j < symbols.length; j++) {
                    for (int k = 0; k < varInis.size(); k++) {
                        if (symbols[j].equals(varInis.get(k).getVar().getName())) {
                            pExp.substituteInPlace(new Expression(symbols[j]), new Expression(varInis.get(k).getIniVal()));
                            break;
                        }
                    }
                }
            }
            pExp = simSymbolTable.substituteFunctions(pExp);
            pExp = pExp.flatten();
            double val = pExp.evaluateConstant();
            if (maxProbability < val) {
                maxProbability = val;
            }
        } catch (ExpressionBindingException e) {
            System.out.println("Cannot estimate the total time points for stochastic simulation!! Due to the reason below...");
            e.printStackTrace();
        } catch (ExpressionException ex) {
            System.out.println("Cannot estimate the total time points for stochastic simulation!! Due to the reason below...");
            ex.printStackTrace();
        } catch (MathException e) {
            System.out.println("Cannot estimate the total time points for stochastic simulation!! Due to the reason below...");
            e.printStackTrace();
        }
    }
    int keepEvery = 1;
    if (tSpec.isDefault()) {
        keepEvery = ((DefaultOutputTimeSpec) tSpec).getKeepEvery();
    }
    // points = (endt-startt)/(t*keepEvery) = (endt - startt)/(keepEvery*1/prob)
    long estimatedPoints = Math.round((tb.getEndingTime() - tb.getStartingTime()) * maxProbability / keepEvery) + 1;
    return estimatedPoints;
}
Also used : VarIniCondition(cbit.vcell.math.VarIniCondition) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) ArrayList(java.util.ArrayList) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ExpressionException(cbit.vcell.parser.ExpressionException) SubDomain(cbit.vcell.math.SubDomain) TimeBounds(cbit.vcell.solver.TimeBounds) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) JumpProcess(cbit.vcell.math.JumpProcess) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription)

Example 15 with DefaultOutputTimeSpec

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

the class SimulationWorkspace method checkSimulationParameters.

/**
 * Insert the method's description here.
 * Creation date: (5/11/2004 2:57:10 PM)
 * @return boolean
 * @param simulation cbit.vcell.solver.Simulation
 */
private static boolean checkSimulationParameters(Simulation simulation, Component parent) {
    SimulationSymbolTable simSymbolTable = new SimulationSymbolTable(simulation, 0);
    String errorMessage = null;
    long maxTimepoints = Simulation.MAX_LIMIT_NON_SPATIAL_TIMEPOINTS;
    long warningTimepoints = Simulation.WARNING_NON_SPATIAL_TIMEPOINTS;
    boolean bSpatial = simulation.isSpatial();
    if (bSpatial) {
        maxTimepoints = Simulation.MAX_LIMIT_SPATIAL_TIMEPOINTS;
        warningTimepoints = Simulation.WARNING_SPATIAL_TIMEPOINTS;
    }
    long maxSizeBytes = megabytesToBytes(Simulation.MAX_LIMIT_0DE_MEGABYTES);
    long warningSizeBytes = megabytesToBytes(Simulation.WARNING_0DE_MEGABYTES);
    if (bSpatial) {
        maxSizeBytes = megabytesToBytes(Simulation.MAX_LIMIT_PDE_MEGABYTES);
        warningSizeBytes = megabytesToBytes(Simulation.WARNING_PDE_MEGABYTES);
    } else if (simulation.getMathDescription().isNonSpatialStoch()) {
        maxSizeBytes = megabytesToBytes(Simulation.MAX_LIMIT_STOCH_MEGABYTES);
        warningSizeBytes = megabytesToBytes(Simulation.WARNING_STOCH_MEGABYTES);
    }
    long expectedNumTimePoints = getExpectedNumTimePoints(simulation);
    long expectedSizeBytes = getExpectedSizeBytes(simSymbolTable);
    // 
    // check for error conditions (hard limits on resources) ... Note: each user should have it's own limits (and quotas).
    // 
    SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
    SolverDescription solverDescription = solverTaskDescription.getSolverDescription();
    if (expectedNumTimePoints > maxTimepoints) {
        errorMessage = "Errors in Simulation: '" + simulation.getName() + "'!\n" + "The simulation has too many timepoints (" + expectedNumTimePoints + ") to be saved, which has exceeded our limit.\n\n" + "maximum saving timepoints limits are:\n" + "     " + Simulation.MAX_LIMIT_NON_SPATIAL_TIMEPOINTS + " for compartmental simulations\n" + "     " + Simulation.MAX_LIMIT_SPATIAL_TIMEPOINTS + " for spatial simulations\n" + "suggested saving timepoints limits are:\n" + "     " + Simulation.WARNING_NON_SPATIAL_TIMEPOINTS + " for compartmental simulations\n" + "     " + Simulation.WARNING_SPATIAL_TIMEPOINTS + " for spatial simulations\n" + "Try saving fewer timepoints\n" + "If you need to exceed the quota, please contact us";
        // not used for multiple stochastic run
        if (solverTaskDescription.getStochOpt() != null && solverTaskDescription.getStochOpt().getNumOfTrials() > 1) {
            errorMessage = null;
        }
    } else if (expectedSizeBytes > maxSizeBytes) {
        errorMessage = "Errors in Simulation: '" + simulation.getName() + "'!\n" + "The simulation's result dataset (" + CodeUtil.humanBytePrint(expectedSizeBytes) + ") is too large, which has exceeded our limit.\n\n" + "maximum size limits are:\n" + "     " + Simulation.MAX_LIMIT_0DE_MEGABYTES + " MB for compartmental ODE simulations\n" + "     " + Simulation.MAX_LIMIT_PDE_MEGABYTES + " MB for spatial simulations\n" + "     " + Simulation.MAX_LIMIT_STOCH_MEGABYTES + " MB for compartmental stochastic simulations\n" + "suggested size limits are:\n" + "     " + Simulation.WARNING_0DE_MEGABYTES + " MB for compartmental ODE simulations\n" + "     " + Simulation.WARNING_PDE_MEGABYTES + " MB for spatial simulations\n" + "     " + Simulation.WARNING_STOCH_MEGABYTES + " MB for compartmental stochastic simulations\n" + "Try saving fewer timepoints or using a smaller mesh (if spatial)\n" + "If you need to exceed the quota, please contact us";
        // not used for multiple stochastic run
        if (solverTaskDescription.getStochOpt() != null && solverTaskDescription.getStochOpt().getNumOfTrials() > 1) {
            errorMessage = null;
        }
    } else if (simulation.getScanCount() > Simulation.MAX_LIMIT_SCAN_JOBS) {
        errorMessage = "Errors in Simulation: '" + simulation.getName() + "'!\n" + "The simulation generates too many simulations (" + simulation.getScanCount() + ") required for parameter scan, which has exceeded our limit.\n\n" + "maximum number of parameter sets is: " + Simulation.MAX_LIMIT_SCAN_JOBS + " \n" + "suggested limit for number of parameter sets is: " + Simulation.WARNING_SCAN_JOBS + " \n" + "Try choosing fewer parameters or reducing the size of scan for each parameter.";
        // not used for multiple stochastic run
        if (simulation.getMathDescription().isNonSpatialStoch() && solverTaskDescription.getStochOpt() != null && solverTaskDescription.getStochOpt().getNumOfTrials() > 1) {
            errorMessage = null;
        }
    } else if (solverDescription.equals(SolverDescription.SundialsPDE)) {
        if (solverTaskDescription.getOutputTimeSpec().isDefault()) {
            DefaultOutputTimeSpec dot = (DefaultOutputTimeSpec) solverTaskDescription.getOutputTimeSpec();
            int maxNumberOfSteps = dot.getKeepEvery() * dot.getKeepAtMost();
            double maximumTimeStep = solverTaskDescription.getTimeStep().getMaximumTimeStep();
            double maxSimTime = maxNumberOfSteps * maximumTimeStep;
            double endingTime = solverTaskDescription.getTimeBounds().getEndingTime();
            if (maxSimTime < endingTime) {
                errorMessage = "Errors in Simulation: '" + simulation.getName() + "'!\n" + "The maximum possible simulation time (keepEvery * maxTimestep * keepAtMost = " + maxSimTime + ") is less than simulation end time (" + endingTime + ").\n\n" + "You have chosen a variable time step solver and specified a maximum number of time steps of " + maxNumberOfSteps + " (keepEvery*keepAtMost).  " + "Actual time steps are often small, but even if all steps were at the maximum time step of " + maximumTimeStep + ", the simulation end time of " + endingTime + " would not be reached. \n\n" + "Either adjust the parameters or choose the \"Output Interval\" option.";
            }
        }
    } else if (simulation.getMathDescription().isNonSpatialStoch() && !(solverDescription.isNonSpatialStochasticSolver())) {
        // to guarantee stochastic model uses stochastic methods and deterministic model uses ODE/PDE methods.
        errorMessage = "Errors in Simulation: '" + simulation.getName() + "'!\n" + "Stochastic simulation(s) must use stochastic solver(s).\n" + solverDescription.getDisplayLabel() + " is not a stochastic solver!";
    } else if (!simulation.getMathDescription().isNonSpatialStoch() && (solverDescription.isNonSpatialStochasticSolver())) {
        errorMessage = "Errors in Simulation: '" + simulation.getName() + "'!\n" + "ODE/PDE simulation(s) must use ODE/PDE solver(s).\n" + solverDescription.getDisplayLabel() + " is not a ODE/PDE solver!";
    } else if (simulation.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
        MeshSpecification meshSpecification = simulation.getMeshSpecification();
        boolean bCellCentered = simulation.hasCellCenteredMesh();
        if (meshSpecification != null && !meshSpecification.isAspectRatioOK(1e-4, bCellCentered)) {
            errorMessage = "Non uniform spatial step is detected. This will affect the accuracy of the solution.\n\n" + "\u0394x=" + meshSpecification.getDx(bCellCentered) + "\n" + "\u0394y=" + meshSpecification.getDy(bCellCentered) + (meshSpecification.getGeometry().getDimension() < 3 ? "" : "\n\u0394z=" + meshSpecification.getDz(bCellCentered));
        }
    } else {
        errorMessage = null;
    }
    if (errorMessage != null) {
        DialogUtils.showErrorDialog(parent, errorMessage);
        return false;
    } else if (simulation.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
        Geometry geometry = simulation.getMathDescription().getGeometry();
        ChomboMeshValidator meshValidator = new ChomboMeshValidator(geometry, simulation.getSolverTaskDescription().getChomboSolverSpec());
        ChomboMeshRecommendation chomboMeshRecommendation = meshValidator.computeMeshSpecs();
        boolean bValid = chomboMeshRecommendation.validate();
        if (!bValid) {
            String option = DialogUtils.showWarningDialog(parent, "Error", chomboMeshRecommendation.getErrorMessage(), chomboMeshRecommendation.getDialogOptions(), ChomboMeshRecommendation.optionClose);
            if (ChomboMeshRecommendation.optionSuggestions.equals(option)) {
                DialogUtils.showInfoDialog(parent, ChomboMeshRecommendation.optionSuggestions, chomboMeshRecommendation.getMeshSuggestions());
            }
        }
        return bValid;
    } else {
        String warningMessage = null;
        // don't check warning message for stochastic multiple trials, let it run.
        if (simulation.getMathDescription().isNonSpatialStoch() && simulation.getSolverTaskDescription().getStochOpt() != null && simulation.getSolverTaskDescription().getStochOpt().getNumOfTrials() > 1) {
            return true;
        }
        // 
        if (expectedNumTimePoints > warningTimepoints) {
            warningMessage = "Warnings from Simulation: '" + simulation.getName() + "'!\n" + "The simulation has large number of saving timepoints (" + expectedNumTimePoints + "), suggested saving timepoints limits are:\n" + "     " + Simulation.WARNING_NON_SPATIAL_TIMEPOINTS + " for compartmental simulations\n" + "     " + Simulation.WARNING_SPATIAL_TIMEPOINTS + " for spatial simulations\n" + "Try saving fewer timepoints";
        } else if (expectedSizeBytes > warningSizeBytes) {
            warningMessage = "Warnings from Simulation: '" + simulation.getName() + "'!\n" + "The simulation has large result dataset (" + (expectedSizeBytes / 1000000L) + "MB), suggested size limits are:\n" + "     " + Simulation.WARNING_0DE_MEGABYTES + " MB for compartmental ODE simulations\n" + "     " + Simulation.WARNING_PDE_MEGABYTES + " MB for spatial simulations\n" + "     " + Simulation.WARNING_STOCH_MEGABYTES + " MB for compartmental stochastic simulations\n" + "Try saving fewer timepoints or using a coarser mesh if spatial.";
        } else if (simulation.getScanCount() > Simulation.WARNING_SCAN_JOBS) {
            warningMessage = "Warnings from Simulation: '" + simulation.getName() + "'!\n" + "The simulation generates a large number of simulations (" + simulation.getScanCount() + ") required for parameter scan.\n" + "maximum number of parameter sets is: " + Simulation.MAX_LIMIT_SCAN_JOBS + " \n" + "suggested limit for the number of parameter sets is: " + Simulation.WARNING_SCAN_JOBS + " \n" + "Try choosing fewer parameters or reducing the size of scan for each parameter.";
        }
        if (solverDescription.equals(SolverDescription.SundialsPDE)) {
            if (solverTaskDescription.getErrorTolerance().getRelativeErrorTolerance() > 1e-4) {
                String msg = "Warnings from Simulation: '" + simulation.getName() + "'!\n" + "Warning: it is not reccomended to use a relative tolerance that is greater than \n1e-4 for " + solverDescription.getDisplayLabel() + ".";
                warningMessage = warningMessage == null ? msg : warningMessage + "\n\n" + msg;
            }
        } else if (solverDescription.isSemiImplicitPdeSolver()) {
            if (solverTaskDescription.getErrorTolerance().getRelativeErrorTolerance() > 1e-8) {
                String msg = "Warnings from Simulation: '" + simulation.getName() + "'!\n" + "Warning: it is not reccomended to use a relative tolerance that is greater than \n1e-8 for " + solverDescription.getDisplayLabel() + ".";
                warningMessage = warningMessage == null ? msg : warningMessage + "\n\n" + msg;
            }
        }
        MeshSpecification meshSpecification = simulation.getMeshSpecification();
        boolean bCellCentered = simulation.hasCellCenteredMesh();
        if (meshSpecification != null && !meshSpecification.isAspectRatioOK(bCellCentered)) {
            warningMessage = (warningMessage == null ? "" : warningMessage + "\n\n") + "Non uniform spatial step is detected. This might affect the accuracy of the solution.\n\n" + "\u0394x=" + meshSpecification.getDx(bCellCentered) + "\n" + "\u0394y=" + meshSpecification.getDy(bCellCentered) + (meshSpecification.getGeometry().getDimension() < 3 ? "" : "\n\u0394z=" + meshSpecification.getDz(bCellCentered));
        }
        if (warningMessage != null) {
            String result = DialogUtils.showWarningDialog(parent, warningMessage + "\n\nDo you want to continue anyway?", new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
            return (result != null && result.equals(UserMessage.OPTION_OK));
        } else {
            return true;
        }
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) ChomboMeshRecommendation(org.vcell.chombo.ChomboMeshValidator.ChomboMeshRecommendation) ChomboMeshValidator(org.vcell.chombo.ChomboMeshValidator) SolverDescription(cbit.vcell.solver.SolverDescription) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) MeshSpecification(cbit.vcell.solver.MeshSpecification)

Aggregations

DefaultOutputTimeSpec (cbit.vcell.solver.DefaultOutputTimeSpec)24 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)15 OutputTimeSpec (cbit.vcell.solver.OutputTimeSpec)13 SolverTaskDescription (cbit.vcell.solver.SolverTaskDescription)13 ExplicitOutputTimeSpec (cbit.vcell.solver.ExplicitOutputTimeSpec)8 Simulation (cbit.vcell.solver.Simulation)7 TimeBounds (cbit.vcell.solver.TimeBounds)6 ExpressionException (cbit.vcell.parser.ExpressionException)5 ErrorTolerance (cbit.vcell.solver.ErrorTolerance)5 SolverDescription (cbit.vcell.solver.SolverDescription)5 MathException (cbit.vcell.math.MathException)4 SolverException (cbit.vcell.solver.SolverException)4 Constant (cbit.vcell.math.Constant)3 SubDomain (cbit.vcell.math.SubDomain)3 Expression (cbit.vcell.parser.Expression)3 NonspatialStochSimOptions (cbit.vcell.solver.NonspatialStochSimOptions)3 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)3 File (java.io.File)3 Geometry (cbit.vcell.geometry.Geometry)2 JumpProcess (cbit.vcell.math.JumpProcess)2