"To rescale the z-dimension by a factor of 1000,\n" "%prog '(x,y,1000*z)' mesh.\n") (options, argv) = optparser.parse_args() if len(argv) != 2: optparser.print_help() sys.exit(1) transformation = argv[0] mesh_name = argv[1] # make all definitions of the math module available in # the transformation expression. globals = math.__dict__ mesh = gmshtools.ReadMsh(mesh_name + '.msh') dim = mesh.GetDim() def remap(coords): globals['x'] = coords[0] globals['y'] = coords[1] if dim == 3: globals['z'] = coords[2] return eval(transformation, globals) mesh.RemapNodeCoords(remap) gmshtools.WriteMsh(mesh, mesh_name + '.msh')
node1 = start node2 = start + 1 node3 = start + Nx node4 = node3 + 1 node5 = start + Nx * Ny node6 = node5 + 1 node8 = node5 + Nx node7 = node8 + 1 # trust us, the following is right: mesh.AddVolumeElement( eles.Element(nodes=[node1, node4, node3, node7], ids=[region_id])) mesh.AddVolumeElement( eles.Element(nodes=[node1, node7, node8, node5], ids=[region_id])) mesh.AddVolumeElement( eles.Element(nodes=[node8, node3, node7, node1], ids=[region_id])) mesh.AddVolumeElement( eles.Element(nodes=[node1, node2, node4, node7], ids=[region_id])) mesh.AddVolumeElement( eles.Element(nodes=[node1, node7, node5, node6], ids=[region_id])) mesh.AddVolumeElement( eles.Element(nodes=[node1, node2, node7, node6], ids=[region_id])) # Now write the constructed mesh to file gmshtools.WriteMsh(mesh, "%s.msh" % (meshname))
description="""Creates an icohedral gmsh mesh of the 2-sphere in 3D.""") optparser.add_option("--ascii", "-a", help="Convert to ASCII Gmsh format", action="store_const", const=True, dest="ascii", default=False) (options, argv) = optparser.parse_args() try: filename = argv[0] radius = float(argv[1]) subdivisions = int(argv[2]) except: optparser.error("Incorrect number or value of arguments.") nodes, faces = icosahedron() for i in xrange(subdivisions): subdivide(nodes, faces) nodes = radius * numpy.array(nodes) mesh = Mesh(3, nodes, volumeElements=[], surfaceElements=[Element(face) for face in faces]) # now we can write the gmsh file: gmshtools.WriteMsh(mesh, "%s.msh" % (filename), binary=not options.ascii)
debug.FatalError("Number of nodes and number of meshes required") try: nodeCount = int(args[0]) assert(nodeCount >= 0) except [ValueError, AssertionError]: debug.FatalError("Number of nodes must be a positive integer") try: meshCount = int(args[1]) assert(meshCount >= 0) except [ValueError, AssertionError]: debug.FatalError("Number of meshes must be a positive integer") baseMesh = meshes.Mesh(2) baseMesh.AddNodeCoords(([0.0, 0.0], [1.0, 0.0], [0.0, 1.0], [1.0, 1.0])) baseMesh.AddSurfaceElement(elements.Element([0, 1], ids = [1])) baseMesh.AddSurfaceElement(elements.Element([1, 3], ids = [2])) baseMesh.AddSurfaceElement(elements.Element([3, 2], ids = [3])) baseMesh.AddSurfaceElement(elements.Element([2, 0], ids = [4])) tempDir = tempfile.mkdtemp() for i in range(meshCount): mesh = copy.deepcopy(baseMesh) mesh.AddNodeCoords([[random.random(), random.random()] for j in range(nodeCount)]) polyFilename = os.path.join(tempDir, str(i) + ".poly") polytools.WritePoly(mesh, polyFilename) mesh = polytools.TriangulatePoly(polyFilename, commandLineSwitches = ["-YY"]) gmshtools.WriteMsh(mesh, str(i)) filehandling.Rmdir(tempDir, force = True)
#!/usr/bin/env python import fluidity.diagnostics.annulus_mesh as mesh import fluidity.diagnostics.gmshtools as gt div = mesh.SliceCoordsConstant(0.0, 1.0, 3) m = mesh.GenerateRectangleMesh(div, div) gt.WriteMsh(m, "square-structured-linear.msh")