use of cbit.vcell.solver.OutputTimeSpec in project vcell by virtualcell.
the class OutputOptionsPanel method refresh.
/**
* Comment
*/
private void refresh() {
if (solverTaskDescription == null) {
return;
}
// enables the panel where the output interval is set if the solver is IDA
// Otherwise, that panel is disabled.
getUniformOutputRadioButton().setEnabled(false);
BeanUtils.enableComponents(getUniformOutputPanel(), false);
if (solverTaskDescription.getSolverDescription().equals(SolverDescription.Smoldyn)) {
getDefaultOutputPanel().setVisible(false);
getDefaultOutputRadioButton().setVisible(false);
} else if (solverTaskDescription.getSolverDescription().isChomboSolver()) {
getDefaultOutputPanel().setVisible(false);
getDefaultOutputRadioButton().setVisible(false);
getUniformOutputPanel().setVisible(false);
getUniformOutputRadioButton().setVisible(false);
} else {
getDefaultOutputPanel().setVisible(true);
getDefaultOutputRadioButton().setVisible(true);
getDefaultOutputRadioButton().setEnabled(false);
getUniformOutputPanel().setVisible(true);
getUniformOutputRadioButton().setVisible(true);
BeanUtils.enableComponents(getDefaultOutputPanel(), false);
}
if (solverTaskDescription.getSimulation().getMathDescription().getGeometry().getDimension() > 0 || solverTaskDescription.getSimulation().getMathDescription().isNonSpatialStoch()) {
getExplicitOutputPanel().setVisible(false);
getExplicitOutputRadioButton().setVisible(false);
} else {
getExplicitOutputPanel().setVisible(true);
getExplicitOutputRadioButton().setVisible(true);
getExplicitOutputRadioButton().setEnabled(false);
BeanUtils.enableComponents(getExplicitOutputPanel(), false);
}
if (solverTaskDescription == null || solverTaskDescription.getSolverDescription() == null) {
// Also, disable its radiobutton and fields.
return;
}
SolverDescription solverDesc = solverTaskDescription.getSolverDescription();
// Amended June 2009, no output option for stochastic gibson multiple trials
if (solverTaskDescription.getStochOpt() != null && solverTaskDescription.getStochOpt().getNumOfTrials() > 1 && solverTaskDescription.getSolverDescription().equals(SolverDescription.StochGibson)) {
return;
}
OutputTimeSpec ots = solverTaskDescription.getOutputTimeSpec();
if (ots.isDefault()) {
// if solver is not IDA, if the output Time step radio button had been set,
// change the setting to the 'keep every' radio button and flush the contents of the output timestep text field.
// Also, disable its radiobutton and fields.
getDefaultOutputRadioButton().setSelected(true);
getKeepEveryTextField().setText(((DefaultOutputTimeSpec) ots).getKeepEvery() + "");
if (solverTaskDescription.getSolverDescription().isSemiImplicitPdeSolver()) {
getKeepAtMostTextField().setText("");
} else {
getKeepAtMostTextField().setText(((DefaultOutputTimeSpec) ots).getKeepAtMost() + "");
}
getOutputTimeStepTextField().setText("");
getOutputTimesTextField().setText("");
} else if (ots.isUniform()) {
getUniformOutputRadioButton().setSelected(true);
getKeepEveryTextField().setText("");
getKeepAtMostTextField().setText("");
getOutputTimeStepTextField().setText(((UniformOutputTimeSpec) ots).getOutputTimeStep() + "");
getOutputTimesTextField().setText("");
} else if (ots.isExplicit()) {
getExplicitOutputRadioButton().setSelected(true);
getKeepEveryTextField().setText("");
getKeepAtMostTextField().setText("");
getOutputTimeStepTextField().setText("");
getOutputTimesTextField().setText(((ExplicitOutputTimeSpec) ots).toCommaSeperatedOneLineOfString() + "");
getOutputTimesTextField().setCaretPosition(0);
}
DefaultOutputTimeSpec dots = new DefaultOutputTimeSpec();
UniformOutputTimeSpec uots = new UniformOutputTimeSpec(0.05);
ExplicitOutputTimeSpec eots = new ExplicitOutputTimeSpec(new double[] { 0.1 });
if (solverDesc.supports(dots)) {
if (!solverDesc.isSemiImplicitPdeSolver() || ots.isDefault()) {
getDefaultOutputRadioButton().setEnabled(true);
if (getDefaultOutputRadioButton().isSelected() || ots.isDefault()) {
BeanUtils.enableComponents(getDefaultOutputPanel(), true);
}
}
}
if (solverDesc.supports(uots)) {
getUniformOutputRadioButton().setEnabled(true);
if (getUniformOutputRadioButton().isSelected() || ots.isUniform()) {
BeanUtils.enableComponents(getUniformOutputPanel(), true);
}
}
if (solverDesc.supports(eots)) {
getExplicitOutputRadioButton().setEnabled(true);
if (getExplicitOutputRadioButton().isSelected() || ots.isExplicit()) {
BeanUtils.enableComponents(getExplicitOutputPanel(), true);
}
}
if (solverDesc.isSemiImplicitPdeSolver()) {
getKeepAtMostTextField().setText("");
getKeepAtMostTextField().setEnabled(false);
}
}
use of cbit.vcell.solver.OutputTimeSpec in project vcell by virtualcell.
the class TimeStepPanel method correctUniformOutputTimeStep.
public void correctUniformOutputTimeStep() {
boolean bValid = true;
double timeStep = Double.parseDouble(getDefaultTimeStepTextField().getText());
if (solverTaskDescription.getOutputTimeSpec().isUniform() && !solverTaskDescription.getSolverDescription().hasVariableTimestep()) {
OutputTimeSpec outputTimeSpec = solverTaskDescription.getOutputTimeSpec();
if (outputTimeSpec instanceof UniformOutputTimeSpec) {
UniformOutputTimeSpec uniformTimeSpec = (UniformOutputTimeSpec) outputTimeSpec;
double outputTime = uniformTimeSpec.getOutputTimeStep();
double suggestedInterval = outputTime;
if (outputTime < timeStep) {
suggestedInterval = timeStep;
bValid = false;
} else if (!BeanUtils.isIntegerMultiple(outputTime, timeStep)) {
double n = outputTime / timeStep;
int intn = (int) Math.round(n);
if (intn != n) {
bValid = false;
suggestedInterval = (intn * timeStep);
}
}
if (!bValid) {
String ret = PopupGenerator.showWarningDialog(TimeStepPanel.this, "Output Interval", "Output Interval must " + "be integer multiple of time step.\n\nChange Output Interval to " + suggestedInterval + "?", new String[] { UserMessage.OPTION_YES, UserMessage.OPTION_NO }, UserMessage.OPTION_YES);
if (ret.equals(UserMessage.OPTION_YES)) {
uniformTimeSpec.setOuputTimeStep(suggestedInterval);
bValid = true;
}
}
}
}
}
use of cbit.vcell.solver.OutputTimeSpec in project vcell by virtualcell.
the class FiniteVolumeFileWriter method writeSimulationParamters.
/**
* @param timeFunction
* @param startTime
* @param endTime
* @param rootFinder
* @param uniqueRootTimes
* @param bPrintIterations
* @throws ExpressionException
*
* for testing within scrapbook, see below:
*
* try {
* edu.northwestern.at.utils.math.rootfinders.MonadicFunctionRootFinder rootFinder =
*// new edu.northwestern.at.utils.math.rootfinders.Brent();
* new edu.northwestern.at.utils.math.rootfinders.Bisection();
*// new edu.northwestern.at.utils.math.rootfinders.NewtonRaphson();
*// new edu.northwestern.at.utils.math.rootfinders.Secant();
* cbit.vcell.parser.SimpleSymbolTable simpleSymbolTable = new cbit.vcell.parser.SimpleSymbolTable(new String[] { "t" });
*
* cbit.vcell.parser.Expression exp = new cbit.vcell.parser.Expression("t-0.56");
*
* exp.bindExpression(simpleSymbolTable);
* java.util.TreeSet<Double> rootTimes = new java.util.TreeSet<Double>();
* double startTime = 0.0;
* double endTime = 100.0;
* System.out.print("exp = '"+ exp.infix() + "'");
* long currentTimeMS = System.currentTimeMillis();
* cbit.vcell.solvers.FiniteVolumeFileWriter.findAllRoots(exp,startTime,endTime,rootFinder,rootTimes,false);
* long finalTimeMS = System.currentTimeMillis();
* for (double root : rootTimes){
* System.out.println("root = "+root);
* }
* System.out.println("elapsedTime of computation = "+(finalTimeMS-currentTimeMS)+" ms, found " + rootTimes.size() + " roots (not unique)");
*
*}catch (Exception e){
* e.printStackTrace(System.out);
*}
*/
/*public static void findAllRoots(Expression timeFunction, double startTime, double endTime, MonadicFunctionRootFinder rootFinder, TreeSet<Double> uniqueRootTimes, boolean bPrintIterations) throws ExpressionException{
TreeSet<Double> allRootTimes = new TreeSet<Double>();
final Expression function_exp = new Expression(timeFunction);
MonadicFunction valueFunction = new MonadicFunction() {
double[] values = new double[1];
public double f(double t) {
values[0] = t;
try {
return function_exp.evaluateVector(values);
} catch (ExpressionException e) {
e.printStackTrace();
throw new RuntimeException("expression exception "+e.getMessage());
}
}
};
final Expression derivative_exp = new Expression(timeFunction.differentiate(ReservedVariable.TIME.getName()));
MonadicFunction derivativeFunction = new MonadicFunction() {
double[] values = new double[1];
public double f(double t) {
values[0] = t;
try {
return derivative_exp.evaluateVector(values);
} catch (ExpressionException e) {
e.printStackTrace();
throw new RuntimeException("expression exception "+e.getMessage());
}
}
};
RootFinderConvergenceTest convergenceTest = new StandardRootFinderConvergenceTest();
RootFinderIterationInformation iterationInformation = null;
if (bPrintIterations){
iterationInformation = new RootFinderIterationInformation() {
public void iterationInformation(double x, double fx, double dfx, int currentIteration) {
System.out.println(currentIteration+") x="+x+", fx="+fx+", dfx="+dfx);
}
};
}
int NUM_BRACKETS = 1000;
double simulationTime = endTime - startTime;
double tolerance = simulationTime/1e10;
int maxIter = 1000;
for (int i=0;i<NUM_BRACKETS-1;i++){
double bracketMin = startTime + simulationTime*i/NUM_BRACKETS;
double bracketMax = startTime + simulationTime*(i+1)/NUM_BRACKETS;
double root = rootFinder.findRoot(bracketMin, bracketMax, tolerance, maxIter, valueFunction, derivativeFunction, convergenceTest, iterationInformation);
if (root>startTime && root<endTime && valueFunction.f(root)<=tolerance){
allRootTimes.add(root);
}
}
double uniqueTolerance = tolerance * 100;
double lastUniqueRoot = Double.NEGATIVE_INFINITY;
for (double root : allRootTimes){
if (root-lastUniqueRoot > uniqueTolerance){
uniqueRootTimes.add(root);
}
lastUniqueRoot = root;
}
} ---------------------------------JIM's CODE COMMENTTED FOR FUTURE DEVELOPMENT*/
/**
*# Simulation Parameters
*SIMULATION_PARAM_BEGIN
*SOLVER SUNDIALS_PDE_SOLVER 1.0E-7 1.0E-9
*DISCONTINUITY_TIMES 2 1.0E-4 3.0000000000000003E-4
*BASE_FILE_NAME c:/Vcell/users/fgao/SimID_31746636_0_
*ENDING_TIME 4.0E-4
*KEEP_EVERY ONE_STEP 3
*KEEP_AT_MOST 1000
*SIMULATION_PARAM_END
* @throws MathException
* @throws ExpressionException
*/
private void writeSimulationParamters() throws ExpressionException, MathException {
Simulation simulation = simTask.getSimulation();
SolverTaskDescription solverTaskDesc = simulation.getSolverTaskDescription();
printWriter.println("# Simulation Parameters");
printWriter.println(FVInputFileKeyword.SIMULATION_PARAM_BEGIN);
if (solverTaskDesc.getSolverDescription().equals(SolverDescription.SundialsPDE)) {
printWriter.print(FVInputFileKeyword.SOLVER + " " + FVInputFileKeyword.SUNDIALS_PDE_SOLVER + " " + solverTaskDesc.getErrorTolerance().getRelativeErrorTolerance() + " " + solverTaskDesc.getErrorTolerance().getAbsoluteErrorTolerance() + " " + solverTaskDesc.getTimeStep().getMaximumTimeStep());
if (simulation.getMathDescription().hasVelocity()) {
printWriter.print(" " + solverTaskDesc.getSundialsPdeSolverOptions().getMaxOrderAdvection());
}
printWriter.println();
Vector<Discontinuity> discontinuities = new Vector<Discontinuity>();
TreeSet<Double> discontinuityTimes = new TreeSet<Double>();
MathDescription mathDesc = simulation.getMathDescription();
Enumeration<SubDomain> enum1 = mathDesc.getSubDomains();
while (enum1.hasMoreElements()) {
SubDomain sd = enum1.nextElement();
Enumeration<Equation> enum_equ = sd.getEquations();
while (enum_equ.hasMoreElements()) {
Equation equation = enum_equ.nextElement();
equation.getDiscontinuities(simTask.getSimulationJob().getSimulationSymbolTable(), discontinuities);
}
}
getDiscontinuityTimes(discontinuities, discontinuityTimes);
if (discontinuityTimes.size() > 0) {
printWriter.print(FVInputFileKeyword.DISCONTINUITY_TIMES + " " + discontinuityTimes.size());
for (double d : discontinuityTimes) {
printWriter.print(" " + d);
}
printWriter.println();
}
} else if (solverTaskDesc.getSolverDescription().equals(SolverDescription.Chombo)) {
printWriter.println(FVInputFileKeyword.SOLVER + " " + FVInputFileKeyword.CHOMBO_SEMIIMPLICIT_SOLVER);
} else if (solverTaskDesc.getSolverDescription().equals(SolverDescription.VCellPetsc)) {
printWriter.println(FVInputFileKeyword.SOLVER + " " + FVInputFileKeyword.VCELL_PETSC_SOLVER);
} else {
printWriter.println(FVInputFileKeyword.SOLVER + " " + FVInputFileKeyword.FV_SOLVER + " " + solverTaskDesc.getErrorTolerance().getRelativeErrorTolerance());
}
printWriter.println(FVInputFileKeyword.BASE_FILE_NAME + " " + new File(workingDirectory, simTask.getSimulationJob().getSimulationJobID()).getAbsolutePath());
if (solverTaskDesc.isParallel() && destinationDirectory != null && !destinationDirectory.equals(workingDirectory)) {
printWriter.println(FVInputFileKeyword.PRIMARY_DATA_DIR + " " + destinationDirectory.getAbsolutePath());
}
printWriter.println(FVInputFileKeyword.ENDING_TIME + " " + solverTaskDesc.getTimeBounds().getEndingTime());
OutputTimeSpec outputTimeSpec = solverTaskDesc.getOutputTimeSpec();
if (solverTaskDesc.getSolverDescription().isChomboSolver()) {
List<TimeInterval> timeIntervalList = solverTaskDesc.getChomboSolverSpec().getTimeIntervalList();
printWriter.println(FVInputFileKeyword.TIME_INTERVALS + " " + timeIntervalList.size());
for (TimeInterval ti : timeIntervalList) {
printWriter.println(ti.getEndingTime() + " " + ti.getTimeStep() + " " + ti.getKeepEvery());
}
} else if (solverTaskDesc.getSolverDescription().equals(SolverDescription.SundialsPDE)) {
if (outputTimeSpec.isDefault()) {
DefaultOutputTimeSpec defaultOutputTimeSpec = (DefaultOutputTimeSpec) outputTimeSpec;
printWriter.println(FVInputFileKeyword.KEEP_EVERY + " " + FVInputFileKeyword.ONE_STEP + " " + defaultOutputTimeSpec.getKeepEvery());
printWriter.println(FVInputFileKeyword.KEEP_AT_MOST + " " + defaultOutputTimeSpec.getKeepAtMost());
} else {
printWriter.println(FVInputFileKeyword.TIME_STEP + " " + ((UniformOutputTimeSpec) outputTimeSpec).getOutputTimeStep());
printWriter.println(FVInputFileKeyword.KEEP_EVERY + " 1");
}
} else {
double defaultTimeStep = solverTaskDesc.getTimeStep().getDefaultTimeStep();
printWriter.println(FVInputFileKeyword.TIME_STEP + " " + defaultTimeStep);
int keepEvery = 1;
if (outputTimeSpec.isDefault()) {
keepEvery = ((DefaultOutputTimeSpec) outputTimeSpec).getKeepEvery();
} else if (outputTimeSpec.isUniform()) {
UniformOutputTimeSpec uots = (UniformOutputTimeSpec) outputTimeSpec;
double ots = uots.getOutputTimeStep();
keepEvery = (int) Math.round(ots / defaultTimeStep);
} else {
throw new RuntimeException("unexpected OutputTime specification type :" + outputTimeSpec.getClass().getName());
}
if (keepEvery <= 0) {
throw new RuntimeException("Output KeepEvery must be a positive integer. Try to change the output option.");
}
printWriter.println(FVInputFileKeyword.KEEP_EVERY + " " + keepEvery);
}
ErrorTolerance stopAtSpatiallyUniformErrorTolerance = solverTaskDesc.getStopAtSpatiallyUniformErrorTolerance();
if (stopAtSpatiallyUniformErrorTolerance != null) {
printWriter.println(FVInputFileKeyword.CHECK_SPATIALLY_UNIFORM + " " + stopAtSpatiallyUniformErrorTolerance.getAbsoluteErrorTolerance() + " " + stopAtSpatiallyUniformErrorTolerance.getRelativeErrorTolerance());
}
printWriter.println(FVInputFileKeyword.SIMULATION_PARAM_END);
printWriter.println();
}
use of cbit.vcell.solver.OutputTimeSpec in project vcell by virtualcell.
the class ITextWriter method writeSimulation.
// container can be a chapter or a section of a chapter.
protected void writeSimulation(Section container, Simulation sim) throws DocumentException {
if (sim == null) {
return;
}
Section simSection = container.addSection(sim.getName(), container.numberDepth() + 1);
writeMetadata(simSection, sim.getName(), sim.getDescription(), null, "Simulation ");
// add overriden params
Table overParamTable = null;
MathOverrides mo = sim.getMathOverrides();
if (mo != null) {
String[] constants = mo.getOverridenConstantNames();
for (int i = 0; i < constants.length; i++) {
String actualStr = "", defStr = "";
Expression tempExp = mo.getDefaultExpression(constants[i]);
if (tempExp != null) {
defStr = tempExp.infix();
}
if (mo.isScan(constants[i])) {
actualStr = mo.getConstantArraySpec(constants[i]).toString();
} else {
tempExp = mo.getActualExpression(constants[i], 0);
if (tempExp != null) {
actualStr = tempExp.infix();
}
}
if (overParamTable == null) {
overParamTable = getTable(3, 75, 1, 3, 3);
overParamTable.setAlignment(Table.ALIGN_LEFT);
overParamTable.addCell(createCell("Overriden Parameters", getBold(DEF_HEADER_FONT_SIZE), 3, 1, Element.ALIGN_CENTER, true));
overParamTable.addCell(createHeaderCell("Name", getBold(), 1));
overParamTable.addCell(createHeaderCell("Actual Value", getBold(), 1));
overParamTable.addCell(createHeaderCell("Default Value", getBold(), 1));
}
overParamTable.addCell(createCell(constants[i], getFont()));
overParamTable.addCell(createCell(actualStr, getFont()));
overParamTable.addCell(createCell(defStr, getFont()));
}
}
if (overParamTable != null) {
simSection.add(overParamTable);
}
// add spatial details
// sim.isSpatial();
Table meshTable = null;
MeshSpecification mesh = sim.getMeshSpecification();
if (mesh != null) {
Geometry geom = mesh.getGeometry();
Extent extent = geom.getExtent();
String extentStr = "(" + extent.getX() + ", " + extent.getY() + ", " + extent.getZ() + ")";
ISize meshSize = mesh.getSamplingSize();
String meshSizeStr = "(" + meshSize.getX() + ", " + meshSize.getY() + ", " + meshSize.getZ() + ")";
meshTable = getTable(2, 75, 1, 3, 3);
meshTable.setAlignment(Table.ALIGN_LEFT);
meshTable.addCell(createCell("Geometry Setting", getBold(DEF_HEADER_FONT_SIZE), 2, 1, Element.ALIGN_CENTER, true));
meshTable.addCell(createCell("Geometry Size (um)", getFont()));
meshTable.addCell(createCell(extentStr, getFont()));
meshTable.addCell(createCell("Mesh Size (elements)", getFont()));
meshTable.addCell(createCell(meshSizeStr, getFont()));
}
if (meshTable != null) {
simSection.add(meshTable);
}
// write advanced sim settings
Table simAdvTable = null;
SolverTaskDescription solverDesc = sim.getSolverTaskDescription();
if (solverDesc != null) {
String solverName = solverDesc.getSolverDescription().getDisplayLabel();
simAdvTable = getTable(2, 75, 1, 3, 3);
simAdvTable.setAlignment(Table.ALIGN_LEFT);
simAdvTable.addCell(createCell("Advanced Settings", getBold(DEF_HEADER_FONT_SIZE), 2, 1, Element.ALIGN_CENTER, true));
simAdvTable.addCell(createCell("Solver Name", getFont()));
simAdvTable.addCell(createCell(solverName, getFont()));
simAdvTable.addCell(createCell("Time Bounds - Starting", getFont()));
simAdvTable.addCell(createCell("" + solverDesc.getTimeBounds().getStartingTime(), getFont()));
simAdvTable.addCell(createCell("Time Bounds - Ending", getFont()));
simAdvTable.addCell(createCell("" + solverDesc.getTimeBounds().getEndingTime(), getFont()));
simAdvTable.addCell(createCell("Time Step - Min", getFont()));
simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getMinimumTimeStep(), getFont()));
simAdvTable.addCell(createCell("Time Step - Default", getFont()));
simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getDefaultTimeStep(), getFont()));
simAdvTable.addCell(createCell("Time Step - Max", getFont()));
simAdvTable.addCell(createCell("" + solverDesc.getTimeStep().getMaximumTimeStep(), getFont()));
ErrorTolerance et = solverDesc.getErrorTolerance();
if (et != null) {
simAdvTable.addCell(createCell("Error Tolerance - Absolute", getFont()));
simAdvTable.addCell(createCell("" + et.getAbsoluteErrorTolerance(), getFont()));
simAdvTable.addCell(createCell("Error Tolerance - Relative", getFont()));
simAdvTable.addCell(createCell("" + et.getRelativeErrorTolerance(), getFont()));
}
OutputTimeSpec ots = solverDesc.getOutputTimeSpec();
if (ots.isDefault()) {
simAdvTable.addCell(createCell("Keep Every", getFont()));
simAdvTable.addCell(createCell("" + ((DefaultOutputTimeSpec) ots).getKeepEvery(), getFont()));
simAdvTable.addCell(createCell("Keep At Most", getFont()));
simAdvTable.addCell(createCell("" + ((DefaultOutputTimeSpec) ots).getKeepAtMost(), getFont()));
} else if (ots.isUniform()) {
simAdvTable.addCell(createCell("Output Time Step", getFont()));
simAdvTable.addCell(createCell("" + ((UniformOutputTimeSpec) ots).getOutputTimeStep(), getFont()));
} else if (ots.isExplicit()) {
simAdvTable.addCell(createCell("Output Time Points", getFont()));
simAdvTable.addCell(createCell("" + ((ExplicitOutputTimeSpec) ots).toCommaSeperatedOneLineOfString(), getFont()));
}
simAdvTable.addCell(createCell("Use Symbolic Jacobian (T/F)", getFont()));
simAdvTable.addCell(createCell((solverDesc.getUseSymbolicJacobian() ? " T " : " F "), getFont()));
Constant sp = solverDesc.getSensitivityParameter();
if (sp != null) {
simAdvTable.addCell(createCell("Sensitivity Analysis Param", getFont()));
simAdvTable.addCell(createCell(sp.getName(), getFont()));
}
}
if (simAdvTable != null) {
simSection.add(simAdvTable);
}
}
use of cbit.vcell.solver.OutputTimeSpec in project vcell by virtualcell.
the class AbstractJavaSolver method printToFile.
/**
* Insert the method's description here.
* Creation date: (6/27/2001 12:17:36 PM)
*/
protected final void printToFile(double progress) throws IOException {
long currentTime = System.currentTimeMillis();
// decide whether to fire progress event
boolean shouldFire = false;
if (progress <= 0 || progress >= 1) {
// always fire at begin and end
shouldFire = true;
} else {
// only fire at specified increment
shouldFire = (progress - lastFiredProgress) * 100 > getProgressIncrement();
}
if (shouldFire) {
lastFiredProgress = progress;
fireSolverProgress(progress);
}
// decide whether to save to file
boolean shouldSave = false;
// only if enabled
if (isSaveEnabled()) {
// check to see whether we need to save
if (progress <= 0) {
// a new run just got initialized; save 0 datapoint
shouldSave = true;
} else if (progress >= 1) {
// a run finished; save last datapoint
shouldSave = true;
} else {
// in the middle of a run; only save at specified time interval
shouldSave = currentTime - lastSavedMS > 1000 * getSaveToFileInterval();
}
if (shouldSave) {
// write file and fire event
if (this instanceof ODESolver) {
ODESolverResultSet odeSolverResultSet = ((ODESolver) this).getODESolverResultSet();
Simulation simulation = simTask.getSimulationJob().getSimulation();
OutputTimeSpec outputTimeSpec = simulation.getSolverTaskDescription().getOutputTimeSpec();
if (outputTimeSpec.isDefault()) {
odeSolverResultSet.trimRows(((DefaultOutputTimeSpec) outputTimeSpec).getKeepAtMost());
}
ODESimData odeSimData = new ODESimData(new VCSimulationDataIdentifier(simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), getJobIndex()), odeSolverResultSet);
String mathName = odeSimData.getMathName();
if (lg.isTraceEnabled())
lg.trace("AbstractJavaSolver.printToFile(" + mathName + ")");
File logFile = new File(getBaseName() + LOGFILE_EXTENSION);
File dataFile = new File(getBaseName() + ODE_DATA_EXTENSION);
ODESimData.writeODEDataFile(odeSimData, dataFile);
odeSimData.writeODELogFile(logFile, dataFile);
}
lastSavedMS = System.currentTimeMillis();
fireSolverPrinted(getCurrentTime());
}
}
}
Aggregations