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

Add PointCloud spatial distribution #3161

Merged
merged 40 commits into from
Nov 13, 2024

Conversation

gonuke
Copy link
Contributor

@gonuke gonuke commented Oct 5, 2024

Description

Allows users to define a list of points in space, each with a different relative intensity, to be sampled discretely. This is a valid SpatialDistribution and can be used anywhere that a SpatialDistribution is valid.

Fixes #3159

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 15) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

@gonuke gonuke marked this pull request as ready for review October 5, 2024 20:08
openmc/stats/multivariate.py Outdated Show resolved Hide resolved
openmc/stats/multivariate.py Outdated Show resolved Hide resolved
Copy link
Contributor

@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 this snappy PR @gonuke! A useful distribution that we haven't been able to support before!

include/openmc/distribution_spatial.h Outdated Show resolved Hide resolved
include/openmc/distribution_spatial.h Outdated Show resolved Hide resolved
Comment on lines 778 to 779
psoitions: numpy.ndarray (3xN)
The points in space to be sampled
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
psoitions: numpy.ndarray (3xN)
The points in space to be sampled
positions: numpy.ndarray
The points in space to be sampled with shape (N, 3)

return cls(positions, strengths)



Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

"""
coord = {}

for axis in ('x','y','z'):
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm thinking the XML format of the data as a flat list of points (X1, Y1, Z1, X2, Y2, Z2, ...) would make the import export code simpler, and it isn't more or less readable in an XML format (for my brain anyway).

include/openmc/distribution_spatial.h Outdated Show resolved Hide resolved

for idx, axis in enumerate(('x','y','z')):
subelement = ET.SubElement(element, axis)
subelement.text = ' '.join(str(e) for e in self.positions[idx,:])
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
subelement.text = ' '.join(str(e) for e in self.positions[idx,:])
subelement.text = ' '.join(str(e) for e in self.positions[..., idx])

I think?

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

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

@gonuke Thanks for this PR! Out of curiosity, what is the intended application of this feature?

@gonuke
Copy link
Contributor Author

gonuke commented Oct 10, 2024

We have a user who has an existing approximation of a volumetric source by a high density list of isotropic point sources. They want to use that source for comparison to other simulations.

@gonuke
Copy link
Contributor Author

gonuke commented Oct 12, 2024

While it may have been elegant to add an istream operator for Position the version I added did not round-trip with the existing ostream operator and it is more convenient in XML to not use the verbose ostream format.

Thus, I've relied on just reading a list of doubles and packing them into Position in the reader.

Copy link
Contributor

@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.

Some small line suggestions here @gonuke. I went ahead and added test that samples the external source distribution on the C++ side and factored out a function in the XML interface for parsing a set of Positions from a flat array of values on a node. Hope that's okay!

Thanks again for this addition.

docs/source/usersguide/settings.rst Outdated Show resolved Hide resolved
openmc/stats/multivariate.py Outdated Show resolved Hide resolved
openmc/stats/multivariate.py Show resolved Hide resolved
Comment on lines 794 to 795
if given_positions is None:
raise ValueError('No positions were provided')
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd opt to let the check_iterable_type throw an error here instead.

openmc/stats/multivariate.py Show resolved Hide resolved
src/distribution_spatial.cpp Outdated Show resolved Hide resolved
openmc/stats/multivariate.py Outdated Show resolved Hide resolved
pshriwise and others added 11 commits October 16, 2024 10:10
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
Co-authored-by: Patrick Shriwise <pshriwise@gmail.com>
Copy link
Contributor

@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.

I just pushed a couple of small changes, but this looks good to me! @paulromano, you mentioned you'd like to have a look at this as well, so I'll give you a little time to review.

src/distribution_spatial.cpp Outdated Show resolved Hide resolved
src/distribution_spatial.cpp Outdated Show resolved Hide resolved
@gonuke
Copy link
Contributor Author

gonuke commented Nov 13, 2024

Pinging @paulromano to see if this can move forward?

Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

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

Thanks @gonuke! I did a bit of refactoring and simplification. I'm good to merge but before I do, let me know if you object to any of my changes.

@gonuke
Copy link
Contributor Author

gonuke commented Nov 13, 2024

All looks good to me - thanks @paulromano

Copy link
Contributor

@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.

Thank you @gonuke!

@paulromano paulromano merged commit 58400cb into openmc-dev:develop Nov 13, 2024
16 checks passed
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.

Allow sampling source location from a point cloud with discrete probabilities
3 participants