1 #ifdef PETSC_RCS_HEADER 2 static char vcid[] = "$Id: pcnull.c,v 1.21 1999/01/31 21:14:38 curfman Exp balay $"; 3 #endif 4 /* 5 Routines to project vectors out of null spaces. 6 */ 7 8 #include "petsc.h" 9 #include "src/sles/pc/pcimpl.h" /*I "pc.h" I*/ 10 #include "src/sys/nreg.h" 11 #include "sys.h" 12 13 14 #undef __FUNC__ 15 #define __FUNC__ "PCNullSpaceCreate" 16 /*@C 17 PCNullSpaceCreate - Creates a data-structure used to project vectors 18 out of null spaces. 19 20 Collective on MPI_Comm 21 22 Input Parameters: 23 + comm - the MPI communicator associated with the object 24 . has_cnst - PETSC_TRUE if the null space contains the constant vector; otherwise PETSC_FALSE 25 . n - number of vectors (excluding constant vector) in null space 26 - vecs - the vectors that span the null space (excluding the constant vector); 27 these vectors must be orthonormal 28 29 Output Parameter: 30 . SP - the null space context 31 32 Level: advanced 33 34 .keywords: PC, null space, create 35 36 .seealso: PCNullSpaceDestroy(), PCNullSpaceRemove() 37 @*/ 38 int PCNullSpaceCreate(MPI_Comm comm, int has_cnst, int n, Vec *vecs,PCNullSpace *SP) 39 { 40 PCNullSpace sp; 41 42 PetscFunctionBegin; 43 PetscHeaderCreate(sp,_p_PCNullSpace,int,PCNULLSPACE_COOKIE,0,"PCNullSpace",comm,PCNullSpaceDestroy,0); 44 PLogObjectCreate(sp); 45 PLogObjectMemory(sp,sizeof(struct _p_PCNullSpace)); 46 47 sp->has_cnst = has_cnst; 48 sp->n = n; 49 sp->vecs = vecs; 50 51 *SP = sp; 52 PetscFunctionReturn(0); 53 } 54 55 #undef __FUNC__ 56 #define __FUNC__ "PCNullSpaceDestroy" 57 /*@ 58 PCNullSpaceDestroy - Destroys a data-structure used to project vectors 59 out of null spaces. 60 61 Collective on PCNullSpace 62 63 Input Parameter: 64 . sp - the null space context to be destroyed 65 66 Level: advanced 67 68 .keywords: PC, null space, destroy 69 70 .seealso: PCNullSpaceDestroy(), PCNullSpaceRemove() 71 @*/ 72 int PCNullSpaceDestroy(PCNullSpace sp) 73 { 74 PetscFunctionBegin; 75 PLogObjectDestroy(sp); 76 PetscHeaderDestroy(sp); 77 PetscFunctionReturn(0); 78 } 79 80 #undef __FUNC__ 81 #define __FUNC__ "PCNullSpaceRemove" 82 /*@ 83 PCNullSpaceRemove - Removes all the components of a null space from a vector. 84 85 Collective on PCNullSpace 86 87 Input Parameters: 88 + sp - the null space context 89 - vec - the vector from which the null space is to be removed 90 91 Level: advanced 92 93 .keywords: PC, null space, remove 94 95 .seealso: PCNullSpaceCreate(), PCNullSpaceDestroy() 96 @*/ 97 int PCNullSpaceRemove(PCNullSpace sp,Vec vec) 98 { 99 Scalar sum; 100 int j, n = sp->n, N,ierr; 101 102 PetscFunctionBegin; 103 if (sp->has_cnst) { 104 ierr = VecSum(vec,&sum); CHKERRQ(ierr); 105 ierr = VecGetSize(vec,&N); CHKERRQ(ierr); 106 sum = sum/(-1.0*N); 107 ierr = VecShift(&sum,vec); CHKERRQ(ierr); 108 } 109 110 for ( j=0; j<n; j++ ) { 111 ierr = VecDot(vec,sp->vecs[j],&sum);CHKERRQ(ierr); 112 sum = -sum; 113 ierr = VecAYPX(&sum,sp->vecs[j],vec); CHKERRQ(ierr); 114 } 115 116 PetscFunctionReturn(0); 117 } 118