-
Notifications
You must be signed in to change notification settings - Fork 0
/
exampleOpenmc.py
218 lines (183 loc) · 5.79 KB
/
exampleOpenmc.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import parametric_stellarator
import openmc
# NOTE FOR EDGAR AND JOSH:
"""
This script creates a single period while also creating all magnets so there is a geometry mismatch. If actually using this script, I'd recommend either taking the magnets out while generating one period or generating all four periods with the magnets.
If using a full (four-period) geometry, the geometry definition in OpenMC will need to be adjusted. The easiest way to do that is to just fill the vacuum surface (vac_surf) with the dagmc.h5m (dag_univ).
Let me know if you have any questions!
"""
# Define plasma equilibrium VMEC file
plas_eq = 'plas_eq.nc'
# Define number of periods in stellarator plasma
num_periods = 1
# Define radial build
radial_build = {
'sol': {'thickness': 10, 'h5m_tag': 'Vacuum'},
'first_wall': {'thickness': 5},
#'breeder': {'thickness': 50},
#'back_wall': {'thickness': 5},
#'shield': {'thickness': 20}
}
# Define number of periods to generate
gen_periods = 1
# Define number of toroidal cross-sections to make
num_phi = 60
# Define number of poloidal points to include in each toroidal cross-section
num_theta = 100
# Define magnet coil parameters
magnets = {
'file': 'coils.txt',
'cross_section': ['circle', 20],
'start': 3,
'stop': None,
'name': 'magnet_coils',
'h5m_tag': 'magnets'
}
# Define source mesh parameters
source = {
'num_s': 11,
'num_theta': 81,
'num_phi': 241
}
# Define export parameters
export = {
'exclude': [],
'graveyard': False,
'step_export': True,
'h5m_export': 'Cubit',
'plas_h5m_tag': 'Vacuum',
'facet_tol': 1,
'len_tol': 5,
'norm_tol': None
}
# Create stellarator
strengths = parametric_stellarator.parametric_stellarator(
plas_eq, num_periods, radial_build, gen_periods, num_phi, num_theta,
magnets = None, source = source,
export = export
)
# Define materials in OpenMC
# Define tungsten
W = openmc.Material()
W.add_element('W', 1.0)
W.set_density('g/cm3', 19.35)
# Define reduced-activation ferritic martensitic (RAFM) steel
RAFM = openmc.Material()
RAFM.add_element('Fe', 0.895, 'wo')
RAFM.add_element('Cr', 0.09, 'wo')
RAFM.add_element('W', 0.015, 'wo')
RAFM.set_density('g/cm3', 7.8)
# Define lead-lithium eutectic coolant/breeder
PbLi = openmc.Material()
PbLi.add_element('Pb', 83.0, 'ao')
PbLi.add_element(
'Li', 17.0, 'ao', enrichment = 90.0, enrichment_target = 'Li6'
)
PbLi.set_density('g/cm3', 9.806)
# Define helium coolant
He = openmc.Material()
He.add_element('He', 1.0)
He.set_density('g/cm3', 0.00572)
# Define silicon carbide
SiC = openmc.Material()
SiC.add_element('Si', 1, 'ao')
SiC.add_element('C', 1, 'ao')
SiC.set_density('g/cm3', 3.21)
# Define water
H2O = openmc.Material()
H2O.add_element('H', 2, 'ao')
H2O.add_element('O', 1, 'ao')
H2O.set_density('g/cm3', 1.0)
# Define tungsten carbide
WC = openmc.Material()
WC.add_element('W', 1, 'ao')
WC.add_element('C', 1, 'ao')
WC.set_density('g/cm3', 15.63)
# Define first wall material
first_wall = openmc.Material.mix_materials(
[W, RAFM, He], [0.04565, 0.323, 0.627], 'vo',
name = 'first_wall'
)
# Add materials to OpenMC model
materials = openmc.Materials(
[first_wall]
)
# Export materials XML
materials.export_to_xml()
# Define geometry in OpenMC
# Define DAGMC universe
dag_univ = openmc.DAGMCUniverse('dagmc.h5m')
# Define problem outer boundary
vac_surf = openmc.Sphere(r = 10000, surface_id = 9999, boundary_type = 'vacuum')
# Define transmission boundary for period model at 0 degrees
trans_x = openmc.XPlane(
boundary_type = 'transmission',
surface_id = 9990
)
# Define transmission boundary for period model at 90 degrees
trans_y = openmc.YPlane(
boundary_type = 'transmission',
surface_id = 9991
)
# Define first period of geometry
region1 = -vac_surf & +trans_x & +trans_y
period1 = openmc.Cell(cell_id = 9996, region = region1, fill = dag_univ)
# Define second period of geometry
region2 = -vac_surf & -trans_x & +trans_y
period2 = openmc.Cell(cell_id = 9997, region = region2, fill = dag_univ)
period2.rotation = [0, 0, 90]
# Define third period of geometry
region3 = -vac_surf & -trans_x & -trans_y
period3 = openmc.Cell(cell_id = 9998, region = region3, fill = dag_univ)
period3.rotation = [0, 0, 180]
# Define fourth period of geometry
region4 = -vac_surf & +trans_x & -trans_y
period4 = openmc.Cell(cell_id = 9999, region = region4, fill = dag_univ)
period4.rotation = [0, 0, 270]
# Add geometry to OpenMC model
geometry = openmc.Geometry([period1, period2, period3, period4])
# Export geometry XML
geometry.export_to_xml()
# Define run settings
settings = openmc.Settings()
settings.run_mode = 'fixed source'
settings.particles = 1000
settings.batches = 10
# Define source
settings.source = []
# Define source mesh
mesh = openmc.UnstructuredMesh("SourceMesh.h5m", 'moab')
src = openmc.Source()
src.space = openmc.stats.MeshSpatial(
mesh, strengths = strengths, volume_normalized = False
)
src.angle = openmc.stats.Isotropic()
src.energy = openmc.stats.Discrete([14.1e6], [1.0])
settings.source = [src]
# Export settings XML
settings.export_to_xml()
# Define TBR tally
TBR = openmc.Tally(name = 'TBR')
TBR.scores = ['H3-production']
# Compile tallies
tallies = openmc.Tallies([TBR])
# Export tallies XML
tallies.export_to_xml()
# Run simulation
openmc.run()
# Access statepoint file
sp = openmc.StatePoint('statepoint.10.h5')
# Extract and store TBR result
TBR_tally = sp.get_tally(name = 'TBR')
TBR_dataframe = TBR_tally.get_pandas_dataframe()
TBR_mean = TBR_dataframe['mean'].sum()
TBR_std_dev = TBR_dataframe['std. dev.'].sum()
# Extract and store leakage result
leakage = sp.global_tallies[3]
leakage_mean = leakage[3]
leakage_std_dev = leakage[4]
# Close statepoint file
sp.close()
# Print tallies to screen
print(f'leakage = {leakage_mean} +/- {leakage_std_dev}')
print(f'TBR = {TBR_mean} +/- {TBR_std_dev}')