use of org.vcell.chombo.RefinementRoi.RoiType in project vcell by virtualcell.
the class XmlReader method getChomboSolverSpec.
private ChomboSolverSpec getChomboSolverSpec(SolverTaskDescription solverTaskDesc, Element element, int dimension) throws XmlParseException {
int maxBoxSize = parseIntWithDefault(element, XMLTags.MaxBoxSizeTag, ChomboSolverSpec.getDefaultMaxBoxSize(dimension));
double fillRatio = parseDoubleWithDefault(element, XMLTags.FillRatioTag, ChomboSolverSpec.getDefaultFillRatio());
boolean bSaveVCellOutput = parseBooleanWithDefault(element, XMLTags.SaveVCellOutput, true);
boolean bSaveChomboOutput = parseBooleanWithDefault(element, XMLTags.SaveChomboOutput, false);
Element childElement = element.getChild(XMLTags.RefineRatios, vcNamespace);
List<Integer> refineRatioList = null;
if (childElement != null) {
String text = childElement.getText();
if (text != null && !text.isEmpty()) {
StringTokenizer st = new StringTokenizer(text, ",");
if (st.hasMoreTokens()) {
refineRatioList = new ArrayList<Integer>();
while (st.hasMoreElements()) {
String token = st.nextToken();
if (token != null) {
int n = Integer.parseInt(token);
refineRatioList.add(n);
}
}
}
}
}
Integer viewLevel = null;
try {
ChomboSolverSpec css = new ChomboSolverSpec(maxBoxSize, fillRatio, viewLevel, bSaveVCellOutput, bSaveChomboOutput, refineRatioList);
double smallVolfracThreshold = parseDoubleWithDefault(element, XMLTags.SmallVolfracThreshold, 0);
int blockFactor = parseIntWithDefault(element, XMLTags.BlockFactorTag, ChomboSolverSpec.DEFAULT_BLOCK_FACTOR);
boolean bActivateFeatureUnderDevelopment = parseBooleanWithDefault(element, XMLTags.ActivateFeatureUnderDevelopment, false);
css.setSmallVolfracThreshold(smallVolfracThreshold);
css.setActivateFeatureUnderDevelopment(bActivateFeatureUnderDevelopment);
css.setBlockFactor(blockFactor);
int tagsGrow = parseIntWithDefault(element, XMLTags.TagsGrowTag, ChomboSolverSpec.defaultTagsGrow);
css.setTagsGrow(tagsGrow);
Element timeBoundsElement = element.getChild(XMLTags.TimeBoundTag, vcNamespace);
List<Element> timeIntervalElementList = null;
boolean noTimeBounds = false;
if (timeBoundsElement == null) {
noTimeBounds = true;
} else {
timeIntervalElementList = timeBoundsElement.getChildren(XMLTags.TimeIntervalTag, vcNamespace);
if (timeIntervalElementList.size() == 0) {
noTimeBounds = true;
}
}
if (noTimeBounds) {
// old format
double startTime = 0;
double endTime = solverTaskDesc.getTimeBounds().getEndingTime();
double timeStep = solverTaskDesc.getTimeStep().getDefaultTimeStep();
double outputTimeStep = ((UniformOutputTimeSpec) solverTaskDesc.getOutputTimeSpec()).getOutputTimeStep();
try {
TimeInterval ti = new TimeInterval(startTime, endTime, timeStep, outputTimeStep);
css.addTimeInterval(ti);
} catch (IllegalArgumentException ex) {
css.addTimeInterval(TimeInterval.getDefaultTimeInterval());
}
} else {
for (Element e : timeIntervalElementList) {
String s = e.getAttributeValue(XMLTags.StartTimeAttrTag);
double startTime = Double.valueOf(s);
s = e.getAttributeValue(XMLTags.EndTimeAttrTag);
double endTime = Double.valueOf(s);
s = e.getAttributeValue(XMLTags.TimeStepAttrTag);
double timeStep = Double.valueOf(s);
s = e.getAttributeValue(XMLTags.OutputTimeStepAttrTag);
double outputTimeStep = Double.valueOf(s);
TimeInterval ti = new TimeInterval(startTime, endTime, timeStep, outputTimeStep);
css.addTimeInterval(ti);
}
}
Element meshRefineElement = element.getChild(XMLTags.MeshRefinementTag, vcNamespace);
if (meshRefineElement != null) {
if (meshRefineElement.getChildren().size() != 0) {
// in old model, if there is no refinement, set view level to finest
// only set viewLevel when meshRefinement has children
Element viewLevelChild = element.getChild(XMLTags.ViewLevelTag, vcNamespace);
if (viewLevelChild != null) {
viewLevel = parseIntWithDefault(element, XMLTags.ViewLevelTag, 0);
css.setViewLevel(viewLevel);
}
}
List<Element> levelElementList = meshRefineElement.getChildren(XMLTags.RefinementRoiTag, vcNamespace);
for (Element levelElement : levelElementList) {
String levelStr = levelElement.getAttributeValue(XMLTags.RefineRoiLevelAttrTag);
int level = 1;
if (levelStr != null) {
level = Integer.parseInt(levelStr);
}
String type = levelElement.getAttributeValue(XMLTags.RefinementRoiTypeAttrTag);
RoiType roiType = RoiType.Membrane;
if (type != null) {
try {
roiType = RoiType.valueOf(type);
} catch (Exception ex) {
// ignore
}
}
Element expElement = levelElement.getChild(XMLTags.ROIExpressionTag, vcNamespace);
String roiExp = null;
if (expElement != null) {
roiExp = expElement.getText();
RefinementRoi roi = new RefinementRoi(roiType, level, roiExp);
css.addRefinementRoi(roi);
}
}
}
return css;
} catch (ExpressionException e) {
throw new XmlParseException(e);
}
}
Aggregations