use of cbit.vcell.solver.NFsimSimulationOptions in project vcell by virtualcell.
the class XmlReader method getSolverTaskDescription.
/**
* This method returns a SolverTaskDescription Object from a XML Element.
* Creation date: (5/22/2001 10:51:23 AM)
* @return cbit.vcell.solver.SolverTaskDescription
* @param param org.jdom.Element
* @param simulation cbit.vcell.solver.Simulation
*/
private SolverTaskDescription getSolverTaskDescription(Element param, Simulation simulation) throws XmlParseException {
// *** create new SolverTaskDescription ***
SolverTaskDescription solverTaskDesc = new SolverTaskDescription(simulation);
// Added July 22nd, 2007, used as condition for stochSimOptions or stochHybridOprtions
SolverDescription sd = null;
// Retrieve attributes
String taskType = param.getAttributeValue(XMLTags.TaskTypeTag);
int keepEvery = -1;
int keepAtMost = -1;
if (param.getAttributeValue(XMLTags.KeepEveryTag) != null) {
keepEvery = Integer.parseInt(param.getAttributeValue(XMLTags.KeepEveryTag));
keepAtMost = Integer.parseInt(param.getAttributeValue(XMLTags.KeepAtMostTag));
}
boolean useSymJacob = new Boolean(param.getAttributeValue(XMLTags.UseSymbolicJacobianAttrTag)).booleanValue();
String solverName = param.getAttributeValue(XMLTags.SolverNameTag);
// get sentivity parameter
Element sensparamElement = param.getChild(XMLTags.ConstantTag, vcNamespace);
Constant sensitivityparam = null;
if (sensparamElement != null) {
sensitivityparam = getConstant(sensparamElement);
}
// set Attributes
try {
// set solver
sd = SolverDescription.fromDatabaseName(solverName);
if (sd == null) {
System.err.println("====================================== couldn't find solver description name ==========================================");
}
solverTaskDesc.setSolverDescription(sd);
if (taskType.equalsIgnoreCase(XMLTags.UnsteadyTag)) {
solverTaskDesc.setTaskType(SolverTaskDescription.TASK_UNSTEADY);
} else if (taskType.equalsIgnoreCase(XMLTags.SteadyTag)) {
solverTaskDesc.setTaskType(SolverTaskDescription.TASK_STEADY);
} else {
throw new XmlParseException("Unexpected task type: " + taskType);
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was fired when setting the taskType: " + taskType, e);
}
int numProcessors = parseIntWithDefault(param, XMLTags.NUM_PROCESSORS, 1);
try {
solverTaskDesc.setNumProcessors(numProcessors);
solverTaskDesc.setUseSymbolicJacobian(useSymJacob);
// get TimeBound
solverTaskDesc.setTimeBounds(getTimeBounds(param.getChild(XMLTags.TimeBoundTag, vcNamespace)));
// get TimeStep
solverTaskDesc.setTimeStep(getTimeStep(param.getChild(XMLTags.TimeStepTag, vcNamespace)));
// get ErrorTolerance
solverTaskDesc.setErrorTolerance(getErrorTolerance(param.getChild(XMLTags.ErrorToleranceTag, vcNamespace)));
// get StochSimOptions
if (simulation != null && simulation.getMathDescription() != null) {
if (simulation.getMathDescription().isNonSpatialStoch() && param.getChild(XMLTags.StochSimOptionsTag, vcNamespace) != null) {
// Amended July 22nd, 2007 to read either stochSimOptions or stochHybridOptions
solverTaskDesc.setStochOpt(getStochSimOptions(param.getChild(XMLTags.StochSimOptionsTag, vcNamespace)));
if (sd != null && !sd.equals(SolverDescription.StochGibson)) {
solverTaskDesc.setStochHybridOpt(getStochHybridOptions(param.getChild(XMLTags.StochSimOptionsTag, vcNamespace)));
}
}
}
// get OutputOptions
if (keepEvery != -1) {
solverTaskDesc.setOutputTimeSpec(new DefaultOutputTimeSpec(keepEvery, keepAtMost));
}
OutputTimeSpec ots = getOutputTimeSpec(param.getChild(XMLTags.OutputOptionsTag, vcNamespace));
if (ots != null) {
solverTaskDesc.setOutputTimeSpec(getOutputTimeSpec(param.getChild(XMLTags.OutputOptionsTag, vcNamespace)));
}
// set SensitivityParameter
solverTaskDesc.setSensitivityParameter(sensitivityparam);
// set StopAtSpatiallyUniform
Element stopSpatiallyElement = param.getChild(XMLTags.StopAtSpatiallyUniform, vcNamespace);
if (stopSpatiallyElement != null) {
Element errTolElement = stopSpatiallyElement.getChild(XMLTags.ErrorToleranceTag, vcNamespace);
if (errTolElement != null) {
solverTaskDesc.setStopAtSpatiallyUniformErrorTolerance(getErrorTolerance(errTolElement));
}
}
String runParameterScanSeriallyAttributeValue = param.getAttributeValue(XMLTags.RunParameterScanSerially);
if (runParameterScanSeriallyAttributeValue != null) {
solverTaskDesc.setSerialParameterScan(new Boolean(runParameterScanSeriallyAttributeValue).booleanValue());
}
Element nfsimSimulationOptionsElement = param.getChild(XMLTags.NFSimSimulationOptions, vcNamespace);
if (nfsimSimulationOptionsElement != null) {
NFsimSimulationOptions nfsimSimulationOptions = getNFSimSimulationOptions(nfsimSimulationOptionsElement);
solverTaskDesc.setNFSimSimulationOptions(nfsimSimulationOptions);
}
Element smoldySimulationOptionsElement = param.getChild(XMLTags.SmoldynSimulationOptions, vcNamespace);
if (smoldySimulationOptionsElement != null) {
SmoldynSimulationOptions smoldynSimulationOptions = getSmoldySimulationOptions(smoldySimulationOptionsElement);
solverTaskDesc.setSmoldynSimulationOptions(smoldynSimulationOptions);
}
Element sundialsPdeSolverOptionsElement = param.getChild(XMLTags.SundialsSolverOptions, vcNamespace);
if (sundialsPdeSolverOptionsElement != null) {
SundialsPdeSolverOptions sundialsPdeSolverOptions = getSundialsPdeSolverOptions(sundialsPdeSolverOptionsElement);
solverTaskDesc.setSundialsPdeSolverOptions(sundialsPdeSolverOptions);
}
Element chomboElement = param.getChild(XMLTags.ChomboSolverSpec, vcNamespace);
if (chomboElement != null) {
ChomboSolverSpec chombo = getChomboSolverSpec(solverTaskDesc, chomboElement, simulation.getMathDescription().getGeometry().getDimension());
solverTaskDesc.setChomboSolverSpec(chombo);
}
Element mbElement = param.getChild(XMLTags.MovingBoundarySolverOptionsTag, vcNamespace);
if (mbElement != null) {
MovingBoundarySolverOptions mb = getMovingBoundarySolverOptions(solverTaskDesc, mbElement);
solverTaskDesc.setMovingBoundarySolverOptions(mb);
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
return solverTaskDesc;
}
use of cbit.vcell.solver.NFsimSimulationOptions in project vcell by virtualcell.
the class XmlReader method getNFSimSimulationOptions.
private NFsimSimulationOptions getNFSimSimulationOptions(Element nfsimSimulationOptionsElement) throws XmlParseException {
NFsimSimulationOptions so = new NFsimSimulationOptions();
String temp = null;
temp = nfsimSimulationOptionsElement.getChildText(XMLTags.NFSimSimulationOptions_observableComputationOff, vcNamespace);
if (temp != null) {
so.setObservableComputationOff(new Boolean(temp));
}
temp = nfsimSimulationOptionsElement.getChildText(XMLTags.NFSimSimulationOptions_moleculeDistance, vcNamespace);
if (temp != null) {
so.setMoleculeDistance(new Integer(temp));
}
temp = nfsimSimulationOptionsElement.getChildText(XMLTags.NFSimSimulationOptions_aggregateBookkeeping, vcNamespace);
if (temp != null) {
so.setAggregateBookkeeping(new Boolean(temp));
}
temp = nfsimSimulationOptionsElement.getChildText(XMLTags.NFSimSimulationOptions_maxMoleculesPerType, vcNamespace);
if (temp != null) {
so.setMaxMoleculesPerType(new Integer(temp));
}
temp = nfsimSimulationOptionsElement.getChildText(XMLTags.NFSimSimulationOptions_equilibrateTime, vcNamespace);
if (temp != null) {
so.setEquilibrateTime(new Integer(temp));
}
temp = nfsimSimulationOptionsElement.getChildText(XMLTags.NFSimSimulationOptions_randomSeed, vcNamespace);
if (temp != null) {
so.setRandomSeed(new Integer(temp));
}
temp = nfsimSimulationOptionsElement.getChildText(XMLTags.NFSimSimulationOptions_preventIntraBonds, vcNamespace);
if (temp != null) {
so.setPreventIntraBonds(new Boolean(temp));
}
return so;
}
use of cbit.vcell.solver.NFsimSimulationOptions in project vcell by virtualcell.
the class NFSimSolver method getMathExecutableCommand.
@Override
protected String[] getMathExecutableCommand() {
String executableName = null;
try {
executableName = SolverUtilities.getExes(SolverDescription.NFSim)[0].getAbsolutePath();
} catch (IOException e) {
throw new RuntimeException("failed to get executable for solver " + SolverDescription.NFSim.getDisplayLabel() + ": " + e.getMessage(), e);
}
String inputFilename = getInputFilename();
String outputFilename = getOutputFilename();
String speciesOutputFilename = getSpeciesOutputFilename();
NFsimSimulationOptions nfsso = simTask.getSimulation().getSolverTaskDescription().getNFSimSimulationOptions();
ArrayList<String> adv = new ArrayList<String>();
boolean observableComputationOff = nfsso.getObservableComputationOff();
if (observableComputationOff == true) {
// false is by default, no need to specify
adv.add("-notf");
}
Integer moleculeDistance = nfsso.getMoleculeDistance();
if (moleculeDistance != null) {
adv.add("-utl");
adv.add(moleculeDistance + "");
}
boolean aggregateBookkeeping = nfsso.getAggregateBookkeeping();
if (aggregateBookkeeping == true || simTask.getSimulation().getMathDescription().hasSpeciesObservable()) {
// false is by default, no need to specify
adv.add("-cb");
}
Integer maxMoleculesPerType = nfsso.getMaxMoleculesPerType();
if (maxMoleculesPerType != null) {
adv.add("-gml");
adv.add(maxMoleculesPerType + "");
}
Integer equilibrateTime = nfsso.getEquilibrateTime();
if (equilibrateTime != null) {
adv.add("-eq");
adv.add(equilibrateTime + "");
}
boolean preventIntraBonds = nfsso.getPreventIntraBonds();
if (preventIntraBonds == true) {
// false is by default, no need to specify
adv.add("-bscb");
}
TimeBounds tb = getSimulationJob().getSimulation().getSolverTaskDescription().getTimeBounds();
double dtime = tb.getEndingTime() - tb.getStartingTime();
String timeSpecOption1 = "-oSteps";
String timeSpecOption2 = "10";
OutputTimeSpec outputTimeSpec = getSimulationJob().getSimulation().getSolverTaskDescription().getOutputTimeSpec();
if (outputTimeSpec instanceof DefaultOutputTimeSpec) {
DefaultOutputTimeSpec dots = (DefaultOutputTimeSpec) outputTimeSpec;
int steps = dots.getKeepAtMost();
timeSpecOption1 = "-oSteps";
timeSpecOption2 = Integer.toString(steps);
} else if (outputTimeSpec instanceof UniformOutputTimeSpec) {
UniformOutputTimeSpec dots = (UniformOutputTimeSpec) outputTimeSpec;
double steps = dtime / dots.getOutputTimeStep();
timeSpecOption1 = "-oSteps";
int stepsi = (int) Math.round(steps);
timeSpecOption2 = Integer.toString(stepsi);
} else {
throw new RuntimeException("Unsupported output time spec class");
}
String[] baseCommands = { "-xml", inputFilename, "-o", outputFilename, "-sim", Double.toString(dtime), "-ss", speciesOutputFilename };
ArrayList<String> cmds = new ArrayList<String>();
cmds.add(executableName);
Integer seed = nfsso.getRandomSeed();
if (seed != null) {
cmds.add("-seed");
cmds.add(seed.toString());
} else {
long randomSeed = System.currentTimeMillis();
randomSeed = randomSeed + simTask.getSimulationJob().getJobIndex();
// multiply with a large prime number to spread numbers that are too close and in sequence
randomSeed = randomSeed * 89611;
Integer rs = (int) randomSeed;
String str = rs.toString();
if (str.startsWith("-")) {
// NFSim wants a positive integer, for anything else is initializing with 0
str = str.substring(1);
}
cmds.add("-seed");
cmds.add(str);
// PrintWriter writer;
// try {
// writer = new PrintWriter("c:\\TEMP\\aaa\\" + randomSeed + ".txt", "UTF-8");
// writer.println(str);
// writer.close();
// } catch (FileNotFoundException | UnsupportedEncodingException e) {
// // Auto-generated catch block
// e.printStackTrace();
// }
}
cmds.add("-vcell");
cmds.addAll(new ArrayList<String>(Arrays.asList(baseCommands)));
cmds.add(timeSpecOption1);
cmds.add(timeSpecOption2);
cmds.addAll(adv);
if (bMessaging) {
cmds.add("-v");
}
return cmds.toArray(new String[cmds.size()]);
}
Aggregations