Commit 489a03c6 authored by Amanda Lund's avatar Amanda Lund

Get value from either attribute or element when reading settings from XML

parent 7ca270be
......@@ -7,6 +7,7 @@ import numpy as np
import openmc.checkvalue as cv
import openmc
from openmc._xml import get_text
from openmc.mixin import EqualityMixin, IDManagerMixin
......@@ -261,23 +262,23 @@ class Mesh(IDManagerMixin):
Mesh generated from XML element
"""
mesh_id = int(elem.get('id'))
mesh_id = int(get_text(elem, 'id'))
mesh = cls(mesh_id)
mesh.type = elem.get('type')
mesh.type = get_text(elem, 'type')
dimension = elem.findtext('dimension')
dimension = get_text(elem, 'dimension')
if dimension is not None:
mesh.dimension = [int(x) for x in dimension.split()]
lower_left = elem.findtext('lower_left')
lower_left = get_text(elem, 'lower_left')
if lower_left is not None:
mesh.lower_left = [float(x) for x in lower_left.split()]
upper_right = elem.findtext('upper_right')
upper_right = get_text(elem, 'upper_right')
if upper_right is not None:
mesh.upper_right = [float(x) for x in upper_right.split()]
width = elem.findtext('width')
width = get_text(elem, 'width')
if width is not None:
mesh.width = [float(x) for x in width.split()]
......
This diff is collapsed.
......@@ -2,6 +2,7 @@ from numbers import Real
import sys
from xml.etree import ElementTree as ET
from openmc._xml import get_text
from openmc.stats.univariate import (Univariate, Discrete, Uniform, Maxwell,
Watt, Normal, Muir, Tabular)
from openmc.stats.multivariate import (UnitSphere, Spatial, PolarAzimuthal,
......@@ -158,21 +159,21 @@ class Source(object):
"""
source = cls()
strength = elem.find('strength')
strength = get_text(elem, 'strength')
if strength is not None:
source.strength = float(strength.text)
source.strength = float(strength)
particle = elem.find('particle')
particle = get_text(elem, 'particle')
if particle is not None:
source.particle = particle.text
source.particle = particle
filename = elem.find('file')
filename = get_text(elem, 'file')
if filename is not None:
source.file = filename.text
source.file = filename
space = elem.find('space')
if space is not None:
space_type = space.get('type')
space_type = get_text(space, 'type')
if space_type == 'cartesian':
source.space = CartesianIndependent.from_xml_element(space)
elif space_type == 'box' or space_type == 'fission':
......@@ -182,7 +183,7 @@ class Source(object):
angle = elem.find('angle')
if angle is not None:
angle_type = angle.get('type')
angle_type = get_text(angle, 'type')
if angle_type == 'mu-phi':
source.angle = PolarAzimuthal.from_xml_element(angle)
elif angle_type == 'isotropic':
......@@ -192,7 +193,7 @@ class Source(object):
energy = elem.find('energy')
if energy is not None:
energy_type = energy.get('type')
energy_type = get_text(energy, 'type')
if energy_type == 'discrete':
source.energy = Discrete.from_xml_element(energy)
elif energy_type == 'uniform':
......
......@@ -8,6 +8,7 @@ from xml.etree import ElementTree as ET
import numpy as np
import openmc.checkvalue as cv
from openmc._xml import get_text
from openmc.stats.univariate import Univariate, Uniform
......@@ -142,7 +143,7 @@ class PolarAzimuthal(UnitSphere):
"""
mu_phi = cls()
params = elem.findtext('parameters')
params = get_text(elem, 'parameters')
if params is not None:
mu_phi.reference_uvw = [float(x) for x in params.split()]
mu_phi.mu = openmc.stats.Univariate.from_xml_element(elem.find('mu'))
......@@ -239,7 +240,7 @@ class Monodirectional(UnitSphere):
"""
monodirectional = cls()
params = elem.findtext('parameters')
params = get_text(elem, 'parameters')
if params is not None:
monodirectional.reference_uvw = [float(x) for x in params.split()]
return monodirectional
......@@ -457,10 +458,10 @@ class Box(Spatial):
Box distribution generated from XML element
"""
only_fissionable = elem.get('type') == 'fission'
params = [float(x) for x in elem.findtext('parameters').split()]
only_fissionable = get_text(elem, 'type') == 'fission'
params = [float(x) for x in get_text(elem, 'parameters').split()]
lower_left = params[:len(params)//2]
upper_right = paramx[len(params)//2:]
upper_right = params[len(params)//2:]
return cls(lower_left, upper_right, only_fissionable)
......@@ -526,5 +527,5 @@ class Point(Spatial):
Point distribution generated from XML element
"""
xyz = [float(x) for x in elem.findtext('parameters').split()]
xyz = [float(x) for x in get_text(elem, 'parameters').split()]
return cls(xyz)
......@@ -7,6 +7,7 @@ from xml.etree import ElementTree as ET
import numpy as np
import openmc.checkvalue as cv
from openmc._xml import get_text
from openmc.mixin import EqualityMixin
......@@ -130,7 +131,7 @@ class Discrete(Univariate):
Discrete distribution generated from XML element
"""
params = [float(x) for x in elem.findtext('parameters').split()]
params = [float(x) for x in get_text(elem, 'parameters').split()]
x = params[:len(params)//2]
p = params[len(params)//2:]
return cls(x, p)
......@@ -221,7 +222,7 @@ class Uniform(Univariate):
Uniform distribution generated from XML element
"""
params = elem.findtext('parameters').split()
params = get_text(elem, 'parameters').split()
a = float(params[0])
b = float(params[1])
return cls(a, b)
......@@ -297,7 +298,7 @@ class Maxwell(Univariate):
Maxwellian distribution generated from XML element
"""
theta = float(elem.findtext('parameters'))
theta = float(get_text(elem, 'parameters'))
return cls(theta)
......@@ -386,7 +387,7 @@ class Watt(Univariate):
Watt distribution generated from XML element
"""
params = elem.findtext('parameters').split()
params = get_text(elem, 'parameters').split()
a = float(params[0])
b = float(params[1])
return watt(a, b)
......@@ -476,7 +477,7 @@ class Normal(Univariate):
Normal distribution generated from XML element
"""
params = elem.findtext('parameters').split()
params = get_text(elem, 'parameters').split()
mean_value = float(params[0])
std_dev = float(params[1])
return cls(mean_value, std_dev)
......@@ -585,7 +586,7 @@ class Muir(Univariate):
Muir distribution generated from XML element
"""
params = elem.findtext('parameters').split()
params = get_text(elem, 'parameters').split()
e0 = float(params[0])
m_rat = float(params[1])
kt = float(params[2])
......@@ -702,8 +703,8 @@ class Tabular(Univariate):
Tabular distribution generated from XML element
"""
interpolation = elem.get('interpolation')
params = [float(x) for x in elem.findtext('parameters').split()]
interpolation = get_text(elem, 'interpolation')
params = [float(x) for x in get_text(elem, 'parameters').split()]
x = params[:len(params)//2]
p = paramx[len(params)//2:]
return cls(x, p, interpolation)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment