Search in sources :

Example 1 with MeshSpecification

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

the class SmoldynFileWriter method writeCompartments.

private void writeCompartments() throws ImageException, PropertyVetoException, GeometryException, ExpressionException {
    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();
    int numXY = numX * numY;
    boolean bCellCentered = simulation.hasCellCenteredMesh();
    double dx = meshSpecification.getDx(bCellCentered);
    double dy = meshSpecification.getDy(bCellCentered);
    double dz = meshSpecification.getDz(bCellCentered);
    Origin origin = resampledGeometry.getGeometrySpec().getOrigin();
    printWriter.println("# compartments");
    resampledGeometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
    for (SubVolume subVolume : resampledGeometry.getGeometrySpec().getSubVolumes()) {
        printWriter.println(SmoldynVCellMapper.SmoldynKeyword.start_compartment + " " + subVolume.getName());
        for (SurfaceClass sc : resampledGeometry.getGeometrySurfaceDescription().getSurfaceClasses()) {
            if (sc.getAdjacentSubvolumes().contains(subVolume)) {
                printWriter.println(SmoldynVCellMapper.SmoldynKeyword.surface + " " + sc.getName());
            }
        }
        if (boundaryXSubVolumes.contains(subVolume)) {
            printWriter.println(SmoldynVCellMapper.SmoldynKeyword.surface + " " + VCellSmoldynKeyword.bounding_wall_surface_X);
        }
        if (dimension > 1) {
            if (boundaryYSubVolumes.contains(subVolume)) {
                printWriter.println(SmoldynVCellMapper.SmoldynKeyword.surface + " " + VCellSmoldynKeyword.bounding_wall_surface_Y);
            }
            if (dimension > 2) {
                if (boundaryZSubVolumes.contains(subVolume)) {
                    printWriter.println(SmoldynVCellMapper.SmoldynKeyword.surface + " " + VCellSmoldynKeyword.bounding_wall_surface_Z);
                }
            }
        }
        // if (DEBUG) {
        // tmppw.println("points" + pointsCount + "=[");
        // pointsCount ++;
        // }
        // gather all the points in all the regions
        Geometry interiorPointGeometry = RayCaster.resampleGeometry(new GeometryThumbnailImageFactoryAWT(), resampledGeometry, resampledGeometry.getGeometrySurfaceDescription().getVolumeSampleSize());
        SubVolume interiorPointSubVolume = interiorPointGeometry.getGeometrySpec().getSubVolume(subVolume.getName());
        GeometricRegion[] geometricRegions = interiorPointGeometry.getGeometrySurfaceDescription().getGeometricRegions(interiorPointSubVolume);
        RegionInfo[] regionInfos = interiorPointGeometry.getGeometrySurfaceDescription().getRegionImage().getRegionInfos();
        for (GeometricRegion geometricRegion : geometricRegions) {
            VolumeGeometricRegion volumeGeometricRegion = (VolumeGeometricRegion) geometricRegion;
            ArrayList<SelectPoint> selectPointList = new ArrayList<SelectPoint>();
            for (RegionInfo regionInfo : regionInfos) {
                if (regionInfo.getRegionIndex() != volumeGeometricRegion.getRegionID()) {
                    continue;
                }
                int volIndex = 0;
                for (int k = 0; k < numZ; k++) {
                    for (int j = 0; j < numY; j++) {
                        int starti = -1;
                        int endi = 0;
                        for (int i = 0; i < numX; i++, volIndex++) {
                            boolean bInRegion = false;
                            if (regionInfo.isIndexInRegion(volIndex)) {
                                bInRegion = true;
                                if (starti == -1) {
                                    starti = i;
                                    endi = i;
                                } else {
                                    endi++;
                                }
                            }
                            if ((!bInRegion || i == numX - 1) && starti != -1) {
                                int midi = (endi + starti) / 2;
                                int midVolIndex = k * numXY + j * numX + midi;
                                boolean bOnBoundary = false;
                                int[] neighbors = { j == 0 ? -1 : midVolIndex - numX, j == numY - 1 ? -1 : midVolIndex + numX, k == 0 ? -1 : midVolIndex - numXY, k == numZ - 1 ? -1 : midVolIndex + numXY };
                                for (int n = 0; n < 2 * (dimension - 1); n++) {
                                    if (neighbors[n] == -1 || !regionInfo.isIndexInRegion(neighbors[n])) {
                                        bOnBoundary = true;
                                        break;
                                    }
                                }
                                if (!bOnBoundary) {
                                    selectPointList.add(new SelectPoint(starti, endi, j, k));
                                }
                                starti = -1;
                            }
                        }
                    // end i
                    }
                // end j
                }
            // end k
            }
            for (int m = 0; m < selectPointList.size(); m++) {
                SelectPoint thisPoint = selectPointList.get(m);
                boolean bPrint = true;
                for (int n = 0; n < selectPointList.size(); n++) {
                    if (n == m) {
                        continue;
                    }
                    SelectPoint point = selectPointList.get(n);
                    if (thisPoint.k == point.k && Math.abs(thisPoint.j - point.j) == 1 || thisPoint.j == point.j && Math.abs(thisPoint.k - point.k) == 1) {
                        if (point.same(thisPoint) && m < n) {
                            // found same one later, print the later one
                            bPrint = false;
                            break;
                        }
                        if (point.contains(thisPoint) && point.length() < 2 * thisPoint.length()) {
                            // found a longer one, but not too much longer
                            bPrint = false;
                            break;
                        }
                    }
                }
                if (bPrint) {
                    int midi = (thisPoint.starti + thisPoint.endi) / 2;
                    double coordX = origin.getX() + dx * midi;
                    printWriter.print(SmoldynVCellMapper.SmoldynKeyword.point + " " + coordX);
                    if (dimension > 1) {
                        double coordY = origin.getY() + dy * thisPoint.j;
                        printWriter.print(" " + coordY);
                        if (dimension > 2) {
                            double coordZ = origin.getZ() + dz * thisPoint.k;
                            printWriter.print(" " + coordZ);
                        }
                    }
                    printWriter.println();
                }
            }
        }
        // end for (GeometricRegion
        printWriter.println(SmoldynVCellMapper.SmoldynKeyword.end_compartment);
        printWriter.println();
    }
// end for (SubVolume
}
Also used : Origin(org.vcell.util.Origin) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ISize(org.vcell.util.ISize) ArrayList(java.util.ArrayList) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) MeshSpecification(cbit.vcell.solver.MeshSpecification) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) Geometry(cbit.vcell.geometry.Geometry) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) SubVolume(cbit.vcell.geometry.SubVolume)

Example 2 with MeshSpecification

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

the class XmlReader method getMeshSpecification.

/**
 * This method returns a MeshSpecification object from a XML Element.
 * Creation date: (5/22/2001 12:05:21 PM)
 * @return cbit.vcell.mesh.MeshSpecification
 * @param param org.jdom.Element
 */
private MeshSpecification getMeshSpecification(Element param, Geometry geometry) throws XmlParseException {
    // *** create new MeshSpecification ***
    MeshSpecification meshSpec = new MeshSpecification(geometry);
    // get ISize
    Element size = param.getChild(XMLTags.SizeTag, vcNamespace);
    int x = Integer.parseInt(size.getAttributeValue(XMLTags.XAttrTag));
    int y = Integer.parseInt(size.getAttributeValue(XMLTags.YAttrTag));
    int z = Integer.parseInt(size.getAttributeValue(XMLTags.ZAttrTag));
    ISize newsize = new ISize(x, y, z);
    // set ISize
    try {
        meshSpec.setSamplingSize(newsize);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("A PropertyVetoException was fired when setting the ISize object to a new MeshSpecification", e);
    }
    return meshSpec;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ISize(org.vcell.util.ISize) Element(org.jdom.Element) MeshSpecification(cbit.vcell.solver.MeshSpecification)

Example 3 with MeshSpecification

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

the class ITextWriter method writeSimulation.

// container can be a chapter or a section of a chapter.
protected void writeSimulation(Section container, Simulation sim) throws DocumentException {
    if (sim == null) {
        return;
    }
    Section simSection = container.addSection(sim.getName(), container.numberDepth() + 1);
    writeMetadata(simSection, sim.getName(), sim.getDescription(), null, "Simulation ");
    // add overriden params
    Table overParamTable = null;
    MathOverrides mo = sim.getMathOverrides();
    if (mo != null) {
        String[] constants = mo.getOverridenConstantNames();
        for (int i = 0; i < constants.length; i++) {
            String actualStr = "", defStr = "";
            Expression tempExp = mo.getDefaultExpression(constants[i]);
            if (tempExp != null) {
                defStr = tempExp.infix();
            }
            if (mo.isScan(constants[i])) {
                actualStr = mo.getConstantArraySpec(constants[i]).toString();
            } else {
                tempExp = mo.getActualExpression(constants[i], 0);
                if (tempExp != null) {
                    actualStr = tempExp.infix();
                }
            }
            if (overParamTable == null) {
                overParamTable = getTable(3, 75, 1, 3, 3);
                overParamTable.setAlignment(Table.ALIGN_LEFT);
                overParamTable.addCell(createCell("Overriden Parameters", getBold(DEF_HEADER_FONT_SIZE), 3, 1, Element.ALIGN_CENTER, true));
                overParamTable.addCell(createHeaderCell("Name", getBold(), 1));
                overParamTable.addCell(createHeaderCell("Actual Value", getBold(), 1));
                overParamTable.addCell(createHeaderCell("Default Value", getBold(), 1));
            }
            overParamTable.addCell(createCell(constants[i], getFont()));
            overParamTable.addCell(createCell(actualStr, getFont()));
            overParamTable.addCell(createCell(defStr, getFont()));
        }
    }
    if (overParamTable != null) {
        simSection.add(overParamTable);
    }
    // add spatial details
    // sim.isSpatial();
    Table meshTable = null;
    MeshSpecification mesh = sim.getMeshSpecification();
    if (mesh != null) {
        Geometry geom = mesh.getGeometry();
        Extent extent = geom.getExtent();
        String extentStr = "(" + extent.getX() + ", " + extent.getY() + ", " + extent.getZ() + ")";
        ISize meshSize = mesh.getSamplingSize();
        String meshSizeStr = "(" + meshSize.getX() + ", " + meshSize.getY() + ", " + meshSize.getZ() + ")";
        meshTable = getTable(2, 75, 1, 3, 3);
        meshTable.setAlignment(Table.ALIGN_LEFT);
        meshTable.addCell(createCell("Geometry Setting", getBold(DEF_HEADER_FONT_SIZE), 2, 1, Element.ALIGN_CENTER, true));
        meshTable.addCell(createCell("Geometry Size (um)", getFont()));
        meshTable.addCell(createCell(extentStr, getFont()));
        meshTable.addCell(createCell("Mesh Size (elements)", getFont()));
        meshTable.addCell(createCell(meshSizeStr, getFont()));
    }
    if (meshTable != null) {
        simSection.add(meshTable);
    }
    // write advanced sim settings
    Table simAdvTable = null;
    SolverTaskDescription solverDesc = sim.getSolverTaskDescription();
    if (solverDesc != null) {
        String solverName = solverDesc.getSolverDescription().getDisplayLabel();
        simAdvTable = getTable(2, 75, 1, 3, 3);
        simAdvTable.setAlignment(Table.ALIGN_LEFT);
        simAdvTable.addCell(createCell("Advanced Settings", getBold(DEF_HEADER_FONT_SIZE), 2, 1, Element.ALIGN_CENTER, true));
        simAdvTable.addCell(createCell("Solver Name", getFont()));
        simAdvTable.addCell(createCell(solverName, getFont()));
        simAdvTable.addCell(createCell("Time Bounds - Starting", getFont()));
        simAdvTable.addCell(createCell("" + solverDesc.getTimeBounds().getStartingTime(), getFont()));
        simAdvTable.addCell(createCell("Time Bounds - Ending", getFont()));
        simAdvTable.addCell(createCell("" + solverDesc.getTimeBounds().getEndingTime(), getFont()));
        simAdvTable.addCell(createCell("Time Step - Min", getFont()));
        simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getMinimumTimeStep(), getFont()));
        simAdvTable.addCell(createCell("Time Step - Default", getFont()));
        simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getDefaultTimeStep(), getFont()));
        simAdvTable.addCell(createCell("Time Step - Max", getFont()));
        simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getMaximumTimeStep(), getFont()));
        ErrorTolerance et = solverDesc.getErrorTolerance();
        if (et != null) {
            simAdvTable.addCell(createCell("Error Tolerance - Absolute", getFont()));
            simAdvTable.addCell(createCell("" + et.getAbsoluteErrorTolerance(), getFont()));
            simAdvTable.addCell(createCell("Error Tolerance - Relative", getFont()));
            simAdvTable.addCell(createCell("" + et.getRelativeErrorTolerance(), getFont()));
        }
        OutputTimeSpec ots = solverDesc.getOutputTimeSpec();
        if (ots.isDefault()) {
            simAdvTable.addCell(createCell("Keep Every", getFont()));
            simAdvTable.addCell(createCell("" + ((DefaultOutputTimeSpec) ots).getKeepEvery(), getFont()));
            simAdvTable.addCell(createCell("Keep At Most", getFont()));
            simAdvTable.addCell(createCell("" + ((DefaultOutputTimeSpec) ots).getKeepAtMost(), getFont()));
        } else if (ots.isUniform()) {
            simAdvTable.addCell(createCell("Output Time Step", getFont()));
            simAdvTable.addCell(createCell("" + ((UniformOutputTimeSpec) ots).getOutputTimeStep(), getFont()));
        } else if (ots.isExplicit()) {
            simAdvTable.addCell(createCell("Output Time Points", getFont()));
            simAdvTable.addCell(createCell("" + ((ExplicitOutputTimeSpec) ots).toCommaSeperatedOneLineOfString(), getFont()));
        }
        simAdvTable.addCell(createCell("Use Symbolic Jacobian (T/F)", getFont()));
        simAdvTable.addCell(createCell((solverDesc.getUseSymbolicJacobian() ? " T " : " F "), getFont()));
        Constant sp = solverDesc.getSensitivityParameter();
        if (sp != null) {
            simAdvTable.addCell(createCell("Sensitivity Analysis Param", getFont()));
            simAdvTable.addCell(createCell(sp.getName(), getFont()));
        }
    }
    if (simAdvTable != null) {
        simSection.add(simAdvTable);
    }
}
Also used : Table(com.lowagie.text.Table) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) Constant(cbit.vcell.math.Constant) Section(com.lowagie.text.Section) MeshSpecification(cbit.vcell.solver.MeshSpecification) Geometry(cbit.vcell.geometry.Geometry) MathOverrides(cbit.vcell.solver.MathOverrides) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) Expression(cbit.vcell.parser.Expression) ErrorTolerance(cbit.vcell.solver.ErrorTolerance) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription)

Example 4 with MeshSpecification

use of cbit.vcell.solver.MeshSpecification 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)

Example 5 with MeshSpecification

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

the class SimulationSummaryPanel method setSimulation.

/**
 * Sets the simulation property (cbit.vcell.solver.Simulation) value.
 * @param newValue The new value for the property.
 * @see #getSimulation
 */
public void setSimulation(Simulation newValue) {
    Simulation oldValue = fieldSimulation;
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(ivjEventHandler);
        oldValue.getSolverTaskDescription().removePropertyChangeListener(ivjEventHandler);
        MeshSpecification meshSpecification = oldValue.getMeshSpecification();
        if (meshSpecification != null) {
            meshSpecification.removePropertyChangeListener(ivjEventHandler);
        }
    }
    fieldSimulation = newValue;
    if (newValue != null) {
        // also set up a listener that will refresh when simulation is edited in place
        newValue.addPropertyChangeListener(ivjEventHandler);
        newValue.getSolverTaskDescription().addPropertyChangeListener(ivjEventHandler);
        MeshSpecification meshSpecification = newValue.getMeshSpecification();
        if (meshSpecification != null) {
            meshSpecification.addPropertyChangeListener(ivjEventHandler);
        }
    }
    refreshDisplay();
}
Also used : Simulation(cbit.vcell.solver.Simulation) 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