Search in sources :

Example 1 with ChomboInvalidGeometryException

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);
    }
}
Also used : SolverDescription(cbit.vcell.solver.SolverDescription) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException)

Example 2 with ChomboInvalidGeometryException

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);
        }
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) ChomboMeshRecommendation(org.vcell.chombo.ChomboMeshValidator.ChomboMeshRecommendation) ChomboMeshValidator(org.vcell.chombo.ChomboMeshValidator) Simulation(cbit.vcell.solver.Simulation) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException)

Example 3 with ChomboInvalidGeometryException

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);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) Simulation(cbit.vcell.solver.Simulation) Dimension(java.awt.Dimension) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException) MathException(cbit.vcell.math.MathException)

Example 4 with ChomboInvalidGeometryException

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);
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) ChomboMeshRecommendation(org.vcell.chombo.ChomboMeshValidator.ChomboMeshRecommendation) ChomboMeshValidator(org.vcell.chombo.ChomboMeshValidator) ChomboGeometryException(cbit.vcell.geometry.ChomboGeometryException) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ChomboMeshSpec(org.vcell.chombo.ChomboMeshValidator.ChomboMeshSpec) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException)

Example 5 with ChomboInvalidGeometryException

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);
    }
}
Also used : SimulationOwner(cbit.vcell.solver.SimulationOwner) UnitInfo(cbit.vcell.solver.SimulationOwner.UnitInfo) Simulation(cbit.vcell.solver.Simulation) SolverTaskDescriptionAdvancedPanel(cbit.vcell.solver.ode.gui.SolverTaskDescriptionAdvancedPanel) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException) MeshSpecification(cbit.vcell.solver.MeshSpecification)

Aggregations

ChomboInvalidGeometryException (cbit.vcell.geometry.ChomboInvalidGeometryException)5 Simulation (cbit.vcell.solver.Simulation)3 Geometry (cbit.vcell.geometry.Geometry)2 ChomboMeshValidator (org.vcell.chombo.ChomboMeshValidator)2 ChomboMeshRecommendation (org.vcell.chombo.ChomboMeshValidator.ChomboMeshRecommendation)2 ChomboGeometryException (cbit.vcell.geometry.ChomboGeometryException)1 MathException (cbit.vcell.math.MathException)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 MeshSpecification (cbit.vcell.solver.MeshSpecification)1 SimulationOwner (cbit.vcell.solver.SimulationOwner)1 UnitInfo (cbit.vcell.solver.SimulationOwner.UnitInfo)1 SolverDescription (cbit.vcell.solver.SolverDescription)1 SolverTaskDescriptionAdvancedPanel (cbit.vcell.solver.ode.gui.SolverTaskDescriptionAdvancedPanel)1 Dimension (java.awt.Dimension)1 JScrollPane (javax.swing.JScrollPane)1 ChomboMeshSpec (org.vcell.chombo.ChomboMeshValidator.ChomboMeshSpec)1 Extent (org.vcell.util.Extent)1 ISize (org.vcell.util.ISize)1