File: flatten.py

package info (click to toggle)
gmsh 4.15.1%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,880 kB
  • sloc: cpp: 440,657; ansic: 114,930; f90: 15,611; python: 13,907; yacc: 7,438; java: 3,491; lisp: 3,206; lex: 633; perl: 571; makefile: 500; xml: 414; sh: 407; javascript: 113; modula3: 32
file content (50 lines) | stat: -rw-r--r-- 1,322 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gmsh
import sys

# script showing how a mesh can be modified (here setting all z coordinates of
# nodes to 0) by getting the mesh, performing a modification, and storing the
# modified mesh in the same model.

# (The approach followed here is overkill to # just change node coordinates of
# course - if you merely want to change coordinates see `flatten2.py' instead.)

if len(sys.argv) < 2:
    print("Usage: " + sys.argv[0] + " file.msh")
    exit(0)

gmsh.initialize()
try:
    gmsh.open(sys.argv[1])
except:
    exit(0)

nodeTags = {}
nodeCoords = {}
elementTypes = {}
elementTags = {}
elementNodeTags = {}

entities = gmsh.model.getEntities()

# get the nodes and elements
for e in entities:
    nodeTags[e], nodeCoords[e], _ = gmsh.model.mesh.getNodes(e[0], e[1])
    elementTypes[e], elementTags[e], elementNodeTags[e] = gmsh.model.mesh.getElements(e[0], e[1])

# delete the mesh
gmsh.model.mesh.clear()

# store new mesh
for e in entities:
    for i in range(2, len(nodeCoords[e]), 3):
        nodeCoords[e][i] = 0
    gmsh.model.mesh.addNodes(e[0], e[1], nodeTags[e], nodeCoords[e])
    gmsh.model.mesh.addElements(e[0], e[1], elementTypes[e], elementTags[e],
                                elementNodeTags[e])

if '-nopopup' not in sys.argv:
    gmsh.fltk.run()

#gmsh.write('flat.msh')

gmsh.finalize()