Skip to content
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

Open
wants to merge 42 commits into
base: main
Choose a base branch
from

Conversation

aaswenson
Copy link
Contributor

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

* power
* enrich
"""
from pyDOE import lhs
Copy link
Member

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']
Copy link
Member

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.


return sampled, const, dim


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 lines there


dim = len(sampled)

return sampled, const, dim
Copy link
Member

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?

cube (ndarray): normalized, N-D latin hypercube
"""

np.random.seed(4654562)
Copy link
Member

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 ?

Copy link
Contributor Author

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.

Copy link
Member

@gonuke gonuke left a 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):
Copy link
Member

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),
Copy link
Member

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?

l_limit = dims[dim][0]
u_limit = dims[dim][1]
# uniform distribution
a = u_limit - l_limit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better variable name: width

u_limit = dims[dim][1]
# uniform distribution
a = u_limit - l_limit
b = l_limit
Copy link
Member

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?

a = u_limit - l_limit
b = l_limit
# save to ndarray
rxt_confs[sample_idx][dim] = b + cube[sample_idx][dim_idx] * a
Copy link
Member

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])

tsteps.append(idx + offset)

for i, tidx in enumerate(tsteps):
step = 0
Copy link
Member

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

ZAID = int(data[1])
mass = float(data[2])

if ZAID in act_inv.keys():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

step.
data (ndarray): container to store results
"""
BOL = act_inv[92235][0] / 1000.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic number

BOL = act_inv[92235][0] / 1000.0
EOL = act_inv[92235][-1] / 1000.0

data['BOL_U'] = BOL
Copy link
Member

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

data['BOL_U'] = BOL
data['EOL_U'] = EOL

delta_rel = abs(EOL - BOL) / data['mass']
Copy link
Member

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...

data (ndarray): container to store results
"""
core_r, r, PD, Q = data[['core_r', 'cool_r', 'PD', 'power']]
# clad thickness
Copy link
Member

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

Copy link
Contributor Author

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.

@ypark234 ypark234 changed the base branch from master to main June 18, 2020 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants