1. petsc
  2. PETSc
  3. petsc

Commits

BarryFSmith  committed 22b0d44

fix examples that did not compile under complex but were in C test suite to work with complex

  • Participants
  • Parent commits a52f552
  • Branches master

Comments (0)

Files changed (2)

File src/snes/examples/tutorials/ex55.c

View file
   AppCtx         user; /* Application context */
   Vec            xl,xu; /* Upper and lower bounds on variables */
   Mat            J;
-  PetscScalar    t=0.0;
+  PetscReal      t=0.0;
   PetscViewer    view_out, view_q, view1;
 
   PetscInitialize(&argc,&argv, (char*)0, help);
   const PetscInt    *ele;
   Vec               coords, rand1, rand2;
   const PetscScalar *_coords;
-  PetscScalar       x[3],y[3];
+  PetscReal         x[3],y[3];
   PetscInt          idx[3];
   PetscScalar       *xx,*w1,*w2,*u1,*u2,*u3;
   PetscViewer       view_out;
   /* Get local element info */
   ierr = DMDAGetElements(user->da,&nele,&nen,&ele);CHKERRQ(ierr);
   for (i=0; i < nele; i++) {
-    idx[0] = ele[3*i]; idx[1] = ele[3*i+1]; idx[2] = ele[3*i+2];
-    x[0]   = _coords[2*idx[0]]; y[0] = _coords[2*idx[0]+1];
-    x[1]   = _coords[2*idx[1]]; y[1] = _coords[2*idx[1]+1];
-    x[2]   = _coords[2*idx[2]]; y[2] = _coords[2*idx[2]+1];
-
     PetscScalar vals1[3],vals2[3],valsrand[3];
     PetscInt    r;
+    idx[0] = ele[3*i]; idx[1] = ele[3*i+1]; idx[2] = ele[3*i+2];
+    x[0]   = PetscRealPart(_coords[2*idx[0]]); y[0] = PetscRealPart(_coords[2*idx[0]+1]);
+    x[1]   = PetscRealPart(_coords[2*idx[1]]); y[1] = PetscRealPart(_coords[2*idx[1]+1]);
+    x[2]   = PetscRealPart(_coords[2*idx[2]]); y[2] = PetscRealPart(_coords[2*idx[2]+1]);
+
     for (r=0; r<3; r++) {
-      valsrand[r]=5*x[r]*(1-x[r])*y[r]*(1-y[r]);
+      valsrand[r]=5.0*x[r]*(1.0-x[r])*y[r]*(1.0-y[r]);
       if (x[r]>=0.5 && y[r]>=0.5) {
         vals1[r]=0.75;
         vals2[r]=0.0;
 
   for (i=0; i<n/4; i++) {
     xx[4*i] = w1[i];
-    if (xx[4*i]>1) xx[4*i]=1;
+    if (PetscRealPart(xx[4*i])>1.0) xx[4*i]=1;
 
     xx[4*i+1] = w2[i];
-    if (xx[4*i+1]>1) xx[4*i+1]=1;
+    if (PetscRealPart(xx[4*i+1])>1.0) xx[4*i+1]=1;
 
-    if (xx[4*i]+xx[4*i+1]>1) xx[4*i+1] = 1.0 - xx[4*i];
+    if (PetscRealPart(xx[4*i]+xx[4*i+1])>1) xx[4*i+1] = 1.0 - xx[4*i];
 
     xx[4*i+2] = 1.0 - xx[4*i] - xx[4*i+1];
     xx[4*i+3] = 0.0;

File src/snes/examples/tutorials/ex70.c

View file
     for (j = 0; j < s->ny; j++) {
       for (i = 0; i < s->nx; i++) {
         n    = j*s->nx+i;
-        ierr = PetscViewerASCIIPrintf(viewer, "%.12g %.12g %.12g %.12g %.12g\n", i*s->hx+s->hx/2, j*s->hy+s->hy/2, array[n], array[n+s->nx*s->ny], array[n+2*s->nx*s->ny]);CHKERRQ(ierr);
+        ierr = PetscViewerASCIIPrintf(viewer, "%.12g %.12g %.12g %.12g %.12g\n", (double)(i*s->hx+s->hx/2),(double)(j*s->hy+s->hy/2), (double)PetscRealPart(array[n]), (double)PetscRealPart(array[n+s->nx*s->ny]),(double)PetscRealPart(array[n+2*s->nx*s->ny]));CHKERRQ(ierr);
       }
     }
     ierr = VecRestoreArray(s->x, &array);CHKERRQ(ierr);
   /* error in velocity */
   ierr = VecGetSubVector(s->y, s->isg[0], &y0);CHKERRQ(ierr);
   ierr = VecNorm(y0, NORM_2, &val);CHKERRQ(ierr);
-  ierr = PetscPrintf(PETSC_COMM_WORLD," discretization error u = %g\n",(double)(val/scale));CHKERRQ(ierr);
+  ierr = PetscPrintf(PETSC_COMM_WORLD," discretization error u = %g\n",(double)(PetscRealPart(val/scale)));CHKERRQ(ierr);
   ierr = VecRestoreSubVector(s->y, s->isg[0], &y0);CHKERRQ(ierr);
 
   /* error in pressure */
   ierr = VecGetSubVector(s->y, s->isg[1], &y1);CHKERRQ(ierr);
   ierr = VecNorm(y1, NORM_2, &val);CHKERRQ(ierr);
-  ierr = PetscPrintf(PETSC_COMM_WORLD," discretization error p = %g\n",(double)(val/scale));CHKERRQ(ierr);
+  ierr = PetscPrintf(PETSC_COMM_WORLD," discretization error p = %g\n",(double)(PetscRealPart(val/scale)));CHKERRQ(ierr);
   ierr = VecRestoreSubVector(s->y, s->isg[1], &y1);CHKERRQ(ierr);
 
   /* total error */
   ierr = VecNorm(s->y, NORM_2, &val);CHKERRQ(ierr);
-  ierr = PetscPrintf(PETSC_COMM_WORLD," discretization error [u,p] = %g\n", (double)(val/scale));CHKERRQ(ierr);
+  ierr = PetscPrintf(PETSC_COMM_WORLD," discretization error [u,p] = %g\n", (double)PetscRealPart((val/scale)));CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }