Exemplo n.º 1
0
Arquivo: block.c Projeto: lw4992/petsc
PetscErrorCode ISSort_Block(IS is)
{
  IS_Block       *sub = (IS_Block*)is->data;
  PetscInt       bs, n;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  if (sub->sorted) PetscFunctionReturn(0);
  ierr = PetscLayoutGetBlockSize(is->map, &bs);CHKERRQ(ierr);
  ierr = PetscLayoutGetLocalSize(is->map, &n);CHKERRQ(ierr);
  ierr = PetscSortInt(n/bs,sub->idx);CHKERRQ(ierr);
  sub->sorted = PETSC_TRUE;
  PetscFunctionReturn(0);
}
Exemplo n.º 2
0
Arquivo: block.c Projeto: lw4992/petsc
PetscErrorCode ISRestoreIndices_Block(IS is,const PetscInt *idx[])
{
  IS_Block       *sub = (IS_Block*)is->data;
  PetscInt       bs;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  ierr = PetscLayoutGetBlockSize(is->map, &bs);CHKERRQ(ierr);
  if (bs != 1) {
    ierr = PetscFree(*(void**)idx);CHKERRQ(ierr);
  } else {
    if (*idx != sub->idx) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Must restore with value from ISGetIndices()");
  }
  PetscFunctionReturn(0);
}
Exemplo n.º 3
0
Arquivo: block.c Projeto: petsc/petsc
static PetscErrorCode ISOnComm_Block(IS is,MPI_Comm comm,PetscCopyMode mode,IS *newis)
{
    PetscErrorCode ierr;
    IS_Block       *sub = (IS_Block*)is->data;
    PetscInt       bs, n;

    PetscFunctionBegin;
    if (mode == PETSC_OWN_POINTER) SETERRQ(comm,PETSC_ERR_ARG_WRONG,"Cannot use PETSC_OWN_POINTER");
    ierr = PetscLayoutGetBlockSize(is->map, &bs);
    CHKERRQ(ierr);
    ierr = PetscLayoutGetLocalSize(is->map, &n);
    CHKERRQ(ierr);
    ierr = ISCreateBlock(comm,bs,n/bs,sub->idx,mode,newis);
    CHKERRQ(ierr);
    PetscFunctionReturn(0);
}
Exemplo n.º 4
0
Arquivo: block.c Projeto: petsc/petsc
static PetscErrorCode ISDuplicate_Block(IS is,IS *newIS)
{
    PetscErrorCode ierr;
    IS_Block       *sub = (IS_Block*)is->data;
    PetscInt        bs, n;

    PetscFunctionBegin;
    ierr = PetscLayoutGetBlockSize(is->map, &bs);
    CHKERRQ(ierr);
    ierr = PetscLayoutGetLocalSize(is->map, &n);
    CHKERRQ(ierr);
    n   /= bs;
    ierr = ISCreateBlock(PetscObjectComm((PetscObject)is),bs,n,sub->idx,PETSC_COPY_VALUES,newIS);
    CHKERRQ(ierr);
    PetscFunctionReturn(0);
}
Exemplo n.º 5
0
static PetscErrorCode ISView_Block(IS is, PetscViewer viewer)
{
  IS_Block       *sub = (IS_Block*)is->data;
  PetscErrorCode ierr;
  PetscInt       i,bs,n,*idx = sub->idx;
  PetscBool      iascii;

  PetscFunctionBegin;
  ierr = PetscLayoutGetBlockSize(is->map, &bs);CHKERRQ(ierr);
  ierr = PetscLayoutGetLocalSize(is->map, &n);CHKERRQ(ierr);
  n   /= bs;
  ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr);
  if (iascii) {
    PetscViewerFormat fmt;

    ierr = PetscViewerGetFormat(viewer,&fmt);CHKERRQ(ierr);
    if (fmt == PETSC_VIEWER_ASCII_MATLAB) {
      IS             ist;
      const char     *name;
      const PetscInt *idx;
      PetscInt       n;

      ierr = PetscObjectGetName((PetscObject)is,&name);CHKERRQ(ierr);
      ierr = ISGetLocalSize(is,&n);CHKERRQ(ierr);
      ierr = ISGetIndices(is,&idx);CHKERRQ(ierr);
      ierr = ISCreateGeneral(PetscObjectComm((PetscObject)is),n,idx,PETSC_USE_POINTER,&ist);CHKERRQ(ierr);
      ierr = PetscObjectSetName((PetscObject)ist,name);CHKERRQ(ierr);
      ierr = ISView(ist,viewer);CHKERRQ(ierr);
      ierr = ISDestroy(&ist);CHKERRQ(ierr);
      ierr = ISRestoreIndices(is,&idx);CHKERRQ(ierr);
    } else {
      ierr = PetscViewerASCIIPushSynchronized(viewer);CHKERRQ(ierr);
      if (is->isperm) {
        ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block Index set is permutation\n");CHKERRQ(ierr);
      }
      ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block size %D\n",bs);CHKERRQ(ierr);
      ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Number of block indices in set %D\n",n);CHKERRQ(ierr);
      ierr = PetscViewerASCIISynchronizedPrintf(viewer,"The first indices of each block are\n");CHKERRQ(ierr);
      for (i=0; i<n; i++) {
        ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block %D Index %D\n",i,idx[i]);CHKERRQ(ierr);
      }
      ierr = PetscViewerFlush(viewer);CHKERRQ(ierr);
      ierr = PetscViewerASCIIPopSynchronized(viewer);CHKERRQ(ierr);
    }
  }
  PetscFunctionReturn(0);
}
Exemplo n.º 6
0
Arquivo: block.c Projeto: lw4992/petsc
PetscErrorCode ISInvertPermutation_Block(IS is,PetscInt nlocal,IS *isout)
{
  IS_Block       *sub = (IS_Block*)is->data;
  PetscInt       i,*ii,bs,n,*idx = sub->idx;
  PetscMPIInt    size;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  ierr = MPI_Comm_size(PetscObjectComm((PetscObject)is),&size);CHKERRQ(ierr);
  ierr = PetscLayoutGetBlockSize(is->map, &bs);CHKERRQ(ierr);
  ierr = PetscLayoutGetLocalSize(is->map, &n);CHKERRQ(ierr);
  n   /= bs;
  if (size == 1) {
    ierr = PetscMalloc1(n,&ii);CHKERRQ(ierr);
    for (i=0; i<n; i++) ii[idx[i]] = i;
    ierr = ISCreateBlock(PETSC_COMM_SELF,bs,n,ii,PETSC_OWN_POINTER,isout);CHKERRQ(ierr);
    ierr = ISSetPermutation(*isout);CHKERRQ(ierr);
  } else SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SUP,"No inversion written yet for block IS");
  PetscFunctionReturn(0);
}
Exemplo n.º 7
0
Arquivo: block.c Projeto: petsc/petsc
static PetscErrorCode ISSortRemoveDups_Block(IS is)
{
    IS_Block       *sub = (IS_Block*)is->data;
    PetscInt       bs, n, nb;
    PetscErrorCode ierr;

    PetscFunctionBegin;
    if (sub->sorted) PetscFunctionReturn(0);
    ierr = PetscLayoutGetBlockSize(is->map, &bs);
    CHKERRQ(ierr);
    ierr = PetscLayoutGetLocalSize(is->map, &n);
    CHKERRQ(ierr);
    nb   = n/bs;
    ierr = PetscSortRemoveDupsInt(&nb,sub->idx);
    CHKERRQ(ierr);
    ierr = PetscLayoutSetLocalSize(is->map, nb*bs);
    CHKERRQ(ierr);
    sub->sorted = PETSC_TRUE;
    PetscFunctionReturn(0);
}
Exemplo n.º 8
0
Arquivo: block.c Projeto: lw4992/petsc
PetscErrorCode ISIdentity_Block(IS is,PetscBool  *ident)
{
  IS_Block      *is_block = (IS_Block*)is->data;
  PetscInt       i,bs,n,*idx = is_block->idx;
  PetscErrorCode ierr;

  PetscFunctionBegin;
  ierr = PetscLayoutGetBlockSize(is->map, &bs);CHKERRQ(ierr);
  ierr = PetscLayoutGetLocalSize(is->map, &n);CHKERRQ(ierr);
  n   /= bs;
  is->isidentity = PETSC_TRUE;
  *ident         = PETSC_TRUE;
  for (i=0; i<n; i++) {
    if (idx[i] != bs*i) {
      is->isidentity = PETSC_FALSE;
      *ident         = PETSC_FALSE;
      PetscFunctionReturn(0);
    }
  }
  PetscFunctionReturn(0);
}
Exemplo n.º 9
0
Arquivo: block.c Projeto: lw4992/petsc
PetscErrorCode ISGetIndices_Block(IS in,const PetscInt *idx[])
{
  IS_Block       *sub = (IS_Block*)in->data;
  PetscErrorCode ierr;
  PetscInt       i,j,k,bs,n,*ii,*jj;

  PetscFunctionBegin;
  ierr = PetscLayoutGetBlockSize(in->map, &bs);CHKERRQ(ierr);
  ierr = PetscLayoutGetLocalSize(in->map, &n);CHKERRQ(ierr);
  n   /= bs;
  if (bs == 1) *idx = sub->idx;
  else {
    ierr = PetscMalloc1(bs*n,&jj);CHKERRQ(ierr);
    *idx = jj;
    k    = 0;
    ii   = sub->idx;
    for (i=0; i<n; i++)
      for (j=0; j<bs; j++)
        jj[k++] = bs*ii[i] + j;
  }
  PetscFunctionReturn(0);
}
Exemplo n.º 10
0
Arquivo: block.c Projeto: petsc/petsc
static PetscErrorCode ISView_Block(IS is, PetscViewer viewer)
{
    IS_Block       *sub = (IS_Block*)is->data;
    PetscErrorCode ierr;
    PetscInt       i,bs,n,*idx = sub->idx;
    PetscBool      iascii;

    PetscFunctionBegin;
    ierr = PetscLayoutGetBlockSize(is->map, &bs);
    CHKERRQ(ierr);
    ierr = PetscLayoutGetLocalSize(is->map, &n);
    CHKERRQ(ierr);
    n   /= bs;
    ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);
    CHKERRQ(ierr);
    if (iascii) {
        ierr = PetscViewerASCIIPushSynchronized(viewer);
        CHKERRQ(ierr);
        if (is->isperm) {
            ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block Index set is permutation\n");
            CHKERRQ(ierr);
        }
        ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block size %D\n",bs);
        CHKERRQ(ierr);
        ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Number of block indices in set %D\n",n);
        CHKERRQ(ierr);
        ierr = PetscViewerASCIISynchronizedPrintf(viewer,"The first indices of each block are\n");
        CHKERRQ(ierr);
        for (i=0; i<n; i++) {
            ierr = PetscViewerASCIISynchronizedPrintf(viewer,"Block %D Index %D\n",i,idx[i]);
            CHKERRQ(ierr);
        }
        ierr = PetscViewerFlush(viewer);
        CHKERRQ(ierr);
        ierr = PetscViewerASCIIPopSynchronized(viewer);
        CHKERRQ(ierr);
    }
    PetscFunctionReturn(0);
}
Exemplo n.º 11
0
Arquivo: block.c Projeto: petsc/petsc
static PetscErrorCode ISLocate_Block(IS is,PetscInt key,PetscInt *location)
{
    IS_Block       *sub = (IS_Block*)is->data;
    PetscInt       numIdx, i, bs, bkey, mkey;
    PetscErrorCode ierr;

    PetscFunctionBegin;
    ierr = PetscLayoutGetBlockSize(is->map,&bs);
    CHKERRQ(ierr);
    ierr = PetscLayoutGetSize(is->map,&numIdx);
    CHKERRQ(ierr);
    numIdx /= bs;
    bkey    = key / bs;
    mkey    = key % bs;
    if (mkey < 0) {
        bkey--;
        mkey += bs;
    }
    if (sub->sorted) {
        ierr = PetscFindInt(bkey,numIdx,sub->idx,location);
        CHKERRQ(ierr);
    } else {
        const PetscInt *idx = sub->idx;

        *location = -1;
        for (i = 0; i < numIdx; i++) {
            if (idx[i] == bkey) {
                *location = i;
                break;
            }
        }
    }
    if (*location >= 0) {
        *location = *location * bs + mkey;
    }
    PetscFunctionReturn(0);
}