def refine(self): "refines the mesh" grad = self.grad g = grad[0]**2 + grad[1]**2 + grad[2]**2 g = convert_grad2constrain(g) savevol("%s/t.1.vol"%self.tmp,g) geom.runtetgen("/home/ondra/femgeom/tetgen/tetgen","%s/t.1"%self.tmp, a=0.01,quadratic=True,refine=True) m=geom.read_tetgen("%s/t.2"%self.tmp) m.printinfo() m.writemsh("%s/t12-2.msh"%self.tmp)
def meshit(self): "meshes the geometry in tetgen, " geom.write_tetgen(self.g,"%s/t.poly"%self.tmp) geom.runtetgen("/home/ondra/femgeom/tetgen/tetgen","%s/t.poly"%self.tmp, a=0.1,quadratic=True) m=geom.read_tetgen("%s/t.1"%self.tmp) m.printinfo() m.writemsh("%s/t12.msh"%self.tmp) m.writexda("%s/in.xda"%self.tmp) m.writeBC("%s/t12.boundaries"%self.tmp) self.regions=m.regions self.nele=len(m.elements)
def meshit(self): "meshes the geometry in tetgen, " geom.write_tetgen(self.g, "%s/t.poly" % self.tmp) geom.runtetgen("/home/ondra/femgeom/tetgen/tetgen", "%s/t.poly" % self.tmp, a=0.1, quadratic=True) m = geom.read_tetgen("%s/t.1" % self.tmp) m.printinfo() m.writemsh("%s/t12.msh" % self.tmp) m.writexda("%s/in.xda" % self.tmp) m.writeBC("%s/t12.boundaries" % self.tmp) self.regions = m.regions self.nele = len(m.elements)
def mesh(): meshgeometry="../meshes/t.geo" pexpect.run("gmsh -0 %s -o tmp/x.geo"%(meshgeometry)) g=geom.read_gmsh("../tmp/x.geo") g.printinfo() geom.write_tetgen(g,"../tmp/t.poly") geom.runtetgen("/home/ondra/femgeom/tetgen/tetgen","../tmp/t.poly", a=0.001,Q=0.8) m=geom.read_tetgen("../tmp/t.1") m.printinfo() m.writemsh("../tmp/t12.msh") m.writexda("../tmp/in.xda") m.writeregions("../tmp/t12.regions") m.writeBC("../tmp/t12.boundaries")
def refine(self): "refines the mesh" grad = self.grad g = grad[0]**2 + grad[1]**2 + grad[2]**2 g = convert_grad2constrain(g) savevol("%s/t.1.vol" % self.tmp, g) geom.runtetgen("/home/ondra/femgeom/tetgen/tetgen", "%s/t.1" % self.tmp, a=0.01, quadratic=True, refine=True) m = geom.read_tetgen("%s/t.2" % self.tmp) m.printinfo() m.writemsh("%s/t12-2.msh" % self.tmp)
def mesh(): meshgeometry = "../meshes/t.geo" pexpect.run("gmsh -0 %s -o tmp/x.geo" % (meshgeometry)) g = geom.read_gmsh("../tmp/x.geo") g.printinfo() geom.write_tetgen(g, "../tmp/t.poly") geom.runtetgen("/home/ondra/femgeom/tetgen/tetgen", "../tmp/t.poly", a=0.001, Q=0.8) m = geom.read_tetgen("../tmp/t.1") m.printinfo() m.writemsh("../tmp/t12.msh") m.writexda("../tmp/in.xda") m.writeregions("../tmp/t12.regions") m.writeBC("../tmp/t12.boundaries")
def mesh(): if len( sys.argv ) == 3: geom_filename = sys.argv[1] vtk_filename = sys.argv[2] if len( sys.argv ) == 2: geom_filename = sys.argv[1] vtk_filename = "tmp/t.1.vtk" else: geom_filename = "database/box.geo" vtk_filename = "tmp/t.1.vtk" os.system( "gmsh -0 %s -o tmp/x.geo" % geom_filename ) g=geom.read_gmsh("tmp/x.geo") g.printinfo() geom.write_tetgen(g,"tmp/t.poly") geom.runtetgen("tmp/t.poly",a=0.03,Q=1.0,quadratic=False, tetgenpath = tetgen_path) m = Mesh.from_file("tmp/t.1.node") m.write( vtk_filename, io = "auto" )
def mesh(tipr=0.5, mesha=0.01, meshQ=0.8, verbose=False): s = "".join(open("afm-templ.geo").readlines()) meshgeometry = "../tmp/t.geo" open(meshgeometry, "w").write(s % (tipr)) pexpect.run("gmsh -0 %s -o ../tmp/x.geo" % (meshgeometry)) g = geom.read_gmsh("../tmp/x.geo") if verbose: g.printinfo() geom.write_tetgen(g, "../tmp/t.poly") geom.runtetgen("/home/ondra/femgeom/tetgen/tetgen", "../tmp/t.poly", a=mesha, Q=meshQ, quadratic=True, verbose=verbose) m = geom.read_tetgen("../tmp/t.1", verbose) if verbose: m.printinfo() m.writemsh("../tmp/t12.msh", verbose) m.writexda("../tmp/in.xda", verbose) m.writeBC("../tmp/t12.boundaries", verbose) regions = m.regions nele = len(m.elements) return regions, nele
#! /usr/bin/env python #problem: probably with surface holes, it doesn't work correctly. Also with # arcs - they approximated by lines. import sys sys.path.append("../..") import pexpect import geom pexpect.run("gmsh -0 t.geo -o /tmp/x.geo") g = geom.read_gmsh("/tmp/x.geo") g.printinfo() geom.write_tetgen(g, "/tmp/t.poly") print "Generating mesh using tetgen..." geom.runtetgen("/home/ondra/fzu/mesh/tetgen", "/tmp/t.poly") print "Reading mesh from tetgen..." m = geom.read_tetgen("/tmp/t.1") m.writemsh("/tmp/t12.msh") print "Mesh written to /tmp/t12.msh" m.writexda("/tmp/in.xda") print "Mesh written to /tmp/in.xda" m.writeregions("/tmp/t12.regions") print "Regions written to /tmp/t12.regions" m.writeBC("/tmp/t12.boundaries") print "Boundaries written to /tmp/t12.boundaries"
#! /usr/bin/env python import sys sys.path.append("../..") import pexpect import geom pexpect.run("gmsh -0 t.geo -o /tmp/x.geo") g=geom.read_gmsh("/tmp/x.geo") g.printinfo() geom.write_tetgen(g,"/tmp/t.poly") print "Generating mesh using tetgen..." geom.runtetgen("/home/ondra/fzu/mesh/tetgen","/tmp/t.poly") print "Reading mesh from tetgen..." m=geom.read_tetgen("/tmp/t.1") m.writemsh("/tmp/t12.msh") print "Mesh written to /tmp/t12.msh" m.writexda("/tmp/in.xda") print "Mesh written to /tmp/in.xda" m.writeregions("/tmp/t12.regions") print "Regions written to /tmp/t12.regions" m.writeBC("/tmp/t12.boundaries") print "Boundaries written to /tmp/t12.boundaries"
def main(): version = open( op.join( init_sfepy.install_dir, 'VERSION' ) ).readlines()[0][:-1] parser = OptionParser( usage = usage, version = "%prog " + version ) parser.add_option( "--mesh", action = "store_true", dest = "mesh", default = False, help = help['mesh'] ) parser.add_option( "--2d", action = "store_true", dest = "dim2", default = False, help = help['dim'] ) parser.add_option( "-o", "", metavar = 'filename', action = "store", dest = "output_filename_trunk", default = "mesh", help = help['filename'] ) parser.add_option( "--oscillator", action = "store_true", dest = "oscillator", default = False, help = help['oscillator'] ) parser.add_option( "--well", action = "store_true", dest = "well", default = False, help = help['well'] ) parser.add_option( "--hydrogen", action = "store_true", dest = "hydrogen", default = False, help = help['hydrogen'] ) parser.add_option( "--boron", action = "store_true", dest = "boron", default = False, help = help['boron'] ) parser.add_option( "--dft", action = "store_true", dest = "dft", default = False, help = help['dft'] ) parser.add_option( "-p", "--plot", action = "store_true", dest = "plot", default = False, help = help['plot'] ) options, args = parser.parse_args() if len( args ) == 1: filename_in = args[0]; elif len( args ) == 0: if options.oscillator: dim = MeshIO.any_from_filename("tmp/mesh.vtk").read_dimension() if dim == 2: filename_in = "input/quantum/oscillator2d.py" else: assert_( dim == 3 ) filename_in = "input/quantum/oscillator3d.py" options.dim = dim print "Dimension:", dim elif options.well: dim = MeshIO.any_from_filename("tmp/mesh.vtk").read_dimension() if dim == 2: filename_in = "input/quantum/well2d.py" else: assert_( dim == 3 ) filename_in = "input/quantum/well3d.py" options.dim = dim print "Dimension:", dim elif options.hydrogen: dim = MeshIO.any_from_filename("tmp/mesh.vtk").read_dimension() if dim == 2: filename_in = "input/quantum/hydrogen2d.py" else: assert_( dim == 3 ) filename_in = "input/quantum/hydrogen3d.py" options.dim = dim print "Dimension:", dim elif options.boron: dim = MeshIO.any_from_filename("tmp/mesh.vtk").read_dimension() if dim == 2: filename_in = "input/quantum/boron2d.py" else: assert_( dim == 3 ) filename_in = "input/quantum/boron3d.py" options.dim = dim print "Dimension:", dim elif options.mesh: try: os.makedirs("tmp") except OSError, e: if e.errno != 17: # [Errno 17] File exists raise if options.dim2: print "Dimension: 2" os.system("cp database/quantum/square.geo tmp/mesh.geo") os.system("gmsh -2 tmp/mesh.geo -format mesh") os.system("script/mesh_to_vtk.py tmp/mesh.mesh tmp/mesh.vtk") else: print "Dimension: 3" import geom from sfepy.fem.mesh import Mesh try: from site_cfg import tetgen_path except ImportError: tetgen_path = '/usr/bin/tetgen' os.system("gmsh -0 database/box.geo -o tmp/x.geo") g = geom.read_gmsh("tmp/x.geo") g.printinfo() geom.write_tetgen(g, "tmp/t.poly") geom.runtetgen("tmp/t.poly", a=0.03, Q=1.0, quadratic=False, tetgenpath=tetgen_path) m = Mesh.from_file("tmp/t.1.node") m.write("tmp/mesh.vtk", io="auto") print "Mesh written to tmp/mesh.vtk" return elif options.dft: dim = MeshIO.any_from_filename("tmp/mesh.vtk").read_dimension() if dim == 2: filename_in = "input/quantum/dft2d.py" else: assert_( dim == 3 ) filename_in = "input/quantum/dft3d.py" print "Dimension:", dim options.dim = dim else: parser.print_help() return