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

Contents of /trunk/pygtk/interface/solver.i

Parent Directory Parent Directory | Revision Log Revision Log


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

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