-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Latin Hypercube Neutronic Sampling #10
base: main
Are you sure you want to change the base?
Conversation
* power | ||
* enrich | ||
""" | ||
from pyDOE import lhs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PEP8: missing blank line
|
||
from mcnp_inputs import HomogeneousInput, build_pyne_matlib | ||
|
||
_dimensions = ['AR', 'core_r', 'cool_r', 'PD', 'power', 'enrich'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doctoring to explain what those variables are.
neutronics/neutronic_sweeps.py
Outdated
|
||
return sampled, const, dim | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 lines there
neutronics/neutronic_sweeps.py
Outdated
|
||
dim = len(sampled) | ||
|
||
return sampled, const, dim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why returning len(sampled) when you actually have sampled?
neutronics/neutronic_sweeps.py
Outdated
cube (ndarray): normalized, N-D latin hypercube | ||
""" | ||
|
||
np.random.seed(4654562) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why always the same seed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I do the analysis again, I want to be able to generate the same input files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also use some tests.
@@ -151,7 +151,7 @@ def write_mat_string(self): | |||
# write mcnp-form string | |||
self.fuel_string = self.homog_mat.mcnp().strip('\n') | |||
|
|||
def write_input(self): | |||
def write_input(self, file_num, header): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add arguments to docstring....
Not sure what file_num
is: is it actually just a number? If so, then not sure about the filename below
|
||
# Set dimension values. A tuple with range boundaries will sample the dimension | ||
# evenly using LHS, a float will set the dimension to the constant value | ||
dims = {'core_r' : (20, 50), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't _dimensions
be set by looking at the keys of this variable to ensure consistency?
neutronics/neutronic_sweeps.py
Outdated
l_limit = dims[dim][0] | ||
u_limit = dims[dim][1] | ||
# uniform distribution | ||
a = u_limit - l_limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better variable name: width
neutronics/neutronic_sweeps.py
Outdated
u_limit = dims[dim][1] | ||
# uniform distribution | ||
a = u_limit - l_limit | ||
b = l_limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use l_limit
?
neutronics/neutronic_sweeps.py
Outdated
a = u_limit - l_limit | ||
b = l_limit | ||
# save to ndarray | ||
rxt_confs[sample_idx][dim] = b + cube[sample_idx][dim_idx] * a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like there is probably a matrix-vector implementation of this?
This won't work as is, but with a little thought on data structures, this whole inner loop can probably be replaced by something like this:
rxtr_confs[sample_idx] = dims[:][0] + cube[sample_idx] * (dims[:][1] - dims[:][0])
neutronics/parse_outputs.py
Outdated
tsteps.append(idx + offset) | ||
|
||
for i, tidx in enumerate(tsteps): | ||
step = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can probably just increment tidx
in this loop rather than adding step
neutronics/parse_outputs.py
Outdated
ZAID = int(data[1]) | ||
mass = float(data[2]) | ||
|
||
if ZAID in act_inv.keys(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dict.setdefauult()
is a handy method to avoid writing these kinds of if statements for dictionaries:
neutronics/parse_outputs.py
Outdated
step. | ||
data (ndarray): container to store results | ||
""" | ||
BOL = act_inv[92235][0] / 1000.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic number
neutronics/parse_outputs.py
Outdated
BOL = act_inv[92235][0] / 1000.0 | ||
EOL = act_inv[92235][-1] / 1000.0 | ||
|
||
data['BOL_U'] = BOL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just assign it directly instead of introducing BOL
and EOL
neutronics/parse_outputs.py
Outdated
data['BOL_U'] = BOL | ||
data['EOL_U'] = EOL | ||
|
||
delta_rel = abs(EOL - BOL) / data['mass'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why abs
? Why not reverse the difference: BOL - EOL
, in which case if it's negative, it should be an error...
…or constant and swept parameters
…e some variables for clarity and adjust the tests
data (ndarray): container to store results | ||
""" | ||
core_r, r, PD, Q = data[['core_r', 'cool_r', 'PD', 'power']] | ||
# clad thickness |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to use a clearer variable name than to add a comment to describe your variable name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used c because it's a common variable used for clad thickness. I can change it though.
This PR contains a new module that writes MCNP6 input files. It uses the HomogeneousInput class in mcnp_inputs.py to generate various homogeneous models for sampled reactor configurations.
The main additions are:
neutronic_sweeps.py: generates the inputs
parse_outputs.py: parses the output files for keff results, energy spectra, depletion results, etc