/[ascend]/trunk/pygtk/solver.i
ViewVC logotype

Contents of /trunk/pygtk/solver.i

Parent Directory Parent Directory | Revision Log Revision Log


Revision 942 - (show annotations) (download)
Sat Nov 25 05:26:47 2006 UTC (14 years, 2 months ago) by johnpye
File size: 5688 byte(s)
Incorporated 'SolverParameters' functionality into 'Integrator', both at C level and C++/Python.
This shouldn't break Tcl/Tk as default parameters will be set and used invisibly.
1 /*
2 SWIG interface for accessing Solver and choosing solver parameters
3 */
4
5 %{
6 #include "integrator.h"
7 #include "integratorreporter.h"
8 %}
9
10 %template(VariableVector) std::vector<Variable>;
11 %template(RelationVector) std::vector<Relation>;
12 %template(SolverVector) std::vector<Solver>;
13
14 %ignore registerSolver;
15 %ignore registerStandardSolvers;
16 %include "solver.h"
17
18 %include "simulation.h"
19 // SOLVE PARAMETERS
20
21 %pythoncode{
22 class SolverParameterIter:
23 def __init__(self, params):
24 self.params = params;
25 self.index = 0;
26
27 def __iter__(self):
28 return self
29
30 def next(self):
31 self.index = self.index + 1
32 if self.index >= self.params.getLength():
33 raise StopIteration
34 print "INDEX = %d" % self.index
35 return self.params.getParameter(self.index)
36 }
37
38 class SolverParameters{
39 public:
40 const std::string toString();
41 SolverParameters(const SolverParameters &);
42 const int getLength() const;
43 SolverParameter getParameter(const int &) const;
44 };
45
46 %extend SolverParameters{
47 %pythoncode{
48 def __iter__(self):
49 return SolverParameterIter(self)
50 def __getitem__(self,index):
51 return self.getParameter(index)
52 def __len__(self):
53 return self.getLength()
54 }
55 }
56
57 class SolverParameter{
58 public:
59 explicit SolverParameter(slv_parameter *);
60
61 const std::string getName() const;
62 const std::string getDescription() const;
63 const std::string getLabel() const;
64 const int &getNumber() const;
65 const int &getPage() const;
66
67 const bool isInt() const;
68 const bool isBool() const;
69 const bool isStr() const;
70 const bool isReal() const;
71
72 // The following throw execeptions unless the parameter type is correct
73 const int &getIntValue() const;
74 const int &getIntLowerBound() const;
75 const int &getIntUpperBound() const;
76 void setIntValue(const int&);
77
78 const bool getBoolValue() const;
79 void setBoolValue(const bool&);
80
81 const std::string getStrValue() const;
82 const std::vector<std::string> getStrOptions() const;
83 void setStrValue(const std::string &);
84 void setStrOption(const int &opt);
85
86 const double &getRealValue() const;
87 const double &getRealLowerBound() const;
88 const double &getRealUpperBound() const;
89 void setRealValue(const double&);
90
91 const bool isBounded() const;
92
93 const std::string toString() const;
94 };
95
96 %extend SolverParameter{
97 %pythoncode{
98 def __str__(self):
99 if self.isInt(): return "%s = %d" %(self.getName(),self.getIntValue())
100 if self.isBool(): return "%s = %s" %(self.getName(),self.getBoolValue())
101 if self.isStr(): return "%s = %s" %(self.getName(),self.getStrValue())
102 if self.isReal(): return "%s = %f" %(self.getName(),self.getRealValue())
103 }
104 }
105
106 /* Incidence matrix stuff */
107 typedef enum{
108 IM_NULL=0, IM_ACTIVE_FIXED, IM_ACTIVE_FREE, IM_DORMANT_FIXED, IM_DORMANT_FREE
109 } IncidencePointType;
110
111 class IncidencePoint{
112 public:
113 IncidencePoint(const IncidencePoint &);
114
115 int row;
116 int col;
117 IncidencePointType type;
118 };
119
120 %extend IncidencePoint{
121 %pythoncode{
122 def __repr__(self):
123 return str([ self.row, self.col, int(self.type) ]);
124 }
125 }
126
127 %template(IncidencePointVector) std::vector<IncidencePoint>;
128
129 class IncidenceMatrix{
130 public:
131 explicit IncidenceMatrix(Simulation &);
132 const std::vector<IncidencePoint> &getIncidenceData();
133 const int &getNumRows() const;
134 const int &getNumCols() const;
135 const Variable getVariable(const int &col);
136 const Relation getRelation(const int &col);
137 const int getBlockRow(const int &row) const;
138 const std::vector<Variable> getBlockVars(const int block);
139 const std::vector<Relation> getBlockRels(const int block);
140 const std::vector<int> getBlockLocation(const int &block) const;
141 const int getNumBlocks();
142 };
143
144
145 /* Variables and relations belong to solvers, so they're here: */
146
147
148 %include "variable.h"
149
150 %extend Variable {
151 %pythoncode{
152 def __repr__(self):
153 return self.getName()
154 }
155 }
156
157 class Relation{
158 public:
159 explicit Relation(const Relation &old);
160 const std::string getName();
161 const double &getResidual();
162 const std::vector<Variable> getIncidentVariables() const;
163 const int getNumIncidentVariables() const;
164 Instanc getInstance() const;
165 std::string getRelationAsString() const;
166 };
167
168 %extend Relation {
169 %pythoncode{
170 def __repr__(self):
171 return self.getName()
172 }
173 }
174
175
176 class SolverStatus{
177 public:
178 SolverStatus();
179 explicit SolverStatus(const SolverStatus &old);
180 void getSimulationStatus(Simulation &);
181
182 const bool isOK() const;
183 const bool isOverDefined() const;
184 const bool isUnderDefined() const;
185 const bool isStructurallySingular() const;
186 const bool isInconsistent() const;
187 const bool isReadyToSolve() const;
188 const bool isConverged() const;
189 const bool isDiverged() const;
190 const bool hasResidualCalculationErrors() const;
191 const bool hasExceededIterationLimit() const;
192 const bool hasExceededTimeLimit() const;
193 const bool isInterrupted() const;
194 const int getIterationNum() const;
195
196 // block structure stuff...
197
198 const int getNumBlocks() const;
199 const int getCurrentBlockNum() const;
200 const int getCurrentBlockSize() const;
201 const int getCurrentBlockIteration() const;
202 const int getNumConverged() const; /* previous total size */
203 const int getNumJacobianEvals() const;
204 const int getNumResidualEvals() const;
205 const double getBlockResidualRMS() const;
206
207 };
208
209 %feature("director") SolverReporter;
210
211 class SolverReporter{
212 public:
213 SolverReporter();
214 virtual ~SolverReporter();
215 virtual int report(SolverStatus *status);
216 virtual void finalise(SolverStatus *status);
217 };
218
219 %apply SWIGTYPE *DISOWN { IntegratorReporterCxx *reporter };
220
221 %include "integrator.h"
222
223 %feature("director") IntegratorReporterCxx;
224
225 %ignore ascxx_integratorreporter_init;
226 %ignore ascxx_integratorreporter_write;
227 %ignore ascxx_integratorreporter_write_obs;
228 %ignore ascxx_integratorreporter_close;
229
230 %include "integratorreporter.h"

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