-
Notifications
You must be signed in to change notification settings - Fork 66
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
Apply code review changes to MCNP files #665
Conversation
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.
These look like positive changes to me @kkiesling. Thanks for getting us started on incorporating the PullRequest changes.
src/mcnp/mcnp_funcs.cpp
Outdated
imp = 1.0; | ||
// otherwise as the map says | ||
} else { | ||
imp = DMD->importance_map[entity][particle_name]; | ||
} | ||
importances += "imp:" + mcnp_name + "=" + _to_string(imp) + " "; | ||
importances += "imp:" + mcnp_name + "=" + std::to_string(imp) + " "; |
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.
It seems that std::to_string
is always going to supply 6 decimal places for floating-point types, even if they aren't needed. The test output of dagmcnp_unit_tests
expects the lcad output to have integer values for the neutron/photon importances and it's causing CI to fail.
We can either change the expected test output or we could get these values as integers before writing them to the lcad file. Given that MCNP treats these importances as floating-point values, I'd say we should update the expected results in our test suite. I'll defer to you and @makeclean on this though as you're both far more knowledgable than I :)
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.
mcnp_funcs.cpp actually defines the importances as doubles. We could define it as an int . If the input to to_string()
is an int, then there's no trailing zeros. But this is probably not recommended because users can define an importance as a doubles.
I am going to update the tests to expect doubles there.
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.
Didn't mean that mcnp_funcs.cpp
defines the importance as an integer.. just that the expected test output has something that looks like an int. :) In the end, the important part is how MCNP interprets them when determining how we should write them IMO, so I back your call to update the expected test output to expect doubles.
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.
Right- Sorry that was my own processing of what was wrong because I was confused by the trailing zeros (I assumed the importances were defined as ints, but doubles makes sense). Anyway, tests have been updated.
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.
Nice! Only caveat here is that importances will now be truncated to 6 digits... something we should probably be aware of. The example here explains in more detail.
After reading a bit on this subject, it seems that our method in mcnp_funds.cpp
for higher precision double --> string conversion (with the addition of a std::setprecision
in the stream) is still recommended. 🤷♂️
I'd be surprised if more than 6 digits are used for these values very often, so I'm good w/ whatever you decide.
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.
@gonuke or @makeclean - any thoughts on this?
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 agree that the to_string()
is not a good change
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 agree as well -- we should go back to our _to_string
function for floating point values. We can still use std::to_string
for int
's like material number though. Probably best to use the standard library where we can.
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 sounds like a good idea- I will update accordingly.
I think to_string()
will still convert ints to floats to write out (eg, 1
will become 1.000000
by default). But I might be able to play with the precision to avoid that.
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'll find that std::to_string()
will write ints without trailing zeros. Its implementation is specialized depending on the type passed to it. So no extra work should be needed there 🎉
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.
Thanks for making these changes @kkiesling - just one question.
"9 1 0.022 imp:n=1 imp:p=1 ", | ||
"12 0 imp:n=0 imp:p=0 $ graveyard", | ||
"13 0 imp:n=1 imp:p=1 $ implicit complement" | ||
const char* expected[] = {"1 9 -12.0 imp:n=1.000000 imp:p=1.000000 ", |
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 isn't a comment from PullRequest, but I think it's worth updating and is in the spirit of this PR.
With C++11 we can now define these expected values using an initializer list rather than the variable-length char array we're using now like so:
std::vector<std::string> expected_lcad = {"1 9 -12.0 imp:n=1.000000 imp:p=1.000000 ",
"2 9 -12.0 imp:n=1.000000 imp:p=1.000000 ",
...
Happens in a few places here I think.
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.
Good idea. I'll search throughout and update.
src/mcnp/mcnp_funcs.cpp
Outdated
mat_num = _to_string(matnumber); | ||
density = "-" + _to_string(material.density); | ||
mat_num = std::to_string(matnumber); | ||
density = "-" + std::to_string(material.density); |
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.
should we also use _to_string()
here?
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.
yes- I haven't gone back through to untangle all the to_string()
/_to_string()
uses yet
2f6d63f
to
e41d2ee
Compare
I think this is ready now as long as the checks pass. |
@@ -52,7 +52,6 @@ set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "-O1 -g") | |||
|
|||
# C compiler flags | |||
if (CMAKE_C_COMPILER_ID STREQUAL "Intel") | |||
#set(CMAKE_C_FLAGS "${CMAKE_Fortran_FLAGS} -mcmodel=medium") |
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.
The reason these commented lines are here is that they appear in the makefiles for native MCNP, but I needed to turn them off. I don't remember why.
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.
Should they be left in and put in use? Or is it okay to remove these lines?
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.
Ehhhh yeah let's just delete them
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.
Thanks for getting us started on this @kkiesling!
Thanks for kicking it off @kkiesling |
Applying the changes from the professional code review (#660) to the MCNP related files. The changes are as follows:
std::cerr
instead ofstd::cout
(original comment)The one comment that I did NOT address was this comment on the readability of using
#ifdef
s in function calls (see here for more information on why). It's doable, just will be done in a separate PR since it will likely be a larger more significant change.