2022-05-25 16:39:42 +02:00
|
|
|
from math import pi, cos
|
2016-01-13 13:16:18 -06:00
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
import openmc
|
|
|
|
|
|
2018-01-29 10:53:46 -06:00
|
|
|
from tests.testing_harness import PyAPITestHarness
|
|
|
|
|
|
2016-01-13 13:16:18 -06:00
|
|
|
|
|
|
|
|
class SourceTestHarness(PyAPITestHarness):
|
2023-02-28 11:31:04 -05:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super().__init__(*args, **kwargs)
|
2016-09-13 23:16:10 +02:00
|
|
|
mat1 = openmc.Material(material_id=1, temperature=294)
|
2016-01-13 13:16:18 -06:00
|
|
|
mat1.set_density('g/cm3', 4.5)
|
2025-01-24 16:49:58 -06:00
|
|
|
mat1.add_nuclide('U235', 1.0)
|
2023-02-28 11:31:04 -05:00
|
|
|
self._model.materials = openmc.Materials([mat1])
|
2016-01-13 13:16:18 -06:00
|
|
|
|
2019-03-08 11:25:26 -06:00
|
|
|
sphere = openmc.Sphere(surface_id=1, r=10.0, boundary_type='vacuum')
|
2016-01-13 13:16:18 -06:00
|
|
|
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)
|
2023-02-28 11:31:04 -05:00
|
|
|
self._model.geometry = openmc.Geometry(root)
|
2016-01-13 13:16:18 -06:00
|
|
|
|
|
|
|
|
# Create an array of different sources
|
2016-01-14 06:46:32 -06:00
|
|
|
x_dist = openmc.stats.Uniform(-3., 3.)
|
|
|
|
|
y_dist = openmc.stats.Discrete([-4., -1., 3.], [0.2, 0.3, 0.5])
|
|
|
|
|
z_dist = openmc.stats.Tabular([-2., 0., 2.], [0.2, 0.3, 0.2])
|
2019-11-04 17:27:50 -05:00
|
|
|
r_dist = openmc.stats.Uniform(2., 3.)
|
2021-10-11 19:48:15 +00:00
|
|
|
r_dist1 = openmc.stats.PowerLaw(2., 3., 1.)
|
|
|
|
|
r_dist2 = openmc.stats.PowerLaw(2., 3., 2.)
|
2022-05-25 16:39:42 +02:00
|
|
|
cos_theta_dist = openmc.stats.Discrete([cos(pi/4), 0.0, cos(3*pi/4)],
|
|
|
|
|
[0.3, 0.4, 0.3])
|
2019-11-04 17:27:50 -05:00
|
|
|
phi_dist = openmc.stats.Uniform(0.0, 2*pi)
|
2016-01-15 06:29:41 -06:00
|
|
|
spatial1 = openmc.stats.CartesianIndependent(x_dist, y_dist, z_dist)
|
|
|
|
|
spatial2 = openmc.stats.Box([-4., -4., -4.], [4., 4., 4.])
|
|
|
|
|
spatial3 = openmc.stats.Point([1.2, -2.3, 0.781])
|
2022-05-25 16:39:42 +02:00
|
|
|
spatial4 = openmc.stats.SphericalIndependent(r_dist, cos_theta_dist,
|
2023-02-13 09:00:33 -06:00
|
|
|
phi_dist,
|
2019-12-31 12:11:49 -05:00
|
|
|
origin=(1., 1., 0.))
|
2023-02-13 09:00:33 -06:00
|
|
|
spatial5 = openmc.stats.CylindricalIndependent(r_dist, phi_dist,
|
2019-12-31 12:11:49 -05:00
|
|
|
z_dist,
|
|
|
|
|
origin=(1., 1., 0.))
|
2022-05-25 16:39:42 +02:00
|
|
|
spatial6 = openmc.stats.SphericalIndependent(r_dist2, cos_theta_dist,
|
2023-02-13 09:00:33 -06:00
|
|
|
phi_dist,
|
2021-10-05 20:06:41 +00:00
|
|
|
origin=(1., 1., 0.))
|
2023-02-13 09:00:33 -06:00
|
|
|
spatial7 = openmc.stats.CylindricalIndependent(r_dist1, phi_dist,
|
2021-10-05 20:06:41 +00:00
|
|
|
z_dist,
|
|
|
|
|
origin=(1., 1., 0.))
|
2016-01-13 13:16:18 -06:00
|
|
|
|
2016-01-14 06:46:32 -06:00
|
|
|
mu_dist = openmc.stats.Discrete([-1., 0., 1.], [0.5, 0.25, 0.25])
|
|
|
|
|
phi_dist = openmc.stats.Uniform(0., 6.28318530718)
|
2016-01-13 13:16:18 -06:00
|
|
|
angle1 = openmc.stats.PolarAzimuthal(mu_dist, phi_dist)
|
|
|
|
|
angle2 = openmc.stats.Monodirectional(reference_uvw=[0., 1., 0.])
|
|
|
|
|
angle3 = openmc.stats.Isotropic()
|
|
|
|
|
|
2023-02-13 09:00:33 -06:00
|
|
|
# Note that the definition for E is equivalent to logspace(0, 7) but we
|
|
|
|
|
# manually take powers because of last-digit differences that may cause
|
|
|
|
|
# test failures with different versions of numpy
|
|
|
|
|
E = np.array([10**x for x in np.linspace(0, 7)])
|
2016-01-13 13:16:18 -06:00
|
|
|
p = np.sin(np.linspace(0., pi))
|
|
|
|
|
p /= sum(np.diff(E)*p[:-1])
|
2016-10-28 10:04:47 -05:00
|
|
|
energy1 = openmc.stats.Maxwell(1.2895e6)
|
|
|
|
|
energy2 = openmc.stats.Watt(0.988e6, 2.249e-6)
|
2016-01-14 06:46:32 -06:00
|
|
|
energy3 = openmc.stats.Tabular(E, p, interpolation='histogram')
|
2021-09-29 17:10:49 +02:00
|
|
|
energy4 = openmc.stats.Mixture([1, 2, 3], [energy1, energy2, energy3])
|
2016-01-13 13:16:18 -06:00
|
|
|
|
2021-12-29 13:06:52 +01:00
|
|
|
time1 = openmc.stats.Uniform(2, 5)
|
|
|
|
|
|
2023-06-20 21:27:55 -05:00
|
|
|
source1 = openmc.IndependentSource(spatial1, angle1, energy1, strength=0.3)
|
|
|
|
|
source2 = openmc.IndependentSource(spatial2, angle2, energy2, strength=0.1)
|
|
|
|
|
source3 = openmc.IndependentSource(spatial3, angle3, energy3, strength=0.1)
|
|
|
|
|
source4 = openmc.IndependentSource(spatial4, angle3, energy3, strength=0.1)
|
|
|
|
|
source5 = openmc.IndependentSource(spatial5, angle3, energy3, strength=0.1)
|
|
|
|
|
source6 = openmc.IndependentSource(spatial5, angle3, energy4, strength=0.1)
|
|
|
|
|
source7 = openmc.IndependentSource(spatial6, angle3, energy4, time1, strength=0.1)
|
|
|
|
|
source8 = openmc.IndependentSource(spatial7, angle3, energy4, time1, strength=0.1)
|
2016-01-13 13:16:18 -06:00
|
|
|
|
2016-04-25 10:37:06 -05:00
|
|
|
settings = openmc.Settings()
|
2016-01-13 13:16:18 -06:00
|
|
|
settings.batches = 10
|
|
|
|
|
settings.inactive = 5
|
|
|
|
|
settings.particles = 1000
|
2021-10-05 20:06:41 +00:00
|
|
|
settings.source = [source1, source2, source3, source4, source5, source6, source7, source8]
|
2023-02-28 11:31:04 -05:00
|
|
|
self._model.settings = settings
|
2016-01-13 13:16:18 -06:00
|
|
|
|
|
|
|
|
|
2018-01-29 12:10:24 -06:00
|
|
|
def test_source():
|
2023-02-28 11:31:04 -05:00
|
|
|
harness = SourceTestHarness('statepoint.10.h5', model=openmc.Model())
|
2016-01-13 13:16:18 -06:00
|
|
|
harness.main()
|