00001 
00006 #ifndef CHUNK_H
00007 #define CHUNK_H
00008 
00009 #include <vector.h>
00010 #include "charm++.h"
00011 #include "ref.h"
00012 #include "node.h"
00013 #include "element.h"
00014 #include "messages.h"
00015 
00016 
00017 #include "PMAF.decl.h"
00018 
00019 
00020 extern CProxy_chunk mesh;
00021 CtvExtern(chunk *, _refineChunk);
00022 
00023 
00024 
00025 class refineClient {
00026 public:
00027   virtual ~refineClient() {}
00028   
00029   
00030   virtual void splinter(int triNo, double x, double y, double z) =0;
00031 
00032   
00033   
00034   
00035   virtual void collapse(int triNo1, int triNo2, int pt1, int pt2) =0;
00036 
00037   
00038   
00039   virtual void movePoint(int pt, double x, double y, double z) =0;
00040 };
00041 
00042 class refineResults; 
00043 
00044 typedef struct prioLockStruct {
00045   int holder;
00046   double prio;
00047   prioLockStruct *next;
00048 } *prioLockRequests;
00049 
00050 class chunk : public ArrayElement1D {
00051   
00052   
00053   int cid, numElements, numNodes, numChunks;
00054 
00055   
00056   int sizeElements, sizeNodes;
00057 
00058   
00059   int additions, coordsRecvd;
00060   
00061   
00062   
00063   
00064   
00065   int debug_counter, refineInProgress, coarsenInProgress, modified;
00066 
00067   int accessLock, adjustLock;
00068  public:
00069   int lock, lockHolder, lockCount;
00070   double lockPrio;
00071   double smoothness;
00072   prioLockRequests lockList;
00073   
00074   std::vector<element> theElements;
00075   std::vector<node> theNodes;
00076   std::vector<std::vector<int> > theSurface;
00077 
00078   
00079   refineClient *theClient;
00080   refineResults *refineResultsStorage;
00081 
00082   
00083   chunk(int nChunks);
00084   chunk(CkMigrateMessage *) { };
00085   
00086   
00087   void refineElement(int idx, double volume);
00088   void refineElement(int idx);
00089   void refiningElements();  
00090   void coarsenElement(int idx, double volume);
00091   void coarseningElements();    
00092   void improveMesh();
00093   void relocatePoints();
00094   void flippingElements();    
00095 
00096   intMsg *lockChunk(int lh, double prio);
00097   void unlockChunk(int lh);
00098   int lockLocalChunk(int lh, double prio);
00099   void unlockLocalChunk(int lh);
00100   void removeLock(int lh);
00101   void insertLock(int lh, double prio);
00102 
00103   
00104   void print();
00105   void out_print();
00106   
00107   
00108   nodeMsg *getNode(int n);
00109   void updateNodeCoord(nodeMsg *);
00110   void relocationVote(nodeVoteMsg *);
00111   
00112   
00113   doubleMsg *getVolume(intMsg *im);
00114   void setTargetVolume(doubleMsg *);
00115   void resetTargetVolume(doubleMsg *);
00116   elemRef findNeighbor(nodeRef nr1, nodeRef nr2, nodeRef nr3, int lidx);
00117   refMsg *findRemoteNeighbor(threeNodeMsg *);
00118   intMsg *checkFace(int idx, elemRef face);
00119   intMsg *checkFace(int idx, node n1, node n2, node n3, elemRef nbr);
00120   intMsg *lockLF(int idx, node n1, node n2, node n3, node n4, 
00121          elemRef requester, double prio);
00122   splitResponse *splitLF(int idx,node in1, node in2, node in3, node in4,
00123                elemRef requester);
00124   LEsplitResult *LEsplit(LEsplitMsg *);
00125   lockResult *lockArc(lockArcMsg *lm);
00126   void unlockArc1(int idx, int prio, elemRef parentRef, elemRef destRef, node aNode, 
00127          node bNode);
00128   void unlockArc2(int idx, int prio, elemRef parentRef, elemRef destRef, node aNode, 
00129          node bNode);
00130   void updateFace(int idx, int rcid, int ridx);
00131   void updateFace(int idx, elemRef oldElem, elemRef newElem);
00132   flip23response *flip23remote(flip23request *);
00133   flip32response *chunk::flip32remote(flip32request *fr);
00134   flip32response *chunk::remove32element(flip32request *fr);
00135 
00136   
00137   void debug_print(int c); 
00138 
00139   
00140   void splitAll(nodeRef le1, nodeRef le2, nodeRef mid, int elemId);
00141   nodeRef findNode(node n);
00142 
00143   
00144   int nodeOnSurface(int n);
00145   int edgeOnSurface(int n1, int n2);
00146   int faceOnSurface(int n1, int n2, int n2);
00147   void updateFace(int n1, int n2, int n3, int oldNode, int newNode);
00148   void addFace(int n1, int n2, int n3);
00149   void removeFace(int n1, int n2, int n3);
00150   void simpleAddFace(int n1, int n2, int n3);
00151   void simpleUpdateFace(int n1, int n2, int n3, int newNode);
00152   void simpleRemoveFace(int n1, int n2, int n3);
00153   void printSurface();
00154   void printEdgeLists();
00155 
00156   
00157   void getAccessLock();
00158   void forcedGetAccessLock();
00159   void releaseAccessLock();
00160   void getAdjustLock();
00161   void releaseAdjustLock();
00162 
00163   
00164   void allocMesh(int nEl);
00165   void adjustMesh();
00166   nodeRef addNode(node& n);
00167   elemRef addElement(nodeRef& nr1, nodeRef& nr2, nodeRef& nr3, nodeRef& nr4);
00168   void removeNode(intMsg *);
00169   void removeElement(intMsg *);
00170 
00171   
00172   
00173   void newMesh(int nEl, int nGhost,const int *conn_,const int *gid_, 
00174            int *surface, int nSurFaces, int idxOffset);
00175   
00176   void updateNodeCoords(int nNode, double *coord, int nEl, int nFx,int *fixed);
00177   
00178   void deriveFaces();
00179   void refine(double *desiredVolume, refineClient *client);
00180   void coarsen(double *desiredVolume, refineClient *client);
00181   void improve(refineClient *client);
00182 
00183   
00184   void newMesh(meshMsg *);  
00185   void updateNodeCoords(coordMsg *);
00186   void refine();
00187   void start();
00188   void improve();
00189   void finalizeImprovements();
00190   void checkRefine();
00191 };
00192 
00193 #endif