Skip to content

Commit 200e50a

Browse files
committed
Add sequential neighbours (before/after)
1 parent 0034f95 commit 200e50a

File tree

9 files changed

+63
-21
lines changed

9 files changed

+63
-21
lines changed

src/classy_blocks/items/block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def add_neighbour(self, candidate: "Block") -> None:
9393
for this_axis in self.axes:
9494
for cnd_axis in candidate.axes:
9595
this_axis.add_neighbour(cnd_axis)
96+
this_axis.add_sequential(cnd_axis)
9697

9798
# wires
9899
for this_wire in self.wire_list:

src/classy_blocks/items/wires/axis.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import List, Set
22

33
from classy_blocks.grading.chop import Chop
4+
from classy_blocks.items.vertex import Vertex
45
from classy_blocks.items.wires.manager import WireChopManager, WireManagerBase, WirePropagateManager
56
from classy_blocks.items.wires.wire import Wire
67
from classy_blocks.types import AxisType
@@ -40,7 +41,7 @@ def __init__(self, index: AxisType, wires: List[Wire]):
4041
# will be replaced by a ChopManager
4142
self.wires: WireManagerBase = WirePropagateManager(wires)
4243

43-
# will be added as blocks are added to mesh
44+
# will be added after blocks are added to mesh
4445
self.neighbours: Set[Axis] = set()
4546

4647
def add_neighbour(self, axis: "Axis") -> None:
@@ -50,6 +51,14 @@ def add_neighbour(self, axis: "Axis") -> None:
5051
if this_wire.is_coincident(nei_wire):
5152
self.neighbours.add(axis)
5253

54+
def add_sequential(self, axis: "Axis") -> None:
55+
"""Adds an axis that comes before/after this one"""
56+
# As opposed to neighbours that are 'around' this axis
57+
if self.start_vertices == axis.end_vertices or self.end_vertices == axis.start_vertices:
58+
for this_wire in self.wires:
59+
for nei_wire in axis.wires:
60+
this_wire.add_series(nei_wire)
61+
5362
def is_aligned(self, other: "Axis") -> bool:
5463
"""Returns True if wires of the other axis are aligned
5564
to wires of this one"""
@@ -95,6 +104,14 @@ def copy_grading(self) -> bool:
95104

96105
return False
97106

107+
@property
108+
def start_vertices(self) -> Set[Vertex]:
109+
return {wire.vertices[0] for wire in self.wires}
110+
111+
@property
112+
def end_vertices(self) -> Set[Vertex]:
113+
return {wire.vertices[1] for wire in self.wires}
114+
98115
def grade(self) -> None:
99116
self.wires.grade()
100117

src/classy_blocks/items/wires/wire.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ def __init__(self, vertices: List[Vertex], axis: int, corner_1: int, corner_2: i
2626
self.grading = Grading(self.length)
2727

2828
# multiple wires can be at the same spot; this list holds other
29-
# coincident wires
29+
# coincident wires from different blocks
3030
self.coincidents: Set[Wire] = set()
31+
# wires that precede this (end with this wire's beginning vertex)
32+
self.before: Set[Wire] = set()
33+
# wires that follow this (start with this wire's end vertex)
34+
self.after: Set[Wire] = set()
3135

3236
@property
3337
def length(self) -> float:
@@ -56,6 +60,13 @@ def add_coincident(self, wire):
5660
if self.is_coincident(wire):
5761
self.coincidents.add(wire)
5862

63+
def add_series(self, wire):
64+
"""Adds a reference to a wire that is before or after this one"""
65+
if wire.vertices[1] == self.vertices[0]:
66+
self.before.add(wire)
67+
elif wire.vertices[0] == self.vertices[1]:
68+
self.after.add(wire)
69+
5970
def add_chop(self, chop: Chop) -> None:
6071
"""Adds Chops to this Wire's Grading object"""
6172
self.grading.add_chop(chop)

src/classy_blocks/lists/block_list.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ def add(self, block: Block) -> None:
1818
self.blocks.append(block)
1919
self.update_neighbours(block)
2020

21-
def grade_blocks(self) -> None:
22-
for block in self.blocks:
23-
block.grade()
24-
2521
def update_neighbours(self, new_block: Block) -> None:
2622
"""Find and assign neighbours of a given block entry"""
2723
for block in self.blocks:
@@ -31,6 +27,10 @@ def update_neighbours(self, new_block: Block) -> None:
3127
block.add_neighbour(new_block)
3228
new_block.add_neighbour(block)
3329

30+
def grade_blocks(self) -> None:
31+
for block in self.blocks:
32+
block.grade()
33+
3434
def propagate_gradings(self):
3535
"""Copy references to gradings from defined blocks to their neighbours"""
3636
# a riddle similar to sudoku, keep traversing
@@ -70,6 +70,16 @@ def check_consistency(self):
7070
for block in self.blocks:
7171
block.check_consistency()
7272

73+
def assemble(self) -> None:
74+
# 1. set counts on user-defined axes
75+
self.grade_blocks()
76+
# 2. distribute counts over all blocks
77+
self.propagate_gradings()
78+
# 3. set gradings on missing wires
79+
80+
# 4. check that everything is in order
81+
self.check_consistency()
82+
7383
def clear(self) -> None:
7484
"""Removes created blocks"""
7585
self.blocks.clear()

src/classy_blocks/mesh.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,6 @@ def assemble(self, skip_edges: bool = False) -> None:
132132
if entity.geometry is not None:
133133
self.add_geometry(entity.geometry)
134134

135-
def grade(self) -> None:
136-
if not self.is_assembled:
137-
raise RuntimeError("Cannot grade a mesh before it is assembled")
138-
139-
self.block_list.grade_blocks()
140-
self.block_list.propagate_gradings()
141-
self.block_list.check_consistency()
142-
143135
def clear(self) -> None:
144136
"""Undoes the assemble() method; clears created blocks and other lists
145137
but leaves added depot items intact"""
@@ -197,7 +189,7 @@ def write(self, output_path: str, debug_path: Optional[str] = None) -> None:
197189

198190
# gradings: define after writing VTK;
199191
# if it is not specified correctly, this will raise an exception
200-
self.grade()
192+
self.block_list.assemble()
201193

202194
with open(output_path, "w", encoding="utf-8") as output:
203195
output.write(constants.MESH_HEADER)

tests/test_construct/test_edge_grading.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def setUp(self):
4343
mesh.add(end)
4444

4545
mesh.assemble()
46-
mesh.grade()
46+
mesh.block_list.assemble()
4747

4848
self.mesh = mesh
4949

@@ -78,7 +78,7 @@ def setUp(self):
7878

7979
def prepare(self):
8080
self.mesh.assemble()
81-
self.mesh.grade()
81+
self.mesh.block_list.assemble()
8282

8383
def test_inconsistent_wires(self):
8484
box_left = Box([0, 0, 0], [1, 1, 1])

tests/test_items/test_axis.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,14 @@ def test_is_not_aligned(self):
4848
block_0.add_neighbour(block_1)
4949

5050
self.assertFalse(block_1.axes[1].is_aligned(block_0.axes[1]))
51+
52+
@parameterized.expand(((0,), (1,), (2,), (3,)))
53+
def test_sequential(self, corner):
54+
block_1 = self.make_block(1)
55+
block_2 = self.make_block(2)
56+
57+
block_1.add_neighbour(block_2)
58+
block_2.add_neighbour(block_1)
59+
60+
self.assertListEqual(list(block_1.axes[1].wires[corner].after), [block_2.axes[1].wires[corner]])
61+
self.assertListEqual(list(block_2.axes[1].wires[corner].before), [block_1.axes[1].wires[corner]])

tests/test_mesh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def test_chop_shape_axial(self):
171171

172172
self.mesh.add(cyl)
173173
self.mesh.assemble()
174-
self.mesh.grade()
174+
self.mesh.block_list.assemble()
175175

176176
for block in self.mesh.block_list.blocks:
177177
self.assertEqual(block.axes[2].count, 10)
@@ -185,7 +185,7 @@ def test_chop_cylinder_tangential(self):
185185

186186
self.mesh.add(cyl)
187187
self.mesh.assemble()
188-
self.mesh.grade()
188+
self.mesh.block_list.assemble()
189189

190190
for block in self.mesh.block_list.blocks:
191191
self.assertEqual(block.axes[1].count, 10)

tests/test_propagation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_propagate_normal(self):
2222
self.mesh.add(op_1)
2323

2424
self.mesh.assemble()
25-
self.mesh.grade()
25+
self.mesh.block_list.assemble()
2626

2727
self.assertListEqual(
2828
self.mesh.block_list.blocks[0].axes[1].wires[2].grading.specification,
@@ -43,7 +43,7 @@ def test_propagate_upsidedown(self):
4343
self.mesh.add(op_1)
4444

4545
self.mesh.assemble()
46-
self.mesh.grade()
46+
self.mesh.block_list.assemble()
4747

4848
self.assertListEqual(
4949
self.mesh.block_list.blocks[0].axes[1].wires[3].grading.specification,

0 commit comments

Comments
 (0)