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

Contents of /trunk/pygtk/solver.i

Parent Directory Parent Directory | Revision Log Revision Log


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

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