use of cbit.vcell.solver.server.SolverStatus in project vcell by virtualcell.
the class ComsolSolver method startSolver.
@Override
public void startSolver() {
try {
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_STARTING, SimulationMessage.MESSAGE_SOLVER_STARTING_INIT));
initialize();
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING);
String filePrefix = simTask.getSimulationJob().getSimulationJobID();
try {
comsolService.connectComsol();
File reportFile = new File(getSaveDirectory(), filePrefix + ".comsoldat");
File javaFile = new File(getSaveDirectory(), filePrefix + ".java");
File mphFile = new File(getSaveDirectory(), filePrefix + ".mph");
comsolService.solve(this.vccModel, reportFile, javaFile, mphFile);
} finally {
comsolService.disconnectComsol();
}
File logFile = new File(getSaveDirectory(), filePrefix + ".log");
FileUtils.writeStringToFile(logFile, createLogFileContents(simTask.getSimulation().getSolverTaskDescription()));
VisMesh visMesh = new VisMesh();
File reportFile = new File(getSaveDirectory(), filePrefix + ".comsoldat");
ComsolMeshReader.read(visMesh, reportFile);
time = simTask.getSimulation().getSolverTaskDescription().getTimeBounds().getEndingTime();
progress = 1.0;
fireSolverPrinted(time);
fireSolverProgress(progress);
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_FINISHED, SimulationMessage.MESSAGE_SOLVER_FINISHED));
fireSolverFinished();
} catch (Exception e) {
e.printStackTrace(System.out);
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted(e.getMessage())));
fireSolverAborted(SimulationMessage.solverAborted(e.getMessage()));
}
}
use of cbit.vcell.solver.server.SolverStatus in project vcell by virtualcell.
the class SmoldynSolver method initialize.
/**
* This method takes the place of the old runUnsteady()...
*/
protected void initialize() throws SolverException {
if (lg.isTraceEnabled())
lg.trace("SmoldynSolver.initialize()");
fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
writeFunctionsFile();
// write subdomains file
try {
SubdomainInfo.write(new File(getBaseName() + SimDataConstants.SUBDOMAINS_FILE_SUFFIX), simTask.getSimulation().getMathDescription());
} catch (IOException e1) {
e1.printStackTrace();
throw new SolverException(e1.getMessage());
} catch (MathException e1) {
e1.printStackTrace();
throw new SolverException(e1.getMessage());
}
String inputFilename = getInputFilename();
if (lg.isTraceEnabled())
lg.trace("SmoldynSolver.initialize() baseName = " + getBaseName());
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_INPUT_FILE));
fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INPUT_FILE);
PrintWriter pw = null;
try {
pw = new PrintWriter(inputFilename);
if (SystemUtils.IS_OS_WINDOWS) {
//
// the windows executable is compiled under cygwin (or mingw) and expect Unix style line termination characters.
// so SmoldynInput file is written with platform default Java convention (different on windows) to a String.
// Then the string is translated to Unix style before written to the file.
// smoldyn is particularly sensitive to this issue, other compiled solvers are more tolerant.
//
StringWriter stringWriter = new StringWriter();
PrintWriter pw2 = new PrintWriter(stringWriter);
SmoldynFileWriter stFileWriter = new SmoldynFileWriter(pw2, false, getBaseName(), simTask, bMessaging);
stFileWriter.write();
String fileContents = stringWriter.getBuffer().toString();
fileContents = fileContents.replace("\r\n", "\n");
pw.write(fileContents);
} else {
//
// for linux or macos, no translation is necessary.
//
SmoldynFileWriter stFileWriter = new SmoldynFileWriter(pw, false, getBaseName(), simTask, bMessaging);
stFileWriter.write();
}
} catch (Exception e) {
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not generate input file: " + e.getMessage())));
e.printStackTrace(System.out);
throw new SolverException(e.getMessage());
} finally {
if (pw != null) {
pw.close();
}
}
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
// get executable path+name.
setMathExecutable(new MathExecutable(getMathExecutableCommand(), getSaveDirectory()));
// setMathExecutable(new cbit.vcell.solvers.MathExecutable(executableName + " gibson " + getBaseName() + ".stochInput" + " " + getBaseName() + ".stoch"));
}
use of cbit.vcell.solver.server.SolverStatus 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.solver.server.SolverStatus in project vcell by virtualcell.
the class AbstractCompiledSolver method runSolver.
/**
* Insert the method's description here.
* Creation date: (6/26/2001 3:08:31 PM)
*/
public void runSolver() {
try {
setCurrentTime(simTask.getSimulationJob().getSimulation().getSolverTaskDescription().getTimeBounds().getStartingTime());
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_STARTING, SimulationMessage.MESSAGE_SOLVER_STARTING_INIT));
// fireSolverStarting("initializing");
// depends on solver; the initialize() method in actual solver will fire detailed messages
initialize();
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING);
if (OperatingSystemInfo.getInstance().isLinux()) {
final String LD_LIB_PATH = "LD_LIBRARY_PATH";
File solversDir = ResourceUtil.getLocalSolversDirectory();
String existingLD_LIB_PATH = null;
Map<String, String> envMap = System.getenv();
Iterator<String> envIter = envMap.keySet().iterator();
while (envIter.hasNext()) {
String key = envIter.next();
String val = envMap.get(key).toString();
// System.out.println(key+"\n "+val);
if (key.equals(LD_LIB_PATH)) {
existingLD_LIB_PATH = val;
if (existingLD_LIB_PATH != null && existingLD_LIB_PATH.length() > 0 && !existingLD_LIB_PATH.endsWith(":")) {
existingLD_LIB_PATH += ":";
}
break;
}
}
String newLD_LIB_PATH = (existingLD_LIB_PATH == null ? "" : existingLD_LIB_PATH) + solversDir.getAbsolutePath();
System.out.println("-----Setting executable " + LD_LIB_PATH + " to " + newLD_LIB_PATH);
getMathExecutable().addEnvironmentVariable(LD_LIB_PATH, newLD_LIB_PATH);
}
getMathExecutable().start();
cleanup();
// getMathExecutable().start() may end prematurely (error or user stop), so check status before firing...
if (getMathExecutable().getStatus().equals(org.vcell.util.exe.ExecutableStatus.COMPLETE)) {
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_FINISHED, SimulationMessage.MESSAGE_SOLVER_FINISHED));
fireSolverFinished();
}
} catch (SolverException integratorException) {
lg.error(integratorException.getMessage(), integratorException);
cleanup();
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted(integratorException.getMessage())));
fireSolverAborted(SimulationMessage.solverAborted(integratorException.getMessage()));
} catch (org.vcell.util.exe.ExecutableException executableException) {
lg.error(executableException.getMessage(), executableException);
cleanup();
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted("Could not execute code: " + executableException.getMessage())));
fireSolverAborted(SimulationMessage.solverAborted(executableException.getMessage()));
} catch (Exception exception) {
if (lg.isWarnEnabled())
lg.warn("AbstractODESolver.start() : Caught Throwable instead of SolverException -- THIS EXCEPTION SHOULD NOT HAPPEN!");
lg.error(exception.getMessage(), exception);
cleanup();
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_ABORTED, SimulationMessage.solverAborted(exception.getMessage())));
fireSolverAborted(SimulationMessage.solverAborted(exception.getMessage()));
} finally {
synchronized (this) {
fieldThread = null;
}
}
}
use of cbit.vcell.solver.server.SolverStatus in project vcell by virtualcell.
the class AbstractCompiledSolver method stopSolver.
/**
*/
public final synchronized void stopSolver() {
if (fieldThread != null && getMathExecutable() != null) {
fieldThread.interrupt();
getMathExecutable().stop();
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_STOPPED, SimulationMessage.MESSAGE_SOLVER_STOPPED_BY_USER));
fireSolverStopped();
}
}
Aggregations