Search in sources :

Example 1 with DataSetIdentifier

use of cbit.vcell.simdata.DataSetIdentifier in project vcell by virtualcell.

the class ChomboSimpleDataViewer method retrieveTimePlot.

private void retrieveTimePlot() {
    if (solTable.getSelectedRow() < 0 || varList.getSelectedIndex() < 0) {
        return;
    }
    final int index = (Integer) solTable.getValueAt(solTable.getSelectedRow(), SolTableModel.COL_INDEX);
    DataSetIdentifier selectedVar = (DataSetIdentifier) varList.getSelectedValue();
    final String varName = selectedVar.getName();
    AsynchClientTask task0 = new AsynchClientTask("clear", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            timePlotTableModel.setTimesAndValues(new double[0], new double[0]);
        }
    };
    AsynchClientTask task1 = new AsynchClientTask("retrieve data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            double[] times = simData.getDataTimes();
            double[] values = new double[times.length];
            for (int i = 0; i < times.length; ++i) {
                SimDataSet simDataBlock = simData.retrieveSimDataSet(times[i], varName);
                values[i] = simDataBlock.solValues[index];
            }
            hashTable.put("values", values);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("show data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            timePlotLabel.setText("Varaible " + varName + " @ Index " + index);
            double[] times = simData.getDataTimes();
            double[] values = (double[]) hashTable.get("values");
            timePlotTableModel.setTimesAndValues(times, values);
            dataTabbedPane.setSelectedComponent(timePlotPanel);
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task0, task1, task2 }, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) DataSetIdentifier(cbit.vcell.simdata.DataSetIdentifier) SimDataSet(cbit.vcell.simdata.SimulationDataSpatialHdf5.SimDataSet)

Example 2 with DataSetIdentifier

use of cbit.vcell.simdata.DataSetIdentifier in project vcell by virtualcell.

the class ChomboSimpleDataViewer method retrieveData.

// private void readMeshMetricsFile(File userDir, VCSimulationDataIdentifier vcDataId, String simId) throws IOException
// {
// File meshMetricsFile = new File(userDir, vcDataId.getID() + ".chombo.memmetrics");
// if (!meshMetricsFile.exists())
// {
// return;
// }
// BufferedReader br = null;
// try
// {
// br = new BufferedReader(new FileReader(meshMetricsFile));
// List<String> cols = new ArrayList<String>();
// List<double[]> values = new ArrayList<double[]>();
// String line = br.readLine();
// if (line != null)
// {
// StringTokenizer st = new StringTokenizer(line, ",");
// while (st.hasMoreTokens())
// {
// String token = st.nextToken();
// cols.add(token);
// }
// }
// while (true)
// {
// line = br.readLine();
// if (line == null)
// {
// break;
// }
// double[] dvalues = new double[cols.size()];
// StringTokenizer st = new StringTokenizer(line, ",");
// int cnt = 0;
// while (st.hasMoreTokens())
// {
// String token = st.nextToken();
// dvalues[cnt] = Double.parseDouble(token);
// ++ cnt;
// }
// assert cnt == cols.size();
// values.add(dvalues);
// }
// meshMetricsTableModel.setData(cols, values);
// }
// finally
// {
// if (br != null)
// {
// br.close();
// }
// }
// }
private void retrieveData() {
    final Double time = (Double) timeComboBox.getSelectedItem();
    if (time == null) {
        return;
    }
    DataSetIdentifier selectedVar = (DataSetIdentifier) varList.getSelectedValue();
    if (selectedVar == null) {
        return;
    }
    final String varName = selectedVar.getName();
    AsynchClientTask task0 = new AsynchClientTask("clear", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            solTableModel.clear();
            timePlotTableModel.clear();
            solLabel.setText("Solution");
            timePlotLabel.setText("Time Plot");
            meanTextField.setText(null);
            maxErrorTextField.setText(null);
            sumVolFracTextField.setText(null);
            l2ErrorTextField.setText(null);
        }
    };
    AsynchClientTask task1 = new AsynchClientTask("retrieve data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (timeComboBox.getSelectedIndex() < 0 || varList.getSelectedIndex() < 0) {
                return;
            }
            SimDataSet simDataSet = simData.retrieveSimDataSet(time, varName);
            hashTable.put("simDataSet", simDataSet);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("show data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            SimDataSet simDataSet = (SimDataSet) hashTable.get("simDataSet");
            if (simDataSet == null) {
                return;
            }
            solLabel.setText("Variable " + varName + " @ Time " + time);
            solTableModel.setValues(simDataSet.solValues);
            meanTextField.setText(simDataSet.mean == null ? "" : simDataSet.mean.toString());
            sumVolFracTextField.setText(simDataSet.sumVolFrac == null ? "" : simDataSet.sumVolFrac.toString());
            maxErrorTextField.setText(simDataSet.maxError == null ? "" : simDataSet.maxError.toString());
            l2ErrorTextField.setText(simDataSet.l2Error == null ? "" : simDataSet.l2Error + "".toString());
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task0, task1, task2 }, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) DataSetIdentifier(cbit.vcell.simdata.DataSetIdentifier) SimDataSet(cbit.vcell.simdata.SimulationDataSpatialHdf5.SimDataSet)

Example 3 with DataSetIdentifier

use of cbit.vcell.simdata.DataSetIdentifier in project vcell by virtualcell.

the class ChomboSimpleDataViewer method retrieveVariablesAndTimes.

private void retrieveVariablesAndTimes() {
    AsynchClientTask task0 = new AsynchClientTask("clear", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            DefaultComboBoxModel dcm = new DefaultComboBoxModel();
            timeComboBox.setModel(dcm);
            DefaultListModel dlm = new DefaultListModel();
            varList.setModel(dlm);
            solTableModel.clear();
            meshMetricsTableModel.clear();
            meanTextField.setText(null);
            maxErrorTextField.setText(null);
            sumVolFracTextField.setText(null);
            l2ErrorTextField.setText(null);
        }
    };
    AsynchClientTask task1 = new AsynchClientTask("retrieve data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            String simId = simIdField.getText().trim();
            if (simId == null || simId.length() == 0) {
                throw new RuntimeException("Please provide a simulation id.");
            }
            String username = userNameTextField.getText().trim();
            if (username == null || username.length() == 0) {
                throw new RuntimeException("Please provide a user name.");
            }
            VCSimulationDataIdentifier vcDataId = new VCSimulationDataIdentifier(new VCSimulationIdentifier(new KeyValue(simId), new User(username, null)), 0);
            SimDataInfoHolder simDataInfoHolder = null;
            String datadir = dataDirTextField.getText();
            if (datadir == null || datadir.length() == 0) {
                simDataInfoHolder = createSimulationDataFromRemote(username, vcDataId);
                datadir = simDataInfoHolder.userDir.getParent();
                dataDirTextField.setText(datadir);
            } else {
                simDataInfoHolder = createSimulationDataFromDir(new File(datadir), username, vcDataId);
            }
            simData = simDataInfoHolder.simData;
            simData.readVarAndFunctionDataIdentifiers();
            usernames.add(username);
            userNameTextField.setAutoCompletionWords(usernames);
            datadirs.add(datadir);
            dataDirTextField.setAutoCompletionWords(datadirs);
            simIds.add(simId);
            simIdField.setAutoCompletionWords(simIds);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("show data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            double[] times = simData.getDataTimes();
            DefaultComboBoxModel dcm = new DefaultComboBoxModel();
            for (double t : times) {
                dcm.addElement(t);
            }
            timeComboBox.setModel(dcm);
            meshMetricsTableModel.setData(simData.getChomboMesh().getMetricsColumnNames(), simData.getChomboMesh().getMetricsNumbers());
            List<DataSetIdentifier> dsiList = simData.getDataSetIdentifiers();
            DefaultListModel dlm = new DefaultListModel();
            for (DataSetIdentifier dsi : dsiList) {
                dlm.addElement(dsi);
            }
            varList.setModel(dlm);
            if (times.length > 0) {
                timeComboBox.setSelectedIndex(0);
            }
            if (dsiList.size() > 0) {
                varList.setSelectedIndex(0);
            }
            meshMetricsTableModel.refreshTable();
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task0, task1, task2 }, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) Hashtable(java.util.Hashtable) DataSetIdentifier(cbit.vcell.simdata.DataSetIdentifier) DefaultListModel(javax.swing.DefaultListModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) File(java.io.File)

Example 4 with DataSetIdentifier

use of cbit.vcell.simdata.DataSetIdentifier in project vcell by virtualcell.

the class ChomboSimpleDataViewer method initialize.

private void initialize() {
    setSize(1000, 500);
    BeanUtils.centerOnScreen(this);
    solTable.setModel(solTableModel);
    solTable.setDefaultRenderer(Number.class, new SolTableCellRenderer());
    meshMetricsTable.setModel(meshMetricsTableModel);
    timePlotTable.setModel(timePlotTableModel);
    varList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    mainPanel.setLayout(new GridBagLayout());
    JPanel meshMetricsPanel = new JPanel(new BorderLayout());
    meshMetricsPanel.add(new JScrollPane(meshMetricsTable), BorderLayout.CENTER);
    dataTabbedPane.addTab("Solution", createSolPanel());
    dataTabbedPane.addTab("Mesh Metrics", meshMetricsPanel);
    dataTabbedPane.addTab("Time Plot", createTimePlotPanel());
    int gridy = 0;
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.weightx = 0.4;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(2, 2, 2, 2);
    mainPanel.add(createInputPanel(), gbc);
    gbc = new GridBagConstraints();
    gbc.gridx = 1;
    gbc.gridy = gridy;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.gridheight = GridBagConstraints.REMAINDER;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.insets = new Insets(2, 2, 2, 2);
    gbc.fill = GridBagConstraints.BOTH;
    mainPanel.add(dataTabbedPane, gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new Insets(2, 2, 2, 2);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1.0;
    gbc.weightx = 0.2;
    mainPanel.add(createSelectionPanel(), gbc);
    gridy++;
    gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.insets = new Insets(2, 2, 20, 20);
    gbc.anchor = GridBagConstraints.LINE_END;
    mainPanel.add(exitButton, gbc);
    add(mainPanel);
    reset();
    resetButton.addActionListener(listener);
    okButton.addActionListener(listener);
    timeComboBox.addActionListener(listener);
    exitButton.addActionListener(listener);
    varList.addListSelectionListener(listener);
    timePlotButton.setEnabled(false);
    timePlotButton.addActionListener(listener);
    solTable.getSelectionModel().addListSelectionListener(listener);
    dataDirTextField.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            dataDirTextField.setToolTipText(dataDirTextField.getText());
        }
    });
    varList.setCellRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value instanceof DataSetIdentifier) {
                setText(((DataSetIdentifier) value).getName());
            }
            return this;
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) MouseEvent(java.awt.event.MouseEvent) GridBagLayout(java.awt.GridBagLayout) DataSetIdentifier(cbit.vcell.simdata.DataSetIdentifier) MouseAdapter(java.awt.event.MouseAdapter) BorderLayout(java.awt.BorderLayout) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Component(java.awt.Component) JList(javax.swing.JList)

Aggregations

DataSetIdentifier (cbit.vcell.simdata.DataSetIdentifier)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 Hashtable (java.util.Hashtable)3 SimDataSet (cbit.vcell.simdata.SimulationDataSpatialHdf5.SimDataSet)2 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)1 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)1 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 File (java.io.File)1 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 DefaultListCellRenderer (javax.swing.DefaultListCellRenderer)1 DefaultListModel (javax.swing.DefaultListModel)1 JList (javax.swing.JList)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1