/[ascend]/trunk/pygtk/simulation.cpp
ViewVC logotype

Diff of /trunk/pygtk/simulation.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 164 by johnpye, Tue Jan 3 09:54:43 2006 UTC revision 190 by johnpye, Mon Jan 16 08:53:30 2006 UTC
# Line 57  extern "C"{ Line 57  extern "C"{
57  Simulation::Simulation(Instance *i, const SymChar &name) : Instanc(i, name), simroot(GetSimulationRoot(i),SymChar("simroot")){  Simulation::Simulation(Instance *i, const SymChar &name) : Instanc(i, name), simroot(GetSimulationRoot(i),SymChar("simroot")){
58      is_built = false;      is_built = false;
59      // Create an Instance object for the 'simulation root' (we'll call      // Create an Instance object for the 'simulation root' (we'll call
60      // it the 'simulation model') and it can be fetched using 'getModel()'      // it the 'simulation model') and it can be fetched using 'getModel()'
61      // any time later.      // any time later.
62      //simroot = Instanc(GetSimulationRoot(i),name);      //simroot = Instanc(GetSimulationRoot(i),name);
63  }  }
# Line 69  Simulation::Simulation(const Simulation Line 69  Simulation::Simulation(const Simulation
69      bin_objname = old.bin_objname;      bin_objname = old.bin_objname;
70      bin_libname = old.bin_libname;      bin_libname = old.bin_libname;
71      bin_cmd = old.bin_cmd;      bin_cmd = old.bin_cmd;
72      bin_rm = old.bin_rm;          bin_rm = old.bin_rm;
73  }  }
74    
75  Simulation::~Simulation(){  Simulation::~Simulation(){
# Line 93  Simulation::checkDoF() const{ Line 93  Simulation::checkDoF() const{
93          }          }
94          slvDOF_status(sys, &status, &dof);          slvDOF_status(sys, &status, &dof);
95          switch(status){          switch(status){
96                  case 1: error_reporter(ASC_USER_ERROR,NULL,0,"Underspecified; %d degrees of freedom",dof); break;                  case 1: ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Underspecified; %d degrees of freedom",dof); break;
97                  case 2: error_reporter(ASC_USER_NOTE,NULL,0,"Square"); break;                  case 2: ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"Square"); break;
98                  case 3: error_reporter(ASC_USER_ERROR,NULL,0,"Structurally singular"); break;                  case 3: ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Structurally singular"); break;
99                  case 4: error_reporter(ASC_USER_ERROR,NULL,0,"Overspecified"); break;                  case 4: ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Overspecified"); break;
100                  case 5:                  case 5:
101                          throw runtime_error("Unable to resolve degrees of freedom"); break;                          throw runtime_error("Unable to resolve degrees of freedom"); break;
102                  default:                  default:
# Line 117  Simulation::run(const Method &method){ Line 117  Simulation::run(const Method &method){
117      );      );
118    
119      if(pe == Proc_all_ok){      if(pe == Proc_all_ok){
120          error_reporter(ASC_PROG_NOTE,NULL,0,"Method '%s' was run (check above for errors)\n",method.getName());          ERROR_REPORTER_NOLINE(ASC_PROG_NOTE,"Method '%s' was run (check above for errors)\n",method.getName());
121          //cerr << "METHOD " << method.getName() << " COMPLETED OK" << endl;          //cerr << "METHOD " << method.getName() << " COMPLETED OK" << endl;
122      }else{      }else{
123          stringstream ss;          stringstream ss;
# Line 199  Simulation::check(){ Line 199  Simulation::check(){
199      Instance *i1 = getModel().getInternalType();      Instance *i1 = getModel().getInternalType();
200      CheckInstance(stderr, &*i1);      CheckInstance(stderr, &*i1);
201      cerr << "...DONE CHECKING" << endl;      cerr << "...DONE CHECKING" << endl;
202  }        }
203    
204  void  void
205  Simulation::build(){  Simulation::build(){
# Line 227  Simulation::getFixableVariables(){ Line 227  Simulation::getFixableVariables(){
227    
228      // Get IDs of elegible variables in array at vip...      // Get IDs of elegible variables in array at vip...
229      if(!slvDOF_eligible(sys,vip)){      if(!slvDOF_eligible(sys,vip)){
230          error_reporter(ASC_USER_NOTE,NULL,0,"No fixable variables found.");          ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"No fixable variables found.");
231      }else{      }else{
232          //cerr << "FIXABLE VARS FOUND" << endl;          //cerr << "FIXABLE VARS FOUND" << endl;
233          struct var_variable **vp = slv_get_solvers_var_list(sys);          struct var_variable **vp = slv_get_solvers_var_list(sys);
# Line 240  Simulation::getFixableVariables(){ Line 240  Simulation::getFixableVariables(){
240          if(vp==NULL){          if(vp==NULL){
241              throw runtime_error("Simulation variable list is null");              throw runtime_error("Simulation variable list is null");
242          }          }
243        
244          // iterate through this list until we find a -1:          // iterate through this list until we find a -1:
245          int i=0;          int i=0;
246          int var_index = (*vip)[i];          int var_index = (*vip)[i];
# Line 255  Simulation::getFixableVariables(){ Line 255  Simulation::getFixableVariables(){
255              ++i;              ++i;
256              var_index = (*vip)[i];              var_index = (*vip)[i];
257          }          }
258          error_reporter(ASC_USER_NOTE,NULL,0,"Found %d fixable variables.",i);          ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"Found %d fixable variables.",i);
259          //cerr << "END ELEGIBLE VARS LIST" << endl;          //cerr << "END ELEGIBLE VARS LIST" << endl;
260          ascfree(*vip);          ascfree(*vip);
261          //cerr << "FREED VIP LIST" << endl;          //cerr << "FREED VIP LIST" << endl;
# Line 274  Simulation::solve(Solver solver){ Line 274  Simulation::solve(Solver solver){
274      cerr << "SIMULATION::SOLVE STARTING..." << endl;      cerr << "SIMULATION::SOLVE STARTING..." << endl;
275      enum inst_t k = getModel().getKind();      enum inst_t k = getModel().getKind();
276      if(k!=MODEL_INST)throw runtime_error("Can't solve: not an instance of type MODEL_INST");      if(k!=MODEL_INST)throw runtime_error("Can't solve: not an instance of type MODEL_INST");
277        
278      Instance *i1 = getInternalType();      Instance *i1 = getInternalType();
279      int npend = NumberPendingInstances(&*i1);      int npend = NumberPendingInstances(&*i1);
280      if(npend)throw runtime_error("Can't solve: There are still %d pending instances");        if(npend)throw runtime_error("Can't solve: There are still %d pending instances");
281    
282      if(!sys)throw runtime_error("Can't solve: Simulation system has not been built yet.");      if(!sys)throw runtime_error("Can't solve: Simulation system has not been built yet.");
283        
284      cerr << "SIMULATION::SOLVE: SET SOLVER..." << endl;      cerr << "SIMULATION::SOLVE: SET SOLVER..." << endl;
285      setSolver(solver);      setSolver(solver);
286        
287        
288      cerr << "PRESOLVING SYSTEM..." << endl;      cerr << "PRESOLVING SYSTEM..." << endl;
289      slv_presolve(sys);      slv_presolve(sys);
290      cerr << "... DONE PRESOLVING" << endl;      cerr << "... DONE PRESOLVING" << endl;
291        
292      cerr << "SOLVING SYSTEM..." << endl;      cerr << "SOLVING SYSTEM..." << endl;
293      slv_solve(sys);      slv_solve(sys);
294    
# Line 297  Simulation::solve(Solver solver){ Line 297  Simulation::solve(Solver solver){
297      if(slvstat.ok){      if(slvstat.ok){
298          cerr << "... DONE SOLVING SYSTEM" << endl;          cerr << "... DONE SOLVING SYSTEM" << endl;
299      }else{      }else{
300          error_reporter(ASC_USER_ERROR,NULL,0,"Solver failed");          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Solver failed");
301      }      }
302    
303      cerr << "SOLVER PERFORMED " << slvstat.iteration << " ITERATIONS IN " << slvstat.cpu_elapsed << "s" << endl;      cerr << "SOLVER PERFORMED " << slvstat.iteration << " ITERATIONS IN " << slvstat.cpu_elapsed << "s" << endl;
304    
305      if(slvstat.iteration_limit_exceeded){      if(slvstat.iteration_limit_exceeded){
306          error_reporter(ASC_USER_ERROR,NULL,0,"Exceeded interation limit");          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Exceeded interation limit");
307      }      }
308    
309      if(slvstat.converged){      if(slvstat.converged){
310          error_reporter(ASC_USER_SUCCESS,NULL,0,"Solver converged: %d iterations, %3.2e s"          ERROR_REPORTER_NOLINE(ASC_USER_SUCCESS,"Solver converged: %d iterations, %3.2e s"
311              ,slvstat.iteration,slvstat.cpu_elapsed);              ,slvstat.iteration,slvstat.cpu_elapsed);
312      }else{      }else{
313          error_reporter(ASC_USER_ERROR,NULL,0,"Solver not converged after %d iteratoins.",slvstat.iteration);          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Solver not converged after %d iteratoins.",slvstat.iteration);
314      }      }
315        
316    
317      //slv_print_output(stderr,solver);      //slv_print_output(stderr,solver);
318    
# Line 333  Simulation::write(){ Line 333  Simulation::write(){
333    
334  //------------------------------------------  //------------------------------------------
335  // ASSIGNING SOLVER TO SIMULATION  // ASSIGNING SOLVER TO SIMULATION
336            
337  void  void
338  Simulation::setSolver(Solver &solver){  Simulation::setSolver(Solver &solver){
339      cerr << "SETTING SOLVER ON SIMULATION TO " << solver.getName() << endl;      cerr << "SETTING SOLVER ON SIMULATION TO " << solver.getName() << endl;
# Line 345  Simulation::setSolver(Solver &solver){ Line 345  Simulation::setSolver(Solver &solver){
345      //cerr << "Simulation::setSolver: slv_select_solver returned " << selected << endl;      //cerr << "Simulation::setSolver: slv_select_solver returned " << selected << endl;
346    
347      if(selected<0){      if(selected<0){
348          error_reporter(ASC_PROG_ERROR,NULL,0,"Failed to select solver");          ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"Failed to select solver");
349          throw runtime_error("Failed to select solver");          throw runtime_error("Failed to select solver");
350      }      }
351    
352      if(selected!=solver.getIndex()){      if(selected!=solver.getIndex()){
353          solver = Solver(slv_solver_name(selected));          solver = Solver(slv_solver_name(selected));
354          error_reporter(ASC_PROG_NOTE,NULL,0,"Substitute solver '%s' (index %d) selected.\n", solver.getName().c_str(), selected);          ERROR_REPORTER_NOLINE(ASC_PROG_NOTE,"Substitute solver '%s' (index %d) selected.\n", solver.getName().c_str(), selected);
355      }      }
356        
357      if( slv_eligible_solver(sys) <= 0){      if( slv_eligible_solver(sys) <= 0){
358          error_reporter(ASC_PROG_ERROR,NULL,0,"Inelegible solver '%s'", solver.getName().c_str() );          ERROR_REPORTER_NOLINE(ASC_PROG_ERROR,"Inelegible solver '%s'", solver.getName().c_str() );
359          throw runtime_error("Inelegible solver");          throw runtime_error("Inelegible solver");
360      }      }
361  }  }

Legend:
Removed from v.164  
changed lines
  Added in v.190

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