Actual source code: ex197.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  1: static char help[] = "Test MatMultHermitianTranspose() and MatMultHermitianTransposeAdd().\n\n";

  3: #include <petscmat.h>

  7: int main(int argc,char **args)
  8: {
  9:   Mat            A;
 10:   Vec            x,y,ys;
 12:   PetscInt       i,j;
 13:   PetscScalar    v;

 15:   PetscInitialize(&argc,&args,(char*)0,help);
 16: #if !defined(PETSC_USE_COMPLEX)
 17:   SETERRQ(PETSC_COMM_WORLD,1,"This example requires complex numbers");
 18: #endif

 20:   MatCreate(PETSC_COMM_WORLD,&A);
 21:   MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,2,2);
 22:   MatSetType(A,MATAIJ);
 23:   MatSetFromOptions(A);
 24:   MatSetUp(A);

 26:   i = 0; j = 0; v = 2.0;
 27:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
 28:   i = 0; j = 1; v = 3.0 + 4.0*PETSC_i;
 29:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
 30:   i = 1; j = 0; v = 5.0 + 6.0*PETSC_i;
 31:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
 32:   i = 1; j = 1; v = 7.0 + 8.0*PETSC_i;
 33:   MatSetValues(A,1,&i,1,&j,&v,INSERT_VALUES);
 34:   MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
 35:   MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);

 37:   /* Create vectors */
 38:   VecCreate(PETSC_COMM_WORLD,&y);
 39:   VecSetSizes(y,PETSC_DECIDE,2);
 40:   VecSetFromOptions(y);
 41:   VecDuplicate(y,&ys);
 42:   VecDuplicate(y,&x);

 44:   i = 0; v = 10.0 + 11.0*PETSC_i;
 45:   VecSetValues(x,1,&i,&v,INSERT_VALUES);
 46:   i = 1; v = 100.0 + 120.0*PETSC_i;
 47:   VecSetValues(x,1,&i,&v,INSERT_VALUES);
 48:   VecAssemblyBegin(x);
 49:   VecAssemblyEnd(x);

 51:   MatMultHermitianTranspose(A,x,y);
 52:   VecView(y,PETSC_VIEWER_STDOUT_WORLD);
 53:   MatMultHermitianTransposeAdd(A,x,y,ys);
 54:   VecView(ys,PETSC_VIEWER_STDOUT_WORLD);
 55: 
 56:   MatDestroy(&A);

 58:   VecDestroy(&x);
 59:   VecDestroy(&y);
 60:   VecDestroy(&ys);
 61:   PetscFinalize();
 62:   return 0;
 63: }