From d244913b4c369ca05f1532688cc317dc36073013 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 13 Jan 2016 13:16:18 -0600 Subject: [PATCH] Replace four source tests with a single comprehensive one. Also fix a few bugs. --- openmc/stats/multivariate.py | 2 +- openmc/stats/univariate.py | 2 +- src/relaxng/settings.rnc | 4 +- src/relaxng/settings.rng | 20 +++-- tests/test_source/inputs_true.dat | 1 + tests/test_source/results_true.dat | 2 + tests/test_source/test_source.py | 73 +++++++++++++++++++ tests/test_source_angle_mono/geometry.xml | 8 -- tests/test_source_angle_mono/materials.xml | 9 --- tests/test_source_angle_mono/results_true.dat | 2 - tests/test_source_angle_mono/settings.xml | 15 ---- .../test_source_angle_mono.py | 11 --- tests/test_source_energy_maxwell/geometry.xml | 8 -- .../test_source_energy_maxwell/materials.xml | 9 --- .../results_true.dat | 2 - tests/test_source_energy_maxwell/settings.xml | 15 ---- .../test_source_energy_maxwell.py | 11 --- tests/test_source_energy_mono/geometry.xml | 8 -- tests/test_source_energy_mono/materials.xml | 9 --- .../test_source_energy_mono/results_true.dat | 2 - tests/test_source_energy_mono/settings.xml | 15 ---- .../test_source_energy_mono.py | 11 --- tests/test_source_point/geometry.xml | 8 -- tests/test_source_point/materials.xml | 9 --- tests/test_source_point/results_true.dat | 2 - tests/test_source_point/settings.xml | 14 ---- tests/test_source_point/test_source_point.py | 11 --- 27 files changed, 89 insertions(+), 194 deletions(-) create mode 100644 tests/test_source/inputs_true.dat create mode 100644 tests/test_source/results_true.dat create mode 100644 tests/test_source/test_source.py delete mode 100644 tests/test_source_angle_mono/geometry.xml delete mode 100644 tests/test_source_angle_mono/materials.xml delete mode 100644 tests/test_source_angle_mono/results_true.dat delete mode 100644 tests/test_source_angle_mono/settings.xml delete mode 100644 tests/test_source_angle_mono/test_source_angle_mono.py delete mode 100644 tests/test_source_energy_maxwell/geometry.xml delete mode 100644 tests/test_source_energy_maxwell/materials.xml delete mode 100644 tests/test_source_energy_maxwell/results_true.dat delete mode 100644 tests/test_source_energy_maxwell/settings.xml delete mode 100644 tests/test_source_energy_maxwell/test_source_energy_maxwell.py delete mode 100644 tests/test_source_energy_mono/geometry.xml delete mode 100644 tests/test_source_energy_mono/materials.xml delete mode 100644 tests/test_source_energy_mono/results_true.dat delete mode 100644 tests/test_source_energy_mono/settings.xml delete mode 100644 tests/test_source_energy_mono/test_source_energy_mono.py delete mode 100644 tests/test_source_point/geometry.xml delete mode 100644 tests/test_source_point/materials.xml delete mode 100644 tests/test_source_point/results_true.dat delete mode 100644 tests/test_source_point/settings.xml delete mode 100644 tests/test_source_point/test_source_point.py diff --git a/openmc/stats/multivariate.py b/openmc/stats/multivariate.py index cb1921ba6d..52dc6b96ab 100644 --- a/openmc/stats/multivariate.py +++ b/openmc/stats/multivariate.py @@ -278,7 +278,7 @@ class SpatialIndependent(Spatial): cv.check_type('y coordinate', y, Univariate) self._y = y - @x.setter + @z.setter def z(self, z): cv.check_type('z coordinate', z, Univariate) self._z = z diff --git a/openmc/stats/univariate.py b/openmc/stats/univariate.py index 8e32fdc1c1..e424d6a3a0 100644 --- a/openmc/stats/univariate.py +++ b/openmc/stats/univariate.py @@ -185,7 +185,7 @@ class Maxwell(Univariate): def to_xml(self): element = ET.Element(self.name) - element.set("type", "uniform") + element.set("type", "maxwell") element.set("parameters", str(self.theta)) return element diff --git a/src/relaxng/settings.rnc b/src/relaxng/settings.rnc index 2fa2b57d82..68f221f677 100644 --- a/src/relaxng/settings.rnc +++ b/src/relaxng/settings.rnc @@ -89,8 +89,8 @@ element settings { distribution = (element type { xsd:string { maxLength = "16" } } | attribute type { xsd:string { maxLength = "16" } }) & - (element interpolation { xsd:string { maxLength = "10" } } | - attribute interpolation { xsd:string { maxLength = "10" } })? & + (element interpolation { xsd:string } | + attribute interpolation { xsd:string })? & (element parameters { list { xsd:double+ } } | attribute parameters { list { xsd:double+ } })? } diff --git a/src/relaxng/settings.rng b/src/relaxng/settings.rng index 72efbe4add..ea3efaff9f 100644 --- a/src/relaxng/settings.rng +++ b/src/relaxng/settings.rng @@ -350,16 +350,18 @@ - - - + + + + + - + - + @@ -410,14 +412,10 @@ - - 10 - + - - 10 - + diff --git a/tests/test_source/inputs_true.dat b/tests/test_source/inputs_true.dat new file mode 100644 index 0000000000..2c2263e4f4 --- /dev/null +++ b/tests/test_source/inputs_true.dat @@ -0,0 +1 @@ +8469cedcf2d3511a80d0f931bc665178ef1bd5b51352dc567385e52c32ad680a1131c8ee079bc022d320c3ea454798afac6b8cac8937a17de92d6cd50d04d72c \ No newline at end of file diff --git a/tests/test_source/results_true.dat b/tests/test_source/results_true.dat new file mode 100644 index 0000000000..18fb895f77 --- /dev/null +++ b/tests/test_source/results_true.dat @@ -0,0 +1,2 @@ +k-combined: +3.014392E-01 7.185055E-03 diff --git a/tests/test_source/test_source.py b/tests/test_source/test_source.py new file mode 100644 index 0000000000..9a398897c9 --- /dev/null +++ b/tests/test_source/test_source.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python + +from math import pi +import os +import sys + +import numpy as np + +sys.path.insert(0, os.pardir) +from testing_harness import PyAPITestHarness +import openmc +import openmc.stats +from openmc.source import Source + + +class SourceTestHarness(PyAPITestHarness): + def _build_inputs(self): + mat1 = openmc.Material(material_id=1) + mat1.set_density('g/cm3', 4.5) + mat1.add_nuclide(openmc.Nuclide('U-235', '71c'), 1.0) + materials = openmc.MaterialsFile() + materials.add_material(mat1) + materials.export_to_xml() + + sphere = openmc.Sphere(surface_id=1, R=10.0, boundary_type='vacuum') + inside_sphere = openmc.Cell(cell_id=1) + inside_sphere.region = -sphere + inside_sphere.fill = mat1 + + root = openmc.Universe(universe_id=0) + root.add_cell(inside_sphere) + geometry = openmc.Geometry() + geometry.root_universe = root + geometry_xml = openmc.GeometryFile() + geometry_xml.geometry = geometry + geometry_xml.export_to_xml() + + # Create an array of different sources + x_dist = openmc.stats.Uniform('x', -3., 3.) + y_dist = openmc.stats.Discrete('y', [-4., -1., 3.], [0.2, 0.3, 0.5]) + z_dist = openmc.stats.Tabular('z', [-2., 0., 2.], [0.2, 0.3, 0.2]) + spatial1 = openmc.stats.SpatialIndependent(x_dist, y_dist, z_dist) + spatial2 = openmc.stats.SpatialBox([-4., -4., -4.], [4., 4., 4.]) + spatial3 = openmc.stats.SpatialPoint([1.2, -2.3, 0.781]) + + mu_dist = openmc.stats.Discrete('mu', [-1., 0., 1.], [0.5, 0.25, 0.25]) + phi_dist = openmc.stats.Uniform('phi', 0., 2.*pi) + angle1 = openmc.stats.PolarAzimuthal(mu_dist, phi_dist) + angle2 = openmc.stats.Monodirectional(reference_uvw=[0., 1., 0.]) + angle3 = openmc.stats.Isotropic() + + E = np.logspace(-6, 1) + p = np.sin(np.linspace(0., pi)) + p /= sum(np.diff(E)*p[:-1]) + energy1 = openmc.stats.Maxwell(1.2895) + energy2 = openmc.stats.Watt(0.988, 2.249) + energy3 = openmc.stats.Tabular('energy', E, p, interpolation='histogram') + + source1 = Source(spatial1, angle1, energy1, strength=0.5) + source2 = Source(spatial2, angle2, energy2, strength=0.3) + source3 = Source(spatial3, angle3, energy3, strength=0.2) + + settings = openmc.SettingsFile() + settings.batches = 10 + settings.inactive = 5 + settings.particles = 1000 + settings.source = [source1, source2, source3] + settings.export_to_xml() + + +if __name__ == '__main__': + harness = SourceTestHarness('statepoint.10.h5') + harness.main() diff --git a/tests/test_source_angle_mono/geometry.xml b/tests/test_source_angle_mono/geometry.xml deleted file mode 100644 index bc56030e18..0000000000 --- a/tests/test_source_angle_mono/geometry.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/tests/test_source_angle_mono/materials.xml b/tests/test_source_angle_mono/materials.xml deleted file mode 100644 index 315c0fa848..0000000000 --- a/tests/test_source_angle_mono/materials.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/tests/test_source_angle_mono/results_true.dat b/tests/test_source_angle_mono/results_true.dat deleted file mode 100644 index 42e948758a..0000000000 --- a/tests/test_source_angle_mono/results_true.dat +++ /dev/null @@ -1,2 +0,0 @@ -k-combined: -2.964943E-01 1.201478E-02 diff --git a/tests/test_source_angle_mono/settings.xml b/tests/test_source_angle_mono/settings.xml deleted file mode 100644 index dd88bbad29..0000000000 --- a/tests/test_source_angle_mono/settings.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - 10 - 5 - 1000 - - - - - - - - diff --git a/tests/test_source_angle_mono/test_source_angle_mono.py b/tests/test_source_angle_mono/test_source_angle_mono.py deleted file mode 100644 index 2a595f3e66..0000000000 --- a/tests/test_source_angle_mono/test_source_angle_mono.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -sys.path.insert(0, os.pardir) -from testing_harness import TestHarness - - -if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') - harness.main() diff --git a/tests/test_source_energy_maxwell/geometry.xml b/tests/test_source_energy_maxwell/geometry.xml deleted file mode 100644 index bc56030e18..0000000000 --- a/tests/test_source_energy_maxwell/geometry.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/tests/test_source_energy_maxwell/materials.xml b/tests/test_source_energy_maxwell/materials.xml deleted file mode 100644 index 315c0fa848..0000000000 --- a/tests/test_source_energy_maxwell/materials.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/tests/test_source_energy_maxwell/results_true.dat b/tests/test_source_energy_maxwell/results_true.dat deleted file mode 100644 index 37b8b36b99..0000000000 --- a/tests/test_source_energy_maxwell/results_true.dat +++ /dev/null @@ -1,2 +0,0 @@ -k-combined: -2.886671E-01 7.534631E-03 diff --git a/tests/test_source_energy_maxwell/settings.xml b/tests/test_source_energy_maxwell/settings.xml deleted file mode 100644 index d0543785b5..0000000000 --- a/tests/test_source_energy_maxwell/settings.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - 10 - 5 - 1000 - - - - - - - - diff --git a/tests/test_source_energy_maxwell/test_source_energy_maxwell.py b/tests/test_source_energy_maxwell/test_source_energy_maxwell.py deleted file mode 100644 index 2a595f3e66..0000000000 --- a/tests/test_source_energy_maxwell/test_source_energy_maxwell.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -sys.path.insert(0, os.pardir) -from testing_harness import TestHarness - - -if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') - harness.main() diff --git a/tests/test_source_energy_mono/geometry.xml b/tests/test_source_energy_mono/geometry.xml deleted file mode 100644 index bc56030e18..0000000000 --- a/tests/test_source_energy_mono/geometry.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/tests/test_source_energy_mono/materials.xml b/tests/test_source_energy_mono/materials.xml deleted file mode 100644 index 315c0fa848..0000000000 --- a/tests/test_source_energy_mono/materials.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/tests/test_source_energy_mono/results_true.dat b/tests/test_source_energy_mono/results_true.dat deleted file mode 100644 index 029376bf37..0000000000 --- a/tests/test_source_energy_mono/results_true.dat +++ /dev/null @@ -1,2 +0,0 @@ -k-combined: -3.002731E-01 7.561170E-03 diff --git a/tests/test_source_energy_mono/settings.xml b/tests/test_source_energy_mono/settings.xml deleted file mode 100644 index be271b6113..0000000000 --- a/tests/test_source_energy_mono/settings.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - 10 - 5 - 1000 - - - - - - - - diff --git a/tests/test_source_energy_mono/test_source_energy_mono.py b/tests/test_source_energy_mono/test_source_energy_mono.py deleted file mode 100644 index 2a595f3e66..0000000000 --- a/tests/test_source_energy_mono/test_source_energy_mono.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -sys.path.insert(0, os.pardir) -from testing_harness import TestHarness - - -if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') - harness.main() diff --git a/tests/test_source_point/geometry.xml b/tests/test_source_point/geometry.xml deleted file mode 100644 index bc56030e18..0000000000 --- a/tests/test_source_point/geometry.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/tests/test_source_point/materials.xml b/tests/test_source_point/materials.xml deleted file mode 100644 index 315c0fa848..0000000000 --- a/tests/test_source_point/materials.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/tests/test_source_point/results_true.dat b/tests/test_source_point/results_true.dat deleted file mode 100644 index fe9a0d78d4..0000000000 --- a/tests/test_source_point/results_true.dat +++ /dev/null @@ -1,2 +0,0 @@ -k-combined: -3.041148E-01 4.558319E-03 diff --git a/tests/test_source_point/settings.xml b/tests/test_source_point/settings.xml deleted file mode 100644 index 3b3c47150e..0000000000 --- a/tests/test_source_point/settings.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - 10 - 5 - 1000 - - - - - - - diff --git a/tests/test_source_point/test_source_point.py b/tests/test_source_point/test_source_point.py deleted file mode 100644 index 2a595f3e66..0000000000 --- a/tests/test_source_point/test_source_point.py +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -sys.path.insert(0, os.pardir) -from testing_harness import TestHarness - - -if __name__ == '__main__': - harness = TestHarness('statepoint.10.*') - harness.main()