File: step_assembly.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 (43 lines) | stat: -rw-r--r-- 1,255 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
import gmsh
import sys
import os

gmsh.initialize()

# load step file
path = os.path.dirname(os.path.abspath(__file__))
gmsh.open(os.path.join(path, 'as1-tu-203.stp'))

# uncomment this to fragment all volumes, i.e. make the geometry conformal
# gmsh.model.occ.removeAllDuplicates()
# gmsh.model.occ.synchronize()

gmsh.option.setNumber('Mesh.MeshSizeFromCurvature', 15)
gmsh.option.setNumber('Mesh.MeshSizeMax', 8)

# get all model entities
ent = gmsh.model.getEntities()

physicals = {}
for e in ent:
    n = gmsh.model.getEntityName(e[0], e[1])
    # get entity labels read from STEP and create a physical group for all
    # entities having the same 3rd label in the /-separated label path
    if n:
        print('Entity ' + str(e) + ' has label ' + n + ' (and mass ' +
              str(gmsh.model.occ.getMass(e[0], e[1])) + ')')
        path = n.split('/')
        if e[0] == 3 and len(path) > 3:
            if (path[2] not in physicals):
                physicals[path[2]] = []
            physicals[path[2]].append(e[1])

# create the physical groups
for name, tags in physicals.items():
    p = gmsh.model.addPhysicalGroup(3, tags)
    gmsh.model.setPhysicalName(3, p, name)

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

gmsh.finalize()