-
Notifications
You must be signed in to change notification settings - Fork 84
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
Changes from 18 commits
3bca812
bcc800c
2544255
b4db6b6
0d834c8
937bb55
c74105e
897069f
3095060
7487920
fe0b8de
7359765
477c58f
4018686
05d693e
a233bb0
15a31d9
8a000a3
8218237
5b06cb3
5c93374
2b31945
64f4dc5
0f34157
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -374,21 +374,29 @@ def get_opencg_cell(openmoc_cell): | |
name = openmoc_cell.getName() | ||
opencg_cell = opencg.Cell(cell_id, name) | ||
|
||
fill = openmoc_cell.getFill() | ||
if (openmoc_cell.getType == openmoc.MATERIAL): | ||
if (openmoc_cell.getType() == openmoc.MATERIAL): | ||
fill = openmoc_cell.getFillMaterial() | ||
opencg_cell.fill = get_opencg_material(fill) | ||
elif (openmoc_cell.getType() == openmoc.FILL): | ||
fill = openmoc_cell.getFillUniverse() | ||
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 | ||
if openmoc_cell.isTranslated(): | ||
rotation = openmoc_cell.getTranslation(3) | ||
opencg_cell.translation = translation | ||
|
||
surfaces = openmoc_cell.getSurfaces() | ||
|
||
for surf_id, surface_halfspace in surfaces.items(): | ||
halfspace = surface_halfspace._halfspace | ||
surface = surface_halfspace._surface | ||
opencg_cell.addSurface(get_opencg_surface(surface), halfspace) | ||
opencg_cell.add_surface(get_opencg_surface(surface), halfspace) | ||
|
||
# Add the OpenMOC Cell to the global collection of all OpenMOC Cells | ||
OPENMOC_CELLS[cell_id] = openmoc_cell | ||
|
@@ -587,6 +595,13 @@ def get_openmoc_cell(opencg_cell): | |
else: | ||
openmoc_cell.setFill(get_openmoc_material(fill)) | ||
|
||
if opencg_cell.rotation is not None: | ||
rotation = np.asarray(opencg_cell.rotation, dtype=np.float64) * -1 | ||
openmoc_cell.setRotation(rotation) | ||
if opencg_cell.translation is not None: | ||
translation = np.asarray(opencg_cell.translation, dtype=np.float64) | ||
openmoc_cell.setTranslation(translation) | ||
|
||
surfaces = opencg_cell.surfaces | ||
|
||
for surface_id in surfaces: | ||
|
@@ -753,8 +768,8 @@ def get_openmoc_lattice(opencg_lattice): | |
universes = opencg_lattice.universes | ||
|
||
# Initialize an empty array for the OpenMOC nested Universes in this Lattice | ||
universe_array = np.ndarray(tuple(np.array(dimension[0:2])), \ | ||
dtype=openmoc.Universe) | ||
# The Lattice universe array is stored x-y-z in OpenCG, but z-y-x in OpenMOC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the master branch of OpenCG, it appears OpenCG stores the Lattice universe array in z-y-x, just like in OpenMOC. For instance, line 1045 of
Is OpenCG indeed storing the universes array as x-y-z? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right that it is indexed by z-y-x in both codes (or at least should be). I made this comment to myself while I was debugging since I had convinced myself otherwise at one point. I'll revert back to the original comment now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a related note though, OpenCG's |
||
universe_array = np.ndarray(tuple(dimension[::-1]), dtype=openmoc.Universe) | ||
|
||
# Create OpenMOC Universes for each unique nested Universe in this Lattice | ||
unique_universes = opencg_lattice.get_unique_universes() | ||
|
@@ -763,14 +778,15 @@ def get_openmoc_lattice(opencg_lattice): | |
unique_universes[universe_id] = get_openmoc_universe(universe) | ||
|
||
# Build the nested Universe array | ||
for y in range(dimension[1]): | ||
for x in range(dimension[0]): | ||
universe_id = universes[0][y][x].id | ||
universe_array[x][y] = unique_universes[universe_id] | ||
for z in range(dimension[2]): | ||
for y in range(dimension[1]): | ||
for x in range(dimension[0]): | ||
universe_id = universes[z][y][x].id | ||
universe_array[z][dimension[1]-y-1][x] = unique_universes[universe_id] | ||
|
||
openmoc_lattice = openmoc.Lattice(lattice_id, name) | ||
openmoc_lattice.setWidth(width[0], width[1], width[2]) | ||
openmoc_lattice.setUniverses([universe_array.tolist()]) | ||
openmoc_lattice.setUniverses(universe_array.tolist()) | ||
openmoc_lattice.setOffset(offset[0], offset[1], offset[2]) | ||
|
||
# Add the OpenMOC Lattice to the global collection of all OpenMOC Lattices | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,23 @@ | |
* using NumPy arrays */ | ||
%apply (double* IN_ARRAY1, int DIM1) {(double* xs, int num_groups)} | ||
|
||
/* The typemap used to match the method signature for the Cell rotation | ||
* angle setter method. This allows users to set the rotation angles | ||
* using NumPy arrays */ | ||
%apply (double* IN_ARRAY1, int DIM1) {(double* rotation, int num_axes)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a good reason for using arrays rather than vectors everywhere? If this was a vector, no typemap would be needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is indeed the case, then I'm sold. I'm not going to make vectors the standard in this PR, but certainly think it would be nice to start using them in place of arrays in some if not all cases, esp. if it would simplify our swig typemaps. |
||
|
||
/* The typemap used to match the method signature for the Cell translation | ||
* setter method. This allows users to set translations using NumPy arrays */ | ||
%apply (double* IN_ARRAY1, int DIM1) {(double* translation, int num_axes)} | ||
|
||
/* 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)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this signature need another attribute for the units? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
/* The typemap used to match the method signature for the Cell's | ||
* getter method for translations used by the OpenCG compatibility module. */ | ||
%apply (double* ARGOUT_ARRAY1, int DIM1) {(double* translations, int num_axes)} | ||
|
||
/* The typemap used to match the method signature for the TrackGenerator's | ||
* getter methods for track start and end coordinates for the plotting | ||
* routines in openmoc.plotter */ | ||
|
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.
What's the reason for the -1 here and on line 599?
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.
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.