|
| 1 | +#!/bin/env -S uv run --script |
| 2 | +# /// script |
| 3 | +# requires-python = ">=3.14" |
| 4 | +# dependencies = ["classy_blocks", "typing_extensions"] |
| 5 | +# /// |
| 6 | + |
| 7 | +# Generator script for the system/blockMeshDict |
| 8 | + |
| 9 | +import classy_blocks as cb |
| 10 | +import pathlib |
| 11 | + |
| 12 | +x0 = 0 |
| 13 | +x1 = 2 |
| 14 | +x2 = 3 |
| 15 | +x3 = 5 |
| 16 | +x4 = 6 |
| 17 | + |
| 18 | +y0 = 0 |
| 19 | +y1 = 1 |
| 20 | +y2 = 2 |
| 21 | + |
| 22 | +# Blocks |
| 23 | + |
| 24 | + |
| 25 | +def blockFor(l, r, b, t): |
| 26 | + return cb.Extrude(cb.Face([ |
| 27 | + [l, b, 0], |
| 28 | + [r, b, 0], |
| 29 | + [r, t, 0], |
| 30 | + [l, t, 0]]), 1) |
| 31 | + |
| 32 | + |
| 33 | +lb = blockFor(x0, x1, y0, y1) |
| 34 | +lt = blockFor(x0, x1, y1, y2) |
| 35 | + |
| 36 | +mt = blockFor(x1, x2, y1, y2) |
| 37 | + |
| 38 | +rt1 = blockFor(x2, x3, y1, y2) |
| 39 | +rb1 = blockFor(x2, x3, y0, y1) |
| 40 | +rt2 = blockFor(x3, x4, y1, y2) |
| 41 | +rb2 = blockFor(x3, x4, y0, y1) |
| 42 | + |
| 43 | +# Patches |
| 44 | + |
| 45 | + |
| 46 | +def patch(side: str, name: str, *items): |
| 47 | + for i in items: |
| 48 | + i.set_patch(side, name) |
| 49 | + |
| 50 | + |
| 51 | +patch("left", "inlet", lb, lt) |
| 52 | +patch("right", "outlet", rb2, rt2) |
| 53 | + |
| 54 | +patch("back", "upperWall", lt, mt, rt1, rt2) |
| 55 | +patch("front", "lowerWall", lb, rb1, rb2) |
| 56 | + |
| 57 | +patch("right", "obstacle", lb) |
| 58 | +patch("front", "obstacle", mt) |
| 59 | +patch("left", "obstacle", rb1) |
| 60 | + |
| 61 | +for b in [lb, lt, mt, rt1, rt2, rb1, rb2]: |
| 62 | + b.set_patch(["top", "bottom"], "frontAndBack") |
| 63 | + |
| 64 | +# Cells |
| 65 | + |
| 66 | + |
| 67 | +def chop(x, *items): |
| 68 | + for i in items: |
| 69 | + i.chop(0, count=x) |
| 70 | + i.chop(1, count=16) |
| 71 | + i.chop(2, count=1) |
| 72 | + |
| 73 | + |
| 74 | +chop(20, lb, lt, rb1, rt1) |
| 75 | +chop(10, mt) |
| 76 | + |
| 77 | +rb2.chop(0, count=20, start_size=0.1) |
| 78 | +rb2.chop(1, count=16) |
| 79 | +rb2.chop(2, count=1) |
| 80 | + |
| 81 | +rt2.chop(0, count=20, start_size=0.1) |
| 82 | +rt2.chop(1, count=16) |
| 83 | +rt2.chop(2, count=1) |
| 84 | + |
| 85 | +# Mesh |
| 86 | + |
| 87 | +m = cb.Mesh() |
| 88 | +m.add(lb) |
| 89 | +m.add(lt) |
| 90 | +m.add(mt) |
| 91 | +m.add(rb1) |
| 92 | +m.add(rb2) |
| 93 | +m.add(rt1) |
| 94 | +m.add(rt2) |
| 95 | + |
| 96 | +m.modify_patch("obstacle", "wall") |
| 97 | +m.modify_patch("upperWall", "wall") |
| 98 | +m.modify_patch("lowerWall", "wall") |
| 99 | +m.modify_patch("frontAndBack", "empty") |
| 100 | + |
| 101 | +m.write(pathlib.Path(__file__).parent / "system" / "blockMeshDict") |
0 commit comments