Skip to content

Commit 4098535

Browse files
committed
Remove grading params from user interface;
Users now only have to import the appropriate grader. Also, sort out confusion with exceptions and whatnot. Also also, cleanup some TODO work
1 parent 15ebd41 commit 4098535

File tree

21 files changed

+114
-151
lines changed

21 files changed

+114
-151
lines changed

examples/advanced/autograding_highre.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import classy_blocks as cb
44
from classy_blocks.grading.autograding.grader import HighReGrader
5-
from classy_blocks.grading.autograding.params import HighReChopParams
65

76
mesh = cb.Mesh()
87

@@ -19,18 +18,12 @@
1918
vertex = list(finder.find_in_sphere(point))[0]
2019
vertex.translate([0, 0.8, 0])
2120

22-
# TODO! Un-hack
23-
mesh.block_list.update()
24-
2521
mesh.set_default_patch("walls", "wall")
2622

23+
# TODO: Hack! mesh.assemble() won't work here but wires et. al. must be updated
24+
mesh.block_list.update()
2725

28-
params = HighReChopParams(0.05)
29-
grader = HighReGrader(mesh, params)
26+
grader = HighReGrader(mesh, 0.05)
3027
grader.grade()
3128

32-
# params = SimpleChopParams(0.05)
33-
# grader = SimpleGrader(mesh, params)
34-
# grader.grade(take="max")
35-
3629
mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")

examples/advanced/low_re_chops.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

examples/complex/cyclone/geometry.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@
1515
T_PIPE,
1616
)
1717

18+
from classy_blocks.base.exceptions import GeometryConstraintError
1819
from classy_blocks.types import NPPointType
1920
from classy_blocks.util import functions as f
2021
from classy_blocks.util.constants import vector_format as fvect
2122

2223

23-
class GeometryConstraintError(Exception):
24-
"""Raised when input parameters produce an invalid geometry"""
25-
26-
2724
@dataclasses.dataclass
2825
class Geometry:
2926
"""Holds user-provided parameters and conversions to SI units;

examples/shape/quarter_cylinder.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import classy_blocks as cb
44
from classy_blocks.construct.flat.sketches.disk import QuarterDisk
55
from classy_blocks.grading.autograding.grader import HighReGrader
6-
from classy_blocks.grading.autograding.params import HighReChopParams
76
from classy_blocks.util import functions as f
87

98
mesh = cb.Mesh()
@@ -21,11 +20,8 @@
2120
mesh.add(quarter_cylinder)
2221

2322
mesh.assemble()
24-
# TODO: automate or something
25-
mesh.block_list.update()
2623

27-
params = HighReChopParams(0.05)
28-
grader = HighReGrader(mesh, params)
24+
grader = HighReGrader(mesh, 0.05)
2925
grader.grade()
3026

3127

src/classy_blocks/base/exceptions.py

Lines changed: 78 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,7 @@
11
from typing import Optional
22

33

4-
class VertexNotFoundError(Exception):
5-
"""Raised when a vertex at a given point in space doesn't exist yet"""
6-
7-
8-
class EdgeNotFoundError(Exception):
9-
"""Raised when an edge between a given pair of vertices doesn't exist yet"""
10-
11-
12-
class CornerPairError(Exception):
13-
"""Raised when given pair of corners is not valid (for example, edge between 0 and 2)"""
14-
15-
16-
class UndefinedGradingsError(Exception):
17-
"""Raised when the user hasn't supplied enough grading data to
18-
define all blocks in the mesh"""
19-
20-
21-
class InconsistentGradingsError(Exception):
22-
"""Raised when cell counts for edges on the same axis is not consistent"""
23-
24-
4+
### Construction
255
class ShapeCreationError(Exception):
266
"""Base class for shape creation errors (invalid parameters/types to
277
shape constructors)"""
@@ -75,3 +55,80 @@ class FrustumCreationError(ShapeCreationError):
7555

7656
class ExtrudedRingCreationError(ShapeCreationError):
7757
pass
58+
59+
60+
class GeometryConstraintError(Exception):
61+
"""Raised when input parameters produce an invalid geometry"""
62+
63+
64+
class DegenerateGeometryError(Exception):
65+
"""Raised when orienting failed because of invalid geometry"""
66+
67+
68+
# Shell/offsetting logic
69+
class SharedPointError(Exception):
70+
"""Errors with shared points"""
71+
72+
73+
class SharedPointNotFoundError(SharedPointError):
74+
pass
75+
76+
77+
class PointNotCoincidentError(SharedPointError):
78+
pass
79+
80+
81+
class DisconnectedChopError(SharedPointError):
82+
"""Issued when chopping a Shell that has disconnected faces"""
83+
84+
85+
### Search/retrieval
86+
class VertexNotFoundError(Exception):
87+
"""Raised when a vertex at a given point in space doesn't exist yet"""
88+
89+
90+
class EdgeNotFoundError(Exception):
91+
"""Raised when an edge between a given pair of vertices doesn't exist yet"""
92+
93+
94+
class CornerPairError(Exception):
95+
"""Raised when given pair of corners is not valid (for example, edge between 0 and 2)"""
96+
97+
98+
### Grading
99+
class UndefinedGradingsError(Exception):
100+
"""Raised when the user hasn't supplied enough grading data to
101+
define all blocks in the mesh"""
102+
103+
104+
class InconsistentGradingsError(Exception):
105+
"""Raised when cell counts for edges on the same axis is not consistent"""
106+
107+
108+
class NoInstructionError(Exception):
109+
"""Raised when building a catalogue"""
110+
111+
112+
class BlockNotFoundError(Exception):
113+
"""Raised when building a catalogue"""
114+
115+
116+
### Optimization
117+
class NoClampError(Exception):
118+
"""Raised when there's no junction defined for a given Clamp"""
119+
120+
121+
class ClampExistsError(Exception):
122+
"""Raised when adding a clamp to a junction that already has one defined"""
123+
124+
125+
class NoCommonSidesError(Exception):
126+
"""Raised when two cells don't share a side"""
127+
128+
129+
class NoJunctionError(Exception):
130+
"""Raised when there's a clamp defined for a vertex that doesn't exist"""
131+
132+
133+
class InvalidLinkError(Exception):
134+
"""Raised when a link has been added that doesn't connect two actual points"""

src/classy_blocks/construct/shape.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import numpy as np
77

88
from classy_blocks.base.element import ElementBase
9+
from classy_blocks.base.exceptions import ShapeCreationError
910
from classy_blocks.construct.edges import Angle
1011
from classy_blocks.construct.flat.sketch import Sketch, SketchT
1112
from classy_blocks.construct.operations.loft import Loft
@@ -16,10 +17,6 @@
1617
ShapeT = TypeVar("ShapeT", bound="Shape")
1718

1819

19-
class ShapeCreationError(Exception):
20-
"""Raised when creating a shape from errorneous data"""
21-
22-
2320
class Shape(ElementBase, abc.ABC):
2421
"""A collection of Operations that form a predefined
2522
parametric shape"""

src/classy_blocks/construct/shapes/shell.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import numpy as np
55

6+
from classy_blocks.base.exceptions import DisconnectedChopError, PointNotCoincidentError, SharedPointNotFoundError
67
from classy_blocks.construct.flat.face import Face
78
from classy_blocks.construct.operations.loft import Loft
89
from classy_blocks.construct.point import Point
@@ -11,22 +12,6 @@
1112
from classy_blocks.util import functions as f
1213

1314

14-
class SharedPointError(Exception):
15-
"""Errors with shared points"""
16-
17-
18-
class SharedPointNotFoundError(SharedPointError):
19-
pass
20-
21-
22-
class PointNotCoincidentError(SharedPointError):
23-
pass
24-
25-
26-
class DisconnectedChopError(SharedPointError):
27-
"""Issued when chopping a Shell that has disconnected faces"""
28-
29-
3015
class SharedPoint:
3116
"""A Point with knowledge of its "owner" Face(s)"""
3217

src/classy_blocks/grading/autograding/grader.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class FixedCountGrader(GraderBase):
7070

7171
stages = 1
7272

73-
def __init__(self, mesh: Mesh, params: FixedCountParams):
74-
super().__init__(mesh, params)
73+
def __init__(self, mesh: Mesh, count: int = 8):
74+
super().__init__(mesh, FixedCountParams(count))
7575

7676

7777
class SimpleGrader(GraderBase):
@@ -81,8 +81,8 @@ class SimpleGrader(GraderBase):
8181

8282
stages = 1
8383

84-
def __init__(self, mesh: Mesh, params: SimpleChopParams):
85-
super().__init__(mesh, params)
84+
def __init__(self, mesh: Mesh, cell_size: float):
85+
super().__init__(mesh, SimpleChopParams(cell_size))
8686

8787

8888
class HighReGrader(GraderBase):
@@ -93,5 +93,5 @@ class HighReGrader(GraderBase):
9393

9494
stages = 3
9595

96-
def __init__(self, mesh: Mesh, params: HighReChopParams):
97-
super().__init__(mesh, params)
96+
def __init__(self, mesh: Mesh, cell_size: float):
97+
super().__init__(mesh, HighReChopParams(cell_size))

src/classy_blocks/grading/autograding/probe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import functools
22
from typing import Dict, List, Optional, get_args
33

4+
from classy_blocks.base.exceptions import BlockNotFoundError, NoInstructionError
45
from classy_blocks.items.block import Block
56
from classy_blocks.items.wires.axis import Axis
67
from classy_blocks.items.wires.wire import Wire
@@ -109,7 +110,7 @@ def _find_instruction(self, block: Block):
109110
if instruction.block == block:
110111
return instruction
111112

112-
raise RuntimeError(f"No instruction found for block {block}")
113+
raise NoInstructionError(f"No instruction found for block {block}")
113114

114115
def _add_block_to_row(self, row: Row, instruction: Instruction, direction: DirectionType) -> None:
115116
row.add_block(instruction.block, direction)
@@ -142,8 +143,7 @@ def get_row_blocks(self, block: Block, direction: DirectionType) -> List[Block]:
142143
if block in row.blocks:
143144
return row.blocks
144145

145-
# TODO: make a custom exception
146-
raise RuntimeError(f"Direction {direction} of {block} not in catalogue")
146+
raise BlockNotFoundError(f"Direction {direction} of {block} not in catalogue")
147147

148148

149149
class Probe:

src/classy_blocks/grading/grading.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import warnings
4040
from typing import List
4141

42+
from classy_blocks.base.exceptions import UndefinedGradingsError
4243
from classy_blocks.grading.chop import Chop, ChopData
4344
from classy_blocks.types import GradingSpecType
4445
from classy_blocks.util import constants
@@ -150,7 +151,7 @@ def is_defined(self) -> bool:
150151
def description(self) -> str:
151152
"""Output string for blockMeshDict"""
152153
if not self.is_defined:
153-
raise ValueError(f"Grading not defined: {self}")
154+
raise UndefinedGradingsError(f"Grading not defined: {self}")
154155

155156
if len(self.specification) == 1:
156157
# its a one-number simpleGrading:

0 commit comments

Comments
 (0)