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

Annotation of /trunk/pygtk/interface/solver.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 154 - (hide annotations) (download) (as text)
Thu Dec 22 15:18:02 2005 UTC (16 years, 11 months ago) by johnpye
File MIME type: text/x-c++src
File size: 2181 byte(s)
Removing debug output, adding self_test to iapws95.
1 johnpye 132 #include "reporter.h"
2    
3     #include <stdexcept>
4     #include <iostream>
5 johnpye 150 #include <sstream>
6 johnpye 132 using namespace std;
7    
8     #include "solver.h"
9    
10     extern "C"{
11 johnpye 150 #include <solver/slv0.h>
12     #include <solver/slv1.h>
13     #include <solver/slv2.h>
14 johnpye 132 #include <solver/slv3.h>
15 johnpye 150 #include <solver/slv9.h>
16 johnpye 132 }
17    
18     /**
19 johnpye 150 Create a solver by name (it must already be registered)
20     Warning, this ctor throws an exception if the name is invalid!
21 johnpye 132 */
22 johnpye 150 Solver::Solver(const string &name){
23 johnpye 154 //cerr << "CREATING SOLVER, name = " << name << endl;
24 johnpye 150 this->name = name;
25 johnpye 132 }
26    
27     Solver::Solver(const Solver &old){
28 johnpye 150 this->name = old.name;
29 johnpye 154 //cerr << "COPIED SOLVER, name = " << name << endl;
30 johnpye 132 }
31    
32 johnpye 150 const int
33 johnpye 132 Solver::getIndex() const{
34 johnpye 150 int index = slv_lookup_client(name.c_str());
35     if(index < 0){
36     stringstream ss;
37     ss << "Unknown or unregistered solver '" << name << "'";
38     throw runtime_error(ss.str());
39     }
40 johnpye 154 //cerr << "))))))))))))))SOLVER INDEX RETURNED IS " << index << endl;
41 johnpye 132 return index;
42     }
43    
44 johnpye 150 const string &
45 johnpye 132 Solver::getName() const{
46 johnpye 150 return name;
47 johnpye 132 }
48    
49     //---------------------------------
50     // global functions for registering solvers and querying the complete list
51    
52     void
53     registerSolver(SlvRegistration regfuncptr){
54 johnpye 151 int newclient =-1;
55 johnpye 150 int res = slv_register_client(regfuncptr,NULL,NULL,&newclient);
56 johnpye 132 if(res!=0){
57     error_reporter(ASC_PROG_ERROR,NULL,0,"Unable to register solver");
58     throw runtime_error("Solver::registerSolver: Unable to register solver");
59     }else{
60 johnpye 150 string name = slv_solver_name(newclient);
61 johnpye 151 error_reporter(ASC_PROG_NOTE,NULL,0,"Registered solver '%s' (index %d)\n", name.c_str(), newclient );
62 johnpye 132 }
63     }
64    
65     const vector<Solver>
66     getSolvers(){
67     extern int g_SlvNumberOfRegisteredClients;
68     vector<Solver> v;
69     for(int i=0; i < g_SlvNumberOfRegisteredClients; ++i){
70 johnpye 150 v.push_back(Solver(slv_solver_name(i)));
71 johnpye 132 }
72     return v;
73     }
74    
75     /**
76     Register the solvers which will be accessible via index number. The order you
77     register them determines the resulting index ids, so don't mess around with the
78     order of stuff in this function.
79    
80     Add to this list as you feel necessary...
81     */
82     void
83     registerStandardSolvers(){
84 johnpye 154 //cerr << "------------- REGISTERING SOLVERS -----------------" << endl;
85 johnpye 132 registerSolver(slv3_register);
86 johnpye 150 registerSolver(slv9_register);
87 johnpye 132 }
88    

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