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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 900 - (show annotations) (download) (as text)
Wed Oct 25 06:03:04 2006 UTC (13 years, 11 months ago) by johnpye
File MIME type: text/x-python
File size: 2231 byte(s)
The 'sim' object is correctly accessible from script methods now, even if run during on_load.
Added 'getSimulation' to registry.cpp, added 'runDefaultMethod' to Simulation, added 'getMethod' to Type.
Running of 'on_load' is instigated at the Python level now, so that relevent python variables are set at simulations are built, etc. This appears to have cause some changes to the way the solver behaves, possibly.
Added SearchProcList to exports in libascend.

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 print "SETUP_SOLVER..."
24 self = ascpy.Registry().getInstance('context')
25 sim = ascpy.Registry().getSimulation('sim')
26
27 reporter = browser.reporter
28
29 db = browser.library.getAnnotationDatabase()
30
31 print "GOT SIM..."
32
33 if not sim:
34 reporter.reportError("No simulation present yet")
35 return
36
37 if not browser.solver:
38 reporter.reportError("No solver yet")
39 return
40
41 solvername = browser.solver.getName()
42 reporter.reportNote("Active solver is '%s'" % solvername)
43
44 notes = db.getNotes(self.getType(),ascpy.SymChar(solvername))
45
46 print "GETTINGS SOLVER PARAMS..."
47
48 params = sim.getSolverParameters()
49
50 print "DONE SOLVER PARAMS"
51
52 print params
53
54 paramnames = [p.getName() for p in params]
55
56 print "DONE PARAMS"
57
58 for i in range(0,len(notes)):
59 note = notes[i]
60
61 if note.getId()==None:
62 #browser.reporter.reportNote("Empty note ID...")
63 continue
64 n = note.getId()
65 param = None
66 for p in params:
67 if p.getName()==n:
68 param = p
69 if param:
70 if param.isInt():
71 v = int( note.getText() )
72 param.setIntValue(v)
73 elif param.isReal():
74 v = float( note.getText() )
75 param.setRealValue(v)
76 elif param.isString():
77 v = note.getText()
78 param.setStrValue(v)
79 elif param.isBool():
80 v = bool( note.getText() )
81 param.setBoolValue(v)
82 else:
83 raise Exception("unknown parameter type")
84 reporter.reportNote("Set %s = %s" % (param.getName(),v))
85 else:
86 reporter.reportWarning("Parameter '%s' is not valid for solver '%s'" % (n,solvername))
87
88 extpy.registermethod(listnotes)
89 extpy.registermethod(setup_solver)

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