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