Skip to content

Commit dab2146

Browse files
committed
Correct optimization criteria to improve mesh quality; jit-ify some slow stuff
1 parent d92175a commit dab2146

File tree

5 files changed

+12
-20
lines changed

5 files changed

+12
-20
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"configurations": [
77
{
88
"name": "Python: classy example",
9-
"type": "python",
9+
"type": "debugpy",
1010
"request": "launch",
1111
"program": "${file}",
1212
"cwd": "${fileDirname}",

classy_blocks.code-workspace

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
],
77
"settings": {
88
"python.languageServer": "Pylance",
9-
"cSpell.words": [
10-
"astype",
11-
"linspace",
12-
"Pylance",
13-
"scipy"
14-
],
15-
"editor.autoClosingBrackets": "never",
169
"editor.defaultFormatter": "charliermarsh.ruff",
1710
"ruff.organizeImports": true
1811
},

src/classy_blocks/assemble/assembler.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
from typing import Tuple, get_args
22

3-
import numpy as np
4-
53
from classy_blocks.assemble.depot import Depot
64
from classy_blocks.assemble.dump import AssembledDump
75
from classy_blocks.assemble.settings import Settings
@@ -15,25 +13,26 @@
1513
from classy_blocks.lists.patch_list import PatchList
1614
from classy_blocks.lists.vertex_list import VertexList
1715
from classy_blocks.lookup.point_registry import HexPointRegistry
18-
from classy_blocks.optimize.grid import HexGrid
1916
from classy_blocks.util import constants
2017

2118

2219
class MeshAssembler:
23-
def __init__(self, depot: Depot, settings: Settings):
20+
def __init__(self, depot: Depot, settings: Settings, merge_tol=constants.TOL):
2421
self.depot = depot
2522
self.settings = settings
23+
self.merge_tol = merge_tol
2624

2725
# once the mesh is assembled, adding new stuff to depot will break things;
2826
# better (and faster) is to cache status quo
2927
self._operations = self.depot.operations
30-
self._grid = HexGrid.from_elements(self._operations)
28+
29+
self._points = HexPointRegistry.from_operations(self._operations, self.merge_tol)
3130

3231
def _create_blocks(self, vertex_list: VertexList) -> BlockList:
3332
block_list = BlockList()
3433

3534
for iop, operation in enumerate(self._operations):
36-
op_indexes = self._grid.addressing[iop]
35+
op_indexes = self._points.cell_addressing[iop]
3736
op_vertices = [vertex_list.vertices[i] for i in op_indexes]
3837

3938
# duplicate vertices on slave patches
@@ -111,14 +110,11 @@ def _create_patches(self, block_list: BlockList) -> Tuple[PatchList, FaceList]:
111110
return patch_list, face_list
112111

113112
def _update_neighbours(self, block_list: BlockList) -> None:
114-
points = np.array([[v.position for v in b.vertices] for b in block_list.blocks])
115-
116-
navigator = HexPointRegistry(HexPointRegistry.flatten(points, 8 * len(block_list.blocks)), constants.TOL)
117-
block_list.update_neighbours(navigator)
113+
block_list.update_neighbours(self._points)
118114

119115
def assemble(self) -> AssembledDump:
120116
# Create reused/indexes vertices from operations' points
121-
vertex_list = VertexList([Vertex(pos, i) for i, pos in enumerate(self._grid.points)])
117+
vertex_list = VertexList([Vertex(pos, i) for i, pos in enumerate(self._points.unique_points)])
122118
# Create blocks from vertices; when there's a slave patch specified in an operation,
123119
# duplicate vertices for that patch
124120
block_list = self._create_blocks(vertex_list)

src/classy_blocks/items/wires/axis.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def add_neighbour(self, other: "Axis") -> None:
2727
for nei_wire in other.wires:
2828
if this_wire.is_coincident(nei_wire):
2929
self.neighbours.add(other)
30+
break
3031

3132
def add_inline(self, other: "Axis") -> None:
3233
"""Adds an axis that comes before/after this one"""
@@ -35,6 +36,7 @@ def add_inline(self, other: "Axis") -> None:
3536
for this_wire in self.wires:
3637
for nei_wire in other.wires:
3738
this_wire.add_inline(nei_wire)
39+
break
3840

3941
def is_aligned(self, other: "Axis") -> bool:
4042
"""Returns True if wires of the other axis are aligned

src/classy_blocks/util/functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ def divide_arc(center: NPPointType, point_1: NPPointType, point_2: NPPointType,
229229
return result
230230

231231

232-
def arc_mid(center: PointType, point_1: PointType, point_2: PointType) -> PointType:
232+
@jit(nopython=True, cache=True)
233+
def arc_mid(center: NPPointType, point_1: NPPointType, point_2: NPPointType) -> PointType:
233234
"""Returns the midpoint of the specified arc in 3D space"""
234235
return divide_arc(center, point_1, point_2, 1)[0]
235236

0 commit comments

Comments
 (0)