src/expde/grid/hash.cc

Go to the documentation of this file.
00001 //    expde: expression templates for partial differential equations.
00002 //    Copyright (C) 2001  Christoph Pflaum
00003 //    This program is free software; you can redistribute it and/or modify
00004 //    it under the terms of the GNU General Public License as published by
00005 //    the Free Software Foundation; either version 2 of the License, or
00006 //    (at your option) any later version.
00007 //
00008 //    This program is distributed in the hope that it will be useful,
00009 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //    GNU General Public License for more details.
00012 //
00013 //                 SEE  Notice1.doc made by 
00014 //                 LAWRENCE LIVERMORE NATIONAL LABORATORY
00015 //
00016 
00017 // ------------------------------------------------------------
00018 //
00019 // hash.cc
00020 //
00021 // ------------------------------------------------------------
00022 
00023 
00024 // Include level 0:
00025 #ifdef COMP_GNUOLD
00026  #include <iostream.h>
00027  #include <fstream.h>
00028  #include <time.h>
00029  #include <math.h>
00030 #else
00031  #include <iostream>
00032  #include <fstream>
00033  #include <ctime>
00034  #include <cmath>
00035 #endif 
00036 
00037 
00038 // Include level 0:
00039 #include "../parser.h"
00040 
00041 // Include level 1:
00042 #include "../paramete.h"
00043 #include "../abbrevi.h"
00044 #include "../math_lib/math_lib.h"
00045 
00046 // Include level 2:
00047 #include "../basic/basic.h"
00048 
00049 // Include level 3:
00050 #include "../domain/domain.h"
00051 
00052 // Include level 4:
00053 #include "../formulas/boundy.h"
00054 #include "../formulas/loc_sten.h"
00055 
00056 // Include level 5:
00057 #include "gpar.h"
00058 #include "parallel.h"
00059 #include "mgcoeff.h"
00060 #include "sto_man.h"
00061 #include "gridbase.h"
00062 #include "grid.h"
00063 
00064 
00065 
00066 // Elementares fuer hashtable0
00067 // ----------------------------
00068 void Grid_base::Initialize_hash0(int lenght) {
00069   int i;
00070   hashtable0_leng = Find_next_prime(lenght);
00071   hashtable0_start = new Point_hashtable0*[hashtable0_leng];
00072   for(i=0;i<hashtable0_leng;++i)
00073     hashtable0_start[i] = NULL;
00074   hashtable0_occ=0;
00075 }
00076 
00077 void Grid_base::Info_hashtable0() {
00078   int max_depth;
00079   double ave_depth;
00080   Depth_hashtable0(&max_depth,&ave_depth);
00081   cout << "  Hashtable0: "  << endl;
00082   cout << "     Maximal depth: "  << max_depth << endl;
00083   cout << "     Average depth: "  << ave_depth << endl;
00084   cout << "     Enties: " << hashtable0_occ  << endl;
00085   cout << "     Length: " << hashtable0_leng  << endl;
00086 }
00087 
00088 
00089 void Grid_base::Depth_hashtable0(int* max_depth, 
00090                                 double* ave_depth) {
00091   static int i, s, anz;
00092   static Point_hashtable0* point;
00093   *max_depth=0;
00094   *ave_depth=0;
00095   anz=0;
00096   for(i=0;i<hashtable0_leng;++i) {
00097     s=0;
00098     for(point=hashtable0_start[i];point!=NULL;point=point->next) ++s;
00099     if(*max_depth<s) *max_depth=s;
00100     if(s!=0) anz++;
00101     *ave_depth = *ave_depth + s;
00102   }
00103   *ave_depth = *ave_depth / anz;
00104 }
00105 
00106 void Grid_base::Resize_hash0(int lenght) {
00107   int i, hashtable0_leng_new, hashtable0_leng_old;
00108   Index3D I;
00109   lenght = Find_next_prime(lenght);
00110   Point_hashtable0* point;
00111   Point_hashtable0** hashtable0_start_new;
00112   Point_hashtable0** hashtable0_start_old;
00113   // Neuer hashtable:
00114   hashtable0_leng_new = lenght;
00115   hashtable0_start_new = new Point_hashtable0*[hashtable0_leng_new];
00116   for(i=0;i<hashtable0_leng_new;++i)
00117     hashtable0_start_new[i] = NULL;
00118   // Uebertrag:
00119   iterate_hash0 {
00120     I = point0->ind;
00121     point = hashtable0_start_new
00122       [hashtable0_function(I.ind_x.index,I.ind_y.index,I.ind_z.index,
00123                            hashtable0_leng_new)];
00124     if(point==NULL) {
00125       hashtable0_start_new
00126         [hashtable0_function(I.ind_x.index,I.ind_y.index,I.ind_z.index,
00127                              hashtable0_leng_new)] = 
00128         new Point_hashtable0(point0);
00129     }
00130     else {
00131       //      while(point->next!=NULL && point->ind!=I) point = point->next;
00132       while(point->next!=NULL) point = point->next;
00133         point->next =   new Point_hashtable0(point0);
00134       }
00135     }
00136   //Tausch
00137   hashtable0_leng_old  = hashtable0_leng;
00138   hashtable0_start_old = hashtable0_start;
00139   hashtable0_leng  = hashtable0_leng_new;
00140   hashtable0_start = hashtable0_start_new;
00141 
00142   //Loeschen des alten hashtables:
00143   for(i_iter=0;i_iter<hashtable0_leng_old;++i_iter) {
00144     point0=hashtable0_start_old[i_iter];
00145     delete point0;
00146   }
00147   delete hashtable0_start_old;
00148 }
00149 
00150 
00151 void Grid_base::Print_hashtable0() {
00152   static int num;
00153   cout << "Print hashtable 0:" << endl;
00154   cout << "Besetzung:" << hashtable0_occ << endl;
00155   num=0;
00156   iterate_hash0 {
00157     num++;
00158     cout << num << " "; point0->ind.coordinate().Print(); cout << endl;
00159   }
00160 }
00161 
00162 
00163 
00164 void Grid_base::Remove_edges() {
00165   Point_hashtable0* point_old; 
00166   for(i_iter=0;i_iter<hashtable0_leng;++i_iter) {
00167     point0=hashtable0_start[i_iter];
00168     if(point0!=NULL) {
00169       // Anfangspunkt ist Kante
00170       if(point0->ind.Edge_index()) {
00171         hashtable0_start[i_iter] = point0->next;
00172         point0->next = NULL;
00173         delete(point0);
00174         --hashtable0_occ;
00175         point0=hashtable0_start[i_iter];
00176       }
00177       point_old = point0;
00178       if(point_old!=NULL) {
00179         for(point0=point0->next;point0!=NULL;) {
00180           // Listenpunkt ist Kante
00181           if(point0->ind.Edge_index()) {
00182             point_old->next = point0->next;
00183             point0->next = NULL;
00184             delete(point0);
00185             --hashtable0_occ;
00186             point0=point_old->next;
00187           }
00188           // In Liste weitergehen
00189           else {
00190             point_old=point_old->next;
00191             point0=point0->next;
00192           }
00193         }
00194       }
00195     }
00196   }
00197 }
00198 
00199 // Elementares fuer hashtable1
00200 // ----------------------------
00201 void Grid_base::Initialize_hash1(int lenght) {
00202   int i;
00203   hashtable1_leng = Find_next_prime(lenght);
00204   hashtable1_start = new Point_hashtable1*[hashtable1_leng];
00205   for(i=0;i<hashtable1_leng;++i)
00206     hashtable1_start[i] = NULL;
00207   hashtable1_occ=0;
00208 }
00209 
00210 void Grid_base::Resize_hash1(int lenght) {
00211   int i, hashtable1_leng_new, hashtable1_leng_old;
00212   Index3D I;
00213   lenght = Find_next_prime(lenght);
00214   Point_hashtable1* point;
00215   Point_hashtable1** hashtable1_start_new;
00216   Point_hashtable1** hashtable1_start_old;
00217   // Neuer hashtable:
00218   hashtable1_leng_new = lenght;
00219   hashtable1_start_new = new Point_hashtable1*[hashtable1_leng_new];
00220   for(i=0;i<hashtable1_leng_new;++i)
00221     hashtable1_start_new[i] = NULL;
00222   // Uebertrag:
00223   iterate_hash1 {
00224     I = point1->ind;
00225     point = hashtable1_start_new
00226       [hashtable1_function(I.ind_x.index,I.ind_y.index,I.ind_z.index,
00227                            hashtable1_leng_new)];
00228     if(point==NULL) {
00229       hashtable1_start_new
00230         [hashtable1_function(I.ind_x.index,I.ind_y.index,I.ind_z.index,
00231                              hashtable1_leng_new)] = 
00232         new Point_hashtable1(point1);
00233     }
00234     else {
00235       //      while(point->next!=NULL && point->ind!=I) point = point->next;
00236       while(point->next!=NULL) point = point->next;
00237         point->next =   new Point_hashtable1(point1);
00238       }
00239     }
00240   //Tausch
00241   hashtable1_leng_old  = hashtable1_leng;
00242   hashtable1_start_old = hashtable1_start;
00243   hashtable1_leng  = hashtable1_leng_new;
00244   hashtable1_start = hashtable1_start_new;
00245 
00246   //Loeschen des alten hashtables:
00247   for(i_iter=0;i_iter<hashtable1_leng_old;++i_iter) {
00248     point1=hashtable1_start_old[i_iter];
00249     delete point1;
00250   }
00251   delete hashtable1_start_old;
00252 }
00253 
00254 
00255 void Grid_base::Info_hashtable1() {
00256   int max_depth;
00257   double ave_depth;
00258   Depth_hashtable1(&max_depth,&ave_depth);
00259   cout << "  Hashtable1: "  << endl;
00260   cout << "     Maximal depth: "  << max_depth << endl;
00261   cout << "     Average depth: "  << ave_depth << endl;
00262   cout << "     Enties: " << hashtable1_occ  << endl;
00263   cout << "     Length: " << hashtable1_leng  << endl;
00264 }
00265 
00266 
00267 void Grid_base::Recursion_Print_cell_info(Index3D I) {
00268   int i;
00269   Index3D son;
00270   for(i=0;i<8;++i) {
00271     son = I.son((dir_sons)i);
00272     if(Exists_Point(son))
00273       Recursion_Print_cell_info(I.son((dir_sons)i));
00274     else {
00275       cout << " Punkt: "; son.coordinate().Print();
00276       cout << " Zellinfo: " << (int)Give_cell_typ(I.son((dir_sons)i)) << endl;
00277     }
00278   }
00279 }
00280 
00281 void Grid_base::Print_cell_info() {
00282   static Index3D ind;
00283 
00284   cout << "\n Infortmation ueber Zellen: \n";
00285   ind = Index3D(2,2,2);
00286 
00287   Recursion_Print_cell_info(ind);
00288 }
00289 
00290 
00291 void Grid_base::Print_hashtable1() {
00292   static int num;
00293   cout << "Print hashtable 1:" << endl;
00294   cout << "Besetzung:" << hashtable1_occ << endl;
00295   num=0;
00296   iterate_hash1 {
00297     num++;
00298     cout << num << " "; point1->ind.coordinate().Print(); 
00299     cout << ", Typ: " << (int)point1->typ << ", level: " << point1->level << endl;
00300   }
00301 }
00302 
00303 
00304 void Grid_base::Depth_hashtable1(int* max_depth, 
00305                                 double* ave_depth) {
00306   static int i, s, anz;
00307   static Point_hashtable1* point;
00308   *max_depth=0;
00309   *ave_depth=0;
00310   anz=0;
00311   for(i=0;i<hashtable1_leng;++i) {
00312     s=0;
00313     for(point=hashtable1_start[i];point!=NULL;point=point->next) ++s;
00314     if(*max_depth<s) *max_depth=s;
00315     if(s!=0) anz++;
00316     *ave_depth = *ave_depth + s;
00317   }
00318   *ave_depth = *ave_depth / anz;
00319 }
00320 
00321 
00322 void Grid_base::Remove_exterior_points() {
00323   Point_hashtable1* point_old; 
00324   Pointtype poi_typ;
00325   for(i_iter=0;i_iter<hashtable1_leng;++i_iter) {
00326     point1=hashtable1_start[i_iter];
00327     // a)
00328     if(point1!=NULL) poi_typ = point1->typ;
00329     while(point1!=NULL && poi_typ==exterior) {
00330       // Anfangspunkt ist exterior
00331       hashtable1_start[i_iter] = point1->next;
00332       point1->next = NULL;
00333       delete(point1);
00334       --hashtable1_occ;
00335       point1=hashtable1_start[i_iter];
00336       if(point1!=NULL) poi_typ = point1->typ;
00337     }
00338     // b)
00339     point_old = point1;
00340     if(point_old!=NULL) {
00341       for(point1=point1->next;point1!=NULL;) {
00342         // Listenpunkt ist exterior
00343         if(point1->typ==exterior) {
00344           point_old->next = point1->next;
00345           point1->next = NULL;
00346           delete(point1);
00347           --hashtable1_occ;
00348           point1=point_old->next;
00349         }
00350         // In Liste weitergehen
00351         else {
00352           point_old=point_old->next;
00353           point1=point1->next;
00354         }
00355       }
00356     }
00357   }
00358 }
00359 
00360 // Elementares fuer hashtable2
00361 // ----------------------------
00362 void Grid_base::Initialize_hash2(int lenght) {
00363   int i;
00364   hashtable2_leng = Find_next_prime(lenght);
00365   hashtable2_start = new Point_hashtable2*[hashtable2_leng];
00366   for(i=0;i<hashtable2_leng;++i)
00367     hashtable2_start[i] = NULL;
00368   hashtable2_occ=0;
00369 }
00370 
00371 
00372 void Grid_base::Info_hashtable2() {
00373   int max_depth;
00374   double ave_depth;
00375   Depth_hashtable2(&max_depth,&ave_depth);
00376   cout << "  Hashtable2: "  << endl;
00377   cout << "     Maximal depth: "  << max_depth << endl;
00378   cout << "     Average depth: "  << ave_depth << endl;
00379   cout << "     Enties: " << hashtable2_occ  << endl;
00380   cout << "     Length: " << hashtable2_leng  << endl;
00381 }
00382 
00383 
00384 void Grid_base::Print_hashtable2() {
00385   static int num;
00386   cout << "Print hashtable 2:" << endl;
00387   cout << "Besetzung:" << hashtable2_occ << endl;
00388   num=0;
00389   iterate_hash2 {
00390     num++;
00391     cout << num << " "; bocell->ind.coordinate().Print(); cout << endl;
00392   }
00393 }
00394 
00395 
00396 void Grid_base::Depth_hashtable2(int* max_depth, 
00397                                 double* ave_depth) {
00398   static int i, s, anz;
00399   static Point_hashtable2* point;
00400   *max_depth=0;
00401   *ave_depth=0;
00402   anz=0;
00403   for(i=0;i<hashtable2_leng;++i) {
00404     s=0;
00405     for(point=hashtable2_start[i];point!=NULL;point=point->next) ++s;
00406     if(*max_depth<s) *max_depth=s;
00407     if(s!=0) anz++;
00408     *ave_depth = *ave_depth + s;
00409   }
00410   *ave_depth = *ave_depth / anz;
00411 }
00412 
00413 
00414 // Elementares fuer hashtable3
00415 // ----------------------------
00416 void Grid_base::Initialize_hash3(int lenght) {
00417   int i;
00418   hashtable3_leng = Find_next_prime(lenght);
00419   hashtable3_start = new Point_hashtable3*[hashtable3_leng];
00420   for(i=0;i<hashtable3_leng;++i)
00421     hashtable3_start[i] = NULL;
00422   hashtable3_occ=0;
00423 }
00424 
00425 
00426 
00427 void Grid_base::Info_hashtable3() {
00428   int max_depth;
00429   double ave_depth;
00430   Depth_hashtable3(&max_depth,&ave_depth);
00431   cout << "  Hashtable3: "  << endl;
00432   cout << "     Maximal depth: "  << max_depth << endl;
00433   cout << "     Average depth: "  << ave_depth << endl;
00434   cout << "     Enties: " << hashtable3_occ  << endl;
00435   cout << "     Length: " << hashtable3_leng  << endl;
00436 }
00437 
00438 
00439 void Grid_base::Print_hashtable3() {
00440   static int num;
00441   cout << "Print hashtable 3:" << endl;
00442   cout << "Besetzung:" << hashtable3_occ << endl;
00443   num=0;
00444   iterate_hash3 {
00445     num++;
00446     cout << num << " Coordinate : "; 
00447     (bo2point->transform_coord(Give_A(),H_mesh())).Print();
00448   }
00449 }
00450 
00451 
00452 void Grid_base::Depth_hashtable3(int* max_depth, 
00453                                 double* ave_depth) {
00454   static int i, s, anz;
00455   static Point_hashtable3* point;
00456   *max_depth=0;
00457   *ave_depth=0;
00458   anz=0;
00459   for(i=0;i<hashtable3_leng;++i) {
00460     s=0;
00461     for(point=hashtable3_start[i];point!=NULL;point=point->next) ++s;
00462     if(*max_depth<s) *max_depth=s;
00463     if(s!=0) anz++;
00464     *ave_depth = *ave_depth + s;
00465   }
00466   *ave_depth = *ave_depth / anz;
00467 }
00468 
00469 
00470 
00471 // Elementares fuer hashtable4
00472 // ----------------------------
00473 
00474 void Grid_base::Initialize_hash4(int lenght) {
00475   int i;
00476   hashtable4_leng = Find_next_prime(lenght);
00477   hashtable4_start = new Point_hashtable4*[hashtable4_leng];
00478   for(i=0;i<hashtable4_leng;++i)
00479     hashtable4_start[i] = NULL;
00480   hashtable4_occ=0;
00481 }
00482 
00483 void Grid_base::Info_hashtable4() {
00484   int max_depth;
00485   double ave_depth;
00486   Depth_hashtable4(&max_depth,&ave_depth);
00487   cout << "  Hashtable4: "  << endl;
00488   cout << "     Maximal depth: "  << max_depth << endl;
00489   cout << "     Average depth: "  << ave_depth << endl;
00490   cout << "     Enties: " << hashtable4_occ  << endl;
00491   cout << "     Length: " << hashtable4_leng  << endl;
00492 }
00493 
00494 void Grid_base::Depth_hashtable4(int* max_depth, 
00495                                  double* ave_depth) {
00496   static int i, s, anz;
00497   static Point_hashtable4* point;
00498   *max_depth=0;
00499   *ave_depth=0;
00500   anz=0;
00501   for(i=0;i<hashtable4_leng;++i) {
00502     s=0;
00503     for(point=hashtable4_start[i];point!=NULL;point=point->next) ++s;
00504     if(*max_depth<s) *max_depth=s;
00505     if(s!=0) anz++;
00506     *ave_depth = *ave_depth + s;
00507   }
00508   if(anz==0) anz=1;
00509   *ave_depth = *ave_depth / anz;
00510 }
00511 
00512 
00513 
00514 void Grid_base::Print_hashtable4() {
00515   static int num;
00516   cout << "Print hashtable 4:" << endl;
00517   cout << "Besetzung:" << hashtable4_occ << endl;
00518   num=0;
00519   iterate_hash4 {
00520     num++;
00521     cout << num << " level,I: " << varpoint->level;
00522     varpoint->ind.coordinate().Print(); cout << endl;
00523   }
00524 }
00525 
00526 
00527 // Remove all hashtables
00528 
00529 void Grid_base::Remove_all_hashtables() {
00530 
00531   //Loeschen des hashtable 0:
00532   for(i_iter=0;i_iter<hashtable0_leng;++i_iter) {
00533     point0=hashtable0_start[i_iter];
00534     delete point0;
00535   }
00536   delete hashtable0_start;
00537 
00538   //Loeschen des hashtable 1:
00539   for(i_iter=0;i_iter<hashtable1_leng;++i_iter) {
00540     point1=hashtable1_start[i_iter];
00541     delete point1;
00542   }
00543   delete hashtable1_start;
00544 
00545   //Loeschen des hashtable 2:
00546   for(i_iter=0;i_iter<hashtable2_leng;++i_iter) {
00547     bocell=hashtable2_start[i_iter];
00548     delete bocell;
00549   }
00550   delete hashtable2_start;
00551 
00552   //Loeschen des hashtable 3:
00553   for(i_iter=0;i_iter<hashtable3_leng;++i_iter) {
00554     bo2point=hashtable3_start[i_iter];
00555     delete bo2point;
00556   }
00557   delete hashtable3_start;
00558 
00559   //Loeschen des hashtable 4:
00560   for(i_iter=0;i_iter<hashtable4_leng;++i_iter) {
00561     varpoint=hashtable4_start[i_iter];
00562     delete varpoint;
00563   }
00564   delete hashtable4_start;
00565 }
00566 

Generated on Mon Jan 16 13:23:41 2006 for IPPL by  doxygen 1.4.6