mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-25 05:20:34 +05:00
Add gmsh-import, pybind2.2 ctor for Mesh
This commit is contained in:
parent
89f41da33b
commit
cb9816c244
@ -431,6 +431,17 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
py::class_<Mesh,shared_ptr<Mesh>>(m, "Mesh")
|
||||
// .def(py::init<>("create empty mesh"))
|
||||
|
||||
.def(py::init( [] (int dim)
|
||||
{
|
||||
auto mesh = make_shared<Mesh>();
|
||||
mesh -> SetDimension(dim);
|
||||
SetGlobalMesh(mesh); // for visualization
|
||||
return mesh;
|
||||
} ),
|
||||
py::arg("dim")=3
|
||||
)
|
||||
|
||||
/*
|
||||
.def("__init__",
|
||||
[](Mesh *instance, int dim)
|
||||
{
|
||||
@ -439,7 +450,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
},
|
||||
py::arg("dim")=3
|
||||
)
|
||||
|
||||
*/
|
||||
|
||||
.def("__str__", &ToString<Mesh>)
|
||||
.def("Load", FunctionPointer
|
||||
|
@ -2,7 +2,7 @@ configure_file(__init__.py ${CMAKE_CURRENT_BINARY_DIR}/__init__.py @ONLY)
|
||||
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/__init__.py
|
||||
meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py
|
||||
meshing.py csg.py geom2d.py stl.py gui.py NgOCC.py read_gmsh.py
|
||||
DESTINATION ${NG_INSTALL_DIR_PYTHON}/${NG_INSTALL_SUFFIX}
|
||||
COMPONENT netgen
|
||||
)
|
||||
|
73
python/read_gmsh.py
Normal file
73
python/read_gmsh.py
Normal file
@ -0,0 +1,73 @@
|
||||
from netgen.meshing import *
|
||||
|
||||
def ReadGmsh (filename):
|
||||
f = open(filename, 'r')
|
||||
|
||||
mesh = Mesh(dim=3)
|
||||
|
||||
pointmap = { }
|
||||
facedescriptormap = { }
|
||||
|
||||
|
||||
while True:
|
||||
line = f.readline()
|
||||
if line == "": break
|
||||
|
||||
if line.split()[0]=="$Nodes":
|
||||
num = int(f.readline().split()[0])
|
||||
print ("reading",num,"nodes")
|
||||
for i in range(num):
|
||||
line = f.readline()
|
||||
nodenum,x,y,z = line.split()[0:4]
|
||||
pnum = mesh.Add (MeshPoint(Pnt(float(x),float(y),float(z))))
|
||||
pointmap[int(nodenum)] = pnum
|
||||
|
||||
if line.split()[0]=="$Elements":
|
||||
num = int(f.readline().split()[0])
|
||||
print ("reading",num,"elements")
|
||||
|
||||
for i in range(num):
|
||||
line = f.readline().split()
|
||||
elmnum = int(line[0])
|
||||
elmtype = int(line[1])
|
||||
numtags = int(line[2])
|
||||
tag1 = int(line[3])
|
||||
|
||||
if elmtype == 2: # 3-node trig
|
||||
num_nodes = 3
|
||||
elif elmtype == 3: # 4-node quad
|
||||
num_nodes = 4
|
||||
elif elmtype == 4: # 4-node tet
|
||||
num_nodes = 4
|
||||
else:
|
||||
print ("element type", elmtype, "not implemented")
|
||||
|
||||
nodenums = line[3+numtags:3+numtags+num_nodes]
|
||||
nodenums2 = [ pointmap[int(nn)] for nn in nodenums ]
|
||||
|
||||
|
||||
if elmtype in [2,3]: # 2d elements
|
||||
|
||||
# generate facedescriptor for boundary conditon number,
|
||||
# first tag is used as bc-number
|
||||
# element index maps into facedescriptor array
|
||||
if tag1 in facedescriptormap.keys():
|
||||
fdindex = facedescriptormap[tag1]
|
||||
else:
|
||||
fd = FaceDescriptor(bc=tag1)
|
||||
fdindex = mesh.Add(fd)
|
||||
facedescriptormap[tag1] = fdindex
|
||||
|
||||
mesh.Add (Element2D(fdindex, nodenums2))
|
||||
|
||||
if elmtype == 4: # 4-node tet
|
||||
nodenums2 = [ pointmap[int(nn)] for nn in nodenums ]
|
||||
mesh.Add (Element3D(tag1, [nodenums2[0],nodenums2[1],nodenums2[3],nodenums2[2]]))
|
||||
print (nodenums2)
|
||||
# print (mesh)
|
||||
# print (pointmap)
|
||||
|
||||
return mesh
|
||||
|
||||
# ReadGMSH ("test.gmsh")
|
||||
|
Loading…
Reference in New Issue
Block a user