Skip to content
Snippets Groups Projects

Cosserat-Continuum-Nonplanar

Compare and Show latest version
6 files
+ 345
1
Compare changes
  • Side-by-side
  • Inline
Files
6
+ 74
0
import math
file = open(r"cylinder10.msh","w+")
file.write("$MeshFormat\n")
file.write("2.2 0 8\n")
file.write("$EndMeshFormat\n")
# The grid nodes
file.write("$Nodes\n")
# Number of nodes in each direction
resolutionCircle = 20
resolutionHeight = 5
file.write(str(resolutionCircle * resolutionHeight) + "\n")
radius = 1
height = 1
counter = 1
#Write the vertices
for j in range(0, resolutionHeight):
for i in range(0, resolutionCircle):
alpha = 2*math.pi*i/(resolutionCircle)
x = radius*math.cos(alpha)
y = radius*math.sin(alpha)
z = 1.0*j*height/(resolutionHeight-1) # the multiplication with 1.0 is necessary here to prevent python from rounding!
file.write(str(counter) + " " + str(x) + " " + str(y) + " " + str(z) + "\n")
counter = counter + 1
file.write("$EndNodes\n")
# The grid elements
file.write("$Elements\n")
# We have resolutionCircle*(resolutionHeight-1) squares, this means we have 2* as many triangles
file.write(str(2*resolutionCircle*(resolutionHeight-1)) + "\n")
counter = 1
for i in range(0,resolutionCircle-1):
for j in range(0,resolutionHeight-1):
base = resolutionCircle * j + i + 1
file.write(str(counter) + " 2 0 "
+ str(base) + " "
+ str(base+1) + " "
+ str(base+resolutionCircle+1) + "\n")
counter = counter + 1
file.write(str(counter) + " 2 0 "
+ str(base) + " "
+ str(base+resolutionCircle+1) + " "
+ str(base+resolutionCircle) + "\n")
counter = counter + 1
# Last row of elements that closes the cylinder
for j in range(0,resolutionHeight-1):
base = resolutionCircle * j + resolutionCircle
file.write(str(counter) + " 2 0 "
+ str(base) + " "
+ str(base - resolutionCircle + 1) + " "
+ str(base + 1) + "\n")
counter = counter + 1
file.write(str(counter) + " 2 0 "
+ str(base) + " "
+ str(base + 1) + " "
+ str(base + resolutionCircle) + "\n")
counter = counter + 1
file.write("$EndElements\n")
file.close()
Loading