Actual source code: ex45.c

  1: /*
  2:    Creates a DMShell and uses it with a KSP
  3:    This tests that the KSP object can still create vectors using the Mat object

  5:    Contributed by Lawrence Mitchell as part of pull request 221

  7: */
  8: #include <petscdm.h>
  9: #include <petscdmshell.h>
 10: #include <petscksp.h>
 11: int main(int argc, char **argv)
 12: {
 13:   Mat      A;
 14:   KSP      ksp;
 15:   DM       shell;
 16:   Vec     *left, *right;
 17:   MPI_Comm c;

 20:   PetscInitialize(&argc, &argv, NULL, NULL);
 21:   c = PETSC_COMM_WORLD;

 23:   MatCreate(c, &A);
 24:   MatSetSizes(A, 1, 1, PETSC_DECIDE, PETSC_DECIDE);
 25:   MatSetFromOptions(A);
 26:   MatSetUp(A);
 27:   KSPCreate(c, &ksp);
 28:   KSPSetOperators(ksp, A, A);
 29:   KSPSetFromOptions(ksp);
 30:   DMShellCreate(c, &shell);
 31:   DMSetFromOptions(shell);
 32:   DMSetUp(shell);
 33:   KSPSetDM(ksp, shell);

 35:   KSPCreateVecs(ksp, 1, &right, 1, &left);
 36:   VecView(right[0], PETSC_VIEWER_STDOUT_(c));
 37:   VecDestroyVecs(1, &right);
 38:   VecDestroyVecs(1, &left);

 40:   DMDestroy(&shell);
 41:   KSPDestroy(&ksp);
 42:   MatDestroy(&A);
 43:   PetscFinalize();
 44:   return 0;
 45: }

 47: /*TEST

 49:    test:

 51: TEST*/