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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 897 by johnpye, Tue Oct 24 11:05:18 2006 UTC revision 898 by johnpye, Tue Oct 24 13:34:13 2006 UTC
# Line 7  def listnotes(self): Line 7  def listnotes(self):
7      self = ascpy.Registry().getInstance('context')      self = ascpy.Registry().getInstance('context')
8    
9      db = browser.library.getAnnotationDatabase()      db = browser.library.getAnnotationDatabase()
10      notes = db.getNotes(self.getType())      notes = db.getNotes(self.getType(),ascpy.SymChar("solver"))
11    
12      for i in range(1,len(notes)):      for i in range(1,len(notes)):
13          mm = notes[i].getMethod()          mm = notes[i].getMethod()
14            ll = notes[i].getLanguage()
15          ii = notes[i].getId()          ii = notes[i].getId()
16          tt = notes[i].getText()          tt = notes[i].getText()
17          s = "type = %s, method = %s, id = %s, text = %s" % (notes[i].getType(), mm, ii, tt)          s = "type = %s, method = %s, lang = %s, id = %s, text = %s" % (notes[i].getType(), mm, ll, ii, tt)
18          print "NOTES:",s          print "NOTES:",s
19          browser.reporter.reportNote(s)          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)  extpy.registermethod(listnotes)
81    extpy.registermethod(setup_solver)

Legend:
Removed from v.897  
changed lines
  Added in v.898

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