use of cbit.vcell.solver.ExplicitOutputTimeSpec 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.ExplicitOutputTimeSpec in project vcell by virtualcell.
the class OutputOptionsPanel method actionOutputOptionButtonState.
private void actionOutputOptionButtonState(java.awt.event.ActionEvent actionEvent) {
try {
if (solverTaskDescription == null) {
return;
}
OutputTimeSpec outputTimeSpec = solverTaskDescription.getOutputTimeSpec();
if (actionEvent.getSource() == getDefaultOutputRadioButton() && !outputTimeSpec.isDefault()) {
solverTaskDescription.setOutputTimeSpec(new DefaultOutputTimeSpec());
} else if (actionEvent.getSource() == getUniformOutputRadioButton() && !outputTimeSpec.isUniform()) {
double outputTime = 0.0;
if (solverTaskDescription.getSolverDescription().isSemiImplicitPdeSolver()) {
String floatStr = "" + (float) (((DefaultOutputTimeSpec) outputTimeSpec).getKeepEvery() * solverTaskDescription.getTimeStep().getDefaultTimeStep());
outputTime = Double.parseDouble(floatStr);
} else {
TimeBounds timeBounds = solverTaskDescription.getTimeBounds();
Range outputTimeRange = NumberUtils.getDecimalRange(timeBounds.getStartingTime(), timeBounds.getEndingTime() / 100, true, true);
outputTime = outputTimeRange.getMax();
}
solverTaskDescription.setOutputTimeSpec(new UniformOutputTimeSpec(outputTime));
} else if (actionEvent.getSource() == getExplicitOutputRadioButton() && !outputTimeSpec.isExplicit()) {
TimeBounds timeBounds = solverTaskDescription.getTimeBounds();
solverTaskDescription.setOutputTimeSpec(new ExplicitOutputTimeSpec(new double[] { timeBounds.getStartingTime(), timeBounds.getEndingTime() }));
}
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.solver.ExplicitOutputTimeSpec in project vcell by virtualcell.
the class SimulationListTableModel method setValueAt.
/**
* Insert the method's description here.
* Creation date: (7/12/2004 2:01:23 PM)
* @param aValue java.lang.Object
* @param rowIndex int
* @param columnIndex int
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
Simulation simulation = getValueAt(rowIndex);
try {
switch(columnIndex) {
case COLUMN_NAME:
if (aValue instanceof String) {
String newName = (String) aValue;
if (!simulation.getName().equals(newName)) {
simulation.setName(newName);
}
}
break;
case COLUMN_ENDTIME:
if (aValue instanceof Double) {
SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
double newEndTime = (Double) aValue;
if (newEndTime != solverTaskDescription.getTimeBounds().getEndingTime()) {
ClientTaskManager.changeEndTime(ownerTable, solverTaskDescription, newEndTime);
simulation.setIsDirty(true);
}
}
break;
case COLUMN_OUTPUT:
if (aValue instanceof String) {
SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
OutputTimeSpec ots = solverTaskDescription.getOutputTimeSpec();
OutputTimeSpec newOts = null;
if (ots instanceof DefaultOutputTimeSpec) {
int newValue = Integer.parseInt((String) aValue);
newOts = new DefaultOutputTimeSpec(newValue, ((DefaultOutputTimeSpec) ots).getKeepAtMost());
} else if (ots instanceof UniformOutputTimeSpec) {
try {
boolean bValid = true;
double outputTime = Double.parseDouble((String) aValue);
if (solverTaskDescription.getOutputTimeSpec().isUniform()) {
if (solverTaskDescription.getSolverDescription().hasVariableTimestep()) {
newOts = new UniformOutputTimeSpec(outputTime);
} else {
double timeStep = solverTaskDescription.getTimeStep().getDefaultTimeStep();
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);
suggestedInterval = (intn * timeStep);
if (suggestedInterval != outputTime) {
bValid = false;
}
}
}
if (bValid) {
newOts = new UniformOutputTimeSpec(outputTime);
} else {
String ret = PopupGenerator.showWarningDialog(ownerTable, "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)) {
newOts = new UniformOutputTimeSpec(suggestedInterval);
}
}
}
}
} catch (NumberFormatException ex) {
DialogUtils.showErrorDialog(ownerTable, "Wrong number format " + ex.getMessage().toLowerCase());
}
} else if (ots instanceof ExplicitOutputTimeSpec) {
newOts = ExplicitOutputTimeSpec.fromString((String) aValue);
}
if (newOts != null && !newOts.compareEqual(ots)) {
solverTaskDescription.setOutputTimeSpec(newOts);
simulation.setIsDirty(true);
}
}
break;
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
}
}
use of cbit.vcell.solver.ExplicitOutputTimeSpec in project vcell by virtualcell.
the class OdeFileWriter method write.
/**
* Insert the method's description here.
* Creation date: (3/8/00 10:31:52 PM)
*/
public void write(String[] parameterNames) throws Exception {
createStateVariables();
createSymbolTable();
Simulation simulation = simTask.getSimulation();
if (simulation.getSolverTaskDescription().getUseSymbolicJacobian()) {
throw new RuntimeException("symbolic jacobian option not yet supported in interpreted Stiff solver");
}
writeJMSParamters();
SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
TimeBounds timeBounds = solverTaskDescription.getTimeBounds();
ErrorTolerance errorTolerance = solverTaskDescription.getErrorTolerance();
printWriter.println("SOLVER " + getSolverName());
printWriter.println("STARTING_TIME " + timeBounds.getStartingTime());
printWriter.println("ENDING_TIME " + timeBounds.getEndingTime());
printWriter.println("RELATIVE_TOLERANCE " + errorTolerance.getRelativeErrorTolerance());
printWriter.println("ABSOLUTE_TOLERANCE " + errorTolerance.getAbsoluteErrorTolerance());
printWriter.println("MAX_TIME_STEP " + simulation.getSolverTaskDescription().getTimeStep().getMaximumTimeStep());
OutputTimeSpec ots = simulation.getSolverTaskDescription().getOutputTimeSpec();
if (ots.isDefault()) {
printWriter.println("KEEP_EVERY " + ((DefaultOutputTimeSpec) ots).getKeepEvery());
} else if (ots.isUniform()) {
printWriter.println("OUTPUT_TIME_STEP " + ((UniformOutputTimeSpec) ots).getOutputTimeStep());
} else if (ots.isExplicit()) {
printWriter.println("OUTPUT_TIMES " + ((ExplicitOutputTimeSpec) ots).getNumTimePoints());
printWriter.println(((ExplicitOutputTimeSpec) ots).toSpaceSeperatedMultiLinesOfString());
}
if (parameterNames != null && parameterNames.length != 0) {
printWriter.println("NUM_PARAMETERS " + parameterNames.length);
for (int i = 0; i < parameterNames.length; i++) {
printWriter.println(parameterNames[i]);
}
}
HashMap<Discontinuity, String> discontinuityNameMap = new HashMap<Discontinuity, String>();
String eventString = null;
if (simulation.getMathDescription().hasEvents()) {
eventString = writeEvents(discontinuityNameMap);
}
String equationString = writeEquations(discontinuityNameMap);
if (discontinuityNameMap.size() > 0) {
printWriter.println("DISCONTINUITIES " + discontinuityNameMap.size());
for (Discontinuity od : discontinuityNameMap.keySet()) {
printWriter.println(discontinuityNameMap.get(od) + " " + od.getDiscontinuityExp().flatten().infix() + "; " + od.getRootFindingExp().flatten().infix() + ";");
}
}
if (eventString != null) {
printWriter.print(eventString);
}
printWriter.println("NUM_EQUATIONS " + getStateVariableCount());
printWriter.println(equationString);
}
Aggregations