Skip to content

Instantly share code, notes, and snippets.

@0x1d107
Created October 28, 2024 13:55
Show Gist options
  • Select an option

  • Save 0x1d107/babc9ace0db18da96b20c50fbadfaebd to your computer and use it in GitHub Desktop.

Select an option

Save 0x1d107/babc9ace0db18da96b20c50fbadfaebd to your computer and use it in GitHub Desktop.
from math import *
HEADER = """
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
"""
scale = 0.1
vertices=[]
edges=[]
blocks=[]
n=10
r= 5
h= 10
vertices.extend([(r*cos(pi*i/n),r*sin(pi*i/n),0) for i in range(n)])
vertices.extend([(r*cos(pi*i/n),r*sin(pi*i/n),h) for i in range(n)])
def print_file():
print(HEADER)
print(f"convertToMeters {scale};")
print('vertices\n(')
for vx in vertices:
print("(",*vx,")")
print(');')
print('edges\n(')
for ed in edges:
print(*ed[0:3],"(",*ed[3],")")
print(');')
print('blocks\n(')
for bl in blocks:
print(bl[0],'(',*bl[1],')','(',*bl[2],')',bl[3],'(',*bl[4],')')
print(');')
print_file()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment