source: trunk/examples/zoo/field/field.tcl @ 572

Last change on this file since 572 was 572, checked in by mmc, 17 years ago

Added a test harness for the nanoVIS server. Run "nanovis-test" and
you can send individual commands or command files to the server and
monitor the communication.

Fixed examples/zoo/field to have nanoVIS output as an option.

Fixed the app-fermi/matlab example to include the proper path
for loading scripts from the local directory.

File size: 4.4 KB
Line 
1# ----------------------------------------------------------------------
2#  EXAMPLE: Rappture <field> elements
3# ======================================================================
4#  AUTHOR:  Michael McLennan, Purdue University
5#  Copyright (c) 2004-2005  Purdue Research Foundation
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# ======================================================================
10package require Rappture
11
12# open the XML file containing the run parameters
13set driver [Rappture::library [lindex $argv 0]]
14
15# get the formula and make it ready for evaluation
16set formula [$driver get input.string(formula).current]
17regsub -all {[xyz]} $formula {$\0} formula
18
19#
20# Generate the 2D mesh and field values...
21#
22set n 0
23set z 1
24foreach {x y} {
25    0 0
26    1 0
27    2 0
28    3 0
29    4 0
30    0 1
31    1 1
32    2 1
33    3 1
34    4 1
35    0 2
36    1 2
37    2 2
38    3 2
39    4 2
40    0 3
41    1 3
42    2 3
43    3 3
44    4 3
45    0 4
46    1 4
47    2 4
48    3 4
49    4 4
50} {
51    $driver put -append yes output.cloud(m2d).points "$x $y\n"
52    incr n
53
54    set fval [expr $formula]
55    $driver put -append yes output.field(f2d).component.values "$fval\n"
56}
57
58#
59# See what sort of 3D data to generate...
60#
61set vizmethod [$driver get input.choice(3D).current]
62
63#
64# Generate the 3D mesh and field values...
65#
66if {$vizmethod == "vtk"} {
67    set n 0
68    foreach {x y z} {
69        0 0 0
70        1 0 0
71        2 0 0
72        3 0 0
73        4 0 0
74        0 1 0
75        1 1 0
76        2 1 0
77        3 1 0
78        4 1 0
79        0 2 0
80        1 2 0
81        2 2 0
82        3 2 0
83        4 2 0
84        0 3 0
85        1 3 0
86        2 3 0
87        3 3 0
88        4 3 0
89        0 4 0
90        1 4 0
91        2 4 0
92        3 4 0
93        4 4 0
94        0 0 1
95        1 0 1
96        2 0 1
97        3 0 1
98        4 0 1
99        0 1 1
100        1 1 1
101        2 1 1
102        3 1 1
103        4 1 1
104        0 2 1
105        1 2 1
106        2 2 1
107        3 2 1
108        4 2 1
109        0 3 1
110        1 3 1
111        2 3 1
112        3 3 1
113        4 3 1
114        0 4 1
115        1 4 1
116        2 4 1
117        3 4 1
118        4 4 1
119    } {
120        $driver put output.mesh(m3d).node($n) "$x $y $z"
121        incr n
122
123        set fval [expr $formula]
124        $driver put -append yes output.field(f3d).component.values "$fval\n"
125    }
126
127    # meshes also need element descriptions
128    $driver put output.mesh(m3d).about.label "3D Mesh"
129    $driver put output.mesh(m3d).units "um"
130    $driver put output.mesh(m3d).hide "yes"
131
132    $driver put output.mesh(m3d).element(0).nodes "0 1 5 6 25 26 30 31"
133    $driver put output.mesh(m3d).element(1).nodes "1 2 6 7 26 27 31 32"
134    $driver put output.mesh(m3d).element(2).nodes "2 3 7 8 27 28 32 33"
135    $driver put output.mesh(m3d).element(3).nodes "3 4 8 9 28 29 33 34"
136    $driver put output.mesh(m3d).element(4).nodes "5 6 10 11 30 31 35 36"
137    $driver put output.mesh(m3d).element(5).nodes "8 9 13 14 33 34 38 39"
138    $driver put output.mesh(m3d).element(6).nodes "10 11 15 16 35 36 40 41"
139    $driver put output.mesh(m3d).element(7).nodes "13 14 18 19 38 39 43 44"
140    $driver put output.mesh(m3d).element(8).nodes "15 16 20 21 40 41 45 46"
141    $driver put output.mesh(m3d).element(9).nodes "16 17 21 22 41 42 46 47"
142    $driver put output.mesh(m3d).element(10).nodes "17 18 22 23 42 43 47 48"
143    $driver put output.mesh(m3d).element(12).nodes "18 19 23 24 43 44 48 49"
144
145    $driver put output.field(f3d).component.mesh "output.mesh(m3d)"
146}
147
148#
149# Generate the 3D mesh in OpenDX format...
150#
151if {$vizmethod == "nanovis"} {
152    set dx "object 1 class gridpositions counts 5 5 3
153delta 1 0 0
154delta 0 1 0
155delta 0 0 1
156object 2 class gridconnections counts 5 5 3
157object 3 class array type double rank 0 items 75 data follows
158"
159    for {set z 0} {$z < 3} {incr z} {
160        for {set y 0} {$y < 5} {incr y} {
161            for {set x 0} {$x < 5} {incr x} {
162                set fval [expr $formula]
163                append dx "$fval\n"
164            }
165        }
166    }
167    append dx {attribute "dep" string "positions"
168    object "regular positions regular connections" class field
169    component "positions" value 1
170    component "connections" value 2
171    component "data" value 3}
172
173    set file "/tmp/dx[clock seconds]"
174    set fid [open $file w]
175    puts $fid $dx
176    close $fid
177
178    set fid [open "| gzip -c $file | mimencode" r]
179    $driver put output.field(f3d).component.dx [read $fid]
180    close $fid
181
182    file delete -force $file
183}
184
185#
186# Save the updated XML describing the run...
187#
188Rappture::result $driver
189exit 0
Note: See TracBrowser for help on using the repository browser.