本文整理汇总了Python中pyne.mesh.Mesh.src[0]方法的典型用法代码示例。如果您正苦于以下问题:Python Mesh.src[0]方法的具体用法?Python Mesh.src[0]怎么用?Python Mesh.src[0]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyne.mesh.Mesh
的用法示例。
在下文中一共展示了Mesh.src[0]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_analog_single_hex
# 需要导入模块: from pyne.mesh import Mesh [as 别名]
# 或者: from pyne.mesh.Mesh import src[0] [as 别名]
def test_analog_single_hex():
"""This test tests that particles of sampled evenly within the phase-space
of a single mesh volume element with one energy group in an analog sampling
scheme. This done by dividing each dimension (x, y, z, E) in half, then
sampling particles and tallying on the basis of which of the 2^4 = 8 regions
of phase space the particle is born into.
"""
seed(1953)
m = Mesh(structured=True, structured_coords=[[0, 1], [0, 1], [0, 1]], mats=None)
m.src = IMeshTag(1, float)
m.src[0] = 1.0
m.mesh.save("sampling_mesh.h5m")
sampler = Sampler("sampling_mesh.h5m", "src", np.array([0, 1]), False)
num_samples = 5000
score = 1.0 / num_samples
num_divs = 2
tally = np.zeros(shape=(num_divs, num_divs, num_divs, num_divs))
for i in range(num_samples):
s = sampler.particle_birth(np.array([uniform(0, 1) for x in range(6)]))
assert_equal(s[4], 1.0) # analog: all weights must be one
tally[int(s[0] * num_divs), int(s[1] * num_divs), int(s[2] * num_divs), int(s[3] * num_divs)] += score
# Test that each half-space of phase space (e.g. x > 0.5) is sampled about
# half the time.
for i in range(0, 4):
for j in range(0, 2):
assert abs(np.sum(np.rollaxis(tally, i)[j, :, :, :]) - 0.5) < 0.05