00001
00002
00003
00004
00005
00006
#ifndef __PROM_NODE_H__
00007
#define __PROM_NODE_H__
00008
00009
#include "prom_obj.hh"
00010
#include "prom_list.hh"
00011
#include "prom_tabl.hh"
00012
#include "prom_options.hh"
00013
#include "prom_perf.hh"
00014
00015
typedef enum promMG{PROM_GEOMG=0,PROM_AGGMG,PROM_NUMMGTYPES}PromMGType;
00016
00017
00018
#if defined(PROM_USE_PETSC)
00019
#include "prom_petsc.hh"
00020
00021
#elif defined(PROM_USE_PETRA)
00022
#include "prom_petra.hh"
00023
#else
00024
#error ERROR pick one!
00025
#endif
00026
00027
struct bitsTAG {
00028
unsigned int state : 2;
00029
unsigned int topo : 2;
00030
unsigned int type : 2;
00031
unsigned int color : 9;
00032
unsigned int exterior : 1;
00033
unsigned int dead : 1;
00034
unsigned int qual : 1;
00035
unsigned int dof0 : 1;
00036
unsigned int dof1 : 1;
00037
unsigned int dof2 : 1;
00038
unsigned int dof3 : 1;
00039
unsigned int dof4 : 1;
00040
unsigned int dof5 : 1;
00041
unsigned int dof6 : 1;
00042
unsigned int dof7 : 1;
00043
unsigned int dof8 : 1;
00044
unsigned int dof9 : 1;
00045
unsigned int dof10 : 1;
00046
unsigned int dof11 : 1;
00047
unsigned int dof12 : 1;
00048
unsigned int dof13 : 1;
00049
00050
unsigned int dof14 : 1;
00051
unsigned int isenv : 1;
00052
unsigned int done : 1;
00053
unsigned int mat_topo : 1;
00054
unsigned int malloced : 1;
00055
unsigned int pointer : 1;
00056
unsigned int shp_sz : 14;
00057
unsigned int aux : 8;
00058
unsigned int ndf : 4;
00059 };
00060
00061
#define PROM_MAXSTATE 3
00062
#define PROM_MAX_COLOR 511
00063
#define PROM_MAX_AUX_SZ 255
00064
#define PROM_MAX_SHP_SZ 16385
00065
#define PROM_MAXNDF 8 // this could be 15!
00066
00068
00071 class PromElement
00072 {
00073
friend class PromNode;
00074
public:
00075
PromElement();
00076
void reset();
00077
PromElement &operator=(
const PromElement& a );
00078
virtual ~
PromElement(){};
00079
virtual int Archive(FILE *file=stderr,
const PromArchiveType type=PROM_PRINT);
00080
int Write(
int **buff )
const;
00081
int Read(
int **buff );
00082
static int GetWrite_size(
int &sz){
00083 sz =
sizeof(
struct bitsTAG)/sizeof(int);
00084
return 0;
00085 }
00086
00087
void mark(
bool b = TRUE ){ assert(
this!=NULL); bits_.done = (b)?1:0;}
00088
bool isMarked()
const{ assert(
this!=NULL);
return (
bool)bits_.done; }
00089
00090
bool isEnvelope()
const{ assert(
this!=NULL);
return bits_.isenv; }
00091
void setEnvelope(
bool b = TRUE ) { assert(
this!=NULL); bits_.isenv = (b)?1:0; }
00092
00093 PromNodeState getState()
const{
00094 assert(
this!=NULL);
return (PromNodeState)bits_.state;
00095 }
00096 PromNodeState getState(
int &ierr)
const{
00097 ierr = (
this==NULL);
return (PromNodeState)bits_.state;
00098 }
00099
void setState(PromNodeState s){
00100 assert(
this!=NULL); assert(s<=PROM_MAXSTATE);
00101 bits_.state = s;
00102 }
00103 PromNodeTopo getTopoType()
const {
00104 assert(
this!=NULL);
return (PromNodeTopo)bits_.topo;
00105 }
00106
void setTopoType( PromNodeTopo s ){
00107 assert(
this!=NULL && s>=0 && s<=PROM_NUMTOPO);
00108 bits_.topo = (
unsigned int)s;
00109 }
00110
int getNDF()
const{
00111 assert(
this!=NULL);
return (
int)bits_.ndf;
00112 }
00113
int SetNDF(
int s){
00114 assert(
this!=NULL);
00115
if(s<0 || s>PROM_MAXNDF) SETERRQ1(1,
"ndf=%d",s);
00116 bits_.ndf = (
unsigned int)s;
00117
return 0;
00118 }
00119 PromElemType getType()
const{
00120 assert(
this!=NULL);
return (PromElemType)bits_.type;
00121 }
00122
void setType(PromElemType s){
00123 assert(
this!=NULL); assert(s<=PROM_NUMELEMTYPES);
00124 bits_.type = (
unsigned int)s;
00125 }
00126
00127
bool isExterior()
const { assert(
this!=NULL);
return bits_.exterior; }
00128
void setExterior(
int i=TRUE){assert(
this!=NULL);bits_.exterior = i?1:0;}
00129
00130
void kill(
const bool d = TRUE ){ assert(
this!=NULL); bits_.dead = d; }
00131
bool isDead()
const{
00132
if(
this==NULL){
00133 PetscTraceBackErrorHandler(1,
"44",
"55",
"66",2,3,
"77",(
void*)
"8");
00134
return 0;
00135 }
00136
return (
bool)bits_.dead;
00137 }
00138
bool setFixed (
int tp,
bool f = TRUE );
00139
inline void setAllFixed(
const int ndf );
00140
bool isFixed (
const int ndf,
int type = -9 )
const;
00141
inline bool isAllFixed(
const int ndf )
const;
00142
public:
00143
void setMaterialTopo(
int tp=1){assert(
this!=NULL);bits_.mat_topo = tp ? 1:0;}
00144
bool isMaterialTopo()
const{ assert(
this!=NULL);
return bits_.mat_topo; }
00145
int color()
const{ assert(
this!=NULL);
return (
int)bits_.color; }
00146
void setColor(
unsigned int i){
00147 assert(
this!=NULL); bits_.color = i; assert(i<=PROM_MAX_COLOR);
00148 }
00149
protected:
00150
struct bitsTAG bits_;
00151 };
00152
00153
class PromFacet;
00154
00155
#define PROM_NODE_MAXFACET 6
00156
00158
00161 class PromParent :
public PromElement,
public PromStack
00162 {
00163
friend class PromParentBank;
00164
public:
00165
PromParent() : procID_(-9), gIndex_(-9), geq_(-9), DAP_(NULL), P0_(NULL){}
00166
00167
virtual ~
PromParent();
00168
00169
00170
00171
00172
PromParent &operator=(
const PromParent &a );
00173
int Copy(
const PromNode *
const,
const int mype );
00174
int Write(
int **ppb )
const;
00175
int Read(
int **ppb );
00176
int GetWrite_size(
int &sz )
const;
00177
00178
int proc(
int &ierr)
const{ierr = !(
this&&procID_ >= 0);
return procID_;}
00179
int proc()
const{ assert(
this!=NULL&&procID_ >= 0);
return procID_;}
00180
int global(
int &ierr)
const{ierr = !(
this && gIndex_>=0);
return gIndex_;}
00181
int global()
const{ assert(
this!=NULL && gIndex_ >= 0);
return gIndex_;}
00182
int geq()
const{ assert(
this!=NULL && geq_ >= 0);
return geq_;}
00183
int geq(
int &ierr)
const{assert(
this!=NULL);ierr=(geq_<0);
return geq_;}
00184
void setProc(
int f){ assert(
this!=NULL); procID_ = f; }
00185
void setGlobal(
int g ){ assert(
this!=NULL); gIndex_ = g; }
00186
void setGEQ(
int g ){ assert(
this!=NULL && g>=0); geq_ = g; }
00187
int isIerr()
const{
return !( gIndex_ >= 0 && procID_ >= 0 );}
00188
int Archive(FILE *file = stderr,
const PromArchiveType type=PROM_PRINT);
00189
00190
int getPsz()
const { assert(
this!=NULL);
return (
int)bits_.shp_sz; }
00191
int SetPsz(
int i );
00192
int SetPsz_hard(
int i ){
00193 bits_.shp_sz = i; assert(
this!=NULL); assert(i>=0 && i<=PROM_MAX_SHP_SZ);
00194 bits_.pointer = (i>0) ? 1 : 0;
00195
if ( bits_.shp_sz == 1 ) shape_ = 0.0;
00196
return 0;
00197 }
00198
void setMalloced(
bool b = TRUE ){ bits_.malloced = (b ? 1: 0); }
00199
int SetP(
const int i, shpfloat *sh ){
00200 assert(
this!=NULL); assert(i>=0 && i<=PROM_MAX_SHP_SZ);
00201 P0_ = sh; bits_.shp_sz = i;
00202 bits_.pointer = 1;
00203
return 0;
00204 }
00205
00206
int setScalarP0( shpfloat val );
00207 shpfloat getScalarP0()
const {
00208 assert(
this!=NULL); assert(bits_.shp_sz == 1);
00209
return (bits_.pointer!=0) ? ((P0_!=NULL) ? P0_[0] : 0.0) : shape_;
00210 }
00211
00212 shpfloat *DAP_;
00213
union{
00214 shpfloat *P0_;
00215 shpfloat shape_;
00216 };
00217
private:
00218
int geq_;
00219
int gIndex_;
00220
int procID_;
00221 };
00222
00224
00227 class PromParentBank
00228 {
00229
friend class Prometheus;
00230
public:
00231
PromParentBank() : parBlocks_(NULL), freePar_(NULL), currPar_(NULL),
00232 numParFree_(0) {}
00233 ~
PromParentBank(){ ClearCache(); }
00234
00235
public:
00236
int ClearCache();
00237
int Deallocate(
PromParent *par );
00238
int GetFreePar(
PromParent** );
00239
private:
00240
00241 PromList<PromParent*> *parBlocks_;
00242
PromParent *currPar_;
00243
PromParent *freePar_;
00244
int numParFree_;
00245 };
00246
00248
00251 class PromParentArr
00252 {
00253
public:
00254
PromParentArr(
PromParentBank *
const bank,
const int n );
00255
virtual ~
PromParentArr();
00256
00257
int GetWrite_size(
int &sz )
const;
00258
int Write(
int **ppb )
const;
00259
int Read(
int **ppb );
00260
int SetSize(
PromParentBank *
const bank,
int n );
00261
int getSize()
const {
return np_; }
00262
00263
PromParent **data_;
00264
protected:
00265
int np_;
00266 };
00267
00269
00273 class PromParentArr_extra :
public PromParentArr
00274 {
00275
public:
00276
PromParentArr_extra(
PromParentBank *
const bank,
int n,
int gid,
int geq,
00277
int ndf,
bool isalfx ):
00278
PromParentArr(bank,n), gid_(gid), geq_(geq)
00279 {
00280 bits_.done = 0; bits_.isfixed = isalfx; bits_.ndf = ndf;
00281 }
00282
void mark(
bool b = TRUE ){ assert(
this!=NULL); bits_.done = (b) ? 1 : 0; }
00283
bool isMarked()
const{ assert(
this!=NULL);
return (
bool)bits_.done; }
00284
int SetGID(
int id ){
00285 assert(
this!=NULL);
00286
if(id<0 || id>=1073741824)SETERRQ1(1,
"gid %d out of bounds",
id);
00287 gid_ =
id;
00288
return 0;
00289 }
00290
int getGID()
const{ assert(
this!=NULL);
return gid_; }
00291
int getGEq()
const{ assert(
this!=NULL);
return geq_; }
00292
bool isFixed()
const{ assert(
this!=NULL);
return bits_.isfixed; }
00293
void setFixed(
bool b = TRUE ){assert(
this!=NULL); bits_.isfixed = (b)?1:0;}
00294
int getNDF()
const{ assert(
this!=NULL);
return bits_.ndf; }
00295
private:
00296
struct {
00297
unsigned int done : 1;
00298
unsigned int isfixed : 1;
00299
unsigned int ndf : 30;
00300 }bits_;
00301
int gid_;
00302
int geq_;
00303 };
00304
00306
00309
class PromPoly;
00310
class PromDTet;
00311
class PromSymbData {
00312
public:
00313 PromSymbData();
00314
virtual ~PromSymbData();
00315
00316 PromList<PromPoly*> elemList;
00317 PromTable<PromNode*> adjac;
00318
PromNode *child;
00319 PromList<PromGlobalID*> *dependents;
00320
PromNode *parent;
00321
PromGlobalID ghostID;
00322 };
00323
00325
00328 class PromNodeBase :
public PromElement
00329 {
00330
public:
00331
virtual ~
PromNodeBase(){}
00332
PromNodeBase() : geq_(-9) { }
00333
PromNodeBase &operator=(
const PromNodeBase &a );
00334
00335
int geq()
const{ assert(
this!=NULL && geq_ >= 0);
return geq_;}
00336
int geq(
int &ierr)
const{assert(
this!=NULL);ierr=(geq_<0);
return geq_;}
00337
void setGEQ(
int g ){ assert(
this!=NULL && g>=0); geq_ = g; }
00338
00339
PromLocalID index_;
00340
protected:
00341
int geq_;
00342 };
00343
00345
00348 class PromCR
00349 {
00350
public:
00351
PromCR(
int nnodes );
00352
PromCR(
int **ppb );
00353 ~
PromCR();
00354
int Write(
int **ppb )
const;
00355
int Read(
int **ppb );
00356
int GetWrite_size(
int &sz )
const;
00357
void mark(
bool b=TRUE){assert(
this!=NULL); bits_.flag = (b==TRUE) ? 1 : 0;}
00358
bool isMarked(){
return (bits_.flag == 1);}
00359
void setEq(
int eq){assert(
this && eq >= 0); bits_.eq = eq;}
00360
int eq()
const{assert(
this!=NULL);
return bits_.eq;}
00361
00362
int len()
const{assert(
this!=NULL);
return bits_.len;}
00363
00364
int *gnodes_;
00365
double *vals_;
00366
private:
00367
struct{
00368
unsigned int eq : 32;
00369
unsigned int len : 31;
00370
unsigned int flag : 1;
00371 }bits_;
00372 };
00373
00374
class PromBank;
00375
class PromMPINode;
00377
00380 class PromNode :
public PromNodeBase,
public PromStack
00381 {
00382
public:
00383
PromNode() : parents_(NULL), symbData_(NULL) {}
00384
virtual ~
PromNode();
00385
00386
virtual int LiftCopy(
const PromNode *
const a );
00387
virtual int Copy(
const PromMPINode &a );
00388
virtual int Write(
int **ppb )
const = 0;
00389
virtual int Read(
PromParentBank *
const bank,
int **ppb ) = 0;
00390
virtual int GetWrite_size(
int &sz)
const = 0;
00391
virtual int Die(
PromBank *bank )=0;
00392
virtual int LiftCopyIn(
PromMPINode *mpinode )
const ;
00393
virtual int getNextNDF()
const = 0;
00394
virtual void reset();
00395
virtual int Archive(FILE *file=stderr,
const PromArchiveType type=PROM_PRINT);
00396
00397
int nParents()
const
00398 {
00399 assert(
this!=NULL);
00400
return (parents_ != NULL) ? parents_->
getSize() : 0;
00401 }
00402
int SetnParents(
PromParentBank *
const bank,
const int i );
00403
00404
PromNode* getParent()
const;
00405
bool isBound()
const{
00406 assert(
this != NULL && symbData_ != NULL );
00407
return (symbData_->dependents && symbData_->ghostID.lIndex_<0); }
00408
bool isExtended()
const {
00409 assert(
this != NULL && symbData_ != NULL );
00410
return (symbData_->dependents ? TRUE : FALSE);
00411 }
00412
bool isGhost()
const {
00413 assert(
this != NULL && symbData_ != NULL);
00414
return (symbData_->ghostID.lIndex_ >= 0);
00415 }
00416
bool isFixed()
const{
return PromElement::isFixed(bits_.ndf); }
00417
bool isFixed(
int type )
const{
return PromElement::isFixed(bits_.ndf,type);}
00418
inline bool isEqualFixed(
const PromNode *node )
const;
00419
inline bool isMoreFixed(
const PromNode *node )
const;
00420
bool isAllFixed()
const{
return PromElement::isAllFixed(bits_.ndf); }
00421
00422
int minAdjInSel()
const{
00423 assert(getState() == PROM_SELECTED); assert(
this!=NULL);
00424
return (
int)bits_.aux;
00425 }
00426
int SetMinAdjInSel(
unsigned int i ){
00427 assert(
this!=NULL);
00428
if(i>PROM_MAX_AUX_SZ){
00429
00430 i = PROM_MAX_AUX_SZ;
00431 }
00432 bits_.aux = i;
00433
return 0;
00434 }
00435
int nChildInSel()
const{
00436 assert(
this!=NULL);
00437
return (
int)bits_.color;
00438 }
00439
int SetnChildInSel(
unsigned int i ){
00440 assert(
this!=NULL);
00441
if(i>PROM_MAX_SHP_SZ){
00442 PetscPrintf(PETSC_COMM_SELF,
"WARNING: SetnChildInSel:i(%d) > %d ",
00443 i,PROM_MAX_COLOR);
00444 i = PROM_MAX_COLOR;
00445 }
00446 bits_.color = i;
00447
return 0;
00448 }
00449
bool skipSmooth()
const {
return bits_.qual; }
00450
int SetSkipSmooth(
bool b = TRUE ){ bits_.qual = b;
return 0; }
00451
00452
PromParentArr *parents_;
00453 PromSymbData *symbData_;
00454 };
00455
00457
00460 class PromAggNode :
public PromNode
00461 {
00462
friend int isAMGDeleteable(
const PromNode *curr,
const PromNode *n1,
00463
bool &deletable );
00464
public:
00465
PromAggNode();
00466
virtual ~
PromAggNode();
00467
00468
00469
virtual void reset();
00470
virtual int LiftCopy(
const PromNode *
const a );
00471
virtual int LiftCopyIn(
PromMPINode *mpinode )
const ;
00472
virtual int getNextNDF()
const;
00473
virtual int Write(
int **ppb )
const;
00474
virtual int Read(
PromParentBank *
const bank,
int **ppb );
00475
virtual int GetWrite_size(
int &sz )
const;
00476
virtual int Die(
PromBank *bank );
00477
virtual int Archive( FILE *file = stderr,
00478
const PromArchiveType type = PROM_PRINT );
00479
int MigrateToAgg(
const unsigned int hard,
const int kk,
00480
const int *
const ewgts,
00481 PromTable<PromList<PromNode*>*> &proc_list,
00482
bool &didit,
PromNode *nodes[],
00483
const PromTable<PromNode*> &ghosts,
00484
const int my0,
const int nloc, PromTable<int> &node_wt,
00485 PromTable<int> &table,
00486
const int nchildInSel = 1000 );
00487
int MigrateTo(
PromNode *c2, PromTable<PromList<PromNode*>*> &proc_list,
00488 PromTable<int> &table );
00489
int getBsz()
const{ assert(
this!=NULL);
return Bsz_; }
00490
int SetBsz(
int ss);
00491
00492 shpfloat *B_;
00493
private:
00494
int Bsz_;
00495 };
00496
00498
00501 class PromSymbGeoData {
00502
public:
00503
PromSymbGeoData() :
00504 parElem(NULL),
00505 coord(0.,0.,0.)
00506 {
00507
for(
int i=0;i<PROM_NODE_MAXFACET;i++) faceID[i] = -9;
00508 }
00509
PromCoord coord;
00510
PromDTet *parElem;
00511
int faceID[PROM_NODE_MAXFACET];
00512 };
00513
00515
00518 class PromGeoNode :
public PromNode
00519 {
00520
friend int IsGeoDeleteable(
const PromNode *
const curr,
00521
const PromNode *
const n1,
00522
bool &deletable );
00523
public:
00524
PromGeoNode();
00525
virtual ~
PromGeoNode();
00526
00527
virtual void reset();
00528
virtual int LiftCopy(
const PromNode *
const a );
00529
virtual int Copy(
const PromMPINode &a );
00530
virtual int LiftCopyIn(
PromMPINode *mpinode )
const ;
00531
virtual int getNextNDF()
const{
return getNDF();}
00532
virtual int Write(
int **ppb )
const;
00533
virtual int Read(
PromParentBank *
const bank,
int **ppb );
00534
virtual int GetWrite_size(
int &sz )
const;
00535
virtual int Die(
PromBank *bank );
00536
virtual int Archive(FILE *file=stderr,
const PromArchiveType type=PROM_PRINT);
00537
00538
PromDTet *setElemWithList(
const PromList<PromPoly*> *eList,
00539
PromParentBank *
const bank,
const int mype,
00540
int numtries, gfloat tol,
const bool set,
const bool nested );
00541
PromDTet *setElem(
PromDTet *e,
PromParentBank *
const bank,
const int mype,
00542
const gfloat t,
const bool,
const int,
00543
const PromDTet*,
const bool,
PromDTet **best = NULL,
00544 gfloat *fout=NULL );
00545
int MakeExteriorFacets(
PromFacet *[],
PromGeoNode *[][2], gfloat*,
00546
PromBank *bank,
int &out )
const;
00547
int SetElemAdjac()
const;
00548
int MaxOff( gfloat &smax,
int *maxi = NULL, gfloat *buff = NULL )
const;
00549
int SetFaceIDs(
int id0,
int id1 = -9,
int id2 = -9,
int id3 = -9,
00550
int id4 = -9,
int id5 = -9 );
00551
int MaxFaceID()
const;
00552
int ReadFaceIDs(
int *&buff ){
00553 assert(
this && symbGeoData_);
00554
int i,ii,ret = PromContext::Read( ii, symbGeoData_->faceID, buff );
00555
for( i = ii ; i < PROM_NODE_MAXFACET ; i++ ) symbGeoData_->faceID[i] = -9;
00556
return ret;
00557 }
00558
int numFaces()
const{
00559 assert(
this && symbGeoData_);
00560
int ret;
00561
for(ret=0 ; ret < PROM_NODE_MAXFACET && symbGeoData_->faceID[ret]>=0;ret++)
00562 ;
00563
return ret;
00564 }
00565
int WriteFaceIDs(
int *&buff)
const{
00566
return PromContext::Write( numFaces(), symbGeoData_->
faceID, buff );
00567 }
00568
00569
00570
static PromTable<PromDTet*> *bufftable_;
00571
public:
00572
static int clearBuffers(){
00573
if(bufftable_){
delete bufftable_; bufftable_=NULL;}
00574
return 0;
00575 }
00576
00577
PromSymbGeoData *symbGeoData_;
00578 };
00579
00581
00584 class PromMPINode :
public PromNodeBase
00585 {
00586
public:
00587
PromMPINode(): fIndex_(-8), angle_(-99.){}
00588
PromMPINode(
PromMPINode &a ){
00589 PromNodeBase::operator=( a );
00590 coord_ = a.
coord_;
00591 ghostID_ = a.
ghostID_;
00592 fIndex_ = a.
fIndex_;
00593 angle_ = a.
angle_;
00594 }
00595
PromMPINode &operator=(
const PromMPINode &a ){
00596 PromNodeBase::operator=( a );
00597 coord_ = a.
coord_; PromElement::operator=( a );
00598 ghostID_ = a.
ghostID_;
00599 fIndex_ = a.
fIndex_;
00600 angle_ = a.
angle_;
00601
return *
this;
00602 }
00603
int feap(
int &ierr)
const{ ierr = !(
this && fIndex_ >= 0);
return fIndex_;}
00604
int feap()
const{ assert(
this!=NULL && fIndex_ >= 0);
return fIndex_;}
00605
void setFeap(
int f ){ assert(
this!=NULL); fIndex_ = f; }
00606
00607
int Write(
int **ppb )
const;
00608
int Read(
int **ppb );
00609
static int GetWrite_size(
int &sz );
00610
00611
int fIndex_;
00612
PromCoord coord_;
00613
PromGlobalID ghostID_;
00614 gfloat angle_;
00615 };
00616
00617
#endif //__PROM_NODE__H__