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")
# plan. There is a problematic issue with the dof name resolution of # the EOM LHS! FIXME! # Notes: # # (1) It is somewhat problematic/annoying that the first script does # not really make clear when a name is a MWE name and when it is a # field/vector name. Corrected that for this example. import os, time, sys, math import nmesh execfile("../../interface/nsim/linalg_machine.py") objects = [ nmesh.difference(nmesh.ellipsoid([3.0, 3.0], [("shift", [0, 0])]), [nmesh.ellipsoid([2.5, 2.5], [("shift", [0, 0])])]) ] mesh = nmesh.mesh( objects=objects, a0=0.25, bounding_box=[[-5.0, -5.0], [5.0, 5.0]], cache_name="geometry.mesh", ) raw_mesh = mesh.raw_mesh if ocaml.petsc_is_mpi(): print "*** PARALLEL EXECUTION ***" nr_nodes = ocaml.petsc_mpi_nr_nodes() nr_points = ocaml.mesh_nr_points(raw_mesh)
# A parallelizable demo script implementing a reaction/diffusion system # ("burning sparkler") import os,time,sys,math import nmesh execfile("../interface/nsim/linalg_machine.py") objects=[nmesh.difference(nmesh.ellipsoid([3.0,3.0],[("shift",[0,0])]), [nmesh.ellipsoid([2.5,2.5],[("shift",[0,0])])]) ] mesh = nmesh.mesh(objects=objects, a0=0.25, bounding_box=[[-5.0,-5.0],[5.0,5.0]], cache_name="linalg_machine_rd.mesh", ) raw_mesh=mesh.raw_mesh if ocaml.petsc_is_mpi(): print "*** PARALLEL EXECUTION ***" nr_nodes=ocaml.petsc_mpi_nr_nodes() nr_points=ocaml.mesh_nr_points(raw_mesh) z=nr_points/nr_nodes distrib = [int(round(z*(i+1)))-int(round(z*i)) for i in range(0,nr_nodes)] slack=nr_points-reduce(lambda x,y:x+y,distrib) distrib[0] = distrib[0] + slack print "*** RAW MESH %s *** DISTRIB %s ***" %(repr(raw_mesh),repr(distrib)) ocaml.mesh_set_vertex_distribution(raw_mesh,distrib)
print """ ** 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]],
nfem.set_default_dimension(2) nfem.set_default_order(1) # 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)
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])] ) #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
print """ ** 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.0, 1.0], transform=[("shift", [-2.5, 0.0])])]), nmesh.difference( nmesh.ellipsoid([3.0, 3.0], transform=[("shift", [2.5, 0.0])]), [nmesh.ellipsoid([1.0, 1.0], 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.508,
""" ** 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.0, 1.0], transform=[("shift", [-2.5, 0.0])])], ), nmesh.difference( nmesh.ellipsoid([3.0, 3.0], transform=[("shift", [2.5, 0.0])]), [nmesh.ellipsoid([1.0, 1.0], 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],
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")
nfem.set_default_dimension(2) nfem.set_default_order(1) # 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)
import nmesh big = nmesh.ellipsoid([4.0,3.0]) # create a big ellipsoid small = nmesh.ellipsoid([3.0,2.0]) # small ellipsoid diff = nmesh.difference(big,[small])# create difference of ellipsoids bbox = [[-5.,-4.],[5.,4.]] mesh_ex = nmesh.mesh(objects = [diff], a0=0.4, bounding_box=bbox) # plot mesh nmesh.visual.plot2d_ps(mesh_ex,"difference.ps")
bbox = [[-10,-10,-thickness/2.],[10,10,thickness/2.]] 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,
import nmesh big = nmesh.ellipsoid([4.0, 3.0]) # create a big ellipsoid small = nmesh.ellipsoid([3.0, 2.0]) # small ellipsoid diff = nmesh.difference(big, [small]) # create difference of ellipsoids bbox = [[-5., -4.], [5., 4.]] mesh_ex = nmesh.mesh(objects=[diff], a0=0.4, bounding_box=bbox) # plot mesh nmesh.visual.plot2d_ps(mesh_ex, "difference.ps")