1dba47a55SKris Buschelman 2b45d2f2cSJed Brown #include <petsc-private/pcimpl.h> /*I "petscpc.h" I*/ 31e25c274SJed Brown #include <petscdm.h> 40971522cSBarry Smith 5443836d0SMatthew G Knepley /* 6443836d0SMatthew G Knepley There is a nice discussion of block preconditioners in 7443836d0SMatthew G Knepley 81997fe2eSSatish Balay [El08] A taxonomy and comparison of parallel block multi-level preconditioners for the incompressible Navier-Stokes equations 9443836d0SMatthew G Knepley Howard Elman, V.E. Howle, John Shadid, Robert Shuttleworth, Ray Tuminaro, Journal of Computational Physics 227 (2008) 1790--1808 101b8e4c5fSJed Brown http://chess.cs.umd.edu/~elman/papers/tax.pdf 11443836d0SMatthew G Knepley */ 12443836d0SMatthew G Knepley 13e87fab1bSBarry Smith const char *const PCFieldSplitSchurPreTypes[] = {"SELF","A11","USER","PCFieldSplitSchurPreType","PC_FIELDSPLIT_SCHUR_PRE_",0}; 14c9c6ffaaSJed Brown const char *const PCFieldSplitSchurFactTypes[] = {"DIAG","LOWER","UPPER","FULL","PCFieldSplitSchurFactType","PC_FIELDSPLIT_SCHUR_FACT_",0}; 15c5d2311dSJed Brown 160971522cSBarry Smith typedef struct _PC_FieldSplitLink *PC_FieldSplitLink; 170971522cSBarry Smith struct _PC_FieldSplitLink { 1869a612a9SBarry Smith KSP ksp; 19443836d0SMatthew G Knepley Vec x,y,z; 20db4c96c1SJed Brown char *splitname; 210971522cSBarry Smith PetscInt nfields; 225d4c12cdSJungho Lee PetscInt *fields,*fields_col; 231b9fc7fcSBarry Smith VecScatter sctx; 245d4c12cdSJungho Lee IS is,is_col; 2551f519a2SBarry Smith PC_FieldSplitLink next,previous; 260971522cSBarry Smith }; 270971522cSBarry Smith 280971522cSBarry Smith typedef struct { 2968dd23aaSBarry Smith PCCompositeType type; 30ace3abfcSBarry Smith PetscBool defaultsplit; /* Flag for a system with a set of 'k' scalar fields with the same layout (and bs = k) */ 31ace3abfcSBarry Smith PetscBool splitdefined; /* Flag is set after the splits have been defined, to prevent more splits from being added */ 3230ad9308SMatthew Knepley PetscInt bs; /* Block size for IS and Mat structures */ 3330ad9308SMatthew Knepley PetscInt nsplits; /* Number of field divisions defined */ 3479416396SBarry Smith Vec *x,*y,w1,w2; 35519d70e2SJed Brown Mat *mat; /* The diagonal block for each split */ 36519d70e2SJed Brown Mat *pmat; /* The preconditioning diagonal block for each split */ 3730ad9308SMatthew Knepley Mat *Afield; /* The rows of the matrix associated with each split */ 38ace3abfcSBarry Smith PetscBool issetup; 392fa5cd67SKarl Rupp 4030ad9308SMatthew Knepley /* Only used when Schur complement preconditioning is used */ 4130ad9308SMatthew Knepley Mat B; /* The (0,1) block */ 4230ad9308SMatthew Knepley Mat C; /* The (1,0) block */ 43443836d0SMatthew G Knepley Mat schur; /* The Schur complement S = A11 - A10 A00^{-1} A01, the KSP here, kspinner, is H_1 in [El08] */ 44084e4875SJed Brown Mat schur_user; /* User-provided preconditioning matrix for the Schur complement */ 45084e4875SJed Brown PCFieldSplitSchurPreType schurpre; /* Determines which preconditioning matrix is used for the Schur complement */ 46c9c6ffaaSJed Brown PCFieldSplitSchurFactType schurfactorization; 4730ad9308SMatthew Knepley KSP kspschur; /* The solver for S */ 48443836d0SMatthew G Knepley KSP kspupper; /* The solver for A in the upper diagonal part of the factorization (H_2 in [El08]) */ 4997bbdb24SBarry Smith PC_FieldSplitLink head; 5063ec74ffSBarry Smith PetscBool reset; /* indicates PCReset() has been last called on this object, hack */ 51c1570756SJed Brown PetscBool suboptionsset; /* Indicates that the KSPSetFromOptions() has been called on the sub-KSPs */ 524ab8060aSDmitry Karpeev PetscBool dm_splits; /* Whether to use DMCreateFieldDecomposition() whenever possible */ 530971522cSBarry Smith } PC_FieldSplit; 540971522cSBarry Smith 5516913363SBarry Smith /* 5616913363SBarry Smith Notes: there is no particular reason that pmat, x, and y are stored as arrays in PC_FieldSplit instead of 5716913363SBarry Smith inside PC_FieldSplitLink, just historical. If you want to be able to add new fields after already using the 5816913363SBarry Smith PC you could change this. 5916913363SBarry Smith */ 60084e4875SJed Brown 61e6cab6aaSJed Brown /* This helper is so that setting a user-provided preconditioning matrix is orthogonal to choosing to use it. This way the 62084e4875SJed Brown * application-provided FormJacobian can provide this matrix without interfering with the user's (command-line) choices. */ 63084e4875SJed Brown static Mat FieldSplitSchurPre(PC_FieldSplit *jac) 64084e4875SJed Brown { 65084e4875SJed Brown switch (jac->schurpre) { 66084e4875SJed Brown case PC_FIELDSPLIT_SCHUR_PRE_SELF: return jac->schur; 67e87fab1bSBarry Smith case PC_FIELDSPLIT_SCHUR_PRE_A11: return jac->pmat[1]; 68084e4875SJed Brown case PC_FIELDSPLIT_SCHUR_PRE_USER: /* Use a user-provided matrix if it is given, otherwise diagonal block */ 69084e4875SJed Brown default: 70084e4875SJed Brown return jac->schur_user ? jac->schur_user : jac->pmat[1]; 71084e4875SJed Brown } 72084e4875SJed Brown } 73084e4875SJed Brown 74084e4875SJed Brown 759804daf3SBarry Smith #include <petscdraw.h> 760971522cSBarry Smith #undef __FUNCT__ 770971522cSBarry Smith #define __FUNCT__ "PCView_FieldSplit" 780971522cSBarry Smith static PetscErrorCode PCView_FieldSplit(PC pc,PetscViewer viewer) 790971522cSBarry Smith { 800971522cSBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 810971522cSBarry Smith PetscErrorCode ierr; 82d9884438SBarry Smith PetscBool iascii,isdraw; 830971522cSBarry Smith PetscInt i,j; 845a9f2f41SSatish Balay PC_FieldSplitLink ilink = jac->head; 850971522cSBarry Smith 860971522cSBarry Smith PetscFunctionBegin; 87251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 88d9884438SBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr); 890971522cSBarry Smith if (iascii) { 902c9966d7SBarry Smith if (jac->bs > 0) { 9151f519a2SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," FieldSplit with %s composition: total splits = %D, blocksize = %D\n",PCCompositeTypes[jac->type],jac->nsplits,jac->bs);CHKERRQ(ierr); 922c9966d7SBarry Smith } else { 932c9966d7SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," FieldSplit with %s composition: total splits = %D\n",PCCompositeTypes[jac->type],jac->nsplits);CHKERRQ(ierr); 942c9966d7SBarry Smith } 95f5236f50SJed Brown if (pc->useAmat) { 96f5236f50SJed Brown ierr = PetscViewerASCIIPrintf(viewer," using Amat (not Pmat) as operator for blocks\n");CHKERRQ(ierr); 97a3df900dSMatthew G Knepley } 9869a612a9SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Solver info for each split is in the following KSP objects:\n");CHKERRQ(ierr); 990971522cSBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 1000971522cSBarry Smith for (i=0; i<jac->nsplits; i++) { 1011ab39975SBarry Smith if (ilink->fields) { 1020971522cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"Split number %D Fields ",i);CHKERRQ(ierr); 10379416396SBarry Smith ierr = PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);CHKERRQ(ierr); 1045a9f2f41SSatish Balay for (j=0; j<ilink->nfields; j++) { 10579416396SBarry Smith if (j > 0) { 10679416396SBarry Smith ierr = PetscViewerASCIIPrintf(viewer,",");CHKERRQ(ierr); 10779416396SBarry Smith } 1085a9f2f41SSatish Balay ierr = PetscViewerASCIIPrintf(viewer," %D",ilink->fields[j]);CHKERRQ(ierr); 1090971522cSBarry Smith } 1100971522cSBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr); 11179416396SBarry Smith ierr = PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);CHKERRQ(ierr); 1121ab39975SBarry Smith } else { 1131ab39975SBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"Split number %D Defined by IS\n",i);CHKERRQ(ierr); 1141ab39975SBarry Smith } 1155a9f2f41SSatish Balay ierr = KSPView(ilink->ksp,viewer);CHKERRQ(ierr); 1165a9f2f41SSatish Balay ilink = ilink->next; 1170971522cSBarry Smith } 1180971522cSBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 1192fa5cd67SKarl Rupp } 1202fa5cd67SKarl Rupp 1212fa5cd67SKarl Rupp if (isdraw) { 122d9884438SBarry Smith PetscDraw draw; 123d9884438SBarry Smith PetscReal x,y,w,wd; 124d9884438SBarry Smith 125d9884438SBarry Smith ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr); 126d9884438SBarry Smith ierr = PetscDrawGetCurrentPoint(draw,&x,&y);CHKERRQ(ierr); 127d9884438SBarry Smith w = 2*PetscMin(1.0 - x,x); 128d9884438SBarry Smith wd = w/(jac->nsplits + 1); 129d9884438SBarry Smith x = x - wd*(jac->nsplits-1)/2.0; 130d9884438SBarry Smith for (i=0; i<jac->nsplits; i++) { 131d9884438SBarry Smith ierr = PetscDrawPushCurrentPoint(draw,x,y);CHKERRQ(ierr); 132d9884438SBarry Smith ierr = KSPView(ilink->ksp,viewer);CHKERRQ(ierr); 133d9884438SBarry Smith ierr = PetscDrawPopCurrentPoint(draw);CHKERRQ(ierr); 134d9884438SBarry Smith x += wd; 135d9884438SBarry Smith ilink = ilink->next; 136d9884438SBarry Smith } 1370971522cSBarry Smith } 1380971522cSBarry Smith PetscFunctionReturn(0); 1390971522cSBarry Smith } 1400971522cSBarry Smith 1410971522cSBarry Smith #undef __FUNCT__ 1423b224e63SBarry Smith #define __FUNCT__ "PCView_FieldSplit_Schur" 1433b224e63SBarry Smith static PetscErrorCode PCView_FieldSplit_Schur(PC pc,PetscViewer viewer) 1443b224e63SBarry Smith { 1453b224e63SBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 1463b224e63SBarry Smith PetscErrorCode ierr; 1474996c5bdSBarry Smith PetscBool iascii,isdraw; 1483b224e63SBarry Smith PetscInt i,j; 1493b224e63SBarry Smith PC_FieldSplitLink ilink = jac->head; 1503b224e63SBarry Smith 1513b224e63SBarry Smith PetscFunctionBegin; 152251f4c67SDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii);CHKERRQ(ierr); 1534996c5bdSBarry Smith ierr = PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERDRAW,&isdraw);CHKERRQ(ierr); 1543b224e63SBarry Smith if (iascii) { 1552c9966d7SBarry Smith if (jac->bs > 0) { 156c9c6ffaaSJed Brown ierr = PetscViewerASCIIPrintf(viewer," FieldSplit with Schur preconditioner, blocksize = %D, factorization %s\n",jac->bs,PCFieldSplitSchurFactTypes[jac->schurfactorization]);CHKERRQ(ierr); 1572c9966d7SBarry Smith } else { 1582c9966d7SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," FieldSplit with Schur preconditioner, factorization %s\n",PCFieldSplitSchurFactTypes[jac->schurfactorization]);CHKERRQ(ierr); 1592c9966d7SBarry Smith } 160f5236f50SJed Brown if (pc->useAmat) { 161f5236f50SJed Brown ierr = PetscViewerASCIIPrintf(viewer," using Amat (not Pmat) as operator for blocks\n");CHKERRQ(ierr); 162a3df900dSMatthew G Knepley } 1633e8b8b31SMatthew G Knepley switch (jac->schurpre) { 1643e8b8b31SMatthew G Knepley case PC_FIELDSPLIT_SCHUR_PRE_SELF: 1653e8b8b31SMatthew G Knepley ierr = PetscViewerASCIIPrintf(viewer," Preconditioner for the Schur complement formed from S itself\n");CHKERRQ(ierr);break; 166e87fab1bSBarry Smith case PC_FIELDSPLIT_SCHUR_PRE_A11: 167e87fab1bSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Preconditioner for the Schur complement formed from A11\n");CHKERRQ(ierr);break; 1683e8b8b31SMatthew G Knepley case PC_FIELDSPLIT_SCHUR_PRE_USER: 1693e8b8b31SMatthew G Knepley if (jac->schur_user) { 1703e8b8b31SMatthew G Knepley ierr = PetscViewerASCIIPrintf(viewer," Preconditioner for the Schur complement formed from user provided matrix\n");CHKERRQ(ierr); 1713e8b8b31SMatthew G Knepley } else { 172e87fab1bSBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Preconditioner for the Schur complement formed from A11\n");CHKERRQ(ierr); 1733e8b8b31SMatthew G Knepley } 1743e8b8b31SMatthew G Knepley break; 1753e8b8b31SMatthew G Knepley default: 17682f516ccSBarry Smith SETERRQ1(PetscObjectComm((PetscObject)pc), PETSC_ERR_ARG_OUTOFRANGE, "Invalid Schur preconditioning type: %d", jac->schurpre); 1773e8b8b31SMatthew G Knepley } 1783b224e63SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," Split info:\n");CHKERRQ(ierr); 1793b224e63SBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 1803b224e63SBarry Smith for (i=0; i<jac->nsplits; i++) { 1813b224e63SBarry Smith if (ilink->fields) { 1823b224e63SBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"Split number %D Fields ",i);CHKERRQ(ierr); 1833b224e63SBarry Smith ierr = PetscViewerASCIIUseTabs(viewer,PETSC_FALSE);CHKERRQ(ierr); 1843b224e63SBarry Smith for (j=0; j<ilink->nfields; j++) { 1853b224e63SBarry Smith if (j > 0) { 1863b224e63SBarry Smith ierr = PetscViewerASCIIPrintf(viewer,",");CHKERRQ(ierr); 1873b224e63SBarry Smith } 1883b224e63SBarry Smith ierr = PetscViewerASCIIPrintf(viewer," %D",ilink->fields[j]);CHKERRQ(ierr); 1893b224e63SBarry Smith } 1903b224e63SBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"\n");CHKERRQ(ierr); 1913b224e63SBarry Smith ierr = PetscViewerASCIIUseTabs(viewer,PETSC_TRUE);CHKERRQ(ierr); 1923b224e63SBarry Smith } else { 1933b224e63SBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"Split number %D Defined by IS\n",i);CHKERRQ(ierr); 1943b224e63SBarry Smith } 1953b224e63SBarry Smith ilink = ilink->next; 1963b224e63SBarry Smith } 197435f959eSBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"KSP solver for A00 block\n");CHKERRQ(ierr); 1983b224e63SBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 19906de4afeSJed Brown if (jac->head) { 200443836d0SMatthew G Knepley ierr = KSPView(jac->head->ksp,viewer);CHKERRQ(ierr); 20106de4afeSJed Brown } else {ierr = PetscViewerASCIIPrintf(viewer," not yet available\n");CHKERRQ(ierr);} 2023b224e63SBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 20306de4afeSJed Brown if (jac->head && jac->kspupper != jac->head->ksp) { 204443836d0SMatthew G Knepley ierr = PetscViewerASCIIPrintf(viewer,"KSP solver for upper A00 in upper triangular factor \n");CHKERRQ(ierr); 205443836d0SMatthew G Knepley ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 206b2750c55SJed Brown if (jac->kspupper) {ierr = KSPView(jac->kspupper,viewer);CHKERRQ(ierr);} 207b2750c55SJed Brown else {ierr = PetscViewerASCIIPrintf(viewer," not yet available\n");CHKERRQ(ierr);} 208443836d0SMatthew G Knepley ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 209443836d0SMatthew G Knepley } 210435f959eSBarry Smith ierr = PetscViewerASCIIPrintf(viewer,"KSP solver for S = A11 - A10 inv(A00) A01 \n");CHKERRQ(ierr); 2113b224e63SBarry Smith ierr = PetscViewerASCIIPushTab(viewer);CHKERRQ(ierr); 21212cae6f2SJed Brown if (jac->kspschur) { 2133b224e63SBarry Smith ierr = KSPView(jac->kspschur,viewer);CHKERRQ(ierr); 21412cae6f2SJed Brown } else { 21512cae6f2SJed Brown ierr = PetscViewerASCIIPrintf(viewer," not yet available\n");CHKERRQ(ierr); 21612cae6f2SJed Brown } 2173b224e63SBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 2183b224e63SBarry Smith ierr = PetscViewerASCIIPopTab(viewer);CHKERRQ(ierr); 21906de4afeSJed Brown } else if (isdraw && jac->head) { 2204996c5bdSBarry Smith PetscDraw draw; 2214996c5bdSBarry Smith PetscReal x,y,w,wd,h; 2224996c5bdSBarry Smith PetscInt cnt = 2; 2234996c5bdSBarry Smith char str[32]; 2244996c5bdSBarry Smith 2254996c5bdSBarry Smith ierr = PetscViewerDrawGetDraw(viewer,0,&draw);CHKERRQ(ierr); 2264996c5bdSBarry Smith ierr = PetscDrawGetCurrentPoint(draw,&x,&y);CHKERRQ(ierr); 227c74581afSBarry Smith if (jac->kspupper != jac->head->ksp) cnt++; 228c74581afSBarry Smith w = 2*PetscMin(1.0 - x,x); 229c74581afSBarry Smith wd = w/(cnt + 1); 230c74581afSBarry Smith 2314996c5bdSBarry Smith ierr = PetscSNPrintf(str,32,"Schur fact. %s",PCFieldSplitSchurFactTypes[jac->schurfactorization]);CHKERRQ(ierr); 2320298fd71SBarry Smith ierr = PetscDrawBoxedString(draw,x,y,PETSC_DRAW_RED,PETSC_DRAW_BLACK,str,NULL,&h);CHKERRQ(ierr); 2334996c5bdSBarry Smith y -= h; 2344996c5bdSBarry Smith if (jac->schurpre == PC_FIELDSPLIT_SCHUR_PRE_USER && !jac->schur_user) { 235e87fab1bSBarry Smith ierr = PetscSNPrintf(str,32,"Prec. for Schur from %s",PCFieldSplitSchurPreTypes[PC_FIELDSPLIT_SCHUR_PRE_A11]);CHKERRQ(ierr); 2363b224e63SBarry Smith } else { 2374996c5bdSBarry Smith ierr = PetscSNPrintf(str,32,"Prec. for Schur from %s",PCFieldSplitSchurPreTypes[jac->schurpre]);CHKERRQ(ierr); 2384996c5bdSBarry Smith } 2390298fd71SBarry Smith ierr = PetscDrawBoxedString(draw,x+wd*(cnt-1)/2.0,y,PETSC_DRAW_RED,PETSC_DRAW_BLACK,str,NULL,&h);CHKERRQ(ierr); 2404996c5bdSBarry Smith y -= h; 2414996c5bdSBarry Smith x = x - wd*(cnt-1)/2.0; 2424996c5bdSBarry Smith 2434996c5bdSBarry Smith ierr = PetscDrawPushCurrentPoint(draw,x,y);CHKERRQ(ierr); 2444996c5bdSBarry Smith ierr = KSPView(jac->head->ksp,viewer);CHKERRQ(ierr); 2454996c5bdSBarry Smith ierr = PetscDrawPopCurrentPoint(draw);CHKERRQ(ierr); 2464996c5bdSBarry Smith if (jac->kspupper != jac->head->ksp) { 2474996c5bdSBarry Smith x += wd; 2484996c5bdSBarry Smith ierr = PetscDrawPushCurrentPoint(draw,x,y);CHKERRQ(ierr); 2494996c5bdSBarry Smith ierr = KSPView(jac->kspupper,viewer);CHKERRQ(ierr); 2504996c5bdSBarry Smith ierr = PetscDrawPopCurrentPoint(draw);CHKERRQ(ierr); 2514996c5bdSBarry Smith } 2524996c5bdSBarry Smith x += wd; 2534996c5bdSBarry Smith ierr = PetscDrawPushCurrentPoint(draw,x,y);CHKERRQ(ierr); 2544996c5bdSBarry Smith ierr = KSPView(jac->kspschur,viewer);CHKERRQ(ierr); 2554996c5bdSBarry Smith ierr = PetscDrawPopCurrentPoint(draw);CHKERRQ(ierr); 2563b224e63SBarry Smith } 2573b224e63SBarry Smith PetscFunctionReturn(0); 2583b224e63SBarry Smith } 2593b224e63SBarry Smith 2603b224e63SBarry Smith #undef __FUNCT__ 2616c924f48SJed Brown #define __FUNCT__ "PCFieldSplitSetRuntimeSplits_Private" 2626c924f48SJed Brown /* Precondition: jac->bs is set to a meaningful value */ 2636c924f48SJed Brown static PetscErrorCode PCFieldSplitSetRuntimeSplits_Private(PC pc) 2646c924f48SJed Brown { 2656c924f48SJed Brown PetscErrorCode ierr; 2666c924f48SJed Brown PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 2675d4c12cdSJungho Lee PetscInt i,nfields,*ifields,nfields_col,*ifields_col; 2685d4c12cdSJungho Lee PetscBool flg,flg_col; 2695d4c12cdSJungho Lee char optionname[128],splitname[8],optionname_col[128]; 2706c924f48SJed Brown 2716c924f48SJed Brown PetscFunctionBegin; 272785e854fSJed Brown ierr = PetscMalloc1(jac->bs,&ifields);CHKERRQ(ierr); 273785e854fSJed Brown ierr = PetscMalloc1(jac->bs,&ifields_col);CHKERRQ(ierr); 2746c924f48SJed Brown for (i=0,flg=PETSC_TRUE;; i++) { 2758caf3d72SBarry Smith ierr = PetscSNPrintf(splitname,sizeof(splitname),"%D",i);CHKERRQ(ierr); 2768caf3d72SBarry Smith ierr = PetscSNPrintf(optionname,sizeof(optionname),"-pc_fieldsplit_%D_fields",i);CHKERRQ(ierr); 2778caf3d72SBarry Smith ierr = PetscSNPrintf(optionname_col,sizeof(optionname_col),"-pc_fieldsplit_%D_fields_col",i);CHKERRQ(ierr); 2786c924f48SJed Brown nfields = jac->bs; 27929499fbbSJungho Lee nfields_col = jac->bs; 2806c924f48SJed Brown ierr = PetscOptionsGetIntArray(((PetscObject)pc)->prefix,optionname,ifields,&nfields,&flg);CHKERRQ(ierr); 2815d4c12cdSJungho Lee ierr = PetscOptionsGetIntArray(((PetscObject)pc)->prefix,optionname_col,ifields_col,&nfields_col,&flg_col);CHKERRQ(ierr); 2826c924f48SJed Brown if (!flg) break; 2835d4c12cdSJungho Lee else if (flg && !flg_col) { 2845d4c12cdSJungho Lee if (!nfields) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Cannot list zero fields"); 2855d4c12cdSJungho Lee ierr = PCFieldSplitSetFields(pc,splitname,nfields,ifields,ifields);CHKERRQ(ierr); 2862fa5cd67SKarl Rupp } else { 2875d4c12cdSJungho Lee if (!nfields || !nfields_col) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Cannot list zero fields"); 2885d4c12cdSJungho Lee if (nfields != nfields_col) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Number of row and column fields must match"); 2895d4c12cdSJungho Lee ierr = PCFieldSplitSetFields(pc,splitname,nfields,ifields,ifields_col);CHKERRQ(ierr); 2905d4c12cdSJungho Lee } 2916c924f48SJed Brown } 2926c924f48SJed Brown if (i > 0) { 2936c924f48SJed Brown /* Makes command-line setting of splits take precedence over setting them in code. 2946c924f48SJed Brown Otherwise subsequent calls to PCFieldSplitSetIS() or PCFieldSplitSetFields() would 2956c924f48SJed Brown create new splits, which would probably not be what the user wanted. */ 2966c924f48SJed Brown jac->splitdefined = PETSC_TRUE; 2976c924f48SJed Brown } 2986c924f48SJed Brown ierr = PetscFree(ifields);CHKERRQ(ierr); 2995d4c12cdSJungho Lee ierr = PetscFree(ifields_col);CHKERRQ(ierr); 3006c924f48SJed Brown PetscFunctionReturn(0); 3016c924f48SJed Brown } 3026c924f48SJed Brown 3036c924f48SJed Brown #undef __FUNCT__ 30469a612a9SBarry Smith #define __FUNCT__ "PCFieldSplitSetDefaults" 30569a612a9SBarry Smith static PetscErrorCode PCFieldSplitSetDefaults(PC pc) 3060971522cSBarry Smith { 3070971522cSBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 3080971522cSBarry Smith PetscErrorCode ierr; 3095a9f2f41SSatish Balay PC_FieldSplitLink ilink = jac->head; 310*3a062f41SBarry Smith PetscBool fieldsplit_default = PETSC_FALSE,stokes = PETSC_FALSE,coupling = PETSC_FALSE; 3116c924f48SJed Brown PetscInt i; 3120971522cSBarry Smith 3130971522cSBarry Smith PetscFunctionBegin; 3147287d2a3SDmitry Karpeev /* 3157287d2a3SDmitry Karpeev Kinda messy, but at least this now uses DMCreateFieldDecomposition() even with jac->reset. 3167287d2a3SDmitry Karpeev Should probably be rewritten. 3177287d2a3SDmitry Karpeev */ 3187287d2a3SDmitry Karpeev if (!ilink || jac->reset) { 3190298fd71SBarry Smith ierr = PetscOptionsGetBool(((PetscObject)pc)->prefix,"-pc_fieldsplit_detect_saddle_point",&stokes,NULL);CHKERRQ(ierr); 320*3a062f41SBarry Smith ierr = PetscOptionsGetBool(((PetscObject)pc)->prefix,"-pc_fieldsplit_detect_coupling",&coupling,NULL);CHKERRQ(ierr); 321*3a062f41SBarry Smith if (pc->dm && jac->dm_splits && !stokes && !coupling) { 322bafc1b83SMatthew G Knepley PetscInt numFields, f, i, j; 3230784a22cSJed Brown char **fieldNames; 3247b62db95SJungho Lee IS *fields; 325e7c4fc90SDmitry Karpeev DM *dms; 326bafc1b83SMatthew G Knepley DM subdm[128]; 327bafc1b83SMatthew G Knepley PetscBool flg; 328bafc1b83SMatthew G Knepley 32916621825SDmitry Karpeev ierr = DMCreateFieldDecomposition(pc->dm, &numFields, &fieldNames, &fields, &dms);CHKERRQ(ierr); 330bafc1b83SMatthew G Knepley /* Allow the user to prescribe the splits */ 331bafc1b83SMatthew G Knepley for (i = 0, flg = PETSC_TRUE;; i++) { 332bafc1b83SMatthew G Knepley PetscInt ifields[128]; 333bafc1b83SMatthew G Knepley IS compField; 334bafc1b83SMatthew G Knepley char optionname[128], splitname[8]; 335bafc1b83SMatthew G Knepley PetscInt nfields = numFields; 336bafc1b83SMatthew G Knepley 3378caf3d72SBarry Smith ierr = PetscSNPrintf(optionname, sizeof(optionname), "-pc_fieldsplit_%D_fields", i);CHKERRQ(ierr); 338bafc1b83SMatthew G Knepley ierr = PetscOptionsGetIntArray(((PetscObject) pc)->prefix, optionname, ifields, &nfields, &flg);CHKERRQ(ierr); 339bafc1b83SMatthew G Knepley if (!flg) break; 34082f516ccSBarry Smith if (numFields > 128) SETERRQ1(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Cannot currently support %d > 128 fields", numFields); 341bafc1b83SMatthew G Knepley ierr = DMCreateSubDM(pc->dm, nfields, ifields, &compField, &subdm[i]);CHKERRQ(ierr); 342bafc1b83SMatthew G Knepley if (nfields == 1) { 343bafc1b83SMatthew G Knepley ierr = PCFieldSplitSetIS(pc, fieldNames[ifields[0]], compField);CHKERRQ(ierr); 34482f516ccSBarry Smith /* ierr = PetscPrintf(PetscObjectComm((PetscObject)pc), "%s Field Indices:", fieldNames[ifields[0]]);CHKERRQ(ierr); 3450298fd71SBarry Smith ierr = ISView(compField, NULL);CHKERRQ(ierr); */ 346bafc1b83SMatthew G Knepley } else { 3478caf3d72SBarry Smith ierr = PetscSNPrintf(splitname, sizeof(splitname), "%D", i);CHKERRQ(ierr); 348bafc1b83SMatthew G Knepley ierr = PCFieldSplitSetIS(pc, splitname, compField);CHKERRQ(ierr); 34982f516ccSBarry Smith /* ierr = PetscPrintf(PetscObjectComm((PetscObject)pc), "%s Field Indices:", splitname);CHKERRQ(ierr); 3500298fd71SBarry Smith ierr = ISView(compField, NULL);CHKERRQ(ierr); */ 3517287d2a3SDmitry Karpeev } 352bafc1b83SMatthew G Knepley ierr = ISDestroy(&compField);CHKERRQ(ierr); 353bafc1b83SMatthew G Knepley for (j = 0; j < nfields; ++j) { 354bafc1b83SMatthew G Knepley f = ifields[j]; 3557b62db95SJungho Lee ierr = PetscFree(fieldNames[f]);CHKERRQ(ierr); 3567b62db95SJungho Lee ierr = ISDestroy(&fields[f]);CHKERRQ(ierr); 3577b62db95SJungho Lee } 358bafc1b83SMatthew G Knepley } 359bafc1b83SMatthew G Knepley if (i == 0) { 360bafc1b83SMatthew G Knepley for (f = 0; f < numFields; ++f) { 361bafc1b83SMatthew G Knepley ierr = PCFieldSplitSetIS(pc, fieldNames[f], fields[f]);CHKERRQ(ierr); 362bafc1b83SMatthew G Knepley ierr = PetscFree(fieldNames[f]);CHKERRQ(ierr); 363bafc1b83SMatthew G Knepley ierr = ISDestroy(&fields[f]);CHKERRQ(ierr); 364bafc1b83SMatthew G Knepley } 365bafc1b83SMatthew G Knepley } else { 366d724dfffSBarry Smith for (j=0; j<numFields; j++) { 367d724dfffSBarry Smith ierr = DMDestroy(dms+j);CHKERRQ(ierr); 368d724dfffSBarry Smith } 369d724dfffSBarry Smith ierr = PetscFree(dms);CHKERRQ(ierr); 370785e854fSJed Brown ierr = PetscMalloc1(i, &dms);CHKERRQ(ierr); 3712fa5cd67SKarl Rupp for (j = 0; j < i; ++j) dms[j] = subdm[j]; 372bafc1b83SMatthew G Knepley } 3737b62db95SJungho Lee ierr = PetscFree(fieldNames);CHKERRQ(ierr); 3747b62db95SJungho Lee ierr = PetscFree(fields);CHKERRQ(ierr); 375e7c4fc90SDmitry Karpeev if (dms) { 3768b8307b2SJed Brown ierr = PetscInfo(pc, "Setting up physics based fieldsplit preconditioner using the embedded DM\n");CHKERRQ(ierr); 377bafc1b83SMatthew G Knepley for (ilink = jac->head, i = 0; ilink; ilink = ilink->next, ++i) { 3787287d2a3SDmitry Karpeev const char *prefix; 3797287d2a3SDmitry Karpeev ierr = PetscObjectGetOptionsPrefix((PetscObject)(ilink->ksp),&prefix);CHKERRQ(ierr); 3807287d2a3SDmitry Karpeev ierr = PetscObjectSetOptionsPrefix((PetscObject)(dms[i]), prefix);CHKERRQ(ierr); 3817b62db95SJungho Lee ierr = KSPSetDM(ilink->ksp, dms[i]);CHKERRQ(ierr); 3827b62db95SJungho Lee ierr = KSPSetDMActive(ilink->ksp, PETSC_FALSE);CHKERRQ(ierr); 3837287d2a3SDmitry Karpeev ierr = PetscObjectIncrementTabLevel((PetscObject)dms[i],(PetscObject)ilink->ksp,0);CHKERRQ(ierr); 384e7c4fc90SDmitry Karpeev ierr = DMDestroy(&dms[i]);CHKERRQ(ierr); 3852fa5ba8aSJed Brown } 3867b62db95SJungho Lee ierr = PetscFree(dms);CHKERRQ(ierr); 3878b8307b2SJed Brown } 38866ffff09SJed Brown } else { 389521d7252SBarry Smith if (jac->bs <= 0) { 390704ba839SBarry Smith if (pc->pmat) { 391521d7252SBarry Smith ierr = MatGetBlockSize(pc->pmat,&jac->bs);CHKERRQ(ierr); 3922fa5cd67SKarl Rupp } else jac->bs = 1; 393521d7252SBarry Smith } 394d32f9abdSBarry Smith 3956ce1633cSBarry Smith if (stokes) { 3966ce1633cSBarry Smith IS zerodiags,rest; 3976ce1633cSBarry Smith PetscInt nmin,nmax; 3986ce1633cSBarry Smith 3996ce1633cSBarry Smith ierr = MatGetOwnershipRange(pc->mat,&nmin,&nmax);CHKERRQ(ierr); 4006ce1633cSBarry Smith ierr = MatFindZeroDiagonals(pc->mat,&zerodiags);CHKERRQ(ierr); 4016ce1633cSBarry Smith ierr = ISComplement(zerodiags,nmin,nmax,&rest);CHKERRQ(ierr); 4027287d2a3SDmitry Karpeev if (jac->reset) { 4037287d2a3SDmitry Karpeev jac->head->is = rest; 4047287d2a3SDmitry Karpeev jac->head->next->is = zerodiags; 4052fa5cd67SKarl Rupp } else { 4066ce1633cSBarry Smith ierr = PCFieldSplitSetIS(pc,"0",rest);CHKERRQ(ierr); 4076ce1633cSBarry Smith ierr = PCFieldSplitSetIS(pc,"1",zerodiags);CHKERRQ(ierr); 4087287d2a3SDmitry Karpeev } 409fcfd50ebSBarry Smith ierr = ISDestroy(&zerodiags);CHKERRQ(ierr); 410fcfd50ebSBarry Smith ierr = ISDestroy(&rest);CHKERRQ(ierr); 411*3a062f41SBarry Smith } else if (coupling) { 412*3a062f41SBarry Smith IS coupling,rest; 413*3a062f41SBarry Smith PetscInt nmin,nmax; 414*3a062f41SBarry Smith 415*3a062f41SBarry Smith ierr = MatGetOwnershipRange(pc->mat,&nmin,&nmax);CHKERRQ(ierr); 416*3a062f41SBarry Smith ierr = MatFindOffBlockDiagonalEntries(pc->mat,&coupling);CHKERRQ(ierr); 417*3a062f41SBarry Smith ierr = ISComplement(coupling,nmin,nmax,&rest);CHKERRQ(ierr); 418*3a062f41SBarry Smith if (jac->reset) { 419*3a062f41SBarry Smith jac->head->is = coupling; 420*3a062f41SBarry Smith jac->head->next->is = rest; 421*3a062f41SBarry Smith } else { 422*3a062f41SBarry Smith ierr = PCFieldSplitSetIS(pc,"0",coupling);CHKERRQ(ierr); 423*3a062f41SBarry Smith ierr = PCFieldSplitSetIS(pc,"1",rest);CHKERRQ(ierr); 424*3a062f41SBarry Smith } 425*3a062f41SBarry Smith ierr = ISDestroy(&coupling);CHKERRQ(ierr); 426*3a062f41SBarry Smith ierr = ISDestroy(&rest);CHKERRQ(ierr); 4276ce1633cSBarry Smith } else { 428ce94432eSBarry Smith if (jac->reset) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Cases not yet handled when PCReset() was used"); 4299eeaaa73SJed Brown ierr = PetscOptionsGetBool(((PetscObject)pc)->prefix,"-pc_fieldsplit_default",&fieldsplit_default,NULL);CHKERRQ(ierr); 4307287d2a3SDmitry Karpeev if (!fieldsplit_default) { 431d32f9abdSBarry Smith /* Allow user to set fields from command line, if bs was known at the time of PCSetFromOptions_FieldSplit() 432d32f9abdSBarry Smith then it is set there. This is not ideal because we should only have options set in XXSetFromOptions(). */ 4336c924f48SJed Brown ierr = PCFieldSplitSetRuntimeSplits_Private(pc);CHKERRQ(ierr); 4346c924f48SJed Brown if (jac->splitdefined) {ierr = PetscInfo(pc,"Splits defined using the options database\n");CHKERRQ(ierr);} 435d32f9abdSBarry Smith } 4367287d2a3SDmitry Karpeev if (fieldsplit_default || !jac->splitdefined) { 437d32f9abdSBarry Smith ierr = PetscInfo(pc,"Using default splitting of fields\n");CHKERRQ(ierr); 438db4c96c1SJed Brown for (i=0; i<jac->bs; i++) { 4396c924f48SJed Brown char splitname[8]; 4408caf3d72SBarry Smith ierr = PetscSNPrintf(splitname,sizeof(splitname),"%D",i);CHKERRQ(ierr); 4415d4c12cdSJungho Lee ierr = PCFieldSplitSetFields(pc,splitname,1,&i,&i);CHKERRQ(ierr); 44279416396SBarry Smith } 4435d4c12cdSJungho Lee jac->defaultsplit = PETSC_TRUE; 444521d7252SBarry Smith } 44566ffff09SJed Brown } 4466ce1633cSBarry Smith } 447edf189efSBarry Smith } else if (jac->nsplits == 1) { 448edf189efSBarry Smith if (ilink->is) { 449edf189efSBarry Smith IS is2; 450edf189efSBarry Smith PetscInt nmin,nmax; 451edf189efSBarry Smith 452edf189efSBarry Smith ierr = MatGetOwnershipRange(pc->mat,&nmin,&nmax);CHKERRQ(ierr); 453edf189efSBarry Smith ierr = ISComplement(ilink->is,nmin,nmax,&is2);CHKERRQ(ierr); 454db4c96c1SJed Brown ierr = PCFieldSplitSetIS(pc,"1",is2);CHKERRQ(ierr); 455fcfd50ebSBarry Smith ierr = ISDestroy(&is2);CHKERRQ(ierr); 45682f516ccSBarry Smith } else SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Must provide at least two sets of fields to PCFieldSplit()"); 457edf189efSBarry Smith } 458d0af7cd3SBarry Smith 459d0af7cd3SBarry Smith 46082f516ccSBarry Smith if (jac->nsplits < 2) SETERRQ1(PetscObjectComm((PetscObject)pc),PETSC_ERR_PLIB,"Unhandled case, must have at least two fields, not %d", jac->nsplits); 46169a612a9SBarry Smith PetscFunctionReturn(0); 46269a612a9SBarry Smith } 46369a612a9SBarry Smith 4645a576424SJed Brown PETSC_EXTERN PetscErrorCode PetscOptionsFindPairPrefix_Private(const char pre[], const char name[], char *value[], PetscBool *flg); 465514bf10dSMatthew G Knepley 46669a612a9SBarry Smith #undef __FUNCT__ 46769a612a9SBarry Smith #define __FUNCT__ "PCSetUp_FieldSplit" 46869a612a9SBarry Smith static PetscErrorCode PCSetUp_FieldSplit(PC pc) 46969a612a9SBarry Smith { 47069a612a9SBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 47169a612a9SBarry Smith PetscErrorCode ierr; 4725a9f2f41SSatish Balay PC_FieldSplitLink ilink; 4732c9966d7SBarry Smith PetscInt i,nsplit; 47469a612a9SBarry Smith MatStructure flag = pc->flag; 4755f4ab4e1SJungho Lee PetscBool sorted, sorted_col; 47669a612a9SBarry Smith 47769a612a9SBarry Smith PetscFunctionBegin; 47869a612a9SBarry Smith ierr = PCFieldSplitSetDefaults(pc);CHKERRQ(ierr); 47997bbdb24SBarry Smith nsplit = jac->nsplits; 4805a9f2f41SSatish Balay ilink = jac->head; 48197bbdb24SBarry Smith 48297bbdb24SBarry Smith /* get the matrices for each split */ 483704ba839SBarry Smith if (!jac->issetup) { 4841b9fc7fcSBarry Smith PetscInt rstart,rend,nslots,bs; 48597bbdb24SBarry Smith 486704ba839SBarry Smith jac->issetup = PETSC_TRUE; 487704ba839SBarry Smith 4885d4c12cdSJungho Lee /* This is done here instead of in PCFieldSplitSetFields() because may not have matrix at that point */ 4892c9966d7SBarry Smith if (jac->defaultsplit || !ilink->is) { 4902c9966d7SBarry Smith if (jac->bs <= 0) jac->bs = nsplit; 4912c9966d7SBarry Smith } 49251f519a2SBarry Smith bs = jac->bs; 49397bbdb24SBarry Smith ierr = MatGetOwnershipRange(pc->pmat,&rstart,&rend);CHKERRQ(ierr); 4941b9fc7fcSBarry Smith nslots = (rend - rstart)/bs; 4951b9fc7fcSBarry Smith for (i=0; i<nsplit; i++) { 4961b9fc7fcSBarry Smith if (jac->defaultsplit) { 497ce94432eSBarry Smith ierr = ISCreateStride(PetscObjectComm((PetscObject)pc),nslots,rstart+i,nsplit,&ilink->is);CHKERRQ(ierr); 4985f4ab4e1SJungho Lee ierr = ISDuplicate(ilink->is,&ilink->is_col);CHKERRQ(ierr); 499704ba839SBarry Smith } else if (!ilink->is) { 500ccb205f8SBarry Smith if (ilink->nfields > 1) { 5015f4ab4e1SJungho Lee PetscInt *ii,*jj,j,k,nfields = ilink->nfields,*fields = ilink->fields,*fields_col = ilink->fields_col; 502785e854fSJed Brown ierr = PetscMalloc1(ilink->nfields*nslots,&ii);CHKERRQ(ierr); 503785e854fSJed Brown ierr = PetscMalloc1(ilink->nfields*nslots,&jj);CHKERRQ(ierr); 5041b9fc7fcSBarry Smith for (j=0; j<nslots; j++) { 5051b9fc7fcSBarry Smith for (k=0; k<nfields; k++) { 5061b9fc7fcSBarry Smith ii[nfields*j + k] = rstart + bs*j + fields[k]; 5075f4ab4e1SJungho Lee jj[nfields*j + k] = rstart + bs*j + fields_col[k]; 50897bbdb24SBarry Smith } 50997bbdb24SBarry Smith } 510ce94432eSBarry Smith ierr = ISCreateGeneral(PetscObjectComm((PetscObject)pc),nslots*nfields,ii,PETSC_OWN_POINTER,&ilink->is);CHKERRQ(ierr); 511ce94432eSBarry Smith ierr = ISCreateGeneral(PetscObjectComm((PetscObject)pc),nslots*nfields,jj,PETSC_OWN_POINTER,&ilink->is_col);CHKERRQ(ierr); 512ccb205f8SBarry Smith } else { 513ce94432eSBarry Smith ierr = ISCreateStride(PetscObjectComm((PetscObject)pc),nslots,rstart+ilink->fields[0],bs,&ilink->is);CHKERRQ(ierr); 514ce94432eSBarry Smith ierr = ISCreateStride(PetscObjectComm((PetscObject)pc),nslots,rstart+ilink->fields_col[0],bs,&ilink->is_col);CHKERRQ(ierr); 515ccb205f8SBarry Smith } 5163e197d65SBarry Smith } 517704ba839SBarry Smith ierr = ISSorted(ilink->is,&sorted);CHKERRQ(ierr); 5185f4ab4e1SJungho Lee if (ilink->is_col) { ierr = ISSorted(ilink->is_col,&sorted_col);CHKERRQ(ierr); } 5195f4ab4e1SJungho Lee if (!sorted || !sorted_col) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_USER,"Fields must be sorted when creating split"); 520704ba839SBarry Smith ilink = ilink->next; 5211b9fc7fcSBarry Smith } 5221b9fc7fcSBarry Smith } 5231b9fc7fcSBarry Smith 524704ba839SBarry Smith ilink = jac->head; 52597bbdb24SBarry Smith if (!jac->pmat) { 526bdddcaaaSMatthew G Knepley Vec xtmp; 527bdddcaaaSMatthew G Knepley 5280298fd71SBarry Smith ierr = MatGetVecs(pc->pmat,&xtmp,NULL);CHKERRQ(ierr); 529785e854fSJed Brown ierr = PetscMalloc1(nsplit,&jac->pmat);CHKERRQ(ierr); 530dcca6d9dSJed Brown ierr = PetscMalloc2(nsplit,&jac->x,nsplit,&jac->y);CHKERRQ(ierr); 531cf502942SBarry Smith for (i=0; i<nsplit; i++) { 532bdddcaaaSMatthew G Knepley MatNullSpace sp; 533bdddcaaaSMatthew G Knepley 534a3df900dSMatthew G Knepley /* Check for preconditioning matrix attached to IS */ 535a3df900dSMatthew G Knepley ierr = PetscObjectQuery((PetscObject) ilink->is, "pmat", (PetscObject*) &jac->pmat[i]);CHKERRQ(ierr); 536a3df900dSMatthew G Knepley if (jac->pmat[i]) { 537a3df900dSMatthew G Knepley ierr = PetscObjectReference((PetscObject) jac->pmat[i]);CHKERRQ(ierr); 538a3df900dSMatthew G Knepley if (jac->type == PC_COMPOSITE_SCHUR) { 539a3df900dSMatthew G Knepley jac->schur_user = jac->pmat[i]; 5402fa5cd67SKarl Rupp 541a3df900dSMatthew G Knepley ierr = PetscObjectReference((PetscObject) jac->schur_user);CHKERRQ(ierr); 542a3df900dSMatthew G Knepley } 543a3df900dSMatthew G Knepley } else { 544*3a062f41SBarry Smith const char *prefix; 5455f4ab4e1SJungho Lee ierr = MatGetSubMatrix(pc->pmat,ilink->is,ilink->is_col,MAT_INITIAL_MATRIX,&jac->pmat[i]);CHKERRQ(ierr); 546*3a062f41SBarry Smith ierr = KSPGetOptionsPrefix(ilink->ksp,&prefix);CHKERRQ(ierr); 547*3a062f41SBarry Smith ierr = MatSetOptionsPrefix(jac->pmat[i],prefix);CHKERRQ(ierr); 548*3a062f41SBarry Smith ierr = MatViewFromOptions(jac->pmat[i],NULL,"-mat_view");CHKERRQ(ierr); 549a3df900dSMatthew G Knepley } 550bdddcaaaSMatthew G Knepley /* create work vectors for each split */ 551bdddcaaaSMatthew G Knepley ierr = MatGetVecs(jac->pmat[i],&jac->x[i],&jac->y[i]);CHKERRQ(ierr); 5520298fd71SBarry Smith ilink->x = jac->x[i]; ilink->y = jac->y[i]; ilink->z = NULL; 553bdddcaaaSMatthew G Knepley /* compute scatter contexts needed by multiplicative versions and non-default splits */ 5540298fd71SBarry Smith ierr = VecScatterCreate(xtmp,ilink->is,jac->x[i],NULL,&ilink->sctx);CHKERRQ(ierr); 555ed1f0337SMatthew G Knepley /* Check for null space attached to IS */ 556bafc1b83SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) ilink->is, "nullspace", (PetscObject*) &sp);CHKERRQ(ierr); 557bafc1b83SMatthew G Knepley if (sp) { 558bafc1b83SMatthew G Knepley ierr = MatSetNullSpace(jac->pmat[i], sp);CHKERRQ(ierr); 559bafc1b83SMatthew G Knepley } 560ed1f0337SMatthew G Knepley ierr = PetscObjectQuery((PetscObject) ilink->is, "nearnullspace", (PetscObject*) &sp);CHKERRQ(ierr); 561ed1f0337SMatthew G Knepley if (sp) { 562ed1f0337SMatthew G Knepley ierr = MatSetNearNullSpace(jac->pmat[i], sp);CHKERRQ(ierr); 563ed1f0337SMatthew G Knepley } 564704ba839SBarry Smith ilink = ilink->next; 565cf502942SBarry Smith } 566bdddcaaaSMatthew G Knepley ierr = VecDestroy(&xtmp);CHKERRQ(ierr); 56797bbdb24SBarry Smith } else { 568cf502942SBarry Smith for (i=0; i<nsplit; i++) { 569a3df900dSMatthew G Knepley Mat pmat; 570a3df900dSMatthew G Knepley 571a3df900dSMatthew G Knepley /* Check for preconditioning matrix attached to IS */ 572a3df900dSMatthew G Knepley ierr = PetscObjectQuery((PetscObject) ilink->is, "pmat", (PetscObject*) &pmat);CHKERRQ(ierr); 573a3df900dSMatthew G Knepley if (!pmat) { 5745f4ab4e1SJungho Lee ierr = MatGetSubMatrix(pc->pmat,ilink->is,ilink->is_col,MAT_REUSE_MATRIX,&jac->pmat[i]);CHKERRQ(ierr); 575a3df900dSMatthew G Knepley } 576704ba839SBarry Smith ilink = ilink->next; 577cf502942SBarry Smith } 57897bbdb24SBarry Smith } 579f5236f50SJed Brown if (pc->useAmat) { 580519d70e2SJed Brown ilink = jac->head; 581519d70e2SJed Brown if (!jac->mat) { 582785e854fSJed Brown ierr = PetscMalloc1(nsplit,&jac->mat);CHKERRQ(ierr); 583519d70e2SJed Brown for (i=0; i<nsplit; i++) { 5845f4ab4e1SJungho Lee ierr = MatGetSubMatrix(pc->mat,ilink->is,ilink->is_col,MAT_INITIAL_MATRIX,&jac->mat[i]);CHKERRQ(ierr); 585519d70e2SJed Brown ilink = ilink->next; 586519d70e2SJed Brown } 587519d70e2SJed Brown } else { 588519d70e2SJed Brown for (i=0; i<nsplit; i++) { 5895f4ab4e1SJungho Lee if (jac->mat[i]) {ierr = MatGetSubMatrix(pc->mat,ilink->is,ilink->is_col,MAT_REUSE_MATRIX,&jac->mat[i]);CHKERRQ(ierr);} 590519d70e2SJed Brown ilink = ilink->next; 591519d70e2SJed Brown } 592519d70e2SJed Brown } 593519d70e2SJed Brown } else { 594519d70e2SJed Brown jac->mat = jac->pmat; 595519d70e2SJed Brown } 59697bbdb24SBarry Smith 5976c8605c2SJed Brown if (jac->type != PC_COMPOSITE_ADDITIVE && jac->type != PC_COMPOSITE_SCHUR) { 59868dd23aaSBarry Smith /* extract the rows of the matrix associated with each field: used for efficient computation of residual inside algorithm */ 59968dd23aaSBarry Smith ilink = jac->head; 60068dd23aaSBarry Smith if (!jac->Afield) { 601785e854fSJed Brown ierr = PetscMalloc1(nsplit,&jac->Afield);CHKERRQ(ierr); 60268dd23aaSBarry Smith for (i=0; i<nsplit; i++) { 6030298fd71SBarry Smith ierr = MatGetSubMatrix(pc->mat,ilink->is,NULL,MAT_INITIAL_MATRIX,&jac->Afield[i]);CHKERRQ(ierr); 60468dd23aaSBarry Smith ilink = ilink->next; 60568dd23aaSBarry Smith } 60668dd23aaSBarry Smith } else { 60768dd23aaSBarry Smith for (i=0; i<nsplit; i++) { 6080298fd71SBarry Smith ierr = MatGetSubMatrix(pc->mat,ilink->is,NULL,MAT_REUSE_MATRIX,&jac->Afield[i]);CHKERRQ(ierr); 60968dd23aaSBarry Smith ilink = ilink->next; 61068dd23aaSBarry Smith } 61168dd23aaSBarry Smith } 61268dd23aaSBarry Smith } 61368dd23aaSBarry Smith 6143b224e63SBarry Smith if (jac->type == PC_COMPOSITE_SCHUR) { 6153b224e63SBarry Smith IS ccis; 6164aa3045dSJed Brown PetscInt rstart,rend; 617093c86ffSJed Brown char lscname[256]; 618093c86ffSJed Brown PetscObject LSC_L; 619ce94432eSBarry Smith 620ce94432eSBarry Smith if (nsplit != 2) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_INCOMP,"To use Schur complement preconditioner you must have exactly 2 fields"); 62168dd23aaSBarry Smith 622e6cab6aaSJed Brown /* When extracting off-diagonal submatrices, we take complements from this range */ 623e6cab6aaSJed Brown ierr = MatGetOwnershipRangeColumn(pc->mat,&rstart,&rend);CHKERRQ(ierr); 624e6cab6aaSJed Brown 6253b224e63SBarry Smith /* need to handle case when one is resetting up the preconditioner */ 6263b224e63SBarry Smith if (jac->schur) { 6270298fd71SBarry Smith KSP kspA = jac->head->ksp, kspInner = NULL, kspUpper = jac->kspupper; 628443836d0SMatthew G Knepley 629fb3147dbSMatthew G Knepley ierr = MatSchurComplementGetKSP(jac->schur, &kspInner);CHKERRQ(ierr); 6303b224e63SBarry Smith ilink = jac->head; 63149bb4cd7SJungho Lee ierr = ISComplement(ilink->is_col,rstart,rend,&ccis);CHKERRQ(ierr); 6324aa3045dSJed Brown ierr = MatGetSubMatrix(pc->mat,ilink->is,ccis,MAT_REUSE_MATRIX,&jac->B);CHKERRQ(ierr); 633fcfd50ebSBarry Smith ierr = ISDestroy(&ccis);CHKERRQ(ierr); 6343b224e63SBarry Smith ilink = ilink->next; 63549bb4cd7SJungho Lee ierr = ISComplement(ilink->is_col,rstart,rend,&ccis);CHKERRQ(ierr); 6364aa3045dSJed Brown ierr = MatGetSubMatrix(pc->mat,ilink->is,ccis,MAT_REUSE_MATRIX,&jac->C);CHKERRQ(ierr); 637fcfd50ebSBarry Smith ierr = ISDestroy(&ccis);CHKERRQ(ierr); 638a3df900dSMatthew G Knepley ierr = MatSchurComplementUpdate(jac->schur,jac->mat[0],jac->pmat[0],jac->B,jac->C,jac->mat[1],pc->flag);CHKERRQ(ierr); 639443836d0SMatthew G Knepley if (kspA != kspInner) { 640443836d0SMatthew G Knepley ierr = KSPSetOperators(kspA,jac->mat[0],jac->pmat[0],pc->flag);CHKERRQ(ierr); 641443836d0SMatthew G Knepley } 642443836d0SMatthew G Knepley if (kspUpper != kspA) { 643443836d0SMatthew G Knepley ierr = KSPSetOperators(kspUpper,jac->mat[0],jac->pmat[0],pc->flag);CHKERRQ(ierr); 644443836d0SMatthew G Knepley } 645084e4875SJed Brown ierr = KSPSetOperators(jac->kspschur,jac->schur,FieldSplitSchurPre(jac),pc->flag);CHKERRQ(ierr); 6463b224e63SBarry Smith } else { 647bafc1b83SMatthew G Knepley const char *Dprefix; 648bafc1b83SMatthew G Knepley char schurprefix[256]; 649514bf10dSMatthew G Knepley char schurtestoption[256]; 650bdddcaaaSMatthew G Knepley MatNullSpace sp; 651514bf10dSMatthew G Knepley PetscBool flg; 6523b224e63SBarry Smith 653a04f6461SBarry Smith /* extract the A01 and A10 matrices */ 6543b224e63SBarry Smith ilink = jac->head; 65549bb4cd7SJungho Lee ierr = ISComplement(ilink->is_col,rstart,rend,&ccis);CHKERRQ(ierr); 6564aa3045dSJed Brown ierr = MatGetSubMatrix(pc->mat,ilink->is,ccis,MAT_INITIAL_MATRIX,&jac->B);CHKERRQ(ierr); 657fcfd50ebSBarry Smith ierr = ISDestroy(&ccis);CHKERRQ(ierr); 6583b224e63SBarry Smith ilink = ilink->next; 65949bb4cd7SJungho Lee ierr = ISComplement(ilink->is_col,rstart,rend,&ccis);CHKERRQ(ierr); 6604aa3045dSJed Brown ierr = MatGetSubMatrix(pc->mat,ilink->is,ccis,MAT_INITIAL_MATRIX,&jac->C);CHKERRQ(ierr); 661fcfd50ebSBarry Smith ierr = ISDestroy(&ccis);CHKERRQ(ierr); 66220252d06SBarry Smith 663f5236f50SJed Brown /* Use mat[0] (diagonal block of Amat) preconditioned by pmat[0] to define Schur complement */ 66420252d06SBarry Smith ierr = MatCreate(((PetscObject)jac->mat[0])->comm,&jac->schur);CHKERRQ(ierr); 66520252d06SBarry Smith ierr = MatSetType(jac->schur,MATSCHURCOMPLEMENT);CHKERRQ(ierr); 66620252d06SBarry Smith ierr = MatSchurComplementSet(jac->schur,jac->mat[0],jac->pmat[0],jac->B,jac->C,jac->mat[1]);CHKERRQ(ierr); 66720252d06SBarry Smith 668bdddcaaaSMatthew G Knepley ierr = MatGetNullSpace(jac->pmat[1], &sp);CHKERRQ(ierr); 66920252d06SBarry Smith if (sp) { 67020252d06SBarry Smith ierr = MatSetNullSpace(jac->schur, sp);CHKERRQ(ierr); 67120252d06SBarry Smith } 67220252d06SBarry Smith 67320252d06SBarry Smith ierr = PetscSNPrintf(schurtestoption, sizeof(schurtestoption), "-fieldsplit_%s_inner_", ilink->splitname);CHKERRQ(ierr); 6740298fd71SBarry Smith ierr = PetscOptionsFindPairPrefix_Private(((PetscObject)pc)->prefix, schurtestoption, NULL, &flg);CHKERRQ(ierr); 675514bf10dSMatthew G Knepley if (flg) { 676514bf10dSMatthew G Knepley DM dmInner; 67721635b76SJed Brown KSP kspInner; 67821635b76SJed Brown 67921635b76SJed Brown ierr = MatSchurComplementGetKSP(jac->schur, &kspInner);CHKERRQ(ierr); 68021635b76SJed Brown ierr = PetscSNPrintf(schurprefix, sizeof(schurprefix), "%sfieldsplit_%s_inner_", ((PetscObject)pc)->prefix ? ((PetscObject)pc)->prefix : "", ilink->splitname);CHKERRQ(ierr); 68121635b76SJed Brown /* Indent this deeper to emphasize the "inner" nature of this solver. */ 68221635b76SJed Brown ierr = PetscObjectIncrementTabLevel((PetscObject)kspInner, (PetscObject) pc, 2);CHKERRQ(ierr); 68321635b76SJed Brown ierr = KSPSetOptionsPrefix(kspInner, schurprefix);CHKERRQ(ierr); 684514bf10dSMatthew G Knepley 685514bf10dSMatthew G Knepley /* Set DM for new solver */ 686bafc1b83SMatthew G Knepley ierr = KSPGetDM(jac->head->ksp, &dmInner);CHKERRQ(ierr); 68721635b76SJed Brown ierr = KSPSetDM(kspInner, dmInner);CHKERRQ(ierr); 68821635b76SJed Brown ierr = KSPSetDMActive(kspInner, PETSC_FALSE);CHKERRQ(ierr); 689514bf10dSMatthew G Knepley } else { 69021635b76SJed Brown /* Use the outer solver for the inner solve, but revert the KSPPREONLY from PCFieldSplitSetFields_FieldSplit or 69121635b76SJed Brown * PCFieldSplitSetIS_FieldSplit. We don't want KSPPREONLY because it makes the Schur complement inexact, 69221635b76SJed Brown * preventing Schur complement reduction to be an accurate solve. Usually when an iterative solver is used for 69321635b76SJed Brown * S = D - C A_inner^{-1} B, we expect S to be defined using an accurate definition of A_inner^{-1}, so we make 69421635b76SJed Brown * GMRES the default. Note that it is also common to use PREONLY for S, in which case S may not be used 69521635b76SJed Brown * directly, and the user is responsible for setting an inexact method for fieldsplit's A^{-1}. */ 69621635b76SJed Brown ierr = KSPSetType(jac->head->ksp,KSPGMRES);CHKERRQ(ierr); 697514bf10dSMatthew G Knepley ierr = MatSchurComplementSetKSP(jac->schur,jac->head->ksp);CHKERRQ(ierr); 698bafc1b83SMatthew G Knepley } 6995a9f2f41SSatish Balay ierr = KSPSetOperators(jac->head->ksp,jac->mat[0],jac->pmat[0],flag);CHKERRQ(ierr); 7005a9f2f41SSatish Balay ierr = KSPSetFromOptions(jac->head->ksp);CHKERRQ(ierr); 70197bbdb24SBarry Smith ierr = MatSetFromOptions(jac->schur);CHKERRQ(ierr); 70297bbdb24SBarry Smith 703443836d0SMatthew G Knepley ierr = PetscSNPrintf(schurtestoption, sizeof(schurtestoption), "-fieldsplit_%s_upper_", ilink->splitname);CHKERRQ(ierr); 7040298fd71SBarry Smith ierr = PetscOptionsFindPairPrefix_Private(((PetscObject)pc)->prefix, schurtestoption, NULL, &flg);CHKERRQ(ierr); 705443836d0SMatthew G Knepley if (flg) { 706443836d0SMatthew G Knepley DM dmInner; 707443836d0SMatthew G Knepley 708443836d0SMatthew G Knepley ierr = PetscSNPrintf(schurprefix, sizeof(schurprefix), "%sfieldsplit_%s_upper_", ((PetscObject)pc)->prefix ? ((PetscObject)pc)->prefix : "", ilink->splitname);CHKERRQ(ierr); 70982f516ccSBarry Smith ierr = KSPCreate(PetscObjectComm((PetscObject)pc), &jac->kspupper);CHKERRQ(ierr); 710443836d0SMatthew G Knepley ierr = KSPSetOptionsPrefix(jac->kspupper, schurprefix);CHKERRQ(ierr); 711443836d0SMatthew G Knepley ierr = KSPGetDM(jac->head->ksp, &dmInner);CHKERRQ(ierr); 712443836d0SMatthew G Knepley ierr = KSPSetDM(jac->kspupper, dmInner);CHKERRQ(ierr); 713443836d0SMatthew G Knepley ierr = KSPSetDMActive(jac->kspupper, PETSC_FALSE);CHKERRQ(ierr); 714443836d0SMatthew G Knepley ierr = KSPSetFromOptions(jac->kspupper);CHKERRQ(ierr); 715443836d0SMatthew G Knepley ierr = KSPSetOperators(jac->kspupper,jac->mat[0],jac->pmat[0],flag);CHKERRQ(ierr); 716443836d0SMatthew G Knepley ierr = VecDuplicate(jac->head->x, &jac->head->z);CHKERRQ(ierr); 717443836d0SMatthew G Knepley } else { 718443836d0SMatthew G Knepley jac->kspupper = jac->head->ksp; 719443836d0SMatthew G Knepley ierr = PetscObjectReference((PetscObject) jac->head->ksp);CHKERRQ(ierr); 720443836d0SMatthew G Knepley } 721443836d0SMatthew G Knepley 722ce94432eSBarry Smith ierr = KSPCreate(PetscObjectComm((PetscObject)pc),&jac->kspschur);CHKERRQ(ierr); 72397bbdb24SBarry Smith ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)jac->kspschur);CHKERRQ(ierr); 72420252d06SBarry Smith ierr = PetscObjectIncrementTabLevel((PetscObject)jac->kspschur,(PetscObject)pc,1);CHKERRQ(ierr); 72597bbdb24SBarry Smith ierr = KSPSetOperators(jac->kspschur,jac->schur,FieldSplitSchurPre(jac),DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr); 72697bbdb24SBarry Smith if (jac->schurpre == PC_FIELDSPLIT_SCHUR_PRE_SELF) { 7277233a360SDmitry Karpeev PC pcschur; 7287233a360SDmitry Karpeev ierr = KSPGetPC(jac->kspschur,&pcschur);CHKERRQ(ierr); 7297233a360SDmitry Karpeev ierr = PCSetType(pcschur,PCNONE);CHKERRQ(ierr); 73097bbdb24SBarry Smith /* Note: This is bad if there exist preconditioners for MATSCHURCOMPLEMENT */ 73197bbdb24SBarry Smith } 73297bbdb24SBarry Smith ierr = KSPGetOptionsPrefix(jac->head->next->ksp, &Dprefix);CHKERRQ(ierr); 73397bbdb24SBarry Smith ierr = KSPSetOptionsPrefix(jac->kspschur, Dprefix);CHKERRQ(ierr); 734b20b4189SMatthew G. Knepley /* propogate DM */ 735b20b4189SMatthew G. Knepley { 736b20b4189SMatthew G. Knepley DM sdm; 737b20b4189SMatthew G. Knepley ierr = KSPGetDM(jac->head->next->ksp, &sdm);CHKERRQ(ierr); 738b20b4189SMatthew G. Knepley if (sdm) { 739b20b4189SMatthew G. Knepley ierr = KSPSetDM(jac->kspschur, sdm);CHKERRQ(ierr); 740b20b4189SMatthew G. Knepley ierr = KSPSetDMActive(jac->kspschur, PETSC_FALSE);CHKERRQ(ierr); 741b20b4189SMatthew G. Knepley } 742b20b4189SMatthew G. Knepley } 74397bbdb24SBarry Smith /* really want setfromoptions called in PCSetFromOptions_FieldSplit(), but it is not ready yet */ 74497bbdb24SBarry Smith /* need to call this every time, since the jac->kspschur is freshly created, otherwise its options never get set */ 74597bbdb24SBarry Smith ierr = KSPSetFromOptions(jac->kspschur);CHKERRQ(ierr); 74697bbdb24SBarry Smith } 74797bbdb24SBarry Smith 7485a9f2f41SSatish Balay /* HACK: special support to forward L and Lp matrices that might be used by PCLSC */ 7498caf3d72SBarry Smith ierr = PetscSNPrintf(lscname,sizeof(lscname),"%s_LSC_L",ilink->splitname);CHKERRQ(ierr); 750519d70e2SJed Brown ierr = PetscObjectQuery((PetscObject)pc->mat,lscname,(PetscObject*)&LSC_L);CHKERRQ(ierr); 7513b224e63SBarry Smith if (!LSC_L) {ierr = PetscObjectQuery((PetscObject)pc->pmat,lscname,(PetscObject*)&LSC_L);CHKERRQ(ierr);} 752c1570756SJed Brown if (LSC_L) {ierr = PetscObjectCompose((PetscObject)jac->schur,"LSC_L",(PetscObject)LSC_L);CHKERRQ(ierr);} 7538caf3d72SBarry Smith ierr = PetscSNPrintf(lscname,sizeof(lscname),"%s_LSC_Lp",ilink->splitname);CHKERRQ(ierr); 75497bbdb24SBarry Smith ierr = PetscObjectQuery((PetscObject)pc->pmat,lscname,(PetscObject*)&LSC_L);CHKERRQ(ierr); 7555a9f2f41SSatish Balay if (!LSC_L) {ierr = PetscObjectQuery((PetscObject)pc->mat,lscname,(PetscObject*)&LSC_L);CHKERRQ(ierr);} 7560971522cSBarry Smith if (LSC_L) {ierr = PetscObjectCompose((PetscObject)jac->schur,"LSC_Lp",(PetscObject)LSC_L);CHKERRQ(ierr);} 75797bbdb24SBarry Smith } else { 75868bd789dSDmitry Karpeev /* set up the individual splits' PCs */ 7590971522cSBarry Smith i = 0; 7600971522cSBarry Smith ilink = jac->head; 7610971522cSBarry Smith while (ilink) { 7620971522cSBarry Smith ierr = KSPSetOperators(ilink->ksp,jac->mat[i],jac->pmat[i],flag);CHKERRQ(ierr); 7630971522cSBarry Smith /* really want setfromoptions called in PCSetFromOptions_FieldSplit(), but it is not ready yet */ 7640971522cSBarry Smith if (!jac->suboptionsset) {ierr = KSPSetFromOptions(ilink->ksp);CHKERRQ(ierr);} 7650971522cSBarry Smith i++; 7660971522cSBarry Smith ilink = ilink->next; 7670971522cSBarry Smith } 7683b224e63SBarry Smith } 7693b224e63SBarry Smith 770c1570756SJed Brown jac->suboptionsset = PETSC_TRUE; 7710971522cSBarry Smith PetscFunctionReturn(0); 7720971522cSBarry Smith } 7730971522cSBarry Smith 7745a9f2f41SSatish Balay #define FieldSplitSplitSolveAdd(ilink,xx,yy) \ 775ca9f406cSSatish Balay (VecScatterBegin(ilink->sctx,xx,ilink->x,INSERT_VALUES,SCATTER_FORWARD) || \ 776ca9f406cSSatish Balay VecScatterEnd(ilink->sctx,xx,ilink->x,INSERT_VALUES,SCATTER_FORWARD) || \ 7775a9f2f41SSatish Balay KSPSolve(ilink->ksp,ilink->x,ilink->y) || \ 778ca9f406cSSatish Balay VecScatterBegin(ilink->sctx,ilink->y,yy,ADD_VALUES,SCATTER_REVERSE) || \ 779ca9f406cSSatish Balay VecScatterEnd(ilink->sctx,ilink->y,yy,ADD_VALUES,SCATTER_REVERSE)) 78079416396SBarry Smith 7810971522cSBarry Smith #undef __FUNCT__ 7823b224e63SBarry Smith #define __FUNCT__ "PCApply_FieldSplit_Schur" 7833b224e63SBarry Smith static PetscErrorCode PCApply_FieldSplit_Schur(PC pc,Vec x,Vec y) 7843b224e63SBarry Smith { 7853b224e63SBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 7863b224e63SBarry Smith PetscErrorCode ierr; 7873b224e63SBarry Smith PC_FieldSplitLink ilinkA = jac->head, ilinkD = ilinkA->next; 788443836d0SMatthew G Knepley KSP kspA = ilinkA->ksp, kspLower = kspA, kspUpper = jac->kspupper; 7893b224e63SBarry Smith 7903b224e63SBarry Smith PetscFunctionBegin; 791c5d2311dSJed Brown switch (jac->schurfactorization) { 792c9c6ffaaSJed Brown case PC_FIELDSPLIT_SCHUR_FACT_DIAG: 793a04f6461SBarry Smith /* [A00 0; 0 -S], positive definite, suitable for MINRES */ 794c5d2311dSJed Brown ierr = VecScatterBegin(ilinkA->sctx,x,ilinkA->x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 795c5d2311dSJed Brown ierr = VecScatterBegin(ilinkD->sctx,x,ilinkD->x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 796c5d2311dSJed Brown ierr = VecScatterEnd(ilinkA->sctx,x,ilinkA->x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 797443836d0SMatthew G Knepley ierr = KSPSolve(kspA,ilinkA->x,ilinkA->y);CHKERRQ(ierr); 798c5d2311dSJed Brown ierr = VecScatterBegin(ilinkA->sctx,ilinkA->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 799c5d2311dSJed Brown ierr = VecScatterEnd(ilinkD->sctx,x,ilinkD->x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 800c5d2311dSJed Brown ierr = KSPSolve(jac->kspschur,ilinkD->x,ilinkD->y);CHKERRQ(ierr); 801c5d2311dSJed Brown ierr = VecScale(ilinkD->y,-1.);CHKERRQ(ierr); 802c5d2311dSJed Brown ierr = VecScatterBegin(ilinkD->sctx,ilinkD->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 803c5d2311dSJed Brown ierr = VecScatterEnd(ilinkA->sctx,ilinkA->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 804c5d2311dSJed Brown ierr = VecScatterEnd(ilinkD->sctx,ilinkD->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 805c5d2311dSJed Brown break; 806c9c6ffaaSJed Brown case PC_FIELDSPLIT_SCHUR_FACT_LOWER: 807a04f6461SBarry Smith /* [A00 0; A10 S], suitable for left preconditioning */ 808c5d2311dSJed Brown ierr = VecScatterBegin(ilinkA->sctx,x,ilinkA->x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 809c5d2311dSJed Brown ierr = VecScatterEnd(ilinkA->sctx,x,ilinkA->x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 810443836d0SMatthew G Knepley ierr = KSPSolve(kspA,ilinkA->x,ilinkA->y);CHKERRQ(ierr); 811c5d2311dSJed Brown ierr = MatMult(jac->C,ilinkA->y,ilinkD->x);CHKERRQ(ierr); 812c5d2311dSJed Brown ierr = VecScale(ilinkD->x,-1.);CHKERRQ(ierr); 813c5d2311dSJed Brown ierr = VecScatterBegin(ilinkD->sctx,x,ilinkD->x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 814c5d2311dSJed Brown ierr = VecScatterBegin(ilinkA->sctx,ilinkA->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 815c5d2311dSJed Brown ierr = VecScatterEnd(ilinkD->sctx,x,ilinkD->x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 816c5d2311dSJed Brown ierr = KSPSolve(jac->kspschur,ilinkD->x,ilinkD->y);CHKERRQ(ierr); 817c5d2311dSJed Brown ierr = VecScatterBegin(ilinkD->sctx,ilinkD->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 818c5d2311dSJed Brown ierr = VecScatterEnd(ilinkA->sctx,ilinkA->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 819c5d2311dSJed Brown ierr = VecScatterEnd(ilinkD->sctx,ilinkD->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 820c5d2311dSJed Brown break; 821c9c6ffaaSJed Brown case PC_FIELDSPLIT_SCHUR_FACT_UPPER: 822a04f6461SBarry Smith /* [A00 A01; 0 S], suitable for right preconditioning */ 823c5d2311dSJed Brown ierr = VecScatterBegin(ilinkD->sctx,x,ilinkD->x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 824c5d2311dSJed Brown ierr = VecScatterEnd(ilinkD->sctx,x,ilinkD->x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 825c5d2311dSJed Brown ierr = KSPSolve(jac->kspschur,ilinkD->x,ilinkD->y);CHKERRQ(ierr); 826c5d2311dSJed Brown ierr = MatMult(jac->B,ilinkD->y,ilinkA->x);CHKERRQ(ierr); 827c5d2311dSJed Brown ierr = VecScale(ilinkA->x,-1.);CHKERRQ(ierr); 828c5d2311dSJed Brown ierr = VecScatterBegin(ilinkA->sctx,x,ilinkA->x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 829c5d2311dSJed Brown ierr = VecScatterBegin(ilinkD->sctx,ilinkD->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 830c5d2311dSJed Brown ierr = VecScatterEnd(ilinkA->sctx,x,ilinkA->x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 831443836d0SMatthew G Knepley ierr = KSPSolve(kspA,ilinkA->x,ilinkA->y);CHKERRQ(ierr); 832c5d2311dSJed Brown ierr = VecScatterBegin(ilinkA->sctx,ilinkA->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 833c5d2311dSJed Brown ierr = VecScatterEnd(ilinkD->sctx,ilinkD->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 834c5d2311dSJed Brown ierr = VecScatterEnd(ilinkA->sctx,ilinkA->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 835c5d2311dSJed Brown break; 836c9c6ffaaSJed Brown case PC_FIELDSPLIT_SCHUR_FACT_FULL: 837a04f6461SBarry Smith /* [1 0; A10 A00^{-1} 1] [A00 0; 0 S] [1 A00^{-1}A01; 0 1], an exact solve if applied exactly, needs one extra solve with A */ 8383b224e63SBarry Smith ierr = VecScatterBegin(ilinkA->sctx,x,ilinkA->x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 8393b224e63SBarry Smith ierr = VecScatterEnd(ilinkA->sctx,x,ilinkA->x,INSERT_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 840443836d0SMatthew G Knepley ierr = KSPSolve(kspLower,ilinkA->x,ilinkA->y);CHKERRQ(ierr); 8413b224e63SBarry Smith ierr = MatMult(jac->C,ilinkA->y,ilinkD->x);CHKERRQ(ierr); 8423b224e63SBarry Smith ierr = VecScale(ilinkD->x,-1.0);CHKERRQ(ierr); 8433b224e63SBarry Smith ierr = VecScatterBegin(ilinkD->sctx,x,ilinkD->x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 8443b224e63SBarry Smith ierr = VecScatterEnd(ilinkD->sctx,x,ilinkD->x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 8453b224e63SBarry Smith 8463b224e63SBarry Smith ierr = KSPSolve(jac->kspschur,ilinkD->x,ilinkD->y);CHKERRQ(ierr); 8473b224e63SBarry Smith ierr = VecScatterBegin(ilinkD->sctx,ilinkD->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 8483b224e63SBarry Smith ierr = VecScatterEnd(ilinkD->sctx,ilinkD->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 8493b224e63SBarry Smith 850443836d0SMatthew G Knepley if (kspUpper == kspA) { 8513b224e63SBarry Smith ierr = MatMult(jac->B,ilinkD->y,ilinkA->y);CHKERRQ(ierr); 8523b224e63SBarry Smith ierr = VecAXPY(ilinkA->x,-1.0,ilinkA->y);CHKERRQ(ierr); 853443836d0SMatthew G Knepley ierr = KSPSolve(kspA,ilinkA->x,ilinkA->y);CHKERRQ(ierr); 854443836d0SMatthew G Knepley } else { 855443836d0SMatthew G Knepley ierr = KSPSolve(kspA,ilinkA->x,ilinkA->y);CHKERRQ(ierr); 856443836d0SMatthew G Knepley ierr = MatMult(jac->B,ilinkD->y,ilinkA->x);CHKERRQ(ierr); 857443836d0SMatthew G Knepley ierr = KSPSolve(kspUpper,ilinkA->x,ilinkA->z);CHKERRQ(ierr); 858443836d0SMatthew G Knepley ierr = VecAXPY(ilinkA->y,-1.0,ilinkA->z);CHKERRQ(ierr); 859443836d0SMatthew G Knepley } 8603b224e63SBarry Smith ierr = VecScatterBegin(ilinkA->sctx,ilinkA->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 8613b224e63SBarry Smith ierr = VecScatterEnd(ilinkA->sctx,ilinkA->y,y,INSERT_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 862c5d2311dSJed Brown } 8633b224e63SBarry Smith PetscFunctionReturn(0); 8643b224e63SBarry Smith } 8653b224e63SBarry Smith 8663b224e63SBarry Smith #undef __FUNCT__ 8670971522cSBarry Smith #define __FUNCT__ "PCApply_FieldSplit" 8680971522cSBarry Smith static PetscErrorCode PCApply_FieldSplit(PC pc,Vec x,Vec y) 8690971522cSBarry Smith { 8700971522cSBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 8710971522cSBarry Smith PetscErrorCode ierr; 8725a9f2f41SSatish Balay PC_FieldSplitLink ilink = jac->head; 873939b8a20SBarry Smith PetscInt cnt,bs; 8740971522cSBarry Smith 8750971522cSBarry Smith PetscFunctionBegin; 87679416396SBarry Smith if (jac->type == PC_COMPOSITE_ADDITIVE) { 8771b9fc7fcSBarry Smith if (jac->defaultsplit) { 878939b8a20SBarry Smith ierr = VecGetBlockSize(x,&bs);CHKERRQ(ierr); 879ce94432eSBarry Smith if (jac->bs > 0 && bs != jac->bs) SETERRQ2(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_WRONGSTATE,"Blocksize of x vector %D does not match fieldsplit blocksize %D",bs,jac->bs); 880939b8a20SBarry Smith ierr = VecGetBlockSize(y,&bs);CHKERRQ(ierr); 881ce94432eSBarry Smith if (jac->bs > 0 && bs != jac->bs) SETERRQ2(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_WRONGSTATE,"Blocksize of y vector %D does not match fieldsplit blocksize %D",bs,jac->bs); 8820971522cSBarry Smith ierr = VecStrideGatherAll(x,jac->x,INSERT_VALUES);CHKERRQ(ierr); 8835a9f2f41SSatish Balay while (ilink) { 8845a9f2f41SSatish Balay ierr = KSPSolve(ilink->ksp,ilink->x,ilink->y);CHKERRQ(ierr); 8855a9f2f41SSatish Balay ilink = ilink->next; 8860971522cSBarry Smith } 8870971522cSBarry Smith ierr = VecStrideScatterAll(jac->y,y,INSERT_VALUES);CHKERRQ(ierr); 8881b9fc7fcSBarry Smith } else { 889efb30889SBarry Smith ierr = VecSet(y,0.0);CHKERRQ(ierr); 8905a9f2f41SSatish Balay while (ilink) { 8915a9f2f41SSatish Balay ierr = FieldSplitSplitSolveAdd(ilink,x,y);CHKERRQ(ierr); 8925a9f2f41SSatish Balay ilink = ilink->next; 8931b9fc7fcSBarry Smith } 8941b9fc7fcSBarry Smith } 89516913363SBarry Smith } else if (jac->type == PC_COMPOSITE_MULTIPLICATIVE || jac->type == PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE) { 89679416396SBarry Smith if (!jac->w1) { 89779416396SBarry Smith ierr = VecDuplicate(x,&jac->w1);CHKERRQ(ierr); 89879416396SBarry Smith ierr = VecDuplicate(x,&jac->w2);CHKERRQ(ierr); 89979416396SBarry Smith } 900efb30889SBarry Smith ierr = VecSet(y,0.0);CHKERRQ(ierr); 9015a9f2f41SSatish Balay ierr = FieldSplitSplitSolveAdd(ilink,x,y);CHKERRQ(ierr); 9023e197d65SBarry Smith cnt = 1; 9035a9f2f41SSatish Balay while (ilink->next) { 9045a9f2f41SSatish Balay ilink = ilink->next; 9053e197d65SBarry Smith /* compute the residual only over the part of the vector needed */ 9063e197d65SBarry Smith ierr = MatMult(jac->Afield[cnt++],y,ilink->x);CHKERRQ(ierr); 9073e197d65SBarry Smith ierr = VecScale(ilink->x,-1.0);CHKERRQ(ierr); 9083e197d65SBarry Smith ierr = VecScatterBegin(ilink->sctx,x,ilink->x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 9093e197d65SBarry Smith ierr = VecScatterEnd(ilink->sctx,x,ilink->x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 9103e197d65SBarry Smith ierr = KSPSolve(ilink->ksp,ilink->x,ilink->y);CHKERRQ(ierr); 9113e197d65SBarry Smith ierr = VecScatterBegin(ilink->sctx,ilink->y,y,ADD_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 9123e197d65SBarry Smith ierr = VecScatterEnd(ilink->sctx,ilink->y,y,ADD_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 9133e197d65SBarry Smith } 91451f519a2SBarry Smith if (jac->type == PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE) { 91511755939SBarry Smith cnt -= 2; 91651f519a2SBarry Smith while (ilink->previous) { 91751f519a2SBarry Smith ilink = ilink->previous; 91811755939SBarry Smith /* compute the residual only over the part of the vector needed */ 91911755939SBarry Smith ierr = MatMult(jac->Afield[cnt--],y,ilink->x);CHKERRQ(ierr); 92011755939SBarry Smith ierr = VecScale(ilink->x,-1.0);CHKERRQ(ierr); 92111755939SBarry Smith ierr = VecScatterBegin(ilink->sctx,x,ilink->x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 92211755939SBarry Smith ierr = VecScatterEnd(ilink->sctx,x,ilink->x,ADD_VALUES,SCATTER_FORWARD);CHKERRQ(ierr); 92311755939SBarry Smith ierr = KSPSolve(ilink->ksp,ilink->x,ilink->y);CHKERRQ(ierr); 92411755939SBarry Smith ierr = VecScatterBegin(ilink->sctx,ilink->y,y,ADD_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 92511755939SBarry Smith ierr = VecScatterEnd(ilink->sctx,ilink->y,y,ADD_VALUES,SCATTER_REVERSE);CHKERRQ(ierr); 92651f519a2SBarry Smith } 92711755939SBarry Smith } 928ce94432eSBarry Smith } else SETERRQ1(PetscObjectComm((PetscObject)pc),PETSC_ERR_SUP,"Unsupported or unknown composition",(int) jac->type); 9290971522cSBarry Smith PetscFunctionReturn(0); 9300971522cSBarry Smith } 9310971522cSBarry Smith 932421e10b8SBarry Smith #define FieldSplitSplitSolveAddTranspose(ilink,xx,yy) \ 933ca9f406cSSatish Balay (VecScatterBegin(ilink->sctx,xx,ilink->y,INSERT_VALUES,SCATTER_FORWARD) || \ 934ca9f406cSSatish Balay VecScatterEnd(ilink->sctx,xx,ilink->y,INSERT_VALUES,SCATTER_FORWARD) || \ 935421e10b8SBarry Smith KSPSolveTranspose(ilink->ksp,ilink->y,ilink->x) || \ 936ca9f406cSSatish Balay VecScatterBegin(ilink->sctx,ilink->x,yy,ADD_VALUES,SCATTER_REVERSE) || \ 937ca9f406cSSatish Balay VecScatterEnd(ilink->sctx,ilink->x,yy,ADD_VALUES,SCATTER_REVERSE)) 938421e10b8SBarry Smith 939421e10b8SBarry Smith #undef __FUNCT__ 9408c03b21aSDmitry Karpeev #define __FUNCT__ "PCApplyTranspose_FieldSplit" 941421e10b8SBarry Smith static PetscErrorCode PCApplyTranspose_FieldSplit(PC pc,Vec x,Vec y) 942421e10b8SBarry Smith { 943421e10b8SBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 944421e10b8SBarry Smith PetscErrorCode ierr; 945421e10b8SBarry Smith PC_FieldSplitLink ilink = jac->head; 946939b8a20SBarry Smith PetscInt bs; 947421e10b8SBarry Smith 948421e10b8SBarry Smith PetscFunctionBegin; 949421e10b8SBarry Smith if (jac->type == PC_COMPOSITE_ADDITIVE) { 950421e10b8SBarry Smith if (jac->defaultsplit) { 951939b8a20SBarry Smith ierr = VecGetBlockSize(x,&bs);CHKERRQ(ierr); 952ce94432eSBarry Smith if (jac->bs > 0 && bs != jac->bs) SETERRQ2(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_WRONGSTATE,"Blocksize of x vector %D does not match fieldsplit blocksize %D",bs,jac->bs); 953939b8a20SBarry Smith ierr = VecGetBlockSize(y,&bs);CHKERRQ(ierr); 954ce94432eSBarry Smith if (jac->bs > 0 && bs != jac->bs) SETERRQ2(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_WRONGSTATE,"Blocksize of y vector %D does not match fieldsplit blocksize %D",bs,jac->bs); 955421e10b8SBarry Smith ierr = VecStrideGatherAll(x,jac->x,INSERT_VALUES);CHKERRQ(ierr); 956421e10b8SBarry Smith while (ilink) { 957421e10b8SBarry Smith ierr = KSPSolveTranspose(ilink->ksp,ilink->x,ilink->y);CHKERRQ(ierr); 958421e10b8SBarry Smith ilink = ilink->next; 959421e10b8SBarry Smith } 960421e10b8SBarry Smith ierr = VecStrideScatterAll(jac->y,y,INSERT_VALUES);CHKERRQ(ierr); 961421e10b8SBarry Smith } else { 962421e10b8SBarry Smith ierr = VecSet(y,0.0);CHKERRQ(ierr); 963421e10b8SBarry Smith while (ilink) { 964421e10b8SBarry Smith ierr = FieldSplitSplitSolveAddTranspose(ilink,x,y);CHKERRQ(ierr); 965421e10b8SBarry Smith ilink = ilink->next; 966421e10b8SBarry Smith } 967421e10b8SBarry Smith } 968421e10b8SBarry Smith } else { 969421e10b8SBarry Smith if (!jac->w1) { 970421e10b8SBarry Smith ierr = VecDuplicate(x,&jac->w1);CHKERRQ(ierr); 971421e10b8SBarry Smith ierr = VecDuplicate(x,&jac->w2);CHKERRQ(ierr); 972421e10b8SBarry Smith } 973421e10b8SBarry Smith ierr = VecSet(y,0.0);CHKERRQ(ierr); 974421e10b8SBarry Smith if (jac->type == PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE) { 975421e10b8SBarry Smith ierr = FieldSplitSplitSolveAddTranspose(ilink,x,y);CHKERRQ(ierr); 976421e10b8SBarry Smith while (ilink->next) { 977421e10b8SBarry Smith ilink = ilink->next; 9789989ab13SBarry Smith ierr = MatMultTranspose(pc->mat,y,jac->w1);CHKERRQ(ierr); 979421e10b8SBarry Smith ierr = VecWAXPY(jac->w2,-1.0,jac->w1,x);CHKERRQ(ierr); 980421e10b8SBarry Smith ierr = FieldSplitSplitSolveAddTranspose(ilink,jac->w2,y);CHKERRQ(ierr); 981421e10b8SBarry Smith } 982421e10b8SBarry Smith while (ilink->previous) { 983421e10b8SBarry Smith ilink = ilink->previous; 9849989ab13SBarry Smith ierr = MatMultTranspose(pc->mat,y,jac->w1);CHKERRQ(ierr); 985421e10b8SBarry Smith ierr = VecWAXPY(jac->w2,-1.0,jac->w1,x);CHKERRQ(ierr); 986421e10b8SBarry Smith ierr = FieldSplitSplitSolveAddTranspose(ilink,jac->w2,y);CHKERRQ(ierr); 987421e10b8SBarry Smith } 988421e10b8SBarry Smith } else { 989421e10b8SBarry Smith while (ilink->next) { /* get to last entry in linked list */ 990421e10b8SBarry Smith ilink = ilink->next; 991421e10b8SBarry Smith } 992421e10b8SBarry Smith ierr = FieldSplitSplitSolveAddTranspose(ilink,x,y);CHKERRQ(ierr); 993421e10b8SBarry Smith while (ilink->previous) { 994421e10b8SBarry Smith ilink = ilink->previous; 9959989ab13SBarry Smith ierr = MatMultTranspose(pc->mat,y,jac->w1);CHKERRQ(ierr); 996421e10b8SBarry Smith ierr = VecWAXPY(jac->w2,-1.0,jac->w1,x);CHKERRQ(ierr); 997421e10b8SBarry Smith ierr = FieldSplitSplitSolveAddTranspose(ilink,jac->w2,y);CHKERRQ(ierr); 998421e10b8SBarry Smith } 999421e10b8SBarry Smith } 1000421e10b8SBarry Smith } 1001421e10b8SBarry Smith PetscFunctionReturn(0); 1002421e10b8SBarry Smith } 1003421e10b8SBarry Smith 10040971522cSBarry Smith #undef __FUNCT__ 1005574deadeSBarry Smith #define __FUNCT__ "PCReset_FieldSplit" 1006574deadeSBarry Smith static PetscErrorCode PCReset_FieldSplit(PC pc) 10070971522cSBarry Smith { 10080971522cSBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 10090971522cSBarry Smith PetscErrorCode ierr; 10105a9f2f41SSatish Balay PC_FieldSplitLink ilink = jac->head,next; 10110971522cSBarry Smith 10120971522cSBarry Smith PetscFunctionBegin; 10135a9f2f41SSatish Balay while (ilink) { 1014574deadeSBarry Smith ierr = KSPReset(ilink->ksp);CHKERRQ(ierr); 1015fcfd50ebSBarry Smith ierr = VecDestroy(&ilink->x);CHKERRQ(ierr); 1016fcfd50ebSBarry Smith ierr = VecDestroy(&ilink->y);CHKERRQ(ierr); 1017443836d0SMatthew G Knepley ierr = VecDestroy(&ilink->z);CHKERRQ(ierr); 1018fcfd50ebSBarry Smith ierr = VecScatterDestroy(&ilink->sctx);CHKERRQ(ierr); 1019fcfd50ebSBarry Smith ierr = ISDestroy(&ilink->is);CHKERRQ(ierr); 1020b5787286SJed Brown ierr = ISDestroy(&ilink->is_col);CHKERRQ(ierr); 10215a9f2f41SSatish Balay next = ilink->next; 10225a9f2f41SSatish Balay ilink = next; 10230971522cSBarry Smith } 102405b42c5fSBarry Smith ierr = PetscFree2(jac->x,jac->y);CHKERRQ(ierr); 1025574deadeSBarry Smith if (jac->mat && jac->mat != jac->pmat) { 1026574deadeSBarry Smith ierr = MatDestroyMatrices(jac->nsplits,&jac->mat);CHKERRQ(ierr); 1027574deadeSBarry Smith } else if (jac->mat) { 10280298fd71SBarry Smith jac->mat = NULL; 1029574deadeSBarry Smith } 103097bbdb24SBarry Smith if (jac->pmat) {ierr = MatDestroyMatrices(jac->nsplits,&jac->pmat);CHKERRQ(ierr);} 103168dd23aaSBarry Smith if (jac->Afield) {ierr = MatDestroyMatrices(jac->nsplits,&jac->Afield);CHKERRQ(ierr);} 10326bf464f9SBarry Smith ierr = VecDestroy(&jac->w1);CHKERRQ(ierr); 10336bf464f9SBarry Smith ierr = VecDestroy(&jac->w2);CHKERRQ(ierr); 10346bf464f9SBarry Smith ierr = MatDestroy(&jac->schur);CHKERRQ(ierr); 10356bf464f9SBarry Smith ierr = MatDestroy(&jac->schur_user);CHKERRQ(ierr); 10366bf464f9SBarry Smith ierr = KSPDestroy(&jac->kspschur);CHKERRQ(ierr); 1037d78dad28SBarry Smith ierr = KSPDestroy(&jac->kspupper);CHKERRQ(ierr); 10386bf464f9SBarry Smith ierr = MatDestroy(&jac->B);CHKERRQ(ierr); 10396bf464f9SBarry Smith ierr = MatDestroy(&jac->C);CHKERRQ(ierr); 104063ec74ffSBarry Smith jac->reset = PETSC_TRUE; 1041574deadeSBarry Smith PetscFunctionReturn(0); 1042574deadeSBarry Smith } 1043574deadeSBarry Smith 1044574deadeSBarry Smith #undef __FUNCT__ 1045574deadeSBarry Smith #define __FUNCT__ "PCDestroy_FieldSplit" 1046574deadeSBarry Smith static PetscErrorCode PCDestroy_FieldSplit(PC pc) 1047574deadeSBarry Smith { 1048574deadeSBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 1049574deadeSBarry Smith PetscErrorCode ierr; 1050574deadeSBarry Smith PC_FieldSplitLink ilink = jac->head,next; 1051574deadeSBarry Smith 1052574deadeSBarry Smith PetscFunctionBegin; 1053574deadeSBarry Smith ierr = PCReset_FieldSplit(pc);CHKERRQ(ierr); 1054574deadeSBarry Smith while (ilink) { 10556bf464f9SBarry Smith ierr = KSPDestroy(&ilink->ksp);CHKERRQ(ierr); 1056574deadeSBarry Smith next = ilink->next; 1057574deadeSBarry Smith ierr = PetscFree(ilink->splitname);CHKERRQ(ierr); 1058574deadeSBarry Smith ierr = PetscFree(ilink->fields);CHKERRQ(ierr); 10595d4c12cdSJungho Lee ierr = PetscFree(ilink->fields_col);CHKERRQ(ierr); 1060574deadeSBarry Smith ierr = PetscFree(ilink);CHKERRQ(ierr); 1061574deadeSBarry Smith ilink = next; 1062574deadeSBarry Smith } 1063574deadeSBarry Smith ierr = PetscFree2(jac->x,jac->y);CHKERRQ(ierr); 1064c31cb41cSBarry Smith ierr = PetscFree(pc->data);CHKERRQ(ierr); 1065bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitGetSubKSP_C",NULL);CHKERRQ(ierr); 1066bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetFields_C",NULL);CHKERRQ(ierr); 1067bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetIS_C",NULL);CHKERRQ(ierr); 1068bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetType_C",NULL);CHKERRQ(ierr); 1069bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetBlockSize_C",NULL);CHKERRQ(ierr); 1070bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSchurPrecondition_C",NULL);CHKERRQ(ierr); 1071bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetSchurFactType_C",NULL);CHKERRQ(ierr); 10720971522cSBarry Smith PetscFunctionReturn(0); 10730971522cSBarry Smith } 10740971522cSBarry Smith 10750971522cSBarry Smith #undef __FUNCT__ 10760971522cSBarry Smith #define __FUNCT__ "PCSetFromOptions_FieldSplit" 10770971522cSBarry Smith static PetscErrorCode PCSetFromOptions_FieldSplit(PC pc) 10780971522cSBarry Smith { 10791b9fc7fcSBarry Smith PetscErrorCode ierr; 10806c924f48SJed Brown PetscInt bs; 1081bc59fbc5SBarry Smith PetscBool flg,stokes = PETSC_FALSE; 10829dcbbd2bSBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 10833b224e63SBarry Smith PCCompositeType ctype; 10841b9fc7fcSBarry Smith 10850971522cSBarry Smith PetscFunctionBegin; 10861b9fc7fcSBarry Smith ierr = PetscOptionsHead("FieldSplit options");CHKERRQ(ierr); 10874ab8060aSDmitry Karpeev ierr = PetscOptionsBool("-pc_fieldsplit_dm_splits","Whether to use DMCreateFieldDecomposition() for splits","PCFieldSplitSetDMSplits",jac->dm_splits,&jac->dm_splits,NULL);CHKERRQ(ierr); 108851f519a2SBarry Smith ierr = PetscOptionsInt("-pc_fieldsplit_block_size","Blocksize that defines number of fields","PCFieldSplitSetBlockSize",jac->bs,&bs,&flg);CHKERRQ(ierr); 108951f519a2SBarry Smith if (flg) { 109051f519a2SBarry Smith ierr = PCFieldSplitSetBlockSize(pc,bs);CHKERRQ(ierr); 109151f519a2SBarry Smith } 1092704ba839SBarry Smith 10930298fd71SBarry Smith ierr = PetscOptionsGetBool(((PetscObject)pc)->prefix,"-pc_fieldsplit_detect_saddle_point",&stokes,NULL);CHKERRQ(ierr); 1094c0adfefeSBarry Smith if (stokes) { 1095c0adfefeSBarry Smith ierr = PCFieldSplitSetType(pc,PC_COMPOSITE_SCHUR);CHKERRQ(ierr); 1096c0adfefeSBarry Smith jac->schurpre = PC_FIELDSPLIT_SCHUR_PRE_SELF; 1097c0adfefeSBarry Smith } 1098c0adfefeSBarry Smith 10993b224e63SBarry Smith ierr = PetscOptionsEnum("-pc_fieldsplit_type","Type of composition","PCFieldSplitSetType",PCCompositeTypes,(PetscEnum)jac->type,(PetscEnum*)&ctype,&flg);CHKERRQ(ierr); 11003b224e63SBarry Smith if (flg) { 11013b224e63SBarry Smith ierr = PCFieldSplitSetType(pc,ctype);CHKERRQ(ierr); 11023b224e63SBarry Smith } 1103c30613efSMatthew Knepley /* Only setup fields once */ 1104c30613efSMatthew Knepley if ((jac->bs > 0) && (jac->nsplits == 0)) { 1105d32f9abdSBarry Smith /* only allow user to set fields from command line if bs is already known. 1106d32f9abdSBarry Smith otherwise user can set them in PCFieldSplitSetDefaults() */ 11076c924f48SJed Brown ierr = PCFieldSplitSetRuntimeSplits_Private(pc);CHKERRQ(ierr); 11086c924f48SJed Brown if (jac->splitdefined) {ierr = PetscInfo(pc,"Splits defined using the options database\n");CHKERRQ(ierr);} 1109d32f9abdSBarry Smith } 1110c5d2311dSJed Brown if (jac->type == PC_COMPOSITE_SCHUR) { 1111c9c6ffaaSJed Brown ierr = PetscOptionsGetEnum(((PetscObject)pc)->prefix,"-pc_fieldsplit_schur_factorization_type",PCFieldSplitSchurFactTypes,(PetscEnum*)&jac->schurfactorization,&flg);CHKERRQ(ierr); 1112c9c6ffaaSJed Brown if (flg) {ierr = PetscInfo(pc,"Deprecated use of -pc_fieldsplit_schur_factorization_type\n");CHKERRQ(ierr);} 11130298fd71SBarry Smith ierr = PetscOptionsEnum("-pc_fieldsplit_schur_fact_type","Which off-diagonal parts of the block factorization to use","PCFieldSplitSetSchurFactType",PCFieldSplitSchurFactTypes,(PetscEnum)jac->schurfactorization,(PetscEnum*)&jac->schurfactorization,NULL);CHKERRQ(ierr); 11140298fd71SBarry Smith ierr = PetscOptionsEnum("-pc_fieldsplit_schur_precondition","How to build preconditioner for Schur complement","PCFieldSplitSchurPrecondition",PCFieldSplitSchurPreTypes,(PetscEnum)jac->schurpre,(PetscEnum*)&jac->schurpre,NULL);CHKERRQ(ierr); 1115c5d2311dSJed Brown } 11161b9fc7fcSBarry Smith ierr = PetscOptionsTail();CHKERRQ(ierr); 11170971522cSBarry Smith PetscFunctionReturn(0); 11180971522cSBarry Smith } 11190971522cSBarry Smith 11200971522cSBarry Smith /*------------------------------------------------------------------------------------*/ 11210971522cSBarry Smith 11220971522cSBarry Smith #undef __FUNCT__ 11230971522cSBarry Smith #define __FUNCT__ "PCFieldSplitSetFields_FieldSplit" 11241e6b0712SBarry Smith static PetscErrorCode PCFieldSplitSetFields_FieldSplit(PC pc,const char splitname[],PetscInt n,const PetscInt *fields,const PetscInt *fields_col) 11250971522cSBarry Smith { 112697bbdb24SBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 11270971522cSBarry Smith PetscErrorCode ierr; 11285a9f2f41SSatish Balay PC_FieldSplitLink ilink,next = jac->head; 112969a612a9SBarry Smith char prefix[128]; 11305d4c12cdSJungho Lee PetscInt i; 11310971522cSBarry Smith 11320971522cSBarry Smith PetscFunctionBegin; 11336c924f48SJed Brown if (jac->splitdefined) { 11346c924f48SJed Brown ierr = PetscInfo1(pc,"Ignoring new split \"%s\" because the splits have already been defined\n",splitname);CHKERRQ(ierr); 11356c924f48SJed Brown PetscFunctionReturn(0); 11366c924f48SJed Brown } 113751f519a2SBarry Smith for (i=0; i<n; i++) { 1138e32f2f54SBarry Smith if (fields[i] >= jac->bs) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Field %D requested but only %D exist",fields[i],jac->bs); 1139e32f2f54SBarry Smith if (fields[i] < 0) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Negative field %D requested",fields[i]); 114051f519a2SBarry Smith } 1141b00a9115SJed Brown ierr = PetscNew(&ilink);CHKERRQ(ierr); 1142a04f6461SBarry Smith if (splitname) { 1143db4c96c1SJed Brown ierr = PetscStrallocpy(splitname,&ilink->splitname);CHKERRQ(ierr); 1144a04f6461SBarry Smith } else { 1145785e854fSJed Brown ierr = PetscMalloc1(3,&ilink->splitname);CHKERRQ(ierr); 1146a04f6461SBarry Smith ierr = PetscSNPrintf(ilink->splitname,2,"%s",jac->nsplits);CHKERRQ(ierr); 1147a04f6461SBarry Smith } 1148785e854fSJed Brown ierr = PetscMalloc1(n,&ilink->fields);CHKERRQ(ierr); 11495a9f2f41SSatish Balay ierr = PetscMemcpy(ilink->fields,fields,n*sizeof(PetscInt));CHKERRQ(ierr); 1150785e854fSJed Brown ierr = PetscMalloc1(n,&ilink->fields_col);CHKERRQ(ierr); 11515d4c12cdSJungho Lee ierr = PetscMemcpy(ilink->fields_col,fields_col,n*sizeof(PetscInt));CHKERRQ(ierr); 11522fa5cd67SKarl Rupp 11535a9f2f41SSatish Balay ilink->nfields = n; 11540298fd71SBarry Smith ilink->next = NULL; 1155ce94432eSBarry Smith ierr = KSPCreate(PetscObjectComm((PetscObject)pc),&ilink->ksp);CHKERRQ(ierr); 115620252d06SBarry Smith ierr = PetscObjectIncrementTabLevel((PetscObject)ilink->ksp,(PetscObject)pc,1);CHKERRQ(ierr); 11575a9f2f41SSatish Balay ierr = KSPSetType(ilink->ksp,KSPPREONLY);CHKERRQ(ierr); 11589005cf84SBarry Smith ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)ilink->ksp);CHKERRQ(ierr); 115969a612a9SBarry Smith 11608caf3d72SBarry Smith ierr = PetscSNPrintf(prefix,sizeof(prefix),"%sfieldsplit_%s_",((PetscObject)pc)->prefix ? ((PetscObject)pc)->prefix : "",ilink->splitname);CHKERRQ(ierr); 11615a9f2f41SSatish Balay ierr = KSPSetOptionsPrefix(ilink->ksp,prefix);CHKERRQ(ierr); 11620971522cSBarry Smith 11630971522cSBarry Smith if (!next) { 11645a9f2f41SSatish Balay jac->head = ilink; 11650298fd71SBarry Smith ilink->previous = NULL; 11660971522cSBarry Smith } else { 11670971522cSBarry Smith while (next->next) { 11680971522cSBarry Smith next = next->next; 11690971522cSBarry Smith } 11705a9f2f41SSatish Balay next->next = ilink; 117151f519a2SBarry Smith ilink->previous = next; 11720971522cSBarry Smith } 11730971522cSBarry Smith jac->nsplits++; 11740971522cSBarry Smith PetscFunctionReturn(0); 11750971522cSBarry Smith } 11760971522cSBarry Smith 1177e69d4d44SBarry Smith #undef __FUNCT__ 1178e69d4d44SBarry Smith #define __FUNCT__ "PCFieldSplitGetSubKSP_FieldSplit_Schur" 11791e6b0712SBarry Smith static PetscErrorCode PCFieldSplitGetSubKSP_FieldSplit_Schur(PC pc,PetscInt *n,KSP **subksp) 1180e69d4d44SBarry Smith { 1181e69d4d44SBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 1182e69d4d44SBarry Smith PetscErrorCode ierr; 1183e69d4d44SBarry Smith 1184e69d4d44SBarry Smith PetscFunctionBegin; 1185785e854fSJed Brown ierr = PetscMalloc1(jac->nsplits,subksp);CHKERRQ(ierr); 1186e69d4d44SBarry Smith ierr = MatSchurComplementGetKSP(jac->schur,*subksp);CHKERRQ(ierr); 11872fa5cd67SKarl Rupp 1188e69d4d44SBarry Smith (*subksp)[1] = jac->kspschur; 118913e0d083SBarry Smith if (n) *n = jac->nsplits; 1190e69d4d44SBarry Smith PetscFunctionReturn(0); 1191e69d4d44SBarry Smith } 11920971522cSBarry Smith 11930971522cSBarry Smith #undef __FUNCT__ 119469a612a9SBarry Smith #define __FUNCT__ "PCFieldSplitGetSubKSP_FieldSplit" 11951e6b0712SBarry Smith static PetscErrorCode PCFieldSplitGetSubKSP_FieldSplit(PC pc,PetscInt *n,KSP **subksp) 11960971522cSBarry Smith { 11970971522cSBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 11980971522cSBarry Smith PetscErrorCode ierr; 11990971522cSBarry Smith PetscInt cnt = 0; 12005a9f2f41SSatish Balay PC_FieldSplitLink ilink = jac->head; 12010971522cSBarry Smith 12020971522cSBarry Smith PetscFunctionBegin; 1203785e854fSJed Brown ierr = PetscMalloc1(jac->nsplits,subksp);CHKERRQ(ierr); 12045a9f2f41SSatish Balay while (ilink) { 12055a9f2f41SSatish Balay (*subksp)[cnt++] = ilink->ksp; 12065a9f2f41SSatish Balay ilink = ilink->next; 12070971522cSBarry Smith } 12085d480477SMatthew G Knepley if (cnt != jac->nsplits) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_PLIB,"Corrupt PCFIELDSPLIT object: number of splits in linked list %D does not match number in object %D",cnt,jac->nsplits); 120913e0d083SBarry Smith if (n) *n = jac->nsplits; 12100971522cSBarry Smith PetscFunctionReturn(0); 12110971522cSBarry Smith } 12120971522cSBarry Smith 1213704ba839SBarry Smith #undef __FUNCT__ 1214704ba839SBarry Smith #define __FUNCT__ "PCFieldSplitSetIS_FieldSplit" 12151e6b0712SBarry Smith static PetscErrorCode PCFieldSplitSetIS_FieldSplit(PC pc,const char splitname[],IS is) 1216704ba839SBarry Smith { 1217704ba839SBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 1218704ba839SBarry Smith PetscErrorCode ierr; 1219704ba839SBarry Smith PC_FieldSplitLink ilink, next = jac->head; 1220704ba839SBarry Smith char prefix[128]; 1221704ba839SBarry Smith 1222704ba839SBarry Smith PetscFunctionBegin; 12236c924f48SJed Brown if (jac->splitdefined) { 12246c924f48SJed Brown ierr = PetscInfo1(pc,"Ignoring new split \"%s\" because the splits have already been defined\n",splitname);CHKERRQ(ierr); 12256c924f48SJed Brown PetscFunctionReturn(0); 12266c924f48SJed Brown } 1227b00a9115SJed Brown ierr = PetscNew(&ilink);CHKERRQ(ierr); 1228a04f6461SBarry Smith if (splitname) { 1229db4c96c1SJed Brown ierr = PetscStrallocpy(splitname,&ilink->splitname);CHKERRQ(ierr); 1230a04f6461SBarry Smith } else { 1231785e854fSJed Brown ierr = PetscMalloc1(8,&ilink->splitname);CHKERRQ(ierr); 1232b5787286SJed Brown ierr = PetscSNPrintf(ilink->splitname,7,"%D",jac->nsplits);CHKERRQ(ierr); 1233a04f6461SBarry Smith } 12341ab39975SBarry Smith ierr = PetscObjectReference((PetscObject)is);CHKERRQ(ierr); 1235b5787286SJed Brown ierr = ISDestroy(&ilink->is);CHKERRQ(ierr); 1236b5787286SJed Brown ilink->is = is; 1237b5787286SJed Brown ierr = PetscObjectReference((PetscObject)is);CHKERRQ(ierr); 1238b5787286SJed Brown ierr = ISDestroy(&ilink->is_col);CHKERRQ(ierr); 1239b5787286SJed Brown ilink->is_col = is; 12400298fd71SBarry Smith ilink->next = NULL; 1241ce94432eSBarry Smith ierr = KSPCreate(PetscObjectComm((PetscObject)pc),&ilink->ksp);CHKERRQ(ierr); 124220252d06SBarry Smith ierr = PetscObjectIncrementTabLevel((PetscObject)ilink->ksp,(PetscObject)pc,1);CHKERRQ(ierr); 1243704ba839SBarry Smith ierr = KSPSetType(ilink->ksp,KSPPREONLY);CHKERRQ(ierr); 12449005cf84SBarry Smith ierr = PetscLogObjectParent((PetscObject)pc,(PetscObject)ilink->ksp);CHKERRQ(ierr); 1245704ba839SBarry Smith 12468caf3d72SBarry Smith ierr = PetscSNPrintf(prefix,sizeof(prefix),"%sfieldsplit_%s_",((PetscObject)pc)->prefix ? ((PetscObject)pc)->prefix : "",ilink->splitname);CHKERRQ(ierr); 1247704ba839SBarry Smith ierr = KSPSetOptionsPrefix(ilink->ksp,prefix);CHKERRQ(ierr); 1248704ba839SBarry Smith 1249704ba839SBarry Smith if (!next) { 1250704ba839SBarry Smith jac->head = ilink; 12510298fd71SBarry Smith ilink->previous = NULL; 1252704ba839SBarry Smith } else { 1253704ba839SBarry Smith while (next->next) { 1254704ba839SBarry Smith next = next->next; 1255704ba839SBarry Smith } 1256704ba839SBarry Smith next->next = ilink; 1257704ba839SBarry Smith ilink->previous = next; 1258704ba839SBarry Smith } 1259704ba839SBarry Smith jac->nsplits++; 1260704ba839SBarry Smith PetscFunctionReturn(0); 1261704ba839SBarry Smith } 1262704ba839SBarry Smith 12630971522cSBarry Smith #undef __FUNCT__ 12640971522cSBarry Smith #define __FUNCT__ "PCFieldSplitSetFields" 12650971522cSBarry Smith /*@ 12660971522cSBarry Smith PCFieldSplitSetFields - Sets the fields for one particular split in the field split preconditioner 12670971522cSBarry Smith 1268ad4df100SBarry Smith Logically Collective on PC 12690971522cSBarry Smith 12700971522cSBarry Smith Input Parameters: 12710971522cSBarry Smith + pc - the preconditioner context 12720298fd71SBarry Smith . splitname - name of this split, if NULL the number of the split is used 12730971522cSBarry Smith . n - the number of fields in this split 1274db4c96c1SJed Brown - fields - the fields in this split 12750971522cSBarry Smith 12760971522cSBarry Smith Level: intermediate 12770971522cSBarry Smith 1278d32f9abdSBarry Smith Notes: Use PCFieldSplitSetIS() to set a completely general set of indices as a field. 1279d32f9abdSBarry Smith 12807287d2a3SDmitry Karpeev The PCFieldSplitSetFields() is for defining fields as strided blocks. For example, if the block 1281d32f9abdSBarry Smith size is three then one can define a field as 0, or 1 or 2 or 0,1 or 0,2 or 1,2 which mean 1282d32f9abdSBarry Smith 0xx3xx6xx9xx12 ... x1xx4xx7xx ... xx2xx5xx8xx.. 01x34x67x... 0x1x3x5x7.. x12x45x78x.... 1283d32f9abdSBarry Smith where the numbered entries indicate what is in the field. 1284d32f9abdSBarry Smith 1285db4c96c1SJed Brown This function is called once per split (it creates a new split each time). Solve options 1286db4c96c1SJed Brown for this split will be available under the prefix -fieldsplit_SPLITNAME_. 1287db4c96c1SJed Brown 12885d4c12cdSJungho Lee Developer Note: This routine does not actually create the IS representing the split, that is delayed 12895d4c12cdSJungho Lee until PCSetUp_FieldSplit(), because information about the vector/matrix layouts may not be 12905d4c12cdSJungho Lee available when this routine is called. 12915d4c12cdSJungho Lee 1292d32f9abdSBarry Smith .seealso: PCFieldSplitGetSubKSP(), PCFIELDSPLIT, PCFieldSplitSetBlockSize(), PCFieldSplitSetIS() 12930971522cSBarry Smith 12940971522cSBarry Smith @*/ 12955d4c12cdSJungho Lee PetscErrorCode PCFieldSplitSetFields(PC pc,const char splitname[],PetscInt n,const PetscInt *fields,const PetscInt *fields_col) 12960971522cSBarry Smith { 12974ac538c5SBarry Smith PetscErrorCode ierr; 12980971522cSBarry Smith 12990971522cSBarry Smith PetscFunctionBegin; 13000700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 1301db4c96c1SJed Brown PetscValidCharPointer(splitname,2); 1302ce94432eSBarry Smith if (n < 1) SETERRQ2(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_OUTOFRANGE,"Provided number of fields %D in split \"%s\" not positive",n,splitname); 1303db4c96c1SJed Brown PetscValidIntPointer(fields,3); 13045d4c12cdSJungho Lee ierr = PetscTryMethod(pc,"PCFieldSplitSetFields_C",(PC,const char[],PetscInt,const PetscInt*,const PetscInt*),(pc,splitname,n,fields,fields_col));CHKERRQ(ierr); 13050971522cSBarry Smith PetscFunctionReturn(0); 13060971522cSBarry Smith } 13070971522cSBarry Smith 13080971522cSBarry Smith #undef __FUNCT__ 1309704ba839SBarry Smith #define __FUNCT__ "PCFieldSplitSetIS" 1310704ba839SBarry Smith /*@ 1311704ba839SBarry Smith PCFieldSplitSetIS - Sets the exact elements for field 1312704ba839SBarry Smith 1313ad4df100SBarry Smith Logically Collective on PC 1314704ba839SBarry Smith 1315704ba839SBarry Smith Input Parameters: 1316704ba839SBarry Smith + pc - the preconditioner context 13170298fd71SBarry Smith . splitname - name of this split, if NULL the number of the split is used 1318db4c96c1SJed Brown - is - the index set that defines the vector elements in this field 1319704ba839SBarry Smith 1320d32f9abdSBarry Smith 1321a6ffb8dbSJed Brown Notes: 1322a6ffb8dbSJed Brown Use PCFieldSplitSetFields(), for fields defined by strided types. 1323a6ffb8dbSJed Brown 1324db4c96c1SJed Brown This function is called once per split (it creates a new split each time). Solve options 1325db4c96c1SJed Brown for this split will be available under the prefix -fieldsplit_SPLITNAME_. 1326d32f9abdSBarry Smith 1327704ba839SBarry Smith Level: intermediate 1328704ba839SBarry Smith 1329704ba839SBarry Smith .seealso: PCFieldSplitGetSubKSP(), PCFIELDSPLIT, PCFieldSplitSetBlockSize() 1330704ba839SBarry Smith 1331704ba839SBarry Smith @*/ 13327087cfbeSBarry Smith PetscErrorCode PCFieldSplitSetIS(PC pc,const char splitname[],IS is) 1333704ba839SBarry Smith { 13344ac538c5SBarry Smith PetscErrorCode ierr; 1335704ba839SBarry Smith 1336704ba839SBarry Smith PetscFunctionBegin; 13370700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 13387b62db95SJungho Lee if (splitname) PetscValidCharPointer(splitname,2); 1339db4c96c1SJed Brown PetscValidHeaderSpecific(is,IS_CLASSID,3); 13404ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCFieldSplitSetIS_C",(PC,const char[],IS),(pc,splitname,is));CHKERRQ(ierr); 1341704ba839SBarry Smith PetscFunctionReturn(0); 1342704ba839SBarry Smith } 1343704ba839SBarry Smith 1344704ba839SBarry Smith #undef __FUNCT__ 134557a9adfeSMatthew G Knepley #define __FUNCT__ "PCFieldSplitGetIS" 134657a9adfeSMatthew G Knepley /*@ 134757a9adfeSMatthew G Knepley PCFieldSplitGetIS - Retrieves the elements for a field as an IS 134857a9adfeSMatthew G Knepley 134957a9adfeSMatthew G Knepley Logically Collective on PC 135057a9adfeSMatthew G Knepley 135157a9adfeSMatthew G Knepley Input Parameters: 135257a9adfeSMatthew G Knepley + pc - the preconditioner context 135357a9adfeSMatthew G Knepley - splitname - name of this split 135457a9adfeSMatthew G Knepley 135557a9adfeSMatthew G Knepley Output Parameter: 13560298fd71SBarry Smith - is - the index set that defines the vector elements in this field, or NULL if the field is not found 135757a9adfeSMatthew G Knepley 135857a9adfeSMatthew G Knepley Level: intermediate 135957a9adfeSMatthew G Knepley 136057a9adfeSMatthew G Knepley .seealso: PCFieldSplitGetSubKSP(), PCFIELDSPLIT, PCFieldSplitSetIS() 136157a9adfeSMatthew G Knepley 136257a9adfeSMatthew G Knepley @*/ 136357a9adfeSMatthew G Knepley PetscErrorCode PCFieldSplitGetIS(PC pc,const char splitname[],IS *is) 136457a9adfeSMatthew G Knepley { 136557a9adfeSMatthew G Knepley PetscErrorCode ierr; 136657a9adfeSMatthew G Knepley 136757a9adfeSMatthew G Knepley PetscFunctionBegin; 136857a9adfeSMatthew G Knepley PetscValidHeaderSpecific(pc,PC_CLASSID,1); 136957a9adfeSMatthew G Knepley PetscValidCharPointer(splitname,2); 137057a9adfeSMatthew G Knepley PetscValidPointer(is,3); 137157a9adfeSMatthew G Knepley { 137257a9adfeSMatthew G Knepley PC_FieldSplit *jac = (PC_FieldSplit*) pc->data; 137357a9adfeSMatthew G Knepley PC_FieldSplitLink ilink = jac->head; 137457a9adfeSMatthew G Knepley PetscBool found; 137557a9adfeSMatthew G Knepley 13760298fd71SBarry Smith *is = NULL; 137757a9adfeSMatthew G Knepley while (ilink) { 137857a9adfeSMatthew G Knepley ierr = PetscStrcmp(ilink->splitname, splitname, &found);CHKERRQ(ierr); 137957a9adfeSMatthew G Knepley if (found) { 138057a9adfeSMatthew G Knepley *is = ilink->is; 138157a9adfeSMatthew G Knepley break; 138257a9adfeSMatthew G Knepley } 138357a9adfeSMatthew G Knepley ilink = ilink->next; 138457a9adfeSMatthew G Knepley } 138557a9adfeSMatthew G Knepley } 138657a9adfeSMatthew G Knepley PetscFunctionReturn(0); 138757a9adfeSMatthew G Knepley } 138857a9adfeSMatthew G Knepley 138957a9adfeSMatthew G Knepley #undef __FUNCT__ 139051f519a2SBarry Smith #define __FUNCT__ "PCFieldSplitSetBlockSize" 139151f519a2SBarry Smith /*@ 139251f519a2SBarry Smith PCFieldSplitSetBlockSize - Sets the block size for defining where fields start in the 139351f519a2SBarry Smith fieldsplit preconditioner. If not set the matrix block size is used. 139451f519a2SBarry Smith 1395ad4df100SBarry Smith Logically Collective on PC 139651f519a2SBarry Smith 139751f519a2SBarry Smith Input Parameters: 139851f519a2SBarry Smith + pc - the preconditioner context 139951f519a2SBarry Smith - bs - the block size 140051f519a2SBarry Smith 140151f519a2SBarry Smith Level: intermediate 140251f519a2SBarry Smith 140351f519a2SBarry Smith .seealso: PCFieldSplitGetSubKSP(), PCFIELDSPLIT, PCFieldSplitSetFields() 140451f519a2SBarry Smith 140551f519a2SBarry Smith @*/ 14067087cfbeSBarry Smith PetscErrorCode PCFieldSplitSetBlockSize(PC pc,PetscInt bs) 140751f519a2SBarry Smith { 14084ac538c5SBarry Smith PetscErrorCode ierr; 140951f519a2SBarry Smith 141051f519a2SBarry Smith PetscFunctionBegin; 14110700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 1412c5eb9154SBarry Smith PetscValidLogicalCollectiveInt(pc,bs,2); 14134ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCFieldSplitSetBlockSize_C",(PC,PetscInt),(pc,bs));CHKERRQ(ierr); 141451f519a2SBarry Smith PetscFunctionReturn(0); 141551f519a2SBarry Smith } 141651f519a2SBarry Smith 141751f519a2SBarry Smith #undef __FUNCT__ 141869a612a9SBarry Smith #define __FUNCT__ "PCFieldSplitGetSubKSP" 14190971522cSBarry Smith /*@C 142069a612a9SBarry Smith PCFieldSplitGetSubKSP - Gets the KSP contexts for all splits 14210971522cSBarry Smith 142269a612a9SBarry Smith Collective on KSP 14230971522cSBarry Smith 14240971522cSBarry Smith Input Parameter: 14250971522cSBarry Smith . pc - the preconditioner context 14260971522cSBarry Smith 14270971522cSBarry Smith Output Parameters: 142813e0d083SBarry Smith + n - the number of splits 142969a612a9SBarry Smith - pc - the array of KSP contexts 14300971522cSBarry Smith 14310971522cSBarry Smith Note: 1432d32f9abdSBarry Smith After PCFieldSplitGetSubKSP() the array of KSPs IS to be freed by the user 1433d32f9abdSBarry Smith (not the KSP just the array that contains them). 14340971522cSBarry Smith 143569a612a9SBarry Smith You must call KSPSetUp() before calling PCFieldSplitGetSubKSP(). 14360971522cSBarry Smith 1437196cc216SBarry Smith Fortran Usage: You must pass in a KSP array that is large enough to contain all the local KSPs. 14380298fd71SBarry Smith You can call PCFieldSplitGetSubKSP(pc,n,NULL_OBJECT,ierr) to determine how large the 1439196cc216SBarry Smith KSP array must be. 1440196cc216SBarry Smith 1441196cc216SBarry Smith 14420971522cSBarry Smith Level: advanced 14430971522cSBarry Smith 14440971522cSBarry Smith .seealso: PCFIELDSPLIT 14450971522cSBarry Smith @*/ 14467087cfbeSBarry Smith PetscErrorCode PCFieldSplitGetSubKSP(PC pc,PetscInt *n,KSP *subksp[]) 14470971522cSBarry Smith { 14484ac538c5SBarry Smith PetscErrorCode ierr; 14490971522cSBarry Smith 14500971522cSBarry Smith PetscFunctionBegin; 14510700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 145213e0d083SBarry Smith if (n) PetscValidIntPointer(n,2); 14534ac538c5SBarry Smith ierr = PetscUseMethod(pc,"PCFieldSplitGetSubKSP_C",(PC,PetscInt*,KSP **),(pc,n,subksp));CHKERRQ(ierr); 14540971522cSBarry Smith PetscFunctionReturn(0); 14550971522cSBarry Smith } 14560971522cSBarry Smith 1457e69d4d44SBarry Smith #undef __FUNCT__ 1458e69d4d44SBarry Smith #define __FUNCT__ "PCFieldSplitSchurPrecondition" 1459e69d4d44SBarry Smith /*@ 1460e69d4d44SBarry Smith PCFieldSplitSchurPrecondition - Indicates if the Schur complement is preconditioned by a preconditioner constructed by the 1461a04f6461SBarry Smith A11 matrix. Otherwise no preconditioner is used. 1462e69d4d44SBarry Smith 1463e69d4d44SBarry Smith Collective on PC 1464e69d4d44SBarry Smith 1465e69d4d44SBarry Smith Input Parameters: 1466e69d4d44SBarry Smith + pc - the preconditioner context 1467e87fab1bSBarry Smith . ptype - which matrix to use for preconditioning the Schur complement, PC_FIELDSPLIT_SCHUR_PRE_A11 (diag) is default 14680298fd71SBarry Smith - userpre - matrix to use for preconditioning, or NULL 1469084e4875SJed Brown 1470e69d4d44SBarry Smith Options Database: 1471e87fab1bSBarry Smith . -pc_fieldsplit_schur_precondition <self,user,a11> default is a11 1472e69d4d44SBarry Smith 1473fd1303e9SJungho Lee Notes: 1474fd1303e9SJungho Lee $ If ptype is 1475fd1303e9SJungho Lee $ user then the preconditioner for the Schur complement is generated by the provided matrix (pre argument 1476fd1303e9SJungho Lee $ to this function). 1477e87fab1bSBarry Smith $ a11 then the preconditioner for the Schur complement is generated by the block diagonal part of the original 1478fd1303e9SJungho Lee $ matrix associated with the Schur complement (i.e. A11) 1479fd1303e9SJungho Lee $ self the preconditioner for the Schur complement is generated from the Schur complement matrix itself: 1480fd1303e9SJungho Lee $ The only preconditioner that currently works directly with the Schur complement matrix object is the PCLSC 1481fd1303e9SJungho Lee $ preconditioner 1482fd1303e9SJungho Lee 1483e87fab1bSBarry Smith When solving a saddle point problem, where the A11 block is identically zero, using a11 as the ptype only makes sense 1484fd1303e9SJungho Lee with the additional option -fieldsplit_1_pc_type none. Usually for saddle point problems one would use a ptype of self and 1485fd1303e9SJungho Lee -fieldsplit_1_pc_type lsc which uses the least squares commutator compute a preconditioner for the Schur complement. 1486fd1303e9SJungho Lee 1487fd1303e9SJungho Lee Developer Notes: This is a terrible name, gives no good indication of what the function does and should also have Set in 1488fd1303e9SJungho Lee the name since it sets a proceedure to use. 1489fd1303e9SJungho Lee 1490e69d4d44SBarry Smith Level: intermediate 1491e69d4d44SBarry Smith 1492fd1303e9SJungho Lee .seealso: PCFieldSplitGetSubKSP(), PCFIELDSPLIT, PCFieldSplitSetFields(), PCFieldSplitSchurPreType, PCLSC 1493e69d4d44SBarry Smith 1494e69d4d44SBarry Smith @*/ 14957087cfbeSBarry Smith PetscErrorCode PCFieldSplitSchurPrecondition(PC pc,PCFieldSplitSchurPreType ptype,Mat pre) 1496e69d4d44SBarry Smith { 14974ac538c5SBarry Smith PetscErrorCode ierr; 1498e69d4d44SBarry Smith 1499e69d4d44SBarry Smith PetscFunctionBegin; 15000700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 15014ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCFieldSplitSchurPrecondition_C",(PC,PCFieldSplitSchurPreType,Mat),(pc,ptype,pre));CHKERRQ(ierr); 1502e69d4d44SBarry Smith PetscFunctionReturn(0); 1503e69d4d44SBarry Smith } 1504e69d4d44SBarry Smith 1505e69d4d44SBarry Smith #undef __FUNCT__ 1506e69d4d44SBarry Smith #define __FUNCT__ "PCFieldSplitSchurPrecondition_FieldSplit" 15071e6b0712SBarry Smith static PetscErrorCode PCFieldSplitSchurPrecondition_FieldSplit(PC pc,PCFieldSplitSchurPreType ptype,Mat pre) 1508e69d4d44SBarry Smith { 1509e69d4d44SBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 1510084e4875SJed Brown PetscErrorCode ierr; 1511e69d4d44SBarry Smith 1512e69d4d44SBarry Smith PetscFunctionBegin; 1513084e4875SJed Brown jac->schurpre = ptype; 1514084e4875SJed Brown if (pre) { 15156bf464f9SBarry Smith ierr = MatDestroy(&jac->schur_user);CHKERRQ(ierr); 1516084e4875SJed Brown jac->schur_user = pre; 1517084e4875SJed Brown ierr = PetscObjectReference((PetscObject)jac->schur_user);CHKERRQ(ierr); 1518084e4875SJed Brown } 1519e69d4d44SBarry Smith PetscFunctionReturn(0); 1520e69d4d44SBarry Smith } 1521e69d4d44SBarry Smith 152230ad9308SMatthew Knepley #undef __FUNCT__ 1523c9c6ffaaSJed Brown #define __FUNCT__ "PCFieldSplitSetSchurFactType" 1524ab1df9f5SJed Brown /*@ 1525c9c6ffaaSJed Brown PCFieldSplitSetSchurFactType - sets which blocks of the approximate block factorization to retain 1526ab1df9f5SJed Brown 1527ab1df9f5SJed Brown Collective on PC 1528ab1df9f5SJed Brown 1529ab1df9f5SJed Brown Input Parameters: 1530ab1df9f5SJed Brown + pc - the preconditioner context 1531c9c6ffaaSJed Brown - ftype - which blocks of factorization to retain, PC_FIELDSPLIT_SCHUR_FACT_FULL is default 1532ab1df9f5SJed Brown 1533ab1df9f5SJed Brown Options Database: 1534c9c6ffaaSJed Brown . -pc_fieldsplit_schur_fact_type <diag,lower,upper,full> default is full 1535ab1df9f5SJed Brown 1536ab1df9f5SJed Brown 1537ab1df9f5SJed Brown Level: intermediate 1538ab1df9f5SJed Brown 1539ab1df9f5SJed Brown Notes: 1540ab1df9f5SJed Brown The FULL factorization is 1541ab1df9f5SJed Brown 1542ab1df9f5SJed Brown $ (A B) = (1 0) (A 0) (1 Ainv*B) 1543ab1df9f5SJed Brown $ (C D) (C*Ainv 1) (0 S) (0 1 ) 1544ab1df9f5SJed Brown 15456be4592eSBarry Smith where S = D - C*Ainv*B. In practice, the full factorization is applied via block triangular solves with the grouping L*(D*U). UPPER uses D*U, LOWER uses L*D, 15466be4592eSBarry Smith and DIAG is the diagonal part with the sign of S flipped (because this makes the preconditioner positive definite for many formulations, thus allowing the use of KSPMINRES). 1547ab1df9f5SJed Brown 15486be4592eSBarry Smith If applied exactly, FULL factorization is a direct solver. The preconditioned operator with LOWER or UPPER has all eigenvalues equal to 1 and minimal polynomial 15496be4592eSBarry Smith of degree 2, so KSPGMRES converges in 2 iterations. If the iteration count is very low, consider using KSPFGMRES or KSPGCR which can use one less preconditioner 15506be4592eSBarry Smith application in this case. Note that the preconditioned operator may be highly non-normal, so such fast convergence may not be observed in practice. With DIAG, 15516be4592eSBarry Smith the preconditioned operator has three distinct nonzero eigenvalues and minimal polynomial of degree at most 4, so KSPGMRES converges in at most 4 iterations. 1552ab1df9f5SJed Brown 15536be4592eSBarry Smith For symmetric problems in which A is positive definite and S is negative definite, DIAG can be used with KSPMINRES. Note that a flexible method like KSPFGMRES 15546be4592eSBarry Smith or KSPGCR must be used if the fieldsplit preconditioner is nonlinear (e.g. a few iterations of a Krylov method is used inside a split). 1555ab1df9f5SJed Brown 1556ab1df9f5SJed Brown References: 1557ab1df9f5SJed Brown Murphy, Golub, and Wathen, A note on preconditioning indefinite linear systems, SIAM J. Sci. Comput., 21 (2000) pp. 1969-1972. 1558ab1df9f5SJed Brown 1559ab1df9f5SJed Brown Ipsen, A note on preconditioning nonsymmetric matrices, SIAM J. Sci. Comput., 23 (2001), pp. 1050-1051. 1560ab1df9f5SJed Brown 1561ab1df9f5SJed Brown .seealso: PCFieldSplitGetSubKSP(), PCFIELDSPLIT, PCFieldSplitSetFields(), PCFieldSplitSchurPreType 1562ab1df9f5SJed Brown @*/ 1563c9c6ffaaSJed Brown PetscErrorCode PCFieldSplitSetSchurFactType(PC pc,PCFieldSplitSchurFactType ftype) 1564ab1df9f5SJed Brown { 1565ab1df9f5SJed Brown PetscErrorCode ierr; 1566ab1df9f5SJed Brown 1567ab1df9f5SJed Brown PetscFunctionBegin; 1568ab1df9f5SJed Brown PetscValidHeaderSpecific(pc,PC_CLASSID,1); 1569c9c6ffaaSJed Brown ierr = PetscTryMethod(pc,"PCFieldSplitSetSchurFactType_C",(PC,PCFieldSplitSchurFactType),(pc,ftype));CHKERRQ(ierr); 1570ab1df9f5SJed Brown PetscFunctionReturn(0); 1571ab1df9f5SJed Brown } 1572ab1df9f5SJed Brown 1573ab1df9f5SJed Brown #undef __FUNCT__ 1574c9c6ffaaSJed Brown #define __FUNCT__ "PCFieldSplitSetSchurFactType_FieldSplit" 15751e6b0712SBarry Smith static PetscErrorCode PCFieldSplitSetSchurFactType_FieldSplit(PC pc,PCFieldSplitSchurFactType ftype) 1576ab1df9f5SJed Brown { 1577ab1df9f5SJed Brown PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 1578ab1df9f5SJed Brown 1579ab1df9f5SJed Brown PetscFunctionBegin; 1580ab1df9f5SJed Brown jac->schurfactorization = ftype; 1581ab1df9f5SJed Brown PetscFunctionReturn(0); 1582ab1df9f5SJed Brown } 1583ab1df9f5SJed Brown 1584ab1df9f5SJed Brown #undef __FUNCT__ 158530ad9308SMatthew Knepley #define __FUNCT__ "PCFieldSplitGetSchurBlocks" 158630ad9308SMatthew Knepley /*@C 15878c03b21aSDmitry Karpeev PCFieldSplitGetSchurBlocks - Gets all matrix blocks for the Schur complement 158830ad9308SMatthew Knepley 158930ad9308SMatthew Knepley Collective on KSP 159030ad9308SMatthew Knepley 159130ad9308SMatthew Knepley Input Parameter: 159230ad9308SMatthew Knepley . pc - the preconditioner context 159330ad9308SMatthew Knepley 159430ad9308SMatthew Knepley Output Parameters: 1595a04f6461SBarry Smith + A00 - the (0,0) block 1596a04f6461SBarry Smith . A01 - the (0,1) block 1597a04f6461SBarry Smith . A10 - the (1,0) block 1598a04f6461SBarry Smith - A11 - the (1,1) block 159930ad9308SMatthew Knepley 160030ad9308SMatthew Knepley Level: advanced 160130ad9308SMatthew Knepley 160230ad9308SMatthew Knepley .seealso: PCFIELDSPLIT 160330ad9308SMatthew Knepley @*/ 1604a04f6461SBarry Smith PetscErrorCode PCFieldSplitGetSchurBlocks(PC pc,Mat *A00,Mat *A01,Mat *A10, Mat *A11) 160530ad9308SMatthew Knepley { 160630ad9308SMatthew Knepley PC_FieldSplit *jac = (PC_FieldSplit*) pc->data; 160730ad9308SMatthew Knepley 160830ad9308SMatthew Knepley PetscFunctionBegin; 16090700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 1610ce94432eSBarry Smith if (jac->type != PC_COMPOSITE_SCHUR) SETERRQ(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_WRONG, "FieldSplit is not using a Schur complement approach."); 1611a04f6461SBarry Smith if (A00) *A00 = jac->pmat[0]; 1612a04f6461SBarry Smith if (A01) *A01 = jac->B; 1613a04f6461SBarry Smith if (A10) *A10 = jac->C; 1614a04f6461SBarry Smith if (A11) *A11 = jac->pmat[1]; 161530ad9308SMatthew Knepley PetscFunctionReturn(0); 161630ad9308SMatthew Knepley } 161730ad9308SMatthew Knepley 161879416396SBarry Smith #undef __FUNCT__ 161979416396SBarry Smith #define __FUNCT__ "PCFieldSplitSetType_FieldSplit" 16201e6b0712SBarry Smith static PetscErrorCode PCFieldSplitSetType_FieldSplit(PC pc,PCCompositeType type) 162179416396SBarry Smith { 162279416396SBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 1623e69d4d44SBarry Smith PetscErrorCode ierr; 162479416396SBarry Smith 162579416396SBarry Smith PetscFunctionBegin; 162679416396SBarry Smith jac->type = type; 16273b224e63SBarry Smith if (type == PC_COMPOSITE_SCHUR) { 16283b224e63SBarry Smith pc->ops->apply = PCApply_FieldSplit_Schur; 16293b224e63SBarry Smith pc->ops->view = PCView_FieldSplit_Schur; 16302fa5cd67SKarl Rupp 1631bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitGetSubKSP_C",PCFieldSplitGetSubKSP_FieldSplit_Schur);CHKERRQ(ierr); 1632bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSchurPrecondition_C",PCFieldSplitSchurPrecondition_FieldSplit);CHKERRQ(ierr); 1633bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetSchurFactType_C",PCFieldSplitSetSchurFactType_FieldSplit);CHKERRQ(ierr); 1634e69d4d44SBarry Smith 16353b224e63SBarry Smith } else { 16363b224e63SBarry Smith pc->ops->apply = PCApply_FieldSplit; 16373b224e63SBarry Smith pc->ops->view = PCView_FieldSplit; 16382fa5cd67SKarl Rupp 1639bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitGetSubKSP_C",PCFieldSplitGetSubKSP_FieldSplit);CHKERRQ(ierr); 1640bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSchurPrecondition_C",0);CHKERRQ(ierr); 1641bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetSchurFactType_C",0);CHKERRQ(ierr); 16423b224e63SBarry Smith } 164379416396SBarry Smith PetscFunctionReturn(0); 164479416396SBarry Smith } 164579416396SBarry Smith 164651f519a2SBarry Smith #undef __FUNCT__ 164751f519a2SBarry Smith #define __FUNCT__ "PCFieldSplitSetBlockSize_FieldSplit" 16481e6b0712SBarry Smith static PetscErrorCode PCFieldSplitSetBlockSize_FieldSplit(PC pc,PetscInt bs) 164951f519a2SBarry Smith { 165051f519a2SBarry Smith PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 165151f519a2SBarry Smith 165251f519a2SBarry Smith PetscFunctionBegin; 1653ce94432eSBarry Smith if (bs < 1) SETERRQ1(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_OUTOFRANGE,"Blocksize must be positive, you gave %D",bs); 1654ce94432eSBarry Smith if (jac->bs > 0 && jac->bs != bs) SETERRQ2(PetscObjectComm((PetscObject)pc),PETSC_ERR_ARG_WRONGSTATE,"Cannot change fieldsplit blocksize from %D to %D after it has been set",jac->bs,bs); 165551f519a2SBarry Smith jac->bs = bs; 165651f519a2SBarry Smith PetscFunctionReturn(0); 165751f519a2SBarry Smith } 165851f519a2SBarry Smith 165979416396SBarry Smith #undef __FUNCT__ 166079416396SBarry Smith #define __FUNCT__ "PCFieldSplitSetType" 1661bc08b0f1SBarry Smith /*@ 166279416396SBarry Smith PCFieldSplitSetType - Sets the type of fieldsplit preconditioner. 166379416396SBarry Smith 166479416396SBarry Smith Collective on PC 166579416396SBarry Smith 166679416396SBarry Smith Input Parameter: 166779416396SBarry Smith . pc - the preconditioner context 166881540f2fSBarry Smith . type - PC_COMPOSITE_ADDITIVE, PC_COMPOSITE_MULTIPLICATIVE (default), PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE, PC_COMPOSITE_SPECIAL, PC_COMPOSITE_SCHUR 166979416396SBarry Smith 167079416396SBarry Smith Options Database Key: 1671a4efd8eaSMatthew Knepley . -pc_fieldsplit_type <type: one of multiplicative, additive, symmetric_multiplicative, special, schur> - Sets fieldsplit preconditioner type 167279416396SBarry Smith 1673b02e2d75SMatthew G Knepley Level: Intermediate 167479416396SBarry Smith 167579416396SBarry Smith .keywords: PC, set, type, composite preconditioner, additive, multiplicative 167679416396SBarry Smith 167779416396SBarry Smith .seealso: PCCompositeSetType() 167879416396SBarry Smith 167979416396SBarry Smith @*/ 16807087cfbeSBarry Smith PetscErrorCode PCFieldSplitSetType(PC pc,PCCompositeType type) 168179416396SBarry Smith { 16824ac538c5SBarry Smith PetscErrorCode ierr; 168379416396SBarry Smith 168479416396SBarry Smith PetscFunctionBegin; 16850700a824SBarry Smith PetscValidHeaderSpecific(pc,PC_CLASSID,1); 16864ac538c5SBarry Smith ierr = PetscTryMethod(pc,"PCFieldSplitSetType_C",(PC,PCCompositeType),(pc,type));CHKERRQ(ierr); 168779416396SBarry Smith PetscFunctionReturn(0); 168879416396SBarry Smith } 168979416396SBarry Smith 1690b02e2d75SMatthew G Knepley #undef __FUNCT__ 1691b02e2d75SMatthew G Knepley #define __FUNCT__ "PCFieldSplitGetType" 1692b02e2d75SMatthew G Knepley /*@ 1693b02e2d75SMatthew G Knepley PCFieldSplitGetType - Gets the type of fieldsplit preconditioner. 1694b02e2d75SMatthew G Knepley 1695b02e2d75SMatthew G Knepley Not collective 1696b02e2d75SMatthew G Knepley 1697b02e2d75SMatthew G Knepley Input Parameter: 1698b02e2d75SMatthew G Knepley . pc - the preconditioner context 1699b02e2d75SMatthew G Knepley 1700b02e2d75SMatthew G Knepley Output Parameter: 1701b02e2d75SMatthew G Knepley . type - PC_COMPOSITE_ADDITIVE, PC_COMPOSITE_MULTIPLICATIVE (default), PC_COMPOSITE_SYMMETRIC_MULTIPLICATIVE, PC_COMPOSITE_SPECIAL, PC_COMPOSITE_SCHUR 1702b02e2d75SMatthew G Knepley 1703b02e2d75SMatthew G Knepley Level: Intermediate 1704b02e2d75SMatthew G Knepley 1705b02e2d75SMatthew G Knepley .keywords: PC, set, type, composite preconditioner, additive, multiplicative 1706b02e2d75SMatthew G Knepley .seealso: PCCompositeSetType() 1707b02e2d75SMatthew G Knepley @*/ 1708b02e2d75SMatthew G Knepley PetscErrorCode PCFieldSplitGetType(PC pc, PCCompositeType *type) 1709b02e2d75SMatthew G Knepley { 1710b02e2d75SMatthew G Knepley PC_FieldSplit *jac = (PC_FieldSplit*) pc->data; 1711b02e2d75SMatthew G Knepley 1712b02e2d75SMatthew G Knepley PetscFunctionBegin; 1713b02e2d75SMatthew G Knepley PetscValidHeaderSpecific(pc,PC_CLASSID,1); 1714b02e2d75SMatthew G Knepley PetscValidIntPointer(type,2); 1715b02e2d75SMatthew G Knepley *type = jac->type; 1716b02e2d75SMatthew G Knepley PetscFunctionReturn(0); 1717b02e2d75SMatthew G Knepley } 1718b02e2d75SMatthew G Knepley 17194ab8060aSDmitry Karpeev #undef __FUNCT__ 17204ab8060aSDmitry Karpeev #define __FUNCT__ "PCFieldSplitSetDMSplits" 17214ab8060aSDmitry Karpeev /*@ 17224ab8060aSDmitry Karpeev PCFieldSplitSetDMSplits - Flags whether DMCreateFieldDecomposition() should be used to define the splits, whenever possible. 17234ab8060aSDmitry Karpeev 17244ab8060aSDmitry Karpeev Logically Collective 17254ab8060aSDmitry Karpeev 17264ab8060aSDmitry Karpeev Input Parameters: 17274ab8060aSDmitry Karpeev + pc - the preconditioner context 17284ab8060aSDmitry Karpeev - flg - boolean indicating whether to use field splits defined by the DM 17294ab8060aSDmitry Karpeev 17304ab8060aSDmitry Karpeev Options Database Key: 17314ab8060aSDmitry Karpeev . -pc_fieldsplit_dm_splits 17324ab8060aSDmitry Karpeev 17334ab8060aSDmitry Karpeev Level: Intermediate 17344ab8060aSDmitry Karpeev 17354ab8060aSDmitry Karpeev .keywords: PC, DM, composite preconditioner, additive, multiplicative 17364ab8060aSDmitry Karpeev 17374ab8060aSDmitry Karpeev .seealso: PCFieldSplitGetDMSplits() 17384ab8060aSDmitry Karpeev 17394ab8060aSDmitry Karpeev @*/ 17404ab8060aSDmitry Karpeev PetscErrorCode PCFieldSplitSetDMSplits(PC pc,PetscBool flg) 17414ab8060aSDmitry Karpeev { 17424ab8060aSDmitry Karpeev PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 17434ab8060aSDmitry Karpeev PetscBool isfs; 17444ab8060aSDmitry Karpeev PetscErrorCode ierr; 17454ab8060aSDmitry Karpeev 17464ab8060aSDmitry Karpeev PetscFunctionBegin; 17474ab8060aSDmitry Karpeev PetscValidHeaderSpecific(pc,PC_CLASSID,1); 17484ab8060aSDmitry Karpeev PetscValidLogicalCollectiveBool(pc,flg,2); 17494ab8060aSDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)pc,PCFIELDSPLIT,&isfs);CHKERRQ(ierr); 17504ab8060aSDmitry Karpeev if (isfs) { 17514ab8060aSDmitry Karpeev jac->dm_splits = flg; 17524ab8060aSDmitry Karpeev } 17534ab8060aSDmitry Karpeev PetscFunctionReturn(0); 17544ab8060aSDmitry Karpeev } 17554ab8060aSDmitry Karpeev 17564ab8060aSDmitry Karpeev 17574ab8060aSDmitry Karpeev #undef __FUNCT__ 17584ab8060aSDmitry Karpeev #define __FUNCT__ "PCFieldSplitGetDMSplits" 17594ab8060aSDmitry Karpeev /*@ 17604ab8060aSDmitry Karpeev PCFieldSplitGetDMSplits - Returns flag indicating whether DMCreateFieldDecomposition() should be used to define the splits, whenever possible. 17614ab8060aSDmitry Karpeev 17624ab8060aSDmitry Karpeev Logically Collective 17634ab8060aSDmitry Karpeev 17644ab8060aSDmitry Karpeev Input Parameter: 17654ab8060aSDmitry Karpeev . pc - the preconditioner context 17664ab8060aSDmitry Karpeev 17674ab8060aSDmitry Karpeev Output Parameter: 17684ab8060aSDmitry Karpeev . flg - boolean indicating whether to use field splits defined by the DM 17694ab8060aSDmitry Karpeev 17704ab8060aSDmitry Karpeev Level: Intermediate 17714ab8060aSDmitry Karpeev 17724ab8060aSDmitry Karpeev .keywords: PC, DM, composite preconditioner, additive, multiplicative 17734ab8060aSDmitry Karpeev 17744ab8060aSDmitry Karpeev .seealso: PCFieldSplitSetDMSplits() 17754ab8060aSDmitry Karpeev 17764ab8060aSDmitry Karpeev @*/ 17774ab8060aSDmitry Karpeev PetscErrorCode PCFieldSplitGetDMSplits(PC pc,PetscBool* flg) 17784ab8060aSDmitry Karpeev { 17794ab8060aSDmitry Karpeev PC_FieldSplit *jac = (PC_FieldSplit*)pc->data; 17804ab8060aSDmitry Karpeev PetscBool isfs; 17814ab8060aSDmitry Karpeev PetscErrorCode ierr; 17824ab8060aSDmitry Karpeev 17834ab8060aSDmitry Karpeev PetscFunctionBegin; 17844ab8060aSDmitry Karpeev PetscValidHeaderSpecific(pc,PC_CLASSID,1); 17854ab8060aSDmitry Karpeev PetscValidPointer(flg,2); 17864ab8060aSDmitry Karpeev ierr = PetscObjectTypeCompare((PetscObject)pc,PCFIELDSPLIT,&isfs);CHKERRQ(ierr); 17874ab8060aSDmitry Karpeev if (isfs) { 17884ab8060aSDmitry Karpeev if(flg) *flg = jac->dm_splits; 17894ab8060aSDmitry Karpeev } 17904ab8060aSDmitry Karpeev PetscFunctionReturn(0); 17914ab8060aSDmitry Karpeev } 17924ab8060aSDmitry Karpeev 17930971522cSBarry Smith /* -------------------------------------------------------------------------------------*/ 17940971522cSBarry Smith /*MC 1795a8c7a070SBarry Smith PCFIELDSPLIT - Preconditioner created by combining separate preconditioners for individual 1796a04f6461SBarry Smith fields or groups of fields. See the users manual section "Solving Block Matrices" for more details. 17970971522cSBarry Smith 1798edf189efSBarry Smith To set options on the solvers for each block append -fieldsplit_ to all the PC 1799edf189efSBarry Smith options database keys. For example, -fieldsplit_pc_type ilu -fieldsplit_pc_factor_levels 1 18000971522cSBarry Smith 1801a8c7a070SBarry Smith To set the options on the solvers separate for each block call PCFieldSplitGetSubKSP() 180269a612a9SBarry Smith and set the options directly on the resulting KSP object 18030971522cSBarry Smith 18040971522cSBarry Smith Level: intermediate 18050971522cSBarry Smith 180679416396SBarry Smith Options Database Keys: 180781540f2fSBarry Smith + -pc_fieldsplit_%d_fields <a,b,..> - indicates the fields to be used in the %d'th split 180881540f2fSBarry Smith . -pc_fieldsplit_default - automatically add any fields to additional splits that have not 180981540f2fSBarry Smith been supplied explicitly by -pc_fieldsplit_%d_fields 181081540f2fSBarry Smith . -pc_fieldsplit_block_size <bs> - size of block that defines fields (i.e. there are bs fields) 18110f188ba9SJed Brown . -pc_fieldsplit_type <additive,multiplicative,symmetric_multiplicative,schur> - type of relaxation or factorization splitting 1812e87fab1bSBarry Smith . -pc_fieldsplit_schur_precondition <self,user,a11> - default is a11 1813435f959eSBarry Smith . -pc_fieldsplit_detect_saddle_point - automatically finds rows with zero or negative diagonal and uses Schur complement with no preconditioner as the solver 181479416396SBarry Smith 18155d4c12cdSJungho Lee - Options prefix for inner solvers when using Schur complement preconditioner are -fieldsplit_0_ and -fieldsplit_1_ 18165d4c12cdSJungho Lee for all other solvers they are -fieldsplit_%d_ for the dth field, use -fieldsplit_ for all fields 18175d4c12cdSJungho Lee 1818c8a0d604SMatthew G Knepley Notes: 1819c8a0d604SMatthew G Knepley Use PCFieldSplitSetFields() to set fields defined by "strided" entries and PCFieldSplitSetIS() 1820d32f9abdSBarry Smith to define a field by an arbitrary collection of entries. 1821d32f9abdSBarry Smith 1822d32f9abdSBarry Smith If no fields are set the default is used. The fields are defined by entries strided by bs, 1823d32f9abdSBarry Smith beginning at 0 then 1, etc to bs-1. The block size can be set with PCFieldSplitSetBlockSize(), 1824d32f9abdSBarry Smith if this is not called the block size defaults to the blocksize of the second matrix passed 1825d32f9abdSBarry Smith to KSPSetOperators()/PCSetOperators(). 1826d32f9abdSBarry Smith 1827c8a0d604SMatthew G Knepley $ For the Schur complement preconditioner if J = ( A00 A01 ) 1828c8a0d604SMatthew G Knepley $ ( A10 A11 ) 1829c8a0d604SMatthew G Knepley $ the preconditioner using full factorization is 183013b05affSJed Brown $ ( I -ksp(A00) A01 ) ( inv(A00) 0 ) ( I 0 ) 1831c8a0d604SMatthew G Knepley $ ( 0 I ) ( 0 ksp(S) ) ( -A10 ksp(A00) I ) 183213b05affSJed Brown where the action of inv(A00) is applied using the KSP solver with prefix -fieldsplit_0_. S is the Schur complement 183313b05affSJed Brown $ S = A11 - A10 ksp(A00) A01 183413b05affSJed Brown which is usually dense and not stored explicitly. The action of ksp(S) is computed using the KSP solver with prefix -fieldsplit_splitname_ (where splitname was given 1835c8a0d604SMatthew G Knepley in providing the SECOND split or 1 if not give). For PCFieldSplitGetKSP() when field number is 0, 1836c8a0d604SMatthew G Knepley it returns the KSP associated with -fieldsplit_0_ while field number 1 gives -fieldsplit_1_ KSP. By default 1837a04f6461SBarry Smith A11 is used to construct a preconditioner for S, use PCFieldSplitSchurPrecondition() to turn on or off this 1838c8a0d604SMatthew G Knepley option. You can use the preconditioner PCLSC to precondition the Schur complement with -fieldsplit_1_pc_type lsc. The 1839c9c6ffaaSJed Brown factorization type is set using -pc_fieldsplit_schur_fact_type <diag, lower, upper, full>. The full is shown above, 18405668aaf4SBarry Smith diag gives 1841c8a0d604SMatthew G Knepley $ ( inv(A00) 0 ) 1842c8a0d604SMatthew G Knepley $ ( 0 -ksp(S) ) 18435668aaf4SBarry Smith note that slightly counter intuitively there is a negative in front of the ksp(S) so that the preconditioner is positive definite. The lower factorization is the inverse of 1844c8a0d604SMatthew G Knepley $ ( A00 0 ) 1845c8a0d604SMatthew G Knepley $ ( A10 S ) 1846c8a0d604SMatthew G Knepley where the inverses of A00 and S are applied using KSPs. The upper factorization is the inverse of 1847c8a0d604SMatthew G Knepley $ ( A00 A01 ) 1848c8a0d604SMatthew G Knepley $ ( 0 S ) 1849c8a0d604SMatthew G Knepley where again the inverses of A00 and S are applied using KSPs. 1850e69d4d44SBarry Smith 1851edf189efSBarry Smith If only one set of indices (one IS) is provided with PCFieldSplitSetIS() then the complement of that IS 1852edf189efSBarry Smith is used automatically for a second block. 1853edf189efSBarry Smith 1854ff218e97SBarry Smith The fieldsplit preconditioner cannot currently be used with the BAIJ or SBAIJ data formats if the blocksize is larger than 1. 1855ff218e97SBarry Smith Generally it should be used with the AIJ format. 1856ff218e97SBarry Smith 1857ff218e97SBarry Smith The forms of these preconditioners are closely related if not identical to forms derived as "Distributive Iterations", see, 1858ff218e97SBarry Smith for example, page 294 in "Principles of Computational Fluid Dynamics" by Pieter Wesseling. Note that one can also use PCFIELDSPLIT 1859ff218e97SBarry Smith inside a smoother resulting in "Distributive Smoothers". 18600716a85fSBarry Smith 1861a541d17aSBarry Smith Concepts: physics based preconditioners, block preconditioners 18620971522cSBarry Smith 18637e8cb189SBarry Smith .seealso: PCCreate(), PCSetType(), PCType (for list of available types), PC, Block_Preconditioners, PCLSC, 1864e69d4d44SBarry Smith PCFieldSplitGetSubKSP(), PCFieldSplitSetFields(), PCFieldSplitSetType(), PCFieldSplitSetIS(), PCFieldSplitSchurPrecondition() 18650971522cSBarry Smith M*/ 18660971522cSBarry Smith 18670971522cSBarry Smith #undef __FUNCT__ 18680971522cSBarry Smith #define __FUNCT__ "PCCreate_FieldSplit" 18698cc058d9SJed Brown PETSC_EXTERN PetscErrorCode PCCreate_FieldSplit(PC pc) 18700971522cSBarry Smith { 18710971522cSBarry Smith PetscErrorCode ierr; 18720971522cSBarry Smith PC_FieldSplit *jac; 18730971522cSBarry Smith 18740971522cSBarry Smith PetscFunctionBegin; 1875b00a9115SJed Brown ierr = PetscNewLog(pc,&jac);CHKERRQ(ierr); 18762fa5cd67SKarl Rupp 18770971522cSBarry Smith jac->bs = -1; 18780971522cSBarry Smith jac->nsplits = 0; 18793e197d65SBarry Smith jac->type = PC_COMPOSITE_MULTIPLICATIVE; 1880e6cab6aaSJed Brown jac->schurpre = PC_FIELDSPLIT_SCHUR_PRE_USER; /* Try user preconditioner first, fall back on diagonal */ 1881c9c6ffaaSJed Brown jac->schurfactorization = PC_FIELDSPLIT_SCHUR_FACT_FULL; 1882fbe7908bSJed Brown jac->dm_splits = PETSC_TRUE; 188351f519a2SBarry Smith 18840971522cSBarry Smith pc->data = (void*)jac; 18850971522cSBarry Smith 18860971522cSBarry Smith pc->ops->apply = PCApply_FieldSplit; 1887421e10b8SBarry Smith pc->ops->applytranspose = PCApplyTranspose_FieldSplit; 18880971522cSBarry Smith pc->ops->setup = PCSetUp_FieldSplit; 1889574deadeSBarry Smith pc->ops->reset = PCReset_FieldSplit; 18900971522cSBarry Smith pc->ops->destroy = PCDestroy_FieldSplit; 18910971522cSBarry Smith pc->ops->setfromoptions = PCSetFromOptions_FieldSplit; 18920971522cSBarry Smith pc->ops->view = PCView_FieldSplit; 18930971522cSBarry Smith pc->ops->applyrichardson = 0; 18940971522cSBarry Smith 1895bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitGetSubKSP_C",PCFieldSplitGetSubKSP_FieldSplit);CHKERRQ(ierr); 1896bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetFields_C",PCFieldSplitSetFields_FieldSplit);CHKERRQ(ierr); 1897bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetIS_C",PCFieldSplitSetIS_FieldSplit);CHKERRQ(ierr); 1898bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetType_C",PCFieldSplitSetType_FieldSplit);CHKERRQ(ierr); 1899bdf89e91SBarry Smith ierr = PetscObjectComposeFunction((PetscObject)pc,"PCFieldSplitSetBlockSize_C",PCFieldSplitSetBlockSize_FieldSplit);CHKERRQ(ierr); 19000971522cSBarry Smith PetscFunctionReturn(0); 19010971522cSBarry Smith } 19020971522cSBarry Smith 19030971522cSBarry Smith 1904a541d17aSBarry Smith 1905