use of cbit.vcell.solver.DataProcessingInstructions in project vcell by virtualcell.
the class RunSims method run.
/**
* Insert the method's description here.
* Creation date: (5/31/2004 6:04:14 PM)
* @param hashTable java.util.Hashtable
* @param clientWorker cbit.vcell.desktop.controls.ClientWorker
*/
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
ClientSimManager clientSimManager = (ClientSimManager) hashTable.get("clientSimManager");
// DocumentManager documentManager = (DocumentManager)hashTable.get(CommonTask.DOCUMENT_MANAGER.name);
JobManager jobManager = (JobManager) hashTable.get("jobManager");
Simulation[] simulations = (Simulation[]) hashTable.get("simulations");
Hashtable<Simulation, Throwable> failures = new Hashtable<Simulation, Throwable>();
if (simulations != null && simulations.length > 0) {
// we need to get the new ones if a save occurred...
if (hashTable.containsKey(SaveDocument.DOC_KEY)) {
VCDocument savedDocument = (VCDocument) hashTable.get(SaveDocument.DOC_KEY);
Simulation[] allSims = null;
if (savedDocument instanceof BioModel) {
allSims = ((BioModel) savedDocument).getSimulations();
} else if (savedDocument instanceof MathModel) {
allSims = ((MathModel) savedDocument).getSimulations();
}
Vector<Simulation> v = new Vector<Simulation>();
for (int i = 0; i < simulations.length; i++) {
for (int j = 0; j < allSims.length; j++) {
if (simulations[i].getName().equals(allSims[j].getName())) {
v.add(allSims[j]);
break;
}
}
}
simulations = (Simulation[]) BeanUtils.getArray(v, Simulation.class);
}
for (Simulation sim : simulations) {
try {
int dimension = sim.getMathDescription().getGeometry().getDimension();
if (clientSimManager.getSimulationStatus(sim).isCompleted()) {
// completed
String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_1, sim.getName());
String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
if (result == null || !result.equals(UserMessage.OPTION_OK)) {
continue;
}
}
DataProcessingInstructions dataProcessingInstructions = sim.getDataProcessingInstructions();
try {
if (dataProcessingInstructions != null) {
dataProcessingInstructions.getSampleImageFieldData(sim.getVersion().getOwner());
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(documentWindowManager.getComponent(), "Problem found in simulation '" + sim.getName() + "':\n" + ex.getMessage());
continue;
}
if (dimension > 0) {
MeshSpecification meshSpecification = sim.getMeshSpecification();
boolean bCellCentered = sim.hasCellCenteredMesh();
if (meshSpecification != null && !meshSpecification.isAspectRatioOK(bCellCentered)) {
String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_2, sim.getName(), "\u0394x=" + meshSpecification.getDx(bCellCentered) + "\n" + "\u0394y=" + meshSpecification.getDy(bCellCentered) + (dimension < 3 ? "" : "\n\u0394z=" + meshSpecification.getDz(bCellCentered)));
String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
if (result == null || !result.equals(UserMessage.OPTION_OK)) {
continue;
}
}
if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.Smoldyn)) {
if (!isSmoldynTimeStepOK(sim)) {
double s = smoldynTimestepVars.getSpatialResolution();
double dMax = smoldynTimestepVars.getMaxDiffusion();
double condn = (s * s) / (2.0 * dMax);
String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_3, Double.toString(s), Double.toString(dMax), Double.toString(condn));
DialogUtils.showErrorDialog(documentWindowManager.getComponent(), warningMessage);
continue;
}
}
// check the number of regions if the simulation mesh is coarser.
Geometry mathGeometry = sim.getMathDescription().getGeometry();
ISize newSize = meshSpecification.getSamplingSize();
ISize defaultSize = mathGeometry.getGeometrySpec().getDefaultSampledImageSize();
if (!sim.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
int defaultTotalVolumeElements = mathGeometry.getGeometrySurfaceDescription().getVolumeSampleSize().getXYZ();
int newTotalVolumeElements = meshSpecification.getSamplingSize().getXYZ();
if (defaultTotalVolumeElements > newTotalVolumeElements) {
// coarser
Geometry resampledGeometry = (Geometry) BeanUtils.cloneSerializable(mathGeometry);
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
geoSurfaceDesc.setVolumeSampleSize(newSize);
geoSurfaceDesc.updateAll();
if (mathGeometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
mathGeometry.getGeometrySurfaceDescription().updateAll();
}
int defaultNumGeometricRegions = mathGeometry.getGeometrySurfaceDescription().getGeometricRegions().length;
int numGeometricRegions = geoSurfaceDesc.getGeometricRegions().length;
if (numGeometricRegions != defaultNumGeometricRegions) {
String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_4, newSize.getX() + (dimension > 1 ? " x " + newSize.getY() : "") + (dimension > 2 ? " x " + newSize.getZ() : ""), sim.getName(), numGeometricRegions, defaultNumGeometricRegions);
String result = PopupGenerator.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
if (result == null || !result.equals(UserMessage.OPTION_OK)) {
continue;
}
}
}
if (mathGeometry.getGeometrySpec().hasImage()) {
// if it's an image.
if (defaultSize.getX() + 1 < newSize.getX() || defaultSize.getY() + 1 < newSize.getY() || defaultSize.getZ() + 1 < newSize.getZ()) {
// finer
String defaultSizeString = (defaultSize.getX() + 1) + (dimension > 1 ? " x " + (defaultSize.getY() + 1) : "") + (dimension > 2 ? " x " + (defaultSize.getZ() + 1) : "");
String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_5, newSize.getX() + (dimension > 1 ? " x " + newSize.getY() : "") + (dimension > 2 ? " x " + newSize.getZ() : ""), sim.getName(), defaultSizeString, defaultSizeString);
String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
if (result == null || !result.equals(UserMessage.OPTION_OK)) {
continue;
}
}
}
}
boolean bGiveWarning = false;
for (int i = 0; i < sim.getScanCount(); i++) {
if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.SundialsPDE)) {
SimulationJob simJob = new SimulationJob(sim, i, null);
if (simJob.getSimulationSymbolTable().hasTimeVaryingDiffusionOrAdvection()) {
bGiveWarning = true;
break;
}
}
}
if (bGiveWarning) {
String warningMessage = VCellErrorMessages.RunSims_6;
String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
if (result == null || !result.equals(UserMessage.OPTION_OK)) {
continue;
}
}
}
SimulationInfo simInfo = sim.getSimulationInfo();
if (simInfo != null) {
//
// translate to common ancestral simulation (oldest mathematically equivalent simulation)
//
SimulationStatus simulationStatus = jobManager.startSimulation(simInfo.getAuthoritativeVCSimulationIdentifier(), sim.getScanCount());
// updateStatus
clientSimManager.updateStatusFromStartRequest(sim, simulationStatus);
} else {
// this should really not happen...
throw new RuntimeException(">>>>>>>>>> trying to run an unsaved simulation...");
}
} catch (Throwable exc) {
exc.printStackTrace(System.out);
failures.put(sim, exc);
}
}
}
// we deal with individual request failures here, passing down only other things (that break the whole thing down) to dispatcher
if (!failures.isEmpty()) {
Enumeration<Simulation> en = failures.keys();
while (en.hasMoreElements()) {
Simulation sim = en.nextElement();
Throwable exc = (Throwable) failures.get(sim);
// // updateStatus
// SimulationStatus simulationStatus = clientSimManager.updateStatusFromStartRequest(sim, true, exc.getMessage());
// notify user
PopupGenerator.showErrorDialog(documentWindowManager, "Failed to start simulation'" + sim.getName() + "'\n" + exc.getMessage());
}
}
}
use of cbit.vcell.solver.DataProcessingInstructions in project vcell by virtualcell.
the class SimulationTable method getSimulation.
/**
* This method was created in VisualAge.
* @return cbit.vcell.math.MathDescription
* @param user cbit.vcell.server.User
* @param rset java.sql.ResultSet
*/
public Simulation getSimulation(QueryHashtable dbc, ResultSet rset, Connection con, User user, MathDescriptionDbDriver mathDB, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException, PropertyVetoException {
//
// get TaskDescription Data into parsable form
//
//
// String taskDescriptionString = new String(solverTaskDescData);
//
// System.out.println("taskDescriptionString '"+taskDescriptionString+"'");
String taskDescriptionString = rset.getString(SimulationTable.table.taskDescription.getUnqualifiedColName());
taskDescriptionString = TokenMangler.getSQLRestoredString(taskDescriptionString);
CommentStringTokenizer solverTaskDescTokens = new CommentStringTokenizer(taskDescriptionString);
//
// get MathOverride Data (language) (MUST BE READ FIRST)
//
/*
byte[] mathOverridesData = null;
mathOverridesData = rset.getBytes(SimulationTable.table.mathOverrides.toString());
if (rset.wasNull() || mathOverridesData==null || mathOverridesData.length==0){
throw new DataAccessException("no data stored for MathOverrides");
}
String mathOverridesString = new String(mathOverridesData);
*/
//
CommentStringTokenizer mathOverrideTokens = getMathOverridesTokenizer(rset, dbSyntax);
String dataProcessingInstructionString = rset.getString(dataProcInstr.getUnqualifiedColName());
DataProcessingInstructions dpi = null;
if (!rset.wasNull() && dataProcessingInstructionString != null && dataProcessingInstructionString.length() > 0) {
dataProcessingInstructionString = TokenMangler.getSQLRestoredString(dataProcessingInstructionString);
dpi = DataProcessingInstructions.fromDbXml(dataProcessingInstructionString);
}
//
// Get Version
//
java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
SimulationVersion simulationVersion = (SimulationVersion) getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
java.math.BigDecimal bigD = rset.getBigDecimal(SimulationTable.table.mathRef.toString());
KeyValue mathKey = null;
if (!rset.wasNull()) {
mathKey = new KeyValue(bigD);
} else {
throw new DataAccessException("Error: MathDescription Reference Cannot be Null for Simulation");
}
MathDescription mathDesc = (MathDescription) mathDB.getVersionable(dbc, con, user, VersionableType.MathDescription, mathKey);
Simulation simulation = new Simulation(simulationVersion, mathDesc, mathOverrideTokens, solverTaskDescTokens);
simulation.setDataProcessingInstructions(dpi);
// MeshSpec (Is This Correct?????)
if (mathDesc != null && mathDesc.getGeometry() != null && mathDesc.getGeometry().getDimension() > 0) {
int msX = rset.getInt(SimulationTable.table.meshSpecX.getUnqualifiedColName());
int msY = rset.getInt(SimulationTable.table.meshSpecY.getUnqualifiedColName());
int msZ = rset.getInt(SimulationTable.table.meshSpecZ.getUnqualifiedColName());
MeshSpecification meshSpec = new MeshSpecification(simulation.getMathDescription().getGeometry());
meshSpec.setSamplingSize(new ISize(msX, msY, msZ));
simulation.getMeshSpecification().copyFrom(meshSpec);
}
return simulation;
}
Aggregations