本文整理汇总了C++中KSPSetUp函数的典型用法代码示例。如果您正苦于以下问题:C++ KSPSetUp函数的具体用法?C++ KSPSetUp怎么用?C++ KSPSetUp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了KSPSetUp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: MatAssemblyBegin
void PETSc::Solve(void)
{
//start_clock("Before Assemble matrix and vector");
ierr = MatAssemblyBegin(A,MAT_FINAL_ASSEMBLY);
ierr = MatAssemblyEnd(A,MAT_FINAL_ASSEMBLY);
ierr = VecAssemblyBegin(x);
ierr = VecAssemblyEnd(x);
ierr = VecAssemblyBegin(b);
ierr = VecAssemblyEnd(b);
//stop_clock("After Assembly matrix and vector");
KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN);
KSPSetType(ksp,KSPBCGSL);
KSPBCGSLSetEll(ksp,2);
//KSPGetPC(ksp, &pc);
//PCSetType(pc, PCJACOBI);
KSPSetFromOptions(ksp);
KSPSetUp(ksp);
//start_clock("Before KSPSolve");
KSPSolve(ksp,b,x);
//stop_clock("After KSPSolve");
}
开发者ID:tonyguo1,项目名称:LSGFD,代码行数:29,代码来源:solver_petsc.cpp
示例2: main
int main(int argc,char **argv)
{
PetscErrorCode ierr;
PetscInt i;
KSP ksp;
DM da;
Vec x;
PetscInitialize(&argc,&argv,(char*)0,help);
ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
ierr = DMDACreate1d(PETSC_COMM_WORLD,DMDA_BOUNDARY_PERIODIC,-3,2,1,0,&da);CHKERRQ(ierr);
ierr = KSPSetDM(ksp,da);CHKERRQ(ierr);
ierr = KSPSetComputeRHS(ksp,ComputeRHS,NULL);CHKERRQ(ierr);
ierr = KSPSetComputeOperators(ksp,ComputeMatrix,NULL);CHKERRQ(ierr);
ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
ierr = DMCreateGlobalVector(da,&x);CHKERRQ(ierr);
ierr = ComputeInitialSolution(da,x);CHKERRQ(ierr);
ierr = DMSetApplicationContext(da,x);CHKERRQ(ierr);
ierr = KSPSetUp(ksp);CHKERRQ(ierr);
ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);
for (i=0; i<10; i++) {
ierr = KSPSolve(ksp,NULL,x);CHKERRQ(ierr);
ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr);
}
ierr = VecDestroy(&x);CHKERRQ(ierr);
ierr = KSPDestroy(&ksp);CHKERRQ(ierr);
ierr = DMDestroy(&da);CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
开发者ID:feelpp,项目名称:debian-petsc,代码行数:32,代码来源:ex28.c
示例3: main
int main(int argc,char **args)
{
KSP ksp; /* linear solver context */
Mat A; /* matrix */
Vec x,b; /* approx solution, RHS, exact solution */
PetscViewer fd; /* viewer */
PetscErrorCode ierr;
PetscInitialize(&argc,&args,(char *)0,help);
fd = PETSC_VIEWER_SOCKET_WORLD;
ierr = VecCreate(PETSC_COMM_WORLD,&b);CHKERRQ(ierr);
ierr = VecLoad(b,fd);CHKERRQ(ierr);
ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
ierr = MatLoad(A,fd);CHKERRQ(ierr);
ierr = VecDuplicate(b,&x);CHKERRQ(ierr);
ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
ierr = KSPSetOperators(ksp,A,A,SAME_NONZERO_PATTERN);CHKERRQ(ierr);
ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
ierr = KSPSetUp(ksp);CHKERRQ(ierr);
ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);
ierr = VecView(x,fd);CHKERRQ(ierr);
ierr = MatDestroy(&A);CHKERRQ(ierr);
ierr = VecDestroy(&b);CHKERRQ(ierr);
ierr = VecDestroy(&x);CHKERRQ(ierr);
ierr = KSPDestroy(&ksp);CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
开发者ID:erdc-cm,项目名称:petsc-dev,代码行数:31,代码来源:ex41.c
示例4: SFieldSolveFor
double SFieldSolveFor(SField sfv, double *Y, unsigned int yCount) {
mySField sf = static_cast<mySField>(sfv);
assert(yCount <= sf->maxN);
assert(Y);
assert(sf->running);
sf->Y = Y;
sf->curN = yCount;
// -------------- SOLVE
PetscErrorCode ierr;
PetscLogDouble tic,toc;
PetscTime(&tic);
int pt[sf->d];
ierr = MatZeroEntries(sf->J); CHKERRQ(ierr);
JacobianOnD(sf->J, sf->F, 0, pt, sf);
ierr = MatAssemblyBegin(sf->J,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
ierr = MatAssemblyEnd(sf->J,MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
PetscTime(&toc);
sf->timeAssembly += toc-tic;
PetscTime(&tic);
ierr = VecZeroEntries(sf->U); CHKERRQ(ierr);
ierr = KSPSetOperators(sf->ksp, sf->J, sf->J); CHKERRQ(ierr);
ierr = KSPSetUp(sf->ksp); CHKERRQ(ierr);
ierr = KSPSolve(sf->ksp,sf->F,sf->U); CHKERRQ(ierr);
PetscTime(&toc);
sf->timeSolver += toc-tic;
return Integrate(sf->U,pt,0,sf);
}
开发者ID:StochasticNumerics,项目名称:mimclib,代码行数:31,代码来源:matern.cpp
示例5: PCSetUp_KSP
static PetscErrorCode PCSetUp_KSP(PC pc)
{
PetscErrorCode ierr;
PC_KSP *jac = (PC_KSP*)pc->data;
Mat mat;
PetscBool A;
PetscFunctionBegin;
if (!jac->ksp) {ierr = PCKSPCreateKSP_KSP(pc);CHKERRQ(ierr);}
ierr = KSPSetFromOptions(jac->ksp);CHKERRQ(ierr);
if (jac->use_true_matrix) mat = pc->mat;
else mat = pc->pmat;
ierr = KSPGetOperatorsSet(jac->ksp,&A,PETSC_NULL);CHKERRQ(ierr);
if (!A) {
ierr = KSPSetOperators(jac->ksp,mat,pc->pmat,pc->flag);CHKERRQ(ierr);
} else if (pc->flag != SAME_PRECONDITIONER) {
Mat Amat,Bmat;
ierr = KSPGetOperators(jac->ksp,&Amat,&Bmat,PETSC_NULL);CHKERRQ(ierr);
if (Amat == mat && Bmat == pc->pmat) {
/* The user has not replaced the matrices so we are expected to forward the update. This incorrectly diagnoses
* changed matrices at the top level as the user manually changing the inner matrices, but we have no way to
* identify that in this context. The longer term solution is to track matrix state internally.
*/
ierr = KSPSetOperators(jac->ksp,mat,pc->pmat,pc->flag);CHKERRQ(ierr);
}
}
ierr = KSPSetUp(jac->ksp);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:erdc-cm,项目名称:petsc-dev,代码行数:30,代码来源:pcksp.c
示例6: MatCreateSchurComplement
/*@
MatSchurComplementComputeExplicitOperator - Compute the Schur complement matrix explicitly
Collective on Mat
Input Parameter:
. M - the matrix obtained with MatCreateSchurComplement()
Output Parameter:
. S - the Schur complement matrix
Note: This can be expensive, so it is mainly for testing
Level: advanced
.seealso: MatCreateSchurComplement(), MatSchurComplementUpdate()
@*/
PetscErrorCode MatSchurComplementComputeExplicitOperator(Mat M, Mat *S)
{
Mat B, C, D;
KSP ksp;
PC pc;
PetscBool isLU, isILU;
PetscReal fill = 2.0;
PetscErrorCode ierr;
PetscFunctionBegin;
ierr = MatSchurComplementGetSubMatrices(M, NULL, NULL, &B, &C, &D);CHKERRQ(ierr);
ierr = MatSchurComplementGetKSP(M, &ksp);CHKERRQ(ierr);
ierr = KSPGetPC(ksp, &pc);CHKERRQ(ierr);
ierr = PetscObjectTypeCompare((PetscObject) pc, PCLU, &isLU);CHKERRQ(ierr);
ierr = PetscObjectTypeCompare((PetscObject) pc, PCILU, &isILU);CHKERRQ(ierr);
if (isLU || isILU) {
Mat fact, Bd, AinvB, AinvBd;
PetscReal eps = 1.0e-10;
/* This can be sped up for banded LU */
ierr = KSPSetUp(ksp);CHKERRQ(ierr);
ierr = PCFactorGetMatrix(pc, &fact);CHKERRQ(ierr);
ierr = MatConvert(B, MATDENSE, MAT_INITIAL_MATRIX, &Bd);CHKERRQ(ierr);
ierr = MatDuplicate(Bd, MAT_DO_NOT_COPY_VALUES, &AinvBd);CHKERRQ(ierr);
ierr = MatMatSolve(fact, Bd, AinvBd);CHKERRQ(ierr);
ierr = MatDestroy(&Bd);CHKERRQ(ierr);
ierr = MatChop(AinvBd, eps);CHKERRQ(ierr);
ierr = MatConvert(AinvBd, MATAIJ, MAT_INITIAL_MATRIX, &AinvB);CHKERRQ(ierr);
ierr = MatDestroy(&AinvBd);CHKERRQ(ierr);
ierr = MatMatMult(C, AinvB, MAT_INITIAL_MATRIX, fill, S);CHKERRQ(ierr);
ierr = MatDestroy(&AinvB);CHKERRQ(ierr);
} else {
Mat Ainvd, Ainv;
ierr = PCComputeExplicitOperator(pc, &Ainvd);CHKERRQ(ierr);
ierr = MatConvert(Ainvd, MATAIJ, MAT_INITIAL_MATRIX, &Ainv);CHKERRQ(ierr);
ierr = MatDestroy(&Ainvd);CHKERRQ(ierr);
#if 0
/* Symmetric version */
ierr = MatPtAP(Ainv, B, MAT_INITIAL_MATRIX, fill, S);CHKERRQ(ierr);
#else
/* Nonsymmetric version */
ierr = MatMatMatMult(C, Ainv, B, MAT_INITIAL_MATRIX, fill, S);CHKERRQ(ierr);
#endif
ierr = MatDestroy(&Ainv);CHKERRQ(ierr);
}
ierr = PetscViewerPushFormat(PETSC_VIEWER_STDOUT_WORLD, PETSC_VIEWER_ASCII_INFO);CHKERRQ(ierr);
ierr = MatView(*S, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
ierr = PetscViewerPopFormat(PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
if (D) {
MatInfo info;
ierr = MatGetInfo(D, MAT_GLOBAL_SUM, &info);CHKERRQ(ierr);
if (info.nz_used) SETERRQ(PetscObjectComm((PetscObject) M), PETSC_ERR_SUP, "Not yet implemented");
}
PetscFunctionReturn(0);
}
开发者ID:fengyuqi,项目名称:petsc,代码行数:76,代码来源:schurm.c
示例7: KSPComputeShifts_GMRES
static PetscErrorCode KSPComputeShifts_GMRES(KSP ksp)
{
PetscErrorCode ierr;
KSP_AGMRES *agmres = (KSP_AGMRES*)(ksp->data);
KSP kspgmres;
Mat Amat, Pmat;
MatStructure flag;
PetscInt max_k = agmres->max_k;
PC pc;
PetscInt m;
PetscScalar *Rshift, *Ishift;
PetscFunctionBegin;
/* Perform one cycle of classical GMRES (with the Arnoldi process) to get the Hessenberg matrix
We assume here that the ksp is AGMRES and that the operators for the
linear system have been set in this ksp */
ierr = KSPCreate(PetscObjectComm((PetscObject)ksp), &kspgmres);CHKERRQ(ierr);
if (!ksp->pc) { ierr = KSPGetPC(ksp,&ksp->pc);CHKERRQ(ierr); }
ierr = PCGetOperators(ksp->pc, &Amat, &Pmat);CHKERRQ(ierr);
ierr = KSPSetOperators(kspgmres, Amat, Pmat);CHKERRQ(ierr);
ierr = KSPSetFromOptions(kspgmres);CHKERRQ(ierr);
ierr = PetscOptionsHasName(NULL, "-ksp_view", &flg);CHKERRQ(ierr);
if (flag) { ierr = PetscOptionsClearValue("-ksp_view");CHKERRQ(ierr); }
ierr = KSPSetType(kspgmres, KSPGMRES);CHKERRQ(ierr);
ierr = KSPGMRESSetRestart(kspgmres, max_k);CHKERRQ(ierr);
ierr = KSPGetPC(ksp, &pc);CHKERRQ(ierr);
ierr = KSPSetPC(kspgmres, pc);CHKERRQ(ierr);
/* Copy common options */
kspgmres->pc_side = ksp->pc_side;
/* Setup KSP context */
ierr = KSPSetComputeEigenvalues(kspgmres, PETSC_TRUE);CHKERRQ(ierr);
ierr = KSPSetUp(kspgmres);CHKERRQ(ierr);
kspgmres->max_it = max_k; /* Restrict the maximum number of iterations to one cycle of GMRES */
kspgmres->rtol = ksp->rtol;
ierr = KSPSolve(kspgmres, ksp->vec_rhs, ksp->vec_sol);CHKERRQ(ierr);
ksp->guess_zero = PETSC_FALSE;
ksp->rnorm = kspgmres->rnorm;
ksp->its = kspgmres->its;
if (kspgmres->reason == KSP_CONVERGED_RTOL) {
ksp->reason = KSP_CONVERGED_RTOL;
PetscFunctionReturn(0);
} else ksp->reason = KSP_CONVERGED_ITERATING;
/* Now, compute the Shifts values */
ierr = PetscMalloc2(max_k,&Rshift,max_k,&Ishift);CHKERRQ(ierr);
ierr = KSPComputeEigenvalues(kspgmres, max_k, Rshift, Ishift, &m);CHKERRQ(ierr);
if (m < max_k) SETERRQ(PetscObjectComm((PetscObject)ksp),PETSC_ERR_PLIB, "Unable to compute the Shifts for the Newton basis");
else {
ierr = KSPAGMRESLejaOrdering(Rshift, Ishift, agmres->Rshift, agmres->Ishift, max_k);CHKERRQ(ierr);
agmres->HasShifts = PETSC_TRUE;
}
/* Restore KSP view options */
if (flg) { ierr = PetscOptionsSetValue("-ksp_view", "");CHKERRQ(ierr); }
PetscFunctionReturn(0);
}
开发者ID:fengyuqi,项目名称:petsc,代码行数:59,代码来源:agmres.c
示例8: main
int main(int argc,char **argv)
{
KSP ksp;
DM da;
UserContext user;
const char *bcTypes[2] = {"dirichlet","neumann"};
PetscErrorCode ierr;
PetscInt bc;
Vec b,x;
PetscInitialize(&argc,&argv,(char *)0,help);
ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);
CHKERRQ(ierr);
ierr = DMDACreate2d(PETSC_COMM_WORLD, DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR,-3,-3,PETSC_DECIDE,PETSC_DECIDE,1,1,0,0,&da);
CHKERRQ(ierr);
ierr = DMDASetUniformCoordinates(da,0,1,0,1,0,0);
CHKERRQ(ierr);
ierr = DMDASetFieldName(da,0,"Pressure");
CHKERRQ(ierr);
ierr = PetscOptionsBegin(PETSC_COMM_WORLD, "", "Options for the inhomogeneous Poisson equation", "DMqq");
user.rho = 1.0;
ierr = PetscOptionsReal("-rho", "The conductivity", "ex29.c", user.rho, &user.rho, PETSC_NULL);
CHKERRQ(ierr);
user.nu = 0.1;
ierr = PetscOptionsReal("-nu", "The width of the Gaussian source", "ex29.c", user.nu, &user.nu, PETSC_NULL);
CHKERRQ(ierr);
bc = (PetscInt)DIRICHLET;
ierr = PetscOptionsEList("-bc_type","Type of boundary condition","ex29.c",bcTypes,2,bcTypes[0],&bc,PETSC_NULL);
CHKERRQ(ierr);
user.bcType = (BCType)bc;
ierr = PetscOptionsEnd();
ierr = KSPSetComputeRHS(ksp,ComputeRHS,&user);
CHKERRQ(ierr);
ierr = KSPSetComputeOperators(ksp,ComputeMatrix,&user);
CHKERRQ(ierr);
ierr = KSPSetDM(ksp,da);
CHKERRQ(ierr);
ierr = KSPSetFromOptions(ksp);
CHKERRQ(ierr);
ierr = KSPSetUp(ksp);
CHKERRQ(ierr);
ierr = KSPSolve(ksp,PETSC_NULL,PETSC_NULL);
CHKERRQ(ierr);
ierr = KSPGetSolution(ksp,&x);
CHKERRQ(ierr);
ierr = KSPGetRhs(ksp,&b);
CHKERRQ(ierr);
ierr = DMDestroy(&da);
CHKERRQ(ierr);
ierr = KSPDestroy(&ksp);
CHKERRQ(ierr);
ierr = PetscFinalize();
return 0;
}
开发者ID:erdc-cm,项目名称:petsc-dev,代码行数:59,代码来源:ex29.c
示例9: PCBDDCScalingSetUp_Deluxe_Private
static PetscErrorCode PCBDDCScalingSetUp_Deluxe_Private(PC pc)
{
PC_BDDC *pcbddc=(PC_BDDC*)pc->data;
PCBDDCDeluxeScaling deluxe_ctx=pcbddc->deluxe_ctx;
PCBDDCSubSchurs sub_schurs = pcbddc->sub_schurs;
PetscErrorCode ierr;
PetscFunctionBegin;
if (!sub_schurs->n_subs) {
PetscFunctionReturn(0);
}
/* Create work vectors for sequential part of deluxe */
ierr = MatCreateVecs(sub_schurs->S_Ej_all,&deluxe_ctx->seq_work1,&deluxe_ctx->seq_work2);CHKERRQ(ierr);
/* Compute deluxe sequential scatter */
if (sub_schurs->reuse_mumps && !sub_schurs->is_dir) {
PCBDDCReuseMumps reuse_mumps = sub_schurs->reuse_mumps;
ierr = PetscObjectReference((PetscObject)reuse_mumps->correction_scatter_B);CHKERRQ(ierr);
deluxe_ctx->seq_scctx = reuse_mumps->correction_scatter_B;
} else {
ierr = VecScatterCreate(pcbddc->work_scaling,sub_schurs->is_Ej_all,deluxe_ctx->seq_work1,NULL,&deluxe_ctx->seq_scctx);CHKERRQ(ierr);
}
/* Create Mat object for deluxe scaling */
ierr = PetscObjectReference((PetscObject)sub_schurs->S_Ej_all);CHKERRQ(ierr);
deluxe_ctx->seq_mat = sub_schurs->S_Ej_all;
if (sub_schurs->sum_S_Ej_all) { /* if this matrix is present, then we need to create the KSP object to invert it */
PC pc_temp;
MatSolverPackage solver=NULL;
char ksp_prefix[256];
size_t len;
ierr = KSPCreate(PETSC_COMM_SELF,&deluxe_ctx->seq_ksp);CHKERRQ(ierr);
ierr = KSPSetOperators(deluxe_ctx->seq_ksp,sub_schurs->sum_S_Ej_all,sub_schurs->sum_S_Ej_all);CHKERRQ(ierr);
ierr = KSPSetType(deluxe_ctx->seq_ksp,KSPPREONLY);CHKERRQ(ierr);
ierr = KSPGetPC(deluxe_ctx->seq_ksp,&pc_temp);CHKERRQ(ierr);
ierr = PCSetType(pc_temp,PCLU);CHKERRQ(ierr);
ierr = KSPGetPC(pcbddc->ksp_D,&pc_temp);CHKERRQ(ierr);
ierr = PCFactorGetMatSolverPackage(pc_temp,(const MatSolverPackage*)&solver);CHKERRQ(ierr);
if (solver) {
PC new_pc;
PCType type;
ierr = PCGetType(pc_temp,&type);CHKERRQ(ierr);
ierr = KSPGetPC(deluxe_ctx->seq_ksp,&new_pc);CHKERRQ(ierr);
ierr = PCSetType(new_pc,type);CHKERRQ(ierr);
ierr = PCFactorSetMatSolverPackage(new_pc,solver);CHKERRQ(ierr);
}
ierr = PetscStrlen(((PetscObject)(pcbddc->ksp_D))->prefix,&len);CHKERRQ(ierr);
len -= 10; /* remove "dirichlet_" */
ierr = PetscStrncpy(ksp_prefix,((PetscObject)(pcbddc->ksp_D))->prefix,len+1);CHKERRQ(ierr);
ierr = PetscStrcat(ksp_prefix,"deluxe_");CHKERRQ(ierr);
ierr = KSPSetOptionsPrefix(deluxe_ctx->seq_ksp,ksp_prefix);CHKERRQ(ierr);
ierr = KSPSetFromOptions(deluxe_ctx->seq_ksp);CHKERRQ(ierr);
ierr = KSPSetUp(deluxe_ctx->seq_ksp);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
开发者ID:masa-ito,项目名称:PETScToPoisson,代码行数:59,代码来源:bddcscalingbasic.c
示例10: TaoSetup_BLMVM
static PetscErrorCode TaoSetup_BLMVM(Tao tao)
{
TAO_BLMVM *blmP = (TAO_BLMVM *)tao->data;
PetscInt n,N;
PetscErrorCode ierr;
KSP H0ksp;
PetscFunctionBegin;
/* Existence of tao->solution checked in TaoSetup() */
ierr = VecDuplicate(tao->solution,&blmP->Xold);CHKERRQ(ierr);
ierr = VecDuplicate(tao->solution,&blmP->Gold);CHKERRQ(ierr);
ierr = VecDuplicate(tao->solution, &blmP->unprojected_gradient);CHKERRQ(ierr);
if (!tao->stepdirection) {
ierr = VecDuplicate(tao->solution, &tao->stepdirection);CHKERRQ(ierr);
}
if (!tao->gradient) {
ierr = VecDuplicate(tao->solution,&tao->gradient);CHKERRQ(ierr);
}
if (!tao->XL) {
ierr = VecDuplicate(tao->solution,&tao->XL);CHKERRQ(ierr);
ierr = VecSet(tao->XL,PETSC_NINFINITY);CHKERRQ(ierr);
}
if (!tao->XU) {
ierr = VecDuplicate(tao->solution,&tao->XU);CHKERRQ(ierr);
ierr = VecSet(tao->XU,PETSC_INFINITY);CHKERRQ(ierr);
}
/* Create matrix for the limited memory approximation */
ierr = VecGetLocalSize(tao->solution,&n);CHKERRQ(ierr);
ierr = VecGetSize(tao->solution,&N);CHKERRQ(ierr);
ierr = MatCreateLMVM(((PetscObject)tao)->comm,n,N,&blmP->M);CHKERRQ(ierr);
ierr = MatLMVMAllocateVectors(blmP->M,tao->solution);CHKERRQ(ierr);
/* If the user has set a matrix to solve as the initial H0, set the options prefix here, and set up the KSP */
if (blmP->H0) {
const char *prefix;
PC H0pc;
ierr = MatLMVMSetH0(blmP->M, blmP->H0);CHKERRQ(ierr);
ierr = MatLMVMGetH0KSP(blmP->M, &H0ksp);CHKERRQ(ierr);
ierr = TaoGetOptionsPrefix(tao, &prefix);CHKERRQ(ierr);
ierr = KSPSetOptionsPrefix(H0ksp, prefix);CHKERRQ(ierr);
ierr = PetscObjectAppendOptionsPrefix((PetscObject)H0ksp, "tao_h0_");CHKERRQ(ierr);
ierr = KSPGetPC(H0ksp, &H0pc);CHKERRQ(ierr);
ierr = PetscObjectAppendOptionsPrefix((PetscObject)H0pc, "tao_h0_");CHKERRQ(ierr);
ierr = KSPSetFromOptions(H0ksp);CHKERRQ(ierr);
ierr = KSPSetUp(H0ksp);CHKERRQ(ierr);
}
PetscFunctionReturn(0);
}
开发者ID:masa-ito,项目名称:PETScToPoisson,代码行数:53,代码来源:blmvm.c
示例11: MatCreate
void SingleLongPipe::initialize() {
MatCreate(PETSC_COMM_WORLD, &M);
MatSetSizes(M, local_n, local_n, global_n, global_n);
MatSetFromOptions(M);
MatMPIAIJSetPreallocation(M, 2, nullptr, 2, nullptr);
MatSeqAIJSetPreallocation(M, 2, nullptr);
MatSetUp(M);
KSPCreate(PETSC_COMM_WORLD, &ksp);
KSPSetOperators(ksp, M, M);
KSPSetFromOptions(ksp);
KSPSetUp(ksp);
}
开发者ID:whyzidane,项目名称:CO2_project,代码行数:12,代码来源:single_long_pipe_class.cpp
示例12: createOuterKsp
void createOuterKsp(OuterContext* ctx) {
KSPCreate((ctx->data)->commAll, &(ctx->outerKsp));
PetscObjectIncrementTabLevel((PetscObject)(ctx->outerKsp), PETSC_NULL, 0);
KSPSetType(ctx->outerKsp, KSPFGMRES);
KSPSetTolerances(ctx->outerKsp, 1.0e-12, 1.0e-12, PETSC_DEFAULT, 50);
KSPSetPC(ctx->outerKsp, ctx->outerPC);
KSPSetOptionsPrefix(ctx->outerKsp, "outer_");
KSPSetFromOptions(ctx->outerKsp);
KSPSetOperators(ctx->outerKsp, ctx->outerMat,
ctx->outerMat, SAME_NONZERO_PATTERN);
KSPSetUp(ctx->outerKsp);
}
开发者ID:hsundar,项目名称:schur,代码行数:12,代码来源:schurSetup.C
示例13: main
int main(int argc,char **args)
{
KSP ksp;
Mat A;
Vec x,b;
PetscViewer fd;
char file[PETSC_MAX_PATH_LEN];
PetscErrorCode ierr;
PetscBool flg,preload = PETSC_TRUE;
PetscInitialize(&argc,&args,(char*)0,help);
ierr = PetscLogDefaultBegin();CHKERRQ(ierr);
ierr = PetscOptionsGetString(NULL,NULL,"-f",file,PETSC_MAX_PATH_LEN,&flg);CHKERRQ(ierr);
PetscPreLoadBegin(preload,"Load system");
/*
Load the matrix and vector; then destroy the viewer.
*/
ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
ierr = MatSetFromOptions(A);CHKERRQ(ierr);
ierr = PetscViewerBinaryOpen(PETSC_COMM_WORLD,file,FILE_MODE_READ,&fd);CHKERRQ(ierr);
ierr = MatLoad(A,fd);CHKERRQ(ierr);
ierr = PetscViewerDestroy(&fd);CHKERRQ(ierr);
ierr = MatCreateVecs(A,&x,&b);CHKERRQ(ierr);
ierr = VecSetFromOptions(b);CHKERRQ(ierr);
ierr = VecSet(b,1.0);CHKERRQ(ierr);
ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
ierr = KSPSetOperators(ksp,A,A);CHKERRQ(ierr);
ierr = KSPSetUp(ksp);CHKERRQ(ierr);
ierr = KSPSetUpOnBlocks(ksp);CHKERRQ(ierr);
PetscPreLoadStage("KSPSolve");
ierr = KSPSolve(ksp,b,x);CHKERRQ(ierr);
ierr = MatDestroy(&A);CHKERRQ(ierr);
ierr = VecDestroy(&b);CHKERRQ(ierr);
ierr = VecDestroy(&x);CHKERRQ(ierr);
ierr = KSPDestroy(&ksp);CHKERRQ(ierr);
PetscPreLoadEnd();
ierr = PetscLogView_VecScatter(PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
ierr = PetscFinalize();
return ierr;
}
开发者ID:firedrakeproject,项目名称:petsc,代码行数:48,代码来源:ex1.c
示例14: main
int main(int argc, char **argv)
{
PetscErrorCode ierr;
Mat A;
KSP ksp;
PC pc;
IS zero, one;
MatNullSpace nullsp;
Vec x, b;
MPI_Comm comm;
PetscInitialize(&argc, &argv, NULL, NULL);
comm = PETSC_COMM_WORLD;
ierr = MatCreate(comm, &A);CHKERRQ(ierr);
ierr = MatSetSizes(A, 4, 4, PETSC_DECIDE, PETSC_DECIDE);CHKERRQ(ierr);
ierr = MatSetUp(A);CHKERRQ(ierr);
ierr = MatSetFromOptions(A);CHKERRQ(ierr);
ierr = MatCreateVecs(A, &x, &b);CHKERRQ(ierr);
ierr = VecSet(x, 2.0);CHKERRQ(ierr);
ierr = VecSet(b, 12.0);CHKERRQ(ierr);
ierr = MatDiagonalSet(A, x, INSERT_VALUES);CHKERRQ(ierr);
ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
ierr = ISCreateStride(comm, 2, 0, 1, &zero);CHKERRQ(ierr);
ierr = ISCreateStride(comm, 2, 2, 1, &one);CHKERRQ(ierr);
ierr = MatNullSpaceCreate(comm, PETSC_TRUE, 0, NULL, &nullsp);CHKERRQ(ierr);
ierr = PetscObjectCompose((PetscObject)zero, "nullspace",(PetscObject)nullsp);CHKERRQ(ierr);
ierr = KSPCreate(comm, &ksp);CHKERRQ(ierr);
ierr = KSPSetOperators(ksp, A, A);CHKERRQ(ierr);
ierr = KSPSetUp(ksp);CHKERRQ(ierr);
ierr = KSPGetPC(ksp, &pc);CHKERRQ(ierr);
ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
ierr = PCFieldSplitSetIS(pc, "0", zero);
ierr = PCFieldSplitSetIS(pc, "1", one);
ierr = KSPSolve(ksp, b, x);CHKERRQ(ierr);
ierr = KSPDestroy(&ksp);CHKERRQ(ierr);
ierr = MatNullSpaceDestroy(&nullsp);CHKERRQ(ierr);
ierr = ISDestroy(&zero);CHKERRQ(ierr);
ierr = ISDestroy(&one);CHKERRQ(ierr);
ierr = MatDestroy(&A);CHKERRQ(ierr);
ierr = VecDestroy(&x);CHKERRQ(ierr);
ierr = VecDestroy(&b);CHKERRQ(ierr);
PetscFinalize();
return 0;
}
开发者ID:plguhur,项目名称:petsc,代码行数:48,代码来源:ex47.c
示例15: KSPSetUp_SpecEst
static PetscErrorCode KSPSetUp_SpecEst(KSP ksp)
{
KSP_SpecEst *spec = (KSP_SpecEst*)ksp->data;
PetscErrorCode ierr;
PetscBool nonzero;
PetscFunctionBegin;
ierr = KSPSetPC(spec->kspest,ksp->pc);CHKERRQ(ierr);
ierr = KSPSetPC(spec->kspcheap,ksp->pc);CHKERRQ(ierr);
ierr = KSPGetInitialGuessNonzero(ksp,&nonzero);CHKERRQ(ierr);
ierr = KSPSetInitialGuessNonzero(spec->kspest,nonzero);CHKERRQ(ierr);
ierr = KSPSetInitialGuessNonzero(spec->kspcheap,nonzero);CHKERRQ(ierr);
ierr = KSPSetComputeSingularValues(spec->kspest,PETSC_TRUE);CHKERRQ(ierr);
ierr = KSPSetUp(spec->kspest);CHKERRQ(ierr);
spec->current = PETSC_FALSE;
PetscFunctionReturn(0);
}
开发者ID:Kun-Qu,项目名称:petsc,代码行数:17,代码来源:specest.c
示例16: PCSetUp_KSP
static PetscErrorCode PCSetUp_KSP(PC pc)
{
PetscErrorCode ierr;
PC_KSP *jac = (PC_KSP*)pc->data;
Mat mat;
PetscFunctionBegin;
if (!jac->ksp) {
ierr = PCKSPCreateKSP_KSP(pc);CHKERRQ(ierr);
ierr = KSPSetFromOptions(jac->ksp);CHKERRQ(ierr);
}
if (pc->useAmat) mat = pc->mat;
else mat = pc->pmat;
ierr = KSPSetOperators(jac->ksp,mat,pc->pmat);CHKERRQ(ierr);
ierr = KSPSetUp(jac->ksp);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:petsc,项目名称:petsc,代码行数:17,代码来源:pcksp.c
示例17: STMatSolve
/*@
STMatSetUp - Build the preconditioner matrix used in STMatSolve().
Collective on ST
Input Parameters:
+ st - the spectral transformation context
. sigma - the shift
- coeffs - the coefficients
Note:
This function is not intended to be called by end users, but by SLEPc
solvers that use ST. It builds matrix st->P as follows, then calls KSPSetUp().
.vb
If (coeffs): st->P = Sum_{i=0:nmat-1} coeffs[i]*sigma^i*A_i.
else st->P = Sum_{i=0:nmat-1} sigma^i*A_i
.ve
Level: developer
.seealso: STMatSolve()
@*/
PetscErrorCode STMatSetUp(ST st,PetscScalar sigma,PetscScalar *coeffs)
{
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidHeaderSpecific(st,ST_CLASSID,1);
PetscValidLogicalCollectiveScalar(st,sigma,2);
PetscValidScalarPointer(coeffs,2);
STCheckMatrices(st,1);
ierr = PetscLogEventBegin(ST_MatSetUp,st,0,0,0);CHKERRQ(ierr);
ierr = STMatMAXPY_Private(st,sigma,0.0,0,coeffs,PETSC_TRUE,&st->P);CHKERRQ(ierr);
if (!st->ksp) { ierr = STGetKSP(st,&st->ksp);CHKERRQ(ierr); }
ierr = KSPSetOperators(st->ksp,st->P,st->P);CHKERRQ(ierr);
ierr = KSPSetUp(st->ksp);CHKERRQ(ierr);
ierr = PetscLogEventEnd(ST_MatSetUp,st,0,0,0);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:OpenCMISS-Dependencies,项目名称:slepc,代码行数:40,代码来源:stsolve.c
示例18: ComputeKSPFETIDP
static PetscErrorCode ComputeKSPFETIDP(DomainData dd, KSP ksp_bddc, KSP *ksp_fetidp)
{
PetscErrorCode ierr;
KSP temp_ksp;
PC pc,D;
Mat F;
PetscFunctionBeginUser;
ierr = KSPGetPC(ksp_bddc,&pc);CHKERRQ(ierr);
ierr = PCBDDCCreateFETIDPOperators(pc,&F,&D);CHKERRQ(ierr);
ierr = KSPCreate(PetscObjectComm((PetscObject)F),&temp_ksp);CHKERRQ(ierr);
ierr = KSPSetOperators(temp_ksp,F,F);CHKERRQ(ierr);
ierr = KSPSetType(temp_ksp,KSPCG);CHKERRQ(ierr);
ierr = KSPSetPC(temp_ksp,D);CHKERRQ(ierr);
ierr = KSPSetComputeSingularValues(temp_ksp,PETSC_TRUE);CHKERRQ(ierr);
ierr = KSPSetFromOptions(temp_ksp);CHKERRQ(ierr);
ierr = KSPSetUp(temp_ksp);CHKERRQ(ierr);
*ksp_fetidp = temp_ksp;
ierr = MatDestroy(&F);CHKERRQ(ierr);
ierr = PCDestroy(&D);CHKERRQ(ierr);
PetscFunctionReturn(0);
}
开发者ID:tom-klotz,项目名称:petsc,代码行数:22,代码来源:ex59.c
示例19: main
int main(int argc, char **argv){
PetscErrorCode ierr;
Vec x,b;
Mat A;
KSP ksp;
ierr=PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
PetscPrintf(PETSC_COMM_WORLD,"]> Initializing PETSc/SLEPc\n");
/*Load data*/
ierr=loadInputs(&A,&b,&x);CHKERRQ(ierr);
PetscPrintf(PETSC_COMM_WORLD,"]> Data loaded\n");
/*Create the KSP context and setup*/
ierr = KSPCreate(PETSC_COMM_WORLD,&ksp);CHKERRQ(ierr);
ierr = KSPSetType(ksp,KSPFGMRES);CHKERRQ(ierr);
ierr = KSPSetOperators(ksp,A,A,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);
ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);
ierr = KSPSetUp(ksp);CHKERRQ(ierr);
PetscPrintf(PETSC_COMM_WORLD,"]> Krylov Solver settings done\n");
/*Solve the system*/
PetscPrintf(PETSC_COMM_WORLD,"]> Krylov Solver Launching solving process\n");
ierr = KSPSolve(ksp, b, x); CHKERRQ(ierr);
PetscPrintf(PETSC_COMM_WORLD,"]> Krylov Solver System solved\n");
/*Clean*/
ierr = KSPDestroy(&ksp);CHKERRQ(ierr);
ierr = VecDestroy(&b);CHKERRQ(ierr);
ierr = VecDestroy(&x);CHKERRQ(ierr);
ierr = MatDestroy(&A);CHKERRQ(ierr);
PetscPrintf(PETSC_COMM_WORLD,"]> Cleaned structures, finalizing\n");
/*Finalize PETSc*/
PetscFinalize();
return 0;
}
开发者ID:Perif,项目名称:PETScHPCBench,代码行数:38,代码来源:hpc_petsc_bench.c
示例20: KSPCreate
void Field_solver::create_solver_and_preconditioner( KSP *ksp, PC *pc, Mat *A )
{
PetscReal rtol = 1.e-12;
// Default.
// Possible to specify from command line using '-ksp_rtol' option.
PetscErrorCode ierr;
ierr = KSPCreate( PETSC_COMM_WORLD, ksp ); CHKERRXX(ierr);
ierr = KSPSetOperators( *ksp, *A, *A, DIFFERENT_NONZERO_PATTERN ); CHKERRXX(ierr);
//ierr = KSPSetOperators( *ksp, *A, *A ); CHKERRXX(ierr);
ierr = KSPGetPC( *ksp, pc ); CHKERRXX(ierr);
ierr = PCSetType( *pc, PCGAMG ); CHKERRXX(ierr);
ierr = KSPSetType( *ksp, KSPGMRES ); CHKERRXX(ierr);
ierr = KSPSetTolerances( *ksp, rtol,
PETSC_DEFAULT, PETSC_DEFAULT, PETSC_DEFAULT); CHKERRXX(ierr);
ierr = KSPSetFromOptions( *ksp ); CHKERRXX(ierr);
ierr = KSPSetInitialGuessNonzero( *ksp, PETSC_TRUE ); CHKERRXX( ierr );
// For test purposes
//ierr = KSPSetInitialGuessNonzero( *ksp, PETSC_FALSE ); CHKERRXX( ierr );
ierr = KSPSetUp( *ksp ); CHKERRXX(ierr);
return;
}
开发者ID:epicf,项目名称:ef,代码行数:24,代码来源:field_solver.cpp
注:本文中的KSPSetUp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论