""" ** Example: meshing four rings & solving the laplace equation for a space-dependent resistivity that depends on outer parameters (Presumably, we will encounter bugs at our first try) ** """ ##### 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,
{ 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() def initial_m(dof_name,coords): print "DDD initial_M(dof_name=\"",dof_name,"\",coords=",coords,")\n" dir=dof_name[1][0] if dir==0:
m=[0.0,1.0,0.0] return m[dof_name_indices[1][0]] # Note that we can easily also use the 3d differential operators for # the 2d problems... diffop_laplace=nfem.diffop("-<d/dxj rho_M||d/dxj phi_M>, j:3") diffop_div_M=nfem.diffop("<rho_M||d/dxj M(j)>, j:3") diffop_grad_phi=nfem.diffop("<H(j)||d/dxj phi_M>, j:3") ##### Creating the mesh ##### # For now, we use a very very simple mesh... double_disc_2d = nmesh.union([nmesh.ellipsoid([3.0,3.0], transform=[("shift",[-1.0,0.0])]), nmesh.ellipsoid([3.0,3.0], transform=[("shift",[1.0,0.0])])]) double_disc_3d = nmesh.union([nmesh.conic([-1.0,0.0,thickness2d*0.5],3.0,[-1.0,0.0,-thickness2d*0.5],3.0), nmesh.conic([ 1.0,0.0,thickness2d*0.5],3.0,[ 1.0,0.0,-thickness2d*0.5],3.0)]) density = "density=1.;" mesh_2d = nmesh.mesh(objects = [double_disc_2d], cache_name="double-disc-2d", a0=0.4, bounding_box=[[-5.0,-5.0],[5.0,5.0]], neigh_force_scale = 1., density = density, initial_settling_steps = 50, max_relaxation = 4,
# external ring R = nmesh.ellipsoid( [outer_radius, outer_radius], transform=[("shift",[x*centres_distance, y*centres_distance])] ) #internal ring r = nmesh.ellipsoid( [inner_radius, inner_radius], transform=[("shift",[x*centres_distance, y*centres_distance])] ) # take the difference rings.append(nmesh.difference(R,[r])) # cut the rings at top and bottom union_rings = nmesh.union(rings) rings_array = nmesh.intersect([union_rings,rings_box]) # semiaxis of a rhombus on the diagonals of the array d = (centres_distance/2.) - Numeric.sqrt(outer_radius**2 - (centres_distance/2.)**2) # rhombi on the diagonals of the array for x in range(-3,4,2): for y in range(-3,4,2): centre_x = 0.5*x*centres_distance centre_y = 0.5*y*centres_distance # centre of the rhombus c = Numeric.array([centre_x,centre_y])
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")
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,
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, )
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 nx = 2 #how many ellipsoids in x direction x0 = 20 #spacing of ellipsoids in x ny = 2 #how many ellipsoids in y direction y0 = 20 #spacing of ellipsoids in x rx, ry = 10.5, 10.5 #radii of ellipsoids angle = 0 #orientation of ellipsoids #create list 'objects' with ellipsoids objects = [] for i in range(nx): for j in range(ny): objects.append( nmesh.ellipsoid([rx, ry], [("rotate2d", angle), ("shift", [i * x0, j * y0])])) union = nmesh.union(objects) #bounding box bbox = [[-15, -15], [(nx - 1) * x0 + 15, (ny - 1) * y0 + 15]] #create the mesh mesh = nmesh.mesh(objects=[union], a0=2, bounding_box=bbox) #save plot to file nmesh.visual.plot2d_ps(mesh, "mergedspheres.ps")
import nmesh nx = 2 #how many ellipsoids in x direction x0 = 20 #spacing of ellipsoids in x ny = 2 #how many ellipsoids in y direction y0 = 20 #spacing of ellipsoids in x rx,ry = 10.5,10.5 #radii of ellipsoids angle = 0 #orientation of ellipsoids #create list 'objects' with ellipsoids objects = [] for i in range(nx): for j in range(ny): objects.append( nmesh.ellipsoid([rx,ry], [("rotate2d",angle), ("shift",[i*x0,j*y0])])) union = nmesh.union(objects) #bounding box bbox = [[-15,-15],[(nx-1)*x0+15,(ny-1)*y0+15]] #create the mesh mesh = nmesh.mesh(objects=[union],a0=2,bounding_box=bbox) #save plot to file nmesh.visual.plot2d_ps(mesh,"mergedspheres.ps")
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