dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #03896
dolfin-convert: bug with conversion from gmsh?
It is indeed not necessary. A simple in-line replace for <mesh> is
enough. Patch is attached.
thanks for pointing that out.
diff -u --new-file --recursive dolfin-0.6.4/src/utils/convert/dolfin-convert dolfin-0.6.4-mod/src/utils/convert/dolfin-convert
--- dolfin-0.6.4/src/utils/convert/dolfin-convert 2006-12-01 11:43:25.000000000 +0100
+++ dolfin-0.6.4-mod/src/utils/convert/dolfin-convert 2006-12-04 12:54:33.000000000 +0100
@@ -5,11 +5,13 @@
#
# Modified by Garth N. Wells (gmsh function)
# Modified by Alexander H. Jarosch (gmsh fix)
+# Modified by Angelo Simone (Gmsh and Medit new format fix)
#
# Script for converting between various data formats
import getopt
import sys
+import os
from commands import getoutput
def main(argv):
@@ -233,6 +235,9 @@
ifile.close()
ofile.close()
+ # Complete file conversion
+ complete_conversion(ofilename)
+
def gmsh2xml(ifilename, ofilename):
"""Convert between .gmsh v2.0 format (http://www.geuz.org/gmsh/) and .xml,
parser implemented as a state machine:
@@ -349,6 +354,9 @@
n2 = nodelist[nn[2]]
n3 = nodelist[nn[3]]
write_cell_tetrahedron(ofile, num_cells_read, n0, n1, n2, n3)
+ else:
+ error("Unknown element type. Did you define a physical surface/volume? \n\
+If you didn't, gmsh exports edges as cells. \nSee http://www.geuz.org/gmsh/doc/texinfo/gmsh.html")
num_cells_read +=1
if num_cells == num_cells_read:
@@ -371,6 +379,9 @@
ifile.close()
ofile.close()
+ # Complete file conversion
+ complete_conversion(ofilename)
+
def xml_old2xml(ifilename, ofilename):
"Convert from old DOLFIN XML format to new."
@@ -428,6 +439,21 @@
ifile.close();
ofile.close();
+def complete_conversion(ofilename):
+ " -- Replace <mesh> with <mesh celltype=CELLTYPE dim=DIM>"
+
+ string="<mesh>"
+
+ # Get dimension
+ tris = len(getoutput("grep triangle " + ofilename))
+ tets = len(getoutput("grep tetrahedron " + ofilename))
+ if tris > 0 and tets == 0:
+ os.system("sed -i -e 's/<mesh>/<mesh celltype=\"triangle\" dim=\"2\">/g' " + ofilename)
+ elif tris == 0 and tets > 0:
+ os.system("sed -i -e 's/<mesh>/<mesh celltype=\"tetrahedron\" dim=\"3\">/g' " + ofilename)
+ else:
+ error("Inconsistent mesh file, not exactly one type of cells.")
+
# Write mesh header
def write_header(ofile):
ofile.write("""\
@@ -456,7 +482,7 @@
def write_vertex(ofile, vertex, x, y, z):
"Write vertex"
- ofile.write(" <vertex name=\"%d\" x=\"%g\" y=\"%g\" z=\"%g\"/>\n" % \
+ ofile.write(" <vertex index=\"%d\" x=\"%g\" y=\"%g\" z=\"%g\"/>\n" % \
(vertex, x, y, z))
def write_header_cells(ofile, num_cells):
@@ -471,12 +497,12 @@
def write_cell_triangle(ofile, cell, n0, n1, n2):
"Write cell (triangle)"
- ofile.write(" <triangle name=\"%d\" n0=\"%d\" n1=\"%d\" n2=\"%d\"/>\n" % \
+ ofile.write(" <triangle index=\"%d\" v0=\"%d\" v1=\"%d\" v2=\"%d\"/>\n" % \
(cell, n0, n1, n2))
def write_cell_tetrahedron(ofile, cell, n0, n1, n2, n3):
"Write cell (tetrahedron)"
- ofile.write(" <tetrahedron name=\"%d\" n0=\"%d\" n1=\"%d\" n2=\"%d\" n3=\"%d\"/>\n" % \
+ ofile.write(" <tetrahedron index=\"%d\" v0=\"%d\" v1=\"%d\" v2=\"%d\" v3=\"%d\"/>\n" % \
(cell, n0, n1, n2, n3))
if __name__ == "__main__":