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);
}
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);
}
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);
}
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;
}
});
}
Aggregations