DFVecGetComponentVectors

Extracts the component vectors from a larger multicomponent vector. We currently assume that all components vectors are of equal length.

Synopsis

int DFVecGetComponentVectors(DFVec v,int *ncomp,DFVec **vcomp)

Input Parameter

v -the DF vector

Output Parameters

ncomp - number of component vectors
vcomp - array of component vectors

See Also

DFVecCreate()
C@*/ int DFVecGetComponentVectors(DFVec v,int *ncomp,DFVec **vcomp) { int ierr, i, gsize, lsize, nc; Vec v1, *vsub; VecScatter vsctx; VecType type; IS newis, is; DF df;

PetscFunctionBegin; PetscValidHeaderSpecific(v,VEC_COOKIE); ierr = DFVecGetDFShell(v,&df); CHKERRQ(ierr); PLogEventBegin(DFVec_GetComponentVectors,v,0,0,0); *ncomp = nc = df->nc; ierr = VecGetSize(v,&gsize); CHKERRQ(ierr); ierr = VecGetLocalSize(v,&lsize); CHKERRQ(ierr); if (gsize%nc || lsize%nc) /* assume same length for each subvector */ SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,0,"invalid number of components"); gsize /= nc; lsize /= nc; ierr = VecGetType(v,&type,PETSC_NULL); CHKERRQ(ierr); if (type == VECSEQ) { ierr = VecCreateSeq(PETSC_COMM_SELF,gsize,&v1); CHKERRQ(ierr); } else if (type == VECMPI) { ierr = VecCreateMPI(df->comm,lsize,gsize,&v1); CHKERRQ(ierr); } else SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,0,"vector type not supported"); PLogObjectParent(df,v1); ierr = VecDuplicateVecs(v1,df->nc,&vsub); CHKERRQ(ierr); PLogObjectParents(df,df->nc,vsub); ierr = VecDestroy(v1); CHKERRQ(ierr); if (nc == 1) { ierr = VecCopy(v,vsub[0]); CHKERRQ(ierr); } else { if (df->order != ORDER_1 && df->order != ORDER_2) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,0,"Ordering not supported."); ierr = ISCreateStride(df->comm,gsize,0,1,&newis); CHKERRQ(ierr); PLogObjectParent(df,newis); for (i=0; i<nc; i++) { if (df->order == ORDER_1) { ierr = ISCreateStride(df->comm,gsize,i,nc,&is); CHKERRQ(ierr); } else if (df->order == ORDER_2) { ierr = ISCreateStride(df->comm,gsize,i*gsize,1,&is); CHKERRQ(ierr); } PLogObjectParent(df,is); ierr = VecScatterCreate(v,is,vsub[i],newis,&vsctx); CHKERRQ(ierr); PLogObjectParent(df,vsctx); ierr = VecScatterBegin(v,vsub[i],INSERT_VALUES,SCATTER_FORWARD,vsctx);CHKERRQ(ierr); ierr = VecScatterEnd(v,vsub[i],INSERT_VALUES,SCATTER_FORWARD,vsctx); CHKERRQ(ierr); ierr = VecScatterDestroy(vsctx); CHKERRQ(ierr); ierr = ISDestroy(is); CHKERRQ(ierr); } ierr = ISDestroy(newis); CHKERRQ(ierr); } *vcomp = vsub; PLogEventEnd(DFVec_GetComponentVectors,v,0,0,0); PetscFunctionReturn(0); }

/* #include "pinclude/pviewer.h" */ #undef __FUNC__#define __FUNC__ "DFVecView" /*@ DFVecView - Views a discrete function vector.

Input Parameters

v -the DF vector
viewer -an optional visualization context

Notes

DFVecView() supports the same viewers as VecView(). The only differenceis that for all multiprocessor cases, the output vector employs the sameordering that would have been used for the uniprocessor case.

The available visualization contexts include

VIEWER_STDOUT_SELF - standard output (default)
VIEWER_STDOUT_WORLD - synchronized standard output where only the first processor opens the file. All other processors send their data to the first processor to print.

The user can open alternative vistualization contexts with

ViewerFileOpenASCII() - Outputs vector to a specified file
ViewerFileOpenBinary() - Outputs vector in binary to a specified file; corresponding input uses VecLoad()
ViewerDrawOpenX() - Outputs vector to an X window display
ViewerMatlabOpen() - Outputs vector to Matlab viewer

Keywords

view, visualize, output, print, write, draw

See Also

DFShellGetInfo(), VecView()

Location: src/dfvec/interface/dfvec.c
Discrete Function Index
Table of Contents