Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import gmsh
- import sys
- gmsh.initialize()
- gmsh.model.add("mover")
- def four_square_mag(height, offset):
- volumes = {
- "magnet-N": [
- gmsh.model.occ.addBox(0, 0, 0, offset, offset, height),
- gmsh.model.occ.addBox(0, 0, 0, -offset, -offset, height),
- ],
- "magnet-S": [
- gmsh.model.occ.addBox(0, 0, 0, -offset, offset, height),
- gmsh.model.occ.addBox(0, 0, 0, offset, -offset, height),
- ]
- }
- return volumes
- def add_iron(base, offset, height, radius):
- base["iron"] = [
- gmsh.model.occ.add_cylinder(0, 0, offset, 0, 0, height, radius),
- ]
- return base
- # We can log all messages for further processing with:
- gmsh.logger.start()
- # air volume
- air_orig = gmsh.model.occ.addSphere(0, 0, 0, 100)
- volumes = four_square_mag(3, 12.5)
- #add a back iron
- volumes = add_iron(volumes, 3, 3, 30.1776/2)
- all_vols = []
- for name, tags in volumes.items():
- all_vols += [(3, x) for x in tags]
- # use fragment to stich it all together
- ov, ovv = gmsh.model.occ.fragment([(3, air_orig)], all_vols)
- gmsh.model.occ.synchronize()
- # assign physical groups using dictionary
- for name, tags in volumes.items():
- gmsh.model.addPhysicalGroup(3, tags, name=name)
- # air phys group
- gmsh.model.addPhysicalGroup(3, [ov[-1][1]], name="air")
- #mesh size for air
- gmsh.model.mesh.setSize(gmsh.model.getBoundary([(3, ov[-1][1])], False, False, True),
- 10)
- #mesh size for inner objects
- gmsh.model.mesh.setSize(gmsh.model.getBoundary(all_vols, False, False, True),
- 0.5)
- # gmsh.option.setNumber("Mesh.MeshSizeFromCurvature", 120)
- gmsh.model.mesh.generate(3)
- gmsh.write("mover.msh")
- # Inspect the log:
- log = gmsh.logger.get()
- print("Logger has recorded " + str(len(log)) + " lines")
- gmsh.logger.stop()
- # Launch the GUI to see the results:
- if '-nopopup' not in sys.argv:
- gmsh.fltk.run()
- gmsh.finalize()
Advertisement
Add Comment
Please, Sign In to add comment