Skip to content

Commit

Permalink
Add missing direct imports of some classes
Browse files Browse the repository at this point in the history
  • Loading branch information
FranzBangar committed May 23, 2024
1 parent 59a32ca commit d4fbee1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
22 changes: 8 additions & 14 deletions examples/complex/heater/heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@

import classy_blocks as cb
from classy_blocks.construct.flat.sketch import Sketch
from classy_blocks.construct.flat.sketches.disk import WrappedDisk
from classy_blocks.construct.operations.operation import Operation

# TODO: direct imports!
from classy_blocks.construct.shape import ExtrudedShape, Shape
from classy_blocks.construct.stack import RevolvedStack

mesh = cb.Mesh()

Expand All @@ -21,7 +15,7 @@
zlv = p.zlv


def set_cell_zones(shape: Shape):
def set_cell_zones(shape: cb.Shape):
solid_indexes = list(range(5))
fluid_indexes = list(range(5, 9))

Expand All @@ -33,11 +27,11 @@ def set_cell_zones(shape: Shape):


# Cross-section of heater and fluid around it
WrappedDisk.chops[0] = [1] # the solid part, chop the fluid zone manually
heater_xs = WrappedDisk(p.heater_start_point, p.wrapping_corner_point, p.heater_diameter / 2, [1, 0, 0])
cb.WrappedDisk.chops[0] = [1] # the solid part, chop the fluid zone manually
heater_xs = cb.WrappedDisk(p.heater_start_point, p.wrapping_corner_point, p.heater_diameter / 2, [1, 0, 0])

# The straight part of the heater, part 1: bottom
straight_1 = ExtrudedShape(heater_xs, p.heater_length)
straight_1 = cb.ExtrudedShape(heater_xs, p.heater_length)

straight_1.chop(0, start_size=p.solid_cell_size)
straight_1.chop(1, start_size=p.solid_cell_size)
Expand All @@ -48,15 +42,15 @@ def set_cell_zones(shape: Shape):


# The curved part of heater (and fluid around it); constructed from 4 revolves
heater_arch = RevolvedStack(straight_1.sketch_2, np.pi, [0, 0, 1], [0, 0, 0], 4)
heater_arch = cb.RevolvedStack(straight_1.sketch_2, np.pi, [0, 0, 1], [0, 0, 0], 4)
heater_arch.chop(start_size=p.solid_cell_size, take="min")
for shape in heater_arch.shapes:
set_cell_zones(shape)
mesh.add(heater_arch)


# The straight part of heater, part 2: after the arch
straight_2 = ExtrudedShape(heater_arch.shapes[-1].sketch_2, p.heater_length)
straight_2 = cb.ExtrudedShape(heater_arch.shapes[-1].sketch_2, p.heater_length)
set_cell_zones(straight_2)
mesh.add(straight_2)

Expand All @@ -70,7 +64,7 @@ def set_cell_zones(shape: Shape):
# A custom sketch that takes the closest faces from given operations;
# They will definitely be wrongly oriented but we'll sort that out later
class NearestSketch(Sketch):
def __init__(self, operations: List[Operation], far_point):
def __init__(self, operations: List[cb.Operation], far_point):
far_point = np.array(far_point)
self._faces = [op.get_closest_face(far_point) for op in operations]

Expand All @@ -88,7 +82,7 @@ def center(self):


cylinder_xs = NearestSketch([arch_fill.operations[i] for i in (0, 1, 2, 5)], [-2 * p.heater_length, 0, 0])
pipe_fill = ExtrudedShape(cylinder_xs, [-p.heater_length, 0, 0])
pipe_fill = cb.ExtrudedShape(cylinder_xs, [-p.heater_length, 0, 0])

# reorient the operations in the shape
reorienter = cb.ViewpointReorienter([-2 * p.heater_length, 0, 0], [0, p.heater_length, 0])
Expand Down
7 changes: 7 additions & 0 deletions src/classy_blocks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
from .construct.operations.connector import Connector
from .construct.operations.extrude import Extrude
from .construct.operations.loft import Loft
from .construct.operations.operation import Operation
from .construct.operations.revolve import Revolve
from .construct.operations.wedge import Wedge
from .construct.shape import ExtrudedShape, LoftedShape, RevolvedShape, Shape
from .construct.shapes.cylinder import Cylinder, SemiCylinder
from .construct.shapes.elbow import Elbow
from .construct.shapes.frustum import Frustum
Expand Down Expand Up @@ -52,6 +54,7 @@
"OnCurve",
"Face",
# construct operations
"Operation",
"Loft",
"Extrude",
"Revolve",
Expand All @@ -67,6 +70,10 @@
"WrappedDisk",
"Oval",
# construct shapes
"Shape",
"ExtrudedShape",
"LoftedShape",
"RevolvedShape",
"Elbow",
"Frustum",
"Cylinder",
Expand Down
13 changes: 7 additions & 6 deletions src/classy_blocks/construct/flat/sketches/mapped.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ class MappedSketch(Sketch):
"""A sketch that is created from predefined points.
The points are connected to form quads which define Faces."""

def __init__(self, positions: PointListType, quads: List[QuadIndexType], smooth_iter: int = 0):
self.map = QuadMap(np.array(positions, dtype=DTYPE), quads)

if smooth_iter > 0:
self.map.smooth_laplacian(smooth_iter)
def __init__(self, positions: PointListType, quads: List[QuadIndexType]):
self.quad_map = QuadMap(np.array(positions, dtype=DTYPE), quads)

self.add_edges()

Expand All @@ -26,7 +23,7 @@ def add_edges(self) -> None:
@property
def faces(self):
"""A 'flattened' grid"""
return [quad.face for quad in self.map.quads]
return [quad.face for quad in self.quad_map.quads]

@property
def grid(self):
Expand All @@ -37,3 +34,7 @@ def grid(self):
def center(self) -> NPPointType:
"""Center of this sketch"""
return np.average([face.center for face in self.faces], axis=0)

def smooth(self, n_iter: int = 5) -> None:
"""Smooth the internal points using laplacian smoothing"""
self.quad_map.smooth_laplacian(n_iter)
2 changes: 1 addition & 1 deletion src/classy_blocks/construct/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def grid(self):
def get_slice(self, axis: AxisType, index: int) -> List[Operation]:
"""Returns all operation with given index in specified axis.
For cartesian grids this is equivalent to 'lofts on the same plane';
This does not work with custom/mapped sketches that do not have
This does not work with custom/mapped sketches that do not
conform to a cartesian grid.
Example:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_construct/test_flat/test_sketch.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def sketch(self):
def test_smooth(self):
# a grid of vertices 3x3

sketch = MappedSketch(self.positions, self.quads, smooth_iter=10)
sketch = MappedSketch(self.positions, self.quads)
sketch.smooth(10)

np.testing.assert_almost_equal(sketch.faces[0].point_array[2], [1, 1, 0])

Expand All @@ -48,7 +49,8 @@ def test_grid(self):
self.assertEqual(len(self.sketch.grid), 1)

def test_center(self):
sketch = MappedSketch(self.positions, self.quads, smooth_iter=10)
sketch = MappedSketch(self.positions, self.quads)
sketch.smooth(10)

np.testing.assert_almost_equal(sketch.center, [1, 1, 0])

Expand Down
4 changes: 1 addition & 3 deletions tests/test_util/test_imports.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import unittest

import classy_blocks as cb
import classy_blocks.construct.flat.sketches.mapped


class ImportsTests(unittest.TestCase):
Expand Down Expand Up @@ -40,10 +39,9 @@ def test_import_operations(self):
_ = cb.Connector

def test_import_sketches(self):
_ = classy_blocks.construct.flat.sketches.mapped.MappedSketch
_ = cb.MappedSketch
_ = cb.Grid
_ = cb.Oval
_ = classy_blocks.construct.flat.sketches.mapped.MappedSketch
_ = cb.Grid
_ = cb.OneCoreDisk
_ = cb.FourCoreDisk
Expand Down

0 comments on commit d4fbee1

Please sign in to comment.