00001
00002
00003
00004
00005
00006
00007 #ifndef __CSAR_PATCH_H
00008 #define __CSAR_PATCH_H
00009
00010 #include <charm++.h>
00011 #include "gridutil.h"
00012
00013
00014 class extrudeMethod {
00015 public:
00016 int toWidth;
00017 bool withCorners;
00018 extrudeMethod(int ghostWidth) {
00019 if (ghostWidth>=0) {
00020 toWidth=ghostWidth; withCorners=false;
00021 } else {
00022 toWidth=-ghostWidth; withCorners=true;
00023 }
00024 }
00025 extrudeMethod(int w,bool c) :toWidth(w),withCorners(c) { }
00026 extrudeMethod(void) { }
00027 void pup(PUP::er &p) {
00028 p(toWidth);
00029 p(withCorners);
00030 }
00031 };
00032
00033
00034 class patch {
00035 protected:
00036
00037 blockSpan span;
00038
00039 int flatAxis;
00040 bool isLow;
00041 public:
00042 enum {ext=0,internal=1} type;
00043
00044
00045 blockSpan getExtents(const extrudeMethod &m,bool forVoxel,int dir=1);
00046
00047 virtual void print(void) = 0;
00048 void pup(PUP::er &p)
00049 {
00050 span.pup(p);
00051 p((int&)type);
00052 p(flatAxis);
00053 p(isLow);
00054 }
00055
00056 patch(void) { }
00057 virtual ~patch() { }
00058 protected:
00059 patch(const blockSpan &span_);
00060 };
00061
00062
00063
00064 class externalBCpatch : public patch {
00065 public:
00066
00067 int bcNo;
00068 externalBCpatch(void) {}
00069 externalBCpatch(
00070 const blockSpan &srcSpan_,
00071 int bcNo_)
00072 : patch(srcSpan_), bcNo(bcNo_) { type=ext; }
00073 void pup(PUP::er &p)
00074 {
00075 patch::pup(p);
00076 p(bcNo);
00077 }
00078 void print(void)
00079 {
00080 CkPrintf("Type=external, bc#=%d, ",bcNo); span.print();
00081 CkPrintf("\n");
00082 }
00083 };
00084
00085
00086
00087
00088 class orientation {
00089 int s2d[3];
00090 int flip[3];
00091 public:
00092 orientation(void) {}
00093 orientation(const int *codedOrient);
00094 int operator[](int sAxis) const {return s2d[sAxis];}
00095 int dIsFlipped(int sAxis) const {return flip[sAxis];}
00096
00097
00098 int dToS(int dAxis)
00099 {
00100 for(int sAxis=0;sAxis<3;sAxis++)
00101 if(dAxis == s2d[sAxis])
00102 return sAxis;
00103
00104 return -1;
00105 }
00106
00107
00108
00109 blockLoc destAxis(int dAxis) {
00110 int sAxis=dToS(dAxis);
00111 blockLoc ret(0,0,0);
00112 if (dIsFlipped(sAxis))
00113 ret[sAxis]=-1;
00114 else
00115 ret[sAxis]=1;
00116 return ret;
00117 }
00118 void pup(PUP::er &p)
00119 {
00120 p(s2d,3);
00121 p(flip,3);
00122 }
00123 void print(void)
00124 {
00125 CkPrintf(" s2d=%d,%d,%d flip=%d,%d,%d\n",
00126 s2d[0],s2d[1],s2d[2],flip[0],flip[1],flip[2]);
00127 }
00128 };
00129
00130
00131 class internalBCpatch : public patch {
00132 public:
00133 int dest;
00134 int destPatch;
00135 orientation orient;
00136
00137 internalBCpatch(void) {}
00138 internalBCpatch(int dest_,int destPatch_,const int *codedOrient,
00139 const blockSpan &span_)
00140 : patch(span_),
00141 dest(dest_),destPatch(destPatch_),
00142 orient(codedOrient) { type=internal; }
00143 void pup(PUP::er &p)
00144 {
00145 patch::pup(p);
00146 p(dest);
00147 p(destPatch);
00148 orient.pup(p);
00149 }
00150 void print(void)
00151 {
00152 CkPrintf("Type=internal (%d:%d) ",dest,destPatch);
00153 span.print();
00154 orient.print();
00155 CkPrintf("\n");
00156 }
00157 };
00158
00159
00160
00161 class block {
00162 blockDim dim;
00163 vector3d *locs;
00164 int nPatches;
00165 patch **patches;
00166 public:
00167 block(const char *filePrefix,int blockNo);
00168 block(void) {};
00169 ~block();
00170
00171 const blockDim &getDim(void) const {return dim;}
00172 vector3d &getLoc(const blockLoc &i) {return locs[dim[i]];}
00173 const vector3d &getLoc(const blockLoc &i) const
00174 {return locs[dim[i]];}
00175
00176 int getPatches(void) const {return nPatches;}
00177 patch *getPatch(int i) const {return patches[i];}
00178 void print(void)
00179 {
00180 CkPrintf("dimensions: %d, %d, %d\n", dim[0], dim[1], dim[2]);
00181 CkPrintf("nPatches=%d\n", nPatches);
00182 for(int i=0;i<nPatches;i++) {
00183 CkPrintf("----patch %d----\n", i);
00184 patches[i]->print();
00185 }
00186 }
00187 void pup(PUP::er &p)
00188 {
00189 dim.pup(p);
00190 int n = dim.getSize();
00191 p(n);
00192 if(p.isUnpacking())
00193 locs = new vector3d[n];
00194 p((char*)locs, n*sizeof(vector3d));
00195 p(nPatches);
00196 if(p.isUnpacking())
00197 patches = new patch*[nPatches];
00198 for(int i=0;i<nPatches;i++) {
00199 if(p.isUnpacking()) {
00200 int type;
00201 p(type);
00202 if(type==patch::ext) {
00203 patches[i] = new externalBCpatch();
00204 ((externalBCpatch*)(patches[i]))->pup(p);
00205 } else {
00206 patches[i] = new internalBCpatch();
00207 ((internalBCpatch*)(patches[i]))->pup(p);
00208 }
00209 } else {
00210 int type = (int) patches[i]->type;
00211 p(type);
00212 if(type==patch::ext)
00213 ((externalBCpatch*)(patches[i]))->pup(p);
00214 else
00215 ((internalBCpatch*)(patches[i]))->pup(p);
00216 }
00217 }
00218 if (p.isPacking())
00219 delete this;
00220 }
00221 };
00222
00223
00224 #endif
00225
00226
00227
00228
00229
00230
00231