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
=== modified file 'tools/gmsh2triangle.py'
--- tools/gmsh2triangle.py 2011-10-21 10:05:25 +0000
+++ tools/gmsh2triangle.py 2012-03-14 11:19:20 +0000
@@ -58,14 +58,14 @@
5858
59dim=options.dim59dim=options.dim
6060
61gmsh_node_map = {}
62nodefile_linelist = []61nodefile_linelist = []
63for i in range(nodecount):62for i in range(nodecount):
64 # Node syntax63 # Node syntax
65 line = mshfile.readline().split()64 line = mshfile.readline().split()
66 gmsh_node = line[0] # the node number that gmsh has assigned, which might65 # compare node id assigned by gmsh to consecutive node id (assumed by fluidity)
67 # not be consecutive66 if eval(line[0])!=i+1:
68 gmsh_node_map[gmsh_node] = str(i+1)67 print line[0], i+1
68 sys.stderr.write("ERROR: Nodes in gmsh .msh file must be numbered consecutively.")
69 nodefile_linelist.append( line[1:dim+1] )69 nodefile_linelist.append( line[1:dim+1] )
7070
71assert(mshfile.readline().strip()=="$EndNodes")71assert(mshfile.readline().strip()=="$EndNodes")
@@ -153,43 +153,23 @@
153 sys.stderr.write("Unable to determine dimension of problem\n")153 sys.stderr.write("Unable to determine dimension of problem\n")
154 sys.exit(1)154 sys.exit(1)
155155
156# Get rid of isolated nodes
157isolated=set(range(1,nodecount+1))
158for ele in elements:
159 for i in range(loc):
160 isolated.discard(int(gmsh_node_map[ele[i]]))
161
162for i in range(nodecount):
163 j = str(i+1)
164 if int(gmsh_node_map[j]) in isolated:
165 gmsh_node_map[j] = -666
166 else:
167 gmsh_node_map[j] = int(gmsh_node_map[j])
168 gmsh_node_map[j] -= sum(gmsh_node_map[j] > k for k in isolated)
169 gmsh_node_map[j] = str(gmsh_node_map[j])
170
171newnodecount = nodecount-len(isolated)
172
173nodefile=file(basename+".node", 'w')156nodefile=file(basename+".node", 'w')
174nodefile.write(`newnodecount`+" "+`options.dim`+" 0 0\n")157nodefile.write(`nodecount`+" "+`options.dim`+" 0 0\n")
175j=0158j=0
176for i in range(nodecount): 159for i in range(nodecount):
177 if not(i+1 in isolated):160 j=j+1
178 j=j+1161 nodefile.write(" ".join( [str(j)] + nodefile_linelist[i] )+"\n")
179 nodefile.write(" ".join( [str(j)] + nodefile_linelist[i] )+"\n")
180162
181nodefile.write("# Produced by: "+" ".join(argv)+"\n")163nodefile.write("# Produced by: "+" ".join(argv)+"\n")
182nodefile.close()164nodefile.close()
183165
184nodecount=newnodecount
185
186# Output ele file166# Output ele file
187elefile.write(`len(elements)`+" "+`loc`+" 1\n")167elefile.write(`len(elements)`+" "+`loc`+" 1\n")
188168
189for i, element in enumerate(elements):169for i, element in enumerate(elements):
190 elefile.write(`i+1`+" ")170 elefile.write(`i+1`+" ")
191 for j in node_order:171 for j in node_order:
192 elefile.write(" ".join([gmsh_node_map[x] for x in element[j-1:j]])+" ")172 elefile.write(" ".join(element[j-1:j])+" ")
193 elefile.write(" ".join(element[-1:]))173 elefile.write(" ".join(element[-1:]))
194 elefile.write(" "+"\n")174 elefile.write(" "+"\n")
195175
@@ -201,7 +181,7 @@
201 # make node element list181 # make node element list
202 ne_list = [set() for i in range(nodecount)]182 ne_list = [set() for i in range(nodecount)]
203 for i, element in enumerate(elements):183 for i, element in enumerate(elements):
204 element=[eval(gmsh_node_map[element[j-1]]) for j in node_order]184 element=[eval(element[j-1]) for j in node_order]
205 for node in element:185 for node in element:
206 ne_list[node-1].add(i)186 ne_list[node-1].add(i)
207187
@@ -212,7 +192,7 @@
212 face_nodes=[eval(node) for node in face[:-1]]192 face_nodes=[eval(node) for node in face[:-1]]
213 # loop through elements around node face_nodes[0]193 # loop through elements around node face_nodes[0]
214 for ele in ne_list[face_nodes[0]-1]:194 for ele in ne_list[face_nodes[0]-1]:
215 element=[eval(gmsh_node_map[elements[ele][j-1]]) for j in node_order]195 element=[eval(elements[ele][j-1]) for j in node_order]
216 if set(face_nodes) < set(element):196 if set(face_nodes) < set(element):
217 facelist.append(face+[`ele+1`])197 facelist.append(face+[`ele+1`])
218 198