use of cbit.vcell.solver.SmoldynSimulationOptions 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());
}
if (solverTaskDesc.isBorderExtrapolationDisabled()) {
// Set with GUI checkbox in SolverTaskDescriptionAdvancedPanel
// Tells vcell-solvers/VCell/src/SundialsPdeScheduler.cpp not to extrapolate values at boundaries
// Read by vcell-solvers/VCell/src/FVSolver.cpp::loadSimulationParameters(...) from file {vcellUserDataDir}/SimID_xxx.fvinput
printWriter.print(" " + ("" + solverTaskDesc.isBorderExtrapolationDisabled()).toLowerCase());
}
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);
}
MathDescription md = simulation.getMathDescription();
if (md.isSpatialHybrid()) {
SmoldynSimulationOptions smoldynSimulationOptions = simulation.getSolverTaskDescription().getSmoldynSimulationOptions();
if (smoldynSimulationOptions != null && smoldynSimulationOptions.getSmoldynStepMultiplier() > 1) {
printWriter.println(FVInputFileKeyword.SMOLDYN_STEP_MULTIPLIER + " " + smoldynSimulationOptions.getSmoldynStepMultiplier());
}
}
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.SmoldynSimulationOptions in project vcell by virtualcell.
the class SmoldynFileWriter method writeSimulationTimes.
private void writeSimulationTimes() {
// write simulation times
TimeBounds timeBounds = simulation.getSolverTaskDescription().getTimeBounds();
TimeStep timeStep = simulation.getSolverTaskDescription().getTimeStep();
printWriter.println("# simulation times");
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.time_start + " " + timeBounds.getStartingTime());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.time_stop + " " + timeBounds.getEndingTime());
MathDescription md = simulation.getMathDescription();
if (md.isSpatialHybrid()) {
SmoldynSimulationOptions smoldynSimulationOptions = simulation.getSolverTaskDescription().getSmoldynSimulationOptions();
double ts = timeStep.getDefaultTimeStep() * (double) smoldynSimulationOptions.getSmoldynStepMultiplier();
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.time_step + " " + ts);
} else {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.time_step + " " + timeStep.getDefaultTimeStep());
}
printWriter.println();
}
use of cbit.vcell.solver.SmoldynSimulationOptions in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* This method returns a XML representation of a SolverTaskDescription object.
* Creation date: (3/2/2001 10:59:55 PM)
* @return Element
* @param param cbit.vcell.solver.SolverTaskDescription
*/
private Element getXML(SolverTaskDescription param) {
Element solvertask = new Element(XMLTags.SolverTaskDescriptionTag);
// Add Attributes
if (param.getTaskType() == SolverTaskDescription.TASK_UNSTEADY) {
solvertask.setAttribute(XMLTags.TaskTypeTag, XMLTags.UnsteadyTag);
} else if (param.getTaskType() == SolverTaskDescription.TASK_STEADY) {
solvertask.setAttribute(XMLTags.TaskTypeTag, XMLTags.SteadyTag);
} else {
throw new IllegalArgumentException("Unexpected task type:" + param.getTaskType());
}
// solvertask.setAttribute(XMLTags.KeepEveryTag, String.valueOf(param.getKeepEvery()));
// solvertask.setAttribute(XMLTags.KeepAtMostTag, String.valueOf(param.getKeepAtMost()));
solvertask.setAttribute(XMLTags.UseSymbolicJacobianAttrTag, String.valueOf(param.getUseSymbolicJacobian()));
// Add timeBounds
solvertask.addContent(getXML(param.getTimeBounds()));
// Add timeStep
solvertask.addContent(getXML(param.getTimeStep()));
// Add ErrorTolerence
solvertask.addContent(getXML(param.getErrorTolerance()));
// Jan 8, 2016 (jim) let getXML(stochOpt) write out the correct stochastic options
if (param.getStochOpt() != null) {
solvertask.addContent(getXML(param.getStochOpt(), param.getStochHybridOpt()));
}
// Add OutputOptions
solvertask.addContent(getXML(param.getOutputTimeSpec()));
// Add sensitivityParameter
if (param.getSensitivityParameter() != null) {
solvertask.addContent(getXML(param.getSensitivityParameter()));
}
// Add solver name
solvertask.setAttribute(XMLTags.SolverNameTag, param.getSolverDescription().getDatabaseName());
// Stop At Spatially Uniform
ErrorTolerance stopAtSpatiallyUniformErrorTolerance = param.getStopAtSpatiallyUniformErrorTolerance();
if (stopAtSpatiallyUniformErrorTolerance != null) {
Element element = new Element(XMLTags.StopAtSpatiallyUniform);
element.addContent(getXML(stopAtSpatiallyUniformErrorTolerance));
solvertask.addContent(element);
}
boolean bRunParameterScanSerially = param.isSerialParameterScan();
if (bRunParameterScanSerially) {
solvertask.setAttribute(XMLTags.RunParameterScanSerially, String.valueOf(bRunParameterScanSerially));
}
boolean bTimeoutSimulationDisabled = param.isTimeoutDisabled();
if (bTimeoutSimulationDisabled) {
solvertask.setAttribute(XMLTags.TimeoutSimulationDisabled, String.valueOf(bTimeoutSimulationDisabled));
}
boolean bBorderExtrapolationDisabled = param.isBorderExtrapolationDisabled();
if (bBorderExtrapolationDisabled) {
solvertask.setAttribute(XMLTags.BorderExtrapolationDisabled, String.valueOf(bBorderExtrapolationDisabled));
}
SmoldynSimulationOptions smoldynSimulationOptions = param.getSmoldynSimulationOptions();
if (smoldynSimulationOptions != null) {
solvertask.addContent(getXML(smoldynSimulationOptions));
}
NFsimSimulationOptions nfsimSimulationOptions = param.getNFSimSimulationOptions();
if (nfsimSimulationOptions != null) {
solvertask.addContent(getXML(nfsimSimulationOptions));
}
SundialsPdeSolverOptions sundialsPdeSolverOptions = param.getSundialsPdeSolverOptions();
if (sundialsPdeSolverOptions != null) {
solvertask.addContent(getXML(sundialsPdeSolverOptions));
}
ChomboSolverSpec chomboSolverSpec = param.getChomboSolverSpec();
if (chomboSolverSpec != null) {
Element chomboElement = getXML(chomboSolverSpec);
solvertask.addContent(chomboElement);
}
MovingBoundarySolverOptions mb = param.getMovingBoundarySolverOptions();
if (mb != null) {
Element e = getXML(mb);
solvertask.addContent(e);
}
Element numProcessors = new Element(XMLTags.NUM_PROCESSORS);
numProcessors.setText(Integer.toString(param.getNumProcessors()));
solvertask.addContent(numProcessors);
return solvertask;
}
use of cbit.vcell.solver.SmoldynSimulationOptions in project vcell by virtualcell.
the class XmlReader method getSmoldySimulationOptions.
private SmoldynSimulationOptions getSmoldySimulationOptions(Element smoldySimulationOptionsElement) throws XmlParseException {
SmoldynSimulationOptions sso = null;
if (smoldySimulationOptionsElement != null) {
sso = new SmoldynSimulationOptions();
String temp = smoldySimulationOptionsElement.getChildText(XMLTags.SmoldynSimulationOptions_accuracy, vcNamespace);
if (temp != null) {
sso.setAccuracy(Double.parseDouble(temp));
}
temp = smoldySimulationOptionsElement.getChildText(XMLTags.SmoldynSimulationOptions_randomSeed, vcNamespace);
if (temp != null) {
sso.setRandomSeed(new Integer(temp));
}
temp = smoldySimulationOptionsElement.getChildText(XMLTags.SmoldynSimulationOptions_gaussianTableSize, vcNamespace);
if (temp != null) {
try {
sso.setGaussianTableSize(Integer.parseInt(temp));
} catch (NumberFormatException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
}
temp = smoldySimulationOptionsElement.getChildText(XMLTags.SmoldynSimulationOptions_high_res, vcNamespace);
if (temp != null) {
sso.setUseHighResolutionSample(new Boolean(temp));
}
temp = smoldySimulationOptionsElement.getChildText(XMLTags.SmoldynSimulationOptions_saveParticleFiles, vcNamespace);
if (temp != null) {
sso.setSaveParticleLocations(new Boolean(temp));
}
temp = smoldySimulationOptionsElement.getChildText(XMLTags.SmoldynSimulationOptions_stepMultiplier, vcNamespace);
if (temp != null) {
sso.setSmoldynStepMultiplier(Integer.parseInt(temp));
}
}
return sso;
}
use of cbit.vcell.solver.SmoldynSimulationOptions in project vcell by virtualcell.
the class SmoldynFileWriter method writeSimulationSettings.
private void writeSimulationSettings() {
printWriter.println("# simulation settings");
SmoldynSimulationOptions smoldynSimulationOptions = simulation.getSolverTaskDescription().getSmoldynSimulationOptions();
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.accuracy + " " + smoldynSimulationOptions.getAccuracy());
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.gauss_table_size + " " + smoldynSimulationOptions.getGaussianTableSize());
printWriter.println();
}
Aggregations