Merge lp:~fluidity-core/fluidity/fluidity-gmsh2triangle-fix-reordering into lp:fluidity

Proposed by Stephan Kramer
Status: Merged
Merged at revision: 3950
Proposed branch: lp:~fluidity-core/fluidity/fluidity-gmsh2triangle-fix-reordering
Merge into: lp:fluidity
Diff against target: 87 lines (+10/-30)
1 file modified
tools/gmsh2triangle.py (+10/-30)
To merge this branch: bzr merge lp:~fluidity-core/fluidity/fluidity-gmsh2triangle-fix-reordering
Reviewer Review Type Date Requested Status
Cian Wilson Approve
Review via email: mp+97371@code.launchpad.net

Description of the change

This deals with bug https://bugs.launchpad.net/fluidity/+bug/947049

"The script gmsh2triangle tries to identify isolated nodes that are not attached to any elements (isolated nodes) and leaves these out of the output triangle files. This requires a renumbering of the nodes. However this renumbering is only applied to the .ele file but not .edge/.face file. Thus this renumbering only works correctly when the isolated nodes have node numbers that are bigger than any of the boundary nodes. Otherwise the node numbering of the surface mesh and the interior mesh no longer correspond leading to very onobvious errors in fluidity."

Fixed by no longer applying any renumbering. This was decided to be the best fix as gmsh meshes are now also be readable directly by fluidity, in which case isolated nodes would be read as well. So if isolated nodes are present in the input gmsh .msh it's up to the user to fix.

To post a comment you must log in.
Revision history for this message
Cian Wilson (cwilson) wrote :

Looks good. Is there a buildbot queue?

Revision history for this message
Stephan Kramer (s-kramer) wrote :

There is. Bizarrely it's failing 2 tests that don't actually use gmsh2triangle! They run fine locally, and also the in the trunk build test, so I really have no idea how to fix this...

Summary of test problems with failures or warnings:
divergence_free_velocity_press_cg_test_cty_cv.xml: PF
darcy_p0p1_test_cty_cv_pressBCinlet_advect_tracer_p1cv_steptwochannel.xml: PPPFPPPPP

Revision history for this message
Cian Wilson (cwilson) wrote :

Yup, those look orthogonal and probably just a result of tolerances being too tight. I guess file them as separate bugs and assign them to their owners if they go red post-merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tools/gmsh2triangle.py'
2--- tools/gmsh2triangle.py 2011-10-21 10:05:25 +0000
3+++ tools/gmsh2triangle.py 2012-03-14 11:19:20 +0000
4@@ -58,14 +58,14 @@
5
6 dim=options.dim
7
8-gmsh_node_map = {}
9 nodefile_linelist = []
10 for i in range(nodecount):
11 # Node syntax
12 line = mshfile.readline().split()
13- gmsh_node = line[0] # the node number that gmsh has assigned, which might
14- # not be consecutive
15- gmsh_node_map[gmsh_node] = str(i+1)
16+ # compare node id assigned by gmsh to consecutive node id (assumed by fluidity)
17+ if eval(line[0])!=i+1:
18+ print line[0], i+1
19+ sys.stderr.write("ERROR: Nodes in gmsh .msh file must be numbered consecutively.")
20 nodefile_linelist.append( line[1:dim+1] )
21
22 assert(mshfile.readline().strip()=="$EndNodes")
23@@ -153,43 +153,23 @@
24 sys.stderr.write("Unable to determine dimension of problem\n")
25 sys.exit(1)
26
27-# Get rid of isolated nodes
28-isolated=set(range(1,nodecount+1))
29-for ele in elements:
30- for i in range(loc):
31- isolated.discard(int(gmsh_node_map[ele[i]]))
32-
33-for i in range(nodecount):
34- j = str(i+1)
35- if int(gmsh_node_map[j]) in isolated:
36- gmsh_node_map[j] = -666
37- else:
38- gmsh_node_map[j] = int(gmsh_node_map[j])
39- gmsh_node_map[j] -= sum(gmsh_node_map[j] > k for k in isolated)
40- gmsh_node_map[j] = str(gmsh_node_map[j])
41-
42-newnodecount = nodecount-len(isolated)
43-
44 nodefile=file(basename+".node", 'w')
45-nodefile.write(`newnodecount`+" "+`options.dim`+" 0 0\n")
46+nodefile.write(`nodecount`+" "+`options.dim`+" 0 0\n")
47 j=0
48 for i in range(nodecount):
49- if not(i+1 in isolated):
50- j=j+1
51- nodefile.write(" ".join( [str(j)] + nodefile_linelist[i] )+"\n")
52+ j=j+1
53+ nodefile.write(" ".join( [str(j)] + nodefile_linelist[i] )+"\n")
54
55 nodefile.write("# Produced by: "+" ".join(argv)+"\n")
56 nodefile.close()
57
58-nodecount=newnodecount
59-
60 # Output ele file
61 elefile.write(`len(elements)`+" "+`loc`+" 1\n")
62
63 for i, element in enumerate(elements):
64 elefile.write(`i+1`+" ")
65 for j in node_order:
66- elefile.write(" ".join([gmsh_node_map[x] for x in element[j-1:j]])+" ")
67+ elefile.write(" ".join(element[j-1:j])+" ")
68 elefile.write(" ".join(element[-1:]))
69 elefile.write(" "+"\n")
70
71@@ -201,7 +181,7 @@
72 # make node element list
73 ne_list = [set() for i in range(nodecount)]
74 for i, element in enumerate(elements):
75- element=[eval(gmsh_node_map[element[j-1]]) for j in node_order]
76+ element=[eval(element[j-1]) for j in node_order]
77 for node in element:
78 ne_list[node-1].add(i)
79
80@@ -212,7 +192,7 @@
81 face_nodes=[eval(node) for node in face[:-1]]
82 # loop through elements around node face_nodes[0]
83 for ele in ne_list[face_nodes[0]-1]:
84- element=[eval(gmsh_node_map[elements[ele][j-1]]) for j in node_order]
85+ element=[eval(elements[ele][j-1]) for j in node_order]
86 if set(face_nodes) < set(element):
87 facelist.append(face+[`ele+1`])
88