use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.
the class RestDatabaseService method getDataSetMetadata.
public DataSetMetadata getDataSetMetadata(SimDataServerResource resource, User vcellUser) throws ObjectNotFoundException, DataAccessException, SQLException {
if (vcellUser == null) {
vcellUser = VCellApiApplication.DUMMY_USER;
}
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
// resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
String simId = resource.getAttribute(VCellApiApplication.SIMDATAID);
KeyValue simKey = new KeyValue(simId);
SimulationRep simRep = getSimulationRep(simKey);
if (simRep == null) {
throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
}
User owner = simRep.getOwner();
int jobIndex = 0;
VCMessageSession rpcSession = vcMessagingService.createProducerSession();
try {
RpcDataServerProxy rpcDataServerProxy = new RpcDataServerProxy(userLoginInfo, rpcSession);
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
VCDataIdentifier vcdID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
DataSetMetadata dataSetMetadata = rpcDataServerProxy.getDataSetMetadata(vcdID);
return dataSetMetadata;
} finally {
rpcSession.close();
}
}
use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.
the class SimResultsViewer method initialize.
/**
* Insert the method's description here.
* Creation date: (10/17/2005 11:37:52 PM)
* @exception org.vcell.util.DataAccessException The exception description.
*/
private void initialize() throws DataAccessException {
// create main viewer for jobIndex 0 and wire it up
if (isODEData) {
setMainViewer(createODEDataViewer());
} else {
setMainViewer(createPDEDataViewer());
}
java.beans.PropertyChangeListener pcl = new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if (evt.getSource() == SimResultsViewer.this && (evt.getPropertyName().equals("dataViewerManager"))) {
try {
getMainViewer().setDataViewerManager(getDataViewerManager());
} catch (java.beans.PropertyVetoException exc) {
exc.printStackTrace();
}
}
if (evt.getSource() == SimResultsViewer.this && (evt.getPropertyName().equals("simulationModelInfo"))) {
getMainViewer().setSimulationModelInfo(getSimulationModelInfo());
}
}
};
addPropertyChangeListener(pcl);
// if necessarry, create parameter choices panel and wire it up
if (getSimulation().getScanCount() > 1) {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout(5, 0));
panel.setBorder(BorderFactory.createEtchedBorder());
JLabel label = new JLabel("<html><b>Choose Parameter Values</b></html>");
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setBorder(BorderFactory.createEmptyBorder(2, 2, 0, 2));
panel.add(label, BorderLayout.NORTH);
String[] scanParams = getSimulation().getMathOverrides().getScannedConstantNames();
Arrays.sort(scanParams);
JPanel tablePanel = new JPanel();
tablePanel.setLayout(new BoxLayout(tablePanel, BoxLayout.X_AXIS));
for (int i = 0; i < scanParams.length; i++) {
Constant[] scanConstants = getSimulation().getMathOverrides().getConstantArraySpec(scanParams[i]).getConstants();
String[][] values = new String[scanConstants.length][1];
for (int j = 0; j < scanConstants.length; j++) {
values[j][0] = scanConstants[j].getExpression().infix();
}
class ScanChoicesTableModel extends javax.swing.table.AbstractTableModel {
String[] columnNames;
Object[][] rowData;
ScanChoicesTableModel(Object[][] argData, String[] argNames) {
columnNames = argNames;
rowData = argData;
}
public String getColumnName(int column) {
return columnNames[column].toString();
}
public int getRowCount() {
return rowData.length;
}
public int getColumnCount() {
return columnNames.length;
}
public Object getValueAt(int row, int col) {
return rowData[row][col];
}
public boolean isCellEditable(int row, int column) {
return false;
}
public void setValueAt(Object value, int row, int col) {
rowData[row][col] = value;
fireTableCellUpdated(row, col);
}
}
;
ScanChoicesTableModel tm = new ScanChoicesTableModel(values, new String[] { scanParams[i] });
final JTable table = new JTable(tm);
choicesHash.put(scanParams[i], table);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().setSelectionInterval(0, 0);
final ListSelectionListener[] nextListSelectionListener = new ListSelectionListener[1];
nextListSelectionListener[0] = new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
DefaultListSelectionModel list = (DefaultListSelectionModel) e.getSource();
int selected = list.getAnchorSelectionIndex();
final int previous = (selected == e.getFirstIndex() ? e.getLastIndex() : e.getFirstIndex());
ListReset listReset = new ListReset() {
@Override
public void reset(VCDataIdentifier myVcDataIdentifier) {
if (myVcDataIdentifier instanceof VCSimulationDataIdentifier) {
int paramScanIndex = ((VCSimulationDataIdentifier) myVcDataIdentifier).getJobIndex();
table.getSelectionModel().removeListSelectionListener(nextListSelectionListener[0]);
try {
table.setRowSelectionInterval(paramScanIndex, paramScanIndex);
} finally {
table.getSelectionModel().addListSelectionListener(nextListSelectionListener[0]);
}
} else {
table.setRowSelectionInterval(previous, previous);
}
}
};
updateScanParamChoices("SimResultsViewer set paramScan index=" + getSelectedParamScanJobIndex(), listReset);
}
}
};
table.getSelectionModel().addListSelectionListener(nextListSelectionListener[0]);
JScrollPane scr = new JScrollPane(table);
JPanel p = new JPanel();
scr.setPreferredSize(new java.awt.Dimension(100, Math.min(150, table.getPreferredSize().height + table.getTableHeader().getPreferredSize().height + 5)));
p.setLayout(new java.awt.BorderLayout());
p.add(scr, java.awt.BorderLayout.CENTER);
p.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
tablePanel.add(p);
}
panel.add(tablePanel, BorderLayout.CENTER);
if (isODEData) {
JPanel buttonPanel = new JPanel(new FlowLayout());
JButton button = new JButton("Time Plot with Multiple Parameter Value Sets");
buttonPanel.add(button);
panel.add(buttonPanel, BorderLayout.SOUTH);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mainViewer.showTimePlotMultipleScans(dataManager);
}
});
} else {
pdeDataViewer.setSimNameSimDataID(new ExportSpecs.SimNameSimDataID(getSimulation().getName(), getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), SimResultsViewer.getParamScanInfo(getSimulation(), getSelectedParamScanJobIndex())));
}
setParamChoicesPanel(panel);
}
// put things together
setLayout(new java.awt.BorderLayout());
add(getMainViewer(), java.awt.BorderLayout.CENTER);
if (getSimulation().getScanCount() > 1) {
add(getParamChoicesPanel(), java.awt.BorderLayout.SOUTH);
}
}
use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.
the class VCellClientDataServiceImpl method getVtkManager.
@Override
public VtkManager getVtkManager(SimulationDataSetRef simulationDataSetRef) throws FileNotFoundException, DataAccessException {
VCSimulationDataIdentifier vcSimulationDataIdentifier = getVCSimulationDataIdentifier(simulationDataSetRef);
VtkManager vtkManager = null;
if (!simulationDataSetRef.isLocal) {
vtkManager = vcellClient.getRequestManager().getVtkManager(null, vcSimulationDataIdentifier);
} else {
// ---- preliminary : construct the localDatasetControllerProvider
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = User.tempUser;
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
vtkManager = new VtkManager(null, vcDataManager, vcSimulationDataIdentifier);
}
return vtkManager;
}
use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.
the class SimulationStateMachine method onWorkerEvent.
public synchronized void onWorkerEvent(WorkerEvent workerEvent, SimulationDatabase simulationDatabase, VCMessageSession session) throws DataAccessException, VCMessagingException, SQLException {
updateSolverProcessTimestamp();
WorkerEventMessage workerEventMessage = new WorkerEventMessage(workerEvent);
VCMongoMessage.sendWorkerEvent(workerEventMessage);
// as the filter of the client
String userName = workerEvent.getUserName();
int workerEventTaskID = workerEvent.getTaskID();
if (lg.isTraceEnabled())
lg.trace("onWorkerEventMessage[" + workerEvent.getEventTypeID() + "," + workerEvent.getSimulationMessage() + "][simid=" + workerEvent.getVCSimulationDataIdentifier() + ",job=" + jobIndex + ",task=" + workerEventTaskID + "]");
VCSimulationDataIdentifier vcSimDataID = workerEvent.getVCSimulationDataIdentifier();
if (vcSimDataID == null) {
VCMongoMessage.sendInfo("onWorkerEvent() ignoring WorkerEvent - no SimID in message): " + workerEvent.show());
return;
}
KeyValue simKey = vcSimDataID.getSimulationKey();
SimulationJobStatus oldSimulationJobStatus = simulationDatabase.getLatestSimulationJobStatus(simKey, jobIndex);
if (oldSimulationJobStatus == null) {
VCMongoMessage.sendInfo("onWorkerEvent() ignoring WorkerEvent, no current SimulationJobStatus: " + workerEvent.show());
return;
}
if (oldSimulationJobStatus == null || oldSimulationJobStatus.getSchedulerStatus().isDone() || oldSimulationJobStatus.getTaskID() > workerEventTaskID) {
VCMongoMessage.sendInfo("onWorkerEvent() ignoring outdated WorkerEvent, (currState=" + oldSimulationJobStatus.getSchedulerStatus().getDescription() + "): " + workerEvent.show());
return;
}
int taskID = oldSimulationJobStatus.getTaskID();
SchedulerStatus oldSchedulerStatus = oldSimulationJobStatus.getSchedulerStatus();
//
// status information (initialized as if new record)
//
Date startDate = null;
Date lastUpdateDate = null;
Date endDate = null;
boolean hasData = false;
HtcJobID htcJobID = null;
String computeHost = null;
VCellServerID vcServerID = VCellServerID.getSystemServerID();
Date submitDate = null;
Date queueDate = null;
int queuePriority = PRIORITY_DEFAULT;
SimulationJobStatus.SimulationQueueID simQueueID = SimulationJobStatus.SimulationQueueID.QUEUE_ID_WAITING;
//
// update using previously stored status (if available).
//
SimulationExecutionStatus oldSimExeStatus = oldSimulationJobStatus.getSimulationExecutionStatus();
if (oldSimExeStatus != null && oldSimExeStatus.getStartDate() != null) {
startDate = oldSimExeStatus.getStartDate();
}
if (oldSimExeStatus != null && oldSimExeStatus.getLatestUpdateDate() != null) {
lastUpdateDate = oldSimExeStatus.getLatestUpdateDate();
}
if (oldSimExeStatus != null && oldSimExeStatus.getEndDate() != null) {
endDate = oldSimExeStatus.getEndDate();
}
if (oldSimExeStatus != null && oldSimExeStatus.hasData()) {
hasData = true;
}
if (oldSimExeStatus != null && oldSimExeStatus.getComputeHost() != null) {
computeHost = oldSimExeStatus.getComputeHost();
}
if (oldSimExeStatus != null && oldSimExeStatus.getHtcJobID() != null) {
htcJobID = oldSimExeStatus.getHtcJobID();
}
vcServerID = oldSimulationJobStatus.getServerID();
submitDate = oldSimulationJobStatus.getSubmitDate();
SimulationQueueEntryStatus oldQueueStatus = oldSimulationJobStatus.getSimulationQueueEntryStatus();
if (oldQueueStatus != null && oldQueueStatus.getQueueDate() != null) {
queueDate = oldQueueStatus.getQueueDate();
}
if (oldQueueStatus != null) {
queuePriority = oldQueueStatus.getQueuePriority();
}
if (oldQueueStatus != null && oldQueueStatus.getQueueID() != null) {
simQueueID = oldQueueStatus.getQueueID();
}
//
if (workerEvent.getHtcJobID() != null) {
htcJobID = workerEvent.getHtcJobID();
}
if (workerEvent.getHostName() != null) {
computeHost = workerEvent.getHostName();
}
SimulationMessage workerEventSimulationMessage = workerEvent.getSimulationMessage();
if (workerEventSimulationMessage.getHtcJobId() != null) {
htcJobID = workerEventSimulationMessage.getHtcJobId();
}
SimulationJobStatus newJobStatus = null;
if (workerEvent.isAcceptedEvent()) {
//
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued()) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
lastUpdateDate = new Date();
startDate = lastUpdateDate;
endDate = null;
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.DISPATCHED, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
} else if (workerEvent.isStartingEvent()) {
// only update database when the job event changes from started to running. The later progress event will not be recorded.
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
lastUpdateDate = new Date();
if (startDate == null) {
startDate = lastUpdateDate;
}
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.RUNNING, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
} else if (workerEvent.isNewDataEvent()) {
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
if (!oldSchedulerStatus.isRunning() || simQueueID != SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL || hasData == false) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
if (startDate == null) {
startDate = lastUpdateDate;
}
hasData = true;
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.RUNNING, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
}
} else if (workerEvent.isProgressEvent() || workerEvent.isWorkerAliveEvent()) {
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
if (!oldSchedulerStatus.isRunning() || simQueueID != SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
if (startDate == null) {
startDate = lastUpdateDate;
}
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.RUNNING, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
} else if (oldSchedulerStatus.isRunning()) {
if (oldSimExeStatus != null) {
// Date latestUpdate = oldSimExeStatus.getLatestUpdateDate();
// if (System.currentTimeMillis() - latestUpdate.getTime() >= MessageConstants.INTERVAL_PING_SERVER_MS * 3 / 5) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.RUNNING, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
// }
}
}
} else if (workerEvent.isCompletedEvent()) {
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
endDate = new Date();
hasData = true;
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.COMPLETED, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
} else if (workerEvent.isFailedEvent()) {
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
endDate = new Date();
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.FAILED, taskID, workerEventSimulationMessage, newQueueStatus, newExeStatus);
}
} else if (workerEvent.isWorkerExitErrorEvent()) {
if (oldSchedulerStatus.isWaiting() || oldSchedulerStatus.isQueued() || oldSchedulerStatus.isDispatched() || oldSchedulerStatus.isRunning()) {
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(queueDate, queuePriority, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
// new exe status
endDate = new Date();
SimulationExecutionStatus newExeStatus = new SimulationExecutionStatus(startDate, computeHost, lastUpdateDate, endDate, hasData, htcJobID);
SimulationMessage simulationMessage = SimulationMessage.workerFailure("solver stopped unexpectedly, " + workerEventSimulationMessage.getDisplayMessage());
newJobStatus = new SimulationJobStatus(vcServerID, vcSimDataID.getVcSimID(), jobIndex, submitDate, SchedulerStatus.FAILED, taskID, simulationMessage, newQueueStatus, newExeStatus);
}
}
if (newJobStatus != null) {
if (!newJobStatus.compareEqual(oldSimulationJobStatus) || workerEvent.isProgressEvent() || workerEvent.isNewDataEvent()) {
Double progress = workerEvent.getProgress();
Double timepoint = workerEvent.getTimePoint();
RunningStateInfo runningStateInfo = null;
if (progress != null && timepoint != null) {
runningStateInfo = new RunningStateInfo(progress, timepoint);
}
simulationDatabase.updateSimulationJobStatus(newJobStatus, runningStateInfo);
StatusMessage msgForClient = new StatusMessage(newJobStatus, userName, progress, timepoint);
msgForClient.sendToClient(session);
if (lg.isTraceEnabled())
lg.trace("Send status to client: " + msgForClient);
} else {
simulationDatabase.updateSimulationJobStatus(newJobStatus);
StatusMessage msgForClient = new StatusMessage(newJobStatus, userName, null, null);
msgForClient.sendToClient(session);
if (lg.isTraceEnabled())
lg.trace("Send status to client: " + msgForClient);
}
} else if (workerEvent.isProgressEvent() || workerEvent.isNewDataEvent()) {
Double progress = workerEvent.getProgress();
Double timepoint = workerEvent.getTimePoint();
RunningStateInfo runningStateInfo = null;
if (progress != null && timepoint != null) {
runningStateInfo = new RunningStateInfo(progress, timepoint);
}
simulationDatabase.updateSimulationJobStatus(oldSimulationJobStatus, runningStateInfo);
StatusMessage msgForClient = new StatusMessage(oldSimulationJobStatus, userName, progress, timepoint);
msgForClient.sendToClient(session);
if (lg.isTraceEnabled())
lg.trace("Send status to client: " + msgForClient);
} else {
VCMongoMessage.sendInfo("onWorkerEvent() ignoring WorkerEvent (currState=" + oldSchedulerStatus.getDescription() + "): " + workerEvent.show());
}
// addStateMachineTransition(new StateMachineTransition(new WorkerStateMachineEvent(taskID, workerEvent), oldSimulationJobStatus, newJobStatus));
}
use of cbit.vcell.solver.VCSimulationDataIdentifier in project vcell by virtualcell.
the class EstParams_ReacBindingPanel method simulateWithCurrentParameters.
private // used by reaction binding panel only. not used by VFRAP 1.1 though
void simulateWithCurrentParameters() {
fStudy = getFrapWorkspace().getWorkingFrapStudy();
// save external files if needed
AsynchClientTask saveTask = new AsynchClientTask("Preparing to run simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// check external data before running simulation
if (!FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo(), fStudy.getRoiExternalDataInfo())) {
// if external files are missing/currupt or ROIs are changed, create keys and save them
fStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(getLocalWorkspace(), FRAPStudy.IMAGE_EXTDATA_NAME));
fStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(getLocalWorkspace(), FRAPStudy.ROI_EXTDATA_NAME));
try {
fStudy.saveROIsAsExternalData(getLocalWorkspace(), fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
fStudy.saveImageDatasetAsExternalData(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
// run simulation task
AsynchClientTask runSimTask = new AsynchClientTask("Running simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModel bioModel = null;
KeyValue simKey = null;
// }
try {
bioModel = FRAPStudy.createNewSimBioModel(fStudy, getCurrentParameters(), null, LocalWorkspace.createNewKeyValue(), LocalWorkspace.getDefaultOwner(), fStudy.getStartingIndexForRecovery());
// we don't have to set the bioModel to frap study, we just need the results.
// change time bound and time step
// Simulation sim = bioModel.getSimulations()[0];
// sim.getSolverTaskDescription().setTimeBounds(getRefTimeBounds());
// sim.getSolverTaskDescription().setTimeStep(getRefTimeStep());
// sim.getSolverTaskDescription().setOutputTimeSpec(getRefTimeSpec());
// System.out.println("run FRAP Reference Simulation...");
// final double RUN_REFSIM_PROGRESS_FRACTION = 1.0;
// DataSetControllerImpl.ProgressListener runRefSimProgressListener =
// new DataSetControllerImpl.ProgressListener(){
// public void updateProgress(double progress) {
// if(progressListener != null){
// //To run to the steady state the time length is unpredictable. Progress increase 10 times
// //because we manually set ending time to 1000 and usually it will reach steady state in less than 100 seconds.
// //max allowed progress is 80%. this is heuristic.
// progressListener.updateProgress(Math.min(0.8, (progress*10)*RUN_REFSIM_PROGRESS_FRACTION));
// }
// }
// public void updateMessage(String message){
// if(progressListener != null){
// progressListener.updateMessage(message);
// }
// }
// };
// run simulation
FRAPStudy.runFVSolverStandalone(new File(getLocalWorkspace().getDefaultSimDataDirectory()), bioModel.getSimulation(0), fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), this.getClientTaskStatusSupport(), false);
/*//prepare to run native FV solver
Simulation simulation = bioModel.getSimulations()[0];
// clone and resample geometry
Geometry resampledGeometry = null;
try {
resampledGeometry = (Geometry) BeanUtils.cloneSerializable(simulation.getMathDescription().getGeometry());
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
ISize newSize = simulation.getMeshSpecification().getSamplingSize();
geoSurfaceDesc.setVolumeSampleSize(newSize);
geoSurfaceDesc.updateAll();
} catch (Exception e) {
e.printStackTrace();
throw new SolverException(e.getMessage());
}
SimulationJob simJob = new SimulationJob(simulation, 0, null); //fielddata ID?
StringWriter simulationInputStringWriter = new StringWriter();
FiniteVolumeFileWriter fvFileWriter = new FiniteVolumeFileWriter(new PrintWriter(simulationInputStringWriter,true), simJob, resampledGeometry, new File(getLocalWorkspace().getDefaultSimDataDirectory())); //need dir?
fvFileWriter.write(null); //what are parameter names?
simulationInputStringWriter.close();
String fvInputStr = simulationInputStringWriter.getBuffer().toString();
//run simulation with native FV solver
double[][][] rawSimResults = new NativeFVSolver().solve(fvInputStr);*/
simKey = bioModel.getSimulations()[0].getVersion().getVersionKey();
} catch (Exception e) {
if (bioModel != null && bioModel.getSimulations() != null) {
FRAPStudy.removeExternalDataAndSimulationFiles(bioModel.getSimulations()[0].getVersion().getVersionKey(), null, null, getLocalWorkspace());
}
throw e;
}
// push sim key into hash table
// for all loaded file
hashTable.put(FRAPStudyPanel.SIMULATION_KEY, simKey);
}
};
// generate dimension reduced sim data
AsynchClientTask readDataTask = new AsynchClientTask("Reading simulation data ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
KeyValue simulationKey = (KeyValue) hashTable.get(FRAPStudyPanel.SIMULATION_KEY);
if (simulationKey != null) {
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simulationKey, LocalWorkspace.getDefaultOwner());
VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, FieldDataFileOperationSpec.JOBINDEX_DEFAULT);
double[] rawSimTimePoints = getLocalWorkspace().getVCDataManager().getDataSetTimes(vcSimDataID);
// to store time points in frap model (simulation time points may be slightly different with exp time points)
setCurrentRawSimTimePoints(rawSimTimePoints);
// refDataTimePoints = timeShiftForBaseDiffRate(rawRefDataTimePoints);
// System.out.println("simulation done...");
// DataSetControllerImpl.ProgressListener reducedRefDataProgressListener =
// new DataSetControllerImpl.ProgressListener(){
// public void updateProgress(double progress) {
// if(progressListener != null){
// progressListener.setProgress((int)((.5+progress*(1-RUNSIM_PROGRESS_FRACTION))*100));
// }
// }
// public void updateMessage(String message){
// if(progressListener != null){
// progressListener.setMessage(message);
// }
// }
// };
double[][] results = FRAPOptimizationUtils.dataReduction(getLocalWorkspace().getVCDataManager(), vcSimDataID, rawSimTimePoints, fStudy.getFrapData().getRois(), this.getClientTaskStatusSupport(), false);
// to store data in frap model.
setCurrentSimResults(results);
System.out.println("generating dimension reduced ref data, done ....");
// remove reference simulation files
FRAPStudy.removeSimulationFiles(simulationKey, getLocalWorkspace());
}
}
};
// plot task
AsynchClientTask plotTask = new AsynchClientTask("Generating plots ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
try {
setData(fStudy.getFrapData(), getCurrentParameters(), fStudy.getFrapData().getImageDataset().getImageTimeStamps(), fStudy.getStartingIndexForRecovery(), fStudy.getSelectedROIsForErrorCalculation());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(System.out);
}
}
};
// dispatch
ClientTaskDispatcher.dispatch(EstParams_ReacBindingPanel.this, new Hashtable<String, Object>(), new AsynchClientTask[] { saveTask, runSimTask, readDataTask, plotTask }, false);
}
Aggregations