use of org.vcell.chombo.ChomboMeshValidator in project vcell by virtualcell.
the class SolverTaskDescriptionAdvancedPanel method validateChomboExtentAR.
private void validateChomboExtentAR(SolverDescription solverDescription) throws ChomboInvalidGeometryException {
if (solverDescription != null && solverDescription.isChomboSolver()) {
Simulation sim = fieldSolverTaskDescription.getSimulation();
Geometry geometry = sim.getMathDescription().getGeometry();
ChomboMeshValidator meshValidator = fieldSolverTaskDescription.getChomboSolverSpec() == null ? new ChomboMeshValidator(geometry.getDimension(), geometry.getExtent(), ChomboSolverSpec.DEFAULT_BLOCK_FACTOR) : new ChomboMeshValidator(geometry, fieldSolverTaskDescription.getChomboSolverSpec());
ChomboMeshRecommendation chomboMeshRecommendation = meshValidator.computeMeshSpecs();
if (!chomboMeshRecommendation.validate()) {
String option = DialogUtils.showWarningDialog(this, "Warning", chomboMeshRecommendation.getErrorMessage(), chomboMeshRecommendation.getDialogOptions(), ChomboMeshRecommendation.optionClose);
if (ChomboMeshRecommendation.optionSuggestions.equals(option)) {
DialogUtils.showInfoDialog(this, ChomboMeshRecommendation.optionSuggestions, chomboMeshRecommendation.getMeshSuggestions());
}
throw new ChomboInvalidGeometryException(chomboMeshRecommendation);
}
}
}
use of org.vcell.chombo.ChomboMeshValidator 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;
}
}
}
use of org.vcell.chombo.ChomboMeshValidator in project vcell by virtualcell.
the class ChomboMeshSpecificationPanel method updateDisplay.
private void updateDisplay(boolean bSolverChanged) throws ChomboGeometryException, ChomboInvalidGeometryException {
if (!simulation.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
setVisible(false);
return;
}
Geometry geometry = simulation.getMathDescription().getGeometry();
Extent extent = geometry.getExtent();
int dimension = geometry.getDimension();
switch(dimension) {
case 0:
setVisible(false);
break;
case 1:
getGeometrySizeTextField().setText("" + extent.getX());
NyLabel.setVisible(false);
NyComboBox.setVisible(false);
NzLabel.setVisible(false);
NzComboBox.setVisible(false);
break;
case 2:
getGeometrySizeTextField().setText("(" + extent.getX() + ", " + extent.getY() + ")");
NzLabel.setVisible(false);
NzComboBox.setVisible(false);
break;
case 3:
getGeometrySizeTextField().setText("(" + extent.getX() + ", " + extent.getY() + ", " + extent.getZ() + ")");
break;
}
String error;
ChomboMeshRecommendation meshRecommendation = new ChomboMeshValidator(geometry.getDimension(), geometry.getExtent(), simulation.getSolverTaskDescription().getChomboSolverSpec().getBlockFactor()).computeMeshSpecs();
if (meshRecommendation.validate()) {
// remove ActionListener, here we only want to set values
removeComboBoxListener();
HComboBox.removeAll();
NxComboBox.removeAll();
NyComboBox.removeAll();
NzComboBox.removeAll();
for (ChomboMeshSpec meshSpec : meshRecommendation.validMeshSpecList) {
HComboBox.addItem((float) meshSpec.H);
NxComboBox.addItem(meshSpec.Nx[0]);
if (geometry.getDimension() > 1) {
NyComboBox.addItem(meshSpec.Nx[1]);
if (geometry.getDimension() == 3) {
NzComboBox.addItem(meshSpec.Nx[2]);
}
}
}
addComboBoxListener();
if (bSolverChanged) {
NxComboBox.setSelectedIndex(0);
} else {
ISize samplingSize = simulation.getMeshSpecification().getSamplingSize();
NxComboBox.setSelectedItem(samplingSize.getX());
// double check if existing mesh size is an option in drop down
Integer selectedNx = (Integer) NxComboBox.getSelectedItem();
Integer selectedNy = geometry.getDimension() > 1 ? (Integer) NyComboBox.getSelectedItem() : 1;
Integer selectedNz = geometry.getDimension() > 2 ? (Integer) NzComboBox.getSelectedItem() : 1;
boolean bMatchFound = selectedNx == samplingSize.getX() && (dimension < 2 || selectedNy == samplingSize.getY()) && (dimension < 3 || selectedNz == samplingSize.getZ());
if (!bMatchFound) {
NxComboBox.setSelectedIndex(0);
throw new ChomboGeometryException(ChomboMeshValidator.ERROR_MESSAGE_INCOMPATIBLE_MESH_SIZE);
}
}
} else {
throw new ChomboInvalidGeometryException(meshRecommendation);
}
}
Aggregations