-
Notifications
You must be signed in to change notification settings - Fork 639
Introduce new C API function for slice plots #3806
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
Open
paulromano
wants to merge
16
commits into
openmc-dev:develop
Choose a base branch
from
paulromano:slice-plot-api
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c547b57
Add filter_get_bins interface (not efficient for plotter)
paulromano 7f668bc
Combine filter index search with id_map
paulromano 2287926
Implement new openmc_raster_plot function
paulromano b12b92e
Avoid duplicated code in get_raster_map
paulromano e86c060
Remove get_plot_bins for Filter
paulromano 2e81cb0
Add tests for raster_plot
paulromano d80198b
Small doc fix
paulromano 3db1e54
Initial shot at arbitrary orientation slice plots
paulromano adf7ad3
Remove 'axes' and reorder arguments in lib.raster_plot
paulromano fceb98c
Support u_span and v_span in Model.raster_plot
paulromano ac0e900
Rename raster -> slice for consistency
paulromano 4d6c610
Merge branch 'develop' into slice-plot-api
paulromano 6533034
Restore original (arbitrary) direction for slice plotting
paulromano 4824efa
Revert changes to comments
paulromano 1485504
Merge branch 'develop' into slice-plot-api
paulromano 447efcc
Merge branch 'develop' into slice-plot-api
paulromano File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |
| #include "openmc/position.h" | ||
| #include "openmc/random_lcg.h" | ||
| #include "openmc/ray.h" | ||
| #include "openmc/tallies/filter.h" | ||
| #include "openmc/tallies/filter_match.h" | ||
| #include "openmc/xml_interface.h" | ||
|
|
||
| namespace openmc { | ||
|
|
@@ -148,10 +150,11 @@ class PlottableInterface { | |
|
|
||
| struct IdData { | ||
| // Constructor | ||
| IdData(size_t h_res, size_t v_res); | ||
| IdData(size_t h_res, size_t v_res, bool include_filter = false); | ||
|
|
||
| // Methods | ||
| void set_value(size_t y, size_t x, const GeometryState& p, int level); | ||
| void set_value(size_t y, size_t x, const Particle& p, int level, | ||
| Filter* filter = nullptr, FilterMatch* match = nullptr); | ||
| void set_overlap(size_t y, size_t x); | ||
|
|
||
| // Members | ||
|
|
@@ -160,24 +163,42 @@ struct IdData { | |
|
|
||
| struct PropertyData { | ||
| // Constructor | ||
| PropertyData(size_t h_res, size_t v_res); | ||
| PropertyData(size_t h_res, size_t v_res, bool include_filter = false); | ||
|
|
||
| // Methods | ||
| void set_value(size_t y, size_t x, const GeometryState& p, int level); | ||
| void set_value(size_t y, size_t x, const Particle& p, int level, | ||
| Filter* filter = nullptr, FilterMatch* match = nullptr); | ||
| void set_overlap(size_t y, size_t x); | ||
|
|
||
| // Members | ||
| tensor::Tensor<double> data_; //!< 2D array of temperature & density data | ||
| }; | ||
|
|
||
| struct RasterData { | ||
| // Constructor | ||
| RasterData(size_t h_res, size_t v_res, bool include_filter = false); | ||
|
|
||
| // Methods | ||
| void set_value(size_t y, size_t x, const Particle& p, int level, | ||
| Filter* filter = nullptr, FilterMatch* match = nullptr); | ||
| void set_overlap(size_t y, size_t x); | ||
|
|
||
| // Members | ||
| tensor::Tensor<int32_t> | ||
| id_data_; //!< [v_res, h_res, 3 or 4]: cell, instance, mat, [filter_bin] | ||
| tensor::Tensor<double> | ||
| property_data_; //!< [v_res, h_res, 2]: temperature, density | ||
| bool include_filter_; //!< Whether filter bin index is included | ||
| }; | ||
|
|
||
| //=============================================================================== | ||
| // Plot class | ||
| //=============================================================================== | ||
|
|
||
| class SlicePlotBase { | ||
| public: | ||
| template<class T> | ||
| T get_map() const; | ||
| T get_map(int32_t filter_index = -1) const; | ||
|
|
||
| enum class PlotBasis { xy = 1, xz = 2, yz = 3 }; | ||
|
|
||
|
|
@@ -189,69 +210,66 @@ class SlicePlotBase { | |
| // Members | ||
| public: | ||
| Position origin_; //!< Plot origin in geometry | ||
| Position width_; //!< Plot width in geometry | ||
| PlotBasis basis_; //!< Plot basis (XY/XZ/YZ) | ||
| Position u_span_; //!< Full-width span vector in geometry | ||
| Position v_span_; //!< Full-height span vector in geometry | ||
| Position width_; //!< Axis-aligned plot width in geometry | ||
| PlotBasis basis_; //!< Plot basis (XY/XZ/YZ) for axis-aligned slices | ||
|
Contributor
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 this property still needed on the C++ side? |
||
| array<size_t, 3> pixels_; //!< Plot size in pixels | ||
| bool slice_color_overlaps_; //!< Show overlapping cells? | ||
| int slice_level_ {-1}; //!< Plot universe level | ||
| private: | ||
| }; | ||
|
|
||
| template<class T> | ||
| T SlicePlotBase::get_map() const | ||
| T SlicePlotBase::get_map(int32_t filter_index) const | ||
| { | ||
|
|
||
| size_t width = pixels_[0]; | ||
| size_t height = pixels_[1]; | ||
|
|
||
| // get pixel size | ||
| double in_pixel = (width_[0]) / static_cast<double>(width); | ||
| double out_pixel = (width_[1]) / static_cast<double>(height); | ||
| // Determine if filter is being used | ||
| bool include_filter = (filter_index >= 0); | ||
| Filter* filter = nullptr; | ||
| if (include_filter) { | ||
| filter = model::tally_filters[filter_index].get(); | ||
| } | ||
|
|
||
| // size data array | ||
| T data(width, height); | ||
|
|
||
| // setup basis indices and initial position centered on pixel | ||
| int in_i, out_i; | ||
| Position xyz = origin_; | ||
| switch (basis_) { | ||
| case PlotBasis::xy: | ||
| in_i = 0; | ||
| out_i = 1; | ||
| break; | ||
| case PlotBasis::xz: | ||
| in_i = 0; | ||
| out_i = 2; | ||
| break; | ||
| case PlotBasis::yz: | ||
| in_i = 1; | ||
| out_i = 2; | ||
| break; | ||
| default: | ||
| UNREACHABLE(); | ||
| } | ||
| T data(width, height, include_filter); | ||
|
|
||
| // set initial position | ||
| xyz[in_i] = origin_[in_i] - width_[0] / 2. + in_pixel / 2.; | ||
| xyz[out_i] = origin_[out_i] + width_[1] / 2. - out_pixel / 2.; | ||
| // compute pixel steps and top-left pixel center | ||
| Position u_step = u_span_ / static_cast<double>(width); | ||
| Position v_step = v_span_ / static_cast<double>(height); | ||
|
|
||
| Position start = | ||
| origin_ - 0.5 * u_span_ + 0.5 * v_span_ + 0.5 * u_step - 0.5 * v_step; | ||
|
|
||
| // Validate that span vectors define a valid plane | ||
| Position cross = u_span_.cross(v_span_); | ||
| if (cross.norm() == 0.0) { | ||
| fatal_error("Slice span vectors are invalid (zero area)."); | ||
| } | ||
|
|
||
| // arbitrary direction | ||
| Direction dir = {1. / std::sqrt(2.), 1. / std::sqrt(2.), 0.0}; | ||
| // Use an arbitrary direction that is not aligned with any coordinate axis. | ||
| // The direction has no physical meaning for plotting but is used by | ||
| // Surface::sense() to break ties when a pixel is coincident with a surface. | ||
| Direction dir = {1.0 / std::sqrt(2.0), 1.0 / std::sqrt(2.0), 0.0}; | ||
|
|
||
| #pragma omp parallel | ||
| { | ||
| GeometryState p; | ||
| p.r() = xyz; | ||
| Particle p; | ||
| p.r() = start; | ||
| p.u() = dir; | ||
| p.coord(0).universe() = model::root_universe; | ||
| int level = slice_level_; | ||
| int j {}; | ||
| FilterMatch match; | ||
|
|
||
| #pragma omp for | ||
| for (int y = 0; y < height; y++) { | ||
| p.r()[out_i] = xyz[out_i] - out_pixel * y; | ||
| Position row = start - v_step * static_cast<double>(y); | ||
| for (int x = 0; x < width; x++) { | ||
| p.r()[in_i] = xyz[in_i] + in_pixel * x; | ||
| p.r() = row + u_step * static_cast<double>(x); | ||
| p.n_coord() = 1; | ||
| // local variables | ||
| bool found_cell = exhaustive_find_cell(p); | ||
|
|
@@ -260,7 +278,7 @@ T SlicePlotBase::get_map() const | |
| j = level; | ||
| } | ||
| if (found_cell) { | ||
| data.set_value(y, x, p, j); | ||
| data.set_value(y, x, p, j, filter, &match); | ||
| } | ||
| if (slice_color_overlaps_ && check_cell_overlap(p, false)) { | ||
| data.set_overlap(y, x); | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Perhaps
Directionis a more appropriate type for the vectorsu_span_andv_span_specified here.