Skip to content

Commit 16c6752

Browse files
committed
Reorganize the whole grading toolbox (savegame; not working)
1 parent d78c7be commit 16c6752

File tree

21 files changed

+365
-242
lines changed

21 files changed

+365
-242
lines changed

examples/shape/cylinder.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,4 @@
3939
mesh.add(cylinder)
4040
mesh.modify_patch("walls", "wall")
4141

42-
from classy_blocks.grading.graders.manual import ManualGrader
43-
44-
grader = ManualGrader(mesh)
45-
grader.grade()
46-
4742
mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")

src/classy_blocks/assemble/assembler.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from classy_blocks.assemble.depot import Depot
32
from classy_blocks.assemble.dump import AssembledDump
43
from classy_blocks.assemble.settings import Settings
@@ -20,10 +19,7 @@ def __init__(self, depot: Depot, settings: Settings, merge_tol=constants.TOL):
2019
self.settings = settings
2120
self.merge_tol = merge_tol
2221

23-
# once the mesh is assembled, adding new stuff to depot will break things;
24-
# better (and faster) is to cache status quo
2522
self._operations = self.depot.operations
26-
2723
self._points = HexPointRegistry.from_operations(self._operations, self.merge_tol)
2824

2925
def _create_blocks(self, vertex_list: VertexList) -> BlockList:

src/classy_blocks/construct/operations/operation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
from classy_blocks.construct.edges import Arc, EdgeData, Line, Project, Spline
2020
from classy_blocks.construct.flat.face import Face
2121
from classy_blocks.construct.point import Point
22-
from classy_blocks.grading.chop import Chop
23-
from classy_blocks.grading.collector import ChopCollector
22+
from classy_blocks.grading.define.chop import Chop
23+
from classy_blocks.grading.define.collector import ChopCollector
2424
from classy_blocks.util import constants
2525
from classy_blocks.util import functions as f
2626
from classy_blocks.util.constants import SIDES_MAP

src/classy_blocks/grading/analyze/__init__.py

Whitespace-only changes.

src/classy_blocks/grading/graders/catalogue.py renamed to src/classy_blocks/grading/analyze/catalogue.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
from classy_blocks.base.exceptions import BlockNotFoundError, NoInstructionError
55
from classy_blocks.cbtyping import DirectionType
6-
from classy_blocks.grading.graders.row import Row
6+
from classy_blocks.grading.analyze.row import Row
77
from classy_blocks.items.block import Block
88
from classy_blocks.items.wires.axis import Axis
9-
from classy_blocks.mesh import Mesh
9+
from classy_blocks.lists.block_list import BlockList
1010

1111

12-
@functools.lru_cache(maxsize=3000) # that's for 1000 blocks
13-
def get_block_from_axis(mesh: Mesh, axis: Axis) -> Block:
14-
for block in mesh.blocks:
12+
@functools.lru_cache(maxsize=9000) # that's for 3000 blocks
13+
def get_block_from_axis(block_list: BlockList, axis: Axis) -> Block:
14+
for block in block_list.blocks:
1515
if axis in block.axes:
1616
return block
1717

@@ -36,11 +36,11 @@ def __hash__(self) -> int:
3636
class RowCatalogue:
3737
"""A collection of rows on a specified axis"""
3838

39-
def __init__(self, mesh: Mesh):
40-
self.mesh = mesh
39+
def __init__(self, block_list: BlockList):
40+
self.block_list = block_list
4141

4242
self.rows: dict[DirectionType, list[Row]] = {0: [], 1: [], 2: []}
43-
self.instructions = [Instruction(block) for block in mesh.blocks]
43+
self.instructions = [Instruction(block) for block in block_list.blocks]
4444

4545
for i in get_args(DirectionType):
4646
self._populate(i)
@@ -63,7 +63,7 @@ def _add_block_to_row(self, row: Row, instruction: Instruction, direction: Direc
6363
block = instruction.block
6464

6565
for neighbour_axis in block.axes[direction].neighbours:
66-
neighbour_block = get_block_from_axis(self.mesh, neighbour_axis)
66+
neighbour_block = get_block_from_axis(self.block_list, neighbour_axis)
6767

6868
if neighbour_block in row.blocks:
6969
continue

src/classy_blocks/grading/graders/probe.py renamed to src/classy_blocks/grading/analyze/probe.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from typing import Optional
33

44
from classy_blocks.assemble.dump import AssembledDump
5+
from classy_blocks.assemble.settings import Settings
56
from classy_blocks.base.exceptions import PatchNotFoundError
67
from classy_blocks.cbtyping import DirectionType, OrientType
7-
from classy_blocks.grading.graders.catalogue import RowCatalogue
8-
from classy_blocks.grading.graders.row import Row
8+
from classy_blocks.grading.analyze.catalogue import RowCatalogue
9+
from classy_blocks.grading.analyze.row import Row
910
from classy_blocks.items.block import Block
1011
from classy_blocks.items.wires.wire import Wire
11-
from classy_blocks.mesh import Mesh
1212
from classy_blocks.optimize.grid import HexGrid
1313
from classy_blocks.util.constants import DIRECTION_MAP
1414

@@ -75,13 +75,12 @@ class WireCatalogue:
7575
many wires can be located at the same spot and only some of them can be
7676
on 'walls'; gather data first so that wall-bounded wires aren't ignored"""
7777

78-
def __init__(self, mesh: Mesh):
79-
self.mesh = mesh
80-
assert isinstance(self.mesh.dump, AssembledDump)
81-
self.dump = self.mesh.dump
78+
def __init__(self, dump: AssembledDump, settings: Settings):
79+
self.dump = dump
80+
self.settings = settings
8281

8382
# finds blocks' neighbours
84-
self.grid = HexGrid.from_mesh(self.mesh)
83+
self.grid = HexGrid.from_dump(dump)
8584

8685
# WireInfo is stored at indexes [vertex_1][vertex_2];
8786
# if a coincident wire is inverted, it will reside at
@@ -97,7 +96,7 @@ def _fetch(self, index_1: int, index_2: int) -> Optional[WireInfo]:
9796
return self.data[index_1].get(index_2)
9897

9998
def _populate(self) -> None:
100-
for block in self.mesh.blocks:
99+
for block in self.dump.blocks:
101100
for wire in block.wire_list:
102101
start_index, end_index = wire.vertices[0].index, wire.vertices[1].index
103102

@@ -116,7 +115,7 @@ def _get_wire_boundaries(self, wire: Wire, block: Block) -> tuple[bool, bool]:
116115
"""Finds out whether a Wire starts or ends on a wall patch"""
117116
start_orient = DIRECTION_MAP[wire.direction][0]
118117
end_orient = DIRECTION_MAP[wire.direction][1]
119-
block_index = self.mesh.blocks.index(block)
118+
block_index = self.dump.blocks.index(block)
120119

121120
def find_patch(orient: OrientType) -> bool:
122121
# search for external faces;
@@ -132,7 +131,7 @@ def find_patch(orient: OrientType) -> bool:
132131
if patch.kind == "wall":
133132
return True
134133
except PatchNotFoundError:
135-
if self.mesh.settings.default_patch.get("kind") == "wall":
134+
if self.settings.default_patch.get("kind") == "wall":
136135
return True
137136

138137
return False
@@ -151,14 +150,12 @@ def get_info(self, wire: Wire) -> WireInfo:
151150
class Probe:
152151
"""Examines the mesh and gathers required data for auto chopping"""
153152

154-
def __init__(self, mesh: Mesh):
155-
self.mesh = mesh
156-
153+
def __init__(self, dump: AssembledDump, settings: Settings):
157154
# maps blocks to rows
158-
self.rows = RowCatalogue(self.mesh)
155+
self.rows = RowCatalogue(dump.block_list)
159156

160157
# build a wire database
161-
self.wires = WireCatalogue(self.mesh)
158+
self.wires = WireCatalogue(dump, settings)
162159

163160
def get_row_blocks(self, block: Block, direction: DirectionType) -> list[Block]:
164161
return self.rows.get_row_blocks(block, direction)

src/classy_blocks/grading/define/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Callable, Optional, Union
44

55
from classy_blocks.cbtyping import ChopPreserveType, ChopTakeType, GradingSpecType
6-
from classy_blocks.grading import relations as rel
6+
from classy_blocks.grading.define import relations as rel
77

88

99
@dataclasses.dataclass

src/classy_blocks/grading/collector.py renamed to src/classy_blocks/grading/define/collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from classy_blocks.cbtyping import DirectionType
2-
from classy_blocks.grading.chop import Chop
2+
from classy_blocks.grading.define.chop import Chop
33
from classy_blocks.util.frame import Frame
44

55

0 commit comments

Comments
 (0)