use of cbit.vcell.solver.SimulationInfo in project vcell by virtualcell.
the class VCellClientDataServiceImpl method getSimsFromOpenModels.
@Override
public List<SimulationDataSetRef> getSimsFromOpenModels() {
ArrayList<SimulationDataSetRef> simulationDataSetRefs = new ArrayList<SimulationDataSetRef>();
for (TopLevelWindowManager windowManager : vcellClient.getMdiManager().getWindowManagers()) {
Simulation[] simulations = null;
VCDocument modelDocument = null;
if (windowManager instanceof BioModelWindowManager) {
BioModelWindowManager selectedBioWindowManager = (BioModelWindowManager) windowManager;
BioModel bioModel = selectedBioWindowManager.getBioModel();
simulations = bioModel.getSimulations();
modelDocument = bioModel;
// simOwnerCount = bioModel.getNumSimulationContexts();
} else if (windowManager instanceof MathModelWindowManager) {
MathModelWindowManager selectedMathWindowManager = (MathModelWindowManager) windowManager;
MathModel mathModel = selectedMathWindowManager.getMathModel();
simulations = mathModel.getSimulations();
modelDocument = mathModel;
// simOwnerCount = 1;
}
if (simulations != null) {
for (Simulation simulation : simulations) {
if (!isVtkSupported(simulation)) {
continue;
}
Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
Extent extent = simulation.getMathDescription().getGeometry().getExtent();
SimulationInfo simInfo = simulation.getSimulationInfo();
SimulationStatus simStatus = vcellClient.getRequestManager().getServerSimulationStatus(simInfo);
for (int jobIndex = 0; jobIndex < simulation.getScanCount(); jobIndex++) {
if (simStatus != null && simStatus.getHasData()) {
SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simulation, modelDocument, jobIndex, false);
simulationDataSetRefs.add(simulationDataSetReference);
}
}
}
}
}
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
String[] simtaskFilenames = localSimDir.list((dir, name) -> (name.endsWith(".simtask.xml")));
for (String simtaskFilename : simtaskFilenames) {
try {
SimulationTask simTask = XmlHelper.XMLToSimTask(org.apache.commons.io.FileUtils.readFileToString(new File(localSimDir, simtaskFilename)));
VCDocument modelDocument = null;
SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simTask.getSimulation(), modelDocument, simTask.getSimulationJob().getJobIndex(), true);
simulationDataSetRefs.add(simulationDataSetReference);
} catch (ExpressionException | XmlParseException | IOException e) {
e.printStackTrace();
}
}
return simulationDataSetRefs;
}
use of cbit.vcell.solver.SimulationInfo in project vcell by virtualcell.
the class TestingFrameworkWindowPanel method getUserSelectedSimulationInfo.
private TFGenerateReport.VCDocumentAndSimInfo getUserSelectedSimulationInfo() throws Exception {
final String CANCEL_STRING = "Cancel";
final String BM_STRING = "BioModel";
final String MM_STRING = "MathModel";
String result = PopupGenerator.showWarningDialog(this, "Choose Reference Model Type.", new String[] { BM_STRING, MM_STRING, CANCEL_STRING }, CANCEL_STRING);
if (result == null || result.equals(CANCEL_STRING)) {
throw UserCancelException.CANCEL_GENERIC;
}
VCDocumentInfo userDefinedRegrRefModel = null;
VCDocument vcDocument = null;
if (result.equals(BM_STRING)) {
userDefinedRegrRefModel = getTestingFrameworkWindowManager().getRequestManager().selectBioModelInfo(getTestingFrameworkWindowManager());
vcDocument = getTestingFrameworkWindowManager().getRequestManager().getDocumentManager().getBioModel(userDefinedRegrRefModel.getVersion().getVersionKey());
} else {
userDefinedRegrRefModel = getTestingFrameworkWindowManager().getRequestManager().selectMathModelInfo(getTestingFrameworkWindowManager());
vcDocument = getTestingFrameworkWindowManager().getRequestManager().getDocumentManager().getMathModel(userDefinedRegrRefModel.getVersion().getVersionKey());
}
SimulationInfo simInfo = getTestingFrameworkWindowManager().getUserSelectedRefSimInfo(getTestingFrameworkWindowManager().getRequestManager(), userDefinedRegrRefModel);
TFGenerateReport.VCDocumentAndSimInfo vcDocumentAndsimInfo = new TFGenerateReport.VCDocumentAndSimInfo(simInfo, vcDocument);
return vcDocumentAndsimInfo;
}
use of cbit.vcell.solver.SimulationInfo in project vcell by virtualcell.
the class TestingFrmwkTreeModel method createTestCaseSubTree.
/**
* Insert the method's description here.
* Creation date: (11/28/00 1:06:51 PM)
* @return cbit.vcell.desktop.BioModelNode
* @param docManager cbit.vcell.clientdb.DocumentManager
*/
private BioModelNode createTestCaseSubTree(TestCaseNew testCase) throws DataAccessException {
//
// add 'test case' node
//
BioModelNode testCaseNode = new BioModelNode(testCase, true);
TestCriteriaNew[] tCriteria = testCase.getTestCriterias();
// Sort
if (tCriteria != null && tCriteria.length > 0) {
java.util.Arrays.sort(tCriteria, new java.util.Comparator<TestCriteriaNew>() {
public int compare(TestCriteriaNew tc1, TestCriteriaNew tc2) {
return tc1.getSimInfo().getVersion().getName().compareTo(tc2.getSimInfo().getVersion().getName());
}
public boolean equals(Object obj) {
return false;
}
});
//
// False => sim has not been run; True => for a regression test, the ref SimInfo is not set.
boolean bRefSimNull = false;
for (int t = 0; t < tCriteria.length; t += 1) {
TestCriteriaNew tcInfo = tCriteria[t];
BioModelNode simInfoNode = new BioModelNode(tcInfo, true);
String tcInfoStr = null;
if (tcInfo != null) {
tcInfoStr = "TestCriteria : LimitAbsError = " + tcInfo.getMaxAbsError() + "; LimitRelError = " + tcInfo.getMaxRelError() + "; ";
if (testCase.getType().equals(TestCaseNew.REGRESSION)) {
if (tcInfo.getRegressionSimInfo() != null) {
SimulationInfo refSimInfo = tcInfo.getRegressionSimInfo();
if (refSimInfo != null) {
if (tcInfo instanceof TestCriteriaNewMathModel) {
tcInfoStr = tcInfoStr + "MathModel : " + ((TestCriteriaNewMathModel) tcInfo).getRegressionMathModelInfo().getVersion().getName() + "; ";
tcInfoStr = tcInfoStr + "SimInfo : " + refSimInfo.getName();
} else if (tcInfo instanceof TestCriteriaNewBioModel) {
tcInfoStr = tcInfoStr + "BioModel : " + ((TestCriteriaNewBioModel) tcInfo).getRegressionBioModelInfo().getVersion().getName() + "; ";
tcInfoStr = tcInfoStr + "SimInfo : " + refSimInfo.getName();
}
}
} else {
tcInfoStr = tcInfoStr + " REFERENCE SIMULATION NOT SET YET";
bRefSimNull = true;
}
}
BioModelNode testCriteriaNode = new BioModelNode(tcInfoStr, false);
simInfoNode.add(testCriteriaNode);
}
// Add sim results if present (by adding the reportInfo subtree ...)
BioModelNode reportInfoNode = createSimulationSubTree(tcInfo, simInfoNode, bRefSimNull);
if (reportInfoNode != null) {
simInfoNode.add(reportInfoNode);
}
testCaseNode.add(simInfoNode);
}
}
return testCaseNode;
}
use of cbit.vcell.solver.SimulationInfo in project vcell by virtualcell.
the class CheckBeforeDelete method checkLostResults.
/**
* Insert the method's description here.
* Creation date: (6/1/2004 3:44:03 PM)
* @return cbit.vcell.solver.SolverResultSetInfo[]
* @param mathmodel cbit.vcell.mathmodel.Mathmodel
*/
private Simulation[] checkLostResults(MathModel oldMathmodel, MathModel newlySavedMathmodel, cbit.vcell.clientdb.DocumentManager documentManager, Simulation[] submittedSimulations) throws Exception {
//
// before deleting old version, prompt user if old simulation results will not be availlable in new edition
//
Vector<Simulation> lostResultsSimulationList = new Vector<Simulation>();
Simulation[] oldSimulations = oldMathmodel.getSimulations();
for (int i = 0; i < oldSimulations.length; i++) {
Simulation oldSimulation = oldSimulations[i];
// SolverResultSetInfo rsInfo = null;
SimulationStatus simStatus = null;
SimulationInfo oldSimInfo = oldSimulation.getSimulationInfo();
if (oldSimInfo != null) {
//
// we need to ask for previous sim results (here we need possible translation to ask for parent's results).
//
simStatus = documentManager.getServerSimulationStatus(oldSimInfo.getAuthoritativeVCSimulationIdentifier());
}
if (simStatus != null && simStatus.getHasData()) {
//
// results exist in old version (the Mathmodel to be deleted) for SimulationInfo "oldSimInfo"
// Users should be warned when they are going to loose any simulation results in any unexpected way.
//
// WARN if the lost data is because new simulation is not mathematically equivalent to old edition
// (different MathDescription key)
//
// IGNORE if the lost data is from edits of a Simulation only (same MathDescription)
// (same MathDescription key, different Simulation key)
//
// IGNORE if Simulation has been deleted
// (Simulation not found in current Mathmodel)
//
// IGNORE if Simulation has been submitted for running
//
boolean bDataInNewEdition = false;
Simulation[] newSimulations = newlySavedMathmodel.getSimulations();
Simulation correspondingSimulation = null;
for (int j = 0; j < newSimulations.length; j++) {
if (newSimulations[j].getName().equals(oldSimulation.getName())) {
correspondingSimulation = newSimulations[j];
if (correspondingSimulation.getKey().equals(oldSimulation.getKey())) {
//
// exactly same simulation (same key), so no lost data
//
bDataInNewEdition = true;
} else if (correspondingSimulation.getSimulationVersion().getParentSimulationReference() != null) {
//
// new simulation changed but points to same results
//
bDataInNewEdition = true;
}
break;
}
}
if (!bDataInNewEdition && correspondingSimulation != null) {
//
// result set (for "rsInfo") will be lost, should we ignore this fact?
//
boolean bIgnore = false;
//
// ignore if only Simulation has been edited (same MathDescription)
//
MathDescription mdCorr = correspondingSimulation.getMathDescription();
MathDescription mdOld = oldSimulation.getMathDescription();
if (mdCorr.getKey().equals(mdOld.getKey())) {
bIgnore = true;
}
//
for (int j = 0; submittedSimulations != null && j < submittedSimulations.length; j++) {
if (correspondingSimulation.getName().equals(submittedSimulations[j].getName())) {
bIgnore = true;
}
}
//
if (!bIgnore) {
lostResultsSimulationList.add(correspondingSimulation);
}
}
}
}
return (Simulation[]) BeanUtils.getArray(lostResultsSimulationList, Simulation.class);
}
use of cbit.vcell.solver.SimulationInfo 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());
}
}
}
Aggregations