Actual source code: strgen.c

  1: /*$Id: strgen.c,v 1.21 2001/03/23 23:21:08 balay Exp $*/

 3:  #include src/vec/is/impls/general/general.h

  5: EXTERN int ISDuplicate_General(IS,IS *);
  6: EXTERN int ISDestroy_General(IS);
  7: EXTERN int ISGetIndices_General(IS,int **);
  8: EXTERN int ISRestoreIndices_General(IS,int **);
  9: EXTERN int ISGetSize_General(IS,int *);
 10: EXTERN int ISGetLocalSize_General(IS,int *);
 11: EXTERN int ISInvertPermutation_General(IS,int,IS *);
 12: EXTERN int ISView_General(IS,PetscViewer);
 13: EXTERN int ISSort_General(IS);
 14: EXTERN int ISSorted_General(IS,PetscTruth*);

 16: static struct _ISOps myops = { ISGetSize_General,
 17:                                ISGetLocalSize_General,
 18:                                ISGetIndices_General,
 19:                                ISRestoreIndices_General,
 20:                                ISInvertPermutation_General,
 21:                                ISSort_General,
 22:                                ISSorted_General,
 23:                                ISDuplicate_General,
 24:                                ISDestroy_General,
 25:                                ISView_General};

 27: #undef __FUNCT__  
 29: /*@C
 30:    ISStrideToGeneral - Converts a stride index set to a general index set.

 32:    Collective on IS

 34:    Input Parameters:
 35: .    is - the index set

 37:    Level: advanced

 39:    Concepts: index sets^converting
 40:    Concepts: stride^converting index sets

 42: .seealso: ISCreateStride(), ISCreateBlock(), ISCreateGeneral()
 43: @*/
 44: int ISStrideToGeneral(IS inis)
 45: {
 46:   int        ierr,step;
 47:   IS_General *sub;
 48:   PetscTruth stride,flg;

 51:   ISStride(inis,&stride);
 52:   if (!stride) SETERRQ(1,"Can only convert stride index sets");

 54:   PetscNew(IS_General,&sub);
 55:   PetscLogObjectMemory(inis,sizeof(IS_General));
 56: 
 57:   ierr   = ISGetIndices(inis,&sub->idx);
 58:   /* Note: we never restore the indices, since we need to keep the copy generated */
 59:   ierr   = ISGetLocalSize(inis,&sub->n);

 61:   ISStrideGetInfo(inis,PETSC_NULL,&step);
 62:   if (step > 0) sub->sorted = PETSC_TRUE; else sub->sorted = PETSC_FALSE;

 64:   /* Remove the old stride data set */
 65:   PetscFree(inis->data);

 67:   inis->type         = IS_GENERAL;
 68:   inis->data         = (void*)sub;
 69:   inis->isperm       = PETSC_FALSE;
 70:   PetscMemcpy(inis->ops,&myops,sizeof(myops));
 71:   PetscOptionsHasName(PETSC_NULL,"-is_view",&flg);
 72:   if (flg) {
 73:     ISView(inis,PETSC_VIEWER_STDOUT_(inis->comm));
 74:   }
 75:   return(0);
 76: }