Script to import .unv mesh from Salome platform¶
Here is a contribution from Luyang Han.
Hello all,
This is an ad-hoc script to import the .unv mesh file exported from Salome platform (http://www.salome-platform.org/). The solid modeling and mesh generation in Salome is much more powerful and easier to use compared to gmsh.
Salome can only export unv file with just one region, thus all simplices are set to region 1.
To use the script do:
chmod +x importunv.py ./importunv.py infile.unv outfile.nmesh.h5
The script need to setup nmag path in the env.
Regards.
#!/usr/bin/env nsim import sys import nmesh def loadmesh(filename): vertices = [] simplex = [] with open(filename) as fname: #skip the first two lines fname.readline() fname.readline() # start to read the vertices input_a = fname.readline() input_b = fname.readline() while input_a.strip() <> '-1' : coord = map(float,input_b.strip().split()) vertices.append(coord) input_a = fname.readline() input_b = fname.readline() # finish the vertices part. # ignore one line here fname.readline() # read lines till we reach the simplex region input_a = fname.readline() while True: if len(input_a.strip().split()) == 6 and input_a.strip().split()[-1] == '4': break else: input_a = fname.readline() # now we reached the first line of the simplex region #input_b = fname.readline() #simp = map(int,input_b.strip().split()) #simplex.append(simp) #input_a = fname.readline() while input_a.strip() <> '-1' : input_b = fname.readline() simp = map(int,input_b.strip().split()) simplex.append(simp) input_a = fname.readline() # finish the reading return vertices, simplex #main program mesh = None infile = sys.argv[1] outfile = sys.argv[2] points,simplices_indices = loadmesh(infile) simplices_regions = [1] * len(simplices_indices) mesh = nmesh.mesh_from_points_and_simplices(points=points, simplices_indices=simplices_indices, simplices_regions=simplices_regions, periodic_point_indices=[], initial=1, do_reorder=True) mesh.save(outfile)