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

Apply code review changes to MCNP files #665

Merged
merged 6 commits into from
Apr 2, 2020

Conversation

kkiesling
Copy link
Contributor

Applying the changes from the professional code review (#660) to the MCNP related files. The changes are as follows:

The one comment that I did NOT address was this comment on the readability of using #ifdefs 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.

Copy link
Member

@pshriwise pshriwise left a 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.

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) + " ";
Copy link
Member

@pshriwise pshriwise Mar 27, 2020

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

Copy link
Contributor Author

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.

Copy link
Member

@pshriwise pshriwise Mar 28, 2020

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

@kkiesling kkiesling Mar 30, 2020

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.

Copy link
Member

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 🎉

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.

Thanks for making these changes @kkiesling - just one question.

src/mcnp/tests/dagmcnp_unit_tests.cpp Outdated Show resolved Hide resolved
"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 ",
Copy link
Member

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.

Copy link
Contributor Author

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.

mat_num = _to_string(matnumber);
density = "-" + _to_string(material.density);
mat_num = std::to_string(matnumber);
density = "-" + std::to_string(material.density);
Copy link
Member

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?

Copy link
Contributor Author

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

@kkiesling
Copy link
Contributor Author

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

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.

Copy link
Contributor Author

@kkiesling kkiesling Apr 1, 2020

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?

Copy link
Member

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

Copy link
Member

@pshriwise pshriwise left a 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!

@gonuke
Copy link
Member

gonuke commented Apr 2, 2020

Thanks for kicking it off @kkiesling

@gonuke gonuke merged commit 6a89166 into svalinn:develop Apr 2, 2020
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.

4 participants