source: trunk/examples/zoo/mesh/mesh.py @ 6420

Last change on this file since 6420 was 5692, checked in by ldelgass, 9 years ago

Remove deprecated nodes/elements mesh from mesh example

File size: 3.8 KB
Line 
1# ----------------------------------------------------------------------
2#  EXAMPLE: Rappture <mesh> elements
3# ======================================================================
4#  AUTHOR:  Martin Hunt, Purdue University
5#  Copyright (c) 2015  HUBzero Foundation, LLC
6#
7#  See the file "license.terms" for information on usage and
8#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9# ======================================================================
10
11import Rappture
12import sys
13import numpy as np
14
15# uncomment these for debugging
16# sys.stderr = open('mesh.err', 'w')
17# sys.stdout = open('mesh.out', 'w')
18
19rx = Rappture.PyXml(sys.argv[1])
20
21meshtype = rx["input.choice(mesh).current"].value
22contour = rx["input.boolean(contour).current"].value
23
24if contour == "yes":
25    view = 'contour'
26else:
27    view = 'heightmap'
28
29mesh = rx['output.mesh']
30mesh['dim'] = 2
31mesh['units'] = "m"
32mesh['hide'] = "yes"
33
34x = np.linspace(0, 1, num=50, endpoint=True)
35y = np.linspace(0, 1, num=50, endpoint=True)
36
37
38if meshtype == 'cloud':
39    mesh['about.label'] = "cloud in unstructured mesh"
40
41    # Warning! Unstructured grids require newlines after each
42    # set of points!.
43
44    # use mgrid. weird syntax, but compact
45    # x, y = np.mgrid[0:1:50j, 0:1:50j]
46    # pts = (x.ravel('F'), y.ravel('F'))
47
48    # OR create x and y vectors then use one of these methods
49
50    # Use list comprehension to create string
51    pts = ' '.join(["%s %s\n" % (a, b) for b in y for a in x])
52
53    # Use meshgrid. Similar to mgrid()
54    # X, Y = np.meshgrid(x, y)
55    # pts = (X.ravel(), Y.ravel())
56
57    mesh['unstructured.points'] = pts
58    mesh['unstructured.celltypes'] = ""
59
60if meshtype == 'regular':
61    mesh['about.label'] = "uniform grid mesh"
62    mesh['grid.xaxis.min'] = 0
63    mesh['grid.xaxis.max'] = 1
64    mesh['grid.xaxis.numpoints'] = 50
65    mesh['grid.yaxis.min'] = 0
66    mesh['grid.yaxis.max'] = 1
67    mesh['grid.yaxis.numpoints'] = 50
68
69if meshtype == 'irregular':
70    mesh['about.label'] = "irregular grid mesh"
71    mesh['grid.xcoords'] = x
72    mesh['grid.ycoords'] = y
73
74if meshtype == 'hybrid':
75    mesh['about.label'] = "hybrid regular and irregular grid mesh"
76    mesh['grid.xcoords'] = x
77    mesh['grid.yaxis.min'] = 0
78    mesh['grid.yaxis.max'] = 1
79    mesh['grid.yaxis.numpoints'] = 50
80
81if meshtype == 'triangular':
82    mesh['about.label'] = "triangles in unstructured mesh"
83    mesh.put('unstructured.points', 'points.txt', type='file')
84    mesh.put('unstructured.triangles', 'triangles.txt', type='file')
85
86if meshtype == 'unstructured':
87    mesh['about.label'] = "Unstructured Grid"
88    mesh['unstructured.celltypes'] = 'triangle'
89    mesh.put('unstructured.points', 'points.txt', type='file')
90    mesh.put('unstructured.cells', 'triangles.txt', type='file')
91
92if meshtype == 'cells':
93    # FIXME. Copied from tcl example, but looks just like 'unstructured'
94    mesh['about.label'] = "Unstructured Grid with Heterogeneous Cells"
95    mesh['unstructured.celltypes'] = 'triangle'
96    mesh.put('unstructured.points', 'points.txt', type='file')
97    mesh.put('unstructured.cells', 'triangles.txt', type='file')
98
99if meshtype == 'vtkmesh':
100    mesh['about.label'] = 'vtk mesh'
101    mesh.put('vtk', 'mesh.vtk', type='file')
102
103if meshtype == 'vtkfield':
104    f = rx['output.field(substrate)']
105    f['about.label'] = "Substrate Surface"
106    f.put('component.vtk', 'file.vtk', type='file')
107    rx.close()
108
109f = rx['output.field(substrate)']
110f['about.label'] = "Substrate Surface"
111f['about.view'] = view
112f['component.mesh'] = mesh.name
113f.put('component.values', 'substrate_data.txt', type='file')
114
115f = rx['output.field(particle)']
116f['about.label'] = "Particle Surface"
117f['about.view'] = view
118f['component.mesh'] = mesh.name
119f.put('component.values', 'particle_data.txt', type='file')
120
121rx['output.string.about.label'] = "Mesh XML definition"
122rx['output.string.current'] = mesh.xml()
123
124rx.close()
Note: See TracBrowser for help on using the repository browser.