mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Added Python geometry.xml basic parsing using minidom.
This commit is contained in:
parent
db6bc7f3fd
commit
3a14e80fb0
1 changed files with 47 additions and 0 deletions
47
src/utils/geometry.py
Normal file
47
src/utils/geometry.py
Normal file
|
|
@ -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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue