Search in sources :

Example 1 with RoiType

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);
    }
}
Also used : UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) TimeInterval(org.vcell.chombo.TimeInterval) Element(org.jdom.Element) ChomboSolverSpec(org.vcell.chombo.ChomboSolverSpec) GeometryException(cbit.vcell.geometry.GeometryException) MathFormatException(cbit.vcell.math.MathFormatException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) DataConversionException(org.jdom.DataConversionException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) ExpressionException(cbit.vcell.parser.ExpressionException) RefinementRoi(org.vcell.chombo.RefinementRoi) StringTokenizer(java.util.StringTokenizer) RoiType(org.vcell.chombo.RefinementRoi.RoiType)

Aggregations

ImageException (cbit.image.ImageException)1 GeometryException (cbit.vcell.geometry.GeometryException)1 MappingException (cbit.vcell.mapping.MappingException)1 MathException (cbit.vcell.math.MathException)1 MathFormatException (cbit.vcell.math.MathFormatException)1 ModelException (cbit.vcell.model.ModelException)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)1 PropertyVetoException (java.beans.PropertyVetoException)1 StringTokenizer (java.util.StringTokenizer)1 DataConversionException (org.jdom.DataConversionException)1 Element (org.jdom.Element)1 ChomboSolverSpec (org.vcell.chombo.ChomboSolverSpec)1 RefinementRoi (org.vcell.chombo.RefinementRoi)1 RoiType (org.vcell.chombo.RefinementRoi.RoiType)1 TimeInterval (org.vcell.chombo.TimeInterval)1