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

Contents of /trunk/pygtk/integratorreporter.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 903 - (show annotations) (download) (as text)
Wed Oct 25 13:07:12 2006 UTC (17 years, 11 months ago) by johnpye
File MIME type: text/x-python
File size: 3602 byte(s)
Some success with IDA: fixed up the indexing dilemma and was able to
integrate 'johnpye/thermalequilibrium.a4c' for a short time span (but
through to 3000 s as with LSODE). I would blame lack of jacobian routine
in the first instance.

Added 'more properties' button in Properties dialog for a variable, to allow
values of ode_id, ode_type etc to be queried (but not changed).

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 _res = self.getIntegrator().solve()
39 self.window.destroy()
40 return _res
41
42 def on_cancelbutton_clicked(self,*args):
43 self.cancelrequested=True
44
45 def initOutput(self):
46 # empty out the data table
47 self.data=[]
48 self.nsteps = self.getIntegrator().getNumSteps()
49 self.progress.set_text("Starting...")
50 self.progress.set_fraction(0.0)
51 #update the GUI
52 while gtk.events_pending():
53 gtk.main_iteration()
54 return 1
55
56 def closeOutput(self):
57 global INTEGRATOR_NUM
58 integrator = self.getIntegrator()
59 # create an empty observer
60 try:
61 _xml = gtk.glade.XML(self.browser.glade_file,"observervbox")
62 _label = gtk.Label();
63 INTEGRATOR_NUM = INTEGRATOR_NUM + 1
64 _name = "Integrator %d" % INTEGRATOR_NUM
65 _tab = self.browser.maintabs.append_page(_xml.get_widget("observervbox"),_label)
66 _obs = ObserverTab(xml=_xml, name=_name, browser=self.browser, tab=_tab, alive=False)
67 _label.set_text(_obs.name)
68 self.browser.observers.append(_obs)
69 self.browser.tabs[_tab]=_obs
70
71 # add the columns
72 _obs.add_instance(integrator.getIndependentVariable().getInstance())
73 for _v in [integrator.getObservedVariable(_i) for _i in range(0,integrator.getNumObservedVars())]:
74 _obs.add_instance(_v.getInstance())
75
76 for _time,_vals in self.data:
77 _obs.do_add_row([_time]+[_v for _v in _vals])
78 except Exception,e:
79 sys.stderr.write("\n\n\nCAUGHT EXCEPTION: %s\n\n\n" % str(e))
80 return 0
81
82 def closeOutput1(self):
83 # output the results (to the console, for now)
84 for _t,_vals in self.data:
85 print _t,_vals
86
87 self.progress.set_fraction(1.0)
88 self.progress.set_text("Finished.")
89 return 1
90
91 def updateStatus(self):
92 # outdate the GUI
93 try:
94 # TODO: change so it's not updating every step!
95 t = self.getIntegrator().getCurrentTime()
96 _frac = float(self.getIntegrator().getCurrentStep())/self.nsteps
97 self.progress.set_text("t = %f" % (self.getIntegrator().getCurrentTime()))
98 self.progress.set_fraction(_frac)
99 while gtk.events_pending():
100 gtk.main_iteration()
101 if self.cancelrequested:
102 return 0
103 return 1
104 except Exception,e:
105 print "\n\nERROR IN UPDATESTATUS!",str(e)
106 return 0
107
108 def recordObservedValues(self):
109 # just add to our in-memory data structure for now...
110 try:
111 i = self.getIntegrator()
112 print str(i.getCurrentObservations())
113 self.data.append((i.getCurrentTime(),i.getCurrentObservations()))
114 except Exception,e:
115 print "\n\nERROR IN RECORDOBSERVEDVALUES!",str(e)
116 return 0
117 return 1
118
119
120

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