Actual source code: IndexBundle.hh

  1: #ifndef included_ALE_IndexBundle_hh
  2: #define included_ALE_IndexBundle_hh

  4: #ifndef  included_ALE_Stack_hh
  5: #include <Stack.hh>
  6: #endif

  8: #include <queue>

 10: namespace ALE {

 12:   typedef enum {INSERTION = 0, ADDITION = 1} BundleAssemblyPolicy;
 13:   typedef enum {localPoint, leasedPoint, rentedPoint} PointType;

 15:   class IndexBundle : public Coaster {
 16:     int     _dirty;
 17:     Obj<Stack>     _dimensionsToElements;
 18:     Obj<Stack>     _indicesToArrows;
 19:     Obj<Stack>     _arrowsToEnds;
 20:     Obj<Stack>     _arrowsToStarts;
 21:     //
 22:     Obj<PreSieve>  _overlapOwnership;     // a PreSieve supporting each overlap point at its owners
 23:     Obj<Stack>     _localOverlapIndices;  // a stack with _overlapOwnership in the base, a discrete top contains the local indices
 24:                                           // attached to the overlap points by vertical arrows
 25:     Obj<PreSieve>  _remoteOverlapIndices; // a completion stack with the remote overlap indices: completionTypeArrow, footprintTypeCone
 26:     Obj<PreSieve> _pointTypes;
 27:     Obj<PreSieve> _localIndices;
 28:     Obj<PreSieve> _globalIndices;
 29:     int *_firstGlobalIndex;
 30:     //
 31:     BundleAssemblyPolicy _assemblyPolicy;
 32:     //
 33:     void __reset(Obj<Sieve> topology = Obj<Sieve>()) {
 34:       if(topology.isNull()) {
 35:         topology = Obj<Sieve>(Sieve(this->comm));
 36:       }
 37:       //
 38:       this->_assemblyPolicy       = INSERTION;
 39:       //
 40:       this->_dimensionsToElements = Obj<Stack>(Stack(this->comm));
 41:       this->_dimensionsToElements->setTop(Obj<PreSieve>(PreSieve(this->comm)));
 42:       this->_dimensionsToElements->setBottom(topology);
 43:       //
 44:       this->_arrowsToStarts = Obj<Stack>(Stack(this->comm));
 45:       this->_arrowsToStarts->setTop(Obj<PreSieve>(PreSieve(this->comm)));
 46:       this->_arrowsToStarts->setBottom(topology);
 47:       //
 48:       this->_arrowsToEnds = Obj<Stack>(Stack(this->comm));
 49:       this->_arrowsToEnds->setTop(this->_arrowsToStarts->top());
 50:       this->_arrowsToEnds->setBottom(topology);
 51:       //
 52:       this->_localOverlapIndices  = Obj<Stack>(Stack(this->comm));
 53:       this->_remoteOverlapIndices = Obj<PreSieve>(PreSieve(this->comm));
 54:       //
 55:       this->__resetArrowIndices(); // this method depends on _arrowsToStarts having already been setup
 56:       this->_cacheFiberIndices = 0;
 57:       //
 58:       _pointTypes = Obj<PreSieve>(PreSieve(this->comm));
 59:       _localIndices = Obj<PreSieve>(PreSieve(this->comm));
 60:       _globalIndices = Obj<PreSieve>(PreSieve(this->comm));
 61:     };
 62:     //
 63:     Obj<Sieve>     __getTopology(){return this->_dimensionsToElements->bottom();};
 64:     Obj<PreSieve>  __getIndices(){return this->_indicesToArrows->top();};
 65:     Obj<PreSieve>  __getArrows(){return this->_arrowsToStarts->top();};
 66:     void           __resetArrowIndices(){
 67:       this->_indicesToArrows = Obj<Stack>(new Stack(this->comm));
 68:       this->_indicesToArrows->setTop(Obj<PreSieve>(new PreSieve(this->comm)));
 69:       this->_indicesToArrows->setBottom(this->__getArrows());  // note that __getArrows does not rely on _indicesToArrows
 70:     };
 71:     //
 72:     bool           _cacheFiberIndices;
 73:     Obj<Point_set> __validateChain(Obj<Point_set> ee) {
 74:       if(!ee->size()){
 75:         return getTopology()->leaves();
 76:       }
 77:       else{
 78:         return(ee);
 79:       };
 80:     };
 81:     Point          __getArrow(Point e1, Point e);
 82:     Point          __getArrowInterval(Point e1, Point e);
 83:     void           __setArrowInterval(Point e1, Point e, Point interval);
 84:     Obj<PreSieve> __computeIndices(Obj<Point_set> supports, Obj<Point_set> base, bool includeBoundary = 0, Obj<Point_set> exclusion = NULL);
 85:     Obj<PreSieve> __computeBoundaryIndices(Point support, Point__Point& seen, int32_t& off);
 86:     //
 87:     void __markDirty(){this->_dirty = 1;};
 88:     void __markClean(){this->_dirty = 0;};
 89:     int  __isClean(){return !(this->_dirty);};
 90:     void __assertClean(int flag){if((this->__isClean()) != flag) throw Exception("Clean assertion failed");};
 91:     //
 92:     static const int stratumTypeDepth  = 0;
 93:     static const int stratumTypeHeight = 1;
 94:     IndexBundle& __setFiberDimensionByStratum(int stratumType, int32_t stratumIndex, int32_t dim);
 95:     ALE::Point __getMaxDepthElement(Obj<Point_set> points);
 96:     int__Point __checkOrderChain(Obj<Point_set> order, int& maxDepth, int& minDepth);
 97:     void __orderElement(int dim, ALE::Point element, std::map<int, std::queue<Point> > *ordered, ALE::Obj<ALE::Point_set> elementsOrdered);
 98:     ALE::Point __orderCell(int dim, int__Point *orderChain, std::map<int, std::queue<Point> > *ordered, ALE::Obj<ALE::Point_set> elementsOrdered);
 99:     ALE::PointType __getPointType(ALE::Point point);
100:     ALE::Obj<ALE::PreSieve> __computePointTypes();
101:     void __postIntervalRequests(ALE::Obj<ALE::PreSieve> pointTypes, int__Point rentMarkers, MPI_Request *intervalRequests[], int **receivedIntervals[]);
102:     void __sendIntervals(ALE::Obj<ALE::PreSieve> pointTypes, int__Point leaseMarkers, ALE::Obj<ALE::PreSieve> indices);
103:     void __receiveIntervals(ALE::Obj<ALE::PreSieve> pointTypes, int__Point rentMarkers, MPI_Request *requests, int *recvIntervals[], ALE::Obj<ALE::PreSieve> indices);
104:   public:
105:     // constructors/destructors
106:     IndexBundle()                    : Coaster(MPI_COMM_SELF) {__reset();};
107:     IndexBundle(MPI_Comm& comm)      : Coaster(comm) {__reset();};
108:     IndexBundle(Obj<Sieve> topology) : Coaster(topology->getComm()) {__reset(topology);};
109:     virtual ~IndexBundle(){};
110:     void view(const char *name);
111:     //
112:     virtual void            setComm(MPI_Comm c) {this->comm = c; __reset();};
113:     //
114:     IndexBundle&            setAssemblyPolicy(BundleAssemblyPolicy policy);
115:     bool                    getFiberIndicesCachingPolicy() {return this->_cacheFiberIndices;};
116:     IndexBundle&            setFiberIndicesCachingPolicy(bool policy){/*cannot cache (yet)*/this->_cacheFiberIndices = 0;return *this;};
117:     BundleAssemblyPolicy    getAssemblyPolicy() {return this->_assemblyPolicy;};
118:     IndexBundle&            setTopology(Obj<Sieve> topology);
119:     Obj<Sieve>              getTopology(){return this->__getTopology();};
120:     IndexBundle&            setFiberDimension(Point element, int32_t d);
121:     IndexBundle&            setFiberDimensionByDepth(int32_t depth, int32_t dim){
122:       return __setFiberDimensionByStratum(stratumTypeDepth, depth, dim);
123:     };
124:     IndexBundle&            setFiberDimensionByHeight(int32_t height, int32_t dim){
125:       return __setFiberDimensionByStratum(stratumTypeHeight, height, dim);
126:     };
127:     // Primary methods
128:     int32_t                 getFiberDimension(Obj<Point_set> ee);
129:     int32_t                 getBundleDimension(Obj<Point_set> ee);
130:     Point                   getFiberInterval(Point support,  Obj<Point_set> base);
131:     Obj<PreSieve>           getFiberIndices(Obj<Point_set> support,  Obj<Point_set> base, Obj<Point_set> exclusion = NULL);
132:     Obj<PreSieve>           getClosureIndices(Obj<Point_set> support, Obj<Point_set> base);
133:     Obj<Point_array>        getOrderedIndices(Obj<Point_set> order,  Obj<PreSieve> indices);
134:     // Convenience methods
135:     int32_t                 getFiberDimension(Point e){return getFiberDimension(Point_set(e));};
136:     int32_t                 getBundleDimension(Point e){return getBundleDimension(Point_set(e));};
137:     Point                   getFiberInterval(Point support) {
138:       return getFiberInterval(support, Point_set());
139:     };
140:     Obj<Point_array>        getOrderedClosureIndices(Obj<Point_set> order, Obj<Point_set> base) {
141:       base = __validateChain(base);
142:       return getOrderedIndices(order, getClosureIndices(Point_set(__getMaxDepthElement(order)), base));
143:     };
144:     // Remote ordering methods
145:     void                    computeOverlapIndices(); // collective
146:     int32_t                 getOverlapSize();
147:     Obj<Point_set>          getOverlapOwners(Point e);
148:     Obj<PreSieve>           getOverlapFiberIndices(Obj<Point_set> supports, int32_t proc);
149:     Obj<PreSieve>           getOverlapClosureIndices(Obj<Point_set> supports, int32_t proc);
150:     // Convenience methods
151:     Obj<PreSieve>           getOverlapFiberIndices(Point e, int32_t proc) {return getOverlapFiberIndices(Point_set(e), proc);};
152:     Obj<PreSieve>           getOverlapClosureIndices(Point e, int32_t proc) {return getOverlapClosureIndices(Point_set(e), proc);};
153:     Obj<Point_array>        getOverlapOrderedClosureIndices(Obj<Point_set> order, int32_t proc) {
154:       Obj<PreSieve> indices = getOverlapClosureIndices(Point_set(__getMaxDepthElement(order)), proc);
155:       return getOrderedIndices(order, indices);
156:     };
157:     // Global ordering methods
158:     Obj<PreSieve>           getPointTypes();
159:     void                    computeGlobalIndices(); // collective
160:     int32_t                 getGlobalSize();
161:     int32_t                 getLocalSize();
162:     int*                    getLocalSizes();
163:     int32_t                 getRemoteSize();
164:     Obj<PreSieve>           getGlobalIndices();
165:     Obj<PreSieve>           getLocalIndices();
166:     int32_t                 getGlobalOwner(Point e);
167:     Point                   getGlobalFiberInterval(Point support);
168:     Obj<PreSieve>           getGlobalFiberIndices(Obj<Point_set> supports);
169:     Obj<PreSieve>           getLocalFiberIndices(Obj<Point_set> supports);
170:     Obj<PreSieve>           getGlobalClosureIndices(Obj<Point_set> supports);
171:     Obj<PreSieve>           getLocalClosureIndices(Obj<Point_set> supports);
172:     // Convenience methods
173:     Obj<PreSieve>           getGlobalFiberIndices(Point e) {return getGlobalFiberIndices(Point_set(e));};
174:     Obj<PreSieve>           getLocalFiberIndices(Point e) {return getLocalFiberIndices(Point_set(e));};
175:     Obj<PreSieve>           getGlobalClosureIndices(Point e) {return getGlobalClosureIndices(Point_set(e));};
176:     Obj<PreSieve>           getLocalClosureIndices(Point e) {return getLocalClosureIndices(Point_set(e));};
177:     Obj<Point_array>        getGlobalOrderedClosureIndices(Obj<Point_set> order) {
178:       Obj<PreSieve> indices = getGlobalClosureIndices(Point_set(__getMaxDepthElement(order)));
179:       return getOrderedIndices(order, indices);
180:     };
181:     Obj<Point_array>        getLocalOrderedClosureIndices(Obj<Point_set> order) {
182:       Obj<PreSieve> indices = getLocalClosureIndices(Point_set(__getMaxDepthElement(order)));
183:       return getOrderedIndices(order, indices);
184:     };
185:     // Mapping methods
186:     Obj<Stack>              computeMappingIndices(Obj<PreSieve> pointTypes, Obj<IndexBundle> target);
187:   };// class IndexBundle



191: } // namespace ALE

193: #endif