source: branches/uq/gui/scripts/uq.tcl @ 5168

Last change on this file since 5168 was 5168, checked in by mmh, 10 years ago

cleanup

File size: 11.0 KB
Line 
1package require Itk
2namespace eval Rappture {}
3
4itcl::class Rappture::UQ {
5
6    constructor {varlist type uqargs} {
7        puts "Rappture::UQ constructor $varlist:$type:$uqargs"
8        set _varlist $varlist
9        set _type $type
10        set _args $uqargs
11    }
12
13    destructor {
14        # defined below
15    }
16
17    public method run_dialog {win}
18    public method num_runs {}
19    public method type {} {return $_type}
20    public method args {} {return $_args}
21
22    protected method _setWaitVariable {state}
23    protected method _adjust_level {win}
24    protected method _set_text {win}
25    protected method _init_num_pts_array {}
26    public variable _type "smolyak"
27    private variable _args "2"
28    private variable _varlist {}
29    private variable _wait_uq 0
30    private variable _num_pts {}
31    private variable _go ""
32}
33
34# ----------------------------------------------------------------------
35# Display a dialog for setting UQ options.
36# Returns 0 to cancel, 1 to continue.
37# ----------------------------------------------------------------------
38itcl::body Rappture::UQ::run_dialog {win} {
39
40    set popup .pop_simulate
41    if {[winfo exists $popup]} {destroy $popup}
42
43    if { ![winfo exists $popup] } {
44
45        Rappture::Balloon $popup -title "UQ Options"
46        set inner [$popup component inner]
47        labelframe  $inner.type -text "UQ Type"
48
49        set _val [Rappture::Combobox $inner.type.val -width 20 -editable no]
50        pack $_val -side top -expand yes -fill x -pady 5
51        $_val choices insert end smolyak "Smolyak"
52        $_val value [$_val label $_type]
53
54        label $inner.type.labeltext -text "Level" -font "Arial 9"
55        Rappture::Spinint $inner.type.level -min 1 -max 20
56        $inner.type.level value $_args
57        bind $inner.type.level <<Value>> [itcl::code $this _adjust_level $inner]
58        pack $inner.type.labeltext $inner.type.level -side left -expand yes -fill x -pady 5
59        pack $inner.type -side top -fill x
60
61        set fr [frame $inner.frame]
62
63        set nr [num_runs]
64        label $fr.text
65
66        #     bind $_val <<Value>> [itcl::code $this _change_param_type $inner]
67
68        button $fr.cancel -text Cancel -command  [itcl::code $this _setWaitVariable 0]
69        set _go $fr.go
70        button $_go -text Continue -command  [itcl::code $this _setWaitVariable 1]
71        _set_text $inner
72
73        pack $fr.text -side top -pady 10
74        pack $_go $fr.cancel -pady 4 -side right
75        pack $fr
76    }
77    update idletasks
78
79    _setWaitVariable -1
80    $popup activate $win below
81    tkwait variable [itcl::scope _wait_uq]
82    $popup deactivate
83
84    return $_wait_uq
85}
86
87itcl::body Rappture::UQ::_setWaitVariable {state} {
88    set _wait_uq $state
89}
90
91itcl::body Rappture::UQ::_set_text {win} {
92    set nr [num_runs]
93
94    switch $_type {
95        smolyak {
96            if {$nr == 0} {
97                set text "ERROR: The number of required jobs exceeds 100,000!\n\  Please\n\
98                adjust the polynomial level or reduce the number of UQ variables."
99                $_go configure -state disabled
100            } else {
101                set text "This method builds a polynomial response\
102                function of degree $_args.\n It will require $nr runs."
103                $_go configure -state normal
104            }
105        }
106        default {
107            set text "This will require $nr runs of the tool."
108            $_go configure -state normal
109        }
110    }
111    $win.frame.text configure -text $text
112}
113
114itcl::body Rappture::UQ::_adjust_level {win} {
115    set _args [$win.type.level value]
116    _set_text $win
117}
118
119itcl::body Rappture::UQ::num_runs {} {
120    set numvars  [llength $_varlist]
121    # puts "UQ num_runs $numvars $_type $_args"
122    if {![array exists _num_pts]} { _init_num_pts_array }
123    switch $_type {
124        smolyak {
125            return $_num_pts($numvars,$_args)
126        }
127        default {
128            return $_args
129        }
130    }
131}
132
133itcl::body Rappture::UQ::_init_num_pts_array {} {
134    # array is indexed (dim,level)
135    unset _num_pts
136    array set _num_pts [list \
137        0,0 0 \
138        0,1 0 \
139        0,2 0 \
140        0,3 0 \
141        0,4 0 \
142        0,5 0 \
143        0,6 0 \
144        0,7 0 \
145        0,8 0 \
146        0,9 0 \
147        0,10 0 \
148        0,11 0 \
149        0,12 0 \
150        0,13 0 \
151        0,14 0 \
152        0,15 0 \
153        0,16 0 \
154        0,17 0 \
155        0,18 0 \
156        0,19 0 \
157        1,0 0 \
158        1,1 3 \
159        1,2 5 \
160        1,3 9 \
161        1,4 17 \
162        1,5 33 \
163        1,6 65 \
164        1,7 129 \
165        1,8 257 \
166        1,9 513 \
167        1,10 1025 \
168        1,11 2049 \
169        1,12 4097 \
170        1,13 8193 \
171        1,14 16385 \
172        1,15 32769 \
173        1,16 65537 \
174        1,17 131073 \
175        1,18 0 \
176        1,19 0 \
177        2,0 0 \
178        2,1 5 \
179        2,2 13 \
180        2,3 29 \
181        2,4 65 \
182        2,5 145 \
183        2,6 321 \
184        2,7 705 \
185        2,8 1537 \
186        2,9 3329 \
187        2,10 7169 \
188        2,11 15361 \
189        2,12 32769 \
190        2,13 69633 \
191        2,14 147457 \
192        2,15 0 \
193        2,16 0 \
194        2,17 0 \
195        2,18 0 \
196        2,19 0 \
197        3,0 0 \
198        3,1 7 \
199        3,2 25 \
200        3,3 69 \
201        3,4 177 \
202        3,5 441 \
203        3,6 1073 \
204        3,7 2561 \
205        3,8 6017 \
206        3,9 13953 \
207        3,10 32001 \
208        3,11 72705 \
209        3,12 163841 \
210        3,13 0 \
211        3,14 0 \
212        3,15 0 \
213        3,16 0 \
214        3,17 0 \
215        3,18 0 \
216        3,19 0 \
217        4,0 0 \
218        4,1 9 \
219        4,2 41 \
220        4,3 137 \
221        4,4 401 \
222        4,5 1105 \
223        4,6 2929 \
224        4,7 7537 \
225        4,8 18945 \
226        4,9 46721 \
227        4,10 113409 \
228        4,11 0 \
229        4,12 0 \
230        4,13 0 \
231        4,14 0 \
232        4,15 0 \
233        4,16 0 \
234        4,17 0 \
235        4,18 0 \
236        4,19 0 \
237        5,0 0 \
238        5,1 11 \
239        5,2 61 \
240        5,3 241 \
241        5,4 801 \
242        5,5 2433 \
243        5,6 6993 \
244        5,7 19313 \
245        5,8 51713 \
246        5,9 135073 \
247        5,10 0 \
248        5,11 0 \
249        5,12 0 \
250        5,13 0 \
251        5,14 0 \
252        5,15 0 \
253        5,16 0 \
254        5,17 0 \
255        5,18 0 \
256        5,19 0 \
257        6,0 0 \
258        6,1 13 \
259        6,2 85 \
260        6,3 389 \
261        6,4 1457 \
262        6,5 4865 \
263        6,6 15121 \
264        6,7 44689 \
265        6,8 127105 \
266        6,9 0 \
267        6,10 0 \
268        6,11 0 \
269        6,12 0 \
270        6,13 0 \
271        6,14 0 \
272        6,15 0 \
273        6,16 0 \
274        6,17 0 \
275        6,18 0 \
276        6,19 0 \
277        7,0 0 \
278        7,1 15 \
279        7,2 113 \
280        7,3 589 \
281        7,4 2465 \
282        7,5 9017 \
283        7,6 30241 \
284        7,7 95441 \
285        7,8 287745 \
286        7,9 0 \
287        7,10 0 \
288        7,11 0 \
289        7,12 0 \
290        7,13 0 \
291        7,14 0 \
292        7,15 0 \
293        7,16 0 \
294        7,17 0 \
295        7,18 0 \
296        7,19 0 \
297        8,0 0 \
298        8,1 17 \
299        8,2 145 \
300        8,3 849 \
301        8,4 3937 \
302        8,5 15713 \
303        8,6 56737 \
304        8,7 190881 \
305        8,8 0 \
306        8,9 0 \
307        8,10 0 \
308        8,11 0 \
309        8,12 0 \
310        8,13 0 \
311        8,14 0 \
312        8,15 0 \
313        8,16 0 \
314        8,17 0 \
315        8,18 0 \
316        8,19 0 \
317        9,0 0 \
318        9,1 19 \
319        9,2 181 \
320        9,3 1177 \
321        9,4 6001 \
322        9,5 26017 \
323        9,6 100897 \
324        9,7 0 \
325        9,8 0 \
326        9,9 0 \
327        9,10 0 \
328        9,11 0 \
329        9,12 0 \
330        9,13 0 \
331        9,14 0 \
332        9,15 0 \
333        9,16 0 \
334        9,17 0 \
335        9,18 0 \
336        9,19 0 \
337        10,0 0 \
338        10,1 21 \
339        10,2 221 \
340        10,3 1581 \
341        10,4 8801 \
342        10,5 41265 \
343        10,6 171425 \
344        10,7 0 \
345        10,8 0 \
346        10,9 0 \
347        10,10 0 \
348        10,11 0 \
349        10,12 0 \
350        10,13 0 \
351        10,14 0 \
352        10,15 0 \
353        10,16 0 \
354        10,17 0 \
355        10,18 0 \
356        10,19 0 \
357        11,0 0 \
358        11,1 23 \
359        11,2 265 \
360        11,3 2069 \
361        11,4 12497 \
362        11,5 63097 \
363        11,6 280017 \
364        11,7 0 \
365        11,8 0 \
366        11,9 0 \
367        11,10 0 \
368        11,11 0 \
369        11,12 0 \
370        11,13 0 \
371        11,14 0 \
372        11,15 0 \
373        11,16 0 \
374        11,17 0 \
375        11,18 0 \
376        11,19 0 \
377        12,0 0 \
378        12,1 25 \
379        12,2 313 \
380        12,3 2649 \
381        12,4 17265 \
382        12,5 93489 \
383        12,6 442001 \
384        12,7 0 \
385        12,8 0 \
386        12,9 0 \
387        12,10 0 \
388        12,11 0 \
389        12,12 0 \
390        12,13 0 \
391        12,14 0 \
392        12,15 0 \
393        12,16 0 \
394        12,17 0 \
395        12,18 0 \
396        12,19 0 \
397        13,0 0 \
398        13,1 27 \
399        13,2 365 \
400        13,3 3329 \
401        13,4 23297 \
402        13,5 134785 \
403        13,6 0 \
404        13,7 0 \
405        13,8 0 \
406        13,9 0 \
407        13,10 0 \
408        13,11 0 \
409        13,12 0 \
410        13,13 0 \
411        13,14 0 \
412        13,15 0 \
413        13,16 0 \
414        13,17 0 \
415        13,18 0 \
416        13,19 0 \
417        14,0 0 \
418        14,1 29 \
419        14,2 421 \
420        14,3 4117 \
421        14,4 30801 \
422        14,5 189729 \
423        14,6 0 \
424        14,7 0 \
425        14,8 0 \
426        14,9 0 \
427        14,10 0 \
428        14,11 0 \
429        14,12 0 \
430        14,13 0 \
431        14,14 0 \
432        14,15 0 \
433        14,16 0 \
434        14,17 0 \
435        14,18 0 \
436        14,19 0 \
437        15,0 0 \
438        15,1 31 \
439        15,2 481 \
440        15,3 5021 \
441        15,4 40001 \
442        15,5 261497 \
443        15,6 0 \
444        15,7 0 \
445        15,8 0 \
446        15,9 0 \
447        15,10 0 \
448        15,11 0 \
449        15,12 0 \
450        15,13 0 \
451        15,14 0 \
452        15,15 0 \
453        15,16 0 \
454        15,17 0 \
455        15,18 0 \
456        15,19 0 \
457        16,0 0 \
458        16,1 33 \
459        16,2 545 \
460        16,3 6049 \
461        16,4 51137 \
462        16,5 353729 \
463        16,6 0 \
464        16,7 0 \
465        16,8 0 \
466        16,9 0 \
467        16,10 0 \
468        16,11 0 \
469        16,12 0 \
470        16,13 0 \
471        16,14 0 \
472        16,15 0 \
473        16,16 0 \
474        16,17 0 \
475        16,18 0 \
476        16,19 0 \
477        17,0 0 \
478        17,1 35 \
479        17,2 613 \
480        17,3 7209 \
481        17,4 64465 \
482        17,5 470561 \
483        17,6 0 \
484        17,7 0 \
485        17,8 0 \
486        17,9 0 \
487        17,10 0 \
488        17,11 0 \
489        17,12 0 \
490        17,13 0 \
491        17,14 0 \
492        17,15 0 \
493        17,16 0 \
494        17,17 0 \
495        17,18 0 \
496        17,19 0 \
497        18,0 0 \
498        18,1 37 \
499        18,2 685 \
500        18,3 8509 \
501        18,4 80257 \
502        18,5 616657 \
503        18,6 0 \
504        18,7 0 \
505        18,8 0 \
506        18,9 0 \
507        18,10 0 \
508        18,11 0 \
509        18,12 0 \
510        18,13 0 \
511        18,14 0 \
512        18,15 0 \
513        18,16 0 \
514        18,17 0 \
515        18,18 0 \
516        18,19 0 \
517        19,0 0 \
518        19,1 39 \
519        19,2 761 \
520        19,3 9957 \
521        19,4 98801 \
522        19,5 797241 \
523        19,6 0 \
524        19,7 0 \
525        19,8 0 \
526        19,9 0 \
527        19,10 0 \
528        19,11 0 \
529        19,12 0 \
530        19,13 0 \
531        19,14 0 \
532        19,15 0 \
533        19,16 0 \
534        19,17 0 \
535        19,18 0 \
536        19,19 0 \
537    ]
538}
Note: See TracBrowser for help on using the repository browser.