Search in sources :

Example 1 with ExplicitOutputTimeSpec

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

the class ParameterEstimationTaskSimulatorIDA method getRowColumnRestultSetByBestEstimations.

public RowColumnResultSet getRowColumnRestultSetByBestEstimations(ParameterEstimationTask parameterEstimationTask, String[] paramNames, double[] paramValues) throws Exception {
    // create a temp simulation based on math description
    KeyValue key = new KeyValue("" + Math.abs(new Random().nextLong()));
    SimulationVersion dummyVersion = new SimulationVersion(key, "name", new User("temp", new KeyValue("1")), null, null, null, null, null, null, null);
    Simulation simulation = new Simulation(dummyVersion, parameterEstimationTask.getSimulationContext().getMathDescription());
    ReferenceData refData = parameterEstimationTask.getModelOptimizationSpec().getReferenceData();
    double[] times = refData.getDataByColumn(0);
    double endTime = times[times.length - 1];
    ExplicitOutputTimeSpec exTimeSpec = new ExplicitOutputTimeSpec(times);
    // set simulation ending time and output interval
    simulation.getSolverTaskDescription().setTimeBounds(new TimeBounds(0, endTime));
    simulation.getSolverTaskDescription().setOutputTimeSpec(exTimeSpec);
    // set parameters as math overrides
    MathOverrides mathOverrides = simulation.getMathOverrides();
    for (int i = 0; i < paramNames.length; i++) {
        mathOverrides.putConstant(new Constant(paramNames[i], new Expression(paramValues[i])));
    }
    SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
    IDASolverStandalone idaSolver = new IDASolverStandalone(simTask, ResourceUtil.getLocalSimDir("temp"), false);
    // startSolver();
    idaSolver.runSolver();
    Thread.sleep(1000);
    long startTimeMS = System.currentTimeMillis();
    while (idaSolver.getSolverStatus().isRunning() && System.currentTimeMillis() < (startTimeMS + 10000L)) {
        Thread.sleep(500);
    }
    ODESolverResultSet resultset = idaSolver.getODESolverResultSet();
    return resultset;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) SimulationTask(cbit.vcell.messaging.server.SimulationTask) Constant(cbit.vcell.math.Constant) ReferenceData(cbit.vcell.opt.ReferenceData) TimeBounds(cbit.vcell.solver.TimeBounds) MathOverrides(cbit.vcell.solver.MathOverrides) ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) SimulationVersion(org.vcell.util.document.SimulationVersion) Random(java.util.Random) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) IDASolverStandalone(cbit.vcell.solver.ode.IDASolverStandalone) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 2 with ExplicitOutputTimeSpec

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

the class Xmlproducer method getXML.

/**
 * This methos returns a XML representation of a ErrorTolerance.
 * Creation date: (3/3/2001 12:02:33 AM)
 * @return Element
 * @param param cbit.vcell.solver.ErrorTolerance
 */
private Element getXML(OutputTimeSpec param) {
    Element outputOptions = new Element(XMLTags.OutputOptionsTag);
    // Add Atributes
    if (param.isDefault()) {
        DefaultOutputTimeSpec dots = (DefaultOutputTimeSpec) param;
        outputOptions.setAttribute(XMLTags.KeepEveryAttrTag, String.valueOf(dots.getKeepEvery()));
        outputOptions.setAttribute(XMLTags.KeepAtMostAttrTag, String.valueOf(dots.getKeepAtMost()));
    } else if (param.isExplicit()) {
        ExplicitOutputTimeSpec eots = (ExplicitOutputTimeSpec) param;
        outputOptions.setAttribute(XMLTags.OutputTimesAttrTag, eots.toCommaSeperatedOneLineOfString());
    } else if (param.isUniform()) {
        UniformOutputTimeSpec uots = (UniformOutputTimeSpec) param;
        outputOptions.setAttribute(XMLTags.OutputTimeStepAttrTag, String.valueOf(uots.getOutputTimeStep()));
    }
    return outputOptions;
}
Also used : ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) Element(org.jdom.Element) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 3 with ExplicitOutputTimeSpec

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

the class OutputOptionsPanel method checkExplicitOutputTimes.

private boolean checkExplicitOutputTimes(ExplicitOutputTimeSpec ots) {
    boolean bValid = true;
    double startingTime = solverTaskDescription.getTimeBounds().getStartingTime();
    double endingTime = solverTaskDescription.getTimeBounds().getEndingTime();
    double[] times = ((ExplicitOutputTimeSpec) ots).getOutputTimes();
    if (times[0] < startingTime || times[times.length - 1] > endingTime) {
        bValid = false;
        String ret = PopupGenerator.showWarningDialog(OutputOptionsPanel.this, "Output times should be within [" + startingTime + "," + endingTime + "].\n\nChange ENDING TIME to " + times[times.length - 1] + "?", new String[] { UserMessage.OPTION_YES, UserMessage.OPTION_NO }, UserMessage.OPTION_YES);
        if (ret.equals(UserMessage.OPTION_YES)) {
            try {
                solverTaskDescription.setTimeBounds(new TimeBounds(startingTime, times[times.length - 1]));
                bValid = true;
            } catch (PropertyVetoException e) {
                e.printStackTrace(System.out);
                DialogUtils.showErrorDialog(OutputOptionsPanel.this, e.getMessage());
            }
        }
    }
    if (bValid) {
        getOutputTimesTextField().setBorder(UIManager.getBorder("TextField.border"));
    } else {
        getOutputTimesTextField().setBorder(GuiConstants.ProblematicTextFieldBorder);
        javax.swing.SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                getOutputTimesTextField().requestFocus();
            }
        });
    }
    return bValid;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) TimeBounds(cbit.vcell.solver.TimeBounds) ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec)

Example 4 with ExplicitOutputTimeSpec

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

the class OutputOptionsPanel method refresh.

/**
 * Comment
 */
private void refresh() {
    if (solverTaskDescription == null) {
        return;
    }
    // enables the panel where the output interval is set if the solver is IDA
    // Otherwise, that panel is disabled.
    getUniformOutputRadioButton().setEnabled(false);
    BeanUtils.enableComponents(getUniformOutputPanel(), false);
    if (solverTaskDescription.getSolverDescription().equals(SolverDescription.Smoldyn)) {
        getDefaultOutputPanel().setVisible(false);
        getDefaultOutputRadioButton().setVisible(false);
    } else if (solverTaskDescription.getSolverDescription().isChomboSolver()) {
        getDefaultOutputPanel().setVisible(false);
        getDefaultOutputRadioButton().setVisible(false);
        getUniformOutputPanel().setVisible(false);
        getUniformOutputRadioButton().setVisible(false);
    } else {
        getDefaultOutputPanel().setVisible(true);
        getDefaultOutputRadioButton().setVisible(true);
        getDefaultOutputRadioButton().setEnabled(false);
        getUniformOutputPanel().setVisible(true);
        getUniformOutputRadioButton().setVisible(true);
        BeanUtils.enableComponents(getDefaultOutputPanel(), false);
    }
    if (solverTaskDescription.getSimulation().getMathDescription().getGeometry().getDimension() > 0 || solverTaskDescription.getSimulation().getMathDescription().isNonSpatialStoch()) {
        getExplicitOutputPanel().setVisible(false);
        getExplicitOutputRadioButton().setVisible(false);
    } else {
        getExplicitOutputPanel().setVisible(true);
        getExplicitOutputRadioButton().setVisible(true);
        getExplicitOutputRadioButton().setEnabled(false);
        BeanUtils.enableComponents(getExplicitOutputPanel(), false);
    }
    if (solverTaskDescription == null || solverTaskDescription.getSolverDescription() == null) {
        // Also, disable its radiobutton and fields.
        return;
    }
    SolverDescription solverDesc = solverTaskDescription.getSolverDescription();
    // Amended June 2009, no output option for stochastic gibson multiple trials
    if (solverTaskDescription.getStochOpt() != null && solverTaskDescription.getStochOpt().getNumOfTrials() > 1 && solverTaskDescription.getSolverDescription().equals(SolverDescription.StochGibson)) {
        return;
    }
    OutputTimeSpec ots = solverTaskDescription.getOutputTimeSpec();
    if (ots.isDefault()) {
        // if solver is not IDA, if the output Time step radio button had been set,
        // change the setting to the 'keep every' radio button and flush the contents of the output timestep text field.
        // Also, disable its radiobutton and fields.
        getDefaultOutputRadioButton().setSelected(true);
        getKeepEveryTextField().setText(((DefaultOutputTimeSpec) ots).getKeepEvery() + "");
        if (solverTaskDescription.getSolverDescription().isSemiImplicitPdeSolver()) {
            getKeepAtMostTextField().setText("");
        } else {
            getKeepAtMostTextField().setText(((DefaultOutputTimeSpec) ots).getKeepAtMost() + "");
        }
        getOutputTimeStepTextField().setText("");
        getOutputTimesTextField().setText("");
    } else if (ots.isUniform()) {
        getUniformOutputRadioButton().setSelected(true);
        getKeepEveryTextField().setText("");
        getKeepAtMostTextField().setText("");
        getOutputTimeStepTextField().setText(((UniformOutputTimeSpec) ots).getOutputTimeStep() + "");
        getOutputTimesTextField().setText("");
    } else if (ots.isExplicit()) {
        getExplicitOutputRadioButton().setSelected(true);
        getKeepEveryTextField().setText("");
        getKeepAtMostTextField().setText("");
        getOutputTimeStepTextField().setText("");
        getOutputTimesTextField().setText(((ExplicitOutputTimeSpec) ots).toCommaSeperatedOneLineOfString() + "");
        getOutputTimesTextField().setCaretPosition(0);
    }
    DefaultOutputTimeSpec dots = new DefaultOutputTimeSpec();
    UniformOutputTimeSpec uots = new UniformOutputTimeSpec(0.05);
    ExplicitOutputTimeSpec eots = new ExplicitOutputTimeSpec(new double[] { 0.1 });
    if (solverDesc.supports(dots)) {
        if (!solverDesc.isSemiImplicitPdeSolver() || ots.isDefault()) {
            getDefaultOutputRadioButton().setEnabled(true);
            if (getDefaultOutputRadioButton().isSelected() || ots.isDefault()) {
                BeanUtils.enableComponents(getDefaultOutputPanel(), true);
            }
        }
    }
    if (solverDesc.supports(uots)) {
        getUniformOutputRadioButton().setEnabled(true);
        if (getUniformOutputRadioButton().isSelected() || ots.isUniform()) {
            BeanUtils.enableComponents(getUniformOutputPanel(), true);
        }
    }
    if (solverDesc.supports(eots)) {
        getExplicitOutputRadioButton().setEnabled(true);
        if (getExplicitOutputRadioButton().isSelected() || ots.isExplicit()) {
            BeanUtils.enableComponents(getExplicitOutputPanel(), true);
        }
    }
    if (solverDesc.isSemiImplicitPdeSolver()) {
        getKeepAtMostTextField().setText("");
        getKeepAtMostTextField().setEnabled(false);
    }
}
Also used : DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) SolverDescription(cbit.vcell.solver.SolverDescription) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 5 with ExplicitOutputTimeSpec

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

the class OutputOptionsPanel method setSolverTaskDescription.

/**
 * set solver description. The contained {@link SolverTaskDescription#getSimulation()}
 * is usually a temporary cloned object with  a null {@link SimulationOwner}  ; therefore
 * we required the {@link UnitInfo} of the actual {@link Simulation} owner as a parameter
 * @param newValue
 * @param unitInfo not null
 */
public final void setSolverTaskDescription(SolverTaskDescription newValue, UnitInfo unitInfo) {
    Objects.requireNonNull(unitInfo);
    SolverTaskDescription oldValue = solverTaskDescription;
    /* Stop listening for events from the current object */
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(ivjEventHandler);
    }
    solverTaskDescription = newValue;
    /* Listen for events from the new object */
    if (newValue != null) {
        newValue.addPropertyChangeListener(ivjEventHandler);
    }
    solverTaskDescription = newValue;
    chomboOutputOptionsPanel.setSolverTaskDescription(solverTaskDescription);
    firePropertyChange("solverTaskDescription", oldValue, newValue);
    getOutputTimeStepTextField().addFocusListener(ivjEventHandler);
    getDefaultOutputRadioButton().addActionListener(ivjEventHandler);
    getUniformOutputRadioButton().addActionListener(ivjEventHandler);
    getExplicitOutputRadioButton().addActionListener(ivjEventHandler);
    getKeepEveryTextField().addFocusListener(ivjEventHandler);
    getKeepAtMostTextField().addFocusListener(ivjEventHandler);
    getOutputTimesTextField().addFocusListener(ivjEventHandler);
    getOutputTimeStepTextField().setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return false;
        }

        @Override
        public boolean shouldYieldFocus(JComponent input) {
            boolean bValid = true;
            try {
                double outputTime = Double.parseDouble(getOutputTimeStepTextField().getText());
                if (solverTaskDescription.getOutputTimeSpec().isUniform() && !solverTaskDescription.getSolverDescription().hasVariableTimestep()) {
                    double timeStep = solverTaskDescription.getTimeStep().getDefaultTimeStep();
                    double suggestedInterval = outputTime;
                    if (outputTime < timeStep) {
                        suggestedInterval = timeStep;
                        bValid = false;
                    } else if (!BeanUtils.isIntegerMultiple(outputTime, timeStep)) {
                        double n = outputTime / timeStep;
                        int intn = (int) Math.round(n);
                        if (intn != n) {
                            bValid = false;
                            suggestedInterval = (intn * timeStep);
                        }
                    }
                    if (!bValid) {
                        String ret = PopupGenerator.showWarningDialog(OutputOptionsPanel.this, "Output Interval", "Output Interval must " + "be integer multiple of time step.\n\nChange Output Interval to " + suggestedInterval + "?", new String[] { UserMessage.OPTION_YES, UserMessage.OPTION_NO }, UserMessage.OPTION_YES);
                        if (ret.equals(UserMessage.OPTION_YES)) {
                            getOutputTimeStepTextField().setText(suggestedInterval + "");
                            bValid = true;
                        }
                    }
                }
            } catch (NumberFormatException ex) {
                DialogUtils.showErrorDialog(OutputOptionsPanel.this, "Wrong number format " + ex.getMessage().toLowerCase());
                bValid = false;
            }
            if (bValid) {
                getOutputTimeStepTextField().setBorder(UIManager.getBorder("TextField.border"));
            } else {
                getOutputTimeStepTextField().setBorder(GuiConstants.ProblematicTextFieldBorder);
                SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                        getOutputTimeStepTextField().requestFocus();
                    }
                });
            }
            return bValid;
        }
    });
    getOutputTimesTextField().setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return false;
        }

        @Override
        public boolean shouldYieldFocus(JComponent input) {
            ExplicitOutputTimeSpec eots = ExplicitOutputTimeSpec.fromString(getOutputTimesTextField().getText());
            return checkExplicitOutputTimes(eots);
        }
    });
    // set time label units
    JLabel timeUnitsLabel = getTimeStepUnitsLabel();
    timeUnitsLabel.setText(unitInfo.getTimeUnitString());
}
Also used : ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) InputVerifier(javax.swing.InputVerifier)

Aggregations

ExplicitOutputTimeSpec (cbit.vcell.solver.ExplicitOutputTimeSpec)9 DefaultOutputTimeSpec (cbit.vcell.solver.DefaultOutputTimeSpec)6 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)6 OutputTimeSpec (cbit.vcell.solver.OutputTimeSpec)5 SolverTaskDescription (cbit.vcell.solver.SolverTaskDescription)4 TimeBounds (cbit.vcell.solver.TimeBounds)4 Simulation (cbit.vcell.solver.Simulation)3 Constant (cbit.vcell.math.Constant)2 Expression (cbit.vcell.parser.Expression)2 ErrorTolerance (cbit.vcell.solver.ErrorTolerance)2 MathOverrides (cbit.vcell.solver.MathOverrides)2 Geometry (cbit.vcell.geometry.Geometry)1 SimulationTask (cbit.vcell.messaging.server.SimulationTask)1 ReferenceData (cbit.vcell.opt.ReferenceData)1 Discontinuity (cbit.vcell.parser.Discontinuity)1 MeshSpecification (cbit.vcell.solver.MeshSpecification)1 SimulationJob (cbit.vcell.solver.SimulationJob)1 SolverDescription (cbit.vcell.solver.SolverDescription)1 IDASolverStandalone (cbit.vcell.solver.ode.IDASolverStandalone)1 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)1