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

Cell Rotations and Translations #225

Merged
merged 24 commits into from
Dec 6, 2015

Conversation

wbinventor
Copy link
Member

This PR introduces cell rotations and translations. These features enable us to model the fully-detailed (3D) BEAVRS benchmark generated by the OpenCG BEAVRS builder for the first time!

Unfortunately, adding in rotations/translations was a little more difficult than I had expected (but not overly cumbersome). Fortunately, the process of putting in these features required some refactoring of the ray tracing code - but it keeps getting better and better and is far more methodical than a few years ago.

In particular, this PR introduces length 3 _rotation and _translation arrays for the Cell class which may be optionally set by the user. The ray tracing code in the Geometry and Universe classes has been refactored such that all updates to LocalCoords positions take place directly within the LocalCoords object (which is a cleaner abstraction than before). In addition, the 2D angle phi wrt the x-axis is now an attribute of LocalCoords, where it is defined based on a track's starting angle and the rotations applied to any Cells found during CSG tree traversal.

With the changes made here, it is quite simple to build a full-core OpenMOC model of the 3D BEAVRS core. In particular, with an installation of the BEAVRS model builder from the mit-crpg/PWR_benchmarks repo, along with OpenCG (a pre-requisite for the BEAVRS builder), one can instantiate an OpenMOC model of BEAVRS as follows:

import opencg
from beavrs.builder import BEAVRS
from openmoc.compatible import get_openmoc_geometry

# Instantiate a BEAVRS OpencG model from mit-crpg/PWR_benchmarks
beavrs = BEAVRS(nndc_xs=True)

# Construct an OpenCG Geometry for the BEAVRS reactor model
opencg_geometry = opencg.Geometry()
opencg_geometry.root_universe = beavrs.main_universe

# Export the 3D OpenCG Geometry to OpenMOC
openmoc_geometry = get_openmoc_geometry(opencg_geometry)

# Voila!

Previously, if one attempted to export the model as above, the baffles were not placed in the correct positions. This is because the baffles have rotations applied. Now that the baffles can be properly treated, the model above can be plotted as shown below and the baffles look as they should.

Full core

Upper right core

Note that the OpenMOC Geometry created above will not have a bounding box applied, and hence is not yet ready for ray tracing. In order to make the Geometry "ray tracing-ready", one would must create a Cell outside the core vessel filled by a dummy Material and bounded by the core vessel's ZCylinder and some bounding XPlanes and YPlanes with VACUUM boundary conditions.

@samuelshaner
Copy link
Contributor

@wbinventor - this is great! I'll give this a full review later this week.

@wbinventor wbinventor mentioned this pull request Nov 25, 2015
if isinstance(fill, openmoc.Lattice):
opencg_cell.fill = get_opencg_lattice(fill)
else:
opencg_cell.fill = get_opencg_universe(fill)

if openmoc_cell.isRotated():
rotation = openmoc_cell.getRotation(3)
opencg_cell.rotation = rotation * -1
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for the -1 here and on line 599?

Copy link
Member Author

Choose a reason for hiding this comment

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

Haha, it was a little hack while I was trying to figure things out. I've removed it now as I've straightened out things in the roll-pitch-yaw convention of the rotation matrix below.

@samuelshaner
Copy link
Contributor

The rotations are input and stored in degrees, but angles are for the most part handled internally in radians. The Cell and LocalCoords objects both have getPhi() methods, but Cell returns phi in degrees while LocalCoords returns phi in radians. At the surface, this can be a bit confusing. I think handling angles internally in one common set of units (I think radians would be most appropriate) would make the code easier to understand and avoid any conversion errors down the road, but allowing the user to input angles for rotations in degrees or radians (which a function parameter indicating what units are being input) would be a reasonable compromise from a user-input standpoint. What are your thoughts on the radians/degrees mixing in the code?

next_coords->setX(new_x);
next_coords->setY(new_y);
next_coords->setZ(new_z);
next_coords->incrementPhi(cell->getPsi() * M_PI / 180.);
Copy link
Contributor

Choose a reason for hiding this comment

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

indented one too many spaces

Copy link
Member Author

Choose a reason for hiding this comment

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

Weird, it doesn't show up that way in emacs. I removed all whitespace and added it back in so perhaps it will show up properly now.

@wbinventor wbinventor changed the title Cells Rotations and Translations Cell Rotations and Translations Nov 29, 2015
@wbinventor
Copy link
Member Author

I've addressed all of the comments made thus far and think this is ready for a final review.

@samuelshaner
Copy link
Contributor

Thanks for updating the PR @wbinventor. I had a comment on mixing of angle units (radians vs degrees) in the code that it looks like you might have missed.

@wbinventor
Copy link
Member Author

@samuelshaner - the rotation angles are now stored internally in radians. The setter and getter routines for the angles now accept a std::string units parameter which defaults to "degrees" but which may alternatively accept "radians".


/* The typemap used to match the method signature for the Cell's
* getter method for rotations used by the OpenCG compatibility module. */
%apply (double* ARGOUT_ARRAY1, int DIM1) {(double* rotations, int num_axes)}
Copy link
Contributor

Choose a reason for hiding this comment

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

does this signature need another attribute for the units?

Copy link
Member Author

Choose a reason for hiding this comment

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

I wondered that too, but it doesn't seem too since it works with my test case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm...maybe swig just ignores all arguments after those included in the signature.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what I think. But this is related to the way NumPy typemaps work with SWIG - and that isn't particularly well documented IMHO.

@samuelshaner
Copy link
Contributor

Just tested this out and everything looks good to merge!

samuelshaner added a commit that referenced this pull request Dec 6, 2015
@samuelshaner samuelshaner merged commit 479cd68 into mit-crpg:develop Dec 6, 2015
@wbinventor wbinventor deleted the rotation-translation branch December 6, 2015 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants