mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-29 06:35:48 -04:00
Merge branch 'develop' into cam_WP7_task3
This commit is contained in:
commit
c679f8e8e1
33 changed files with 1746 additions and 903 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from collections.abc import Mapping, Callable
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
|
@ -144,3 +145,9 @@ def test_export_to_hdf5(tmpdir, element):
|
|||
element2.bremsstrahlung['electron_energy']).all()
|
||||
# Export to hdf5 again
|
||||
element2.export_to_hdf5(filename, 'w')
|
||||
|
||||
def test_photodat_only(run_in_tmpdir):
|
||||
endf_dir = Path(os.environ['OPENMC_ENDF_DATA'])
|
||||
photoatomic_file = endf_dir / 'photoat' / 'photoat-001_H_000.endf'
|
||||
data = openmc.data.IncidentPhoton.from_endf(photoatomic_file)
|
||||
data.export_to_hdf5('tmp.h5', 'w')
|
||||
|
|
@ -149,12 +149,18 @@ def test_fission_yield_distribution():
|
|||
# __getitem__ return yields as a view into yield matrix
|
||||
assert orig_yields.yields.base is yield_dist.yield_matrix
|
||||
|
||||
# Fission yield feature uses scaled and incremented
|
||||
# Scale and increment fission yields
|
||||
mod_yields = orig_yields * 2
|
||||
assert numpy.array_equal(orig_yields.yields * 2, mod_yields.yields)
|
||||
mod_yields += orig_yields
|
||||
assert numpy.array_equal(orig_yields.yields * 3, mod_yields.yields)
|
||||
|
||||
mod_yields = 2.0 * orig_yields
|
||||
assert numpy.array_equal(orig_yields.yields * 2, mod_yields.yields)
|
||||
|
||||
mod_yields = numpy.float64(2.0) * orig_yields
|
||||
assert numpy.array_equal(orig_yields.yields * 2, mod_yields.yields)
|
||||
|
||||
# Failure modes for adding, multiplying yields
|
||||
similar = numpy.empty_like(orig_yields.yields)
|
||||
with pytest.raises(TypeError):
|
||||
|
|
|
|||
|
|
@ -34,3 +34,11 @@ def test_source_file():
|
|||
elem = src.to_xml_element()
|
||||
assert 'strength' in elem.attrib
|
||||
assert 'file' in elem.attrib
|
||||
|
||||
def test_source_dlopen():
|
||||
library = './libsource.so'
|
||||
src = openmc.Source(library=library)
|
||||
assert src.library == library
|
||||
|
||||
elem = src.to_xml_element()
|
||||
assert 'library' in elem.attrib
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ from functools import partial
|
|||
from random import uniform, seed
|
||||
|
||||
import numpy as np
|
||||
import math
|
||||
import openmc
|
||||
import pytest
|
||||
|
||||
|
|
@ -139,6 +140,51 @@ def test_zplane():
|
|||
repr(s)
|
||||
|
||||
|
||||
def test_cylinder():
|
||||
x0, y0, z0, r = 2, 3, 4, 2
|
||||
dx, dy, dz = 1, -1, 1
|
||||
s = openmc.Cylinder(x0=x0, y0=y0, z0=z0, dx=dx, dy=dy, dz=dz, r=r)
|
||||
assert s.x0 == 2
|
||||
assert s.y0 == 3
|
||||
assert s.z0 == 4
|
||||
assert s.dx == 1
|
||||
assert s.dy == -1
|
||||
assert s.dz == 1
|
||||
assert s.r == 2
|
||||
|
||||
# Check bounding box
|
||||
assert_infinite_bb(s)
|
||||
|
||||
# evaluate method
|
||||
# |(p - p1) ⨯ (p - p2)|^2 / |p2 - p1|^2 - r^2
|
||||
p1 = s._origin
|
||||
p2 = p1 + s._axis
|
||||
perp = np.array((1, -2, 1))*(1 / s._axis)
|
||||
divisor = np.linalg.norm(p2 - p1)
|
||||
pin = p1 + 5*s._axis # point inside cylinder
|
||||
pout = np.array((4., 0., 2.5)) # point outside the cylinder
|
||||
pon = p1 + s.r*perp / np.linalg.norm(perp) # point on cylinder
|
||||
for p, fn in zip((pin, pout, pon), (np.less, np.greater, np.isclose)):
|
||||
c1 = np.linalg.norm(np.cross(p - p1, p - p2)) / divisor
|
||||
val = c1*c1 - s.r*s.r
|
||||
p_eval = s.evaluate(p)
|
||||
assert fn(p_eval, 0.)
|
||||
assert p_eval == pytest.approx(val)
|
||||
|
||||
# translate method
|
||||
st = s.translate((1.0, 1.0, 1.0))
|
||||
assert st.x0 == s.x0 + 1
|
||||
assert st.y0 == s.y0 + 1
|
||||
assert st.z0 == s.z0 + 1
|
||||
assert st.dx == s.dx
|
||||
assert st.dy == s.dy
|
||||
assert st.dz == s.dz
|
||||
assert st.r == s.r
|
||||
|
||||
# Make sure repr works
|
||||
repr(s)
|
||||
|
||||
|
||||
def test_xcylinder():
|
||||
y, z, r = 3, 5, 2
|
||||
s = openmc.XCylinder(y0=y, z0=z, r=r)
|
||||
|
|
@ -284,6 +330,58 @@ def cone_common(apex, r2, cls):
|
|||
repr(s)
|
||||
|
||||
|
||||
def test_cone():
|
||||
x0, y0, z0, r2 = 2, 3, 4, 4
|
||||
dx, dy, dz = 1, -1, 1
|
||||
s = openmc.Cone(x0=x0, y0=y0, z0=z0, dx=dx, dy=dy, dz=dz, r2=r2)
|
||||
assert s.x0 == 2
|
||||
assert s.y0 == 3
|
||||
assert s.z0 == 4
|
||||
assert s.dx == 1
|
||||
assert s.dy == -1
|
||||
assert s.dz == 1
|
||||
assert s.r2 == 4
|
||||
|
||||
# Check bounding box
|
||||
assert_infinite_bb(s)
|
||||
|
||||
# evaluate method
|
||||
# cos^2(theta) * ((p - p1))**2 - (d @ (p - p1))^2
|
||||
# The argument r2 for cones is actually tan^2(theta) so that
|
||||
# cos^2(theta) = 1 / (1 + r2)
|
||||
#
|
||||
# This makes the evaluation equation shown below where p is the evaluation
|
||||
# point (x, y, z) p1 is the apex (origin) of the cone and r2 is related to
|
||||
# the aperature of the cone as described above
|
||||
# (p - p1) @ (p - p1) / (1 + r2) - (d @ (p - p1))^2
|
||||
# point inside
|
||||
p1 = s._origin
|
||||
d = s._axis
|
||||
perp = np.array((1, -2, 1))*(1 / d)
|
||||
perp /= np.linalg.norm(perp)
|
||||
pin = p1 + 5*d # point inside cone
|
||||
pout = p1 + 3.2*perp # point outside cone
|
||||
pon = p1 + 3.2*d + 3.2*math.sqrt(s.r2)*perp # point on cone
|
||||
for p, fn in zip((pin, pout, pon), (np.less, np.greater, np.isclose)):
|
||||
val = np.sum((p - p1)**2) / (1 + s.r2) - np.sum((d @ (p - p1))**2)
|
||||
p_eval = s.evaluate(p)
|
||||
assert fn(p_eval, 0.)
|
||||
assert p_eval == pytest.approx(val)
|
||||
|
||||
# translate method
|
||||
st = s.translate((1.0, 1.0, 1.0))
|
||||
assert st.x0 == s.x0 + 1
|
||||
assert st.y0 == s.y0 + 1
|
||||
assert st.z0 == s.z0 + 1
|
||||
assert st.dx == s.dx
|
||||
assert st.dy == s.dy
|
||||
assert st.dz == s.dz
|
||||
assert st.r2 == s.r2
|
||||
|
||||
# Make sure repr works
|
||||
repr(s)
|
||||
|
||||
|
||||
def test_xcone():
|
||||
apex = (10, 0, 0)
|
||||
r2 = 4
|
||||
|
|
@ -339,7 +437,7 @@ def test_cylinder_from_points():
|
|||
p1 = np.array([xi(), xi(), xi()])
|
||||
p2 = np.array([xi(), xi(), xi()])
|
||||
r = uniform(1.0, 100.0)
|
||||
s = openmc.model.cylinder_from_points(p1, p2, r)
|
||||
s = openmc.Cylinder.from_points(p1, p2, r)
|
||||
|
||||
# Points p1 and p2 need to be inside cylinder
|
||||
assert p1 in -s
|
||||
|
|
@ -369,24 +467,27 @@ def test_cylinder_from_points_axis():
|
|||
|
||||
# (x - 3)^2 + (y - 4)^2 = 2^2
|
||||
# x^2 + y^2 - 6x - 8y + 21 = 0
|
||||
s = openmc.model.cylinder_from_points((3., 4., 0.), (3., 4., 1.), 2.)
|
||||
assert (s.a, s.b, s.c) == pytest.approx((1., 1., 0.))
|
||||
assert (s.d, s.e, s.f) == pytest.approx((0., 0., 0.))
|
||||
assert (s.g, s.h, s.j) == pytest.approx((-6., -8., 0.))
|
||||
assert s.k == pytest.approx(21.)
|
||||
s = openmc.Cylinder.from_points((3., 4., 0.), (3., 4., 1.), 2.)
|
||||
a, b, c, d, e, f, g, h, j, k = s._get_base_coeffs()
|
||||
assert (a, b, c) == pytest.approx((1., 1., 0.))
|
||||
assert (d, e, f) == pytest.approx((0., 0., 0.))
|
||||
assert (g, h, j) == pytest.approx((-6., -8., 0.))
|
||||
assert k == pytest.approx(21.)
|
||||
|
||||
# (y + 7)^2 + (z - 1)^2 = 3^2
|
||||
# y^2 + z^2 + 14y - 2z + 41 = 0
|
||||
s = openmc.model.cylinder_from_points((0., -7, 1.), (1., -7., 1.), 3.)
|
||||
assert (s.a, s.b, s.c) == pytest.approx((0., 1., 1.))
|
||||
assert (s.d, s.e, s.f) == pytest.approx((0., 0., 0.))
|
||||
assert (s.g, s.h, s.j) == pytest.approx((0., 14., -2.))
|
||||
assert s.k == 41.
|
||||
s = openmc.Cylinder.from_points((0., -7, 1.), (1., -7., 1.), 3.)
|
||||
a, b, c, d, e, f, g, h, j, k = s._get_base_coeffs()
|
||||
assert (a, b, c) == pytest.approx((0., 1., 1.))
|
||||
assert (d, e, f) == pytest.approx((0., 0., 0.))
|
||||
assert (g, h, j) == pytest.approx((0., 14., -2.))
|
||||
assert k == 41.
|
||||
|
||||
# (x - 2)^2 + (z - 5)^2 = 4^2
|
||||
# x^2 + z^2 - 4x - 10z + 13 = 0
|
||||
s = openmc.model.cylinder_from_points((2., 0., 5.), (2., 1., 5.), 4.)
|
||||
assert (s.a, s.b, s.c) == pytest.approx((1., 0., 1.))
|
||||
assert (s.d, s.e, s.f) == pytest.approx((0., 0., 0.))
|
||||
assert (s.g, s.h, s.j) == pytest.approx((-4., 0., -10.))
|
||||
assert s.k == pytest.approx(13.)
|
||||
s = openmc.Cylinder.from_points((2., 0., 5.), (2., 1., 5.), 4.)
|
||||
a, b, c, d, e, f, g, h, j, k = s._get_base_coeffs()
|
||||
assert (a, b, c) == pytest.approx((1., 0., 1.))
|
||||
assert (d, e, f) == pytest.approx((0., 0., 0.))
|
||||
assert (g, h, j) == pytest.approx((-4., 0., -10.))
|
||||
assert k == pytest.approx(13.)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue