use of cbit.vcell.math.Constant 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.math.Constant in project vcell by virtualcell.
the class XmlReader method getConstant.
/**
* This method returns a Constant object from a XML element.
* Creation date: (5/16/2001 1:50:07 PM)
* @return cbit.vcell.math.Constant
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
private Constant getConstant(Element param) throws XmlParseException {
// retrieve values
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
Expression exp = unMangleExpression(param.getText());
// -- create new constant object ---
Constant newconstant = new Constant(name, exp);
transcribeComments(param, newconstant);
return newconstant;
}
use of cbit.vcell.math.Constant in project vcell by virtualcell.
the class XmlReader method addResevedSymbols.
/**
* This method returns a Kinetics object from a XML Element based on the value of the kinetics type attribute.
* Creation date: (3/19/2001 4:42:04 PM)
* @return cbit.vcell.model.Kinetics
* @param param org.jdom.Element
*/
private void addResevedSymbols(VariableHash varHash, Model model) throws XmlParseException {
//
try {
// add reserved symbols
varHash.addVariable(new Constant(model.getPI_CONSTANT().getName(), new Expression(0.0)));
varHash.addVariable(new Constant(model.getFARADAY_CONSTANT().getName(), new Expression(0.0)));
varHash.addVariable(new Constant(model.getFARADAY_CONSTANT_NMOLE().getName(), new Expression(0.0)));
varHash.addVariable(new Constant(model.getGAS_CONSTANT().getName(), new Expression(0.0)));
varHash.addVariable(new Constant(model.getKMILLIVOLTS().getName(), new Expression(0.0)));
varHash.addVariable(new Constant(model.getN_PMOLE().getName(), new Expression(0.0)));
varHash.addVariable(new Constant(model.getKMOLE().getName(), new Expression(0.0)));
varHash.addVariable(new Constant(model.getTEMPERATURE().getName(), new Expression(0.0)));
varHash.addVariable(new Constant(model.getK_GHK().getName(), new Expression(0.0)));
varHash.addVariable(new Constant(model.getTIME().getName(), new Expression(0.0)));
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException("error reordering parameters according to dependencies", e);
}
}
use of cbit.vcell.math.Constant in project vcell by virtualcell.
the class SimulationRepresentation method getParameters.
private static ParameterRepresentation[] getParameters(BioModel bioModel, SimulationRep simulationRep) {
SimulationContext simContext = null;
for (SimulationContext sc : bioModel.getSimulationContexts()) {
if (sc.getMathDescription().getKey().equals(simulationRep.getMathKey())) {
simContext = sc;
break;
}
}
if (simContext == null) {
return null;
}
// initialize to old mathDescription in case error generating math
MathDescription mathDesc = simContext.getMathDescription();
MathMapping mathMapping = simContext.createNewMathMapping();
MathSymbolMapping mathSymbolMapping = null;
try {
mathDesc = mathMapping.getMathDescription();
mathSymbolMapping = mathMapping.getMathSymbolMapping();
} catch (Exception e1) {
System.err.println(e1.getMessage());
}
ArrayList<ParameterRepresentation> parameterReps = new ArrayList<ParameterRepresentation>();
Enumeration<Constant> enumMath = mathDesc.getConstants();
while (enumMath.hasMoreElements()) {
Constant constant = enumMath.nextElement();
if (constant.getExpression().isNumeric()) {
SymbolTableEntry biologicalSymbolTableEntry = null;
if (mathSymbolMapping != null) {
SymbolTableEntry[] stes = mathSymbolMapping.getBiologicalSymbol(constant);
if (stes != null && stes.length >= 1) {
biologicalSymbolTableEntry = stes[0];
}
}
if (biologicalSymbolTableEntry instanceof ReservedSymbol) {
continue;
}
try {
parameterReps.add(new ParameterRepresentation(constant.getName(), constant.getExpression().evaluateConstant(), biologicalSymbolTableEntry));
} catch (ExpressionException e) {
// can't happen, because constant expression is numeric
e.printStackTrace();
}
}
}
return parameterReps.toArray(new ParameterRepresentation[0]);
}
use of cbit.vcell.math.Constant in project vcell by virtualcell.
the class ConstantArraySpec method createListSpec.
/**
* Insert the method's description here.
* Creation date: (9/23/2005 1:33:00 PM)
* @return cbit.vcell.solver.ConstantArraySpec
*/
public static ConstantArraySpec createListSpec(String name, String[] values) throws cbit.vcell.parser.ExpressionException {
if (values.length < 2)
throw new RuntimeException("List must contain at least two values");
ConstantArraySpec spec = new ConstantArraySpec();
spec.type = TYPE_LIST;
spec.name = name;
spec.constants = new Constant[values.length];
spec.numValues = values.length;
for (int i = 0; i < values.length; i++) {
spec.constants[i] = new Constant(name, new cbit.vcell.parser.Expression(values[i]));
}
return spec;
}
Aggregations