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

src/expde/domain/domain.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 // domain.cc
00020 //
00021 // ------------------------------------------------------------
00022 
00023 
00024 // Include level 0:
00025 
00026 #ifdef COMP_GNUOLD
00027  #include <iostream.h>
00028  #include <fstream.h>
00029  #include <math.h>
00030 #else
00031  #include <iostream>
00032  #include <fstream>
00033  #include <cmath>
00034 #endif 
00035 
00036 // Include level 1:
00037 #include "../paramete.h"
00038 #include "../abbrevi.h"
00039 #include "../math_lib/math_lib.h"
00040 
00041 // Include level 2:
00042 #include "../basic/basic.h"
00043 
00044 // Include level 3:
00045 #include "domain.h"
00046 
00047 #include "d_exam.h"
00048 
00049 
00050 //  SQUARE:      [0,1]^3
00051 // ----------------------------------------------
00052 
00053 PointtypeD All_interior(D3vector V) {
00054   if(V.x < 1.0 && V.x > 0.0 &&
00055      V.y < 1.0 && V.y > 0.0 &&
00056      V.z < 1.0 && V.z > 0.0)
00057     return interiorD;
00058   else return exteriorD; 
00059 };
00060 
00061 
00062 double dis_Square(D3vector V, dir_3D d) {
00063   if(V.x < 1.0 && V.x > 0.0 &&
00064      V.y < 1.0 && V.y > 0.0 &&
00065      V.z < 1.0 && V.z > 0.0) {
00066     if(d==Tdir) return 1.0 - V.z;
00067     if(d==Ddir) return V.z;
00068     
00069     if(d==Edir) return 1.0 - V.x;
00070     if(d==Wdir) return V.x;
00071     
00072     if(d==Ndir) return 1.0 - V.y;
00073     if(d==Sdir) return V.y;
00074   }
00075   return 0.0;
00076 }
00077 
00078 
00079 //  BALL:         Radius: 0.5,  center: (0.5,0.5,0.5)
00080 // ---------------------------------------------------
00081 
00082 #define radius_ball 0.5
00083 
00084 PointtypeD Poi_Ball(D3vector V) { 
00085   V.x = V.x - 0.5;
00086   V.y = V.y - 0.5;
00087   V.z = V.z - 0.5;
00088   
00089     if(sqrt(V.x*V.x+V.y*V.y+V.z*V.z)<=radius_ball) return interiorD;
00090     else return exteriorD;
00091 }
00092 
00093 double dis_Ball(D3vector V, dir_3D d) {
00094   static double x,y,z; 
00095   x = V.x - 0.5;
00096   y = V.y - 0.5;
00097   z = V.z - 0.5;
00098   if(sqrt(x*x+y*y+z*z) < radius_ball) {
00099     if(d==Tdir) return sqrt(radius_ball*radius_ball-x*x-y*y) - z;
00100     if(d==Ddir) return sqrt(radius_ball*radius_ball-x*x-y*y) + z;
00101 
00102     if(d==Edir) return sqrt(radius_ball*radius_ball-y*y-z*z) - x;
00103     if(d==Wdir) return sqrt(radius_ball*radius_ball-y*y-z*z) + x;
00104 
00105     if(d==Ndir) return sqrt(radius_ball*radius_ball-x*x-z*z) - y;
00106     if(d==Sdir) return sqrt(radius_ball*radius_ball-x*x-z*z) + y;
00107   }
00108   return 0.0;
00109 }
00110 
00111 
00112 //  Cylinder:         Radius: 0.5,  center: (0.5,0.5,0.5)
00113 // ---------------------------------------------------
00114 
00115 #define radius_cyl 0.5
00116 
00117 PointtypeD Poi_Cylinder(D3vector V) { 
00118   V.x = V.x - 0.5;
00119   V.y = V.y - 0.5;
00120   
00121   if(sqrt(V.x*V.x+V.y*V.y)<=radius_cyl
00122      && V.z>=0.0 && V.z<=1.0) return interiorD;
00123   else return exteriorD;
00124 }
00125 
00126 double dis_Cylinder(D3vector V, dir_3D d) {
00127   static double x,y; 
00128   x = V.x - 0.5;
00129   y = V.y - 0.5;
00130   if(sqrt(x*x+y*y)<=radius_cyl
00131      && V.z>=0.0 && V.z<=1.0) {
00132     if(d==Tdir) return 1.0 - V.z;
00133     if(d==Ddir) return V.z;
00134     
00135     if(d==Edir) return sqrt(radius_cyl*radius_cyl-y*y) - x;
00136     if(d==Wdir) return sqrt(radius_cyl*radius_cyl-y*y) + x;
00137 
00138     if(d==Ndir) return sqrt(radius_cyl*radius_cyl-x*x) - y;
00139     if(d==Sdir) return sqrt(radius_cyl*radius_cyl-x*x) + y;
00140   }
00141   return 0.0;
00142 }
00143 
00144 
00145 
00146 //  Skew_cylinder:  radius: r_down, r_top,   center: (0.0,0.0,0.5)
00147 // ------------------------------------------------------------
00148 //  R = R_down * V.z + R_top * (1-V.z)
00149 
00150 PointtypeD Poi_Skew_cylinder(D3vector V, double R_down, double R_top) { 
00151   double radius;
00152   radius = R_top * V.z + R_down * (1.0-V.z);
00153   
00154   if(sqrt(V.x*V.x+V.y*V.y)<=radius
00155      && V.z>=0.0 && V.z<=1.0) return interiorD;
00156   else return exteriorD;
00157 }
00158 
00159 double dis_Skew_cylinder(D3vector V, dir_3D d, double R_down, double R_top) {
00160   double radius, r_point;
00161   radius = R_top * V.z + R_down * (1.0-V.z);
00162   r_point = sqrt(V.x*V.x+V.y*V.y);
00163   if(r_point<=radius
00164      && V.z>=0.0 && V.z<=1.0) {
00165     if(d==Ddir) {
00166       if(r_point<R_down) {
00167         return V.z;
00168       }
00169       else {
00170         return (r_point + R_top) / (R_down - R_top);
00171       }
00172     }
00173     if(d==Tdir) {
00174       if(r_point<R_top) {
00175         return 1.0-V.z;
00176       }
00177       else {
00178         return 1.0-(r_point + R_top) / (R_down - R_top);
00179       }
00180     }
00181 
00182     if(d==Edir) return sqrt(radius*radius-V.y*V.y) - V.x;
00183     if(d==Wdir) return sqrt(radius*radius-V.y*V.y) + V.x;
00184 
00185     if(d==Ndir) return sqrt(radius*radius-V.x*V.x) - V.y;
00186     if(d==Sdir) return sqrt(radius*radius-V.x*V.x) + V.y;
00187   }
00188   return 0.0;
00189 }
00190 
00191 //  Double_cylinder:  radius: R_down = r_in, 
00192 //                            R_top  = r_out,   center: (0.0,0.0,0.5)
00193 // ------------------------------------------------------------
00194 //  R = R_down * V.z + R_top * (1-V.z)
00195 
00196 PointtypeD Poi_Double_cylinder(D3vector V, double r_in, double r_out) { 
00197   double radius;
00198   radius = sqrt(V.x*V.x+V.y*V.y);
00199   
00200   if(V.z>=0.0 && V.z<=1.0) {
00201     if(r_in<=radius && radius<=r_out)
00202       return interiorD;
00203   }
00204   return exteriorD;
00205 }
00206 
00207 double dis_Double_cylinder(D3vector V, dir_3D d, double r_in, double r_out) {
00208   double radius;
00209   radius = sqrt(V.x*V.x+V.y*V.y);
00210   if(r_in<=radius && radius<=r_out
00211      && V.z>=0.0 && V.z<=1.0) {
00212     if(d==Ddir) {
00213       return V.z;
00214     }
00215     if(d==Tdir) {
00216       return 1.0-V.z;
00217     }
00218 
00219     if(d==Edir) {
00220       if(V.y < -r_in || V.y > r_in || V.x > 0.0)
00221         return sqrt(r_out*r_out-V.y*V.y) - V.x;
00222       else
00223         return - sqrt(r_in*r_in-V.y*V.y) - V.x;
00224     }
00225     if(d==Wdir) {
00226       if(V.y < -r_in || V.y > r_in || V.x < 0.0)
00227         return sqrt(r_out*r_out-V.y*V.y) + V.x;
00228       else
00229         return - sqrt(r_in*r_in-V.y*V.y) + V.x;
00230     }
00231     if(d==Ndir) {
00232       if(V.x < -r_in || V.x > r_in || V.y > 0.0)
00233         return sqrt(r_out*r_out-V.x*V.x) - V.y;
00234       else
00235         return - sqrt(r_in*r_in-V.x*V.x) - V.y;
00236     }
00237     if(d==Sdir) {
00238       if(V.x < -r_in || V.x > r_in || V.y < 0.0)
00239         return sqrt(r_out*r_out-V.x*V.x) + V.y;
00240       else
00241         return - sqrt(r_in*r_in-V.x*V.x) + V.y;
00242     }
00243   }
00244   return 0.0;
00245 }
00246 
00247 
00248 
00249 //  SCREW SQUARE:  angles:               alpha_up, alpha_down
00250 // -------------------------------------------------------------
00251 
00252 
00253 PointtypeD Poi_Skew_square(D3vector V, double R_down, double R_top) { 
00254   if(0<=V.x     && V.x<=1.0   &&
00255      0<=V.y     && V.y<=1.0   &&
00256      V.z>=my_tan(R_down)*V.x    &&
00257      V.z<=1.0+my_tan(R_top)*V.x) return interiorD;
00258   else return exteriorD;
00259 }
00260 
00261 double dis_Skew_square(D3vector V, dir_3D d, double R_down, double R_top) {
00262   if(0<=V.x     && V.x<=1.0   &&
00263      0<=V.y     && V.y<=1.0   &&
00264      V.z>=my_tan(R_down)*V.x    &&
00265      V.z<=1.0+my_tan(R_top)*V.x) {
00266     if(d==Tdir) return 1.0+my_tan(R_top)*V.x - V.z;
00267     if(d==Ddir) return V.z-my_tan(R_down)*V.x;
00268     
00269     if(d==Edir) {
00270       if(V.z>1.0+my_tan(R_top)) {
00271         return (V.z-1.0)/my_tan(R_top)-V.x;
00272       }
00273       if(V.z<my_tan(R_down)) {
00274         return V.z/my_tan(R_down)-V.x;
00275       }
00276       return 1.0 - V.x;
00277     }
00278     if(d==Wdir) {
00279       if(V.z>1.0) {
00280         return V.x-(V.z-1.0)/my_tan(R_top);
00281       }
00282       if(V.z<0.0) {
00283         return V.x-V.z/my_tan(R_down);
00284       }
00285       return V.x;
00286     }
00287     if(d==Ndir) return 1.0 - V.y;
00288     if(d==Sdir) return V.y;
00289   }
00290   return 0.0;
00291 }
00292 
00293 
00294 
00295 //  SCREW SQUARE: DTLR:  angles:            alpha_up,   alpha_down
00296 //                                         alpha_left, alpha_right
00297 // ----------------------------------------------------------------
00298 
00299 /*
00300 PointtypeD Poi_Skew_squareDTLR(D3vector V, 
00301                                double R_down, double R_top,
00302                                double R_left, double R_right) { 
00303   if(0<=V.x     && V.x<=1.0     &&
00304      V.y>=my_tan(R_left)*V.x       &&
00305      V.y<=1.0+my_tan(R_right)*V.x  &&
00306      V.z>=my_tan(R_down)*V.x       &&
00307      V.z<=1.0+my_tan(R_top)*V.x) return interiorD;
00308   else return exteriorD;
00309 }
00310 
00311 double dis_Skew_squareDTLR(D3vector V, dir_3D d, 
00312                            double R_down, double R_top,
00313                            double R_left, double R_right) {
00314   double disA;
00315   double disB;
00316 
00317   if(0<=V.x     && V.x<=1.0     &&
00318      V.y>=my_tan(R_left)*V.x       &&
00319      V.y<=1.0+my_tan(R_right)*V.x &&
00320      V.z>=my_tan(R_down)*V.x       &&
00321      V.z<=1.0+my_tan(R_top)*V.x) {
00322     if(d==Tdir) return 1.0+my_tan(R_top)*V.x - V.z;
00323     if(d==Ddir) return V.z-my_tan(R_down)*V.x;
00324     
00325     if(d==Edir) {
00326       // for z-x
00327       if(V.z>1.0+my_tan(R_top)) {
00328         disA = (V.z-1.0)/my_tan(R_top)-V.x;
00329       }
00330       else {
00331         if(V.z<my_tan(R_down)) {
00332           disA = V.z/my_tan(R_down)-V.x;
00333         }
00334         else 
00335           disA = 1.0 - V.x;
00336       }
00337       // for y-x
00338       if(V.y>1.0+my_tan(R_right)) {
00339         disB = (V.y-1.0)/my_tan(R_right)-V.x;
00340       }
00341       else {
00342         if(V.y<my_tan(R_left)) {
00343           disB = V.y/my_tan(R_left)-V.x;
00344         }
00345         else 
00346           disB = 1.0 - V.x;
00347       }
00348       //      return disB;
00349       return MIN(disA,disB);
00350     }
00351     if(d==Wdir) {
00352       // for z-x
00353       if(V.z>1.0) {
00354         disA =  V.x-(V.z-1.0)/my_tan(R_top);
00355       } 
00356       else {
00357         if(V.z<0.0) {
00358           disA =  V.x-V.z/my_tan(R_down);
00359         }
00360         else disA =  V.x;
00361       }
00362       // for y-x
00363       if(V.y>1.0) {
00364         disB =  V.x-(V.y-1.0)/my_tan(R_right);
00365       }
00366       else {
00367         if(V.y<0.0) {
00368           disB =  V.x-V.y/my_tan(R_left);
00369         }
00370         else disB =  V.x;
00371       }
00372       return MIN(disA,disB);
00373     }
00374     if(d==Ndir) return 1.0+my_tan(R_right)*V.x - V.y;
00375     if(d==Sdir) return V.y-my_tan(R_left)*V.x;
00376   }
00377   return 0.0;
00378 }
00379 */
00380 
00381 PointtypeD Poi_Skew_squareDTLR(D3vector V, 
00382                                double R_down, double R_top,
00383                                double R_left, double R_right) { 
00384   if(0<=V.z     && V.z<=1.0     &&
00385      V.y>=my_tan(R_left)*V.z       &&
00386      V.y<=1.0+my_tan(R_right)*V.z  &&
00387      V.x>=my_tan(R_down)*V.z       &&
00388      V.x<=1.0+my_tan(R_top)*V.z) return interiorD;
00389   else return exteriorD;
00390 }
00391 
00392 double dis_Skew_squareDTLR(D3vector V, dir_3D d, 
00393                            double R_down, double R_top,
00394                            double R_left, double R_right) {
00395   double disA;
00396   double disB;
00397 
00398   if(0<=V.z     && V.z<=1.0     &&
00399      V.y>=my_tan(R_left)*V.z       &&
00400      V.y<=1.0+my_tan(R_right)*V.z &&
00401      V.x>=my_tan(R_down)*V.z       &&
00402      V.x<=1.0+my_tan(R_top)*V.z) {
00403     if(d==Edir) return 1.0+my_tan(R_top)*V.z - V.x;
00404     if(d==Wdir) return V.x-my_tan(R_down)*V.z;
00405     
00406     if(d==Tdir) {
00407       // for z-x
00408       if(V.x>1.0+my_tan(R_top)) {
00409         disA = (V.x-1.0)/my_tan(R_top)-V.z;
00410       }
00411       else {
00412         if(V.x<my_tan(R_down)) {
00413           disA = V.x/my_tan(R_down)-V.z;
00414         }
00415         else 
00416           disA = 1.0 - V.z;
00417       }
00418       // for y-x
00419       if(V.y>1.0+my_tan(R_right)) {
00420         disB = (V.y-1.0)/my_tan(R_right)-V.z;
00421       }
00422       else {
00423         if(V.y<my_tan(R_left)) {
00424           disB = V.y/my_tan(R_left)-V.z;
00425         }
00426         else 
00427           disB = 1.0 - V.z;
00428       }
00429       //      return disB;
00430       return MIN(disA,disB);
00431     }
00432     if(d==Ddir) {
00433       // for z-x
00434       if(V.x>1.0) {
00435         disA =  V.z-(V.x-1.0)/my_tan(R_top);
00436       } 
00437       else {
00438         if(V.x<0.0) {
00439           disA =  V.z-V.x/my_tan(R_down);
00440         }
00441         else disA =  V.z;
00442       }
00443       // for y-x
00444       if(V.y>1.0) {
00445         disB =  V.z-(V.y-1.0)/my_tan(R_right);
00446       }
00447       else {
00448         if(V.y<0.0) {
00449           disB =  V.z-V.y/my_tan(R_left);
00450         }
00451         else disB =  V.z;
00452       }
00453       return MIN(disA,disB);
00454     }
00455     if(d==Ndir) return 1.0+my_tan(R_right)*V.z - V.y;
00456     if(d==Sdir) return V.y-my_tan(R_left)*V.z;
00457   }
00458   return 0.0;
00459 }
00460 
00461 
00462 
00463 
00464 //  periodic Cylinder:         Radius: 0.5,  center: (0.5,0.5,0.5)
00465 // ---------------------------------------------------
00466 
00467 
00468 PointtypeD Poi_periodic_Cylinder(D3vector V) { 
00469   V.x = V.x - 0.5;
00470   V.y = V.y - 0.5;
00471   
00472   if(sqrt(V.x*V.x+V.y*V.y)<=radius_cyl) return interiorD;
00473   else return exteriorD;
00474 }
00475 
00476 double dis_periodic_Cylinder(D3vector V, dir_3D d) {
00477   static double x,y; 
00478   x = V.x - 0.5;
00479   y = V.y - 0.5;
00480   if(sqrt(x*x+y*y)<=radius_cyl
00481      && V.z>=0.0 && V.z<=1.0) {
00482     if(d==Tdir || d==Ddir) {
00483       cout << " error in periodic cylinder " << endl;
00484       return 10.0e10;
00485     } 
00486    
00487     if(d==Edir) return sqrt(radius_cyl*radius_cyl-y*y) - x;
00488     if(d==Wdir) return sqrt(radius_cyl*radius_cyl-y*y) + x;
00489 
00490     if(d==Ndir) return sqrt(radius_cyl*radius_cyl-x*x) - y;
00491     if(d==Sdir) return sqrt(radius_cyl*radius_cyl-x*x) + y;
00492   }
00493   return 0.0;
00494 }

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