Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

src/expde/extemp/locsum.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 // locsum.cc
00019 //
00020 // ------------------------------------------------------------
00021 
00022 // Include level 0:
00023 #ifdef COMP_GNUOLD
00024  #include <iostream.h>
00025  #include <fstream.h>
00026  #include <time.h>
00027 #else
00028  #include <iostream>
00029  #include <fstream>
00030  #include <ctime>
00031 #endif 
00032 
00033 
00034 // Include level 0:
00035 #include "../parser.h"
00036 
00037 // Include level 1:
00038 #include "../paramete.h"
00039 #include "../abbrevi.h"
00040 #include "../math_lib/math_lib.h"
00041 
00042 // Include level 2:
00043 #include "../basic/basic.h"
00044 
00045 // Include level 3:
00046 #include "../domain/domain.h"
00047 
00048 // Include level 4:
00049 #include "../formulas/boundy.h"
00050 #include "../formulas/loc_sten.h"
00051 
00052 // Include level 5:
00053 #include "../grid/gpar.h"
00054 #include "../grid/parallel.h"
00055 #include "../grid/mgcoeff.h"
00056 #include "../grid/sto_man.h"
00057 #include "../grid/gridbase.h"
00058 #include "../grid/grid.h"
00059 #include "../grid/input.h"
00060 
00061 // Include level 5.1
00062 #include "../evpar/evpar.h"
00063 
00064 // Include level 6:
00065 #include "variable.h"
00066 #include "locsum.h"
00067 
00068 
00069 #define sum_up_27_test(ppoi) ppoi->varM(grid,level)[num_sum_var];
00070 
00071 #define sum_up_27(ppoi) ppoi->varM(grid,level)[num_sum_var] + \
00072                         ppoi->varEND(grid,level)[num_sum_var] + \
00073                         ppoi->varWND(grid,level)[num_sum_var] + \
00074                         ppoi->varESD(grid,level)[num_sum_var] + \
00075                         ppoi->varWSD(grid,level)[num_sum_var] + \
00076                         ppoi->varENT(grid,level)[num_sum_var] + \
00077                         ppoi->varWNT(grid,level)[num_sum_var] + \
00078                         ppoi->varEST(grid,level)[num_sum_var] + \
00079                         ppoi->varWST(grid,level)[num_sum_var] + \
00080                         ppoi->varND(grid,level)[num_sum_var] + \
00081                         ppoi->varSD(grid,level)[num_sum_var] + \
00082                         ppoi->varNT(grid,level)[num_sum_var] + \
00083                         ppoi->varST(grid,level)[num_sum_var] + \
00084                         ppoi->varED(grid,level)[num_sum_var] + \
00085                         ppoi->varWD(grid,level)[num_sum_var] + \
00086                         ppoi->varET(grid,level)[num_sum_var] + \
00087                         ppoi->varWT(grid,level)[num_sum_var] + \
00088                         ppoi->varEN(grid,level)[num_sum_var] + \
00089                         ppoi->varWN(grid,level)[num_sum_var] + \
00090                         ppoi->varES(grid,level)[num_sum_var] + \
00091                         ppoi->varWS(grid,level)[num_sum_var] + \
00092                         ppoi->varN(grid,level)[num_sum_var] + \
00093                         ppoi->varS(grid,level)[num_sum_var] + \
00094                         ppoi->varE(grid,level)[num_sum_var] + \
00095                         ppoi->varW(grid,level)[num_sum_var] + \
00096                         ppoi->varT(grid,level)[num_sum_var] + \
00097                         ppoi->varD(grid,level)[num_sum_var];
00098 
00099 #define set_next_27(ppoi) ppoi->varEND(grid,level)[number_variable] = sum; \
00100                           ppoi->varWND(grid,level)[number_variable] = sum; \
00101                           ppoi->varESD(grid,level)[number_variable] = sum; \
00102                           ppoi->varWSD(grid,level)[number_variable] = sum; \
00103                           ppoi->varENT(grid,level)[number_variable] = sum; \
00104                           ppoi->varWNT(grid,level)[number_variable] = sum; \
00105                           ppoi->varEST(grid,level)[number_variable] = sum; \
00106                           ppoi->varWST(grid,level)[number_variable] = sum; \
00107                           ppoi->varND(grid,level)[number_variable] = sum; \
00108                           ppoi->varSD(grid,level)[number_variable] = sum; \
00109                           ppoi->varNT(grid,level)[number_variable] = sum; \
00110                           ppoi->varST(grid,level)[number_variable] = sum; \
00111                           ppoi->varED(grid,level)[number_variable] = sum; \
00112                           ppoi->varWD(grid,level)[number_variable] = sum; \
00113                           ppoi->varET(grid,level)[number_variable] = sum; \
00114                           ppoi->varWT(grid,level)[number_variable] = sum; \
00115                           ppoi->varEN(grid,level)[number_variable] = sum; \
00116                           ppoi->varWN(grid,level)[number_variable] = sum; \
00117                           ppoi->varES(grid,level)[number_variable] = sum; \
00118                           ppoi->varWS(grid,level)[number_variable] = sum; \
00119                           ppoi->varN(grid,level)[number_variable] = sum; \
00120                           ppoi->varS(grid,level)[number_variable] = sum; \
00121                           ppoi->varE(grid,level)[number_variable] = sum; \
00122                           ppoi->varW(grid,level)[number_variable] = sum; \
00123                           ppoi->varT(grid,level)[number_variable] = sum; \
00124                           ppoi->varD(grid,level)[number_variable] = sum;
00125 
00126 
00127 // some first functions
00128 LocalSumObj Local_Sum(int i, int j, int k, Variable& v) {
00129   return LocalSumObj(i,j,k, v.Number_variable(),v.Level()); 
00130 }
00131 
00132 
00133 
00134 
00135 void Variable::operator<<= (const LocalSumObj& local_sum_object) {
00136   int I,J,K;
00137   int p,q,r;
00138   dir_sons color;
00139   int level;
00140   int num_sum_var;
00141   double sum;
00142   Index3D ind;
00143 
00144   // 1. Step: get values
00145   I = local_sum_object.i();
00146   J = local_sum_object.j();
00147   K = local_sum_object.k();
00148 
00149   num_sum_var = local_sum_object.Number_variable();
00150   level = local_sum_object.Level();
00151 
00152   // 2. Step: test error in Parameter
00153   if(I<0 || I>3 ||
00154      J<0 || J>3 ||
00155      K<0 || K>3) {
00156     cout << " Parameter Error in Local_Sum! " << endl;
00157   }
00158   else {
00159     // 3. Step calculate color
00160     color = (dir_sons)((I&1) + 2 * (J&1) + 4 * (K&1));
00161     color = reordering_formula(color);
00162 
00163     /*
00164     cout << " jjjjj: " << color 
00165                << " I: " << (I&1)
00166                << " J: " << (J&1)
00167                << " K: " << (K&1) 
00168                << " level: " << level << endl;
00169     */
00170 
00171     if(level=Max_Level()) { // !!! on finest grid
00172       // 4. Step: Sum up
00173       // innere Punkte
00174       for(iter_i=grid->Start_P_interior(level,color);
00175           iter_i!=NULL;iter_i=iter_i->Next()) {
00176         ind = iter_i->Ind();
00177         if(ind.Is_color_four(I,J,K,level)) {
00178           
00179           sum = sum_up_27(iter_i);
00180           for(p=0;p<3;++p) for(q=0;q<3;++q) for(r=0;r<3;++r) {
00181             sum = sum + grid->sum_rest_at_point(ind.next((Ort1D)p,
00182                                                          (Ort1D)q,
00183                                                          (Ort1D)r,level),
00184                                                 num_sum_var);
00185           }
00186           sum = sum + grid->sum_of_cellp(ind,num_sum_var);
00187 
00188           iter_i->varM(grid,level)[number_variable] = sum;      
00189           
00190         }
00191       }
00192       
00193       // randnahe Punkte
00194       for(iter_n=grid->Start_P_nearb(level,color);
00195           iter_n!=NULL;iter_n=iter_n->Next()) {
00196         ind = iter_n->Ind();
00197         if(ind.Is_color_four(I,J,K,level)) {
00198           sum = 0.0;
00199           for(p=0;p<3;++p) for(q=0;q<3;++q) for(r=0;r<3;++r) {
00200             sum = sum + grid->sum_at_point(ind.next((Ort1D)p,
00201                                                     (Ort1D)q,
00202                                                     (Ort1D)r,level),
00203                                            num_sum_var,level);
00204           }
00205           sum = sum + grid->sum_of_cellp(ind,num_sum_var);
00206           //    sum = sum_up_27_test(iter_n);
00207           
00208           iter_n->varM(grid,level)[number_variable] = sum;
00209         }
00210       }
00211       // 5. Step: Set next points
00212       // innere Punkte
00213       for(iter_i=grid->Start_P_interior(level,color);
00214           iter_i!=NULL;iter_i=iter_i->Next()) {
00215         ind = iter_i->Ind();
00216         if(ind.Is_color_four(I,J,K,level)) {
00217           sum = iter_i->varM(grid,level)[number_variable];      
00218           set_next_27(iter_i);
00219           for(p=0;p<3;++p) for(q=0;q<3;++q) for(r=0;r<3;++r) {
00220             grid->set_rest_at_point(ind.next((Ort1D)p,
00221                                              (Ort1D)q,
00222                                              (Ort1D)r,level),
00223                                     number_variable,sum);
00224             grid->set_at_cellp(ind,number_variable,sum);
00225           }
00226         }
00227       }
00228       
00229       // randnahe Punkte
00230       for(iter_n=grid->Start_P_nearb(level,color);
00231           iter_n!=NULL;iter_n=iter_n->Next()) {
00232         ind = iter_n->Ind();
00233         if(ind.Is_color_four(I,J,K,level)) {
00234           sum = iter_n->varM(grid,level)[number_variable];      
00235           for(p=0;p<3;++p) for(q=0;q<3;++q) for(r=0;r<3;++r) {
00236             grid->set_at_point(ind.next((Ort1D)p,
00237                                         (Ort1D)q,
00238                                         (Ort1D)r,level),
00239                                number_variable,sum,level);
00240             grid->set_at_cellp(ind,number_variable,sum);
00241           }
00242         }
00243       }
00244     }
00245     else { // !!! on coarser grids
00246       // 4. Step: Sum up
00247       // innere Punkte
00248       for(iter_i=grid->Start_P_interior(level,color);
00249           iter_i!=NULL;iter_i=iter_i->Next()) {
00250         ind = iter_i->Ind();
00251         if(ind.Is_color_four(I,J,K,level)) {      
00252           sum = sum_up_27(iter_i);
00253           iter_i->varM(grid,level)[number_variable] = sum;                
00254         }
00255       }
00256       
00257       // randnahe Punkte
00258       for(iter_n=grid->Start_P_nearb(level,color);
00259           iter_n!=NULL;iter_n=iter_n->Next()) {
00260         ind = iter_n->Ind();
00261         if(ind.Is_color_four(I,J,K,level)) {
00262           sum = 0.0;
00263           for(p=0;p<3;++p) for(q=0;q<3;++q) for(r=0;r<3;++r) {
00264             sum = sum + grid->sum_at_point(ind.next((Ort1D)p,
00265                                                     (Ort1D)q,
00266                                                     (Ort1D)r,level),
00267                                            num_sum_var,level);
00268           }
00269           iter_n->varM(grid,level)[number_variable] = sum;
00270         }
00271       }
00272 
00273       // exterior grobe Randpunkte
00274       for(iter_n=grid->Start_P_exteri(level,color);
00275           iter_n!=NULL;iter_n=iter_n->Next()) {
00276         ind = iter_n->Ind();
00277         if(ind.Is_color_four(I,J,K,level)) {
00278           sum = 0.0;
00279           for(p=0;p<3;++p) for(q=0;q<3;++q) for(r=0;r<3;++r) {
00280             sum = sum + grid->sum_at_point(ind.next((Ort1D)p,
00281                                                     (Ort1D)q,
00282                                                     (Ort1D)r,level),
00283                                            num_sum_var,level);
00284           }
00285           iter_n->varM(grid,level)[number_variable] = sum;
00286         }
00287       }
00288       // 5. Step: Sum up
00289       // innere Punkte
00290       for(iter_i=grid->Start_P_interior(level,color);
00291           iter_i!=NULL;iter_i=iter_i->Next()) {
00292         ind = iter_i->Ind();
00293         if(ind.Is_color_four(I,J,K,level)) {
00294           sum = iter_i->varM(grid,level)[number_variable];
00295           set_next_27(iter_i);     
00296         }
00297       }
00298       
00299       // randnahe Punkte
00300       for(iter_n=grid->Start_P_nearb(level,color);
00301           iter_n!=NULL;iter_n=iter_n->Next()) {
00302         ind = iter_n->Ind();
00303         if(ind.Is_color_four(I,J,K,level)) {
00304           sum = iter_n->varM(grid,level)[number_variable];
00305           for(p=0;p<3;++p) for(q=0;q<3;++q) for(r=0;r<3;++r) {
00306             grid->set_at_point(ind.next((Ort1D)p,
00307                                         (Ort1D)q,
00308                                         (Ort1D)r,level),
00309                                number_variable,sum,level);
00310           }                                                                
00311         }
00312       }
00313 
00314       // exterior grobe Randpunkte
00315       for(iter_n=grid->Start_P_exteri(level,color);
00316           iter_n!=NULL;iter_n=iter_n->Next()) {
00317         ind = iter_n->Ind();
00318         if(ind.Is_color_four(I,J,K,level)) {
00319           sum = iter_n->varM(grid,level)[number_variable];
00320           for(p=0;p<3;++p) for(q=0;q<3;++q) for(r=0;r<3;++r) {
00321             grid->set_at_point(ind.next((Ort1D)p,
00322                                         (Ort1D)q,
00323                                         (Ort1D)r,level),
00324                                number_variable,sum,level);
00325           }
00326         }
00327       }
00328     }
00329 
00330     
00331   }
00332 }
00333 
00334 
00335 // member functions 
00336 
00337 LocalSumObj::LocalSumObj(int i, int j, int k, int num_var, int lev) {
00338   I=i;
00339   J=j;
00340   K=k;
00341 
00342   number_var = num_var;
00343   level = lev;
00344 }
00345 
00346 
00347 double Grid_base::sum_rest_at_point(Index3D ind, int num_sum_variable) {
00348   double sum;
00349   sum = 0.0;
00350   if(Give_type(ind)>interior) {
00351     for(int d=0;d<6;d++) {
00352       if(Exists_Bo_Point(ind,(dir_3D)d)) {
00353         sum = sum + Give_variable(ind,(dir_3D)d)[num_sum_variable];
00354       }
00355     }
00356   }
00357   return sum;
00358 }
00359 
00360 double Grid_base::sum_at_point(Index3D ind, int num_sum_variable, int level) {
00361   double sum;
00362 
00363   if(Give_type(ind)>=interior) {
00364     sum = Give_variable(ind,level)[num_sum_variable];
00365     if(level == max_level) {
00366       for(int d=0;d<6;d++) {
00367         if(Exists_Bo_Point(ind,(dir_3D)d)) {
00368           sum = sum + Give_variable(ind,(dir_3D)d)[num_sum_variable];
00369         }
00370       }
00371     }
00372   }
00373   else {
00374     sum = 0.0;
00375   }
00376   return sum;
00377 }
00378 
00379 double Grid_base::sum_of_cellp(Index3D ind, int num_sum_variable) {
00380   double sum;
00381   Index3D In;
00382   Index3D I;
00383   double* vars;
00384 
00385   sum = 0.0;
00386   for(int i=0;i<8;++i) { // go to next corners
00387     In = ind.next((dir_sons)i,max_level);
00388     for(int j=0;j<8;++j) { // go to next cells
00389      I = In.next((dir_sons)j,max_level+1);
00390      vars = Give_variable_cellpoi_slow(I);
00391      if(vars!=NULL) {
00392        sum = sum + vars[num_sum_variable];
00393      }
00394     }
00395   }
00396   return sum;
00397 }
00398 
00399 
00400 void Grid_base::set_rest_at_point(Index3D ind, int num_variable, 
00401                                   double sum) {
00402   if(Give_type(ind)>interior) {
00403     for(int d=0;d<6;d++) {
00404       if(Exists_Bo_Point(ind,(dir_3D)d)) {
00405         Give_variable(ind,(dir_3D)d)[num_variable] = sum;
00406       }
00407     }
00408   }
00409 }
00410 
00411 void Grid_base::set_at_point(Index3D ind, int num_variable,
00412                              double sum, int level) {
00413   if(Give_type(ind)>=interior) {
00414     Give_variable(ind,level)[num_variable] = sum;
00415     if(level == max_level) {
00416       for(int d=0;d<6;d++) {
00417         if(Exists_Bo_Point(ind,(dir_3D)d)) {
00418           Give_variable(ind,(dir_3D)d)[num_variable] = sum;
00419         }
00420       }
00421     }
00422   }
00423 }
00424 
00425 void Grid_base::set_at_cellp(Index3D ind, int number_variable, double sum) {
00426   Index3D In;
00427   Index3D I;
00428   double* vars;
00429 
00430   for(int i=0;i<8;++i) { // go to next corners
00431     In = ind.next((dir_sons)i,max_level);
00432     for(int j=0;j<8;++j) { // go to next cells
00433      I = In.next((dir_sons)j,max_level+1);
00434      vars = Give_variable_cellpoi_slow(I);
00435      if(vars!=NULL) {
00436        vars[number_variable] = sum;
00437      }
00438     }
00439   }
00440 }
00441 

Generated on Fri Nov 2 01:25:56 2007 for IPPL by doxygen 1.3.5