Skip to content

Commit e25ea17

Browse files
committed
Add an InflationGrader (WIP)
1 parent 5247453 commit e25ea17

File tree

8 files changed

+479
-48
lines changed

8 files changed

+479
-48
lines changed

examples/operation/extrude.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,24 @@
77
extrude = cb.Extrude(base, [0.5, 0.5, 3])
88

99
# direction of corners 0-1
10-
extrude.chop(0, length_ratio=0.5, start_size=0.02, c2c_expansion=1.2)
11-
extrude.chop(0, length_ratio=0.5, end_size=0.02, c2c_expansion=1 / 1.2)
10+
# extrude.chop(0, length_ratio=0.5, start_size=0.02, c2c_expansion=1.2)
11+
# extrude.chop(0, length_ratio=0.5, end_size=0.02, c2c_expansion=1 / 1.2)
1212

1313
# direction of corners 1-2
14-
extrude.chop(1, length_ratio=0.5, start_size=0.02, c2c_expansion=1.2)
15-
extrude.chop(1, length_ratio=0.5, end_size=0.02, c2c_expansion=1 / 1.2)
14+
# extrude.chop(1, length_ratio=0.5, start_size=0.02, c2c_expansion=1.2)
15+
# extrude.chop(1, length_ratio=0.5, end_size=0.02, c2c_expansion=1 / 1.2)
1616

1717
# extrude direction
18-
extrude.chop(2, c2c_expansion=1, count=20)
18+
# extrude.chop(2, c2c_expansion=1, count=20)
19+
20+
extrude.set_patch("bottom", "wall")
21+
1922

2023
mesh = cb.Mesh()
2124
mesh.add(extrude)
22-
mesh.set_default_patch("walls", "wall")
25+
mesh.set_default_patch("air", "patch")
26+
mesh.modify_patch("wall", "wall")
27+
grader = cb.InflationGrader(mesh, 0.01, 0.1)
28+
grader.grade()
2329

2430
mesh.write(os.path.join("..", "case", "system", "blockMeshDict"))

src/classy_blocks/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
from .construct.shapes.shell import Shell
3535
from .construct.shapes.sphere import EighthSphere, Hemisphere, QuarterSphere
3636
from .construct.stack import ExtrudedStack, RevolvedStack, TransformedStack
37-
from .grading.graders.fixed import FixedCountGrader, SimpleGrader
37+
from .grading.graders.fixed import FixedCountGrader
38+
from .grading.graders.inflation import InflationGrader
39+
from .grading.graders.simple import SimpleGrader
3840
from .mesh import Mesh
3941
from .modify.find.geometric import GeometricFinder
4042
from .modify.find.shape import RoundSolidFinder
@@ -77,6 +79,7 @@
7779
"HalfSplineDisk",
7880
"HalfSplineRing",
7981
"Hemisphere",
82+
"InflationGrader",
8083
"LJoint",
8184
"LineClamp",
8285
"LineCurve",

src/classy_blocks/grading/analyze/probe.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def find_patch(orient: OrientType) -> bool:
126126
return False
127127

128128
vertices = set(block.get_side_vertices(orient))
129+
129130
try:
130131
patch = self.dump.patch_list.find(vertices)
131132
if patch.kind == "wall":
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import abc
2+
3+
import numpy as np
4+
5+
from classy_blocks.cbtyping import ChopTakeType
6+
from classy_blocks.grading.analyze.row import Row
7+
8+
9+
class AutoGraderMixin(abc.ABC):
10+
take: ChopTakeType
11+
12+
def _get_row_length(self, row: Row) -> float:
13+
lengths = []
14+
15+
for entry in row.entries:
16+
lengths += entry.lengths
17+
18+
if self.take == "max":
19+
return max(lengths)
20+
21+
if self.take == "min":
22+
return min(lengths)
23+
24+
return float(np.average(np.array(lengths)))
Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import numpy as np
2-
31
from classy_blocks.assemble.dump import AssembledDump
4-
from classy_blocks.cbtyping import ChopTakeType, DirectionType
2+
from classy_blocks.cbtyping import DirectionType
53
from classy_blocks.grading.analyze.row import Row
64
from classy_blocks.grading.define.chop import Chop
5+
from classy_blocks.grading.graders.auto import AutoGraderMixin
76
from classy_blocks.grading.graders.manager import AxisGrader, GradingManager
87
from classy_blocks.items.block import Block
98
from classy_blocks.mesh import Mesh
@@ -18,9 +17,7 @@ def get_chops(self):
1817
return [Chop(count=self.count)]
1918

2019

21-
class FixedCountGrader(GradingManager):
22-
axis_grader = FixedAxisGrader
23-
20+
class FixedCountGrader(GradingManager, AutoGraderMixin):
2421
def __init__(self, mesh: Mesh, count: int = 5):
2522
self.count = count
2623
mesh.assemble()
@@ -36,38 +33,3 @@ def _grade_row(self, row: Row):
3633
entry = row.entries[0]
3734
axis_grader = FixedAxisGrader(entry.block, entry.heading, self.count)
3835
axis_grader.grade()
39-
40-
41-
class SimpleGrader(GradingManager):
42-
def __init__(self, mesh: Mesh, cell_size: float, take: ChopTakeType = "avg"):
43-
self.cell_size = cell_size
44-
self.take = take
45-
mesh.assemble()
46-
47-
assert isinstance(mesh.dump, AssembledDump)
48-
49-
super().__init__(mesh.dump, mesh.settings)
50-
51-
def _get_row_count(self, row: Row):
52-
lengths = []
53-
54-
for entry in row.entries:
55-
lengths += entry.lengths
56-
57-
if self.take == "max":
58-
ref_len = max(lengths)
59-
60-
elif self.take == "min":
61-
ref_len = min(lengths)
62-
else:
63-
ref_len = np.average(np.array(lengths))
64-
65-
return max(1, int(ref_len / self.cell_size))
66-
67-
def _grade_row(self, row: Row):
68-
super()._grade_row(row)
69-
70-
if row.count == 0:
71-
entry = row.entries[0]
72-
axis_grader = FixedAxisGrader(entry.block, entry.heading, self._get_row_count(row))
73-
axis_grader.grade()

0 commit comments

Comments
 (0)