user2863620
user2863620

Reputation: 643

How to create a 3D mesh with Python?

I have a rectangular parallelepiped with three dimensions (X, Y, Z): 1 x 1 x 10. I want to create a mesh with 3 x 3 x 21 nodes and 2 x 2 x 20 finite elements which are 8-nodes solid elements with 2x2x2 integrating points. How can i do this with Python and collect the coordinates of all integrating points?

enter image description here

(photo's credits: Anton Zaicenco)

Thanks for your attention!

Upvotes: 1

Views: 13062

Answers (1)

user3072164
user3072164

Reputation:

Although I am still not entirely sure what you want, here an example using numpy.meshgrid printing all nodes:

import numpy

x = numpy.linspace(0, 1, 3)
y = numpy.linspace(0, 1, 3)
z = numpy.linspace(0, 10, 21)
mesh = numpy.meshgrid(x, y, z)
nodes = list(zip(*(dim.flat for dim in mesh)))
for node in nodes:
    print(node)

Although this can also be done as three simple loops:

for x in numpy.linsapce(0, 1, 3):
    for y in numpy.linspace(0, 1, 3):
        for z in numpy.linspace(0, 10, 21):
            print((x, y, z))

For further information on the usage of numpy.meshgrid see the documentation.

Upvotes: 2

Related Questions