1. petsc
  2. PETSc
  3. petsc

Commits

Peter Brune  committed 0b09383

Add VTK output and fix up BCs for snes/examples/tutorials/ex16.c

  • Participants
  • Parent commits 08e43b6
  • Branches master

Comments (0)

Files changed (3)

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

View file
   Vec            x,X,b;
   PetscBool      youngflg,poissonflg,muflg,lambdaflg,view=PETSC_FALSE,viewline=PETSC_FALSE;
   PetscReal      poisson=0.2,young=4e4;
+  char           filename[PETSC_MAX_PATH_LEN] = "ex16.vts";
+  char           filename_def[PETSC_MAX_PATH_LEN] = "ex16_def.vts";
 
   ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return(1);
 
 
   ierr = DMDASetFieldName(da,0,"x_disp");CHKERRQ(ierr);
   ierr = DMDASetFieldName(da,1,"y_disp");CHKERRQ(ierr);
-  ierr = DMDASetFieldName(da,2,"y_disp");CHKERRQ(ierr);
+  ierr = DMDASetFieldName(da,2,"z_disp");CHKERRQ(ierr);
 
   ierr = DMSetApplicationContext(da,&user);CHKERRQ(ierr);
   ierr = DMDASNESSetFunctionLocal(da,INSERT_VALUES,(PetscErrorCode (*)(DMDALocalInfo*,void*,void*,void*))FormFunctionLocal,&user);CHKERRQ(ierr);
     ierr = DisplayLine(snes,X);CHKERRQ(ierr);
   }
 
+  if (view) {
+    PetscViewer viewer;
+    Vec coords;
+    ierr = PetscViewerVTKOpen(PETSC_COMM_WORLD,filename,FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
+    ierr = VecView(x,viewer);CHKERRQ(ierr);
+    ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
+    ierr = DMGetCoordinates(da,&coords);CHKERRQ(ierr);
+    ierr = VecAXPY(coords,1.0,x);CHKERRQ(ierr);
+    ierr = PetscViewerVTKOpen(PETSC_COMM_WORLD,filename_def,FILE_MODE_WRITE,&viewer);CHKERRQ(ierr);
+    ierr = VecView(x,viewer);CHKERRQ(ierr);
+    ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
+  }
+
   ierr = VecDestroy(&x);CHKERRQ(ierr);
   ierr = VecDestroy(&b);CHKERRQ(ierr);
   ierr = DMDestroy(&da);CHKERRQ(ierr);
 
 PetscInt OnBoundary(PetscInt i,PetscInt j,PetscInt k,PetscInt mx,PetscInt my,PetscInt mz)
 {
-  if ((i == 0 || i == mx-1) && j == my/2) return 1;
+  if ((i == 0 || i == mx-1) && j == my-1) return 1;
   return 0;
 }
 
         PetscReal rad = user->rad + cy*user->height;
         PetscReal ang = (cx - 0.5)*user->arc;
         x[k][j][i][0] = rad*PetscSinReal(ang);
-        x[k][j][i][1] = rad*PetscCosReal(ang) - rad*PetscCosReal(-0.5*user->arc);
+        x[k][j][i][1] = rad*PetscCosReal(ang) - (user->rad + 0.5*user->height)*PetscCosReal(-0.5*user->arc);
         x[k][j][i][2] = user->width*(cz - 0.5);
       }
     }
         x[k][j][i][0] = 0.;
         x[k][j][i][1] = 0.;
         x[k][j][i][2] = 0.;
-        if (i == (mx-1)/2 && j == (my-1) && k == (mz-1)/2) x[k][j][i][1] = user->ploading;
+        if (i == (mx-1)/2 && j == (my-1)) x[k][j][i][1] = user->ploading/(mz-1);
       }
     }
   }

File src/snes/examples/tutorials/output/ex16_1.out

View file
 lambda: 2.777778 mu: 4.166667
-  0 SNES Function norm 0.0831281 
-    0 KSP Residual norm 371.981 
-    1 KSP Residual norm 40.2918 
-    2 KSP Residual norm 7.52248 
-    3 KSP Residual norm 0.617684 
-    4 KSP Residual norm 0.0728605 
-    5 KSP Residual norm 0.0172846 
-    6 KSP Residual norm 0.00480705 
-    7 KSP Residual norm 0.000933107 
-  1 SNES Function norm 0.0816684 
-    0 KSP Residual norm 333.077 
-    1 KSP Residual norm 11.169 
-    2 KSP Residual norm 1.40687 
-    3 KSP Residual norm 0.131425 
-    4 KSP Residual norm 0.00862797 
-    5 KSP Residual norm 0.00178031 
-  2 SNES Function norm 0.0792439 
-    0 KSP Residual norm 246.868 
-    1 KSP Residual norm 2.94514 
-    2 KSP Residual norm 0.38738 
-    3 KSP Residual norm 0.0211293 
-    4 KSP Residual norm 0.00150754 
-  3 SNES Function norm 0.0789858 
-    0 KSP Residual norm 168.222 
-    1 KSP Residual norm 1.40498 
-    2 KSP Residual norm 0.0873035 
-    3 KSP Residual norm 0.0037583 
-    4 KSP Residual norm 0.000704599 
-  4 SNES Function norm 0.0754888 
-    0 KSP Residual norm 128.561 
-    1 KSP Residual norm 1.03728 
-    2 KSP Residual norm 0.0541608 
-    3 KSP Residual norm 0.0027685 
-    4 KSP Residual norm 0.000626261 
-  5 SNES Function norm 0.0705719 
-    0 KSP Residual norm 103.218 
-    1 KSP Residual norm 0.81458 
-    2 KSP Residual norm 0.0377383 
-    3 KSP Residual norm 0.00230933 
-    4 KSP Residual norm 0.000547811 
-  6 SNES Function norm 0.0652094 
-    0 KSP Residual norm 85.2271 
-    1 KSP Residual norm 0.662663 
-    2 KSP Residual norm 0.0278423 
-    3 KSP Residual norm 0.00203323 
-    4 KSP Residual norm 0.000473194 
-  7 SNES Function norm 0.059837 
-    0 KSP Residual norm 71.6679 
-    1 KSP Residual norm 0.551149 
-    2 KSP Residual norm 0.0212104 
-    3 KSP Residual norm 0.00183622 
-    4 KSP Residual norm 0.000423579 
-  8 SNES Function norm 0.0526202 
-    0 KSP Residual norm 55.7176 
-    1 KSP Residual norm 0.422284 
-    2 KSP Residual norm 0.0141346 
-    3 KSP Residual norm 0.00158609 
-    4 KSP Residual norm 0.00038517 
-  9 SNES Function norm 0.0417511 
-    0 KSP Residual norm 34.442 
-    1 KSP Residual norm 0.255145 
-    2 KSP Residual norm 0.00632659 
-    3 KSP Residual norm 0.00116905 
-    4 KSP Residual norm 0.000329744 
- 10 SNES Function norm 0.0298319 
-    0 KSP Residual norm 3.26949 
-    1 KSP Residual norm 0.0265403 
-    2 KSP Residual norm 0.00093532 
-    3 KSP Residual norm 5.5349e-05 
-    4 KSP Residual norm 3.1393e-05 
- 11 SNES Function norm 0.000596343 
-    0 KSP Residual norm 0.0422426 
-    1 KSP Residual norm 0.000455393 
-    2 KSP Residual norm 4.7035e-05 
-    3 KSP Residual norm 2.59335e-05 
-    4 KSP Residual norm 1.23556e-06 
-    5 KSP Residual norm 1.70279e-07 
- 12 SNES Function norm 2.13393e-07 
-    0 KSP Residual norm 8.74299e-06 
-    1 KSP Residual norm 3.22701e-07 
-    2 KSP Residual norm 1.6343e-07 
-    3 KSP Residual norm 2.08694e-08 
-    4 KSP Residual norm 6.87665e-09 
-    5 KSP Residual norm 2.64881e-09 
-    6 KSP Residual norm 5.268e-10 
-    7 KSP Residual norm 5.175e-11 
- 13 SNES Function norm < 1.e-11
-Number of SNES iterations = 13
+  0 SNES Function norm 0.472955 
+    0 KSP Residual norm 796.36 
+    1 KSP Residual norm 44.0362 
+    2 KSP Residual norm 14.3938 
+    3 KSP Residual norm 0.609089 
+    4 KSP Residual norm 0.225388 
+    5 KSP Residual norm 0.0552247 
+    6 KSP Residual norm 0.00642713 
+  1 SNES Function norm 0.46423 
+    0 KSP Residual norm 576.427 
+    1 KSP Residual norm 13.4641 
+    2 KSP Residual norm 8.8971 
+    3 KSP Residual norm 1.80563 
+    4 KSP Residual norm 0.0410906 
+    5 KSP Residual norm 0.00890581 
+    6 KSP Residual norm 0.000870458 
+  2 SNES Function norm 0.445447 
+    0 KSP Residual norm 414.443 
+    1 KSP Residual norm 7.26068 
+    2 KSP Residual norm 4.92369 
+    3 KSP Residual norm 0.751501 
+    4 KSP Residual norm 0.251326 
+    5 KSP Residual norm 0.00849148 
+    6 KSP Residual norm 0.000695246 
+  3 SNES Function norm 0.406748 
+    0 KSP Residual norm 270.079 
+    1 KSP Residual norm 5.36009 
+    2 KSP Residual norm 1.37696 
+    3 KSP Residual norm 1.19231 
+    4 KSP Residual norm 0.537912 
+    5 KSP Residual norm 0.00599234 
+    6 KSP Residual norm 0.000589587 
+  4 SNES Function norm 0.367841 
+    0 KSP Residual norm 204.19 
+    1 KSP Residual norm 4.00605 
+    2 KSP Residual norm 0.695199 
+    3 KSP Residual norm 0.583857 
+    4 KSP Residual norm 0.423925 
+    5 KSP Residual norm 0.00513746 
+    6 KSP Residual norm 0.000481265 
+  5 SNES Function norm 0.331881 
+    0 KSP Residual norm 163.014 
+    1 KSP Residual norm 3.0915 
+    2 KSP Residual norm 0.546506 
+    3 KSP Residual norm 0.258826 
+    4 KSP Residual norm 0.257635 
+    5 KSP Residual norm 0.00484508 
+    6 KSP Residual norm 0.000435677 
+  6 SNES Function norm 0.278966 
+    0 KSP Residual norm 117.231 
+    1 KSP Residual norm 2.09192 
+    2 KSP Residual norm 0.398551 
+    3 KSP Residual norm 0.0992969 
+    4 KSP Residual norm 0.0803857 
+    5 KSP Residual norm 0.00460956 
+    6 KSP Residual norm 0.000387953 
+  7 SNES Function norm 0.184413 
+    0 KSP Residual norm 57.1438 
+    1 KSP Residual norm 0.905886 
+    2 KSP Residual norm 0.129636 
+    3 KSP Residual norm 0.0217824 
+    4 KSP Residual norm 0.00177469 
+    5 KSP Residual norm 0.00176823 
+    6 KSP Residual norm 0.00131235 
+    7 KSP Residual norm 0.000153827 
+  8 SNES Function norm 0.085136 
+    0 KSP Residual norm 5.83255 
+    1 KSP Residual norm 0.0768013 
+    2 KSP Residual norm 0.0126386 
+    3 KSP Residual norm 0.00960665 
+    4 KSP Residual norm 0.00272803 
+    5 KSP Residual norm 3.42724e-05 
+  9 SNES Function norm 0.00181491 
+    0 KSP Residual norm 0.0811755 
+    1 KSP Residual norm 0.00766808 
+    2 KSP Residual norm 0.00152447 
+    3 KSP Residual norm 0.000782465 
+    4 KSP Residual norm 3.3319e-05 
+    5 KSP Residual norm 2.87258e-06 
+    6 KSP Residual norm 3.81706e-07 
+ 10 SNES Function norm 3.5124e-06 
+    0 KSP Residual norm 5.39592e-05 
+    1 KSP Residual norm 1.93611e-05 
+    2 KSP Residual norm 1.17433e-06 
+    3 KSP Residual norm 6.20593e-07 
+    4 KSP Residual norm 4.34494e-08 
+    5 KSP Residual norm 3.41452e-09 
+    6 KSP Residual norm 2.351e-10 
+ 11 SNES Function norm 4.634e-11 
+Number of SNES iterations = 11

File src/snes/examples/tutorials/output/ex16_2.out

View file
 lambda: 2.777778 mu: 4.166667
-  0 SNES Function norm 0.0831281 
-    0 SNES Function norm 0.0831281 
-    1 SNES Function norm 0.319185 
-    0 KSP Residual norm 4.4885 
-    1 KSP Residual norm 0.0667631 
-    2 KSP Residual norm 0.00397109 
-    3 KSP Residual norm 0.000321695 
-    4 KSP Residual norm 0.000176072 
-    5 KSP Residual norm 6.8841e-05 
-    6 KSP Residual norm 4.22795e-06 
-  1 SNES Function norm 0.134213 
-    0 SNES Function norm 0.134213 
-    1 SNES Function norm 0.0277313 
-    0 KSP Residual norm 0.111054 
-    1 KSP Residual norm 0.00154158 
-    2 KSP Residual norm 9.07826e-05 
-    3 KSP Residual norm 1.46645e-05 
-    4 KSP Residual norm 4.38228e-06 
-    5 KSP Residual norm 1.02772e-06 
-  2 SNES Function norm 0.000199778 
-    0 SNES Function norm 0.000199778 
-    1 SNES Function norm 4.96735e-05 
-    0 KSP Residual norm 0.000112454 
-    1 KSP Residual norm 7.7973e-06 
-    2 KSP Residual norm 2.97332e-07 
-    3 KSP Residual norm 3.51382e-08 
-    4 KSP Residual norm 1.49767e-08 
-    5 KSP Residual norm 2.36965e-09 
-    6 KSP Residual norm 4.459e-10 
-  3 SNES Function norm 2.43411e-09 
-    0 SNES Function norm 2.43411e-09 
-    1 SNES Function norm 1.07964e-09 
-    0 KSP Residual norm 3.64073e-09 
-    1 KSP Residual norm 1.392e-10 
-    2 KSP Residual norm 3.212e-11 
+  0 SNES Function norm 0.472955 
+    0 SNES Function norm 0.472955 
+    1 SNES Function norm 1.23865 
+    0 KSP Residual norm 18.4472 
+    1 KSP Residual norm 0.463226 
+    2 KSP Residual norm 0.386609 
+    3 KSP Residual norm 0.010227 
+    4 KSP Residual norm 0.000616355 
+    5 KSP Residual norm 7.73457e-05 
+  1 SNES Function norm 0.221209 
+    0 SNES Function norm 0.221209 
+    1 SNES Function norm 0.0448074 
+    0 KSP Residual norm 0.312532 
+    1 KSP Residual norm 0.00542729 
+    2 KSP Residual norm 0.00201827 
+    3 KSP Residual norm 6.56869e-05 
+    4 KSP Residual norm 2.72307e-05 
+    5 KSP Residual norm 1.31394e-06 
+  2 SNES Function norm 0.000251186 
+    0 SNES Function norm 0.000251186 
+    1 SNES Function norm 0.000115426 
+    0 KSP Residual norm 0.000169684 
+    1 KSP Residual norm 7.16941e-06 
+    2 KSP Residual norm 2.04868e-06 
+    3 KSP Residual norm 7.71801e-08 
+    4 KSP Residual norm 2.50788e-08 
+    5 KSP Residual norm 2.34149e-09 
+    6 KSP Residual norm 1.523e-10 
+  3 SNES Function norm 5.75099e-09 
+    0 SNES Function norm 5.75099e-09 
+    1 SNES Function norm 1.62036e-09 
+    0 KSP Residual norm 1.7293e-09 
+    1 KSP Residual norm 1.813e-11 
+    2 KSP Residual norm < 1.e-11
     3 KSP Residual norm < 1.e-11
     4 KSP Residual norm < 1.e-11
     5 KSP Residual norm < 1.e-11
     6 KSP Residual norm < 1.e-11
-    7 KSP Residual norm < 1.e-11
   4 SNES Function norm < 1.e-11
 Number of SNES iterations = 4