-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnested_spheres.py
More file actions
59 lines (44 loc) · 1.6 KB
/
nested_spheres.py
File metadata and controls
59 lines (44 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Nested spheres for distance-to-boundary benchmarking"""
from __future__ import annotations
import openmc
import numpy as np
BENCHMARK_NAME = "NestedSpheres"
def build_model() -> openmc.Model:
# Create a simple low-density hydrogen material (effectively vacuum)
mat = openmc.Material(name='Low-density H')
mat.add_nuclide('H1', 1.0)
mat.set_density('g/cm3', 1.0e-10)
# Create 100 nested spherical shells
n_shells = 100
r_inner = 1.0
r_outer = 100.0
# Generate radii for shells (linearly spaced)
radii = np.linspace(r_inner, r_outer, n_shells + 1)
# Create spherical surfaces
spheres = [openmc.Sphere(r=r) for r in radii]
# Set vacuum boundary on outermost sphere
spheres[-1].boundary_type = 'vacuum'
# Create cells
cells = []
for i in range(n_shells + 1):
if i == 0:
# Innermost cell
region = -spheres[i]
else:
# Shell cells
region = +spheres[i - 1] & -spheres[i]
cell = openmc.Cell(fill=mat, region=region)
cells.append(cell)
geometry = openmc.Geometry(cells)
# Settings with point source in the first (innermost) cell
settings = openmc.Settings()
settings.batches = 10
settings.inactive = 5
settings.particles = 100000
settings.run_mode = "fixed source"
# Point source at origin (center of first cell)
source = openmc.IndependentSource()
source.space = openmc.stats.Point((0, 0, 0))
source.energy = openmc.stats.delta_function(1.0e6)
settings.source = source
return openmc.Model(geometry=geometry, settings=settings)