/* PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened. This one registers all the KSP and PC methods that are in the basic PETSc libpetscksp library. */ PETSC_EXTERN PetscErrorCode PetscDLLibraryRegister_petscksp(void) { PetscErrorCode ierr; PetscFunctionBegin; ierr = PCInitializePackage();CHKERRQ(ierr); ierr = KSPInitializePackage();CHKERRQ(ierr); PetscFunctionReturn(0); }
static PetscErrorCode DMKSPCreate(MPI_Comm comm,DMKSP *kdm) { PetscErrorCode ierr; PetscFunctionBegin; ierr = KSPInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(*kdm, DMKSP_CLASSID, "DMKSP", "DMKSP", "DMKSP", comm, DMKSPDestroy, NULL);CHKERRQ(ierr); PetscFunctionReturn(0); }
static PetscErrorCode DMKSPCreate(MPI_Comm comm,DMKSP *kdm) { PetscErrorCode ierr; PetscFunctionBegin; ierr = KSPInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(*kdm, _p_DMKSP, struct _DMKSPOps, DMKSP_CLASSID, "DMKSP", "DMKSP", "DMKSP", comm, DMKSPDestroy, NULL);CHKERRQ(ierr); ierr = PetscMemzero((*kdm)->ops, sizeof(struct _DMKSPOps));CHKERRQ(ierr); PetscFunctionReturn(0); }
/*@ KSPCreate - Creates the default KSP context. Collective on MPI_Comm Input Parameter: . comm - MPI communicator Output Parameter: . ksp - location to put the KSP context Notes: The default KSP type is GMRES with a restart of 30, using modified Gram-Schmidt orthogonalization. Level: beginner .keywords: KSP, create, context .seealso: KSPSetUp(), KSPSolve(), KSPDestroy(), KSP @*/ PetscErrorCode KSPCreate(MPI_Comm comm,KSP *inksp) { KSP ksp; PetscErrorCode ierr; void *ctx; PetscFunctionBegin; PetscValidPointer(inksp,2); *inksp = 0; ierr = KSPInitializePackage();CHKERRQ(ierr); ierr = PetscHeaderCreate(ksp,KSP_CLASSID,"KSP","Krylov Method","KSP",comm,KSPDestroy,KSPView);CHKERRQ(ierr); ksp->max_it = 10000; ksp->pc_side = ksp->pc_side_set = PC_SIDE_DEFAULT; ksp->rtol = 1.e-5; #if defined(PETSC_USE_REAL_SINGLE) ksp->abstol = 1.e-25; #else ksp->abstol = 1.e-50; #endif ksp->divtol = 1.e4; ksp->chknorm = -1; ksp->normtype = ksp->normtype_set = KSP_NORM_DEFAULT; ksp->rnorm = 0.0; ksp->its = 0; ksp->guess_zero = PETSC_TRUE; ksp->calc_sings = PETSC_FALSE; ksp->res_hist = NULL; ksp->res_hist_alloc = NULL; ksp->res_hist_len = 0; ksp->res_hist_max = 0; ksp->res_hist_reset = PETSC_TRUE; ksp->numbermonitors = 0; ierr = KSPConvergedDefaultCreate(&ctx);CHKERRQ(ierr); ierr = KSPSetConvergenceTest(ksp,KSPConvergedDefault,ctx,KSPConvergedDefaultDestroy);CHKERRQ(ierr); ksp->ops->buildsolution = KSPBuildSolutionDefault; ksp->ops->buildresidual = KSPBuildResidualDefault; ksp->vec_sol = 0; ksp->vec_rhs = 0; ksp->pc = 0; ksp->data = 0; ksp->nwork = 0; ksp->work = 0; ksp->reason = KSP_CONVERGED_ITERATING; ksp->setupstage = KSP_SETUP_NEW; ierr = KSPNormSupportTableReset_Private(ksp);CHKERRQ(ierr); *inksp = ksp; PetscFunctionReturn(0); }
/*@ MatCreateSchurComplement - Creates a new matrix object that behaves like the Schur complement of a matrix Collective on Mat Input Parameters: + A00,A01,A10,A11 - the four parts of the original matrix A = [A00 A01; A10 A11] (A11 is optional) - Ap00 - preconditioning matrix for use in ksp(A00,Ap00) to approximate the action of A^{-1} Output Parameter: . S - the matrix that the Schur complement S = A11 - A10 ksp(A00,Ap00) A01 Level: intermediate Notes: The Schur complement is NOT actually formed! Rather, this object performs the matrix-vector product by using formula S = A11 - A10 A^{-1} A01 for Schur complement S and a KSP solver to approximate the action of A^{-1}. All four matrices must have the same MPI communicator. A00 and A11 must be square matrices. .seealso: MatCreateNormal(), MatMult(), MatCreate(), MatSchurComplementGetKSP(), MatSchurComplementUpdateSubMatrices(), MatCreateTranspose(), MatGetSchurComplement() @*/ PetscErrorCode MatCreateSchurComplement(Mat A00,Mat Ap00,Mat A01,Mat A10,Mat A11,Mat *S) { PetscErrorCode ierr; PetscFunctionBegin; ierr = KSPInitializePackage();CHKERRQ(ierr); ierr = MatCreate(((PetscObject)A00)->comm,S);CHKERRQ(ierr); ierr = MatSetType(*S,MATSCHURCOMPLEMENT);CHKERRQ(ierr); ierr = MatSchurComplementSetSubMatrices(*S,A00,Ap00,A01,A10,A11);CHKERRQ(ierr); PetscFunctionReturn(0); }
static PetscErrorCode DMKSPCreate(MPI_Comm comm,DMKSP *kdm) { PetscErrorCode ierr; PetscFunctionBegin; #ifndef PETSC_USE_DYNAMIC_LIBRARIES ierr = KSPInitializePackage(PETSC_NULL);CHKERRQ(ierr); #endif ierr = PetscHeaderCreate(*kdm, _p_DMKSP, struct _DMKSPOps, DMKSP_CLASSID, -1, "DMKSP", "DMKSP", "DMKSP", comm, DMKSPDestroy, PETSC_NULL);CHKERRQ(ierr); ierr = PetscMemzero((*kdm)->ops, sizeof(struct _DMKSPOps));CHKERRQ(ierr); PetscFunctionReturn(0); }
EXTERN_C_BEGIN #undef __FUNCT__ #define __FUNCT__ "PetscDLLibraryRegister_petscksp" /* PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened. This one registers all the KSP and PC methods that are in the basic PETSc libpetscksp library. Input Parameter: path - library path */ PetscErrorCode PetscDLLibraryRegister_petscksp(const char path[]) { PetscErrorCode ierr; PetscFunctionBegin; ierr = PCInitializePackage(path);CHKERRQ(ierr); ierr = KSPInitializePackage(path);CHKERRQ(ierr); PetscFunctionReturn(0); }
/* PetscInitialize_DynamicLibraries - Adds the default dynamic link libraries to the search path. */ PETSC_INTERN PetscErrorCode PetscInitialize_DynamicLibraries(void) { char *libname[32]; PetscErrorCode ierr; PetscInt nmax,i; #if defined(PETSC_USE_DYNAMIC_LIBRARIES) && defined(PETSC_USE_SHARED_LIBRARIES) PetscBool preload; #endif PetscFunctionBegin; nmax = 32; ierr = PetscOptionsGetStringArray(NULL,NULL,"-dll_prepend",libname,&nmax,NULL);CHKERRQ(ierr); for (i=0; i<nmax; i++) { ierr = PetscDLLibraryPrepend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,libname[i]);CHKERRQ(ierr); ierr = PetscFree(libname[i]);CHKERRQ(ierr); } #if !defined(PETSC_USE_DYNAMIC_LIBRARIES) || !defined(PETSC_USE_SHARED_LIBRARIES) /* This just initializes the most basic PETSc stuff. The classes, from PetscDraw to PetscTS, are initialized the first time an XXCreate() is called. */ ierr = PetscSysInitializePackage();CHKERRQ(ierr); #else preload = PETSC_FALSE; ierr = PetscOptionsGetBool(NULL,NULL,"-dynamic_library_preload",&preload,NULL);CHKERRQ(ierr); if (preload) { PetscBool found; #if defined(PETSC_USE_SINGLE_LIBRARY) ierr = PetscLoadDynamicLibrary("",&found);CHKERRQ(ierr); if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc dynamic library \n You cannot move the dynamic libraries!"); #else ierr = PetscLoadDynamicLibrary("sys",&found);CHKERRQ(ierr); if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc dynamic library \n You cannot move the dynamic libraries!"); ierr = PetscLoadDynamicLibrary("vec",&found);CHKERRQ(ierr); if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc Vec dynamic library \n You cannot move the dynamic libraries!"); ierr = PetscLoadDynamicLibrary("mat",&found);CHKERRQ(ierr); if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc Mat dynamic library \n You cannot move the dynamic libraries!"); ierr = PetscLoadDynamicLibrary("dm",&found);CHKERRQ(ierr); if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc DM dynamic library \n You cannot move the dynamic libraries!"); ierr = PetscLoadDynamicLibrary("ksp",&found);CHKERRQ(ierr); if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc KSP dynamic library \n You cannot move the dynamic libraries!"); ierr = PetscLoadDynamicLibrary("snes",&found);CHKERRQ(ierr); if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc SNES dynamic library \n You cannot move the dynamic libraries!"); ierr = PetscLoadDynamicLibrary("ts",&found);CHKERRQ(ierr); if (!found) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_FILE_OPEN,"Unable to locate PETSc TS dynamic library \n You cannot move the dynamic libraries!"); #endif } #endif nmax = 32; ierr = PetscOptionsGetStringArray(NULL,NULL,"-dll_append",libname,&nmax,NULL);CHKERRQ(ierr); for (i=0; i<nmax; i++) { ierr = PetscDLLibraryAppend(PETSC_COMM_WORLD,&PetscDLLibrariesLoaded,libname[i]);CHKERRQ(ierr); ierr = PetscFree(libname[i]);CHKERRQ(ierr); } #if defined(PETSC_HAVE_THREADSAFETY) /* These must be done here because it is not safe for individual threads to call these initialize routines */ ierr = AOInitializePackage();CHKERRQ(ierr); ierr = PetscSFInitializePackage();CHKERRQ(ierr); #if !defined(PETSC_USE_COMPLEX) ierr = CharacteristicInitializePackage();CHKERRQ(ierr); #endif ierr = ISInitializePackage();CHKERRQ(ierr); ierr = VecInitializePackage();CHKERRQ(ierr); ierr = MatInitializePackage();CHKERRQ(ierr); ierr = DMInitializePackage();CHKERRQ(ierr); ierr = PCInitializePackage();CHKERRQ(ierr); ierr = KSPInitializePackage();CHKERRQ(ierr); ierr = SNESInitializePackage();CHKERRQ(ierr); ierr = TSInitializePackage();CHKERRQ(ierr); ierr = PetscCommDuplicate(PETSC_COMM_SELF,&PETSC_COMM_SELF_INNER,NULL);CHKERRQ(ierr); ierr = PetscCommDuplicate(PETSC_COMM_WORLD,&PETSC_COMM_WORLD_INNER,NULL);CHKERRQ(ierr); #endif PetscFunctionReturn(0); }