-
Notifications
You must be signed in to change notification settings - Fork 18
Support Spheres #877
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
Merged
Support Spheres #877
Changes from 29 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
52fd292
Add SphereOnAxis
tjlaboss 1e3f752
Add GeneralSphere
tjlaboss 24be846
Add SphereAtOrigin
tjlaboss d33847a
Touch up sphere files
tjlaboss ddd19fa
Add spheres to surface builder
tjlaboss f300c46
format_for_mcnp_input() type hinting
tjlaboss 639def3
Debug general sphere
tjlaboss 6875e8a
Test sphere constant setter
tjlaboss 145eeae
Test the new sphere classes
tjlaboss 25db4d3
Update CHANGELOG
tjlaboss 8a791ec
Touch up GeneralSphere some more
tjlaboss 36ce708
A sphere cannot be a periodic surface of a plane.
tjlaboss 6f1d999
Restore sphere periodic check
tjlaboss d7e2271
Format with black
tjlaboss 1652be1
Increase sphere code coverage
tjlaboss 2c6eaf5
test_surfaces.py cleanup
tjlaboss 8f71eb4
Merge branch 'develop' into baller
tjlaboss 63fcc47
Update montepy/surfaces/general_sphere.py
tjlaboss 58fc726
Update montepy/surfaces/general_sphere.py
tjlaboss a8d4bf5
Remove copypasted duplicate surface finding
tjlaboss cb1556e
Update surfaces/__init__.py
tjlaboss 5625055
surface_type does not need to be passed here
tjlaboss 17864bc
mislabeled test
tjlaboss fea49b0
Add spheres to doc toc
tjlaboss cfd1431
Spheres will be added to version 1.3.0
tjlaboss 31e9b92
pragma: no cover
tjlaboss 4bf6df3
Increase sphere coverage
tjlaboss ea0fb6f
Corrected version-added directives
tjlaboss ed6f05d
versionadded directive not renamed just yet
tjlaboss fd759da
Merge branch 'develop' into baller
tjlaboss dae51fc
Move # pragma: no cover
tjlaboss c65d1d6
surface_type setting for sphere testing
tjlaboss f96169e
Fix overwritten test
tjlaboss 6fd41fc
lil fixes
tjlaboss b4f42aa
Increase sphere text coverage
tjlaboss 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
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
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 |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # Copyright 2026, Battelle Energy Alliance, LLC All Rights Reserved. | ||
| from .surface_type import SurfaceType | ||
| from .surface import Surface, InitInput | ||
| from montepy.exceptions import * | ||
| from montepy.utilities import * | ||
|
|
||
| from numbers import Real | ||
| from typing import Union | ||
|
|
||
|
|
||
| def _enforce_positive_radius(self, value): | ||
| if value < 0.0: | ||
| raise ValueError(f"Radius must be positive. {value} given") | ||
|
|
||
|
|
||
| class GeneralSphere(Surface): | ||
| """Represents surface S: a general sphere | ||
|
|
||
| .. versionadded:: 1.3.0 | ||
|
|
||
| Parameters | ||
| ---------- | ||
| input : Union[Input, str] | ||
| The Input object representing the input | ||
| number : int | ||
| The number to set for this object. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| input: InitInput = None, | ||
| number: int = None, | ||
| ): | ||
| self._coordinates = [ | ||
| self._generate_default_node(float, None), | ||
| self._generate_default_node(float, None), | ||
| self._generate_default_node(float, None), | ||
| ] | ||
| self._radius = self._generate_default_node(float, None) | ||
| super().__init__(input, number) | ||
| if input and self.surface_type != SurfaceType.S: | ||
MicahGale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| raise ValueError(f"A {self.__class__.__name__} must be a surface of type S") | ||
| if len(self.surface_constants) != 4: | ||
| raise ValueError( | ||
| f"A {self.__class__.__name__} must have exactly 4 surface_constants" | ||
| ) | ||
| self._coordinates = self._surface_constants[:3] | ||
| self._radius = self._surface_constants[3] | ||
|
|
||
| @staticmethod | ||
| def _number_of_params(): | ||
| return 4 | ||
|
|
||
| @make_prop_val_node( | ||
| "_radius", (float, int), float, validator=_enforce_positive_radius | ||
| ) | ||
| def radius(self): | ||
| """The radius of the sphere | ||
|
|
||
| Returns | ||
| ------- | ||
| float | ||
| """ | ||
| pass | ||
|
|
||
| @property | ||
| def coordinates(self): | ||
| """The three coordinates for the sphere center | ||
|
|
||
| :rytpe: tuple | ||
tjlaboss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """ | ||
| return tuple(c.value for c in self._coordinates) | ||
|
|
||
| @coordinates.setter | ||
| def coordinates(self, coordinates): | ||
| if not isinstance(coordinates, (list, tuple)): | ||
| raise TypeError("coordinates must be a list") | ||
| if len(coordinates) != 3: | ||
| raise ValueError("coordinates must have exactly three elements") | ||
| for val in coordinates: | ||
| if not isinstance(val, Real): | ||
| raise TypeError(f"Coordinate must be a number. {val} given.") | ||
| for i, val in enumerate(coordinates): | ||
| self._coordinates[i].value = val | ||
|
|
||
| def validate(self): | ||
| super().validate() | ||
| if self.radius is None: # pragma: no cover | ||
| raise IllegalState(f"Surface: {self.number} does not have a radius set.") | ||
| if any({c is None for c in self.coordinates}): # pragma: no cover | ||
| raise IllegalState(f"Surface: {self.number} does not have coordinates set.") | ||
|
|
||
| def find_duplicate_surfaces(self, surfaces, tolerance): | ||
| """Duplicate sphere finding is not yet implemented""" | ||
| return [] | ||
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 |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Copyright 2026, Battelle Energy Alliance, LLC All Rights Reserved. | ||
| from .surface_type import SurfaceType | ||
| from .surface import Surface, InitInput | ||
| from montepy.exceptions import * | ||
| from montepy.utilities import * | ||
|
|
||
| from typing import Union | ||
|
|
||
|
|
||
| def _enforce_positive_radius(self, value): | ||
| if value < 0.0: | ||
| raise ValueError(f"Radius must be positive. {value} given") | ||
|
|
||
|
|
||
| class SphereAtOrigin(Surface): | ||
| """Represents surface SO: a sphere at the origin | ||
|
|
||
| .. versionadded:: 1.3.0 | ||
|
|
||
| Parameters | ||
| ---------- | ||
| input : Union[Input, str] | ||
| The Input object representing the input | ||
| number : int | ||
| The number to set for this object. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| input: InitInput = None, | ||
| number: int = None, | ||
| ): | ||
| self._location = self._generate_default_node(float, None) | ||
| self._radius = self._generate_default_node(float, None) | ||
| super().__init__(input, number) | ||
| if len(self.surface_constants) != 1: | ||
| raise ValueError( | ||
| f"{self.__class__.__name__} must have exactly 1 surface_constant" | ||
| ) | ||
| self._radius = self._surface_constants[0] | ||
|
|
||
| @make_prop_val_node( | ||
| "_radius", (float, int), float, validator=_enforce_positive_radius | ||
| ) | ||
| def radius(self): | ||
| """The radius of the sphere | ||
|
|
||
| Returns | ||
| ------- | ||
| float | ||
| """ | ||
| pass | ||
|
|
||
| def validate(self): | ||
| super().validate() | ||
| if self.radius is None: # pragma: no cover | ||
| raise IllegalState(f"Surface: {self.number} does not have a radius set.") | ||
|
|
||
| def find_duplicate_surfaces(self, surfaces, tolerance): | ||
| """Duplicate sphere finding is not yet implemented""" | ||
| return [] |
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 |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # Copyright 2026, Battelle Energy Alliance, LLC All Rights Reserved. | ||
| from .surface_type import SurfaceType | ||
| from .surface import Surface, InitInput | ||
| from montepy.exceptions import * | ||
| from montepy.utilities import * | ||
|
|
||
| from typing import Union | ||
|
|
||
|
|
||
| def _enforce_positive_radius(self, value): | ||
| if value < 0.0: | ||
| raise ValueError(f"Radius must be positive. {value} given") | ||
|
|
||
|
|
||
| class SphereOnAxis(Surface): | ||
| """Represents surfaces SX, SY, and SZ: spheres on axes | ||
|
|
||
| .. versionadded:: 1.3.0 | ||
|
|
||
| Parameters | ||
| ---------- | ||
| input : Union[Input, str] | ||
| The Input object representing the input | ||
| number : int | ||
| The number to set for this object. | ||
| surface_type: Union[SurfaceType, str] | ||
| The surface_type to set for this object | ||
| """ | ||
|
|
||
| COORDINATE = {SurfaceType.SX: "x", SurfaceType.SY: "y", SurfaceType.SZ: "z"} | ||
|
|
||
| def __init__( | ||
| self, | ||
| input: InitInput = None, | ||
| number: int = None, | ||
| surface_type: Union[SurfaceType, str] = None, | ||
| ): | ||
| self._location = self._generate_default_node(float, None) | ||
| self._radius = self._generate_default_node(float, None) | ||
| super().__init__(input, number, surface_type) | ||
| if len(self.surface_constants) != 2: | ||
| raise ValueError( | ||
| f"{self.__class__.__name__} must have exactly 2 surface_constants" | ||
| ) | ||
| self._location, self._radius = self._surface_constants | ||
|
|
||
| @staticmethod | ||
| def _number_of_params(): | ||
| return 2 | ||
|
|
||
| @make_prop_val_node( | ||
| "_radius", (float, int), float, validator=_enforce_positive_radius | ||
| ) | ||
| def radius(self): | ||
| """The radius of the sphere | ||
|
|
||
| Returns | ||
| ------- | ||
| float | ||
| """ | ||
| pass | ||
|
|
||
| @make_prop_val_node("_location", (float, int), float) | ||
| def location(self): | ||
| """The location of the center of the sphere in space | ||
|
|
||
| Returns | ||
| ------- | ||
| float | ||
| """ | ||
| pass | ||
|
|
||
| @staticmethod | ||
| def _allowed_surface_types(): | ||
| return {SurfaceType.SX, SurfaceType.SY, SurfaceType.SZ} | ||
|
|
||
| def validate(self): | ||
| super().validate() | ||
| if self.radius is None: | ||
| raise IllegalState(f"Surface: {self.number} does not have a radius set.") | ||
| if self.location is None: # pragma: no cover | ||
| raise IllegalState(f"Surface: {self.number} does not have a location set.") | ||
|
|
||
| def find_duplicate_surfaces(self, surfaces, tolerance): | ||
tjlaboss marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """Duplicate sphere finding is not yet implemented""" | ||
| return [] | ||
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 |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| 1 0 -1 | ||
|
|
||
| 1 -2 SO -5 | ||
| 1 SO -5 | ||
| 2 PZ 0.0 | ||
| 3 PZ 5.0 | ||
| 3 -2 PZ 5.0 | ||
| 4 1 PZ 3.0 | ||
|
|
||
| TR1 0 0 1.0 |
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
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.
Uh oh!
There was an error while loading. Please reload this page.