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

Contents of /trunk/pygtk/solver.i

Parent Directory Parent Directory | Revision Log Revision Log


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

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