Main Page | Class Hierarchy | Class List | File List | Class Members

prom_obj.hh

00001 // $Id: prom_obj.hh,v 1.4 2004/05/05 21:20:50 adams Exp $ 00002 // Author: Mark F. Adams 00003 // Copyright (c) 2000 by Mark F. Adams 00004 // Filename: prom_obj.hh 00005 // 00006 #ifndef __PROM_OBJECT_H__ 00007 #define __PROM_OBJECT_H__ 00008 00009 #include "prom_defs.h" 00010 00011 #if defined(__cplusplus) 00012 extern "C"{ 00013 #endif 00014 int prom_intcompar(const void *a, const void *b); 00015 int prom_intcompar2(const void *a, const void *b); 00016 int prom_floatcompar(const void *a, const void *b); 00017 #if defined(__cplusplus) 00018 } 00019 #endif 00020 00022 00025 class PromCoord { 00026 friend class PromDTet; 00027 public: 00028 PromCoord() { data_[0] = 0.0;data_[1] = 0.0; data_[2] = 0.0; } 00029 PromCoord(gfloat a,gfloat b,gfloat c){data_[0]=a;data_[1]=b;data_[2]=c;} 00030 gfloat operator*( const PromCoord &b )const { 00031 return data_[0]*b.data_[0] + data_[1]*b.data_[1] + data_[2]*b.data_[2]; 00032 } 00033 PromCoord &operator=( const PromCoord &b ) { 00034 data_[0] = b.data_[0]; 00035 data_[1] = b.data_[1]; 00036 data_[2] = b.data_[2]; 00037 return *this; } 00038 PromCoord &operator=( const gfloat d ) { 00039 data_[0] = d; 00040 data_[1] = d; 00041 data_[2] = d; 00042 return *this; } 00043 PromCoord &operator=( const gfloat *d ) { 00044 data_[0] = d[0]; 00045 data_[1] = d[1]; 00046 data_[2] = d[2]; 00047 return *this; } 00048 PromCoord &operator-=( const PromCoord &b ) { 00049 data_[0] -= b.data_[0]; 00050 data_[1] -= b.data_[1]; 00051 data_[2] -= b.data_[2]; 00052 return *this; } 00053 PromCoord& operator+=( const PromCoord &a) { 00054 data_[0] += a.data_[0]; 00055 data_[1] += a.data_[1]; 00056 data_[2] += a.data_[2]; 00057 return *this; } 00058 PromCoord& operator/=( const gfloat d ) { 00059 data_[0] /= d; 00060 data_[1] /= d; 00061 data_[2] /= d; 00062 return *this; } 00063 PromCoord& operator*=( const gfloat d ) { 00064 data_[0] *= d; 00065 data_[1] *= d; 00066 data_[2] *= d; 00067 return *this; } 00068 PromCoord& operator/=( const PromCoord& d ) { 00069 data_[0] /= d.data_[0]; 00070 data_[1] /= d.data_[1]; 00071 data_[2] /= d.data_[2]; 00072 return *this; } 00073 PromCoord& operator*=( const PromCoord& d ) { 00074 data_[0] *= d.data_[0]; 00075 data_[1] *= d.data_[1]; 00076 data_[2] *= d.data_[2]; 00077 return *this; } 00078 PromCoord operator+(const PromCoord a)const{ 00079 PromCoord cc; 00080 cc.data_[0] = data_[0] + a.data_[0]; 00081 cc.data_[1] = data_[1] + a.data_[1]; 00082 cc.data_[2] = data_[2] + a.data_[2]; 00083 return cc; } 00084 PromCoord operator-(const PromCoord a)const { 00085 PromCoord cc; 00086 cc.data_[0] = data_[0]-a.data_[0]; 00087 cc.data_[1] = data_[1]-a.data_[1]; 00088 cc.data_[2] = data_[2]-a.data_[2]; 00089 return cc; } 00090 PromCoord operator*(const gfloat a)const { 00091 PromCoord cc; 00092 cc.data_[0] = data_[0]*a; 00093 cc.data_[1] = data_[1]*a; 00094 cc.data_[2] = data_[2]*a; 00095 return cc; } 00096 PromCoord operator/(const gfloat a)const { 00097 PromCoord cc; 00098 cc.data_[0] = data_[0]/a; 00099 cc.data_[1] = data_[1]/a; 00100 cc.data_[2] = data_[2]/a; 00101 return cc; } 00102 PromCoord operator-()const { 00103 PromCoord cc; 00104 cc.data_[0] = -data_[0]; 00105 cc.data_[1] = -data_[1]; 00106 cc.data_[2] = -data_[2]; 00107 return cc; } 00108 gfloat length()const{ 00109 return sqrt((data_[0]*data_[0])+(data_[1]*data_[1])+(data_[2]*data_[2])); 00110 } 00111 gfloat norm2()const{ 00112 return sqrt((data_[0]*data_[0])+(data_[1]*data_[1])+(data_[2]*data_[2])); 00113 } 00114 gfloat length2()const { 00115 return (data_[0]*data_[0]) + (data_[1]*data_[1]) + (data_[2]*data_[2]); 00116 } 00117 00118 gfloat &operator[]( int ii ){ return data_[ii]; } 00119 gfloat operator[]( int ii ) const { return data_[ii]; } 00120 00121 // int buffer i/o of PromCoord for MPI 00122 int Write( int **buff )const; 00123 int Read( int **buff ); 00124 static int GetWrite_size( int &sz ){ 00125 sz = 3*(sizeof(gfloat)/sizeof(int)); 00126 return 0; 00127 } 00128 int Archive( FILE *file = stderr, const PromArchiveType type = PROM_PRINT ); 00129 private: 00130 gfloat data_[3]; 00131 }; 00132 00133 #define MEM_FILE_FLAG (9999) 00134 class PromNode; 00135 class PromMatrix; 00136 class PromOptions; 00138 00141 class PromContext 00142 { 00143 // Disable the copy constructor and assignment by default so you will get 00144 // compiler errors instead of unexpected behaviour if you pass objects 00145 // by value or assign objects. 00146 //void operator=( const PromContext & objectSrc ); // no implementation 00147 protected: 00148 PromContext(){} // no real copies of this 00149 public: 00150 static int GetNextFactor( const PromOptions &opts, const int np, 00151 const int lastf, const int nneq, int *nf ); 00152 static int getNextFactor( const PromOptions &opts, const int np, 00153 const int lastf, const int gnodes ); 00154 // util functions 00155 00156 static int WriteMat_private(const PromMatrix *, FILE *file, 00157 const int ioff, const int joff, const bool trans); 00158 static int WriteMat( const PromMatrix *, char *n, int l ); 00159 static int PrintMatInfo(const PromMatrix *AA, const int level, 00160 const int factor, const int mype, const int np ); 00161 00162 // array i/o functions 00163 static int printArr( FILE *file, const int *arr, const int n, 00164 const char *header = "%d", const int step = 0 ); 00165 static int printArr( FILE *file, const bool *arr, const int n, 00166 const char *header = "%d", const int step = 0 ); 00167 static int printArr( FILE *file, const int *arr, const int n, const int aux, 00168 const char *header = "%d", const int step = 0 ); 00169 static int printArr( FILE *file, const double *arr, const int n,const int ax, 00170 const char *header = "%d", const int step = 0 ); 00171 static int printArr( FILE *file, const double *arr, const int n, 00172 const char *header = "%d", const int step = 0 ); 00173 static int printArr( FILE *file, const float *arr, const int n, 00174 const char *header = "%d", const int step = 0 ); 00175 static int scanArr( FILE *file, int **arr, int *n, 00176 const char *header = "%d", const int step = 0 ); 00177 static int scanArr( FILE *file, int **arr, int *n, int *aux, 00178 const char *header = "%d", const int step = 0 ); 00179 static int scanArr( FILE *file, double **arr, int *n, 00180 const char *header = "%d", const int step = 0 ); 00181 static int scanArr( FILE *file, float **arr, int *n, 00182 const char *header = "%d", const int step = 0 ); 00183 static int WriteMetis( char *name, const int *xadj, const int *adjncy, 00184 const int *vwgts, const int *ewgts, PromNode **nodes, 00185 const int nNodes, const int numadjac ); 00186 // buffer i/o of int for MPI 00187 static int ScanArrMPI( int myn, int *&array, MPI_Comm Comm ); 00188 static int TInvert( const double src[], double dest[], const int NN, 00189 const int LDA = -1 ); 00190 static int Write( const int val, int *&buff ){ 00191 *buff++ = val; 00192 return 0; 00193 } 00194 static int Read( int &val, int *&buff ){ 00195 val = *buff++; 00196 return 0; 00197 } 00198 static int Read( int &val, int **buff ){ 00199 val = **buff; *buff += 1; 00200 return 0; 00201 } 00202 #if !defined(PROM_NO_SYSTEM_BOOL) 00203 static int Read( bool &val, int *&buff ){ 00204 val = (bool)*buff++; 00205 return 0; 00206 } 00207 static int Read( bool &val, int **buff ){ 00208 val = (bool)**buff; *buff += 1; 00209 return 0; 00210 } 00211 static int Write( const bool val, int **buff ){ 00212 **buff = (int)val; *buff += 1; 00213 return 0; 00214 } 00215 #endif 00216 static int Write( const int val, int **buff ){ 00217 **buff = val; *buff += 1; 00218 return 0; 00219 } 00220 static int Write( const int num, const int *arr, int *&buff ){ 00221 *buff++ = num; 00222 for( int i = 0; i < num ; i++ ) *buff++ = arr[i]; 00223 return 0; 00224 } 00225 static int Read( int &num, int *arr, int *&buff ){ 00226 num = *buff++; 00227 for(int i = 0 ; i < num ; i++ ) arr[i] = *buff++; 00228 return 0; 00229 } 00230 00231 static int Write( const double val, int *&buff ){ 00232 double *fp = (double*)buff; *fp++ = val; 00233 buff = (int*)fp; 00234 return 0; 00235 } 00236 static int Read( double &val, int *&buff ){ 00237 double *fp = (double*)buff; val = *fp++; 00238 buff = (int*)fp; 00239 return 0; 00240 } 00241 static double **pivot45( const int j , double a[4][5] ){ 00242 double temp, max = fabs(a[j][j]); 00243 int jj, i; 00244 for ( jj = j, i = j + 1 ; i < 4 ; i++ ){ 00245 temp = fabs(a[i][j]); 00246 if( temp > max ) { 00247 jj = i; 00248 max = temp; 00249 } 00250 } 00251 if ( jj == j ) return NULL; 00252 else { 00253 // swap rows j & jj swap5 ( a[jj], a[j]); 00254 double *aa = a[jj], *bb = a[j]; 00255 double temp1 = aa[0]; aa[0] = bb[0]; bb[0] = temp1; 00256 double temp2 = aa[1]; aa[1] = bb[1]; bb[1] = temp2; 00257 double temp3 = aa[2]; aa[2] = bb[2]; bb[2] = temp3; 00258 double temp4 = aa[3]; aa[3] = bb[3]; bb[3] = temp4; 00259 double temp5 = aa[4]; aa[4] = bb[4]; bb[4] = temp5; 00260 return (double **)a; 00261 } 00262 } 00263 static gfloat cross( const PromCoord&, const PromCoord&, 00264 const PromCoord&_NODE, PromCoord *ret = NULL ); 00265 static gfloat crossDot( const PromCoord&, const PromCoord&, 00266 const PromCoord&, const PromCoord&, 00267 PromCoord *cross = NULL ); 00268 static int CheckClearMPI( MPI_Comm, const int mype, const int verbose ); 00269 // gloabal data 00270 static char stateNames_[PROM_NUMSTATE+1][12]; 00271 static char typeNames_[PROM_NUMTOPO+1][12]; 00272 static int prom_logs_[LOG_TOT+1]; 00273 static int prom_stages_[11]; 00274 }; 00275 00276 template <class T> class PromList ; 00278 00282 class PromStack 00283 { 00284 friend class PromAggGrid; 00285 friend class PromBank; 00286 friend class PromParentBank; 00287 // Disable the copy constructor and assignment by default so you will get 00288 // compiler errors instead of unexpected behaviour if you pass objects 00289 // by value or assign objects. 00290 PromStack( const PromStack& objectSrc ); // no implementation 00291 //void operator=( const PromStack& objectSrc ); // no implementation 00292 protected: 00293 PromStack( PromStack *n = NULL ){ next_ = n; } 00294 virtual ~PromStack(){ next_ = NULL; } 00295 public: 00296 bool isChildListEmpty() const { return (next_ == NULL); } 00297 bool findChild( const PromStack *n ) const ; 00298 bool removeChild( PromStack *n ); 00299 int removeChildren( PromList<PromStack*> * ); 00300 int ClearChildren(); 00301 int GetChildren( PromList<PromStack*> * ) const ; 00302 int numChildren() const ; 00303 int addChild( PromStack *n ){ 00304 assert(this!=NULL); 00305 if( n->next_ ) return 1; // only in one list at a time 00306 n->next_ = next_; 00307 next_ = n; 00308 return 0; 00309 } 00310 PromStack *PopChild(){ 00311 assert(this!=NULL); PromStack *ret = NULL; 00312 if( next_ ) { ret = next_; next_ = next_->next_; ret->next_ = NULL; } 00313 return ret; 00314 } 00315 PromStack *getChild() const{assert(this!=NULL); return next_;} 00316 private: 00317 PromStack *next_; 00318 }; 00319 00321 00324 class PromGlobalID 00325 { 00326 friend class PromNode; 00327 public: 00328 PromGlobalID( int i = -9, int p = -9 ); 00329 ~PromGlobalID(); 00330 PromGlobalID &operator=( const PromGlobalID &a ); 00331 void reset() { procID_ = lIndex_ = -9; } 00332 int Write( int **ppb )const{ 00333 int *pb = *ppb; *pb++ = lIndex_; *pb++ = procID_; *ppb = pb; 00334 return 0; 00335 } 00336 int Read( int **ppb ){ 00337 int *pb = *ppb; lIndex_ = *pb++; procID_ = *pb++; *ppb = pb; 00338 return 0; 00339 } 00340 static int GetWrite_size( int &sz ){ sz = 2; return 0;} 00341 bool operator==(const PromGlobalID &a)const{ 00342 assert(lIndex_ >= 0); return lIndex_ == a.lIndex_; 00343 } 00344 bool operator!=(const PromGlobalID &a)const {return lIndex_ != a.lIndex_;} 00345 bool operator<(const PromGlobalID &a)const {return lIndex_ < a.lIndex_;} 00346 bool operator>( const PromGlobalID &a)const {return lIndex_ > a.lIndex_;} 00347 bool operator<=( const PromGlobalID &a)const{return lIndex_ <= a.lIndex_;} 00348 bool operator>=( const PromGlobalID &a)const{return lIndex_ >= a.lIndex_;} 00349 bool operator==( int i ) const { assert(lIndex_ >= 0); return lIndex_ == i;} 00350 bool operator!=( int i ) const { return lIndex_ != i;} 00351 bool operator<( int i ) const { return lIndex_ < i;} 00352 bool operator>( int i ) const { return lIndex_ > i;} 00353 bool operator<=( int i ) const { return lIndex_ <= i;} 00354 bool operator>=( int i ) const { return lIndex_ >= i;} 00355 int operator+( int i ) const { assert(lIndex_ >= 0); return lIndex_ + i; } 00356 int operator-( int i ) const { assert(lIndex_ >= 0); return lIndex_ - i; } 00357 00358 // stored id[ gloabal index, addrsp index index]; sp[0,addrsp] 00359 void setProc(int f){ 00360 assert(this!=NULL); 00361 procID_ = f; 00362 } 00363 void setProc(int f, int &ierr){ 00364 assert(this!=NULL); ierr = !(f >= 0); 00365 procID_ = f; 00366 } 00367 int proc(int &ierr)const{ 00368 assert(this!=NULL); 00369 ierr = !(procID_>=0); 00370 return procID_;} 00371 int proc()const{ 00372 assert(this!=NULL); assert(procID_>=0); 00373 return procID_;} 00374 void setLocal( const int ii ){ lIndex_ = ii; } 00375 int local(int &ierr)const{ ierr = !(this && lIndex_ >= 0); return lIndex_;} 00376 int local()const{ assert(this!=NULL && lIndex_ >= 0); return lIndex_;} 00377 int isIerr()const{ 00378 return !(procID_>=0 && lIndex_>=0); 00379 } 00380 int Archive( FILE *file = stderr, const PromArchiveType type=PROM_PRINT); 00381 private: 00382 int procID_; // FEAP (real) index, global solver index. 00383 int lIndex_; 00384 }; 00385 00387 00391 class PromLocalID 00392 { 00393 public: 00394 PromLocalID(int i = -9){ 00395 assert(this!=NULL); 00396 gIndex_ = -9; 00397 lIndex_ = i; 00398 } 00399 void reset() { gIndex_ = lIndex_ = -9; } 00400 PromLocalID( const PromLocalID &a ){ 00401 assert(this!=NULL); 00402 //fIndex = a.fIndex; 00403 gIndex_ = a.gIndex_; 00404 lIndex_ = a.lIndex_; 00405 } 00406 PromLocalID &operator=( const PromLocalID &a ){ 00407 assert(this!=NULL); 00408 lIndex_ = a.lIndex_; 00409 gIndex_ = a.gIndex_; 00410 return *this; 00411 } 00412 int Write( int **ppb )const{ 00413 int *pb = *ppb; *pb++ = lIndex_; *pb++ = gIndex_; *ppb = pb; 00414 return 0; 00415 } 00416 int Read( int **ppb ){ 00417 int *pb = *ppb; lIndex_ = *pb++; gIndex_ = *pb++; *ppb = pb; 00418 return 0; 00419 } 00420 static int GetWrite_size( int &sz ){ sz = 2; return 0; } 00421 00422 /*bool operator==( const PromLocalID &a )const { return lIndex_ == a.lIndex_; } 00423 bool operator!=( const PromLocalID &a )const { return lIndex_ != a.lIndex_; } 00424 bool operator<( const PromLocalID &a )const { return lIndex_ < a.lIndex_; } 00425 bool operator>( const PromLocalID &a )const { return lIndex_ > a.lIndex_; } 00426 bool operator<=( const PromLocalID &a )const { return lIndex_ <= a.lIndex_; } 00427 bool operator>=( const PromLocalID &a )const { return lIndex_ >= a.lIndex_; } 00428 bool operator==( int i )const { return lIndex_ == i; } 00429 bool operator!=( int i )const { return lIndex_ != i; } 00430 bool operator<( int i )const { return lIndex_ < i; } 00431 bool operator>( int i )const { return lIndex_ > i; } 00432 bool operator<=( int i )const { return lIndex_ <= i; } 00433 bool operator>=( int i )const { return lIndex_ >= i; } 00434 int operator+( int i )const { return lIndex_ + i; } 00435 int operator-( int i )const { return lIndex_ - i; }*/ 00436 00437 // stored id[ gloabal index, addrsp index index]; sp[0,addrsp] 00438 int global(int &ierr)const{ierr = !(this && gIndex_ >= 0);return gIndex_;} 00439 int global()const{ assert(this!=NULL && gIndex_ >= 0); return gIndex_;} 00440 void setGlobal( int g ){ assert(this!=NULL); gIndex_ = g; } 00441 int operator()(int &ierr)const{ierr=!(this && lIndex_ >= 0);return lIndex_;} 00442 int operator()()const{ assert(this!=NULL && lIndex_ >= 0); return lIndex_;} 00443 PromLocalID &operator=( int i ){ lIndex_ = i; return *this; } 00444 00445 int isIerr()const{return !(gIndex_ >= 0 && lIndex_ >= 0 );} 00446 int Archive( FILE *file = stderr, const PromArchiveType type = PROM_PRINT ); 00447 private: 00448 int gIndex_; 00449 int lIndex_; // FEAP (real) index, global solver index. 00450 }; 00451 00452 #endif // __PROM_OBJECT_H__

Generated on Fri May 21 14:17:53 2004 by doxygen 1.3.7