use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.
the class FRAPStudy method runFVSolverStandalone_ref.
public static void runFVSolverStandalone_ref(File simulationDataDir, Simulation sim, ExternalDataIdentifier imageDataExtDataID, ExternalDataIdentifier roiExtDataID, ExternalDataIdentifier psfExtDataID, ClientTaskStatusSupport progressListener, boolean bCheckSteadyState) throws Exception {
FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
if (fieldFunctionArgs[i].getFieldName().equals(imageDataExtDataID.getName())) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], imageDataExtDataID);
} else if (fieldFunctionArgs[i].getFieldName().equals(roiExtDataID.getName())) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], roiExtDataID);
} else if (fieldFunctionArgs[i].getFieldName().equals(psfExtDataID.getName())) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], psfExtDataID);
} else {
throw new RuntimeException("failed to resolve field named " + fieldFunctionArgs[i].getFieldName());
}
}
int jobIndex = 0;
SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs), 0);
SolverUtilities.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
// if we need to check steady state, do the following two lines
if (bCheckSteadyState) {
simTask.getSimulation().getSolverTaskDescription().setStopAtSpatiallyUniformErrorTolerance(ErrorTolerance.getDefaultSpatiallyUniformErrorTolerance());
// simJob.getSimulation().getSolverTaskDescription().setErrorTolerance(new ErrorTolerance(1e-6, 1e-2));
}
FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simulationDataDir, false);
fvSolver.startSolver();
SolverStatus status = fvSolver.getSolverStatus();
while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED) {
if (progressListener != null) {
progressListener.setProgress((int) (fvSolver.getProgress() * 100));
if (progressListener.isInterrupted()) {
fvSolver.stopSolver();
throw UserCancelException.CANCEL_GENERIC;
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace(System.out);
// catch interrupted exception and ignore it, otherwise it will popup a dialog in user interface saying"sleep interrupted"
}
status = fvSolver.getSolverStatus();
}
if (status.getStatus() != SolverStatus.SOLVER_FINISHED) {
throw new Exception("Sover did not finish normally." + status);
}
}
use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.
the class SimulationData method getChomboFiles.
@Override
public ChomboFiles getChomboFiles() throws IOException, XmlParseException, ExpressionException {
if (chomboFileIterationIndices == null) {
throw new RuntimeException("SimulationData.chomboFileIterationIndices is null, can't process Chombo HDF5 files");
}
if (!(getVcDataId() instanceof VCSimulationDataIdentifier)) {
throw new RuntimeException("SimulationData.getVcDataId() is not a VCSimulationDataIdentifier (type is " + getVcDataId().getClass().getName() + "), can't process chombo HDF5 files");
}
VCSimulationDataIdentifier vcDataID = (VCSimulationDataIdentifier) getVcDataId();
String expectedMeshfile = vcDataID.getID() + ".mesh.hdf5";
File meshFile = amplistorHelper.getFile(expectedMeshfile);
ChomboFiles chomboFiles = new ChomboFiles(vcDataID.getSimulationKey(), vcDataID.getJobIndex(), meshFile);
String simtaskFilePath = vcDataID.getID() + "_0.simtask.xml";
File simtaskFile = amplistorHelper.getFile(simtaskFilePath);
if (!simtaskFile.exists()) {
throw new RuntimeException("Chombo dataset mission .simtask.xml file, please rerun");
}
String xmlString = FileUtils.readFileToString(simtaskFile);
SimulationTask simTask = XmlHelper.XMLToSimTask(xmlString);
if (!simTask.getSimulation().getSolverTaskDescription().getChomboSolverSpec().isSaveChomboOutput() && !simTask.getSimulation().getSolverTaskDescription().isParallel()) {
throw new RuntimeException("Export of Chombo simulations to VTK requires chombo data, select 'Chombo' data format in simulation solver options and rerun simulation.");
}
CartesianMeshChombo chomboMesh = (CartesianMeshChombo) mesh;
FeaturePhaseVol[] featurePhaseVols = chomboMesh.getFeaturePhaseVols();
for (int timeIndex : chomboFileIterationIndices) {
if (featurePhaseVols == null) {
// for old format which doesn't have featurephasevols, we need to try ivol up to 20 for each feature
Enumeration<SubDomain> subdomainEnum = simTask.getSimulation().getMathDescription().getSubDomains();
while (subdomainEnum.hasMoreElements()) {
SubDomain subDomain = subdomainEnum.nextElement();
if (subDomain instanceof CompartmentSubDomain) {
for (int ivol = 0; ivol < 20; ++ivol) {
// can be many vol, let us try 20
findChomboFeatureVolFile(chomboFiles, vcDataID, subDomain.getName(), ivol, timeIndex);
}
}
}
} else {
// note: some feature + ivol doesn't have a file if there are no variables defined in that feature
for (FeaturePhaseVol pfv : featurePhaseVols) {
findChomboFeatureVolFile(chomboFiles, vcDataID, pfv.feature, pfv.ivol, timeIndex);
}
}
}
return chomboFiles;
}
use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.
the class SimulationStateMachine method onDispatch.
public synchronized void onDispatch(Simulation simulation, SimulationJobStatus oldSimulationJobStatus, SimulationDatabase simulationDatabase, VCMessageSession session) throws VCMessagingException, DataAccessException, SQLException {
updateSolverProcessTimestamp();
VCSimulationIdentifier vcSimID = oldSimulationJobStatus.getVCSimulationIdentifier();
int taskID = oldSimulationJobStatus.getTaskID();
if (!oldSimulationJobStatus.getSchedulerStatus().isWaiting()) {
VCMongoMessage.sendInfo("onDispatch(" + vcSimID.getID() + ") Can't start, simulation[" + vcSimID + "] job [" + jobIndex + "] task [" + taskID + "] is already dispatched (" + oldSimulationJobStatus.getSchedulerStatus().getDescription() + ")");
throw new RuntimeException("Can't start, simulation[" + vcSimID + "] job [" + jobIndex + "] task [" + taskID + "] is already dispatched (" + oldSimulationJobStatus.getSchedulerStatus().getDescription() + ")");
}
FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = simulationDatabase.getFieldDataIdentifierSpecs(simulation);
SimulationTask simulationTask = new SimulationTask(new SimulationJob(simulation, jobIndex, fieldDataIdentifierSpecs), taskID);
double requiredMemMB = simulationTask.getEstimatedMemorySizeMB();
double allowableMemMB = Double.parseDouble(PropertyLoader.getRequiredProperty(PropertyLoader.limitJobMemoryMB));
final SimulationJobStatus newSimJobStatus;
if (requiredMemMB > allowableMemMB) {
//
// fail the simulation
//
Date currentDate = new Date();
// new queue status
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(currentDate, PRIORITY_DEFAULT, SimulationJobStatus.SimulationQueueID.QUEUE_ID_NULL);
SimulationExecutionStatus newSimExeStatus = new SimulationExecutionStatus(null, null, new Date(), null, false, null);
newSimJobStatus = new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, jobIndex, oldSimulationJobStatus.getSubmitDate(), SchedulerStatus.FAILED, taskID, SimulationMessage.jobFailed("simulation required " + requiredMemMB + "MB of memory, only " + allowableMemMB + "MB allowed"), newQueueStatus, newSimExeStatus);
simulationDatabase.updateSimulationJobStatus(newSimJobStatus);
StatusMessage message = new StatusMessage(newSimJobStatus, simulation.getVersion().getOwner().getName(), null, null);
message.sendToClient(session);
} else {
//
// dispatch the simulation, new queue status
//
Date currentDate = new Date();
SimulationQueueEntryStatus newQueueStatus = new SimulationQueueEntryStatus(currentDate, PRIORITY_DEFAULT, SimulationJobStatus.SimulationQueueID.QUEUE_ID_SIMULATIONJOB);
SimulationExecutionStatus newSimExeStatus = new SimulationExecutionStatus(null, null, new Date(), null, false, null);
newSimJobStatus = new SimulationJobStatus(VCellServerID.getSystemServerID(), vcSimID, jobIndex, oldSimulationJobStatus.getSubmitDate(), SchedulerStatus.DISPATCHED, taskID, SimulationMessage.MESSAGE_JOB_DISPATCHED, newQueueStatus, newSimExeStatus);
SimulationTaskMessage simTaskMessage = new SimulationTaskMessage(simulationTask);
simTaskMessage.sendSimulationTask(session);
simulationDatabase.updateSimulationJobStatus(newSimJobStatus);
StatusMessage message = new StatusMessage(newSimJobStatus, simulation.getVersion().getOwner().getName(), null, null);
message.sendToClient(session);
}
// addStateMachineTransition(new StateMachineTransition(new DispatchStateMachineEvent(taskID), oldSimulationJobStatus, newSimJobStatus));
}
use of cbit.vcell.messaging.server.SimulationTask in project vcell by virtualcell.
the class RunSimulation2DOp method runFVSolverStandalone.
private static void runFVSolverStandalone(File simulationDataDir, Simulation sim, ClientTaskStatusSupport progressListener) throws Exception {
int jobIndex = 0;
SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, null), 0);
SolverUtilities.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simulationDataDir, false);
fvSolver.startSolver();
// fvSolver.runSolver();
SolverStatus status = fvSolver.getSolverStatus();
while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED && status.getStatus() != SolverStatus.SOLVER_STOPPED) {
if (progressListener != null) {
progressListener.setProgress((int) (fvSolver.getProgress() * 100));
if (progressListener.isInterrupted()) {
fvSolver.stopSolver();
throw UserCancelException.CANCEL_GENERIC;
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace(System.out);
// catch interrupted exception and ignore it, otherwise it will popup a dialog in user interface saying"sleep interrupted"
}
status = fvSolver.getSolverStatus();
}
if (status.getStatus() != SolverStatus.SOLVER_FINISHED) {
throw new Exception("Sover did not finish normally." + status);
}
}
Aggregations