PetscErrorCode BSSCR_KSPSetConvergenceMinIts(KSP ksp, PetscInt n, KSP_BSSCR * bsscr) { BSSCR_KSPConverged_Ctx *ctx; PetscErrorCode ierr; PetscFunctionBegin; bsscr->min_it = n; /* set minimum its */ #if ( (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR >= 5 ) ) ierr = Stg_PetscNew(BSSCR_KSPConverged_Ctx,&ctx);CHKERRQ(ierr); ierr = KSPConvergedDefaultCreate(&ctx->ctx);CHKERRQ(ierr); ctx->bsscr=bsscr; ierr = KSPSetConvergenceTest(ksp,BSSCR_KSPConverged,ctx,BSSCR_KSPConverged_Destroy);CHKERRQ(ierr); #endif #if ( (PETSC_VERSION_MAJOR == 3) && (PETSC_VERSION_MINOR <=4 ) ) ierr = Stg_PetscNew(BSSCR_KSPConverged_Ctx,&ctx);CHKERRQ(ierr); ierr = KSPDefaultConvergedCreate(&ctx->ctx);CHKERRQ(ierr); ctx->bsscr=bsscr; ierr = KSPSetConvergenceTest(ksp,BSSCR_KSPConverged,ctx,BSSCR_KSPConverged_Destroy);CHKERRQ(ierr); #endif #if ( PETSC_VERSION_MAJOR < 3) ierr = KSPSetConvergenceTest(ksp,BSSCR_KSPConverged,(void*)bsscr);CHKERRQ(ierr); #endif PetscFunctionReturn(0); }
PetscErrorCode BSSCR_KSPPWConvergedCreate(void **ctx) { PetscErrorCode ierr; KSPPWConvergedCtx *cctx; PetscFunctionBegin; ierr = Stg_PetscNew(KSPPWConvergedCtx,&cctx);CHKERRQ(ierr); *ctx = cctx; PetscFunctionReturn(0); }
EXTERN_C_BEGIN #undef __FUNCT__ #define __FUNCT__ "KSPCreate_BSSCR" PetscErrorCode PETSCKSP_DLLEXPORT KSPCreate_BSSCR(KSP ksp) { KSP_BSSCR *bsscr; PetscErrorCode ierr; PetscFunctionBegin; ierr = Stg_PetscNew(KSP_BSSCR,&bsscr);CHKERRQ(ierr); ierr = PetscLogObjectMemory((PetscObject)ksp,sizeof(KSP_BSSCR));CHKERRQ(ierr); //ierr = PetscNewLog(ksp,KSP_BSSCR,&bsscr);CHKERRQ(ierr); ksp->data = (void*)bsscr; #if ( (PETSC_VERSION_MAJOR >= 3) && (PETSC_VERSION_MINOR >= 2 ) ) ierr = KSPSetSupportedNorm(ksp,KSP_NORM_PRECONDITIONED,PC_LEFT,0);CHKERRQ(ierr); ierr = KSPSetSupportedNorm(ksp,KSP_NORM_UNPRECONDITIONED,PC_LEFT,1);CHKERRQ(ierr); ierr = KSPSetSupportedNorm(ksp,KSP_NORM_NATURAL,PC_LEFT,0);CHKERRQ(ierr); ierr = KSPSetSupportedNorm(ksp,KSP_NORM_NONE,PC_LEFT,1);CHKERRQ(ierr); #endif /* Sets the functions that are associated with this data structure (in C++ this is the same as defining virtual functions) */ ksp->ops->setup = KSPSetUp_BSSCR; ksp->ops->solve = KSPSolve_BSSCR; ksp->ops->destroy = KSPDestroy_BSSCR; ksp->ops->view = KSPView_BSSCR; ksp->ops->setfromoptions = KSPSetFromOptions_BSSCR; ksp->ops->buildsolution = KSPDefaultBuildSolution; ksp->ops->buildresidual = KSPDefaultBuildResidual; // bsscr->k2type=K2_GMG; bsscr->k2type = 0; bsscr->do_scaling = PETSC_FALSE; bsscr->scaled = PETSC_FALSE; bsscr->K2built = PETSC_FALSE; bsscr->check_cb_pressureNS = PETSC_FALSE;/* checker board nullspace */ bsscr->check_const_pressureNS = PETSC_FALSE;/* constant nullspace */ bsscr->check_pressureNS = PETSC_FALSE;/* is true if either of above two are true */ bsscr->t = NULL;/* null space vectors for pressure */ bsscr->v = NULL; bsscr->nstol = 1e-7;/* null space detection tolerance */ bsscr->uStar = NULL; bsscr->been_here = 0; PetscFunctionReturn(0); }
PetscErrorCode BSSCR_PCCreate_GtKG( PC pc ) { PC_GtKG pc_data; PetscErrorCode ierr; /* create memory for ctx */ ierr = Stg_PetscNew( _PC_GtKG,&pc_data);CHKERRQ(ierr); /* init ctx */ pc_data->K = PETSC_NULL; pc_data->G = PETSC_NULL; pc_data->M = PETSC_NULL; pc_data->GtG = PETSC_NULL; pc_data->form_GtG = PETSC_TRUE; pc_data->ksp = PETSC_NULL; pc_data->monitor_activated = PETSC_FALSE; pc_data->monitor_rhs_consistency = PETSC_FALSE; pc_data->s = PETSC_NULL; pc_data->t = PETSC_NULL; pc_data->X = PETSC_NULL; pc_data->inv_diag_M = PETSC_NULL; /* create internals */ KSPCreate( ((PetscObject)pc)->comm, &pc_data->ksp ); /* set ctx onto pc */ pc->data = (void*)pc_data; ierr = PetscLogObjectMemory(pc,sizeof(_PC_GtKG));CHKERRQ(ierr); /* define operations */ pc->ops->setup = BSSCR_PCSetUp_GtKG; pc->ops->view = BSSCR_PCView_GtKG; pc->ops->destroy = BSSCR_PCDestroy_GtKG; pc->ops->setfromoptions = BSSCR_PCSetFromOptions_GtKG; pc->ops->apply = BSSCR_PCApply_GtKG; pc->ops->applytranspose = BSSCR_PCApplyTranspose_GtKG; PetscFunctionReturn(0); }
PetscErrorCode BSSCR_PCCreate_ScGtKG( PC pc ) { PC_SC_GtKG pc_data; PetscErrorCode ierr; /* create memory for ctx */ ierr = Stg_PetscNew( _PC_SC_GtKG,&pc_data);CHKERRQ(ierr); /* init ctx */ pc_data->F = PETSC_NULL; pc_data->Bt = PETSC_NULL; pc_data->B = PETSC_NULL; pc_data->BBt_has_cnst_nullspace = PETSC_FALSE; pc_data->ksp_BBt = PETSC_NULL; pc_data->monitor_activated = PETSC_FALSE; pc_data->X1 = PETSC_NULL; pc_data->X2 = PETSC_NULL; pc_data->Y1 = PETSC_NULL; pc_data->Y2 = PETSC_NULL; pc_data->s = PETSC_NULL; pc_data->t = PETSC_NULL; pc_data->X = PETSC_NULL; /* set ctx onto pc */ pc->data = (void*)pc_data; ierr = PetscLogObjectMemory(pc,sizeof(_PC_SC_GtKG));CHKERRQ(ierr); /* define operations */ pc->ops->setup = BSSCR_PCSetUp_ScGtKG; pc->ops->view = BSSCR_PCView_ScGtKG; pc->ops->destroy = BSSCR_PCDestroy_ScGtKG; pc->ops->setfromoptions = BSSCR_PCSetFromOptions_ScGtKG; pc->ops->apply = BSSCR_PCApply_ScGtKG; pc->ops->applytranspose = BSSCR_PCApplyTranspose_ScGtKG; PetscFunctionReturn(0); }