Actual source code: const.c

      1: #define PETSCVEC_DLL

     3:  #include src/vec/pf/pfimpl.h

      7: PetscErrorCode PFApply_Constant(void *value,PetscInt n,PetscScalar *x,PetscScalar *y)
      8: {
      9:   PetscInt    i;
     10:   PetscScalar v = ((PetscScalar*)value)[0];

     13:   n *= (PetscInt) PetscRealPart(((PetscScalar*)value)[1]);
     14:   for (i=0; i<n; i++) {
     15:     y[i] = v;
     16:   }
     17:   return(0);
     18: }

     22: PetscErrorCode PFApplyVec_Constant(void *value,Vec x,Vec y)
     23: {
     26:   VecSet(y,*((PetscScalar*)value));
     27:   return(0);
     28: }
     31: PetscErrorCode PFView_Constant(void *value,PetscViewer viewer)
     32: {
     34:   PetscTruth     iascii;

     37:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
     38:   if (iascii) {
     39: #if !defined(PETSC_USE_COMPLEX)
     40:     PetscViewerASCIIPrintf(viewer,"Constant = %g\n",*(double*)value);
     41: #else
     42:     PetscViewerASCIIPrintf(viewer,"Constant = %g + %gi\n",PetscRealPart(*(PetscScalar*)value),PetscImaginaryPart(*(PetscScalar*)value));
     43: #endif
     44:   }
     45:   return(0);
     46: }
     49: PetscErrorCode PFDestroy_Constant(void *value)
     50: {
     53:   PetscFree(value);
     54:   return(0);
     55: }

     59: PetscErrorCode PFSetFromOptions_Constant(PF pf)
     60: {
     62:   PetscScalar    *value = (PetscScalar *)pf->data;

     65:   PetscOptionsHead("Constant function options");
     66:     PetscOptionsScalar("-pf_constant","The constant value","None",*value,value,0);
     67:   PetscOptionsTail();
     68:   return(0);
     69: }

     74: PetscErrorCode PETSCVEC_DLLEXPORT PFCreate_Constant(PF pf,void *value)
     75: {
     77:   PetscScalar    *loc;

     80:   PetscMalloc(2*sizeof(PetscScalar),&loc);
     81:   if (value) loc[0] = *(PetscScalar*)value; else loc[0] = 0.0;
     82:   loc[1] = pf->dimout;
     83:   PFSet(pf,PFApply_Constant,PFApplyVec_Constant,PFView_Constant,PFDestroy_Constant,loc);

     85:   pf->ops->setfromoptions = PFSetFromOptions_Constant;
     86:   return(0);
     87: }

     95: PetscErrorCode PETSCVEC_DLLEXPORT PFCreate_Quick(PF pf,void *function)
     96: {

    100:   PFSet(pf,(FCN)function,0,0,0,0);
    101:   return(0);
    102: }

    105: /* -------------------------------------------------------------------------------------------------------------------*/
    108: PetscErrorCode PFApply_Identity(void *value,PetscInt n,PetscScalar *x,PetscScalar *y)
    109: {
    110:   PetscInt    i;

    113:   n *= *(PetscInt*)value;
    114:   for (i=0; i<n; i++) {
    115:     y[i] = x[i];
    116:   }
    117:   return(0);
    118: }

    122: PetscErrorCode PFApplyVec_Identity(void *value,Vec x,Vec y)
    123: {
    126:   VecCopy(x,y);
    127:   return(0);
    128: }
    131: PetscErrorCode PFView_Identity(void *value,PetscViewer viewer)
    132: {
    134:   PetscTruth     iascii;

    137:   PetscTypeCompare((PetscObject)viewer,PETSC_VIEWER_ASCII,&iascii);
    138:   if (iascii) {
    139:     PetscViewerASCIIPrintf(viewer,"Identity function\n");
    140:   }
    141:   return(0);
    142: }
    145: PetscErrorCode PFDestroy_Identity(void *value)
    146: {
    149:   PetscFree(value);
    150:   return(0);
    151: }

    156: PetscErrorCode PETSCVEC_DLLEXPORT PFCreate_Identity(PF pf,void *value)
    157: {
    159:   PetscInt       *loc;

    162:   if (pf->dimout != pf->dimin) {
    163:     SETERRQ2(PETSC_ERR_ARG_SIZ,"Input dimension must match output dimension for Identity function, dimin = %D dimout = %D\n",pf->dimin,pf->dimout);
    164:   }
    165:   PetscMalloc(sizeof(PetscInt),&loc);
    166:   loc[0] = pf->dimout;
    167:   PFSet(pf,PFApply_Identity,PFApplyVec_Identity,PFView_Identity,PFDestroy_Identity,loc);
    168:   return(0);
    169: }