1 |
#include "config.h" |
2 |
#include "reporter.h" |
3 |
#include "solver.h" |
4 |
|
5 |
#include <stdexcept> |
6 |
#include <iostream> |
7 |
#include <sstream> |
8 |
using namespace std; |
9 |
|
10 |
extern "C"{ |
11 |
#include <ascend/system/system.h> |
12 |
#include <ascend/solver/solver.h> |
13 |
#include <ascend/solver/slvDOF.h> |
14 |
} |
15 |
|
16 |
/** |
17 |
Create a solver by name (it must already be registered) |
18 |
Warning, this ctor throws an exception if the name is invalid! |
19 |
*/ |
20 |
Solver::Solver(const string &name){ |
21 |
//cerr << "CREATING SOLVER, name = " << name << endl; |
22 |
this->name = name; |
23 |
} |
24 |
|
25 |
Solver::Solver(const Solver &old){ |
26 |
this->name = old.name; |
27 |
//cerr << "COPIED SOLVER, name = " << name << endl; |
28 |
} |
29 |
|
30 |
Solver::Solver(){ |
31 |
//cerr << "RETREIVING SOLVER NAME" << name << endl; |
32 |
this->name = ""; |
33 |
} |
34 |
|
35 |
const int |
36 |
Solver::getIndex() const{ |
37 |
int index = slv_lookup_client(name.c_str()); |
38 |
if(index < 0){ |
39 |
stringstream ss; |
40 |
ss << "Unknown or unregistered solver '" << name << "'"; |
41 |
throw runtime_error(ss.str()); |
42 |
} |
43 |
//cerr << "))))))))))))))SOLVER INDEX RETURNED IS " << index << endl;s |
44 |
return index; |
45 |
} |
46 |
|
47 |
const string & |
48 |
Solver::getName() const{ |
49 |
return name; |
50 |
} |
51 |
|
52 |
//--------------------------------- |
53 |
// >>>> GLOBAL FUNCTIONS <<<< |
54 |
// for registering solvers and querying the complete list |
55 |
|
56 |
#if 0 |
57 |
void |
58 |
registerSolver(SlvRegistration regfuncptr){ |
59 |
int newclient =-1; |
60 |
int res = solver_register(slv_register_client(regfuncptr,NULL,NULL,&newclient); |
61 |
if(res!=0){ |
62 |
ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"Unable to register solver"); |
63 |
throw runtime_error("Solver::registerSolver: Unable to register solver"); |
64 |
e }else{ |
65 |
string name = slv_solver_name(newclient); |
66 |
cerr << "Registered solver '" << name << "' (index " << newclient << ")" << endl; |
67 |
} |
68 |
} |
69 |
#endif |
70 |
|
71 |
const vector<Solver> |
72 |
getSolvers(){ |
73 |
const struct gl_list_t *L = solver_get_engines(); |
74 |
vector<Solver> v; |
75 |
for(unsigned long i=1; i <= gl_length(L); ++i){ |
76 |
v.push_back(Solver( ( (SlvFunctionsT *)(gl_fetch(L,i)))->name) ); |
77 |
} |
78 |
return v; |
79 |
} |
80 |
|
81 |
/** |
82 |
Register the solvers which will be accessible via index number. The order you |
83 |
register them determines the resulting index ids, so don't mess around with the |
84 |
order of stuff in this function. |
85 |
|
86 |
Add to this list as you feel necessary... |
87 |
*/ |
88 |
void |
89 |
registerStandardSolvers(){ |
90 |
//cerr << "------------- REGISTERING SOLVERS -----------------" << endl; |
91 |
SlvRegisterStandardClients(); |
92 |
/* |
93 |
registerSolver(slv3_register); |
94 |
registerSolver(slv9_register); |
95 |
*/ |
96 |
} |
97 |
|