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

Contents of /trunk/pygtk/integratorreporter.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 669 - (show annotations) (download) (as text)
Wed Jun 21 07:00:45 2006 UTC (13 years, 2 months ago) by johnpye
File MIME type: text/x-python
File size: 2408 byte(s)
Merged changes from DAE branch (revisions 702 to 819) back into trunk.
This adds the Integration API to the ASCEND solver (in base/generic).
Also provides pre-alpha support for 'IDA' from the SUNDIALS suite, a DAE solver.
Many other minor code clean-ups, including adoption of new 'ASC_NEW' and friends (to replace 'ascmalloc')
Added some very sketchy stuff providing 'DIFF(...)' syntax, although it is anticipated that this will be removed.
1 import ascpy
2 import time
3 import gtk
4 import gtk.glade
5 import time
6 from varentry import *
7 from preferences import *
8
9 # When writing this class, we assume that the integrator class has already had
10 # its "analyse" method called, so we know all that stuff like the number of
11 # observed variables, what our time samples are, what the independent variable
12 # is, etc.
13
14 class IntegratorReporterPython(ascpy.IntegratorReporterCxx):
15 def __init__(self,browser,integrator):
16 self.browser=browser
17 ascpy.IntegratorReporterCxx.__init__(self,integrator)
18
19 # GUI elements
20 _xml = gtk.glade.XML(browser.glade_file,"integratorstatusdialog")
21 _xml.signal_autoconnect(self)
22 self.window=_xml.get_widget("integratorstatusdialog")
23 self.window.set_transient_for(self.browser.window)
24 self.label=_xml.get_widget("integratorlabel")
25 self.label.set_text("Solving with "+self.getIntegrator().getEngineName())
26 self.progress=_xml.get_widget("integratorprogress")
27 self.data = None
28
29 def run(self):
30 # run the dialog: start solution, monitor use events
31 _res = self.getIntegrator().solve()
32 self.window.destroy()
33 return _res
34
35 def initOutput(self):
36 # empty out the data table
37 self.data=[]
38 self.nsteps = self.getIntegrator().getNumSteps()
39 self.progress.set_text("Starting...")
40 self.progress.set_fraction(0.0);
41 #update the GUI
42 while gtk.events_pending():
43 gtk.main_iteration()
44 return 1
45
46 def closeOutput(self):
47 # output the results (to the console, for now)
48 for _k,_v in self.data:
49 print _k,_v
50
51 self.progress.set_fraction(1.0);
52 self.progress.set_text("Finished.")
53 return 1
54
55 def updateStatus(self):
56 # outdate the GUI
57 try:
58 # TODO: change so it's not updating every step!
59 t = self.getIntegrator().getCurrentTime()
60 _frac = float(self.getIntegrator().getCurrentStep())/self.nsteps
61 self.progress.set_text("t = %f" % (self.getIntegrator().getCurrentTime()))
62 self.progress.set_fraction(_frac)
63 while gtk.events_pending():
64 gtk.main_iteration()
65 return 1
66 except Exception,e:
67 print "\n\nERROR IN UPDATESTATUS!",str(e)
68 return 0
69
70 def recordObservedValues(self):
71 # just add to our in-memory data structure for now...
72 try:
73 i = self.getIntegrator()
74 print str(i.getCurrentObservations())
75 self.data.append((i.getCurrentTime(),i.getCurrentObservations()))
76 except Exception,e:
77 print "\n\nERROR IN RECORDOBSERVEDVALUES!",str(e)
78 return 0
79 return 1

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