Reputation: 11
How can i create a 2D mesh in Python? I tried to use meshpy. If i try to run, python told me Error: all Vertices are coplanar.
I am currently working on a finite Elements program and the first step is to build meshes for geometries. Can anybody help me?
Thats the Code i usually use, you can see it below.
import meshpy as mp
from meshpy.tet import MeshInfo, build
mesh_info = MeshInfo()
mesh = build(mesh_info)
mesh_info.set_points([
(0, 0, 0), (1.445, 0.19, 0), (3, 0.19, 0), (1.555, 0.19, 0),
(1.555, 2.81, 0), (3, 2.81, 0), (3, 3, 0), (0, 3, 0),
(0, 2.81, 0), (1.445, 2.81, 0), (1.445, 0.19, 0),
(0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0),
mesh_info.set_facets([
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
[0,1,2],[0,2,3],
])
print('Mesh Points')
for i,p in enumerate(mesh_info.points):
print(i, p)
Upvotes: 1
Views: 4112
Reputation: 159
You can use the pymadcad module, it is meant for 3d, but as far as 2d is a subcase of 3d one can easily get things done that way. This module aims to keep things simple and intuitive.
There is also a geometry constraints solver, you can take a look at that documentation
To make sure your result is perfectly planar and not wrapped during the constraint solving, you can use the OnPlane
constraint doc
But just to know: What kind of geometries are you looking for ?
Upvotes: 0
Reputation: 1
I think you are effectively generating a 3D mesh (tet module used). Therefore since you are trying to generate 2D mesh, all your points lies on the same plane. You need to find the specific module for 2D in the lib
Upvotes: 0