Skip to content

Commit d7f6be7

Browse files
authored
Merge pull request #747 from idaholab/652-surfaces-cant-be-created-and-exported-from-scratch
Made making surfaces from scratch possible.
2 parents 156024e + 9aaaa5e commit d7f6be7

File tree

11 files changed

+317
-98
lines changed

11 files changed

+317
-98
lines changed

doc/source/changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@ MontePy Changelog
1414

1515
**Bugs Fixed**
1616

17+
* Fixed bug where surfaces created from scratch couldn't be accurately written out to the file (:issue:`652`).
18+
* Fixed bug where surface transformations couldn't be unset and exported properly (:issue:`711`).
19+
* Fixed bug where negative numbers were treated as valid by ``append_renumber`` (:issue:`690`).
1720
* Fixed bug that couldn't parse ``SDEF`` by simply not parsing the input for the time being (:pull:`767`).
1821
* Fixed parsing bug with ``DE LOG`` style inputs by simply not parsing them for now (:pull:`767`).
1922

23+
2024
1.1.0
2125
--------------
2226

@@ -31,6 +35,8 @@ MontePy Changelog
3135
* Fixed bug where MontePy would overly aggressively round outputs and remove the user's intent (:issue:`756`).
3236
* Fixed bug where a cell complement in the first five characters causes a spurious vertical mode detection (:issue:`753`).
3337

38+
1.0 releases
39+
============
3440

3541
1.0 releases
3642
============

doc/source/developing.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ How to __init__
347347
"""""""""""""""
348348
After running the super init method
349349
you will then have access to ``self.surface_type``, and ``self.surface_constants``.
350-
You then need to verify that the surface type is correct, and there are the correct number of surface constants.
350+
You will need to implement a ``_allowed_surface_types`` to specify which surface types are allowed for your class.
351+
You then need to verify that there are the correct number of surface constants.
351352
You will also need to add a branch in the logic for :func:`montepy.surfaces.surface_builder.surface_builder`.
352353

353354
:func:`~montepy.surfaces.surface.Surface.find_duplicate_surfaces`

montepy/input_parser/syntax_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ def _convert_to_enum(
10491049
convert to enum.
10501050
"""
10511051
self._type = enum_class
1052-
if switch_to_upper:
1052+
if switch_to_upper and self._value is not None:
10531053
value = self._value.upper()
10541054
else:
10551055
value = self._value

montepy/numbered_mcnp_object.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def __init__(
5555
parser: montepy.input_parser.parser_base.MCNP_Parser,
5656
number: int = None,
5757
):
58-
self._number = self._generate_default_node(int, -1)
58+
if not input:
59+
self._number = self._generate_default_node(int, -1)
5960
super().__init__(input, parser)
6061
self._load_init_num(number)
6162

montepy/numbered_object_collection.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,11 @@ def check_number(self, number):
243243
"""
244244
if not isinstance(number, Integral):
245245
raise TypeError("The number must be an int")
246+
247+
if number < 0:
248+
raise ValueError(f"The number must be non-negative. {number} given.")
246249
conflict = False
247-
# only can trust cache if being
250+
# only can trust cache if being updated
248251
if self._problem:
249252
if number in self.__num_cache:
250253
conflict = True
@@ -476,6 +479,8 @@ def __internal_append(self, obj, **kwargs):
476479
raise TypeError(
477480
f"Object must be of type: {self._obj_class.__name__}. {obj} given."
478481
)
482+
if obj.number < 0:
483+
raise ValueError(f"The number must be non-negative. {obj.number} given.")
479484
if obj.number in self.__num_cache:
480485
try:
481486
if obj is self[obj.number]:
@@ -603,12 +608,12 @@ def append_renumber(self, obj, step=1):
603608
raise TypeError(f"object being appended must be of type: {self._obj_class}")
604609
if not isinstance(step, Integral):
605610
raise TypeError("The step number must be an int")
606-
number = obj.number
611+
number = obj.number if obj.number > 0 else 1
607612
if self._problem:
608613
obj.link_to_problem(self._problem)
609614
try:
610615
self.append(obj)
611-
except NumberConflictError:
616+
except (NumberConflictError, ValueError) as e:
612617
number = self.request_number(number, step)
613618
obj.number = number
614619
self.append(obj)

montepy/surfaces/axis_plane.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from montepy.errors import *
66
from montepy.utilities import *
77

8+
from typing import Union
9+
810

911
class AxisPlane(Surface):
1012
"""Represents PX, PY, PZ
@@ -19,22 +21,23 @@ class AxisPlane(Surface):
1921
The Input object representing the input
2022
number : int
2123
The number to set for this object.
24+
surface_type: Union[SurfaceType, str]
25+
The surface_type to set for this object
2226
"""
2327

2428
COORDINATE = {SurfaceType.PX: "x", SurfaceType.PY: "y", SurfaceType.PZ: "z"}
2529

26-
def __init__(self, input: InitInput = None, number: int = None):
30+
def __init__(
31+
self,
32+
input: InitInput = None,
33+
number: int = None,
34+
surface_type: Union[SurfaceType, str] = None,
35+
):
2736
self._location = self._generate_default_node(float, None)
28-
super().__init__(input, number)
29-
ST = SurfaceType
30-
if input:
31-
if self.surface_type not in [ST.PX, ST.PY, ST.PZ]:
32-
raise ValueError("AxisPlane must be a surface of type: PX, PY, or PZ")
33-
if len(self.surface_constants) != 1:
34-
raise ValueError("AxisPlane must have exactly 1 surface constant")
35-
self._location = self._surface_constants[0]
36-
else:
37-
self._surface_constants = [self._location]
37+
super().__init__(input, number, surface_type)
38+
if len(self.surface_constants) != 1:
39+
raise ValueError("AxisPlane must have exactly 1 surface constant")
40+
self._location = self._surface_constants[0]
3841

3942
@make_prop_val_node("_location", (float, int), float)
4043
def location(self):
@@ -46,6 +49,10 @@ def location(self):
4649
"""
4750
pass
4851

52+
@staticmethod
53+
def _allowed_surface_types():
54+
return {SurfaceType.PX, SurfaceType.PY, SurfaceType.PZ}
55+
4956
def validate(self):
5057
super().validate()
5158
if self.location is None:

montepy/surfaces/cylinder_on_axis.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from montepy.errors import *
55
from montepy.utilities import *
66

7+
from typing import Union
8+
79

810
def _enforce_positive_radius(self, value):
911
if value < 0.0:
@@ -23,20 +25,21 @@ class CylinderOnAxis(Surface):
2325
The Input object representing the input
2426
number : int
2527
The number to set for this object.
28+
surface_type: Union[SurfaceType, str]
29+
The surface_type to set for this object
2630
"""
2731

28-
def __init__(self, input: InitInput = None, number: int = None):
32+
def __init__(
33+
self,
34+
input: InitInput = None,
35+
number: int = None,
36+
surface_type: Union[SurfaceType, str] = None,
37+
):
2938
self._radius = self._generate_default_node(float, None)
30-
super().__init__(input, number)
31-
ST = SurfaceType
32-
if input:
33-
if self.surface_type not in [ST.CX, ST.CY, ST.CZ]:
34-
raise ValueError("CylinderOnAxis must be of surface_type: CX, CY, CZ")
35-
if len(self.surface_constants) != 1:
36-
raise ValueError("CylinderOnAxis only accepts one surface_constant")
37-
self._radius = self._surface_constants[0]
38-
else:
39-
self._surface_constants = [self._radius]
39+
super().__init__(input, number, surface_type)
40+
if len(self.surface_constants) != 1:
41+
raise ValueError("CylinderOnAxis only accepts one surface_constant")
42+
self._radius = self._surface_constants[0]
4043

4144
@make_prop_val_node(
4245
"_radius", (float, int), float, validator=_enforce_positive_radius
@@ -50,6 +53,10 @@ def radius(self):
5053
"""
5154
pass
5255

56+
@staticmethod
57+
def _allowed_surface_types():
58+
return {SurfaceType.CX, SurfaceType.CY, SurfaceType.CZ}
59+
5360
def validate(self):
5461
super().validate()
5562
if self.radius is None:

montepy/surfaces/cylinder_par_axis.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from montepy.utilities import *
66

77
from numbers import Real
8+
from typing import Union
89

910

1011
def _enforce_positive_radius(self, value):
@@ -25,6 +26,8 @@ class CylinderParAxis(Surface):
2526
The Input object representing the input
2627
number : int
2728
The number to set for this object.
29+
surface_type: Union[SurfaceType, str]
30+
The surface_type to set for this object
2831
"""
2932

3033
COORDINATE_PAIRS = {
@@ -34,27 +37,30 @@ class CylinderParAxis(Surface):
3437
}
3538
"""Which coordinate is what value for each cylinder type."""
3639

37-
def __init__(self, input: InitInput = None, number: int = None):
40+
def __init__(
41+
self,
42+
input: InitInput = None,
43+
number: int = None,
44+
surface_type: Union[SurfaceType, str] = None,
45+
):
3846
self._coordinates = [
3947
self._generate_default_node(float, None),
4048
self._generate_default_node(float, None),
4149
]
4250
self._radius = self._generate_default_node(float, None)
43-
super().__init__(input, number)
44-
ST = SurfaceType
45-
if input:
46-
if self.surface_type not in [ST.C_X, ST.C_Y, ST.C_Z]:
47-
raise ValueError(
48-
"CylinderParAxis must be a surface of types: C/X, C/Y, C/Z"
49-
)
50-
if len(self.surface_constants) != 3:
51-
raise ValueError(
52-
"CylinderParAxis must have exactly 3 surface_constants"
53-
)
54-
self._coordinates = self._surface_constants[0:2]
55-
self._radius = self._surface_constants[2]
56-
else:
57-
self._surface_constants = [*self._coordinates, self._radius]
51+
super().__init__(input, number, surface_type)
52+
if len(self.surface_constants) != 3:
53+
raise ValueError("CylinderParAxis must have exactly 3 surface_constants")
54+
self._coordinates = self._surface_constants[0:2]
55+
self._radius = self._surface_constants[2]
56+
57+
@staticmethod
58+
def _number_of_params():
59+
return 3
60+
61+
@staticmethod
62+
def _allowed_surface_types():
63+
return {SurfaceType.C_X, SurfaceType.C_Y, SurfaceType.C_Z}
5864

5965
@property
6066
def coordinates(self):

0 commit comments

Comments
 (0)