Skip to content

Commit 44e2384

Browse files
committed
Add new blockMesh including generator
1 parent 7b2d66a commit 44e2384

File tree

2 files changed

+234
-131
lines changed

2 files changed

+234
-131
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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")
Lines changed: 133 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,158 @@
1+
/*---------------------------------------------------------------------------*\
2+
| ========= | |
3+
| \ / F ield | OpenFOAM: The Open Source CFD Toolbox |
4+
| \ / O peration | Script: ./createMesh.py |
5+
| \ / A nd | Time: 2025-12-10 15:04:24.979831 |
6+
| \/ M anipulation | |
7+
\*---------------------------------------------------------------------------*/
18
FoamFile
29
{
310
version 2.0;
411
format ascii;
512
class dictionary;
613
object blockMeshDict;
714
}
8-
9-
x0 0.;
10-
x1 2.;
11-
x2 3.;
12-
x3 6.;
13-
14-
y0 0.;
15-
y1 1.;
16-
y2 2.;
17-
18-
z0 0;
19-
z1 1;
15+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2016

2117
vertices
2218
(
23-
($x0 $y0 $z0 ) // 0
24-
($x1 $y0 $z0 ) // 1
25-
($x2 $y0 $z0 ) // 2
26-
($x3 $y0 $z0 ) // 3
27-
($x0 $y1 $z0 ) // 4
28-
($x1 $y1 $z0 ) // 5
29-
($x2 $y1 $z0 ) // 6
30-
($x3 $y1 $z0 ) // 7
31-
($x0 $y2 $z0 ) // 8
32-
($x1 $y2 $z0 ) // 9
33-
($x2 $y2 $z0 ) // 10
34-
($x3 $y2 $z0 ) // 11
19+
(0.00000000 0.00000000 0.00000000) // 0
20+
(2.00000000 0.00000000 0.00000000) // 1
21+
(2.00000000 1.00000000 0.00000000) // 2
22+
(0.00000000 1.00000000 0.00000000) // 3
23+
(0.00000000 0.00000000 1.00000000) // 4
24+
(2.00000000 0.00000000 1.00000000) // 5
25+
(2.00000000 1.00000000 1.00000000) // 6
26+
(0.00000000 1.00000000 1.00000000) // 7
27+
(2.00000000 2.00000000 0.00000000) // 8
28+
(0.00000000 2.00000000 0.00000000) // 9
29+
(2.00000000 2.00000000 1.00000000) // 10
30+
(0.00000000 2.00000000 1.00000000) // 11
31+
(3.00000000 1.00000000 0.00000000) // 12
32+
(3.00000000 2.00000000 0.00000000) // 13
33+
(3.00000000 1.00000000 1.00000000) // 14
34+
(3.00000000 2.00000000 1.00000000) // 15
35+
(3.00000000 0.00000000 0.00000000) // 16
36+
(5.00000000 0.00000000 0.00000000) // 17
37+
(5.00000000 1.00000000 0.00000000) // 18
38+
(3.00000000 0.00000000 1.00000000) // 19
39+
(5.00000000 0.00000000 1.00000000) // 20
40+
(5.00000000 1.00000000 1.00000000) // 21
41+
(6.00000000 0.00000000 0.00000000) // 22
42+
(6.00000000 1.00000000 0.00000000) // 23
43+
(6.00000000 0.00000000 1.00000000) // 24
44+
(6.00000000 1.00000000 1.00000000) // 25
45+
(5.00000000 2.00000000 0.00000000) // 26
46+
(5.00000000 2.00000000 1.00000000) // 27
47+
(6.00000000 2.00000000 0.00000000) // 28
48+
(6.00000000 2.00000000 1.00000000) // 29
49+
);
3550

36-
($x0 $y0 $z1 ) // 12
37-
($x1 $y0 $z1 ) // 13
38-
($x2 $y0 $z1 ) // 14
39-
($x3 $y0 $z1 ) // 15
40-
($x0 $y1 $z1 ) // 16
41-
($x1 $y1 $z1 ) // 17
42-
($x2 $y1 $z1 ) // 18
43-
($x3 $y1 $z1 ) // 19
44-
($x0 $y2 $z1 ) // 20
45-
($x1 $y2 $z1 ) // 21
46-
($x2 $y2 $z1 ) // 22
47-
($x3 $y2 $z1 ) // 23
51+
blocks
52+
(
53+
hex ( 0 1 2 3 4 5 6 7 ) ( 20 16 1 ) simpleGrading ( 1 1 1 ) // 0
54+
hex ( 3 2 8 9 7 6 10 11 ) ( 20 16 1 ) simpleGrading ( 1 1 1 ) // 1
55+
hex ( 2 12 13 8 6 14 15 10 ) ( 10 16 1 ) simpleGrading ( 1 1 1 ) // 2
56+
hex ( 16 17 18 12 19 20 21 14 ) ( 20 16 1 ) simpleGrading ( 1 1 1 ) // 3
57+
hex ( 17 22 23 18 20 24 25 21 ) ( 20 16 1 ) simpleGrading ( 0.19723533562312945 1 1 ) // 4
58+
hex ( 12 18 26 13 14 21 27 15 ) ( 20 16 1 ) simpleGrading ( 1 1 1 ) // 5
59+
hex ( 18 23 28 26 21 25 29 27 ) ( 20 16 1 ) simpleGrading ( 0.19723533562312945 1 1 ) // 6
4860
);
4961

62+
edges
63+
(
64+
);
5065

51-
// Grading
52-
//h1 16;
53-
//h2 8;
54-
//h3 24;
55-
//v1 8;
66+
boundary
67+
(
68+
frontAndBack
69+
{
70+
type empty;
71+
faces
72+
(
73+
(14 21 27 15)
74+
(6 14 15 10)
75+
(2 12 13 8)
76+
(18 23 28 26)
77+
(16 17 18 12)
78+
(17 22 23 18)
79+
(0 1 2 3)
80+
(12 18 26 13)
81+
(19 20 21 14)
82+
(7 6 10 11)
83+
(20 24 25 21)
84+
(3 2 8 9)
85+
(4 5 6 7)
86+
(21 25 29 27)
87+
);
88+
}
5689

57-
//h1 40;
58-
//h2 20;
59-
//h3 60;
60-
//v1 32;
90+
lowerWall
91+
{
92+
type wall;
93+
faces
94+
(
95+
(20 24 22 17)
96+
(4 5 1 0)
97+
(19 20 17 16)
98+
);
99+
}
61100

62-
h1 20;
63-
h2 10;
64-
h3 30;
65-
v1 16;
101+
obstacle
102+
{
103+
type wall;
104+
faces
105+
(
106+
(5 1 2 6)
107+
(19 16 12 14)
108+
(6 14 12 2)
109+
);
110+
}
66111

67-
blocks
68-
(
69-
hex ( 0 1 5 4 12 13 17 16 )
70-
($h1 $v1 1 )
71-
simpleGrading (1 1 1)
112+
inlet
113+
{
114+
type patch;
115+
faces
116+
(
117+
(7 3 9 11)
118+
(4 0 3 7)
119+
);
120+
}
72121

73-
hex ( 2 3 7 6 14 15 19 18 )
74-
($h3 $v1 1)
75-
simpleGrading (1 1 1)
122+
upperWall
123+
{
124+
type wall;
125+
faces
126+
(
127+
(27 29 28 26)
128+
(15 27 26 13)
129+
(11 10 8 9)
130+
(10 15 13 8)
131+
);
132+
}
76133

77-
hex ( 4 5 9 8 16 17 21 20 )
78-
($h1 $v1 1)
79-
simpleGrading (1 1 1)
134+
outlet
135+
{
136+
type patch;
137+
faces
138+
(
139+
(24 22 23 25)
140+
(25 23 28 29)
141+
);
142+
}
80143

81-
hex ( 5 6 10 9 17 18 22 21 )
82-
($h2 $v1 1)
83-
simpleGrading (1 1 1)
144+
);
84145

85-
hex ( 6 7 11 10 18 19 23 22 )
86-
($h3 $v1 1 )
87-
simpleGrading (1 1 1)
146+
faces
147+
(
88148
);
89149

90-
boundary
150+
mergePatchPairs
91151
(
92-
inlet
93-
{
94-
type patch;
95-
faces
96-
(
97-
( 0 4 16 12 )
98-
( 4 8 20 16 )
99-
);
100-
}
101-
outlet
102-
{
103-
type patch;
104-
faces
105-
(
106-
( 3 7 19 15 )
107-
( 7 11 23 19 )
108-
);
109-
}
110-
obstacle
111-
{
112-
type wall;
113-
faces
114-
(
115-
( 1 5 17 13 )
116-
( 5 6 18 17 )
117-
( 6 2 14 18 )
118-
);
119-
}
120-
upperWall
121-
{
122-
type wall;
123-
faces
124-
(
125-
( 8 9 21 20 )
126-
( 9 10 22 21 )
127-
( 10 11 23 22 )
128-
);
129-
}
130-
lowerWall
131-
{
132-
type wall;
133-
faces
134-
(
135-
( 0 1 13 12 )
136-
( 2 3 15 14 )
137-
);
138-
}
139-
frontAndBack
140-
{
141-
type empty;
142-
faces
143-
(
144-
( 0 1 5 4 )
145-
( 2 3 7 6 )
146-
( 4 5 9 8 )
147-
( 5 6 10 9 )
148-
( 6 7 11 10 )
149-
( 12 13 17 16 )
150-
( 14 15 19 18 )
151-
( 16 17 21 20 )
152-
( 17 18 22 21 )
153-
( 18 19 23 22 )
154-
);
155-
}
156152
);
153+
154+
scale 1;
155+
156+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157+
// Created with classy_blocks: https://github.com/damogranlabs/classy_blocks //
158+
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

0 commit comments

Comments
 (0)