Commits

BarryFSmith committed 50339e3 Merge

Merge branch 'barry/fix-complex-examples'

  • Participants
  • Parent commits ab20f83, b45d02c

Comments (0)

Files changed (9)

File include/petscoptions.h

 PETSC_EXTERN PetscErrorCode PetscOptionsGetScalar(const char[],const char[],PetscScalar *,PetscBool *);
 PETSC_EXTERN PetscErrorCode PetscOptionsGetIntArray(const char[],const char[],PetscInt[],PetscInt *,PetscBool *);
 PETSC_EXTERN PetscErrorCode PetscOptionsGetRealArray(const char[],const char[],PetscReal[],PetscInt *,PetscBool *);
+PETSC_EXTERN PetscErrorCode PetscOptionsGetScalarArray(const char[],const char[],PetscScalar[],PetscInt *,PetscBool *);
 PETSC_EXTERN PetscErrorCode PetscOptionsGetBoolArray(const char[],const char[],PetscBool [],PetscInt *,PetscBool *);
 PETSC_EXTERN PetscErrorCode PetscOptionsGetString(const char[],const char[],char[],size_t,PetscBool *);
 PETSC_EXTERN PetscErrorCode PetscOptionsGetStringArray(const char[],const char[],char*[],PetscInt*,PetscBool *);

File src/dm/examples/tests/ex15.c

   } else if (dim == 3) {
     ierr = DMDACreate3d(PETSC_COMM_WORLD,bx,by,bz,DMDA_STENCIL_BOX,M1,M1,M1,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,dof,s,NULL,NULL,NULL,&da_c);CHKERRQ(ierr);
     ierr = DMDACreate3d(PETSC_COMM_WORLD,bx,by,bz,DMDA_STENCIL_BOX,M2,M2,M2,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,dof,s,NULL,NULL,NULL,&da_f);CHKERRQ(ierr);
-  }
+  } else SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Dimension must be one, two, or three");
 
   ierr = DMCreateGlobalVector(da_c,&v_c);CHKERRQ(ierr);
   ierr = DMCreateGlobalVector(da_f,&v_f);CHKERRQ(ierr);

File src/dm/examples/tutorials/ex3.c

     ierr = DMDACreate2d(PETSC_COMM_WORLD,bx,by,stype,M,N,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&dac);CHKERRQ(ierr);
   } else if (dim == 3) {
     ierr = DMDACreate3d(PETSC_COMM_WORLD,bx,by,bz,stype,M,N,P,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,NULL,&dac);CHKERRQ(ierr);
-  }
+  } else SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"Dimension must be one, two, or three");
 
   ierr = DMRefine(dac,PETSC_COMM_WORLD,&daf);CHKERRQ(ierr);
 

File src/docs/website/documentation/changes/dev.html

 
       <h4>General:</h4>
       <ul>
+        <li>PETSc options of complex numbers must be passed as [+/-][realnumber][+/-]realnumberi with no spaces, you can no longer pass the real and complex part with a comma between them</li>
         <li>PetscSynchronizedFlush() takes an additional argument, the file pointer on rank 0</li>
         <li>PetscObjectStateQuery() is now corrected with PetscObjectStateGet()</li>
         <li>A new PetscObjectState typedef is used by interface; 64-bit int to prevent overflow.</li>

File src/ksp/ksp/examples/tutorials/makefile

 
 
 
-runex10_basic:
-	-@${MPIEXEC} -n 2 ./ex10 -f0 ${PETSC_DIR}/include/datafiles/matrices/spd-${PETSC_SCALAR_TYPE}-${PETSC_INDEX_SIZE}-${PETSC_SCALAR_SIZE} > ex10_1.tmp 2>&1; \
+runex10:
+	-@${MPIEXEC} -n 2 ./ex10 -f0 ${PETSC_DIR}/include/datafiles/matrices/spd-real-${PETSC_INDEX_SIZE}-${PETSC_SCALAR_SIZE} > ex10_1.tmp 2>&1; \
 	   if (${DIFF} output/ex10_1.out ex10_1.tmp) then true; \
 	   else echo ${PWD} ; echo "Possible problem with with ex10_1, diffs above \n========================================="; fi; \
 	   ${RM} -f ex10_1.tmp
 TESTEXAMPLES_C_X_MPIUNI      = ex1.PETSc runex1 runex1_2 runex1_3 ex1.rm ex2.PETSc runex2 runex2_3 ex2.rm \
                                  ex7.PETSc ex7.rm ex5.PETSc ex5.rm  ex9.PETSc runex9 ex9.rm \
                                  ex23.PETSc runex23 ex23.rm
-TESTEXAMPLES_C_COMPLEX	       = ex10.PETSc runex10 ex10.rm ex11.PETSc runex11 ex11.rm ex39.PETSc runex39 ex39.rm ex40.PETSc runex40 ex40.rm
+TESTEXAMPLES_C_COMPLEX	       = ex10.PETSc ex10.rm ex11.PETSc runex11 ex11.rm ex39.PETSc runex39 ex39.rm ex40.PETSc runex40 ex40.rm
 TESTEXAMPLES_DATAFILESPATH     = ex10.PETSc runex10_2 runex10_3 runex10_4 runex10_5 runex10_6 runex10_7 runex10_8 \
                                  runex10_9 runex10_10 runex10_19 runex10_22 runex10_23 runex10_24 runex10_25  runex10_ILU runex10_ILUBAIJ runex10_cg \
                                  runex10_cg_singlereduction runex10_seqaijcrl runex10_mpiaijcrl runex10_seqaijperm runex10_mpiaijperm ex10.rm

File src/mat/examples/tutorials/ex4.c

   /* Form the sum of all the local multiplies : this is work2 = U'*x = sum_{all processors} work1 */
   ierr = VecGetArray(work1,&w1);CHKERRQ(ierr);
   ierr = VecGetArray(work2,&w2);CHKERRQ(ierr);
-  ierr = MPI_Allreduce(w1,w2,nwork,MPI_DOUBLE,MPI_SUM,PETSC_COMM_WORLD);CHKERRQ(ierr);
+  ierr = MPI_Allreduce(w1,w2,nwork,MPIU_SCALAR,MPIU_SUM,PETSC_COMM_WORLD);CHKERRQ(ierr);
   ierr = VecRestoreArray(work1,&w1);CHKERRQ(ierr);
   ierr = VecRestoreArray(work2,&w2);CHKERRQ(ierr);
 

File src/sys/objects/options.c

 
 /* Define Feature test macros to make sure atoll is available (SVr4, POSIX.1-2001, 4.3BSD, C99), not in (C89 and POSIX.1-1996) */
 #define PETSC_DESIRE_FEATURE_TEST_MACROS
+#define PETSC_DESIRE_COMPLEX
 
 /*
    These routines simplify the use of command line, file options, etc., and are used to manipulate the options database.
 }
 
 #undef __FUNCT__
+#define __FUNCT__ "PetscOptionsStringToScalar"
+/*
+   Converts a string to PetscScalar value. Handles
+      [-][2].0
+      [-][2].0i
+      [-][2].0+/-2.0i
+
+*/
+PetscErrorCode  PetscOptionsStringToScalar(const char name[],PetscScalar *a)
+{
+  PetscErrorCode ierr;
+  size_t         len;
+
+  PetscFunctionBegin;
+  ierr = PetscStrlen(name,&len);CHKERRQ(ierr);
+  if (!len) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"character string of length zero has no numerical value");
+
+  if (name[0] == '+') name++;
+  if (name[0] == 'i') {
+#if defined(PETSC_USE_COMPLEX)
+    *a = PETSC_i;
+#else
+    SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Input string %s is imaginary but complex not supported ",name);
+#endif
+  } else {
+    PetscToken token;
+    char       *tvalue;
+    PetscBool  neg = PETSC_FALSE, negim = PETSC_FALSE;
+    PetscReal  re = 0.0,im = 0.0;
+
+    if (name[0] != '-' && name[0] != '.' && name[0] < '0' && name[0] > '9') SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Input string %s has no numeric value ",name);
+    if (name[0] == '-') {
+      neg = PETSC_TRUE;
+      name++;
+    }
+    if (name[0] == 'i') {
+#if defined(PETSC_USE_COMPLEX)
+      *a = -PETSC_i;
+#else
+     SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Input string %s is imaginary but complex not supported ",name);
+#endif
+      PetscFunctionReturn(0);
+    }
+
+    ierr = PetscTokenCreate(name,'+',&token);CHKERRQ(ierr);
+    ierr = PetscTokenFind(token,&tvalue);CHKERRQ(ierr);
+    if (!tvalue) {
+      ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
+      ierr = PetscTokenCreate(name,'-',&token);CHKERRQ(ierr);
+      ierr = PetscTokenFind(token,&tvalue);CHKERRQ(ierr);
+    }
+    if (tvalue) {
+      ierr = PetscOptionsStringToReal(tvalue,&re);CHKERRQ(ierr);
+      if (neg) re = -re;
+      ierr = PetscTokenFind(token,&tvalue);CHKERRQ(ierr);
+      if (!tvalue) {
+        *a = re;
+        PetscFunctionReturn(0);
+      }
+      ierr = PetscStrlen(tvalue,&len);CHKERRQ(ierr);
+      if (tvalue[len-1] != 'i') SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Input string %s has no numeric value ",name);
+      tvalue[len-1] = 0;
+      ierr = PetscOptionsStringToReal(tvalue,&im);CHKERRQ(ierr);
+      if (negim) im = -im;
+      ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
+    } else {
+      ierr = PetscStrstr(name,"i",&tvalue);CHKERRQ(ierr);
+      if (tvalue) {
+        tvalue[0] = 0;
+        ierr = PetscOptionsStringToReal(name,&im);CHKERRQ(ierr);
+      } else {
+        ierr = PetscOptionsStringToReal(name,&re);CHKERRQ(ierr);
+      }
+    }
+#if defined(PETSC_USE_COMPLEX)
+    *a = re + im*PETSC_i;
+#else
+    if (im != 0.0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Input string %s is complex but complex not supported ",name);
+    *a = re;
+#endif
+  }
+  PetscFunctionReturn(0);
+}
+
+#undef __FUNCT__
 #define __FUNCT__ "PetscOptionsStringToBool"
 /*
    PetscOptionsStringToBool - Converts string to PetscBool , handles cases like "yes", "no", "true", "false", "0", "1"
    Level: beginner
 
    Usage:
-   A complex number 2+3i can be specified as 2,3 at the command line.
-   or a number 2.0e-10 - 3.3e-20 i  can be specified as 2.0e-10,-3.3e-20
+   A complex number 2+3i must be specified with NO spaces
 
    Note: if the option is given but no value is provided then set is given the value PETSC_FALSE
 
 #if !defined(PETSC_USE_COMPLEX)
       ierr = PetscOptionsStringToReal(value,dvalue);CHKERRQ(ierr);
 #else
-      PetscReal  re=0.0,im=0.0;
-      PetscToken token;
-      char       *tvalue = 0;
-
-      ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
-      ierr = PetscTokenFind(token,&tvalue);CHKERRQ(ierr);
-      if (!tvalue) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"unknown string specified\n");
-      ierr = PetscOptionsStringToReal(tvalue,&re);CHKERRQ(ierr);
-      ierr = PetscTokenFind(token,&tvalue);CHKERRQ(ierr);
-      if (!tvalue) *dvalue = re; /* Unknown separator used. using only real value */
-      else {
-        ierr    = PetscOptionsStringToReal(tvalue,&im);CHKERRQ(ierr);
-        *dvalue = re + PETSC_i*im;
-      }
-      ierr = PetscTokenDestroy(&token);CHKERRQ(ierr);
+      ierr = PetscOptionsStringToScalar(value,dvalue);CHKERRQ(ierr);
 #endif
       if (set) *set = PETSC_TRUE;
     }
 -  nmax - maximum number of values to retrieve
 
    Output Parameters:
-+  dvalue - the double value to return
++  dvalue - the double values to return
 .  nmax - actual number of values retreived
 -  set - PETSC_TRUE if found, else PETSC_FALSE
 
 }
 
 #undef __FUNCT__
+#define __FUNCT__ "PetscOptionsGetScalarArray"
+/*@C
+   PetscOptionsGetScalarArray - Gets an array of scalars for a
+   particular option in the database.  The values must be separated with
+   commas with no intervening spaces.
+
+   Not Collective
+
+   Input Parameters:
++  pre - string to prepend to each name or NULL
+.  name - the option one is seeking
+-  nmax - maximum number of values to retrieve
+
+   Output Parameters:
++  dvalue - the scalar values to return
+.  nmax - actual number of values retreived
+-  set - PETSC_TRUE if found, else PETSC_FALSE
+
+   Level: beginner
+
+   Concepts: options database^array of doubles
+
+.seealso: PetscOptionsGetInt(), PetscOptionsHasName(),
+           PetscOptionsGetString(), PetscOptionsGetIntArray(), PetscOptionsBool(),
+          PetscOptionsName(), PetscOptionsBegin(), PetscOptionsEnd(), PetscOptionsHead(),
+          PetscOptionsStringArray(),PetscOptionsRealArray(), PetscOptionsScalar(),
+          PetscOptionsBoolGroupBegin(), PetscOptionsBoolGroup(), PetscOptionsBoolGroupEnd(),
+          PetscOptionsFList(), PetscOptionsEList()
+@*/
+PetscErrorCode  PetscOptionsGetScalarArray(const char pre[],const char name[],PetscScalar dvalue[],PetscInt *nmax,PetscBool  *set)
+{
+  char           *value;
+  PetscErrorCode ierr;
+  PetscInt       n = 0;
+  PetscBool      flag;
+  PetscToken     token;
+
+  PetscFunctionBegin;
+  PetscValidCharPointer(name,2);
+  PetscValidRealPointer(dvalue,3);
+  ierr = PetscOptionsFindPair_Private(pre,name,&value,&flag);CHKERRQ(ierr);
+  if (!flag) {
+    if (set) *set = PETSC_FALSE;
+    *nmax = 0;
+    PetscFunctionReturn(0);
+  }
+  if (!value) {
+    if (set) *set = PETSC_TRUE;
+    *nmax = 0;
+    PetscFunctionReturn(0);
+  }
+
+  if (set) *set = PETSC_TRUE;
+
+  ierr = PetscTokenCreate(value,',',&token);CHKERRQ(ierr);
+  ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
+  while (n < *nmax) {
+    if (!value) break;
+    ierr = PetscOptionsStringToScalar(value,dvalue++);CHKERRQ(ierr);
+    ierr = PetscTokenFind(token,&value);CHKERRQ(ierr);
+    n++;
+  }
+  ierr  = PetscTokenDestroy(&token);CHKERRQ(ierr);
+  *nmax = n;
+  PetscFunctionReturn(0);
+}
+
+#undef __FUNCT__
 #define __FUNCT__ "PetscOptionsGetIntArray"
 /*@C
    PetscOptionsGetIntArray - Gets an array of integer values for a particular

File src/ts/examples/tutorials/ex31.c

   PetscErrorCode ierr;
   PetscScalar    *y;
   PetscInt       row = 0,col = 0;
-  PetscReal      value = a - 1.0;
+  PetscScalar    value = a - 1.0;
 
   PetscFunctionBegin;
   ierr = VecGetArray(Y,&y);CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscScalar    *y;
   PetscInt       row = 0,col = 0;
-  PetscReal      value;
+  PetscScalar    value;
 
   PetscFunctionBegin;
   ierr = VecGetArray(Y,&y);CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscScalar    *y;
   PetscInt       row = 0,col = 0;
-  PetscReal      value = a - PetscCosReal(t);
+  PetscScalar    value = a - PetscCosReal(t);
 
   PetscFunctionBegin;
   ierr = VecGetArray(Y,&y);CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscScalar    *y;
   PetscInt       row = 0,col = 0;
-  PetscReal      value;
+  PetscScalar    value;
 
   PetscFunctionBegin;
   ierr = VecGetArray(Y,&y);CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscScalar    *y;
   PetscInt       row = 0,col = 0;
-  PetscReal      value;
+  PetscScalar    value;
 
   PetscFunctionBegin;
   ierr = VecGetArray(Y,&y);CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscScalar    *y;
   PetscInt       row[2] = {0,1};
-  PetscReal      value[2][2];
+  PetscScalar    value[2][2];
 
   PetscFunctionBegin;
   ierr = VecGetArray(Y,&y);CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscScalar    *y;
   PetscInt       row[3] = {0,1,2};
-  PetscReal      value[3][3];
+  PetscScalar    value[3][3];
 
   PetscFunctionBegin;
   ierr = VecGetArray(Y,&y);CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscScalar    *y;
   PetscInt       row[3] = {0,1,2};
-  PetscReal      value[3][3];
+  PetscScalar    value[3][3];
 
   PetscFunctionBegin;
   ierr = VecGetArray(Y,&y);CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscScalar    *y;
   PetscInt       row[3] = {0,1,2};
-  PetscReal      value[3][3],fac,fac2;
+  PetscScalar    value[3][3],fac,fac2;
 
   PetscFunctionBegin;
   ierr = VecGetArray(Y,&y);CHKERRQ(ierr);
   PetscErrorCode ierr;
   PetscScalar    *y;
   PetscInt       row[3] = {0,1,2};
-  PetscReal      value[3][3];
+  PetscScalar    value[3][3];
 
   PetscFunctionBegin;
   ierr = VecGetArray(Y,&y);CHKERRQ(ierr);
   PetscErrorCode  ierr;
   PetscScalar    *y;
   PetscInt        N,i,col[2];
-  PetscReal       value[2];
+  PetscScalar     value[2];
 
   PetscFunctionBegin;
   ierr = VecGetSize (Y,&N);CHKERRQ(ierr);
   PetscErrorCode  ierr;
   PetscScalar    *y;
   PetscInt        N,i,col[2];
-  PetscReal       value[2];
+  PetscScalar     value[2];
 
   PetscFunctionBegin;
   ierr = VecGetSize (Y,&N);CHKERRQ(ierr);
     IFunction   = IFunction_Hull1972C34;
     IJacobian   = IJacobian_Hull1972C34;
   }
-  ierr = PetscOptionsGetRealArray(PETSC_NULL,"-yinit",y,&N,&flg);CHKERRQ(ierr);
+  ierr = PetscOptionsGetScalarArray(PETSC_NULL,"-yinit",y,&N,&flg);CHKERRQ(ierr);
   if ((N != GetSize(s)) && flg) {
     printf("Error: number of initial values %d does not match problem size %d.\n",N,GetSize(s));
   }
   PetscErrorCode  ierr;                       /* Error code                                           */
   char            ptype[256] = "hull1972a1";  /* Problem specification                                */
   PetscInt        n_refine   = 1;             /* Number of refinement levels for convergence analysis */
-  PetscReal       refine_fac = 2.0;           /* Refinement factor for dt                             */
+  PetscReal     refine_fac = 2.0;           /* Refinement factor for dt                             */
   PetscReal       dt_initial = 0.01;          /* Initial default value of dt                          */
   PetscReal       dt;
   PetscReal       tfinal     = 20.0;          /* Final time for the time-integration                  */

File src/ts/examples/tutorials/makefile

                             ex17.PETSc runex17 runex17_2 ex17.rm \
                             ex20.PETSc ex20.rm \
                             ex22.PETSc runex22 runex22_2 runex22_3 ex22.rm \
-                            ex25.PETSc runex25 ex25.rm ex26.PETSc runex26 runex26_2 runex26_3 runex26_4 ex26.rm \
-                            ex31.PETsc ex31.rm
-TESTEXAMPLES_C_NOCOMPLEX  = ex9.PETSc runex9 runex9_2 runex9_3 ex9.rm
+                            ex25.PETSc runex25 ex25.rm \
+                            ex31.PETSc ex31.rm
+TESTEXAMPLES_C_NOCOMPLEX  = ex9.PETSc runex9 runex9_2 runex9_3 ex9.rm ex26.PETSc runex26 runex26_2 runex26_3 runex26_4 ex26.rm
 TESTEXAMPLES_C_X	  =
 TESTEXAMPLES_FORTRAN	  = ex1f.PETSc runex1f ex1f.rm ex2f.PETSc runex2f ex2f.rm ex22f.PETSc ex22f.rm # ex22f_mf.PETSc ex22f_mf.rm
 TESTEXAMPLES_C_X_MPIUNI =