use of cbit.vcell.geometry.ChomboInvalidGeometryException in project vcell by virtualcell.
the class SolverTaskDescriptionAdvancedPanel method connEtoM6.
/**
* connEtoM6: (SolverComboBox.item.itemStateChanged(java.awt.event.ItemEvent) --> TornOffSolverTaskDescription.solverDescription)
* @param arg1 java.awt.event.ItemEvent
*/
private void connEtoM6(java.awt.event.ItemEvent arg1) {
try {
SolverDescription solverDescription = getSolverDescriptionFromDisplayLabel((String) getSolverComboBox().getSelectedItem());
validateChomboExtentAR(solverDescription);
getTornOffSolverTaskDescription().setSolverDescription(solverDescription);
} catch (ChomboInvalidGeometryException ivjExc) {
// set solver back to what it was
fieldSolverComboBoxModel.setSelectedItem(fieldSolverTaskDescription.getSolverDescription().getDisplayLabel());
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.geometry.ChomboInvalidGeometryException 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 cbit.vcell.geometry.ChomboInvalidGeometryException in project vcell by virtualcell.
the class SimulationWorkspace method editSimulation.
/**
* Comment
*/
public static void editSimulation(Component parent, SimulationOwner simOwner, Simulation simulation) {
String errorMessage = checkCompatibility(simOwner, simulation);
if (errorMessage != null) {
PopupGenerator.showErrorDialog(parent, errorMessage + "\nUpdate Math before editing");
return;
}
try {
SimulationEditor simEditor = new SimulationEditor();
simEditor.prepareToEdit(simulation, parent);
JScrollPane scrollPane = new JScrollPane(simEditor);
Dimension panesize = simEditor.getPreferredSize();
scrollPane.setPreferredSize(new Dimension(panesize.width + 20, panesize.height + 20));
boolean acceptable = false;
String errors = null;
do {
int ok = PopupGenerator.showComponentOKCancelDialog(parent, scrollPane, "Edit: " + simulation.getName());
if (ok != javax.swing.JOptionPane.OK_OPTION) {
// user cancels, we discard
return;
} else {
acceptable = checkSimulationParameters(simEditor.getClonedSimulation(), parent);
}
} while (!acceptable);
Simulation clonedSimulation = simEditor.getClonedSimulation();
if (clonedSimulation.compareEqual(simulation)) {
return;
}
// clonedSimulation is the new one.
errors = applyChanges(clonedSimulation, simulation);
if (!errors.equals("")) {
throw new Exception("Some or all of the changes could not be applied:" + errors);
}
} catch (ChomboInvalidGeometryException e) {
String option = DialogUtils.showWarningDialog(parent, "Warning", e.getRecommendation().getErrorMessage(), e.getRecommendation().getDialogOptions(), ChomboMeshRecommendation.optionClose);
if (ChomboMeshRecommendation.optionSuggestions.equals(option)) {
DialogUtils.showInfoDialog(parent, ChomboMeshRecommendation.optionSuggestions, e.getRecommendation().getMeshSuggestions());
}
} catch (Exception e) {
DialogUtils.showErrorDialog(parent, e.getMessage(), e);
}
}
use of cbit.vcell.geometry.ChomboInvalidGeometryException 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);
}
}
use of cbit.vcell.geometry.ChomboInvalidGeometryException in project vcell by virtualcell.
the class SimulationEditor method prepareToEdit.
/**
* Comment
* @param simulation not null
* @param parent
* @throws ChomboInvalidGeometryException
* @throws NullPointerException
*/
public void prepareToEdit(Simulation simulation, Component parent) throws ChomboInvalidGeometryException {
Objects.requireNonNull(simulation);
try {
Simulation clonedSimulation = (Simulation) BeanUtils.cloneSerializable(simulation);
clonedSimulation.refreshDependencies();
getMathOverridesPanel1().setMathOverrides(clonedSimulation == null ? null : clonedSimulation.getMathOverrides());
getMeshTabPanel().setSimulation(parent, clonedSimulation);
SolverTaskDescriptionAdvancedPanel stdap = getSolverTaskDescriptionAdvancedPanel1();
{
SimulationOwner so = simulation.getSimulationOwner();
UnitInfo unitInfo = so.getUnitInfo();
stdap.setUnitInfo(unitInfo);
}
stdap.setSolverTaskDescription(clonedSimulation == null ? null : clonedSimulation.getSolverTaskDescription());
boolean shouldMeshBeEnabled = false;
MeshSpecification meshSpec = clonedSimulation.getMeshSpecification();
if (meshSpec != null && meshSpec.getGeometry() != null && meshSpec.getGeometry().getDimension() > 0) {
shouldMeshBeEnabled = true;
}
if (!shouldMeshBeEnabled) {
getJTabbedPane1().remove(getMeshTabPanel());
}
setClonedSimulation(clonedSimulation);
} catch (ChomboInvalidGeometryException exc) {
// if this happens, sim is not allowed to edit
exc.printStackTrace(System.out);
throw exc;
} catch (Throwable exc) {
exc.printStackTrace(System.out);
JOptionPane.showMessageDialog(this, "Could not initialize simulation editor\n" + exc.getMessage(), "Error:", JOptionPane.ERROR_MESSAGE);
}
}
Aggregations