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

Raytrace plots #2655

Open
wants to merge 59 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
f55def3
implement Phong-shaded ray trace plots
gridley Feb 25, 2024
0cf377d
remove outdated TODO
gridley Mar 7, 2024
94913e7
use std::set for opaque ids in plot
gridley Mar 7, 2024
9752412
use doxygen class comments for new plot types
gridley Mar 7, 2024
ff94c9f
clang format
gridley Mar 7, 2024
50dbc18
add application of inverse rotation method to Position class
gridley Mar 7, 2024
923e293
review comments
gridley Mar 7, 2024
8a014ad
get clang-format to pass
gridley Mar 7, 2024
afd408e
try to make clangformat happy
gridley Mar 7, 2024
6282f04
update comment
gridley Mar 16, 2024
fb352d0
nominal fixes for ray trace plots with dagmc
gridley Jun 2, 2024
2f85fb9
have ray-based plotting use seperate in-model and out-model loops
gridley Sep 2, 2024
1e28719
remove extraneous passing of particle state to reflections
gridley Sep 7, 2024
4f19579
now works beautifully with dagmc
gridley Sep 8, 2024
fa8bed6
Merge remote-tracking branch 'upstream/develop' into raytrace_plots
pshriwise Dec 6, 2024
ab5480d
Providing rng. Correcting comment indentation
pshriwise Dec 6, 2024
d5d04fb
Updating plot_projection results. Verified that there are no noticeab…
pshriwise Dec 7, 2024
b6bad23
fix comment indentation in plots.py
gridley Dec 13, 2024
c536898
address review comments
gridley Dec 13, 2024
79614ed
Reverting to old Surface::reflect signatures
pshriwise Jan 2, 2025
c24e37a
C++ style
pshriwise Jan 2, 2025
61fdaed
Adding XML roundtrip test for PhongPlot
pshriwise Jan 2, 2025
0ae7612
Adding methods operating on the camera class for clarity. Templating …
pshriwise Jan 6, 2025
9fbf479
Correct test name
pshriwise Jan 6, 2025
8989eb7
Simplifying logic in Plots.from_xml_element
pshriwise Jan 6, 2025
027deee
Passing particle pointer to Surface::reflect, re-adding Ensures in DA…
pshriwise Jan 6, 2025
7c8f988
Correcting comment indentation
pshriwise Jan 6, 2025
d76ffe5
Test PhongPlot repr
pshriwise Jan 6, 2025
b202ee5
Style update
pshriwise Jan 6, 2025
90012e5
Adding description of the camera_to_model matrix axes
pshriwise Jan 7, 2025
58cce6d
Adding tests for ProjectionPlot roundtrip
pshriwise Jan 7, 2025
d4ed3de
Style update
pshriwise Jan 7, 2025
6280602
rm whitespace
pshriwise Jan 7, 2025
6cc4d1a
Using some existing data members on GeometryState when possible
pshriwise Jan 9, 2025
4593775
Starting a refactor
pshriwise Jan 9, 2025
ad47cdf
Using new method. No visual changes but some small ones.
pshriwise Jan 9, 2025
c674b4d
Move std::abs out of adv_to_bnd_frm_vd
pshriwise Jan 11, 2025
7cdf555
Turn i_surface_ into a token
pshriwise Jan 11, 2025
2920938
Change from index check to token check
pshriwise Jan 11, 2025
6779f55
Better evaluation of surface normal
pshriwise Jan 11, 2025
cb8ebf9
Getting rid of i_surface_ attribute in favor of built-in surface toke…
pshriwise Jan 11, 2025
3228f8b
Removing first_surface_ attribute in favor of a local variable in tra…
pshriwise Jan 11, 2025
51b9412
Removing intersection_found_ member variable
pshriwise Jan 11, 2025
189828d
Removing intersection found variable altogether
pshriwise Jan 11, 2025
2a84266
Removing first_surface variable altogether
pshriwise Jan 11, 2025
c490367
whitespace
pshriwise Jan 11, 2025
36ac7cf
Style
pshriwise Jan 11, 2025
818418a
Updating projection plot results again
pshriwise Jan 11, 2025
22fced2
Removing unused method from RayTracePlot
pshriwise Jan 11, 2025
1da7b93
Merge remote-tracking branch 'upstream/develop' into raytrace_plots
pshriwise Jan 11, 2025
ba7db72
Updating to Surface::geom_type accessor
pshriwise Jan 12, 2025
a889387
Style
pshriwise Jan 12, 2025
5f01059
Style again
pshriwise Jan 12, 2025
782fc13
Merge remote-tracking branch 'upstream/develop' into raytrace_plots
pshriwise Jan 17, 2025
313df06
Updates based on changes in #3260
pshriwise Jan 17, 2025
05d6dc4
Moving to surface indices for identifier in TrackSegment.
pshriwise Jan 17, 2025
d87ba96
Very minor cleanup in plots.py
pshriwise Jan 21, 2025
ada075a
Consistent spacing in rst files
paulromano Feb 7, 2025
2afaefc
Small edits here and there
paulromano Feb 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 102 additions & 15 deletions docs/source/io_formats/plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ Geometry Plotting Specification -- plots.xml
Basic plotting capabilities are available in OpenMC by creating a plots.xml file
and subsequently running with the ``--plot`` command-line flag. The root element
of the plots.xml is simply ``<plots>`` and any number output plots can be
defined with ``<plot>`` sub-elements. Two plot types are currently implemented
defined with ``<plot>`` sub-elements. Four plot types are currently implemented
in openMC:

* ``slice`` 2D pixel plot along one of the major axes. Produces a PNG image
file.
* ``voxel`` 3D voxel data dump. Produces an HDF5 file containing voxel xyz
position and cell or material id.
* ``projection`` 2D pixel plot of a three-dimensional view of a geometry using
wireframes around cells or materials and coloring by depth through each
material.
* ``phong`` 2D pixel plot of a three-dimensional view of a geometry with solid
colored surfaces of a set of cells or materials.


------------------
Expand Down Expand Up @@ -66,21 +71,22 @@ sub-elements:
*Default*: None - Required entry

:type:
Keyword for type of plot to be produced. Currently only "slice" and "voxel"
plots are implemented. The "slice" plot type creates 2D pixel maps saved in
the PNG file format. The "voxel" plot type produces a binary datafile
containing voxel grid positioning and the cell or material (specified by the
``color`` tag) at the center of each voxel. Voxel plot files can be
processed into VTK files using the :ref:`scripts_voxel` script provided with
OpenMC and subsequently viewed with a 3D viewer such as VISIT or Paraview.
See the :ref:`io_voxel` for information about the datafile structure.
Keyword for type of plot to be produced. Currently "slice", "voxel",
"projection", and "phong" plots are implemented. The "slice" plot type
creates 2D pixel maps saved in the PNG file format. The "voxel" plot type
produces a binary datafile containing voxel grid positioning and the cell or
material (specified by the ``color`` tag) at the center of each voxel. Voxel
plot files can be processed into VTK files using the :ref:`scripts_voxel`
script provided with OpenMC and subsequently viewed with a 3D viewer such as
VISIT or Paraview. See :ref:`io_voxel` for information about the datafile
structure.

.. note:: High-resolution voxel files produced by OpenMC can be quite large,
but the equivalent VTK files will be significantly smaller.

*Default*: "slice"

``<plot>`` elements of ``type`` "slice" and "voxel" must contain the ``pixels``
All ``<plot>`` elements must contain the ``pixels``
attribute or sub-element:

:pixels:
Expand All @@ -96,7 +102,7 @@ attribute or sub-element:
``width``/``pixels`` along that basis direction may not appear
in the plot.

*Default*: None - Required entry for "slice" and "voxel" plots
*Default*: None - Required entry for all plots

``<plot>`` elements of ``type`` "slice" can also contain the following
attributes or sub-elements. These are not used in "voxel" plots:
Expand Down Expand Up @@ -125,6 +131,11 @@ attributes or sub-elements. These are not used in "voxel" plots:
Specifies the custom color for the cell or material. Should be 3 integers
separated by spaces.

:xs:
The attenuation coefficient for volume rendering of color in units of
inverse centimeters. Zero corresponds to transparency. Only for plot type
"projection".

As an example, if your plot is colored by material and you want material 23
to be blue, the corresponding ``color`` element would look like:

Expand Down Expand Up @@ -152,17 +163,17 @@ attributes or sub-elements. These are not used in "voxel" plots:
*Default*: 255 255 255 (white)

:show_overlaps:
Indicates whether overlapping regions of different cells are shown.
Indicates whether overlapping regions of different cells are shown.

*Default*: None

:overlap_color:
Specifies the RGB color of overlapping regions of different cells. Does not
do anything if ``show_overlaps`` is "false" or not specified. Should be 3
Specifies the RGB color of overlapping regions of different cells. Does not
do anything if ``show_overlaps`` is "false" or not specified. Should be 3
integers separated by spaces.

*Default*: 255 0 0 (red)

:meshlines:
The ``meshlines`` sub-element allows for plotting the boundaries of a
regular mesh on top of a plot. Only one ``meshlines`` element is allowed per
Expand Down Expand Up @@ -191,3 +202,79 @@ attributes or sub-elements. These are not used in "voxel" plots:
*Default*: 0 0 0 (black)

*Default*: None

``<plot>`` elements of ``type`` "projection" or "phong" can contain the
following attributes or sub-elements.

:camera_position:
Location in 3D Cartesian space the camera is at.


*Default*: None - Required for all phong or projection plots

:look_at:
Location in 3D Cartesian space the camera is looking at.


*Default*: None - Required for all phong or projection plots

:field_of_view:
The horizontal field of view in degrees. Defaults to roughly the same value
as for the human eye.

*Default*: 70

:orthographic_width:
If set to a nonzero value, an orthographic rather than perspective
projection for the camera is employed. An orthographic projection puts out
parallel rays from the camera of a width prescribed here in the horizontal
direction, with the width in the vertical direction decided by the pixel
aspect ratio.

*Default*: 0

``<plot>`` elements of ``type`` "phong" can contain the following attributes or
sub-elements.

:opaque_ids:
List of integer IDs of cells or materials to be treated as visible in the
plot. Whether the integers are interpreted as cell or material IDs depends
on ``color_by``.


*Default*: None - Required for all phong plots

:light_position:
Location in 3D Cartesian space of the light.


*Default*: Same location as ``camera_position``

:diffuse_fraction:
Fraction of light originating from non-directional sources. If set to one,
the coloring is not influenced by surface curvature, and no shadows appear.
If set to zero, only regions illuminated by the light are not black.


*Default*: 0.1

``<plot>`` elements of ``type`` "projection" can contain the following
attributes or sub-elements.

:wireframe_color:
RGB value of the wireframe's color

*Default*: 0, 0, 0 (black)

:wireframe_thickness:
Integer number of pixels that the wireframe takes up. The value is a radius
of the wireframe. Setting to zero removes any wireframing.

*Default*: 0

:wireframe_ids:
Integer IDs of cells or materials of regions to draw wireframes around.
Whether the integers are interpreted as cell or material IDs depends on
``color_by``.

*Default*: None
79 changes: 67 additions & 12 deletions docs/source/usersguide/plots.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,57 @@ will depend on the 3D viewer, but should be straightforward.
million or so). Thus if you want an accurate picture that renders
smoothly, consider using only one voxel in a certain direction.

-----------
Phong Plots
-----------

.. image:: ../_images/phong_triso.png
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this file is missing

:width: 300px

The :class:`openmc.PhongPlot` class allows three dimensional visualization of
detailed geometric features without voxelization. The plot above visualizes a
geometry created by :class:`openmc.TRISO`, with the materials in the fuel kernel
distinguished by color. It was enclosed in a bounding box such that some kernels
are cut off, revealing the inner structure of the kernel.

The `Phong reflection model
<https://en.wikipedia.org/wiki/Phong_reflection_model>`_ approximates how light
reflects off of a surface. On a diffusely light-scattering material, the Phong
model prescribes the amount of light reflected from a surface as proportional to
the dot product between the normal vector of the surface and the vector between
that point on the surface and the light. With this assumption, visually
appealing plots of simulation geometries can be created.

Phong plots use the same ray tracing functions that neutrons and photons do in
OpenMC, so any input that does not leak particles can be visualized in 3D using
a Phong plot. That being said, these plots are not useful for detecting overlap
or undefined regions, so it is recommended to use the slice plot approach for
geometry debugging.

Only a few inputs are required for a Phong plot. The camera location, where the
camera is looking, and a set of opaque material or cell IDs are required. The
colors of materials or cells are prescribed in the same way as slice plots. The
set of IDs that are opaque in the Phong plot must correspond to materials if
coloring by material, or cells if coloring by cell.

A minimal Phong plot input could be::

plot = openmc.PhongPlot()
plot.pixels = (600, 600)
plot.camera_position = (10.0, 20.0, -30.0)
plot.look_at = (4.0, 5.0, 1.0)
plot.color_by = 'cell'

# optional. defaults to camera_position
plot.light_position = (10, 20, 30)

# controls ambient lighting. Defaults to 10%
plot.diffuse_fraction = 0.1
plot.opaque_domains = [cell2, cell3]

These plots are then stored into a :class:`openmc.Plots` instance, just like the
slice plots.

----------------
Projection Plots
----------------
Expand All @@ -131,14 +182,18 @@ Projection Plots
.. image:: ../_images/hexlat_anim.gif
:width: 200px

The :class:`openmc.ProjectionPlot` class presents an alternative method of
producing 3D visualizations of OpenMC geometries. It was developed to overcome
the primary shortcoming of voxel plots, that an enormous number of voxels must
be employed to capture detailed geometric features. Projection plots perform
volume rendering on material or cell volumes, with colors specified in the same
manner as slice plots. This is done using the native ray tracing capabilities
within OpenMC, so any geometry in which particles successfully run without
overlaps or leaks will work with projection plots.
The :class:`openmc.ProjectionPlot` class also produces 3D visualizations of
OpenMC geometries without voxelization but is intended to show the inside of a
model using wireframing of cell or material boundaries in addition to cell
coloring based on the path length of camera rays through the model. The coloring
in these plots is a bit like turning the model into partially transparent
colored glass that can be seen through, without any refractive effects. This is
called volume rendering. The colors are specified in exactly the same interface
employed by slice plots.

Similar to Phong plots, these use the native ray tracing capabilities within
OpenMC, so any geometry in which particles successfully run without overlaps or
leaks will work with projection plots.

One drawback of projection plots is that particle tracks cannot be overlaid on
them at present. Moreover, checking for overlap regions is not currently
Expand Down Expand Up @@ -186,22 +241,22 @@ Two camera projections are available when using these plots, perspective and
orthographic. The default, perspective projection, is a cone of rays passing
through each pixel which radiate from the camera position and span the field of
view in the x and y positions. The horizontal field of view can be set with the
:attr: `ProjectionPlot.horizontal_field_of_view` attribute, which is to be
:attr:`ProjectionPlot.horizontal_field_of_view` attribute, which is to be
specified in units of degrees. The field of view only influences behavior in
perspective projection mode.

In the orthographic projection, rays follow the same angle but originate from
different points. The horizontal width of this plane of ray starting points may
be set with the :attr: `ProjectionPlot.orthographic_width` element. If this
be set with the :attr:`ProjectionPlot.orthographic_width` attribute. If this
element is nonzero, the orthographic projection is employed. Left to its default
value of zero, the perspective projection is employed.

Lastly, projection plots come packaged with wireframe generation that can target
either all surface/cell/material boundaries in the geometry, or only wireframing
around specific regions. In the above example, we have set only the fuel region
from the hexagonal lattice example to have a wireframe drawn around it. This is
accomplished by setting the :attr: `ProjectionPlot.wireframe_domains`, which may
be set to either material IDs or cell IDs. The
accomplished by setting the :attr:`ProjectionPlot.wireframe_domains` attribute,
which may be set to either material IDs or cell IDs. The
:attr:`ProjectionPlot.wireframe_thickness` attribute sets the wireframe
thickness in units of pixels.

Expand Down
2 changes: 1 addition & 1 deletion include/openmc/cell.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Region {
//!
//! Uses the comobination of half-spaces and binary operators to determine
//! if short circuiting can be used. Short cicuiting uses the relative and
//! absolute depth of parenthases in the expression.
//! absolute depth of parentheses in the expression.
bool contains_complex(Position r, Direction u, int32_t on_surface) const;

//! BoundingBox if the paritcle is in a simple cell.
Expand Down
3 changes: 2 additions & 1 deletion include/openmc/dagmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class DAGSurface : public Surface {
double evaluate(Position r) const override;
double distance(Position r, Direction u, bool coincident) const override;
Direction normal(Position r) const override;
Direction reflect(Position r, Direction u, GeometryState* p) const override;
Direction reflect(
Position r, Direction u, GeometryState* p = nullptr) const override;

inline void to_hdf5_inner(hid_t group_id) const override {};

Expand Down
4 changes: 0 additions & 4 deletions include/openmc/particle.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ class Particle : public ParticleData {

double speed() const;

//! moves the particle by the distance length to its next location
//! \param length the distance the particle is moved
void move_distance(double length);

//! create a secondary particle
//
//! stores the current phase space attributes of the particle in the
Expand Down
14 changes: 13 additions & 1 deletion include/openmc/particle_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ struct BoundaryInfo {
array<int, 3>
lattice_translation {}; //!< which way lattice indices will change

void reset()
{
distance = INFINITY;
surface = SURFACE_NONE;
coord_level = 0;
lattice_translation = {0, 0, 0};
}
// TODO: off-by-one
int surface_index() const { return std::abs(surface) - 1; }
};
Expand Down Expand Up @@ -226,6 +233,12 @@ class GeometryState {
n_coord_last_ = 1;
}

//! moves the particle by the specified distance to its next location
//! \param distance the distance the particle is moved
void move_distance(double distance);

void advance_to_boundary_from_void();

// Initialize all internal state from position and direction
void init_from_r_u(Position r_a, Direction u_a)
{
Expand Down Expand Up @@ -563,7 +576,6 @@ class ParticleData : public GeometryState {
int& cell_born() { return cell_born_; }
const int& cell_born() const { return cell_born_; }

// index of the current and last material
// Total number of collisions suffered by particle
int& n_collision() { return n_collision_; }
const int& n_collision() const { return n_collision_; }
Expand Down
Loading