use of cbit.vcell.solver.ErrorTolerance in project vcell by virtualcell.
the class SimulationSummaryPanel method displayTask.
/**
* Comment
*/
private void displayTask() {
SolverTaskDescription solverTaskDescription = getSimulation().getSolverTaskDescription();
try {
NonspatialStochSimOptions stochOpt = solverTaskDescription.getStochOpt();
if (stochOpt != null && stochOpt.getNumOfTrials() > 1) {
getJLabelOutput().setText("Histogram with " + stochOpt.getNumOfTrials() + " Trials(@last time point)");
} else {
// gcwtodo
String text = solverTaskDescription.getOutputTimeSpec().getShortDescription();
if (solverTaskDescription.getSolverDescription().isChomboSolver()) {
text = "Variable";
if (solverTaskDescription.getChomboSolverSpec().getTimeIntervalList().size() == 1) {
text = "Every " + solverTaskDescription.getChomboSolverSpec().getLastTimeInterval().getOutputTimeStep() + "s";
}
} else if (solverTaskDescription.getOutputTimeSpec().isDefault() && !solverTaskDescription.getSolverDescription().isSemiImplicitPdeSolver() && !solverTaskDescription.getSolverDescription().equals(SolverDescription.StochGibson)) {
text += ", at most " + ((DefaultOutputTimeSpec) solverTaskDescription.getOutputTimeSpec()).getKeepAtMost();
}
getJLabelOutput().setText(text);
}
} catch (Exception exc) {
exc.printStackTrace(System.out);
getJLabelOutput().setText("");
}
SolverDescription solverDescription = solverTaskDescription.getSolverDescription();
try {
ErrorTolerance errorTolerance = solverTaskDescription.getErrorTolerance();
TimeStep timeStep = solverTaskDescription.getTimeStep();
getJLabelRelTol().setText("Rel tol");
getJLabelAbsTol().setText("Abs tol");
getJLabel12().setText("Timestep");
getJLabelRelTol().setEnabled(false);
getJLabelAbsTol().setEnabled(false);
getJLabel12().setEnabled(false);
getJLabel10().setText("Sensitivity Analysis");
getJLabel10().setEnabled(true);
if (solverDescription.equals(SolverDescription.StochGibson)) {
getJLabel12().setEnabled(false);
getJLabelTimestep().setText("");
} else if (solverDescription.equals(SolverDescription.NFSim)) {
TimeBounds tb = solverTaskDescription.getTimeBounds();
double dtime = tb.getEndingTime() - tb.getStartingTime();
if (solverTaskDescription.getOutputTimeSpec() instanceof UniformOutputTimeSpec) {
UniformOutputTimeSpec uots = (UniformOutputTimeSpec) solverTaskDescription.getOutputTimeSpec();
double interval = uots.getOutputTimeStep();
int steps = (int) Math.round(dtime / interval);
getJLabel12().setEnabled(true);
getJLabel12().setText("Timepoints");
getJLabelTimestep().setText(steps + "");
} else if (solverTaskDescription.getOutputTimeSpec() instanceof DefaultOutputTimeSpec) {
DefaultOutputTimeSpec uots = (DefaultOutputTimeSpec) solverTaskDescription.getOutputTimeSpec();
getJLabel12().setEnabled(true);
getJLabel12().setText("End Time");
getJLabelTimestep().setText(solverTaskDescription.getTimeBounds().getEndingTime() + "");
} else {
getJLabel12().setEnabled(false);
getJLabel12().setText("End Time");
getJLabelTimestep().setText("na");
}
NFsimSimulationOptions nfsso = solverTaskDescription.getNFSimSimulationOptions();
String utl = "default";
Integer moleculeDistance = nfsso.getMoleculeDistance();
if (moleculeDistance != null) {
utl = moleculeDistance + "";
}
getJLabelRelTol().setEnabled(true);
getJLabelRelTol().setText("Universal Transversal Limit");
getJLabelRelTolValue().setText(utl);
String gml = "default";
Integer maxMoleculesPerType = nfsso.getMaxMoleculesPerType();
if (maxMoleculesPerType != null) {
gml = maxMoleculesPerType + "";
}
getJLabelAbsTol().setEnabled(true);
getJLabelAbsTol().setText("Max # of each " + MolecularType.typeName);
getJLabelAbsTolValue().setText(gml);
} else if (solverDescription.isNonSpatialStochasticSolver()) {
getJLabel12().setEnabled(true);
getJLabel12().setText("Timestep");
getJLabelTimestep().setText(timeStep.getDefaultTimeStep() + "s");
} else if (solverDescription.hasVariableTimestep()) {
getJLabel12().setEnabled(true);
getJLabel12().setText("Max timestep");
getJLabelTimestep().setText(timeStep.getMaximumTimeStep() + "s");
getJLabelRelTol().setEnabled(true);
getJLabelRelTolValue().setText("" + errorTolerance.getRelativeErrorTolerance());
getJLabelAbsTol().setEnabled(true);
getJLabelAbsTolValue().setText("" + errorTolerance.getAbsoluteErrorTolerance());
} else {
getJLabel12().setEnabled(true);
getJLabel12().setText("Timestep");
if (solverDescription.isChomboSolver()) {
String text = "Variable";
if (solverTaskDescription.getChomboSolverSpec().getTimeIntervalList().size() == 1) {
text = solverTaskDescription.getChomboSolverSpec().getLastTimeInterval().getTimeStep() + "s";
}
getJLabelTimestep().setText(text);
} else {
getJLabelTimestep().setText(timeStep.getDefaultTimeStep() + "s");
}
if (solverDescription.isSemiImplicitPdeSolver()) {
getJLabelRelTol().setEnabled(true);
getJLabelRelTolValue().setText("" + errorTolerance.getRelativeErrorTolerance());
} else {
getJLabelRelTol().setEnabled(false);
getJLabelRelTolValue().setText("");
}
getJLabelAbsTol().setEnabled(false);
getJLabelAbsTolValue().setText("");
}
} catch (Exception exc) {
exc.printStackTrace(System.out);
getJLabelTimestep().setText("");
getJLabelRelTolValue().setText("");
getJLabelAbsTolValue().setText("");
}
try {
boolean bChomboSolver = solverDescription.isChomboSolver();
getJLabelTitleNumProcessors().setVisible(bChomboSolver);
getJLabelNumProcessors().setVisible(bChomboSolver);
if (bChomboSolver) {
getJLabelNumProcessors().setText(String.valueOf(solverTaskDescription.getNumProcessors()));
}
if (getSimulation().isSpatial() || solverDescription.isNonSpatialStochasticSolver()) {
getJLabelSensitivity().setVisible(false);
getJLabel10().setVisible(false);
} else if (solverDescription.equals(SolverDescription.NFSim)) {
getJLabel10().setText("On-the-fly observ comp.");
NFsimSimulationOptions nfsso = solverTaskDescription.getNFSimSimulationOptions();
boolean goc = nfsso.getObservableComputationOff();
getJLabelSensitivity().setText(goc + "");
} else {
getJLabelSensitivity().setVisible(true);
getJLabel10().setVisible(true);
Constant param = solverTaskDescription.getSensitivityParameter();
if (param == null) {
getJLabelSensitivity().setText("no");
} else {
getJLabelSensitivity().setText(param.getName());
}
}
} catch (Exception exc) {
exc.printStackTrace(System.out);
getJLabelSensitivity().setText("");
}
if (solverDescription.isNonSpatialStochasticSolver()) {
getJLabelRelTol().setVisible(false);
getJLabelAbsTol().setVisible(false);
getJLabelRelTolValue().setVisible(false);
getJLabelAbsTolValue().setVisible(false);
} else {
getJLabelRelTol().setVisible(true);
getJLabelAbsTol().setVisible(true);
}
}
use of cbit.vcell.solver.ErrorTolerance in project vcell by virtualcell.
the class StopAtSpatiallyUniformPanel method setNewErrorTolerance.
public void setNewErrorTolerance() {
double absError = absTolTextField.isEnabled() ? new Double(absTolTextField.getText()).doubleValue() : 1e-9;
double relError = relTolTextField.isEnabled() ? new Double(relTolTextField.getText()).doubleValue() : 1e-9;
ErrorTolerance newErrorTol = new ErrorTolerance(absError, relError);
solverTaskDescription.setStopAtSpatiallyUniformErrorTolerance(newErrorTol);
}
use of cbit.vcell.solver.ErrorTolerance 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.ErrorTolerance 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.ErrorTolerance in project vcell by virtualcell.
the class StochFileWriter method write.
/**
* Write the model to a text file which serves as an input for Stochastic simulation engine.
* Creation date: (6/22/2006 5:37:26 PM)
*/
public void write(String[] parameterNames) throws Exception, ExpressionException {
Simulation simulation = simTask.getSimulation();
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
initialize();
if (bUseMessaging) {
writeJMSParamters();
}
// Write control information
printWriter.println("<control>");
cbit.vcell.solver.SolverTaskDescription solverTaskDescription = simulation.getSolverTaskDescription();
cbit.vcell.solver.TimeBounds timeBounds = solverTaskDescription.getTimeBounds();
cbit.vcell.solver.OutputTimeSpec outputTimeSpec = solverTaskDescription.getOutputTimeSpec();
ErrorTolerance errorTolerance = solverTaskDescription.getErrorTolerance();
NonspatialStochSimOptions stochOpt = solverTaskDescription.getStochOpt();
printWriter.println("STARTING_TIME" + "\t" + timeBounds.getStartingTime());
printWriter.println("ENDING_TIME " + "\t" + timeBounds.getEndingTime());
// pw.println("MAX_ITERATION"+"\t"+outputTimeSpec.getKeepAtMost());
printWriter.println("TOLERANCE " + "\t" + errorTolerance.getAbsoluteErrorTolerance());
if (outputTimeSpec.isDefault()) {
printWriter.println("SAMPLE_INTERVAL" + "\t" + ((DefaultOutputTimeSpec) outputTimeSpec).getKeepEvery());
printWriter.println("MAX_SAVE_POINTS" + "\t" + ((DefaultOutputTimeSpec) outputTimeSpec).getKeepAtMost());
} else if (outputTimeSpec.isUniform()) {
printWriter.println("SAVE_PERIOD" + "\t" + ((UniformOutputTimeSpec) outputTimeSpec).getOutputTimeStep());
}
printWriter.println("NUM_TRIAL" + "\t" + solverTaskDescription.getStochOpt().getNumOfTrials());
if (stochOpt.isUseCustomSeed()) {
printWriter.println("SEED" + "\t" + stochOpt.getCustomSeed());
} else {
// we generate our own random seed
RandomDataGenerator rdg = new RandomDataGenerator();
int randomSeed = rdg.nextInt(1, Integer.MAX_VALUE);
printWriter.println("SEED" + "\t" + randomSeed);
}
printWriter.println("</control>");
printWriter.println();
// write model information
// Model info. will be extracted from subDomain of mathDescription
Enumeration<SubDomain> e = simulation.getMathDescription().getSubDomains();
SubDomain subDomain = null;
if (e.hasMoreElements()) {
subDomain = e.nextElement();
}
if (subDomain != null) {
printWriter.println("<model>");
// variables
printWriter.println("<discreteVariables>");
// Species iniCondition (if in concentration) is sampled from a poisson distribution(which has a mean of the current iniExp value)
// There is only one subDomain for compartmental model
List<VarIniCondition> varInis = subDomain.getVarIniConditions();
if ((varInis != null) && (varInis.size() > 0)) {
RandomDataGenerator dist = new RandomDataGenerator();
if (simulation.getSolverTaskDescription().getStochOpt().isUseCustomSeed()) {
Integer randomSeed = simulation.getSolverTaskDescription().getStochOpt().getCustomSeed();
if (randomSeed != null) {
dist.reSeed(randomSeed);
}
}
printWriter.println("TotalVars" + "\t" + varInis.size());
for (VarIniCondition varIniCondition : varInis) {
try {
Expression iniExp = varIniCondition.getIniVal();
iniExp.bindExpression(simSymbolTable);
iniExp = simSymbolTable.substituteFunctions(iniExp).flatten();
double expectedCount = iniExp.evaluateConstant();
// 1000 mill
final Integer limit = 1000000000;
if (limit < expectedCount) {
String eMessage = "The Initial count for Species '" + varIniCondition.getVar().getName() + "' is " + BigDecimal.valueOf(expectedCount).toBigInteger() + "\n";
eMessage += "which is higher than the internal vCell limit of " + limit + ".\n";
eMessage += "Please reduce the Initial Condition value for this Species or reduce the compartment size.";
throw new MathFormatException(eMessage);
}
long varCount = 0;
if (varIniCondition instanceof VarIniCount) {
varCount = (long) expectedCount;
} else {
if (expectedCount > 0) {
varCount = dist.nextPoisson(expectedCount);
}
}
// System.out.println("expectedCount: " + expectedCount + ", varCount: " + varCount);
printWriter.println(varIniCondition.getVar().getName() + "\t" + varCount);
} catch (ExpressionException ex) {
ex.printStackTrace();
throw new MathFormatException("variable " + varIniCondition.getVar().getName() + "'s initial condition is required to be a constant.");
}
}
} else
printWriter.println("TotalVars" + "\t" + "0");
printWriter.println("</discreteVariables>");
printWriter.println();
// jump processes
printWriter.println("<jumpProcesses>");
List<JumpProcess> jumpProcesses = subDomain.getJumpProcesses();
if ((jumpProcesses != null) && (jumpProcesses.size() > 0)) {
printWriter.println("TotalProcesses" + "\t" + jumpProcesses.size());
for (int i = 0; i < jumpProcesses.size(); i++) {
printWriter.println(jumpProcesses.get(i).getName());
}
} else
printWriter.println("TotalProcesses" + "\t" + "0");
printWriter.println("</jumpProcesses>");
printWriter.println();
// process description
printWriter.println("<processDesc>");
if ((jumpProcesses != null) && (jumpProcesses.size() > 0)) {
printWriter.println("TotalDescriptions" + "\t" + jumpProcesses.size());
for (int i = 0; i < jumpProcesses.size(); i++) {
JumpProcess temProc = (JumpProcess) jumpProcesses.get(i);
// jump process name
printWriter.println("JumpProcess" + "\t" + temProc.getName());
Expression probExp = temProc.getProbabilityRate();
try {
probExp.bindExpression(simSymbolTable);
probExp = simSymbolTable.substituteFunctions(probExp).flatten();
if (!isValidProbabilityExpression(probExp)) {
throw new MathFormatException("probability rate in jump process " + temProc.getName() + " has illegal symbols(should only contain variable names).");
}
} catch (cbit.vcell.parser.ExpressionException ex) {
ex.printStackTrace();
throw new cbit.vcell.parser.ExpressionException("Binding math description error in probability rate in jump process " + temProc.getName() + ". Some symbols can not be resolved.");
}
// Expression temp = replaceVarIniInProbability(probExp);
// Propensity
printWriter.println("\t" + "Propensity" + "\t" + probExp.infix());
// effects
printWriter.println("\t" + "Effect" + "\t" + temProc.getActions().size());
for (int j = 0; j < temProc.getActions().size(); j++) {
printWriter.print("\t\t" + ((Action) temProc.getActions().get(j)).getVar().getName() + "\t" + ((Action) temProc.getActions().get(j)).getOperation());
printWriter.println("\t" + ((Action) temProc.getActions().get(j)).evaluateOperand());
printWriter.println();
}
// dependencies
Vector<String> dependencies = getDependencies(temProc, jumpProcesses);
if ((dependencies != null) && (dependencies.size() > 0)) {
printWriter.println("\t" + "DependentProcesses" + "\t" + dependencies.size());
for (int j = 0; j < dependencies.size(); j++) printWriter.println("\t\t" + dependencies.elementAt(j));
} else
printWriter.println("\t" + "DependentProcesses" + "\t" + "0");
printWriter.println();
}
} else
printWriter.println("TotalDescriptions" + "\t" + "0");
printWriter.println("</processDesc>");
printWriter.println("</model>");
}
// if (subDomain != null)
}
Aggregations