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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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