Example #1
0
   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

Example #2
0
"""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")
Example #3
0
import nmesh

ell = nmesh.ellipsoid([3, 2])  # create ellipsoid
cone = nmesh.conic([-3, 0], 2, [3, 0], 0)  # create cone

inters = nmesh.intersect([ell, cone])  # create intersection of objects

bbox = [[-5., -4.], [5., 4.]]
mesh_ex = nmesh.mesh(objects=[inters], a0=0.4, bounding_box=bbox)

nmesh.visual.plot2d_ps(mesh_ex, "intersection.ps")
Example #4
0
import nmesh

P2 = [0, 4]  #center of 'circle' 2
R2 = 3  #radius of 'circle' 2
P1 = [0, 0]  #center of 'circle' 1
R1 = 5  #radius of 'circle' 1

frustum = nmesh.conic(P1, R1, P2, R2)

bbox = [[-5, 0], [5, 4]]

mesh = nmesh.mesh(objects=[frustum], bounding_box=bbox)

nmesh.visual.plot2d_ps(mesh, "frustum.ps")
Example #5
0
# temporarily commented out by turning this into a string...
"""
the_mesh = nm.mesh(([-5.0,-5.0,-5.0],[5.0,5.0,5.0]), # bounding box
                   objects= \
                    [nm.difference( \
                      nm.intersect([nm.conic([0.0,0.0,-2.0],7.0,
                                             [0.0,0.0,2.0],7.0),
                                    nm.box([-4.0,-4.0,-4.0],[4.0,4.0,4.0])]))],
                   a0=1.2,
                   max_steps=500,
                   cache_name="ddiffop_mesh")
"""

mesh_obj = nm.mesh(([-5.0,-5.0,-5.0],[5.0,5.0,5.0]), # bounding box
                   objects= [nm.conic([0.0,0.0,-2.0],4.0,[0.0,0.0,2.0],4.0)],
                   a0=1.2,
                   max_steps=500,
                   cache_name="ddiffop_mesh")

the_mesh = mesh_obj.raw_mesh

print "MESH: ",the_mesh,type(the_mesh)


elem_T = ocaml.make_element("T",[],3,1)
elem_sigma = ocaml.make_element("sigma",[],3,1)
elem_j_q = ocaml.make_element("j_q",[3],3,1)

mwe_T=ocaml.make_mwe("mwe_T",the_mesh,[(1,elem_T)],[])
mwe_sigma=ocaml.make_mwe("mwe_sigma",the_mesh,[(1,elem_sigma)],[])
Example #6
0
import nmesh
frustum = nmesh.conic([0.0, 0.0, 0.0], 1.0, [2.0, 0.0, 0.0], 2.0)

bbox = [[-2., -2., -2.0], [2., 2., 2.]]

mesh = nmesh.mesh(objects=[frustum], bounding_box=bbox)

#create 3d-plot of surfaces
vis = nmesh.visual.show_bodies_mayavi(mesh)

import time
time.sleep(5)
#and save to eps file
nmesh.visual.export_visualisation(vis, "frustum3d.eps")
Example #7
0
import nmesh

P2 = [0,4]  #center of 'circle' 2
R2 = 3      #radius of 'circle' 2
P1 = [0,0]  #center of 'circle' 1
R1 = 5      #radius of 'circle' 1


frustum = nmesh.conic( P1, R1, P2, R2 )

bbox = [[-5,0],[5,4]]

mesh = nmesh.mesh(objects=[frustum], bounding_box=bbox)

nmesh.visual.plot2d_ps( mesh, "frustum.ps")
"""This example should demonstrate how to use the function order_mesh()
   but rather than sorting by position along an axis, the simplices will
   be sorted by their quality. In this case the metric 3*inradius/circumradius
   is used.

   Author: James Kenny       Last modified: $Date$
"""
import nmesh
frustum = nmesh.conic([0.0,0.0,0.0],1.0,[2.0,0.0,0.0],2.0)
bbox = [[-2.,-2.,-2.],[2.,2.,2.]]
mesh = nmesh.mesh(objects=[frustum],bounding_box=bbox)
mesh_info = mesh.tolists()


# now order the mesh by it's quality and display the worst 100 elements only
vtkData, points, simplices, simplexIndices, icradii, ccradii = nmesh.visual.mesh2vtk(mesh_info, VTKonly=False)

# calculate the quality metric
in2circ = nmesh.visual.findRatios(icradii, ccradii, factor=3)

# order the mesh by this metric
mesh_info = nmesh.visual.order_mesh(mesh_info, data=in2circ)

import mayavi
v= mayavi.mayavi()

# display this information and open the ExtractUnstructuredGrid filter
nmesh.visual.solid_in2circ(mesh_info, myv = v)

f = v.load_filter('ExtractUnstructuredGrid',0)
Example #9
0
#
# Using the discretized differential operator machinery
# from within python...
#

# NOTE: Mesher (version from 30-04-2007) has difficulty here, cannot
# generate the mesh. Reverting to the mesher version from 01-04-2007 works.

import nmag2 as nmag, nmesh as nm, sys, math, time
import nfem
import nfem.visual

mesh_obj = nm.mesh(
    ([-6.0, -6.0, -6.0], [6.0, 6.0, 6.0]),  # bounding box
    objects=[
        nm.conic([0.0, 0.0, -4.0], 2.0, [0.0, 0.0, 4.0], 2.0),
    ],
    a0=0.8,
    max_steps=400,
    cache_name="ddiffop4_mesh_rod")

the_mesh = mesh_obj.raw_mesh

print "MESH: ", the_mesh, type(the_mesh)

elem_scalar = ocaml.make_element("S", [], 3, 1)
elem_vector = ocaml.make_element("V", [3], 3, 1)


def surface_type(pos):
    if pos[2] < -3.99:
Example #10
0
# Test example 2: heat flow with spatially changing heat conductivity
#
# Using the discretized differential operator machinery
# from within python...
#

# NOTE: Mesher (version from 30-04-2007) has difficulty here, cannot
# generate the mesh. Reverting to the mesher version from 01-04-2007 works.

import nmag2 as nmag, nmesh as nm, sys, math, time
import nfem
import nfem.visual


mesh_obj = nm.mesh(([-6.0,-6.0,-6.0],[6.0,6.0,6.0]), # bounding box
                   objects= [nm.conic([0.0,0.0,-4.0],2.0,[0.0,0.0,4.0],2.0),
                             nm.conic([0.0,0.0,-5.0],2.0,[0.0,0.0,-4.0],2.0),
                             nm.conic([0.0,0.0,5.0],2.0,[0.0,0.0,4.0],2.0)
                             ],
                   a0=0.6,
                   max_steps=100,
                   cache_name="ddiffop_mesh_rod")

the_mesh = mesh_obj.raw_mesh

print "MESH: ",the_mesh,type(the_mesh)


elem_scalar = ocaml.make_element("S",[],3,1)
elem_vector = ocaml.make_element("V",[3],3,1)
Example #11
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,
                     max_steps=500
                     )
Example #12
0
import nmesh

ell = nmesh.ellipsoid([3,2])            # create ellipsoid
cone = nmesh.conic([-3,0],2,[3,0],0)    # create cone

inters = nmesh.intersect([ell, cone])   # create intersection of objects 

bbox = [[-5.,-4.],[5.,4.]]
mesh_ex = nmesh.mesh(objects = [inters], a0=0.4, bounding_box=bbox)

nmesh.visual.plot2d_ps(mesh_ex,"intersection.ps")


Example #13
0
"""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)
Example #14
0
"""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)
Example #15
0
#=================================== mesh parameters ==============
rod = 0.8

outer_radius = 5.0
inner_radius = 2 
thickness = 1.

import math

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
Example #16
0
import nmesh, pylab, Numeric

rod = 1.2

outer_radius = 10.0
inner_radius = 6.0
thickness = 2.0

import math

bbox = [[-10, -10, -thickness], [10, 10, thickness]]

# external ring
R = nmesh.conic(
    [0.0, 0.0, -thickness],
    outer_radius,
    [0.0, 0.0, thickness],
    outer_radius,
)
#internal ring
r = nmesh.conic(
    [0.0, 0.0, -thickness],
    inner_radius,
    [0.0, 0.0, thickness],
    inner_radius,
)
# take the difference
ring = nmesh.difference(R, [r])

density = """density = 1.;"""

N = 10