Skip to content

Commit

Permalink
Merge with feature/autochop
Browse files Browse the repository at this point in the history
  • Loading branch information
FranzBangar committed Oct 25, 2024
2 parents 9a2d992 + 550ea7d commit 3cd87b3
Show file tree
Hide file tree
Showing 58 changed files with 1,598 additions and 706 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.wordBasedSuggestions": "off",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
"source.organizeImports.isort": "explicit"
},
},
"python.analysis.typeCheckingMode": "basic",
Expand Down
29 changes: 29 additions & 0 deletions examples/advanced/autograding_highre.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os

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

mesh = cb.Mesh()

base = cb.Grid([0, 0, 0], [3, 2, 0], 3, 2)

shape = cb.ExtrudedShape(base, 1)
mesh.add(shape)
mesh.assemble()
finder = cb.GeometricFinder(mesh)

move_points = [[0, 1, 1], [2, 1, 1], [3, 1, 1]]

for point in move_points:
vertex = list(finder.find_in_sphere(point))[0]
vertex.translate([0, 0.8, 0])

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()

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

mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
2 changes: 1 addition & 1 deletion examples/advanced/edge_grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@

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

mesh.write(os.path.join("..", "case", "system", "blockMeshDict"))
mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
14 changes: 6 additions & 8 deletions examples/chaining/labyrinth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List

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

mesh = cb.Mesh()
Expand All @@ -14,7 +15,7 @@

face = cb.Face([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])
extrude = cb.Extrude(face, 1)
extrudes.append(extrude)
mesh.add(extrude)

for side in ("top", "right", "top", "top", "left", "top"):
face = extrude.get_face(side)
Expand All @@ -29,14 +30,11 @@
# the operations to keep them consistent - 'top' faces
# facing upwards.
orienter.reorient(extrude)

extrudes.append(extrude)

for extrude in extrudes:
for i in range(3):
extrude.chop(i, count=10)

mesh.add(extrude)

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

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

mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
12 changes: 4 additions & 8 deletions examples/chaining/tank.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
import os

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

# a cylindrical tank with round end caps
diameter = 0.5
length = 0.5 # including end caps

# refer to other examples for a proper-ish grading setup
h = 0.05

mesh = cb.Mesh()

cylinder = cb.Cylinder([0, 0, 0], [length, 0, 0], [0, diameter / 2, 0])

wall_name = "tank_wall"

cylinder.chop_axial(start_size=h)
cylinder.chop_radial(start_size=h)
cylinder.chop_tangential(start_size=h)
cylinder.set_outer_patch(wall_name)

start_cap = cb.Hemisphere.chain(cylinder, start_face=True)
start_cap.chop_axial(start_size=h)
start_cap.set_outer_patch(wall_name)

end_cap = cb.Hemisphere.chain(cylinder, start_face=False)
end_cap.chop_axial(start_size=h)
end_cap.set_outer_patch(wall_name)

mesh.add(cylinder)
mesh.add(start_cap)
mesh.add(end_cap)

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

mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
6 changes: 3 additions & 3 deletions examples/complex/airfoil/airfoil.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ def get_loft(indexes):
# chopping will propagate automatically through blocking
lofts[0].chop(2, count=1) # 1 cell in the 3rd dimension
# keep consistent first cell thickness by using edge grading
lofts[1].chop(1, start_size=BL_THICKNESS, c2c_expansion=C2C_EXPANSION, preserve="start_size")
lofts[8].chop(1, start_size=CELL_SIZE)
lofts[1].chop(1, start_size=BL_THICKNESS, c2c_expansion=C2C_EXPANSION, take="max", preserve="start_size")
lofts[8].chop(1, start_size=CELL_SIZE, take="max")

for i in (0, 1, 2, 3, 4, 5, 6):
lofts[i].chop(0, start_size=CELL_SIZE)
lofts[i].chop(0, start_size=CELL_SIZE, take="max")

for loft in lofts:
mesh.add(loft)
Expand Down
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
2 changes: 1 addition & 1 deletion examples/complex/heater/heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def set_cell_zones(shape: cb.Shape):

# The curved part of heater (and fluid around it); constructed from 4 revolves
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)
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)
Expand Down
6 changes: 3 additions & 3 deletions examples/operation/loft.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
# 4 points for face corners
[[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]],
# edges: arc between 0-1, line between 1-2, arc between 2-3, line between 3-0
[cb.Arc([0.5, -0.25, 0]), None, cb.Arc([0.5, 1.25, 0]), None],
[cb.Arc([0.5, -0.2, 0]), None, cb.Arc([0.5, 1.2, 0]), None],
)

top_face = cb.Face(
[[0, 0, 2], [1, 0, 2], [1, 1, 2], [0, 1, 2]], [None, cb.Arc([1.25, 0.5, 2]), None, cb.Arc([-0.25, 0.5, 2])]
[[0, 0, 2], [1, 0, 2], [1, 1, 2], [0, 1, 2]], [None, cb.Arc([1.2, 0.5, 2]), None, cb.Arc([-0.2, 0.5, 2])]
)

loft = cb.Loft(bottom_face, top_face)
loft.add_side_edge(0, cb.PolyLine([[0.15, 0.15, 0.5], [0.2, 0.2, 1.0], [0.15, 0.15, 1.5]])) # corners 0 - 4
loft.add_side_edge(0, cb.PolyLine([[0.1, 0.1, 0.5], [0.15, 0.15, 1.0], [0.1, 0.1, 1.5]])) # corners 0 - 4
loft.add_side_edge(1, cb.Arc([0.9, 0.1, 1])) # 1 - 5
loft.add_side_edge(2, cb.Arc([0.9, 0.9, 1])) # 2 - 6
loft.add_side_edge(3, cb.Arc([0.1, 0.9, 1])) # 3 - 7
Expand Down
10 changes: 6 additions & 4 deletions examples/shape/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numpy as np

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

Expand Down Expand Up @@ -61,10 +62,11 @@ 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()

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

mesh.set_default_patch("walls", "wall")
mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
17 changes: 13 additions & 4 deletions examples/shape/cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import classy_blocks as cb
from classy_blocks.construct.flat.sketches.disk import DiskBase
from classy_blocks.grading.autograding.grader import HighReGrader

DiskBase.core_ratio = 0.7 # Default is 0.8
DiskBase.core_ratio = 0.4 # Default is 0.8

mesh = cb.Mesh()

Expand All @@ -24,10 +25,18 @@
bl_thickness = 0.05
core_size = 0.2

cylinder.chop_axial(count=30)
cylinder.chop_radial(start_size=core_size, end_size=bl_thickness)
cylinder.chop_tangential(start_size=core_size)
# 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)

mesh.add(cylinder)

mesh.assemble()
mesh.block_list.update()

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

mesh.write(os.path.join("..", "case", "system", "blockMeshDict"), debug_path="debug.vtk")
28 changes: 28 additions & 0 deletions examples/shape/quarter_cylinder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os

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.util import functions as f

mesh = cb.Mesh()

axis_point_1 = f.vector(0.0, 0.0, 0.0)
axis_point_2 = f.vector(5.0, 5.0, 0.0)
radius_point_1 = f.vector(0.0, 0.0, 2.0)

# make a disk with small core block - yields particularly bad cell sizes with normal chops
QuarterDisk.core_ratio = 0.4

quarter_disk = QuarterDisk(axis_point_1, radius_point_1, axis_point_1 - axis_point_2)
quarter_cylinder = cb.ExtrudedShape(quarter_disk, f.norm(axis_point_2 - axis_point_1))

mesh.add(quarter_cylinder)

mesh.assemble()

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"""
Loading

0 comments on commit 3cd87b3

Please sign in to comment.