Skip to content

Commit

Permalink
Merge branch 'feature/autochop' of github.com:damogranlabs/classy_blo…
Browse files Browse the repository at this point in the history
…cks into feature/autochop
  • Loading branch information
FranzBangar committed Oct 27, 2024
2 parents 2d19700 + 550ea7d commit 039ed67
Show file tree
Hide file tree
Showing 30 changed files with 274 additions and 207 deletions.
13 changes: 3 additions & 10 deletions examples/advanced/autograding_highre.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import classy_blocks as cb
from classy_blocks.grading.autograding.grader import HighReGrader
from classy_blocks.grading.autograding.params import HighReChopParams

mesh = cb.Mesh()

Expand All @@ -19,18 +18,12 @@
vertex = list(finder.find_in_sphere(point))[0]
vertex.translate([0, 0.8, 0])

# TODO! Un-hack
mesh.block_list.update()

mesh.set_default_patch("walls", "wall")

# TODO: Hack! mesh.assemble() won't work here but wires et. al. must be updated
mesh.block_list.update()

params = HighReChopParams(0.05)
grader = HighReGrader(mesh, params)
grader = HighReGrader(mesh, 0.05)
grader.grade()

# params = SimpleChopParams(0.05)
# grader = SimpleGrader(mesh, params)
# grader.grade(take="max")

mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
37 changes: 0 additions & 37 deletions examples/advanced/low_re_chops.py

This file was deleted.

3 changes: 1 addition & 2 deletions examples/chaining/labyrinth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import classy_blocks as cb
from classy_blocks.grading.autograding.grader import FixedCountGrader
from classy_blocks.grading.autograding.params import FixedCountParams
from classy_blocks.util import functions as f

mesh = cb.Mesh()
Expand Down Expand Up @@ -35,7 +34,7 @@

mesh.set_default_patch("walls", "wall")

grader = FixedCountGrader(mesh, FixedCountParams(5))
grader = FixedCountGrader(mesh, 5)
grader.grade()

mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
4 changes: 1 addition & 3 deletions examples/chaining/tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import classy_blocks as cb
from classy_blocks.grading.autograding.grader import SimpleGrader
from classy_blocks.grading.autograding.params import SimpleChopParams

# a cylindrical tank with round end caps
diameter = 0.5
Expand All @@ -26,8 +25,7 @@
mesh.add(start_cap)
mesh.add(end_cap)

params = SimpleChopParams(0.05)
grader = SimpleGrader(mesh, params)
grader = SimpleGrader(mesh, 0.05)
grader.grade()

mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
5 changes: 1 addition & 4 deletions examples/complex/cyclone/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
T_PIPE,
)

from classy_blocks.base.exceptions import GeometryConstraintError
from classy_blocks.types import NPPointType
from classy_blocks.util import functions as f
from classy_blocks.util.constants import vector_format as fvect


class GeometryConstraintError(Exception):
"""Raised when input parameters produce an invalid geometry"""


@dataclasses.dataclass
class Geometry:
"""Holds user-provided parameters and conversions to SI units;
Expand Down
8 changes: 1 addition & 7 deletions examples/shape/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import classy_blocks as cb
from classy_blocks.grading.autograding.grader import HighReGrader
from classy_blocks.grading.autograding.params import HighReChopParams
from classy_blocks.types import PointType
from classy_blocks.util import functions as f

Expand Down Expand Up @@ -63,15 +62,10 @@ def add_edges(self) -> None:

shape = cb.ExtrudedShape(base_1, 1)

# for op in shape.operations:
# for i in range(3):
# op.chop(i, count=10)
mesh.add(shape)
mesh.assemble()
mesh.block_list.update()

params = HighReChopParams(0.03)
grader = HighReGrader(mesh, params)
grader = HighReGrader(mesh, 0.03)
grader.grade(take="max")

mesh.set_default_patch("walls", "wall")
Expand Down
7 changes: 3 additions & 4 deletions examples/shape/cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import classy_blocks as cb
from classy_blocks.construct.flat.sketches.disk import DiskBase
from classy_blocks.grading.autograding.grader import HighReGrader
from classy_blocks.grading.autograding.params import HighReChopParams

DiskBase.core_ratio = 0.4 # Default is 0.8

Expand All @@ -26,6 +25,7 @@
bl_thickness = 0.05
core_size = 0.2

# manual grading
# cylinder.chop_axial(count=30)
# cylinder.chop_radial(start_size=core_size, end_size=bl_thickness)
# cylinder.chop_tangential(start_size=core_size)
Expand All @@ -35,9 +35,8 @@
mesh.assemble()
mesh.block_list.update()

params = HighReChopParams(0.1)
grader = HighReGrader(mesh, params)
# automatic grading
grader = HighReGrader(mesh, 0.1)
grader.grade()


mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
8 changes: 2 additions & 6 deletions examples/shape/quarter_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import classy_blocks as cb
from classy_blocks.construct.flat.sketches.disk import QuarterDisk
from classy_blocks.grading.autograding.grader import HighReGrader
from classy_blocks.grading.autograding.params import HighReChopParams
from classy_blocks.util import functions as f

mesh = cb.Mesh()
Expand All @@ -21,12 +20,9 @@
mesh.add(quarter_cylinder)

mesh.assemble()
# TODO: automate or something
mesh.block_list.update()

params = HighReChopParams(0.05)
grader = HighReGrader(mesh, params)
grader = HighReGrader(mesh, 0.05)
grader.grade()


mesh.set_default_patch("walls", "wall")
mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
99 changes: 78 additions & 21 deletions src/classy_blocks/base/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,7 @@
from typing import Optional


class VertexNotFoundError(Exception):
"""Raised when a vertex at a given point in space doesn't exist yet"""


class EdgeNotFoundError(Exception):
"""Raised when an edge between a given pair of vertices doesn't exist yet"""


class CornerPairError(Exception):
"""Raised when given pair of corners is not valid (for example, edge between 0 and 2)"""


class UndefinedGradingsError(Exception):
"""Raised when the user hasn't supplied enough grading data to
define all blocks in the mesh"""


class InconsistentGradingsError(Exception):
"""Raised when cell counts for edges on the same axis is not consistent"""


### Construction
class ShapeCreationError(Exception):
"""Base class for shape creation errors (invalid parameters/types to
shape constructors)"""
Expand Down Expand Up @@ -75,3 +55,80 @@ class FrustumCreationError(ShapeCreationError):

class ExtrudedRingCreationError(ShapeCreationError):
pass


class GeometryConstraintError(Exception):
"""Raised when input parameters produce an invalid geometry"""


class DegenerateGeometryError(Exception):
"""Raised when orienting failed because of invalid geometry"""


# Shell/offsetting logic
class SharedPointError(Exception):
"""Errors with shared points"""


class SharedPointNotFoundError(SharedPointError):
pass


class PointNotCoincidentError(SharedPointError):
pass


class DisconnectedChopError(SharedPointError):
"""Issued when chopping a Shell that has disconnected faces"""


### Search/retrieval
class VertexNotFoundError(Exception):
"""Raised when a vertex at a given point in space doesn't exist yet"""


class EdgeNotFoundError(Exception):
"""Raised when an edge between a given pair of vertices doesn't exist yet"""


class CornerPairError(Exception):
"""Raised when given pair of corners is not valid (for example, edge between 0 and 2)"""


### Grading
class UndefinedGradingsError(Exception):
"""Raised when the user hasn't supplied enough grading data to
define all blocks in the mesh"""


class InconsistentGradingsError(Exception):
"""Raised when cell counts for edges on the same axis is not consistent"""


class NoInstructionError(Exception):
"""Raised when building a catalogue"""


class BlockNotFoundError(Exception):
"""Raised when building a catalogue"""


### Optimization
class NoClampError(Exception):
"""Raised when there's no junction defined for a given Clamp"""


class ClampExistsError(Exception):
"""Raised when adding a clamp to a junction that already has one defined"""


class NoCommonSidesError(Exception):
"""Raised when two cells don't share a side"""


class NoJunctionError(Exception):
"""Raised when there's a clamp defined for a vertex that doesn't exist"""


class InvalidLinkError(Exception):
"""Raised when a link has been added that doesn't connect two actual points"""
5 changes: 1 addition & 4 deletions src/classy_blocks/construct/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np

from classy_blocks.base.element import ElementBase
from classy_blocks.base.exceptions import ShapeCreationError
from classy_blocks.construct.edges import Angle
from classy_blocks.construct.flat.sketch import Sketch, SketchT
from classy_blocks.construct.operations.loft import Loft
Expand All @@ -16,10 +17,6 @@
ShapeT = TypeVar("ShapeT", bound="Shape")


class ShapeCreationError(Exception):
"""Raised when creating a shape from errorneous data"""


class Shape(ElementBase, abc.ABC):
"""A collection of Operations that form a predefined
parametric shape"""
Expand Down
17 changes: 1 addition & 16 deletions src/classy_blocks/construct/shapes/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np

from classy_blocks.base.exceptions import DisconnectedChopError, PointNotCoincidentError, SharedPointNotFoundError
from classy_blocks.construct.flat.face import Face
from classy_blocks.construct.operations.loft import Loft
from classy_blocks.construct.point import Point
Expand All @@ -11,22 +12,6 @@
from classy_blocks.util import functions as f


class SharedPointError(Exception):
"""Errors with shared points"""


class SharedPointNotFoundError(SharedPointError):
pass


class PointNotCoincidentError(SharedPointError):
pass


class DisconnectedChopError(SharedPointError):
"""Issued when chopping a Shell that has disconnected faces"""


class SharedPoint:
"""A Point with knowledge of its "owner" Face(s)"""

Expand Down
12 changes: 6 additions & 6 deletions src/classy_blocks/grading/autograding/grader.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ class FixedCountGrader(GraderBase):

stages = 1

def __init__(self, mesh: Mesh, params: FixedCountParams):
super().__init__(mesh, params)
def __init__(self, mesh: Mesh, count: int = 8):
super().__init__(mesh, FixedCountParams(count))


class SimpleGrader(GraderBase):
Expand All @@ -81,8 +81,8 @@ class SimpleGrader(GraderBase):

stages = 1

def __init__(self, mesh: Mesh, params: SimpleChopParams):
super().__init__(mesh, params)
def __init__(self, mesh: Mesh, cell_size: float):
super().__init__(mesh, SimpleChopParams(cell_size))


class HighReGrader(GraderBase):
Expand All @@ -93,5 +93,5 @@ class HighReGrader(GraderBase):

stages = 3

def __init__(self, mesh: Mesh, params: HighReChopParams):
super().__init__(mesh, params)
def __init__(self, mesh: Mesh, cell_size: float):
super().__init__(mesh, HighReChopParams(cell_size))
Loading

0 comments on commit 039ed67

Please sign in to comment.