AFEPack
|
00001 00011 #define TEMPLATE template <int DIM, int DOW> 00012 #define THIS MemoryReclaimer<DIM,DOW> 00013 00017 TEMPLATE 00018 template <int DIM1> inline void 00019 THIS::labelHGeometry(HGeometry<DIM1,DOW>& g, int lab) 00020 { 00021 for (int i = 0;i < g.n_vertex;++ i) { 00022 labelHGeometry(*(g.vertex[i]), lab); 00023 } 00024 for (int i = 0;i < g.n_boundary;++ i) { 00025 labelHGeometry(*(g.boundary[i]), lab); 00026 } 00027 g.index = lab; 00028 } 00029 00034 TEMPLATE 00035 template <int DIM1> inline void 00036 THIS::labelHGeometryRecursively(HGeometry<DIM1,DOW>& g, int lab) 00037 { 00038 for (int i = 0;i < g.n_boundary;++ i) { 00039 labelHGeometryRecursively(*(g.boundary[i]), lab); 00040 } 00041 if (g.isRefined()) { 00042 for (int i = 0;i < g.n_child;++ i) { 00043 labelHGeometryRecursively(*(g.child[i]), lab); 00044 } 00045 } 00046 00047 labelHGeometry(g, lab); 00048 } 00049 00054 TEMPLATE inline void 00055 THIS::labelHGeometry(HGeometry<0,DOW>& g, int lab) 00056 { 00057 g.index = lab; 00058 } 00059 00060 TEMPLATE inline void 00061 THIS::labelHGeometryRecursively(HGeometry<0,DOW>& g, int lab) 00062 { 00063 g.index = lab; 00064 } 00065 00071 TEMPLATE void 00072 THIS::reclaimIrregularMesh(typename THIS::ir_mesh_t& m) 00073 { 00074 ActiveElementIterator<DIM, DOW> 00075 the_ele = m.beginActiveElement(), 00076 end_ele = m.endActiveElement(); 00077 for (;the_ele != end_ele;++ the_ele) { 00078 if (the_ele->isRefined()) { 00079 for (int i = 0;i < the_ele->n_child;++ i) { 00080 m.deleteTree(the_ele->child[i]); 00081 the_ele->child[i] = NULL; 00082 } 00083 } 00084 } 00085 } 00086 00091 TEMPLATE 00092 void THIS::initialTreeLabel() 00093 { 00094 typename HGeometryTree<DIM,DOW>::RootIterator 00095 the_ele = h_tree->beginRootElement(), 00096 end_ele = h_tree->endRootElement(); 00097 for (;the_ele != end_ele;++ the_ele) { 00098 labelHGeometryRecursively(*the_ele, -1); 00099 } 00100 } 00101 00106 TEMPLATE 00107 void THIS::labelIrregularMesh(typename THIS::ir_mesh_t& m) 00108 { 00109 RootFirstElementIterator<DIM, DOW> 00110 the_ele = m.beginRootFirstElement(), 00111 end_ele = m.endRootFirstElement(); 00112 for (;the_ele != end_ele;++ the_ele) { 00113 labelHGeometry(*(the_ele->h_element), 1); 00114 } 00115 00116 typename THIS::ir_mesh_t::mesh_t& mesh = m.regularMesh(); 00117 #define LABEL_USED_HGEOMETRY(D) \ 00118 if (dim >= D) { \ 00119 int n_geo = mesh.h_geometry()[D].size(); \ 00120 for (int i = 0;i < n_geo;++ i) { \ 00121 HGeometry<D,dow> * p_geo = mesh.template h_geometry<D>(i); \ 00122 labelHGeometry(*p_geo, 1); \ 00123 } \ 00124 } 00125 00126 LABEL_USED_HGEOMETRY(0); 00127 LABEL_USED_HGEOMETRY(1); 00128 LABEL_USED_HGEOMETRY(2); 00129 LABEL_USED_HGEOMETRY(3); 00130 00131 #undef LABEL_USED_HGEOMETRY 00132 } 00133 00141 TEMPLATE 00142 template <int DIM1> inline int 00143 THIS::relabelHGeometryRecursively(HGeometry<DIM1,DOW>& g) 00144 { 00145 for (int i = 0;i < g.n_vertex;++ i) { 00146 if (g.vertex[i] == NULL) continue; 00147 if (relabelHGeometryRecursively(*(g.vertex[i])) == -2) { 00148 g.vertex[i] = NULL; 00149 } 00150 } 00151 for (int i = 0;i < g.n_boundary;++ i) { 00152 if (g.boundary[i] == NULL) continue; 00153 if (relabelHGeometryRecursively(*(g.boundary[i])) == -2) { 00154 g.boundary[i] = NULL; 00155 } 00156 } 00157 if (g.isRefined()) { 00158 for (int i = 0;i < g.n_child;++ i) { 00159 if (g.child[i] == NULL) continue; 00160 if (relabelHGeometryRecursively(*(g.child[i])) == -2) { 00161 g.child[i] = NULL; 00162 } 00163 } 00164 } 00165 Assert ((g.index == -1) || 00166 (g.index == 1) || 00167 (g.index == -2), ExcInternalError()); 00168 if (g.index == -1) { 00169 g.index = -2; 00170 return -1; 00171 } 00172 else return g.index; 00173 } 00174 00175 00180 TEMPLATE inline int 00181 THIS::relabelHGeometryRecursively(HGeometry<0,DOW>& g) 00182 { 00183 Assert ((g.index == -1) || 00184 (g.index == 1) || 00185 (g.index == -2), ExcInternalError()); 00186 if (g.index == -1) { 00187 g.index = -2; 00188 return -1; 00189 } 00190 else return g.index; 00191 } 00192 00197 TEMPLATE 00198 template <int DIM1> inline int 00199 THIS::reclaimHGeometryRecursively(HGeometry<DIM1,DOW>& g) 00200 { 00201 for (int i = 0;i < g.n_vertex;++ i) { 00202 if (g.vertex[i] != NULL) { 00203 if (reclaimHGeometryRecursively(*(g.vertex[i])) == -1) { 00204 g.vertex[i] = NULL; 00205 } 00206 } 00207 } 00208 for (int i = 0;i < g.n_boundary;++ i) { 00209 if (g.boundary[i] != NULL) { 00210 if (reclaimHGeometryRecursively(*(g.boundary[i])) == -1) { 00211 g.boundary[i] = NULL; 00212 } 00213 } 00214 } 00215 for (int i = 0;i < g.n_child;++ i) { 00216 if (g.child[i] == NULL) continue; 00217 if (reclaimHGeometryRecursively(*(g.child[i])) == -1) { 00218 g.child[i] = NULL; 00219 } 00220 } 00221 Assert ((g.index == 1 || g.index == -2), ExcInternalError()); 00222 if (g.index == -2) { 00223 this->reclaimHGeometry(&g, DIM1); 00224 return -1; 00225 } 00226 else { 00227 return 1; 00228 } 00229 } 00230 00231 00236 TEMPLATE inline int 00237 THIS::reclaimHGeometryRecursively(HGeometry<0,DOW>& g) 00238 { 00239 Assert ((g.index == 1 || g.index == -2), ExcInternalError()); 00240 if (g.index == -2) { 00241 this->reclaimHGeometry(&g, 0); 00242 return -1; 00243 } 00244 else { 00245 return 1; 00246 } 00247 } 00248 00249 00254 TEMPLATE 00255 void THIS::reclaimTreeMemory() 00256 { 00257 typename HGeometryTree<DIM,DOW>::RootIterator 00258 the_ele = h_tree->beginRootElement(), 00259 end_ele = h_tree->endRootElement(); 00260 for (;the_ele != end_ele;++ the_ele) { 00261 relabelHGeometryRecursively(*the_ele); 00262 } 00263 00264 the_ele = h_tree->beginRootElement(); 00265 for (;the_ele != end_ele;++ the_ele) { 00266 reclaimHGeometryRecursively(*the_ele); 00267 } 00268 } 00269 00270 TEMPLATE 00271 void THIS::reclaim() 00272 { 00274 typename std::list<typename THIS::ir_mesh_t *>::iterator 00275 the_ir_mesh = ir_mesh.begin(), 00276 end_ir_mesh = ir_mesh.end(); 00277 for (;the_ir_mesh != end_ir_mesh;++ the_ir_mesh) { 00278 reclaimIrregularMesh(**the_ir_mesh); 00279 } 00280 00282 initialTreeLabel(); 00283 00285 the_ir_mesh = ir_mesh.begin(); 00286 for (;the_ir_mesh != end_ir_mesh;++ the_ir_mesh) { 00287 labelIrregularMesh(**the_ir_mesh); 00288 } 00289 00291 reclaimTreeMemory(); 00292 } 00293 00294 #undef THIS 00295 #undef TEMPLATE 00296