/[ascend]/trunk/models/johnpye/listnotes.py
ViewVC logotype

Contents of /trunk/models/johnpye/listnotes.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 898 - (show annotations) (download) (as text)
Tue Oct 24 13:34:13 2006 UTC (15 years, 9 months ago) by johnpye
File MIME type: text/x-python
File size: 2548 byte(s)
Added 'solver notes' to thermalequilibrium.a4c.
Added 'setup_solver' method in listnotes.py
Added 'getLanguage' to Annotation class
Added 'paramname' to SolverParameters popup in PyGTK
Fixed up some commenting in notate.c
Turned on warning about ignored notes in ascParse.y
1 import ascpy
2 import extpy
3 browser = extpy.getbrowser()
4
5 def listnotes(self):
6 """ make a list of NOTES for the present model """
7 self = ascpy.Registry().getInstance('context')
8
9 db = browser.library.getAnnotationDatabase()
10 notes = db.getNotes(self.getType(),ascpy.SymChar("solver"))
11
12 for i in range(1,len(notes)):
13 mm = notes[i].getMethod()
14 ll = notes[i].getLanguage()
15 ii = notes[i].getId()
16 tt = notes[i].getText()
17 s = "type = %s, method = %s, lang = %s, id = %s, text = %s" % (notes[i].getType(), mm, ll, ii, tt)
18 print "NOTES:",s
19 browser.reporter.reportNote(s)
20
21 def setup_solver(self):
22 """ use the NOTES DB to configure solver parameters for the current model """
23 self = ascpy.Registry().getInstance('context')
24 sim = browser.sim
25 reporter = browser.reporter
26
27 # at present this code is pretty clunky because of the bare-bone code in the wrapper API.
28 # this could be improved a lot with some python wizardry for iterators, __getitem__ etc.
29
30 db = browser.library.getAnnotationDatabase()
31
32 solvernotes = db.getNotes(self.getType(),ascpy.SymChar("solver"),ascpy.SymChar("name"))
33 if len(solvernotes) > 1:
34 reporter.reportNote("Multiple solvers specified in NOTES for model '%s'", sim.getType())
35 elif len(solvernotes) == 1:
36 solver = ascpy.Solver(solvernotes[0].getText())
37 reporter.reportNote("Setting solver to '%s'" % solver.getName())
38 sim.setSolver(solver)
39 else:
40 reporter.reportNote("No solver specified in NOTES , using current")
41
42 solvername = sim.getSolver().getName()
43 #reporter.reportNote("Parameters for solver '%s'" % solvername)
44
45 notes = db.getNotes(self.getType(),ascpy.SymChar(solvername))
46
47 params = sim.getSolverParameters()
48 paramnames = [p.getName() for p in params]
49
50 for i in range(0,len(notes)):
51 note = notes[i]
52
53 if note.getId()==None:
54 #browser.reporter.reportNote("Empty note ID...")
55 continue
56 n = note.getId()
57 param = None
58 for p in params:
59 if p.getName()==n:
60 param = p
61 if param:
62 if param.isInt():
63 v = int( note.getText() )
64 param.setIntValue(v)
65 elif param.isReal():
66 v = float( note.getText() )
67 param.setRealValue(v)
68 elif param.isString():
69 v = note.getText()
70 param.setStrValue(v)
71 elif param.isBool():
72 v = bool( note.getText() )
73 param.setBoolValue(v)
74 else:
75 raise Exception("unknown parameter type")
76 reporter.reportNote("Set %s = %s" % (param.getName(),v))
77 else:
78 reporter.reportWarning("Parameter '%s' is not valid for solver '%s'" % (n,solvername))
79
80 extpy.registermethod(listnotes)
81 extpy.registermethod(setup_solver)

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