/[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 771 by johnpye, Fri Jul 7 11:01:26 2006 UTC revision 772 by johnpye, Fri Jul 14 06:03:47 2006 UTC
# Line 153  Simulation::checkConsistency() const{ Line 153  Simulation::checkConsistency() const{
153      }      }
154  }  }
155    
156  void  /** Returns TRUE if all is OK (not singular) */
157  Simulation::checkStructuralSingularity() const{  bool
158    Simulation::checkStructuralSingularity(){
159      cerr << "CHECKING STRUCTURAL SINGULARITY..." << endl;      cerr << "CHECKING STRUCTURAL SINGULARITY..." << endl;
160    
161      int *vil;      int *vil;
# Line 165  Simulation::checkStructuralSingularity() Line 166  Simulation::checkStructuralSingularity()
166      struct var_variable **varlist = slv_get_solvers_var_list(sys);      struct var_variable **varlist = slv_get_solvers_var_list(sys);
167      struct rel_relation **rellist = slv_get_solvers_rel_list(sys);      struct rel_relation **rellist = slv_get_solvers_rel_list(sys);
168    
169      if(res==0){      if(this->sing){
170          cerr << "UNABLE TO DETERMINE SINGULARITY LISTS" << endl;          delete this->sing;
171          return;          this->sing = NULL;
172      }else if(res==1){      }
173          ERROR_REPORTER_NOLINE(ASC_USER_ERROR,"Structurally singular. Check the listing on the console.");  
174          cerr << "STRUCTURALLY SINGULAR: The found singularity involves these relations:" << endl;      if(res==1){
175            CONSOLE_DEBUG("processing singularity data...");
176            sing = new SingularityInfo;
177    
178            // 'singular relations'
179          for(int i=0; ril[i]!=-1; ++i){          for(int i=0; ril[i]!=-1; ++i){
180              Instanc i1((struct Instance *)rel_instance(rellist[ril[i]]));              sing->rels.push_back( Relation( this, rellist[ril[i]] ) );
             cerr << "  " << getInstanceName(i1) << endl;  
181          }          }
182    
183          cerr << "STRUCTURALLY SINGULAR: ... and these variables:" << endl;          // 'singular variables'
184          for(int i=0; vil[i]!=-1; ++i){          for(int i=0; vil[i]!=-1; ++i){
185              Instanc i1((struct Instance *)var_instance(varlist[vil[i]]));              sing->vars.push_back( Variable( this, varlist[vil[i]] ) );
             cerr << "  " << getInstanceName(i1) << endl;  
186          }          }
187    
188          cerr << "STRUCTURALLY SINGULAR: ... and may be mitigated by freeing these variables:" << endl;          // 'free these variables'
189          for(int i=0; fil[i]!=-1; ++i){          for(int i=0; fil[i]!=-1; ++i){
190              Instanc i1((struct Instance *)var_instance(varlist[fil[i]]));              sing->freeablevars.push_back( Variable( this, varlist[fil[i]] ) );
             cerr << "  " << getInstanceName(i1) << endl;  
191          }          }
192    
193            // we're done with those lists now
194            ASC_FREE(vil);
195            ASC_FREE(ril);
196            ASC_FREE(fil);
197    
198            if(sing->isSingular()){
199                CONSOLE_DEBUG("singularity found");
200                this->sing = sing;
201                return FALSE;
202            }
203            CONSOLE_DEBUG("no singularity");
204            delete sing;
205            return TRUE;
206      }else{      }else{
207          throw runtime_error("Invalid return from slvDOF_structsing.");          if(res==0){
208                throw runtime_error("Unable to determine singularity lists");
209            }else{
210                throw runtime_error("Invalid return from slvDOF_structsing.");
211            }
212        }
213    }
214    
215    const SingularityInfo &
216    Simulation::getSingularityInfo() const{
217        if(sing==NULL){
218            throw runtime_error("No singularity info present");
219      }      }
220      ascfree(vil);      return *sing;
     ascfree(ril);  
     ascfree(fil);  
221  }  }
222    
223  void  void
# Line 284  Simulation::run(const Method &method){ Line 309  Simulation::run(const Method &method){
309      }      }
310  }  }
311    
312    /**
313        @return TRUE if all is OK
314    */
315  const bool  const bool
316  Simulation::check(){  Simulation::check(){
317      cerr << "CHECKING SIMULATION" << endl;      cerr << "CHECKING SIMULATION" << endl;
# Line 291  Simulation::check(){ Line 319  Simulation::check(){
319      CheckInstance(stderr, &*i1);      CheckInstance(stderr, &*i1);
320      cerr << "...DONE CHECKING" << endl;      cerr << "...DONE CHECKING" << endl;
321      this->checkConsistency();      this->checkConsistency();
322      this->checkStructuralSingularity();  
323      return true;      return this->checkStructuralSingularity();
324  }  }
325    
326  void  void
# Line 322  Simulation::getFixableVariables(){ Line 350  Simulation::getFixableVariables(){
350      if(!slvDOF_eligible(sys,&vip)){      if(!slvDOF_eligible(sys,&vip)){
351          ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"No fixable variables found.");          ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"No fixable variables found.");
352      }else{      }else{
         //cerr << "FIXABLE VARS FOUND" << endl;  
353          struct var_variable **vp = slv_get_solvers_var_list(sys);          struct var_variable **vp = slv_get_solvers_var_list(sys);
354    
         /*struct var_variable *first_var = vp[0];  
         char *first_var_name = var_make_name(sys,first_var);  
         cerr << "FIRST SYS VAR IS NAMED " << var_make_name(s,first_var) << endl;  
         ascfree(first_var_name);*/  
   
355          if(vp==NULL){          if(vp==NULL){
356              throw runtime_error("Simulation variable list is null");              throw runtime_error("Simulation variable list is null");
357          }          }
# Line 338  Simulation::getFixableVariables(){ Line 360  Simulation::getFixableVariables(){
360          int i=0;          int i=0;
361          int var_index = vip[i];          int var_index = vip[i];
362          while(var_index >= 0){          while(var_index >= 0){
             //cerr << "FOUND VARIABLE var_index = " << var_index << endl;  
363              struct var_variable *var = vp[var_index];              struct var_variable *var = vp[var_index];
             //cerr << "VARIABLE " << var_index << " IS ELIGIBLE" << endl;  
   
             //char *var_name = var_make_name(sys,var);  
             //cerr << "ELIGIBLE VAR: " << var_name << endl;  
             //ascfree(var_name);  
   
364              vars.push_back( Variable(this, var) );              vars.push_back( Variable(this, var) );
365              ++i;              ++i;
366              var_index = vip[i];              var_index = vip[i];
367          }          }
368          ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"Found %d fixable variables.",i);          ERROR_REPORTER_NOLINE(ASC_USER_NOTE,"Found %d fixable variables.",i);
         //cerr << "END ELEGIBLE VARS LIST" << endl;  
369          ascfree(vip);          ascfree(vip);
         //cerr << "FREED VIP LIST" << endl;  
370      }      }
371    
     //cerr << "FINISHED WITH FINDING ELEGIBLE VARIABLES" << endl;  
372      return vars;      return vars;
373  }  }
374    
# Line 600  const int Line 612  const int
612  Simulation::getActiveBlock() const{  Simulation::getActiveBlock() const{
613      return activeblock;      return activeblock;
614  }  }
615    
616    bool
617    SingularityInfo::isSingular() const{
618        if(vars.size()||rels.size()){
619            return true;
620        }
621        return false;
622    }

Legend:
Removed from v.771  
changed lines
  Added in v.772

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