import nmesh large = nmesh.box( [-4,-4], [4,4] ) small = nmesh.box( [-2,-2], [2,2] ) diff = nmesh.difference(large,[small]) bbox=[[-4,-4],[4,4]] mesh = nmesh.mesh(bounding_box=bbox, objects = [diff] ) nmesh.visual.plot2d_ps( mesh, "fixedpoints_faulty.ps") #can provide some 'fixed points' to avoid round corners fixed_points = [[-2,-2],[2,-2],[-2,2],[2,2]] mesh = nmesh.mesh(bounding_box=bbox, objects = [diff], fixed_points=fixed_points ) nmesh.visual.plot2d_ps( mesh, "fixedpoints.ps")
import nmesh # rotation of the object is performed # around the [0,0,1] axis (z-axis). box = nmesh.box([0, 0, 0], [2, 1, 1], transform=[("rotate", [0, 1], 0)]) bbox = [[-1, -1, -1], [3, 3, 3]] mesh = nmesh.mesh(objects=[box], bounding_box=bbox, mesh_bounding_box=False, a0=0.5) mesh.save('rotate.nmesh') #create 3d-plot of surfaces and export eps vis = nmesh.visual.show_bodies_mayavi(mesh) nmesh.visual.export_visualisation(vis, "rotate.eps")
mat_Fe = mag.MagMaterial("Fe", Ms=1.2, A=4.0, extra_H="""H_total_Fe(0) -= mag[0]*1.2; if(X(0)<0.01 || X(0)>2.99) /* pin the M field at boundaries */ { H_total_Fe(0)=0.0; H_total_Fe(1)=0.0; H_total_Fe(2)=0.0; } """) mag.set_local_magnetic_coupling(mat_Dy, mat_Fe, -80.0) mag.defregion("DyFe2", nm.box([1.0], [2.0]), mag_mat=[mat_Dy, mat_Fe]) mag.defregion( "YFe2", nm.union([nm.box([0.0], [1.0]), nm.box([2.0], [3.0])]), mag_mat=mat_Fe # can pass either a material or a list of materials ) mag.set_meshing_parameters( cache_name="exchange-spring-mesh", bounding_box=([-1.0], [5.0]), a0=0.25, max_steps=100, ) mag.create_mesh()
import nmesh x = nmesh.box( [0,0],[5,5], transform=[("rotate2d",30)]) bbox = [[-10,-10],[10,10]] mesh = nmesh.mesh(objects=[x],bounding_box=bbox,mesh_bounding_box=True) nmesh.visual.plot2d_ps(mesh,"rotate2d.ps")
from __future__ import division import nmesh, pylab, timing, Numeric #create objects box = nmesh.box([-2.0, 6.0], [2.0, 7.0]) ellipsoid = nmesh.ellipsoid([1.5, 1.5]) #create bounding box bbox = ([-3., -3.], [3., 9.]) #fixed points *to fix points uncomment line below* fix = ([-2.0, 6.0], [2.0, 7.0], [-2.0, 7.0], [2.0, 6.0], [-3., -3], [-3., 9.], [3., 9.], [3., -3.]) #density density = "density=1.0;" force = [0, 1, 2, 5, 7, 10, 20, 50, 70, 100] for e in force: shape_force = e / 100.0 neigh_force = 1. - shape_force #create empty string time = [] nodes = [] average_quality = [] #create quality stacks to plot later stack1 = [] stack2 = [] stack3 = []
# Simulation parameters sigma0 = 1.0 print """ ** Example: meshing half ring and compute current density for contacts at either side. This is for possible collaboration with Uni Hamburg. ** """ ##### Creating the mesh ##### ring = nmesh.difference( nmesh.ellipsoid([4.0, 4.0]), [nmesh.ellipsoid([2.5, 2.5])]) halfring = nmesh.intersect([ring, nmesh.box([-4.0, -0.0], [4.0, 4.0])]) the_mesh = nmesh.mesh( objects=[halfring], cache_name="halfring", a0=0.2, bounding_box=[[-4.0, -4], [4.0, 4.0]], neigh_force_scale=1., initial_settling_steps=50, max_relaxation=4, max_steps=400) nfem.set_default_mesh(the_mesh) the_mesh.save("themesh.nmesh")
import nmesh box = nmesh.box( [-4,-2],[4,2] ) ellipsoid = nmesh.ellipsoid([3,3]) # create union union = nmesh.union([box,ellipsoid]) bbox = [[-5,-4],[5,4]] mesh = nmesh.mesh(objects = [union],bounding_box=bbox) mesh.save("union.nmesh") nmesh.visual.plot2d_ps(mesh,"union.ps")
import nmesh squares = [] for i in range(4): xshift = i * 6 yshift = 0 squares.append( nmesh.box([-2, -2], [2, 2], transform=[("shift", [xshift, yshift])])) bbox = [[-5, -5], [23, 5]] mesh = nmesh.mesh(objects=squares, bounding_box=bbox) # plot mesh nmesh.visual.plot2d_ps(mesh, "shift.ps")
import nmesh box1 = nmesh.box( [0.0,0.0],[3.0,3.0] ) box2 = nmesh.box( [-1.0,-1.0],[-3.0,-3.0] ) circle = nmesh.ellipsoid(length=[1.5,1.5],transform=[("shift",[-2.,2.])]) bbox = [[-4,-4],[4,4]] #define call back function def my_fun(piece_nr, iteration_nr, mesh_info): print "** In callback function: Piece %d, Step %d \n" % \ (piece_nr, iteration_nr) print "Points = %d\nSimplices = %d\nSurface elements = %d\n" % \ (len(mesh_info[0][2]),len(mesh_info[2][2]),len(mesh_info[4][2])) #Call callback function every 5 iterations mesh = nmesh.mesh(objects = [box1,box2,circle], bounding_box=bbox, \ a0=0.5, callback = (my_fun,5)) nmesh.visual.plot2d_ps(mesh,"callback.ps")
rod = 0.30 outer_radius = 5.45 inner_radius = 3.30 centres_distance = 10 thickness = 1 # thickness of the sample eps = 1e-6 half_bbox_dimx = 5.00 half_bbox_dimy = 5.00 half_voltage_probe_dimx = centres_distance+outer_radius half_voltage_probe_dimy = 100 rings_box = nmesh.box([-5.00, -5.00], [5.00,5.00]) bbox = [[-half_bbox_dimx,-half_bbox_dimy],[half_bbox_dimx,half_bbox_dimy]] fix_pts = [] rings = [] voltage_probes = [] for x in range(-1,2): for y in range(-1,2): # external ring R = nmesh.ellipsoid( [outer_radius, outer_radius], transform=[("shift",[x*centres_distance, y*centres_distance])] )
import nmesh # create sections of a square ring bottom = nmesh.box( [2.0,1.0], [4.0,2.0]) right = nmesh.box( [4.0,1.0], [5.0,3.0]) top = nmesh.box( [3.0,3.0], [5.0,4.0]) left = nmesh.box( [2.0,2.0], [3.0,4.0]) # create compound square_ring = nmesh.union([bottom,right,top,left]) rod= 0.4 bbox = [[-1.,-1.],[7.,6.]] fixed_points = [[3.0,2.0],[4.0,2.0,],[3.0,3.0],[4.0,3.0]] # create mesh mesh_ex = nmesh.mesh(objects = [square_ring], a0=rod, bounding_box=bbox, \ fixed_points=fixed_points, topology_threshold=0.2, # change the threshold # for re-triangulation # during mesh relaxation time_step_scale=0.1, # change the factor which # controls the time step # used to relax the mesh tolerated_rel_move=0.002,# change the threshold to # stop the mesh relaxation
Authors: James Kenny Last modified: $Date$ Version: $Id$ """ import nmesh, pylab, Numeric # create cone #cone = nmesh.conic([3.0,0.0,0.0],1.0,[3.0,0.1,0.0],0.0) #box = nmesh.box( [0.0,0.0,0.0], [1.0,1.0,1.0], transform=[("rotate3d",[1.,1.,1.],30), \ # ("shift",[3.0,3.0,3.0])] ) #rod= 0.4 #bbox = [[-1.,-1.,-1.],[7.,6.,6.]] box1 = nmesh.box( [2,2,2],[3,3,3], transform=[("rotate3d",[-1,-1,-1],50)]) box2 = nmesh.box( [0,0,0],[1,1,1], transform=[("rotate3d",[-1,-1,-1],-30), \ ("shift",[-2,-3,-2])] ) ground = nmesh.box( [-5,-5,-0.3],[5,5,0.3] ) bbox = [[-5,-5,-5],[5,5,5]] rod = 0.5 # Set up a MayaVi window ready for use during mesher 'pauses'. # The sys.argv hack is only required when MayaVi is used in # a 'callback' function as below, it is not needed in static mode. import mayavi, sys sys.argv=["",""] # define a few globals, so that the interval function can use them globals()['v'] = mayavi.mayavi() globals()['intervals'] = Numeric.arange(0,1.05,0.05)
import nmesh x = nmesh.box( [0,0],[1,1], transform=[("scale",[10,2])]) bbox = [[-2,-2],[12,4]] mesh = nmesh.mesh(objects=[x],bounding_box=bbox) nmesh.visual.plot2d_ps(mesh,"scale.ps")
rod = 0.50 outer_radius = 5.50 inner_radius = 3.25 centres_distance = 10 thickness = 1 # thickness of the sample eps = 1e-6 half_bbox_dimx = 17 half_bbox_dimy = 15 half_voltage_probe_dimx = centres_distance+outer_radius half_voltage_probe_dimy = 100 rings_box = nmesh.box([-17, -15], [17,15]) bbox = [[-half_bbox_dimx,-half_bbox_dimy],[half_bbox_dimx,half_bbox_dimy]] fix_pts = [] rings = [] voltage_probes = [] for x in range(-1,2): for y in range(-1,2): # external ring R = nmesh.ellipsoid( [outer_radius, outer_radius], transform=[("shift",[x*centres_distance, y*centres_distance])] )
import nmesh P1 = [0, 0] #one corner of box P2 = [5, 10] #other corner box = nmesh.box(P1, P2) bbox = [[0, 0], [5, 10]] mesh = nmesh.mesh(bounding_box=bbox, objects=[box]) nmesh.visual.plot2d_ps(mesh, "box.ps")
rod = 0.30 outer_radius = 5.45 inner_radius = 3.30 centres_distance = 10 thickness = 1 # thickness of the sample eps = 1e-6 half_bbox_dimx = 16.95 half_bbox_dimy = 14.95 half_voltage_probe_dimx = centres_distance+outer_radius half_voltage_probe_dimy = 100 rings_box = nmesh.box([-16.95, -14.95], [16.95,14.95]) bbox = [[-half_bbox_dimx,-half_bbox_dimy],[half_bbox_dimx,half_bbox_dimy]] fix_pts = [] rings = [] voltage_probes = [] for x in range(-1,2): for y in range(-1,2): # external ring R = nmesh.ellipsoid( [outer_radius, outer_radius], transform=[("shift",[x*centres_distance, y*centres_distance])] )
import nmesh a = 2.3 P1 = [0, 0, 0] #one corner of box P2 = [a, a, a] #other corner box = nmesh.box(P1, P2, use_fixed_corner_points=True) bbox = [[0, 0, 0], [a, a, a]] mesh = nmesh.mesh(bounding_box=bbox, objects=[box]) mv = nmesh.visual.show_bodies_mayavi(mesh) nmesh.visual.export_visualisation(mv, 'box_with_fixed_corner_points.eps')
import nfem, nmesh, math, sys nfem.set_default_dimension(3) nfem.set_default_order(1) bar = nmesh.box([-5.0,-2.0,-2.0],[5.0,2.0,2.0]) the_mesh = nmesh.mesh(objects = [bar], cache_name="bar-mesh3", a0=0.7, bounding_box=[[-6.0,-3.0,-3.0],[6.0,3.0,3.0]], neigh_force_scale = 1., # density = density, initial_settling_steps = 50, max_relaxation = 4, # callback=(my_function, N), # max_steps=677 max_steps=500 ) nfem.set_default_mesh(the_mesh) element_M = nfem.make_element("M",[3]) element_H = nfem.make_element("H",[3]) mwe_M = nfem.make_mwe("mwe_M", [(1,element_M)]) mwe_H = nfem.make_mwe("mwe_H", [(1,element_H)])
trasl = [0,5.,0] # external ring R = nmesh.conic( [0.0,0.0,-thickness], outer_radius, [0.0,0.0,thickness], outer_radius, \ transform=[("shift",trasl)] ) #internal ring r = nmesh.conic( [0.0,0.0,-thickness], inner_radius, [0.0,0.0,thickness], inner_radius, \ transform=[("shift",trasl)], ) # take the difference ring = nmesh.difference(R,[r]) box = nmesh.box([-10,0,-thickness/2.],[10,10,thickness/2.]) system = nmesh.intersect([ring, box]) density = """density = 1.;""" N = 50 # create mesh of three objects and bounding box mesh_ex = nmesh.mesh(objects = [system], a0=rod, bounding_box=bbox, density = density, # with these values there is # a bit more pressure than with
""" ##### Creating the mesh ##### # For now, we use a very very simple mesh... rings = nmesh.union([nmesh.difference(nmesh.ellipsoid([3.0,3.0], transform=[("shift",[-2.5,0.0])]), [nmesh.ellipsoid([1.5,1.5], transform=[("shift",[-2.5,0.0])])]), nmesh.difference(nmesh.ellipsoid([3.0,3.0], transform=[("shift",[2.5,0.0])]), [nmesh.ellipsoid([1.5,1.5], transform=[("shift",[2.5,0.0])])])]) boxed_rings=nmesh.intersect([rings,nmesh.box([-8.0,-2.5],[8.0,2.5])]) N = 100 density = "density=1.;" the_mesh = nmesh.mesh(objects = [boxed_rings], cache_name="rings-mesh", a0=0.3, bounding_box=[[-10.0,-3.5],[10.0,3.5]], neigh_force_scale = 1., density = density, initial_settling_steps = 50, max_relaxation = 4, # callback=(my_function, N), # max_steps=677 max_steps=200
rod = 0.30 outer_radius = 5.45 inner_radius = 3.30 centres_distance = 10 thickness = 1 # thickness of the sample eps = 1e-6 half_bbox_dimx = 16.95 half_bbox_dimy = 14.95 half_voltage_probe_dimx = centres_distance + outer_radius half_voltage_probe_dimy = 100 rings_box = nmesh.box([-16.95, -14.95], [16.95, 14.95]) bbox = [[-half_bbox_dimx, -half_bbox_dimy], [half_bbox_dimx, half_bbox_dimy]] fix_pts = [] rings = [] voltage_probes = [] for x in range(-1, 2): for y in range(-1, 2): # external ring R = nmesh.ellipsoid([outer_radius, outer_radius], transform=[ ("shift", [x * centres_distance, y * centres_distance])
from __future__ import division import nmesh, pylab, timing #create objects box = nmesh.box([-2.0,6.0],[2.0,7.0]) ellipsoid = nmesh.ellipsoid ([1.5,1.5]) #create bounding box bbox =([-3.,-3.],[3.,9.]) #fixed points *to fix points uncomment line below* fix =([-2.0,6.0],[2.0,7.0],[-2.0,7.0],[2.0,6.0], [-3.,-3],[-3.,9.],[3.,9.],[3.,-3.]) #density density = "density=1.0;" #create empty string time = [] nodes = [] average_quality=[] shape=[1] for shape_elem in shape: #create quality stacks to plot later stack1=[] stack2=[] stack3=[]
"""Simple visualisation of a 3D mesh. Author: James Kenny Last modified: $Date$ """ import nmesh import nmesh.visual as viz # define a simple mesh and submit request to mesher box = nmesh.box([3.0, 0.0, 0.0], [4.0, 1.0, 1.0]) cone = nmesh.conic([0.0, 0.0, 0.0], 0.0, [2.0, 0.0, 0.0], 2.0) bbox = [[-4., -4., -4.0], [4., 4., 4.]] mesh = nmesh.mesh(objects=[box, cone], bounding_box=bbox) mesh_info = mesh.tolists() # visualise in MayaVi, using the ratio of inradius:circumradius # as cell_data for a colour scale v = viz.solid_in2circ(mesh_info, order=1)
visualises direct from RAM. This is more suitable for fast machines when a small interval is being used. (ie N < 20) No .PNG images are saved. Pylab plots have been coded, but commented out, as have the waiting commands. On a fast machine this example should display a fluid mesh generation. Authors: James Kenny Last modified: $Date$ Version: $Id$ """ import nmesh, pylab, Numeric # create square box = nmesh.box([0.0, 0.0], [1.0, 1.0]) # create cone cone = nmesh.conic([3.0, 0.0], 1.0, [3.0, 4.0], 0.0) rod = 0.4 bbox = [[-1., -1.], [7., 6.]] # Set up a MayaVi window ready for use during mesher 'pauses'. # The sys.argv hack is only required when MayaVi is used in # a 'callback' function as below, it is not needed in static mode. import mayavi, sys sys.argv = ["", ""] # define a few globals, so that the interval function can use them globals()['v'] = mayavi.mayavi() globals()['intervals'] = Numeric.arange(0, 1.05, 0.05) globals()['call_counter'] = 0
mat_Fe = mag.MagMaterial("Fe",Ms=1.2,A=4.0, extra_H="""H_total_Fe(0) -= mag[0]*1.2; if(X(0)<0.01 || X(0)>3.99) /* pin the M field at boundaries */ { H_total_Fe(0)=0.0; H_total_Fe(1)=0.0; H_total_Fe(2)=0.0; } """ ) mag.set_local_magnetic_coupling(mat_Dy,mat_Fe,-80.0) mag.defregion("DyFe2",nm.union([nm.box([0.0],[0.5]), nm.box([1.5],[2.5]), nm.box([3.5],[4.0])]), mag_mat=[mat_Dy,mat_Fe] ) mag.defregion("YFe2", nm.union([nm.box([0.5],[1.5]), nm.box([2.5],[3.5])]), mag_mat=mat_Fe # can pass either a material or a list of materials ) mag.set_meshing_parameters(cache_name="exchange-spring-mesh", bounding_box=([-1.0],[5.0]), a0=0.1, max_steps=100,
# Simulation parameters sigma0=1.0 print """ ** Example: meshing half ring and compute current density for contacts at either side. This is for possible collaboration with Uni Hamburg. ** """ ##### Creating the mesh ##### ring = nmesh.difference(nmesh.ellipsoid([4.0,4.0]),[nmesh.ellipsoid([2.5,2.5])]) halfring=nmesh.intersect([ring,nmesh.box([-4.0,-0.0],[4.0,4.0])]) the_mesh = nmesh.mesh(objects = [halfring], cache_name="halfring", a0=0.2, bounding_box=[[-4.0,-4],[4.0,4.0]], neigh_force_scale = 1., initial_settling_steps = 50, max_relaxation = 4, max_steps=400 ) nfem.set_default_mesh(the_mesh) the_mesh.save("themesh.nmesh")
import nmesh ellipsoid = nmesh.ellipsoid([1.25,0.5]) bbox = [[-1.25,-0.75],[10.25,0.75]] #create a mesh to be saved and then reloaded with another name mesh2save = nmesh.mesh(objects = [ellipsoid] ,bounding_box=bbox,a0=0.2) # save the mesh mesh2save.save("saved4hint.nmesh") # reload the mesh with another name loaded_mesh=nmesh.load("saved4hint.nmesh") # define a new object square = nmesh.box([-1.25,-0.75],[1.25,0.75], transform=[("shift",[5.0,0.0])]) # first we create a mesh out of the simplices of the loaded mesh which satisfy the # boundary conditions related to the ellipsoid object. If we # define some other object, the mesher will triangulate only the # simplices of the loaded mesh which are within the new boundary conditions. # the square is meshed after all the loaded_objects are meshed mesh2 = nmesh.mesh(objects = [square], hints=[(loaded_mesh,ellipsoid)] ,bounding_box=bbox,a0=0.2) mesh2.save("hint.nmesh")
import nmesh, Numeric rod = 10. edge = 100 import math bbox = [[-edge, -edge], [edge, edge]] # box box = nmesh.box([-edge, -edge], [edge, edge]) density = """density = 1.;""" N = 10 # create mesh of three objects and bounding box mesh_ex = nmesh.mesh( objects=[box], a0=rod, bounding_box=bbox, density=density, ) mesh_ex.save("test-demag-2d.nmesh")
import nmesh ellipsoid = nmesh.ellipsoid([1.25, 0.5]) bbox = [[-1.25, -0.75], [10.25, 0.75]] #create a mesh to be saved and then reloaded with another name mesh2save = nmesh.mesh(objects=[ellipsoid], bounding_box=bbox, a0=0.2) # save the mesh mesh2save.save("saved4hint.nmesh") # reload the mesh with another name loaded_mesh = nmesh.load("saved4hint.nmesh") # define a new object square = nmesh.box([-1.25, -0.75], [1.25, 0.75], transform=[("shift", [5.0, 0.0])]) # first we create a mesh out of the simplices of the loaded mesh which satisfy the # boundary conditions related to the ellipsoid object. If we # define some other object, the mesher will triangulate only the # simplices of the loaded mesh which are within the new boundary conditions. # the square is meshed after all the loaded_objects are meshed mesh2 = nmesh.mesh(objects=[square], hints=[(loaded_mesh, ellipsoid)], bounding_box=bbox, a0=0.2) mesh2.save("hint.nmesh")
layer_thick = thickness/float(nr_layers) for node in coord_nodes: x, y = node for i in range(nr_layers+1): layer_heigth = -thickness/2. + layer_thick*i mobile_pts.append([x, y, layer_heigth]) bbox = [[-edge,-edge,-thickness/2.],[edge,edge,thickness/2.]] # box box = nmesh.box([-edge,-edge,-thickness/2.],[edge,edge,thickness/2.]) density = """density = 1.;""" # create mesh of three objects and bounding box mesh_ex = nmesh.mesh(objects = [box], cache_name = "", a0=rod, mobile_points = mobile_pts, bounding_box=bbox, density = density, neigh_force_scale = 0.0, shape_force_scale = 0.0, max_steps = 1 ) mesh_ex.save("box-2d-to-3d.nmesh")
rod = 0.30 outer_radius = 5.45 inner_radius = 3.30 centres_distance = 10 thickness = 1 # thickness of the sample eps = 1e-6 half_bbox_dimx = 5.00 half_bbox_dimy = 5.00 half_voltage_probe_dimx = centres_distance + outer_radius half_voltage_probe_dimy = 100 rings_box = nmesh.box([-5.00, -5.00], [5.00, 5.00]) bbox = [[-half_bbox_dimx, -half_bbox_dimy], [half_bbox_dimx, half_bbox_dimy]] fix_pts = [] rings = [] voltage_probes = [] for x in range(-1, 2): for y in range(-1, 2): # external ring R = nmesh.ellipsoid([outer_radius, outer_radius], transform=[ ("shift", [x * centres_distance, y * centres_distance])
nr_layers = 1 layer_thick = thickness / float(nr_layers) for node in coord_nodes: x, y = node for i in range(nr_layers + 1): layer_heigth = -thickness / 2. + layer_thick * i mobile_pts.append([x, y, layer_heigth]) bbox = [[-edge, -edge, -thickness / 2.], [edge, edge, thickness / 2.]] # box box = nmesh.box([-edge, -edge, -thickness / 2.], [edge, edge, thickness / 2.]) density = """density = 1.;""" # create mesh of three objects and bounding box mesh_ex = nmesh.mesh(objects=[box], cache_name="", a0=rod, mobile_points=mobile_pts, bounding_box=bbox, density=density, neigh_force_scale=0.0, shape_force_scale=0.0, max_steps=1) mesh_ex.save("box-2d-to-3d.nmesh")
import nmesh, Numeric rod = 10. edge = 100 import math bbox = [[-edge,-edge],[edge,edge]] # box box = nmesh.box([-edge,-edge],[edge,edge]) density = """density = 1.;""" N = 10 # create mesh of three objects and bounding box mesh_ex = nmesh.mesh(objects = [box], a0=rod, bounding_box=bbox, density = density, ) mesh_ex.save("test-demag-2d.nmesh")
import nmesh # rotation of the object is performed # around the [0,0,1] axis (z-axis). box = nmesh.box( [0,0,0],[2,1,1], transform=[("rotate",[0,1],0)]) bbox = [[-1,-1,-1],[3,3,3]] mesh = nmesh.mesh(objects=[box],bounding_box=bbox,mesh_bounding_box=False,a0=0.5) mesh.save('rotate.nmesh') #create 3d-plot of surfaces and export eps vis=nmesh.visual.show_bodies_mayavi(mesh) nmesh.visual.export_visualisation(vis,"rotate.eps")
import nmesh squares = [] for i in range(4): xshift = i*6 yshift = 0 squares.append( nmesh.box( [-2,-2],[2,2], transform=[("shift",[xshift,yshift])] ) ) bbox = [[-5,-5],[23,5]] mesh = nmesh.mesh(objects=squares,bounding_box=bbox) # plot mesh nmesh.visual.plot2d_ps(mesh,"shift.ps")
import nmesh # create a number of objects one = nmesh.ellipsoid([3.0,3.0]) two = nmesh.ellipsoid([3.0,3.0],transform=[("shift",[7,0])]) three=nmesh.box( [-4.0,-6], [10,-4] ) bbox = [[-5.,-8.],[11.,5.]] # create mesh of three objects and bounding box mesh_ex = nmesh.mesh(objects = [one,two,three], bounding_box=bbox, mesh_bounding_box=True) # plot mesh nmesh.visual.plot2d_ps(mesh_ex,"multiobjects.ps")
import nmesh box = nmesh.box([-4, -2], [4, 2]) ellipsoid = nmesh.ellipsoid([3, 3]) # create union union = nmesh.union([box, ellipsoid]) bbox = [[-5, -4], [5, 4]] mesh = nmesh.mesh(objects=[union], bounding_box=bbox) mesh.save("union.nmesh") nmesh.visual.plot2d_ps(mesh, "union.ps")
import nfem, nmesh, math, sys nfem.set_default_dimension(3) nfem.set_default_order(1) bar = nmesh.box([-5.0, -2.0, -2.0], [5.0, 2.0, 2.0]) the_mesh = nmesh.mesh( objects=[bar], cache_name="bar-mesh3", a0=0.7, bounding_box=[[-6.0, -3.0, -3.0], [6.0, 3.0, 3.0]], neigh_force_scale=1., # density = density, initial_settling_steps=50, max_relaxation=4, # callback=(my_function, N), # max_steps=677 max_steps=500) nfem.set_default_mesh(the_mesh) element_M = nfem.make_element("M", [3]) element_H = nfem.make_element("H", [3]) mwe_M = nfem.make_mwe("mwe_M", [(1, element_M)]) mwe_H = nfem.make_mwe("mwe_H", [(1, element_H)]) diffop_v_laplace = nfem.diffop("-<d/dxj H(k) || d/dxj M(k)>, j:3, k:3")
"""Simple visualisation of a 3D mesh. Author: James Kenny Last modified: $Date$ """ import nmesh import nmesh.visual as viz # define a simple mesh and submit request to mesher box=nmesh.box( [3.0,0.0,0.0], [4.0,1.0,1.0] ) cone = nmesh.conic([0.0,0.0,0.0],0.0,[2.0,0.0,0.0],2.0) bbox = [[-4.,-4.,-4.0],[4.,4.,4.]] mesh = nmesh.mesh(objects = [box,cone], bounding_box=bbox) mesh_info=mesh.tolists() # visualise in MayaVi, using the ratio of inradius:circumradius # as cell_data for a colour scale v = viz.solid_in2circ(mesh_info, order=1)
import nmesh box1 = nmesh.box([0.0, 0.0], [3.0, 3.0]) box2 = nmesh.box([-1.0, -1.0], [-3.0, -3.0]) circle = nmesh.ellipsoid(length=[1.5, 1.5], transform=[("shift", [-2., 2.])]) bbox = [[-4, -4], [4, 4]] #define call back function def my_fun(piece_nr, iteration_nr, mesh_info): print "** In callback function: Piece %d, Step %d \n" % \ (piece_nr, iteration_nr) print "Points = %d\nSimplices = %d\nSurface elements = %d\n" % \ (len(mesh_info[0][2]),len(mesh_info[2][2]),len(mesh_info[4][2])) #Call callback function every 5 iterations mesh = nmesh.mesh(objects = [box1,box2,circle], bounding_box=bbox, \ a0=0.5, callback = (my_fun,5)) nmesh.visual.plot2d_ps(mesh, "callback.ps")
import nmesh box1 = nmesh.box( [-1,-1,2],[1,1,4], \ transform=[("connectionbug",[0,0,1],45)]) ground = nmesh.box( [-1,-1,-0.3],[1,1,2] ) bbox = [[-2,-2,-0.3],[2,2,4]] mesh = nmesh.mesh(objects=[ground,box1],bounding_box=bbox,a0=0.5) mesh.save("connectionbug.nmesh") # visualise in MayaVi vis =nmesh.visual.show_bodies_mayavi(mesh) nmesh.visual.export_visualisation(vis,"connectionbug.eps")
import nmesh box = nmesh.box([0.0,0.0], [1.0,1.0], \ transform=[("rotate2d",45), \ ("shift",[-1.0,-2.0]), \ ("scale",[1.5,1.5])]) # create ellipsoid ell = nmesh.ellipsoid([1.0,2.0], \ transform=[("rotate2d",45), \ ("shift",[1.0,1.0]),]) rod = 0.5 bbox = [[-3., -3.], [4., 4.]] # create mesh mesh = nmesh.mesh(objects=[box, ell], a0=rod, bounding_box=bbox) # plot mesh nmesh.visual.plot2d_ps(mesh, "transformations.ps")
import nmesh a=2.3 P1 = [0,0,0] #one corner of box P2 = [a,a,a]#other corner box = nmesh.box( P1,P2, use_fixed_corner_points=True) bbox = [[0,0,0],[a,a,a]] mesh = nmesh.mesh(bounding_box=bbox, objects=[box]) mv=nmesh.visual.show_bodies_mayavi( mesh ) nmesh.visual.export_visualisation(mv,'box_with_fixed_corner_points.eps')
mat_Fe = mag.MagMaterial("Fe",Ms=1.2,A=4.0, extra_H="""H_total_Fe(0) -= mag[0]*1.2; if(X(0)<0.01 || X(0)>2.99) /* pin the M field at boundaries */ { H_total_Fe(0)=0.0; H_total_Fe(1)=0.0; H_total_Fe(2)=0.0; } """ ) mag.set_local_magnetic_coupling(mat_Dy,mat_Fe,-80.0) mag.defregion("DyFe2",nm.box([1.0],[2.0]), mag_mat=[mat_Dy,mat_Fe] ) mag.defregion("YFe2", nm.union([nm.box([0.0],[1.0]),nm.box([2.0],[3.0])]), mag_mat=mat_Fe # can pass either a material or a list of materials ) mag.set_meshing_parameters(cache_name="exchange-spring-mesh", bounding_box=([-1.0],[5.0]), a0=0.25, max_steps=100, ) mag.create_mesh()
Ms=1.2, A=4.0, extra_H="""H_total_Fe(0) -= mag[0]*1.2; if(X(0)<0.01 || X(0)>3.99) /* pin the M field at boundaries */ { H_total_Fe(0)=0.0; H_total_Fe(1)=0.0; H_total_Fe(2)=0.0; } """) mag.set_local_magnetic_coupling(mat_Dy, mat_Fe, -80.0) mag.defregion("DyFe2", nm.union([ nm.box([0.0], [0.5]), nm.box([1.5], [2.5]), nm.box([3.5], [4.0]) ]), mag_mat=[mat_Dy, mat_Fe]) mag.defregion( "YFe2", nm.union([nm.box([0.5], [1.5]), nm.box([2.5], [3.5])]), mag_mat=mat_Fe # can pass either a material or a list of materials ) mag.set_meshing_parameters( cache_name="exchange-spring-mesh", bounding_box=([-1.0], [5.0]), a0=0.1,
"""This script demonstrates the function 'separate_parts()' compounded with 'outer_skin()'. In the first dataset displayed a triangle and square are present. In the second dataset the square has been removed. Author: James Kenny Last modified: $Date$ """ import nmesh import nmesh.visual as viz # define a simple mesh and submit request to mesher box=nmesh.box( [0.0,0.0], [1.0,1.0] ) cone = nmesh.conic([3.0,0.0],1.0,[3.0,4.0],0.0) bbox = [[-1.,-1.],[7.,6.]] mesh = nmesh.mesh(objects = [box,cone],a0=0.4, bounding_box=bbox) mesh_info=mesh.tolists() # create mesh_info lists for parts 1&2 combined and for part 2 alone [mesh_info1, mesh_info2] = viz.separate_parts(mesh_info, listOfParts=[[1,2],[2]]) # generate a VTK dataset for parts 1&2 combined vtkData, points, simplices,indices, icradii, ccradii = \ viz.mesh2vtk(mesh_info1, VTKonly=False) in2circ=viz.findRatios(icradii, ccradii, factor=2) vtkData=viz.append2vtk(vtkData, in2circ, "in2circ") vtkData=viz.append2vtk(vtkData, indices, "part indices")
import nmesh x = nmesh.box([0, 0], [5, 5], transform=[("rotate2d", 30)]) bbox = [[-10, -10], [10, 10]] mesh = nmesh.mesh(objects=[x], bounding_box=bbox, mesh_bounding_box=True) nmesh.visual.plot2d_ps(mesh, "rotate2d.ps")
import nmesh box1 = nmesh.box( [-1,-1,2],[1,1,4], \ transform=[("rotate3d",[0,0,1],45)]) ground = nmesh.box( [-1,-1,-0.3],[1,1,1] ) bbox = [[-2,-2,-0.3],[2,2,4]] mesh = nmesh.mesh(objects=[ground,box1],bounding_box=bbox,a0=0.5) mesh.save("rotate3d.nmesh") # visualise in MayaVi vis =nmesh.visual.show_bodies_mayavi(mesh) nmesh.visual.export_visualisation(vis,"rotate3d.eps")
import nmesh cube1 = nmesh.box([-0., -0., -0.], [1.0, 1.0, 1.0]) cube2 = nmesh.box([1., -0., -0.], [2.0, 1.0, 1.0]) simply_points = [ [0., 0., 0.], [0., 0., 1.], [0., 1., 0.], [0., 1., 1.], [1., 0., 0.], [1., 0., 1.], [1., 1., 0.], [1., 1., 1.], [0.4, 1.0, 0.5], [1., 0., 0.], [1., 0., 1.], [1., 1., 0.], [1., 1., 1.], [2., 0., 0.], [2., 0., 1.], [2., 1., 0.], [2., 1., 1.], [1.6, 1.0, 0.5], ] bbox = [[0.0, 0.0, 0.0], [2.0, 1.0, 1.0]] mesh = nmesh.mesh(objects=[cube2, cube1], bounding_box=bbox, a0=0.6,
import nmesh large = nmesh.box([-4, -4], [4, 4]) small = nmesh.box([-2, -2], [2, 2]) diff = nmesh.difference(large, [small]) bbox = [[-4, -4], [4, 4]] mesh = nmesh.mesh(bounding_box=bbox, objects=[diff]) nmesh.visual.plot2d_ps(mesh, "fixedpoints_faulty.ps") #can provide some 'fixed points' to avoid round corners fixed_points = [[-2, -2], [2, -2], [-2, 2], [2, 2]] mesh = nmesh.mesh(bounding_box=bbox, objects=[diff], fixed_points=fixed_points) nmesh.visual.plot2d_ps(mesh, "fixedpoints.ps")
import nmesh cube1 = nmesh.box( [-0.,-0.,-0.],[1.0,1.0,1.0]) cube2 = nmesh.box( [1.,-0.,-0.],[2.0,1.0,1.0]) simply_points = [ [0.,0.,0.], [0.,0.,1.], [0.,1.,0.], [0.,1.,1.], [1.,0.,0.], [1.,0.,1.], [1.,1.,0.], [1.,1.,1.], [0.4,1.0,0.5], [1.,0.,0.], [1.,0.,1.], [1.,1.,0.], [1.,1.,1.], [2.,0.,0.], [2.,0.,1.], [2.,1.,0.], [2.,1.,1.], [1.6,1.0,0.5], ] bbox = [[0.0,0.0, 0.0],[2.0,1.0,1.0]]