use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class SmoldynFileWriter method writeDataProcessor.
private void writeDataProcessor() throws DataAccessException, IOException, MathException, DivideByZeroException, ExpressionException {
Simulation simulation = simTask.getSimulation();
DataProcessingInstructions dpi = simulation.getDataProcessingInstructions();
if (dpi == null) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " begin " + DataProcessingInstructions.ROI_TIME_SERIES);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " end");
} else {
FieldDataIdentifierSpec fdis = dpi.getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis == null) {
throw new DataAccessException("Can't find sample image in data processing instructions");
}
File userDirectory = outputFile.getParentFile();
String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
DataSetControllerImpl dsci = new DataSetControllerImpl(null, userDirectory.getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
CartesianMesh origMesh = dsci.getMesh(fdis.getExternalDataIdentifier());
SimDataBlock simDataBlock = dsci.getSimDataBlock(null, fdis.getExternalDataIdentifier(), fdis.getFieldFuncArgs().getVariableName(), fdis.getFieldFuncArgs().getTime().evaluateConstant());
VariableType varType = fdis.getFieldFuncArgs().getVariableType();
VariableType dataVarType = simDataBlock.getVariableType();
if (!varType.equals(VariableType.UNKNOWN) && !varType.equals(dataVarType)) {
throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
}
double[] origData = simDataBlock.getData();
String filename = SimulationJob.createSimulationJobID(Simulation.createSimulationID(simulation.getKey()), simTask.getSimulationJob().getJobIndex()) + SimulationData.getDefaultFieldDataFileNameForSimulation(fdis.getFieldFuncArgs());
File fdatFile = new File(userDirectory, filename);
DataSet.writeNew(fdatFile, new String[] { fdis.getFieldFuncArgs().getVariableName() }, new VariableType[] { simDataBlock.getVariableType() }, new ISize(origMesh.getSizeX(), origMesh.getSizeY(), origMesh.getSizeZ()), new double[][] { origData });
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " begin " + dpi.getScriptName());
StringTokenizer st = new StringTokenizer(dpi.getScriptInput(), "\n\r");
while (st.hasMoreTokens()) {
String str = st.nextToken();
if (str.trim().length() > 0) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " " + str);
}
}
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " SampleImageFile " + fdis.getFieldFuncArgs().getVariableName() + " " + fdis.getFieldFuncArgs().getTime().infix() + " " + fdatFile);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " end");
}
}
use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class FRAPOptData method runRefSimulation.
public KeyValue runRefSimulation(final ClientTaskStatusSupport progressListener) throws Exception {
BioModel bioModel = null;
if (progressListener != null) {
progressListener.setMessage("Running Reference Simulation...");
}
try {
FieldDataIdentifierSpec psfFieldFunc = FRAPStudy.getPSFFieldData(getLocalWorkspace());
bioModel = FRAPStudy.createNewRefBioModel(expFrapStudy, REFERENCE_DIFF_RATE_STR, getRefTimeStep(), LocalWorkspace.createNewKeyValue(), LocalWorkspace.getDefaultOwner(), psfFieldFunc, expFrapStudy.getStartingIndexForRecovery());
// change time bound and time step
Simulation sim = bioModel.getSimulations()[0];
ROIDataGenerator roiDataGenerator = getExpFrapStudy().getROIDataGenerator(getLocalWorkspace());
sim.getMathDescription().getPostProcessingBlock().addDataGenerator(roiDataGenerator);
System.out.println("run FRAP Reference Simulation...");
// run simulation
FRAPStudy.runFVSolverStandalone_ref(new File(getLocalWorkspace().getDefaultSimDataDirectory()), bioModel.getSimulation(0), getExpFrapStudy().getFrapDataExternalDataInfo().getExternalDataIdentifier(), getExpFrapStudy().getRoiExternalDataInfo().getExternalDataIdentifier(), psfFieldFunc.getExternalDataIdentifier(), progressListener, true);
KeyValue referenceSimKeyValue = sim.getVersion().getVersionKey();
return referenceSimKeyValue;
} catch (Exception e) {
e.printStackTrace(System.out);
if (bioModel != null && bioModel.getSimulations() != null) {
FRAPStudy.removeExternalDataAndSimulationFiles(bioModel.getSimulations()[0].getVersion().getVersionKey(), null, null, getLocalWorkspace());
}
throw e;
}
}
use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class FRAPStudy method runFVSolverStandalone.
public static void runFVSolverStandalone(File simulationDataDir, Simulation sim, ExternalDataIdentifier imageDataExtDataID, ExternalDataIdentifier roiExtDataID, 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 {
throw new RuntimeException("failed to resolve field named " + fieldFunctionArgs[i].getFieldName());
}
}
int jobIndex = 0;
SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs), 0);
// if we need to check steady state, do the following two lines
if (bCheckSteadyState) {
simTask.getSimulation().getSolverTaskDescription().setStopAtSpatiallyUniformErrorTolerance(ErrorTolerance.getDefaultSpatiallyUniformErrorTolerance());
simTask.getSimulation().getSolverTaskDescription().setErrorTolerance(new ErrorTolerance(1e-6, 1e-2));
}
SolverUtilities.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
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) {
String roiMeshFileName = SimulationData.createCanonicalMeshFileName(roiExtDataID.getKey(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT, false);
String imageDataMeshFileName = SimulationData.createCanonicalMeshFileName(imageDataExtDataID.getKey(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT, false);
String simulationMeshFileName = SimulationData.createCanonicalMeshFileName(sim.getVersion().getVersionKey(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT, false);
// delete old external data mesh files and copy simulation mesh file to them
File roiMeshFile = new File(simulationDataDir, roiMeshFileName);
File imgMeshFile = new File(simulationDataDir, imageDataMeshFileName);
File simMeshFile = new File(simulationDataDir, simulationMeshFileName);
if (!roiMeshFile.delete()) {
throw new Exception("Couldn't delete ROI Mesh file " + roiMeshFile.getAbsolutePath());
}
if (!imgMeshFile.delete()) {
throw new Exception("Couldn't delete ImageData Mesh file " + imgMeshFile.getAbsolutePath());
}
FileUtils.copyFile(simMeshFile, roiMeshFile);
FileUtils.copyFile(simMeshFile, imgMeshFile);
} else {
throw new Exception("Sover did not finish normally." + status.toString());
}
}
use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class ROIDataGenerator method getSampleImageFieldData.
public FieldDataIdentifierSpec getSampleImageFieldData(User user) {
// key
String key = fieldDataKey.toString();
String fieldInput = fieldFuncArguments.infix();
StringTokenizer st = null;
int index = fieldInput.indexOf(FieldFunctionDefinition.FUNCTION_name);
if (index >= 0) {
st = new StringTokenizer(fieldInput.substring(index), "\n");
if (st.hasMoreTokens()) {
String fieldFunction = st.nextToken();
try {
Expression exp = new Expression(fieldFunction);
FieldFunctionArguments[] ffa = FieldUtilities.getFieldFunctionArguments(exp);
return new FieldDataIdentifierSpec(ffa[0], new ExternalDataIdentifier(KeyValue.fromString(key), user, ffa[0].getFieldName()));
} catch (ExpressionException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Failed to load data processing script.");
}
}
}
return null;
}
use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class SimulationTaskMessage method toMessage.
/**
* Insert the method's description here.
* Creation date: (12/31/2003 11:08:17 AM)
* @return javax.jms.Message
* @param session cbit.vcell.messaging.VCellSession
* @throws VCMessagingException
*/
private VCMessage toMessage(VCMessageSession session) throws VCMessagingException {
VCMessage message;
try {
message = session.createTextMessage(XmlHelper.simTaskToXML(simTask));
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new VCMessagingException("failed to restore Simulation Task from XML", e);
}
// must have
message.setStringProperty(VCMessagingConstants.MESSAGE_TYPE_PROPERTY, MessageConstants.MESSAGE_TYPE_SIMULATION_JOB_VALUE);
// must have
message.setIntProperty(MessageConstants.JOBINDEX_PROPERTY, simTask.getSimulationJob().getJobIndex());
// must have
message.setIntProperty(MessageConstants.TASKID_PROPERTY, simTask.getTaskID());
// might be used to remove from the job queue when do stopSimulation
message.setStringProperty(VCMessagingConstants.USERNAME_PROPERTY, simTask.getUserName());
// might be used to remove from the job queue when do stopSimulation
message.setLongProperty(MessageConstants.SIMKEY_PROPERTY, Long.parseLong(simTask.getSimKey() + ""));
// for worker message filter
message.setDoubleProperty(MessageConstants.SIZE_MB_PROPERTY, simTask.getEstimatedMemorySizeMB());
if (simTask.getComputeResource() != null) {
// for worker message filter
message.setStringProperty(MessageConstants.COMPUTE_RESOURCE_PROPERTY, simTask.getComputeResource());
}
FieldDataIdentifierSpec[] fieldDataIDs = simTask.getSimulationJob().getFieldDataIdentifierSpecs();
if (fieldDataIDs != null && fieldDataIDs.length > 0) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < fieldDataIDs.length; i++) {
sb.append(fieldDataIDs[i].toCSVString() + "\n");
}
message.setStringProperty(MessageConstants.FIELDDATAID_PROPERTY, sb.toString());
}
return message;
}
Aggregations