<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>poisson.c</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,7 +1,7 @@
 ALL : ex15 shell
 CFLAGS= -std=c99
 
-include ${PETSC_DIR}/bmake/common/base
+include ${PETSC_DIR}/conf/base
 
 nk : nk.o chkopts
 	${CLINKER} -o nk nk.o ${PETSC_LIB}
@@ -14,3 +14,6 @@ shell : shell.o chkopts
 
 cheb : cheb.o chebyshev.o chkopts
 	${CLINKER} -o cheb cheb.o chebyshev.o -lfftw3 ${PETSC_LIB}
+
+poisson : poisson.o chebyshev.o chkopts
+	${CLINKER} -o poisson poisson.o chebyshev.o -lfftw3 ${PETSC_LIB}</diff>
      <filename>Makefile</filename>
    </modified>
    <modified>
      <diff>@@ -17,7 +17,7 @@ int main(int argc,char **args)
 {
   Vec            x,b,u;   /* approx solution, RHS, exact solution */
   Mat            A;
-  Vec            x2,b2,u2;   /* approx solution, RHS, exact solution */
+  Vec            x2,b2,u2,du2;   /* approx solution, RHS, exact solution */
   Mat            A2;
   KSP            ksp;      /* linear solver context */
   PC             pc;        /* preconditioner context */
@@ -45,7 +45,7 @@ int main(int argc,char **args)
   ierr = VecDuplicate(b,&amp;x);CHKERRQ(ierr);
 
   ierr = MatCreateChebD1(PETSC_COMM_WORLD, x, b,
-                         FFTW_ESTIMATE | FFTW_PRESERVE_INPUT, &amp;A); CHKERRQ(ierr);
+                         FFTW_ESTIMATE, &amp;A); CHKERRQ(ierr);
 
   int dims[] = { m, n, p };
   // ierr = VecCreate(PETSC_COMM_WORLD, &amp;u2);CHKERRQ(ierr);
@@ -53,8 +53,9 @@ int main(int argc,char **args)
   // ierr = VecSetFromOptions(u2);CHKERRQ(ierr);
   ierr = VecCreateSeq(PETSC_COMM_WORLD, m * n * p, &amp;u2); CHKERRQ(ierr);
   ierr = VecDuplicate(u2, &amp;b2);CHKERRQ(ierr);
-  ierr = VecDuplicate(b2, &amp;x2);CHKERRQ(ierr);
-  ierr = MatCreateCheb(PETSC_COMM_WORLD, 3, d, dims, FFTW_ESTIMATE | FFTW_PRESERVE_INPUT,
+  ierr = VecDuplicate(u2, &amp;du2);CHKERRQ(ierr);
+  ierr = VecDuplicate(u2, &amp;x2);CHKERRQ(ierr);
+  ierr = MatCreateCheb(PETSC_COMM_WORLD, 3, d, dims, FFTW_ESTIMATE,
                        x2, b2, &amp;A2); CHKERRQ(ierr);
 
   ierr = KSPCreate(PETSC_COMM_WORLD,&amp;ksp);CHKERRQ(ierr);
@@ -70,7 +71,9 @@ int main(int argc,char **args)
   ierr = VecRestoreArray(u, &amp;a); CHKERRQ(ierr);
 
   // 2-D solution function
+  double *e;
   ierr = VecGetArray(u2, &amp;a); CHKERRQ(ierr);
+  ierr = VecGetArray(du2, &amp;e); CHKERRQ(ierr);
   for (int i=0; i &lt; m; i++) {
     double x = (m==1) ? 0 : cos (i * PI / (m-1));
     for (int j=0; j &lt; n; j++) {
@@ -78,13 +81,18 @@ int main(int argc,char **args)
       for (int k=0; k &lt; p; k++) {
         double z = (p==1) ? 0 : cos (k * PI / (p-1));
         a[(i*n + j) * p + k] = exp(x) + exp(y) + exp(z);
+        switch (d) {
+          case 0: e[(i*n + j) * p + k] = exp(x); break;
+          case 1: e[(i*n + j) * p + k] = exp(y); break;
+          case 2: e[(i*n + j) * p + k] = exp(z); break;
+        }
       }
     }
   }
   ierr = VecRestoreArray(u2, &amp;a); CHKERRQ(ierr);
+  ierr = VecRestoreArray(du2, &amp;e); CHKERRQ(ierr);
 
   ierr = MatMult(A, u, b); CHKERRQ(ierr);
-  ierr = MatMult(A2, u2, b2); CHKERRQ(ierr);
   // ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);
   ierr = VecCopy(b, x); CHKERRQ(ierr);
 
@@ -94,11 +102,20 @@ int main(int argc,char **args)
   //ierr = PetscPrintf(PETSC_COMM_WORLD,&quot;Norm of error %A iterations %D\n&quot;,norm,its);CHKERRQ(ierr);
   ierr = PetscPrintf(PETSC_COMM_WORLD,&quot;Norm of error %A\n&quot;,norm);CHKERRQ(ierr);
 
+  ierr = MatMult(A2, u2, b2); CHKERRQ(ierr);
+  ierr = VecCopy(b2, x2); CHKERRQ(ierr);
+
+  ierr = VecAXPY(x2,none,du2);CHKERRQ(ierr);
+  ierr = VecNorm(x2,NORM_INFINITY,&amp;norm);CHKERRQ(ierr);
+  // ierr = KSPGetIterationNumber(ksp,&amp;its);CHKERRQ(ierr);
+  //ierr = PetscPrintf(PETSC_COMM_WORLD,&quot;Norm of error %A iterations %D\n&quot;,norm,its);CHKERRQ(ierr);
+  ierr = PetscPrintf(PETSC_COMM_WORLD,&quot;Norm of error %A\n&quot;,norm);CHKERRQ(ierr);
+
   /* /\* ierr = VecView(x, PETSC_VIEWER_STDOUT_SELF); CHKERRQ(ierr); *\/ */
-  printf(&quot;\n&quot;);
-  ierr = VecView(b, PETSC_VIEWER_STDOUT_SELF); CHKERRQ(ierr);
-  printf(&quot;\n&quot;);
-  ierr = VecView(b2, PETSC_VIEWER_STDOUT_SELF); CHKERRQ(ierr);
+  /* printf(&quot;\n&quot;); */
+  /* ierr = VecView(b, PETSC_VIEWER_STDOUT_SELF); CHKERRQ(ierr); */
+  /* printf(&quot;\n&quot;); */
+  /* ierr = VecView(b2, PETSC_VIEWER_STDOUT_SELF); CHKERRQ(ierr); */
 
   /*
      Free work space.  All PETSc objects should be destroyed when they</diff>
      <filename>cheb.c</filename>
    </modified>
    <modified>
      <diff>@@ -123,9 +123,9 @@ PetscErrorCode MatCreateCheb(MPI_Comm comm, int rank, int tr, int *dim, unsigned
   ierr = VecGetArray(vx, &amp;x); CHKERRQ(ierr);
   ierr = VecGetArray(vy, &amp;y); CHKERRQ(ierr);
   const fftw_r2r_kind redft00 = FFTW_REDFT00, rodft00 = FFTW_RODFT00;
-  c-&gt;p_forward = fftw_plan_guru_r2r(1, &amp;(c-&gt;tdim), c-&gt;rank-1, c-&gt;dim, x, c-&gt;work, &amp;redft00, flag);
+  c-&gt;p_forward = fftw_plan_guru_r2r(1, &amp;(c-&gt;tdim), c-&gt;rank-1, c-&gt;dim, x, c-&gt;work, &amp;redft00, flag | FFTW_PRESERVE_INPUT);
   fftw_iodim tdim1 = c-&gt;tdim; tdim1.n -= 2; // we need a modified tdim to come back.
-  c-&gt;p_backward = fftw_plan_guru_r2r(1, &amp;tdim1, c-&gt;rank-1, c-&gt;dim, c-&gt;work + tdim1.os, y + tdim1.is, &amp;rodft00, flag);
+  c-&gt;p_backward = fftw_plan_guru_r2r(1, &amp;tdim1, c-&gt;rank-1, c-&gt;dim, c-&gt;work + tdim1.os, y + tdim1.is, &amp;rodft00, flag | FFTW_DESTROY_INPUT);
   ierr = VecRestoreArray(vx, &amp;x); CHKERRQ(ierr);
   ierr = VecRestoreArray(vy, &amp;y); CHKERRQ(ierr);
 
@@ -153,38 +153,39 @@ PetscErrorCode ChebMult(Mat A, Vec vx, Vec vy) {
 
   fftw_execute_r2r(c-&gt;p_forward, x, c-&gt;work);
 
+  double N = (double)n;
   ierr = PetscMemzero(ind, (c-&gt;rank - 1) * sizeof(int)); CHKERRQ(ierr);
   int offset = 0;
   for (bool done = false; !done; ) {
+    int ix0 = offset;
+    int ixn = offset + n * c-&gt;tdim.is;
+    y[ix0] = 0.0;
+    y[ixn] = 0.0;
+    double s = 1.0;
     for (int i = 1; i &lt; n; i++) {
       int ix = offset + i * c-&gt;tdim.is;
-      c-&gt;work[ix] *= (double)i;
+      double I = (double)i;
+      c-&gt;work[ix] *= I;
+      y[ix0] += I * c-&gt;work[ix];
+      y[ixn] += s * I * c-&gt;work[ix];
+      s = -s;
     }
+    y[ix0] = 0.5 * c-&gt;work[ixn] * N + y[ix0] / n;
+    y[ixn] = y[ixn] / N + 0.5 * s * N * c-&gt;work[ixn];
     perform_carry(c, ind, &amp;offset, &amp;done);
   }
 
   fftw_execute_r2r(c-&gt;p_backward, c-&gt;work + c-&gt;tdim.os, y + c-&gt;tdim.is);
 
-  double N = (double)n;
   double pin = PI / N;
   ierr = PetscMemzero(ind, (c-&gt;rank - 1) * sizeof(int)); CHKERRQ(ierr);
   offset = 0;
   for (bool done = false; !done; ) {
-    int ix0 = offset;
-    int ixn = offset + n * c-&gt;tdim.is;
-    y[ix0] = 0.0;
-    y[ixn] = 0.0;
-    double s = 1.0;
     for (int i = 1; i &lt; n; i++) {
       int ix = offset + i * c-&gt;tdim.is;
       double I = (double)i;
       y[ix] /= 2 * n * sqrt(1.0 - PetscSqr(cos(I * pin)));
-      y[ix0] += I * c-&gt;work[ix];
-      y[ixn] += s * I * c-&gt;work[ix];
-      s = -s;
     }
-    y[ix0] = 0.5 * c-&gt;work[ixn] * N + y[ix0] / n;
-    y[ixn] = y[ixn] / N + 0.5 * s * N * c-&gt;work[ixn];
     perform_carry(c, ind, &amp;offset, &amp;done);
   }
 </diff>
      <filename>chebyshev.c</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b2d95fbfd5e5711669d16e02c710a4b2169aed3a</id>
    </parent>
  </parents>
  <author>
    <name>Jed Brown</name>
    <email>jed@59A2.org</email>
  </author>
  <url>http://github.com/jedbrown/spectral-petsc/commit/92d68dd3b8a7929e26dd6f77da703d9554b7b838</url>
  <id>92d68dd3b8a7929e26dd6f77da703d9554b7b838</id>
  <committed-date>2008-03-03T14:34:00-08:00</committed-date>
  <authored-date>2008-03-03T14:34:00-08:00</authored-date>
  <message>Poisson solver.

darcs-hash:20080303223426-40437-d68e6bd220058e767326782d29634ec83d089f16.gz</message>
  <tree>e81693ca8748ee0549aca2628e94ce3111edfe01</tree>
  <committer>
    <name>Jed Brown</name>
    <email>jed@59A2.org</email>
  </committer>
</commit>
