use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class DefaultODESolver method initialize.
/**
* This method was created by a SmartGuide.
* @exception SolverException The exception description.
*/
protected void initialize() throws SolverException {
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
Simulation sim = simSymbolTable.getSimulation();
try {
// create a fast system if necessary
fieldFastAlgebraicSystem = null;
if (getSubDomain().getFastSystem() != null) {
fieldFastAlgebraicSystem = new FastAlgebraicSystem(new FastSystemAnalyzer(getSubDomain().getFastSystem(), simSymbolTable));
}
// refreshIdentifiers();
fieldIdentifiers = createIdentifiers();
fieldSensVariables = createSensitivityVariables();
// refreshStateVariables();
fieldStateVariables = createStateVariables();
//
// allocate ValueVectors object
fieldValueVectors = new ValueVectors(getValueVectorCount(), fieldIdentifiers.size());
// initialize indexes of variables
fieldVariableIndexes = new int[getStateVariableCount()];
for (int i = 0; i < getStateVariableCount(); i++) {
fieldVariableIndexes[i] = getStateVariable(i).getVariable().getIndex();
}
// initialize constants
double[] initialValues = getValueVector(0);
for (int i = 0; i < fieldIdentifiers.size(); i++) {
if (fieldIdentifiers.elementAt(i) instanceof Constant) {
Constant constant = (Constant) fieldIdentifiers.elementAt(i);
constant.bind(simSymbolTable);
if (constant.isConstant()) {
// constant.getValue();
initialValues[constant.getIndex()] = constant.getExpression().evaluateConstant();
} else {
throw new SolverException("cannot evaluate constant '" + constant.getName() + "' = " + constant.getExpression());
}
}
}
// initialize variables
for (int i = 0; i < getStateVariableCount(); i++) {
initialValues[getVariableIndex(i)] = getStateVariable(i).evaluateIC(initialValues);
}
fieldODESolverResultSet = createODESolverResultSet();
// reset - in the ** default ** solvers we don't pick up from where we left off, we can override that behaviour in integrate() if ever necessary
fieldCurrentTime = sim.getSolverTaskDescription().getTimeBounds().getStartingTime();
} catch (ExpressionException expressionException) {
expressionException.printStackTrace(System.out);
throw new SolverException(expressionException.getMessage());
} catch (MathException mathException) {
mathException.printStackTrace(System.out);
throw new SolverException(mathException.getMessage());
}
}
use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class IDASolverStandalone method initialize.
/**
* This method takes the place of the old runUnsteady()...
*/
protected void initialize() throws SolverException {
fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_INIT);
super.initialize();
String inputFilename = getInputFilename();
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);
IDAFileWriter idaFileWriter = new IDAFileWriter(pw, simTask, bMessaging);
idaFileWriter.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("IDA solver could not generate input file: " + e.getMessage());
} finally {
if (pw != null) {
pw.close();
}
}
setSolverStatus(new SolverStatus(SolverStatus.SOLVER_RUNNING, SimulationMessage.MESSAGE_SOLVER_RUNNING_START));
setMathExecutable(new MathExecutable(getMathExecutableCommand(), getSaveDirectory()));
}
use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class SundialsSolver method writeLogFile.
private void writeLogFile() throws SolverException {
String logFile = getBaseName() + LOGFILE_EXTENSION;
String ideDataFileName = new File(getBaseName() + IDA_DATA_EXTENSION).getName();
PrintWriter pw = null;
try {
pw = new PrintWriter(logFile);
pw.println(IDA_DATA_IDENTIFIER);
pw.println(IDA_DATA_FORMAT_ID);
pw.println(ideDataFileName);
OutputTimeSpec outputTimeSpec = simTask.getSimulation().getSolverTaskDescription().getOutputTimeSpec();
if (outputTimeSpec.isDefault()) {
pw.println(KEEP_MOST + " " + ((DefaultOutputTimeSpec) outputTimeSpec).getKeepAtMost());
}
pw.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
throw new SolverException(e.getMessage());
} finally {
if (pw != null) {
pw.close();
}
}
}
use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class SolverFactory method createSolver.
public static Solver createSolver(File userDir, File parallelDir, SimulationTask simTask, boolean bMessaging) throws SolverException {
SolverDescription solverDescription = simTask.getSimulationJob().getSimulation().getSolverTaskDescription().getSolverDescription();
File simTaskFile = new File(userDir, simTask.getSimulationJobID() + "_" + simTask.getTaskID() + ".simtask.xml");
if (userDir.exists() && !simTaskFile.exists()) {
try {
String simTaskXmlText = XmlHelper.simTaskToXML(simTask);
XmlUtil.writeXMLStringToFile(simTaskXmlText, simTaskFile.toString(), true);
} catch (Exception e) {
e.printStackTrace(System.out);
throw new SolverException("unable to write SimulationTask file");
}
}
if (solverDescription == null) {
throw new IllegalArgumentException("SolverDescription cannot be null");
}
Maker maker = FACTORY.get(solverDescription);
if (maker != null) {
Solver s = maker.make(simTask, userDir, parallelDir, bMessaging);
return s;
}
throw new SolverException("Unknown solver: " + solverDescription);
}
use of cbit.vcell.solver.SolverException in project vcell by virtualcell.
the class RungeKuttaFehlbergSolver method step.
/**
* Integrate over time step using the forward Euler method (1st order explicit)
* results must be stored in NumVectors-1 = vector(4);
* t is the current time
* h is the time step
*/
protected void step(double t, double h) throws SolverException {
try {
double[] oldValues = getValueVector(0);
double[] newValues = getValueVector(1);
//
// update time
oldValues[getTimeIndex()] = t;
//
for (int i = 0; i < 6; i++) {
newValues[getTimeIndex()] = t + a[i] * h;
for (int j = 0; j < getStateVariableCount(); j++) {
int J = getVariableIndex(j);
newValues[J] = oldValues[J];
for (int m = 0; m < i; m++) {
newValues[J] += b[i][m] * k[m][J];
}
}
for (int j = 0; j < getStateVariableCount(); j++) {
k[i][getVariableIndex(j)] = h * evaluate(newValues, j);
}
}
for (int i = 0; i < getStateVariableCount(); i++) {
int I = getVariableIndex(i);
newValues[I] = oldValues[I];
for (int j = 0; j < 6; j++) {
newValues[I] += c[j] * k[j][I];
}
}
} catch (ExpressionException expressionException) {
throw new SolverException(expressionException.getMessage());
}
}
Aggregations