-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into feature/autochop
- Loading branch information
Showing
17 changed files
with
350 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# An example where a Shape is optimized *before* it is added to mesh, using ShapeOptimizer | ||
import os | ||
|
||
import classy_blocks as cb | ||
from classy_blocks.optimize.junction import ClampExistsError | ||
from classy_blocks.optimize.optimizer import ShapeOptimizer | ||
|
||
mesh = cb.Mesh() | ||
|
||
start_sketch = cb.SplineDisk([0, 0, 0], [2.5, 0, 0], [0, 1, 0], 0, 0) | ||
end_sketch = cb.SplineDisk([0, 0, 0], [1, 0, 0], [0, 2.5, 0], 0, 0).translate([0, 0, 1]) | ||
|
||
shape = cb.LoftedShape(start_sketch, end_sketch) | ||
|
||
optimizer = ShapeOptimizer(shape.operations) | ||
|
||
for operation in shape.operations[:4]: | ||
# remove edges because inner splines will ruin the day | ||
# TODO: make edges move with points too | ||
operation.top_face.remove_edges() | ||
operation.bottom_face.remove_edges() | ||
|
||
for point in operation.point_array: | ||
try: | ||
optimizer.add_clamp(cb.FreeClamp(point)) | ||
except ClampExistsError: | ||
pass | ||
|
||
optimizer.optimize(tolerance=0.01) | ||
|
||
# Quick'n'dirty chopping, don't do this at home | ||
for operation in shape.operations: | ||
for axis in range(3): | ||
operation.chop(axis, count=10) | ||
|
||
mesh.add(shape) | ||
|
||
mesh.set_default_patch("walls", "wall") | ||
mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from typing import List, Union | ||
|
||
from classy_blocks.construct.flat.face import Face | ||
from classy_blocks.construct.operations.operation import Operation | ||
from classy_blocks.types import IndexType, NPPointType | ||
from classy_blocks.util import functions as f | ||
from classy_blocks.util.constants import TOL | ||
|
||
ElementType = Union[Face, Operation] | ||
|
||
|
||
class Mapper: | ||
"""A helper that constructs mapped sketches/shapes | ||
from arbitrary collection of faces/operations""" | ||
|
||
def __init__(self) -> None: | ||
self.points: List[NPPointType] = [] | ||
self.indexes: List[IndexType] = [] | ||
self.elements: List[Union[Face, Operation]] = [] | ||
|
||
def _add_point(self, point: NPPointType) -> int: | ||
# TODO: this code is repeated several times all over; | ||
# consolidate, unify, agglomerate, amass | ||
# (especially in case one would need to utilize an octree or something) | ||
for i, position in enumerate(self.points): | ||
if f.norm(point - position) < TOL: | ||
# reuse an existing point | ||
index = i | ||
break | ||
else: | ||
# no point found, create a new one | ||
index = len(self.points) | ||
self.points.append(point) | ||
|
||
return index | ||
|
||
def add(self, element: ElementType) -> None: | ||
"""Add Face's or Operation's points to the map""" | ||
indexes = [self._add_point(point) for point in element.point_array] | ||
self.indexes.append(indexes) | ||
self.elements.append(element) | ||
|
||
@classmethod | ||
def from_map(cls, points: List[NPPointType], indexes: List[IndexType], elements: List[ElementType]) -> "Mapper": | ||
"""Creates a ready-made mapper from a sketch/shape that already has points/indexes defined""" | ||
if len(indexes) != len(elements): | ||
raise ValueError("Number of indexes and elements don't match!") | ||
|
||
mapper = cls() | ||
mapper.points = points | ||
mapper.indexes = indexes | ||
mapper.elements = elements | ||
|
||
return mapper |
Oops, something went wrong.