|
AFEPack
|
00001 00011 #define TEMPLATE template <int DIM, int DOW> 00012 #define THIS MemoryReclaimer<DIM,DOW> 00013 00018 TEMPLATE 00019 template <int DIM1> inline void 00020 THIS::labelHGeometry(HGeometry<DIM1,DOW>& g, int lab) 00021 { 00022 for (int i = 0;i < g.n_vertex;++ i) { 00023 labelHGeometry(*(g.vertex[i]), lab); 00024 } 00025 for (int i = 0;i < g.n_boundary;++ i) { 00026 labelHGeometry(*(g.boundary[i]), lab); 00027 } 00028 g.index = lab; 00029 } 00030 00035 TEMPLATE inline void 00036 THIS::labelHGeometry(HGeometry<0,DOW>& g, int lab) 00037 { 00038 g.index = lab; 00039 } 00040 00045 TEMPLATE 00046 template <int DIM1> inline void 00047 THIS::labelHGeometryRecursively(HGeometry<DIM1,DOW>& g, int lab) 00048 { 00049 if (g.isRefined()) { 00050 for (int i = 0;i < g.n_child;++ i) { 00051 labelHGeometryRecursively(*(g.child[i]), lab); 00052 } 00053 } 00054 00055 labelHGeometry(g, lab); 00056 } 00057 00062 TEMPLATE inline void 00063 THIS::labelHGeometryRecursively(HGeometry<0,DOW>& g, int lab) 00064 { 00065 labelHGeometry(g, lab); 00066 } 00067 00073 TEMPLATE void 00074 THIS::reclaimIrregularMesh(typename THIS::ir_mesh_t& m) 00075 { 00076 ActiveElementIterator<DIM, DOW> 00077 the_ele = m.beginActiveElement(), 00078 end_ele = m.endActiveElement(); 00079 for (;the_ele != end_ele;++ the_ele) { 00080 if (the_ele->isRefined()) { 00081 for (int i = 0;i < the_ele->n_child;++ i) { 00082 m.deleteTree(the_ele->child[i]); 00083 the_ele->child[i] = NULL; 00084 } 00085 } 00086 } 00087 } 00088 00093 TEMPLATE 00094 void THIS::initialTreeLabel() 00095 { 00096 typename HGeometryTree<DIM,DOW>::RootIterator 00097 the_ele = h_tree->beginRootElement(), 00098 end_ele = h_tree->endRootElement(); 00099 for (;the_ele != end_ele;++ the_ele) { 00100 labelHGeometryRecursively(*the_ele, -1); 00101 } 00102 } 00103 00108 TEMPLATE 00109 void THIS::labelIrregularMesh(typename THIS::ir_mesh_t& m) 00110 { 00111 RootFirstElementIterator<DIM, DOW> 00112 the_ele = m.beginRootFirstElement(), 00113 end_ele = m.endRootFirstElement(); 00114 for (;the_ele != end_ele;++ the_ele) { 00115 labelHGeometry(*(the_ele->h_element), 1); 00116 } 00117 } 00118 00126 TEMPLATE 00127 template <int DIM1> inline int 00128 THIS::relabelHGeometryRecursively(HGeometry<DIM1,DOW>& g) 00129 { 00130 for (int i = 0;i < g.n_vertex;++ i) { 00131 if (g.vertex[i] == NULL) continue; 00132 if (relabelHGeometryRecursively(*(g.vertex[i])) == -2) { 00133 g.vertex[i] = NULL; 00134 } 00135 } 00136 for (int i = 0;i < g.n_boundary;++ i) { 00137 if (g.boundary[i] == NULL) continue; 00138 if (relabelHGeometryRecursively(*(g.boundary[i])) == -2) { 00139 g.boundary[i] = NULL; 00140 } 00141 } 00142 if (g.isRefined()) { 00143 for (int i = 0;i < g.n_child;++ i) { 00144 if (g.child[i] == NULL) continue; 00145 if (relabelHGeometryRecursively(*(g.child[i])) == -2) { 00146 g.child[i] = NULL; 00147 } 00148 } 00149 } 00150 if (g.index == -1) { 00151 g.index = -2; 00152 return -1; 00153 } 00154 else return g.index; 00155 } 00156 00157 00162 TEMPLATE inline int 00163 THIS::relabelHGeometryRecursively(HGeometry<0,DOW>& g) 00164 { 00165 if (g.index == -1) { 00166 g.index = -2; 00167 return -1; 00168 } 00169 else return g.index; 00170 } 00171 00176 TEMPLATE 00177 template <int DIM1> inline int 00178 THIS::reclaimHGeometryRecursively(HGeometry<DIM1,DOW>& g) 00179 { 00180 for (int i = 0;i < g.n_vertex;++ i) { 00181 if (g.vertex[i] != NULL) { 00182 if (reclaimHGeometryRecursively(*(g.vertex[i])) == -1) { 00183 g.vertex[i] = NULL; 00184 } 00185 } 00186 } 00187 for (int i = 0;i < g.n_boundary;++ i) { 00188 if (g.boundary[i] != NULL) { 00189 if (reclaimHGeometryRecursively(*(g.boundary[i])) == -1) { 00190 g.boundary[i] = NULL; 00191 } 00192 } 00193 } 00194 for (int i = 0;i < g.n_child;++ i) { 00195 if (g.child[i] == NULL) continue; 00196 if (reclaimHGeometryRecursively(*(g.child[i])) == -1) { 00197 g.child[i] = NULL; 00198 } 00199 } 00200 Assert ((g.index == 1 || g.index == -2), ExcInternalError()); 00201 if (g.index == -2) { 00202 this->reclaimHGeometry(&g, DIM1); 00203 return -1; 00204 } 00205 else { 00206 return 1; 00207 } 00208 } 00209 00210 00215 TEMPLATE inline int 00216 THIS::reclaimHGeometryRecursively(HGeometry<0,DOW>& g) 00217 { 00218 Assert ((g.index == 1 || g.index == -2), ExcInternalError()); 00219 if (g.index == -2) { 00220 this->reclaimHGeometry(&g, 0); 00221 return -1; 00222 } 00223 else { 00224 return 1; 00225 } 00226 } 00227 00228 00233 TEMPLATE 00234 void THIS::reclaimTreeMemory() 00235 { 00236 typename HGeometryTree<DIM,DOW>::RootIterator 00237 the_ele = h_tree->beginRootElement(), 00238 end_ele = h_tree->endRootElement(); 00239 for (;the_ele != end_ele;++ the_ele) { 00240 relabelHGeometryRecursively(*the_ele); 00241 } 00242 00243 the_ele = h_tree->beginRootElement(); 00244 for (;the_ele != end_ele;++ the_ele) { 00245 reclaimHGeometryRecursively(*the_ele); 00246 } 00247 } 00248 00249 TEMPLATE 00250 void THIS::reclaim() 00251 { 00253 typename std::list<typename THIS::ir_mesh_t *>::iterator 00254 the_ir_mesh = ir_mesh.begin(), 00255 end_ir_mesh = ir_mesh.end(); 00256 for (;the_ir_mesh != end_ir_mesh;++ the_ir_mesh) { 00257 reclaimIrregularMesh(**the_ir_mesh); 00258 } 00259 00261 initialTreeLabel(); 00262 00264 the_ir_mesh = ir_mesh.begin(); 00265 for (;the_ir_mesh != end_ir_mesh;++ the_ir_mesh) { 00266 labelIrregularMesh(**the_ir_mesh); 00267 } 00268 00270 reclaimTreeMemory(); 00271 } 00272 00273 #undef THIS 00274 #undef TEMPLATE 00275
1.7.4