src/expde/grid/input.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 // input.cc
00020 //
00021 // ------------------------------------------------------------
00022 
00023 
00024 
00025 // Include level 0:
00026 #ifdef COMP_GNUOLD
00027  #include <iostream.h>
00028  #include <fstream.h>
00029  #include <math.h>
00030  #include <time.h>
00031 #else
00032  #include <iostream>
00033  #include <fstream>
00034  #include <cmath>
00035  #include <ctime>
00036 #endif 
00037 
00038 
00039 // Include level 0:
00040 #include "../parser.h"
00041 
00042 // Include level 1:
00043 #include "../paramete.h"
00044 #include "../abbrevi.h"
00045 #include "../math_lib/math_lib.h"
00046 
00047 // Include level 2:
00048 #include "../basic/basic.h"
00049 
00050 // Include level 3:
00051 #include "../domain/domain.h"
00052 
00053 // Include level 4:
00054 #include "../formulas/boundy.h"
00055 #include "../formulas/loc_sten.h"
00056 
00057 // Include level 5:
00058 
00059 #include "gpar.h"
00060 #include "parallel.h"
00061 #include "mgcoeff.h"
00062 #include "sto_man.h"
00063 #include "gridbase.h"
00064 #include "grid.h"
00065 #include "input.h"
00066 
00067 
00068 
00069 Input_data_object::Input_data_object (D3vector* coordinates,
00070                                       double* value,
00071                                       int num_points,
00072                                       double mesh_x,
00073                                       double mesh_y,
00074                                       double mesh_z) {
00075   int i;
00076   
00077   // 1. set 
00078   ort   = coordinates;
00079   werte = value;
00080   anz_punkte = num_points;
00081   h_x = mesh_x;
00082   h_y = mesh_y;
00083   h_z = mesh_z;
00084 
00085   epsx = h_x * factor_eps_input;
00086   epsy = h_y * factor_eps_input;
00087   epsz = h_z * factor_eps_input;
00088 
00089   // 2. hashtable
00090   hashtable_input_leng  = Find_next_prime(2*num_points);
00091   hashtable_input_start = 
00092     new Point_hashtable_input*[hashtable_input_leng];
00093   for(i=0;i<hashtable_input_leng;++i)
00094     hashtable_input_start[i] = NULL;
00095   hashtable_input_occ=0;
00096 
00097   // 3. find minimum
00098   org_x = coordinates[0].x;
00099   org_y = coordinates[0].y;
00100   org_z = coordinates[0].z;
00101   for(i=0;i<num_points;++i) {
00102     org_x = MIN(coordinates[0].x,org_x);
00103     org_y = MIN(coordinates[0].y,org_y);
00104     org_z = MIN(coordinates[0].z,org_z);
00105   }
00106 
00107   // 4. add points
00108   for(i=0;i<num_points;++i)
00109     Add_point(coordinates[i].x,coordinates[i].y,coordinates[i].z,value[i]);
00110 
00111 }
00112 
00113 void Input_data_object::Add_point(double x, double y, double z,
00114                                   double value) {
00115   Point_hashtable_input* point;
00116   int Nx, Ny, Nz;
00117 
00118   Nx = (int)((x+h_x/4.0-org_x)/h_x);
00119   Ny = (int)((y+h_y/4.0-org_y)/h_y);
00120   Nz = (int)((z+h_z/4.0-org_z)/h_z);
00121   
00122 
00123   point = hashtable_input_start
00124     [hashtable_input_function(Nx,Ny,Nz,hashtable_input_leng)];
00125   if(point==NULL) {
00126     hashtable_input_occ++;
00127     point = new Point_hashtable_input(Nx,Ny,Nz,value);
00128     hashtable_input_start[hashtable_input_function(Nx,Ny,Nz,
00129                                                    hashtable_input_leng)] = 
00130       point;
00131   }
00132   else {
00133     while(point->next!=NULL && 
00134           (point->nx!=Nx || point->ny!=Ny || point->nz!=Nz))
00135       point = point->next;
00136     if(point->nx!=Nx || point->ny!=Ny || point->nz!=Nz) {
00137       hashtable_input_occ++;
00138       point->next = new Point_hashtable_input(Nx,Ny,Nz,value);
00139     }
00140   }
00141 }
00142 
00143 
00144 double Input_data_object::Give_value(D3vector coordinates) {
00145   int Nx, Ny, Nz;
00146   Point_hashtable_input* point;
00147 
00148   Nx = (int)((coordinates.x+epsx-org_x)/h_x);
00149   Ny = (int)((coordinates.y+epsy-org_y)/h_y);
00150   Nz = (int)((coordinates.z+epsz-org_z)/h_z);
00151   
00152   point = 
00153     hashtable_input_start[hashtable_input_function(Nx,Ny,Nz,
00154                                      hashtable_input_leng)];
00155   while(point!=NULL) {
00156     if(point->Is_point(Nx,Ny,Nz)) return point->wert;
00157     point = point->next;
00158   }
00159   return 0.0;
00160 }
00161 
00162 bool Input_data_object::Exists_point(D3vector coordinates) {
00163   int Nx, Ny, Nz;
00164   Point_hashtable_input* point;
00165 
00166   Nx = (int)((coordinates.x+epsx-org_x)/h_x);
00167   Ny = (int)((coordinates.y+epsy-org_y)/h_y);
00168   Nz = (int)((coordinates.z+epsz-org_z)/h_z);
00169   
00170   point = 
00171     hashtable_input_start[hashtable_input_function(Nx,Ny,Nz,
00172                                      hashtable_input_leng)];
00173   while(point!=NULL) {
00174     if(point->Is_point(Nx,Ny,Nz)) return true;
00175     point = point->next;
00176   }
00177   return false;
00178 }
00179 
00180 D3vector Input_data_object::Staggered_coordinate(D3vector coordinates) {
00181   return D3vector(((int)((coordinates.x+epsx-org_x)/h_x))*h_x+org_x,
00182                   ((int)((coordinates.y+epsy-org_y)/h_y))*h_y+org_y,
00183                   ((int)((coordinates.z+epsz-org_z)/h_z))*h_z+org_z);
00184 }
00185 
00186 
00187 double Input_data_object::Interpolate_value(D3vector coordinates) {
00188   D3vector lambda;
00189   int i,j,k,l;
00190   double sum;
00191   int anz;
00192 
00193   if(Exists_point(coordinates) &&
00194      Exists_point(coordinates+D3vector(h_x,0.0,0.0)) &&
00195      Exists_point(coordinates+D3vector(0.0,h_y,0.0)) &&
00196      Exists_point(coordinates+D3vector(0.0,0.0,h_z)) &&
00197      Exists_point(coordinates+D3vector(0.0,h_y,h_z)) &&
00198      Exists_point(coordinates+D3vector(h_x,0.0,h_z)) &&
00199      Exists_point(coordinates+D3vector(h_x,h_y,0.0)) &&
00200      Exists_point(coordinates+D3vector(h_x,h_y,h_z))) {
00201     lambda = (coordinates - Staggered_coordinate(coordinates))/
00202       D3vector(h_x,h_y,h_z);
00203     
00204     sum = 0.0;
00205     for(i=0;i<2;++i) for(j=0;j<2;++j) for(k=0;k<2;++k) {
00206       sum = sum +
00207         Give_value(coordinates+D3vector(i*h_x,j*h_y,k*h_z))
00208         * ((1.0*(1-i) - lambda.x * (1-2*i)))
00209         * ((1.0*(1-j) - lambda.y * (1-2*j)))
00210         * ((1.0*(1-k) - lambda.z * (1-2*k)));
00211     }
00212     return sum;
00213   }
00214   else {
00215     for(l=1;l<search_length;++l) {
00216       anz = 0;
00217       sum = 0.0;
00218       for(i=0;i<2;++i) for(j=0;j<2;++j) for(k=0;k<2;++k) {
00219         if(Exists_point(coordinates+D3vector(h_x*((1-l)+i*(2*l-1)),
00220                                              h_y*((1-l)+j*(2*l-1)),
00221                                              h_z*((1-l)+k*(2*l-1))))) {
00222           sum = sum +
00223             Give_value(coordinates+D3vector(h_x*((1-l)+i*(2*l-1)),
00224                                             h_y*((1-l)+j*(2*l-1)),
00225                                             h_z*((1-l)+k*(2*l-1))));
00226           anz =  anz + 1;
00227         }
00228       }
00229       if(anz>0) return sum / (double)anz;
00230     }
00231   }
00232   return 0.0;
00233 }
00234 
00235      

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