source: branches/blt4/examples/zoo/field/field.tcl @ 3026

Last change on this file since 3026 was 3026, checked in by gah, 12 years ago

intermediate updates for vtkcontourviewer

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