Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

jacobi_poisson/miscFcnsX.C.sed

Go to the documentation of this file.
00001 
00002 #include <MultiDimArrayAccess.h>
00003 #include <tbox_PIO.h>
00004 #include <math.h>
00005 
00006 /*
00007   Relax current solution and put result in scratch space.
00008 */
00009 int jacobiPoissonSmooth(
00010   double relax_coef
00011 , MultiDimArrayAccess<double,2> c
00012 , MultiDimArrayAccess<double,2> s
00013 , MultiDimArrayAccess<double,2> f
00014 , const int *lower
00015 , const int *upper
00016 , const double *xlo
00017 , const double *xhi
00018 , const double *dx
00019 ) {
00020   int i, j;
00021   const double a1=dx[0]*dx[0];
00022   for ( j=lower[1]; j<=upper[1]; ++j ) {
00023     for ( i=lower[0]; i<=upper[0]; ++i ) {
00024       c(j,i) = 0.25*( s(j-1,i) + s(j+1,i) + s(j,i-1) + s(j,i+1) - a1*f(j,i) );
00025     }
00026   }
00027   return 0;
00028 }
00029 
00030 
00031 /*
00032   Set the boundary condition.
00033   Set the data in ghost cell to the reverse of the interior data
00034   to force a Dirichlet boundary condition.
00035 */
00036 int jacobiPoissonBoundary(
00037   MultiDimArrayAccess<double,2> d
00038 , const int *lower
00039 , const int *upper
00040 , const double *xlo
00041 , const double *xhi
00042 , const double *dx
00043 ) {
00044 
00045   int i, j;
00046 
00047   j = lower[1]-1;
00048   for ( i=lower[0]; i<=upper[0]; ++i ) {
00049     d(j,i) = -d(j+1,i);
00050   }
00051   j = upper[1]+1;
00052   for ( i=lower[0]; i<=upper[0]; ++i ) {
00053     d(j,i) = -d(j-1,i);
00054   }
00055 
00056   i = lower[0]-1;
00057   for ( j=lower[1]; j<=upper[1]; ++j ) {
00058     d(j,i) = -d(j,i+1);
00059   }
00060   i = upper[0]+1;
00061   for ( j=lower[1]; j<=upper[1]; ++j ) {
00062     d(j,i) = -d(j,i-1);
00063   }
00064 
00065   return 0;
00066 }
00067 
00068 
00069 
00070 
00071 /*
00072   Set boundary condition to exact solution.
00073   Which is -source/(8*pi*pi).
00074 */
00075 int jacobiPoissonExactBC(
00076   MultiDimArrayAccess<double,2> s
00077 , const int *lower
00078 , const int *upper
00079 , const double *xlo
00080 , const double *xhi
00081 , const double *dx
00082 ) {
00083 
00084   int i, j;
00085   double a1 = -1.0/(8*M_PI*M_PI);
00086   double x, y, sinx, siny;
00087 
00088   j = lower[1]-1;
00089   y = xlo[1] - 0.5*dx[1];
00090   siny = sin(2*M_PI*y);
00091   for ( i=lower[0]; i<=upper[0]; ++i ) {
00092     x = xlo[0] + (i-lower[0]+0.5)*dx[0];
00093     sinx = sin(2*M_PI*x);
00094     s(j,i) = a1*sinx*siny;
00095   }
00096 
00097   j = upper[1]+1;
00098   y = xhi[1] + 0.5*dx[1];
00099   siny = sin(2*M_PI*y);
00100   for ( i=lower[0]; i<=upper[0]; ++i ) {
00101     x = xlo[0] + (i-lower[0]+0.5)*dx[0];
00102     sinx = sin(2*M_PI*x);
00103     s(j,i) = a1*sinx*siny;
00104   }
00105 
00106   i = lower[0]-1;
00107   x = xlo[0] - 0.5*dx[0];
00108   sinx = sin(2*M_PI*x);
00109   for ( j=lower[1]; j<=upper[1]; ++j ) {
00110     y = xlo[1] + (j-lower[1]+0.5)*dx[1];
00111     siny = sin(2*M_PI*y);
00112     s(j,i) = a1*sinx*siny;
00113   }
00114 
00115   i = upper[0]+1;
00116   x = xhi[0] + 0.5*dx[0];
00117   sinx = sin(2*M_PI*x);
00118   for ( j=lower[1]; j<=upper[1]; ++j ) {
00119     y = xlo[1] + (j-lower[1]+0.5)*dx[1];
00120     siny = sin(2*M_PI*y);
00121     s(j,i) = a1*sinx*siny;
00122   }
00123 
00124   return 0;
00125 }

Generated on Wed Apr 17 12:51:45 2002 for samtut by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001