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