From b4ae003caa15e80766fe59b64b48e895609ad966 Mon Sep 17 00:00:00 2001 From: kandelabr Date: Tue, 11 Jun 2024 15:52:16 +0200 Subject: [PATCH] Add methods to remove spline edges from shapes Namely, anything created from Disks that now contain spline edges; these do not get updated during optimization and that will produce bad cells. Also, update optimization examples that are affected by that. --- examples/complex/cyclone/regions/inlet.py | 5 ++--- examples/optimization/diffuser_free.py | 8 ++++++++ examples/optimization/diffuser_line.py | 10 +++++++--- src/classy_blocks/construct/shapes/round.py | 7 +++++++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/examples/complex/cyclone/regions/inlet.py b/examples/complex/cyclone/regions/inlet.py index b70197d8..ed2606da 100644 --- a/examples/complex/cyclone/regions/inlet.py +++ b/examples/complex/cyclone/regions/inlet.py @@ -40,9 +40,8 @@ def create_inlet(self): ) for op in inlet.operations: - # TODO: remove edges from face/operation - op.top_face.edges = [Line(), Line(), Line(), Line()] - op.bottom_face.edges = [Line(), Line(), Line(), Line()] + op.top_face.remove_edges() + op.bottom_face.remove_edges() for point in op.top_face.points: # move points on inlet's end face so that they touch cyclone body, diff --git a/examples/optimization/diffuser_free.py b/examples/optimization/diffuser_free.py index d35db5d3..dacc4b90 100644 --- a/examples/optimization/diffuser_free.py +++ b/examples/optimization/diffuser_free.py @@ -26,6 +26,14 @@ mesh.set_default_patch("walls", "wall") +# Internal edges in Cylinders are Splines by default; +# In this case their endpoints will be moved ('optimized') but not +# the points in between; this will create bad cells. Either re-define these edges after optimization +# or remove them altogether. +diffuser.remove_inner_edges() +small_pipe.remove_inner_edges() +big_pipe.remove_inner_edges() + # Assemble the mesh before making changes mesh.assemble() diff --git a/examples/optimization/diffuser_line.py b/examples/optimization/diffuser_line.py index 304a52ef..65b1a1fb 100644 --- a/examples/optimization/diffuser_line.py +++ b/examples/optimization/diffuser_line.py @@ -10,6 +10,7 @@ # The setup is the same as the diffuser_free example # except that here vertices are only allowed to move # axially in a straight line. +# See diffuser_free for comments. small_pipe = cb.Cylinder([0, 0, 0], [2, 0, 0], [0, 1, 0]) small_pipe.chop_axial(start_size=size) @@ -23,19 +24,22 @@ big_pipe = cb.Cylinder.chain(diffuser, 5) big_pipe.chop_axial(start_size=size) + mesh.add(big_pipe) mesh.set_default_patch("walls", "wall") -# Assemble the mesh before making changes +diffuser.remove_inner_edges() +small_pipe.remove_inner_edges() +big_pipe.remove_inner_edges() + mesh.assemble() -# Find inside vertices finder = cb.RoundSolidFinder(mesh, diffuser) inner_vertices = finder.find_core(True) inner_vertices.update(finder.find_core(False)) -# Release those vertices so that optimization can find a better position for them + optimizer = cb.Optimizer(mesh) for vertex in inner_vertices: diff --git a/src/classy_blocks/construct/shapes/round.py b/src/classy_blocks/construct/shapes/round.py index 72ec3546..e71de554 100644 --- a/src/classy_blocks/construct/shapes/round.py +++ b/src/classy_blocks/construct/shapes/round.py @@ -71,6 +71,13 @@ def set_outer_patch(self, name: str) -> None: for operation in self.shell: operation.set_patch(self.outer_patch, name) + def remove_inner_edges(self) -> None: + """Removes spline edges from cylinders. + This needs to be done in cases where any of the start/end plane points will move + (due to optimization or manual adjustments).""" + for face in (*self.sketch_1.core, *self.sketch_2.core): + face.remove_edges() + class RoundHollowShape(RoundSolidShape): def __init__(