use of cbit.vcell.math.MathDescription in project vcell by virtualcell.
the class XmlHelper method XMLToSim.
public static Simulation XMLToSim(String xmlString) throws XmlParseException {
Simulation sim = null;
Namespace ns = Namespace.getNamespace(XMLTags.VCML_NS);
try {
if (xmlString == null || xmlString.length() == 0) {
throw new XmlParseException("Invalid xml for Simulation: " + xmlString);
}
// default parser and no validation
Element root = (XmlUtil.stringToXML(xmlString, null)).getRootElement();
Element simElement = root.getChild(XMLTags.SimulationTag, ns);
Element mdElement = root.getChild(XMLTags.MathDescriptionTag, ns);
Element geomElement = root.getChild(XMLTags.GeometryTag, ns);
XmlReader reader = new XmlReader(true, ns);
Geometry geom = null;
if (geomElement != null) {
geom = reader.getGeometry(geomElement);
}
MathDescription md = reader.getMathDescription(mdElement, geom);
sim = reader.getSimulation(simElement, md);
} catch (Exception pve) {
pve.printStackTrace();
throw new XmlParseException("Unable to parse simulation string.", pve);
}
sim.refreshDependencies();
return sim;
}
use of cbit.vcell.math.MathDescription in project vcell by virtualcell.
the class XmlHelper method XMLToSimTask.
public static SimulationTask XMLToSimTask(String xmlString) throws XmlParseException, ExpressionException {
Namespace ns = Namespace.getNamespace(XMLTags.VCML_NS);
try {
if (xmlString == null || xmlString.length() == 0) {
throw new XmlParseException("Invalid xml for Simulation: " + xmlString);
}
// default parser and no validation
Element root = (XmlUtil.stringToXML(xmlString, null)).getRootElement();
if (!root.getName().equals(SimulationTask_tag)) {
throw new RuntimeException("expecting top level element to be " + SimulationTask_tag);
}
int taskId = Integer.parseInt(root.getAttributeValue(TaskId_attr));
int jobIndex = Integer.parseInt(root.getAttributeValue(JobIndex_attr));
String computeResource = root.getChildTextTrim(ComputeResource_tag, ns);
List<?> children = root.getChildren(FieldFunctionIdentifierSpec_tag, ns);
ArrayList<FieldDataIdentifierSpec> fdisArrayList = new ArrayList<FieldDataIdentifierSpec>();
for (Object child : children) {
if (child instanceof Element) {
String fdisText = ((Element) child).getTextTrim();
FieldDataIdentifierSpec fdis = FieldDataIdentifierSpec.fromCSVString(fdisText);
fdisArrayList.add(fdis);
}
}
FieldDataIdentifierSpec[] fdisArray = fdisArrayList.toArray(new FieldDataIdentifierSpec[0]);
Element simElement = root.getChild(XMLTags.SimulationTag, ns);
Element mdElement = root.getChild(XMLTags.MathDescriptionTag, ns);
Element geomElement = root.getChild(XMLTags.GeometryTag, ns);
XmlReader reader = new XmlReader(true, ns);
Geometry geom = null;
if (geomElement != null) {
geom = reader.getGeometry(geomElement);
}
MathDescription md = reader.getMathDescription(mdElement, geom);
Simulation sim = reader.getSimulation(simElement, md);
sim.refreshDependencies();
SimulationJob simJob = new SimulationJob(sim, jobIndex, fdisArray);
SimulationTask simTask = new SimulationTask(simJob, taskId, computeResource);
return simTask;
} catch (Exception pve) {
pve.printStackTrace();
throw new XmlParseException("Unable to parse simulation string.", pve);
}
}
use of cbit.vcell.math.MathDescription in project vcell by virtualcell.
the class OutputFunctionContext method getAutoCompleteSymbolFilter.
public AutoCompleteSymbolFilter getAutoCompleteSymbolFilter() {
AutoCompleteSymbolFilter stef = new AutoCompleteSymbolFilter() {
public boolean accept(SymbolTableEntry ste) {
MathDescription math = getSimulationOwner().getMathDescription();
Variable var = math.getVariable(ste.getName());
return (!(var instanceof InsideVariable || var instanceof OutsideVariable));
}
public boolean acceptFunction(String funcName) {
return true;
}
};
return stef;
}
use of cbit.vcell.math.MathDescription in project vcell by virtualcell.
the class OutputFunctionContext method getEntries.
// public abstract void validateNamingConflicts(String symbolDescription, Class<?> newSymbolClass, String newSymbolName, PropertyChangeEvent e) throws PropertyVetoException ;
public void getEntries(Map<String, SymbolTableEntry> entryMap) {
// add all valid entries (variables) from mathdescription
MathDescription mathDescription = simulationOwner.getMathDescription();
if (mathDescription != null) {
Enumeration<Variable> varEnum = mathDescription.getVariables();
while (varEnum.hasMoreElements()) {
Variable var = varEnum.nextElement();
if (!(var instanceof PseudoConstant) && !(var instanceof Constant)) {
entryMap.put(var.getName(), var);
}
}
for (DataGenerator dataGenerator : mathDescription.getPostProcessingBlock().getDataGeneratorList()) {
entryMap.put(dataGenerator.getName(), dataGenerator);
}
}
entryMap.put(ReservedVariable.TIME.getName(), ReservedVariable.TIME);
int dimension = mathDescription.getGeometry().getDimension();
if (dimension > 0) {
entryMap.put(ReservedVariable.X.getName(), ReservedVariable.X);
if (dimension > 1) {
entryMap.put(ReservedVariable.Y.getName(), ReservedVariable.Y);
if (dimension > 2) {
entryMap.put(ReservedVariable.Z.getName(), ReservedVariable.Z);
}
}
}
// then add list of output functions.
for (SymbolTableEntry ste : outputFunctionsList) {
entryMap.put(ste.getName(), ste);
}
}
use of cbit.vcell.math.MathDescription in project vcell by virtualcell.
the class OutputFunctionContext method computeFunctionTypeWRTExpression.
// check if the new expression is valid for outputFunction of functionType
public VariableType computeFunctionTypeWRTExpression(AnnotatedFunction outputFunction, Expression exp) throws ExpressionException, InconsistentDomainException {
MathDescription mathDescription = getSimulationOwner().getMathDescription();
boolean bSpatial = getSimulationOwner().getGeometry().getDimension() > 0;
if (!bSpatial) {
return VariableType.NONSPATIAL;
}
Expression newexp = new Expression(exp);
// making sure that output function is not direct function of constant.
newexp.bindExpression(this);
// here use math description as symbol table because we allow
// new expression itself to be function of constant.
newexp = MathUtilities.substituteFunctions(newexp, this).flatten();
String[] symbols = newexp.getSymbols();
VariableType functionType = outputFunction.getFunctionType();
String funcName = outputFunction.getName();
Domain funcDomain = outputFunction.getDomain();
VariableType[] varTypes = null;
if (symbols != null && symbols.length > 0) {
// making sure that new expression is defined in the same domain
varTypes = new VariableType[symbols.length];
for (int i = 0; i < symbols.length; i++) {
if (ReservedMathSymbolEntries.getReservedVariableEntry(symbols[i]) != null) {
varTypes[i] = functionType;
} else {
Variable var = mathDescription.getVariable(symbols[i]);
if (var == null) {
var = mathDescription.getPostProcessingBlock().getDataGenerator(symbols[i]);
}
varTypes[i] = VariableType.getVariableType(var);
if (funcDomain != null) {
if (var.getDomain() == null) {
// OK
continue;
}
GeometryClass funcGeoClass = simulationOwner.getGeometry().getGeometryClass(funcDomain.getName());
GeometryClass varGeoClass = simulationOwner.getGeometry().getGeometryClass(var.getDomain().getName());
if (varGeoClass instanceof SubVolume && funcGeoClass instanceof SurfaceClass) {
// seems ok if membrane refereces volume
if (!((SurfaceClass) funcGeoClass).isAdjacentTo((SubVolume) varGeoClass)) {
// but has to be adjacent
String errMsg = "'" + funcName + "' defined on Membrane '" + funcDomain.getName() + "' directly or indirectly references " + " variable '" + symbols[i] + "' defined on Volume '" + var.getDomain().getName() + " which is not adjacent to Membrane '" + funcDomain.getName() + "'.";
throw new ExpressionException(errMsg);
}
} else if (!var.getDomain().compareEqual(funcDomain)) {
String errMsg = "'" + funcName + "' defined on '" + funcDomain.getName() + "' directly or indirectly references " + " variable '" + symbols[i] + "' defined on '" + var.getDomain().getName() + ".";
throw new ExpressionException(errMsg);
}
}
}
}
}
// if there are no variables (like built in function, vcRegionArea), check with flattened expression to find out the variable type of the new expression
VariableDomain functionVariableDomain = functionType.getVariableDomain();
Function flattenedFunction = new Function(funcName, newexp, funcDomain);
flattenedFunction.bind(this);
VariableType newVarType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, getSimulationOwner().getMathDescription(), symbols, varTypes, bSpatial);
if (!newVarType.getVariableDomain().equals(functionVariableDomain)) {
String errMsg = "The expression for '" + funcName + "' includes at least one " + newVarType.getVariableDomain().getName() + " variable. Please make sure that only " + functionVariableDomain.getName() + " variables are " + "referenced in " + functionVariableDomain.getName() + " output functions.";
throw new ExpressionException(errMsg);
}
return newVarType;
}
Aggregations