/[ascend]/trunk/pygtk/integratorreporter.py
ViewVC logotype

Contents of /trunk/pygtk/integratorreporter.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1129 - (show annotations) (download) (as text)
Sat Jan 13 11:40:59 2007 UTC (14 years ago) by johnpye
File MIME type: text/x-python
File size: 4072 byte(s)
Added integrator_write_matrix routine to allow integrator matrices to be written out.
Modified integrator in PyGTK to output this matrix to a file in /tmp in the case where Integrator::solve fails.
Fixed a bug in densematrix_write_mmio.
The current implementation of integrator_write_matrix might not be quite right yet... needs some more thought.
1 import ascpy
2 import time
3 import sys
4 import gtk
5 import gtk.glade
6 import time
7 from varentry import *
8 from preferences import *
9
10 from observer import *
11
12 # When writing this class, we assume that the integrator class has already had
13 # its "analyse" method called, so we know all that stuff like the number of
14 # observed variables, what our time samples are, what the independent variable
15 # is, etc.
16
17 INTEGRATOR_NUM = 0
18
19 class IntegratorReporterPython(ascpy.IntegratorReporterCxx):
20 def __init__(self,browser,integrator):
21 self.browser=browser
22 ascpy.IntegratorReporterCxx.__init__(self,integrator)
23
24 # GUI elements
25 _xml = gtk.glade.XML(browser.glade_file,"integratorstatusdialog")
26 _xml.signal_autoconnect(self)
27 self.window=_xml.get_widget("integratorstatusdialog")
28 self.window.set_transient_for(self.browser.window)
29 self.label=_xml.get_widget("integratorlabel")
30 self.label.set_text("Solving with "+self.getIntegrator().getEngineName())
31 self.progress=_xml.get_widget("integratorprogress")
32 self.data = None
33
34 self.cancelrequested=False
35
36 def run(self):
37 # run the dialog: start solution, monitor use events
38 try:
39 self.getIntegrator().solve()
40 except RuntimeError,e:
41 self.browser.reporter.reportError("Integrator failed: %s" % e)
42 if self.browser.prefs.getBoolPref("Integrator","writeendmatrix",True):
43 _fn = "/tmp/ascintegratormatrix.mtx"
44 self.browser.reporter.reportNote("Writing matrix to file '%s'" % _fn)
45 _fp = file(_fn,"w")
46 try:
47 try:
48 self.getIntegrator().writeMatrix(_fp)
49 except RuntimeError,e:
50 self.browser.reporter.reportError(str(e))
51 finally:
52 _fp.close()
53 self.window.destroy()
54 return
55
56 def on_cancelbutton_clicked(self,*args):
57 self.cancelrequested=True
58
59 def initOutput(self):
60 # empty out the data table
61 self.data=[]
62 self.nsteps = self.getIntegrator().getNumSteps()
63 self.progress.set_text("Starting...")
64 self.progress.set_fraction(0.0)
65 #update the GUI
66 while gtk.events_pending():
67 gtk.main_iteration()
68 return 1
69
70 def closeOutput(self):
71 global INTEGRATOR_NUM
72 integrator = self.getIntegrator()
73 # create an empty observer
74 try:
75 _xml = gtk.glade.XML(self.browser.glade_file,"observervbox")
76 _label = gtk.Label();
77 INTEGRATOR_NUM = INTEGRATOR_NUM + 1
78 _name = "Integrator %d" % INTEGRATOR_NUM
79 _tab = self.browser.maintabs.append_page(_xml.get_widget("observervbox"),_label)
80 _obs = ObserverTab(xml=_xml, name=_name, browser=self.browser, tab=_tab, alive=False)
81 _label.set_text(_obs.name)
82 self.browser.observers.append(_obs)
83 self.browser.tabs[_tab]=_obs
84
85 # add the columns
86 _obs.add_instance(integrator.getIndependentVariable().getInstance())
87 for _v in [integrator.getObservedVariable(_i) for _i in range(0,integrator.getNumObservedVars())]:
88 _obs.add_instance(_v.getInstance())
89
90 for _time,_vals in self.data:
91 _obs.do_add_row([_time]+[_v for _v in _vals])
92 except Exception,e:
93 sys.stderr.write("\n\n\nCAUGHT EXCEPTION: %s\n\n\n" % str(e))
94 return 0
95
96 def closeOutput1(self):
97 # output the results (to the console, for now)
98 for _t,_vals in self.data:
99 print _t,_vals
100
101 self.progress.set_fraction(1.0)
102 self.progress.set_text("Finished.")
103 return 1
104
105 def updateStatus(self):
106 # outdate the GUI
107 try:
108 # TODO: change so it's not updating every step!
109 t = self.getIntegrator().getCurrentTime()
110 _frac = float(self.getIntegrator().getCurrentStep())/self.nsteps
111 self.progress.set_text("t = %f" % (self.getIntegrator().getCurrentTime()))
112 self.progress.set_fraction(_frac)
113 while gtk.events_pending():
114 gtk.main_iteration()
115 if self.cancelrequested:
116 return 0
117 return 1
118 except Exception,e:
119 print "\n\nERROR IN UPDATESTATUS!",str(e)
120 return 0
121
122 def recordObservedValues(self):
123 # just add to our in-memory data structure for now...
124 try:
125 i = self.getIntegrator()
126 print str(i.getCurrentObservations())
127 self.data.append((i.getCurrentTime(),i.getCurrentObservations()))
128 except Exception,e:
129 print "\n\nERROR IN RECORDOBSERVEDVALUES!",str(e)
130 return 0
131 return 1
132
133
134

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22