Actual source code: ex14.c

petsc-3.13.6 2020-09-29
Report Typos and Errors

  2: static char help[] = "Tests PetscOptionsGetScalar(), PetscOptionsScalarArray() for complex numbers\n";

  4:  #include <petscsys.h>

  6: int main(int argc,char **argv)
  7: {
  8:   PetscInt    ierr,n,i;
  9:   PetscScalar a,array[10];
 10:   PetscReal   rarray[10];

 12:   PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr;
 13:   PetscOptionsGetScalar(NULL,NULL,"-a",&a,NULL);
 14:   PetscPrintf(PETSC_COMM_SELF,"Scalar a = %g + %gi\n",(double)PetscRealPart(a),(double)PetscImaginaryPart(a));

 16:   PetscOptionsBegin(PETSC_COMM_WORLD,NULL,"test options",NULL);
 17:   n = 10; /* max num of input values */
 18:   PetscOptionsRealArray("-rarray", "Input a real array", "ex14.c", rarray, &n, NULL);
 19:   if (n) {
 20:     PetscPrintf(PETSC_COMM_SELF,"Real rarray of length %d\n",n);
 21:     for (i=0; i<n; i++){
 22:       PetscPrintf(PETSC_COMM_SELF," %g,\n",rarray[i]);
 23:     }
 24:   }

 26:   n = 10; /* max num of input values */
 27:   PetscOptionsScalarArray("-array", "Input a scalar array", "ex14.c", array, &n, NULL);
 28:   if (n) {
 29:     PetscPrintf(PETSC_COMM_SELF,"Scalar rarray of length %d\n",n);
 30:     for (i=0; i<n; i++){
 31:       if (PetscImaginaryPart(array[i]) < 0.0) {
 32:         PetscPrintf(PETSC_COMM_SELF," %g - %gi\n",(double)PetscRealPart(array[i]),(double)PetscAbsReal(PetscImaginaryPart(array[i])));
 33:       } else {
 34:         PetscPrintf(PETSC_COMM_SELF," %g + %gi\n",(double)PetscRealPart(array[i]),(double)PetscImaginaryPart(array[i]));
 35:       }
 36:     }
 37:   }
 38:   PetscOptionsEnd();
 39:   PetscFinalize();
 40:   return ierr;
 41: }



 45: /*TEST

 47:    test:
 48:       requires: complex
 49:       args: -array 1.0,-2-3i,4.5+6.2i,4.5,6.8+4i,i,-i,-1.2i -rarray 1,2,3 -a 1.5+2.1i

 51: TEST*/