From 3a14e80fb05d550eac1046995c81208bebf6a5c3 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 12 Oct 2011 11:40:57 -0400 Subject: [PATCH] Added Python geometry.xml basic parsing using minidom. --- src/utils/geometry.py | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/utils/geometry.py diff --git a/src/utils/geometry.py b/src/utils/geometry.py new file mode 100644 index 0000000000..396bdafbac --- /dev/null +++ b/src/utils/geometry.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python + +from xml.dom.minidom import parse + +class Geometry(object): + + def __init__(self, filename): + dom = parse(filename) + rootElement = dom.firstChild + + cells = rootElement.getElementsByTagName('cell') + surfaces = rootElement.getElementsByTagName('surfaces') + lattices = rootElement.getElementsByTagName('lattices') + + self.cells = [Cell(elem) for elem in cells] + self.surfaces = [Surface(elem) for elem in surfaces] + self.lattices = [Lattice(elem) for elem in lattices] + + +class Cell(object): + + def __init__(self, domElement): + self.parse(domElement) + + def parse(self, element): + for attribute in ['uid', 'universe', 'fill', 'material', 'surfaces']: + if element.hasAttribute(attribute): + setattr(self, attribute, element.getAttribute(attribute)) + + # Split strings into lists where necessary + if hasattr(self, 'surfaces'): + self.surfaces = self.surfaces.split() + + +class Surface(object): + + def __init__(self, domElement): + self.parse(domElement) + + def parse(self, element): + for attribute in ['uid', 'type', 'coeffs', 'boundary']: + if element.hasAttribute(attribute): + setattr(self, attribute, element.getAttribute(attribute)) + + # Split strings into lists where necessary + if hasattr(self, 'coeffs'): + self.surfaces = self.surfaces.split()