source: trunk/examples/zoo/mesh/mesh.tcl @ 3456

Last change on this file since 3456 was 3456, checked in by gah, 11 years ago

change name of tag from unstructured_grid to unstructured.

File size: 5.5 KB
Line 
1
2# Example of using unirect2d meshes in a field object in Rappture.
3
4package require Rappture
5package require BLT
6
7# Read in the data since we're not simulating anything...
8source data.tcl
9source datatri.tcl
10
11# Open an XML run file to write into
12set driver [Rappture::library [lindex $argv 0]]
13
14set meshtype [$driver get input.choice.current]
15
16set xv [blt::vector create \#auto]
17$xv seq 0 1 50
18
19switch -- $meshtype {
20    "unirect2d" {
21        set mesh "output.unirect2d"
22
23        $driver put $mesh.about.label "unirect2d mesh"
24        $driver put $mesh.units "m"
25        $driver put $mesh.hide "yes"
26
27        # Create a unirect2d mesh.  The mesh will be used in the "field"
28        # object below. We will specify a mesh and then provide the data
29        # points to the field.
30
31        $driver put $mesh.xaxis.label "Fermi-Dirac Factor"
32        $driver put $mesh.yaxis.label "Energy"
33
34        # The uniform grid that we are specifying is a mesh of 50 points on
35        # the x-axis # and 50 points on the y-axis.  The 50 points are
36        # equidistant between 0.0 and # 1.0
37
38        # Specify the x-axis of the mesh
39        $driver put $mesh.xaxis.min 0.0
40        $driver put $mesh.xaxis.max 1.0
41        $driver put $mesh.xaxis.numpoints 50
42       
43        # Specify the y-axis of the mesh
44        $driver put $mesh.yaxis.min 0.0
45        $driver put $mesh.yaxis.max 1.0
46        $driver put $mesh.yaxis.numpoints 50
47    }
48    "oldcloud" {
49        set mesh output.cloud
50        $driver put $mesh.about.label "cloud (deprecated)"
51        $driver put $mesh.units "m"
52        $driver put $mesh.hide "yes"
53
54        set points {}
55        foreach y [$xv range 0 end] {
56            foreach x [$xv range 0 end] {
57                append points "$x $y\n"
58            }
59        }
60   
61        # Test old-style cloud element.
62        $driver put $mesh.units "m"
63        $driver put $mesh.points $points
64    }
65    "cloud" {
66        set mesh output.mesh
67
68        $driver put $mesh.about.label "cloud in mesh"
69        $driver put $mesh.units "m"
70        $driver put $mesh.hide "yes"
71
72        set points {}
73        foreach y [$xv range 0 end] {
74            foreach x [$xv range 0 end] {
75                append points "$x $y\n"
76            }
77        }
78        $driver put $mesh.cloud.points $points
79    }
80    "regular" {
81        set mesh output.mesh
82
83        $driver put $mesh.about.label "uniform grid mesh"
84        $driver put $mesh.units "m"
85        $driver put $mesh.hide "yes"
86
87        $driver put $mesh.grid.xaxis.min 0.0
88        $driver put $mesh.grid.xaxis.max 1.0
89        $driver put $mesh.grid.xaxis.numpoints 50
90        $driver put $mesh.grid.yaxis.min 0.0
91        $driver put $mesh.grid.yaxis.max 1.0
92        $driver put $mesh.grid.yaxis.numpoints 50
93    }
94    "irregular" {
95        set mesh output.mesh
96
97        $driver put $mesh.about.label "irregular grid mesh"
98        $driver put $mesh.units "m"
99        $driver put $mesh.hide "yes"
100
101        $driver put $mesh.grid.xcoords [$xv range 0 end]
102        $driver put $mesh.grid.ycoords [$xv range 0 end]
103    }
104    "hybrid" {
105        set mesh output.mesh
106
107        $driver put $mesh.about.label "hybrid regular and irregular grid mesh"
108        $driver put $mesh.units "m"
109        $driver put $mesh.hide "yes"
110
111        $driver put $mesh.units "m"
112        $driver put $mesh.grid.xcoords [$xv range 0 end]
113        $driver put $mesh.grid.yaxis.min 0.0
114        $driver put $mesh.grid.yaxis.max 1.0
115        $driver put $mesh.grid.yaxis.numpoints 50
116    }
117    "triangular" {
118        set mesh output.mesh
119
120        $driver put $mesh.about.label "triangular mesh"
121        $driver put $mesh.units "m"
122        $driver put $mesh.hide "yes"
123
124        $driver put $mesh.triangles.points $points
125        $driver put $mesh.triangles.indices $triangles
126    }
127    "generic" {
128        set mesh output.mesh
129
130        $driver put $mesh.about.label "nodes and elements mesh"
131        $driver put $mesh.units "m"
132        $driver put $mesh.hide "yes"
133
134        set count 0
135        foreach { x y } $points {
136            $driver put $mesh.node($count) "$x $y"
137            incr count
138        }
139        set count 0
140        foreach { a b c } $triangles {
141            $driver put $mesh.element($count).nodes "$a $b $c"
142            incr count
143        }
144    }
145    "unstructured" {
146        set mesh output.mesh
147
148        $driver put $mesh.about.label "Unstructured Grid"
149        $driver put $mesh.units "m"
150        $driver put $mesh.hide "yes"
151
152        $driver put $mesh.unstructured.points $points
153        set celltypes {}
154        set cells {}
155        foreach { a b c } $triangles {
156            lappend celltypes "5"
157            append cells "3 $a $b $c\n"
158        }
159        $driver put $mesh.unstructured.cells $cells
160        $driver put $mesh.unstructured.celltypes $celltypes
161    }
162    "cells" {
163        set mesh output.mesh
164
165        $driver put $mesh.about.label "homogeneous cells"
166        $driver put $mesh.units "m"
167        $driver put $mesh.hide "yes"
168
169        $driver put $mesh.cells.points $points
170        $driver put $mesh.cells.triangles $triangles
171    }
172    "vtkmesh" {
173        set mesh output.mesh
174
175        set f [open "mesh.vtk" "r"]
176        set data [read $f]
177        close $f
178
179        $driver put $mesh.about.label "vtk mesh"
180        $driver put $mesh.units "m"
181        $driver put $mesh.hide "yes"
182        $driver put $mesh.vtk $data
183    }
184    "vtkfield" {
185
186
187        $driver put output.field(substrate).about.label "Substrate Surface"
188        set f [open "file.vtk" "r"]
189        set data [read $f]
190        close $f
191        $driver put output.field(substrate).component.vtk "$data"
192        #$driver put output.field(substrate).about.view "contour"
193        # save the updated XML describing the run...
194        Rappture::result $driver
195        exit 0
196    }
197    default {
198        error "unknown mesh type \"$meshtype\""
199    }
200}
201
202$driver put output.field(substrate).about.label "Substrate Surface"
203#$driver put output.field(substrate).about.type "contour"
204$driver put output.field(substrate).component.mesh $mesh
205$driver put output.field(substrate).component.values $substrate_data
206
207$driver put output.field(particle).about.label "Particle Surface"
208#$driver put output.field(particle).about.type "contour"
209$driver put output.field(particle).component.mesh $mesh
210$driver put output.field(particle).component.values $particle_data
211
212$driver put output.string.about.label "Mesh XML definition"
213$driver put output.string.current [$driver xml $mesh]
214
215# save the updated XML describing the run...
216Rappture::result $driver
217exit 0
218
Note: See TracBrowser for help on using the repository browser.