Actual source code: pciss.c

slepc-3.17.1 2022-04-11
Report Typos and Errors
  1: /*
  2:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  3:    SLEPc - Scalable Library for Eigenvalue Problem Computations
  4:    Copyright (c) 2002-, Universitat Politecnica de Valencia, Spain

  6:    This file is part of SLEPc.
  7:    SLEPc is distributed under a 2-clause BSD license (see LICENSE).
  8:    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  9: */
 10: /*
 11:    SLEPc eigensolver: "ciss"

 13:    Method: Contour Integral Spectral Slicing

 15:    Algorithm:

 17:        Contour integral based on Sakurai-Sugiura method to construct a
 18:        subspace, with various eigenpair extractions (Rayleigh-Ritz,
 19:        explicit moment).

 21:    Based on code contributed by Y. Maeda, T. Sakurai.

 23:    References:

 25:        [1] J. Asakura, T. Sakurai, H. Tadano, T. Ikegami, K. Kimura, "A
 26:            numerical method for polynomial eigenvalue problems using contour
 27:            integral", Japan J. Indust. Appl. Math. 27:73-90, 2010.
 28: */

 30: #include <slepc/private/pepimpl.h>
 31: #include <slepc/private/slepccontour.h>

 33: typedef struct {
 34:   /* parameters */
 35:   PetscInt          N;             /* number of integration points (32) */
 36:   PetscInt          L;             /* block size (16) */
 37:   PetscInt          M;             /* moment degree (N/4 = 4) */
 38:   PetscReal         delta;         /* threshold of singular value (1e-12) */
 39:   PetscInt          L_max;         /* maximum number of columns of the source matrix V */
 40:   PetscReal         spurious_threshold; /* discard spurious eigenpairs */
 41:   PetscBool         isreal;        /* T(z) is real for real z */
 42:   PetscInt          npart;         /* number of partitions */
 43:   PetscInt          refine_inner;
 44:   PetscInt          refine_blocksize;
 45:   PEPCISSExtraction extraction;
 46:   /* private data */
 47:   SlepcContourData  contour;
 48:   PetscReal         *sigma;        /* threshold for numerical rank */
 49:   PetscScalar       *weight;
 50:   PetscScalar       *omega;
 51:   PetscScalar       *pp;
 52:   BV                V;
 53:   BV                S;
 54:   BV                Y;
 55:   PetscBool         useconj;
 56:   Mat               J,*Psplit;     /* auxiliary matrices */
 57:   BV                pV;
 58:   PetscObjectId     rgid;
 59:   PetscObjectState  rgstate;
 60: } PEP_CISS;

 62: static PetscErrorCode PEPComputeFunction(PEP pep,PetscScalar lambda,Mat T,Mat P,PetscBool deriv)
 63: {
 64:   PetscInt         i;
 65:   PetscScalar      *coeff;
 66:   Mat              *A,*K;
 67:   MatStructure     str,strp;
 68:   PEP_CISS         *ctx = (PEP_CISS*)pep->data;
 69:   SlepcContourData contour = ctx->contour;

 71:   A = (contour->pA)?contour->pA:pep->A;
 72:   K = (contour->pP)?contour->pP:ctx->Psplit;
 73:   PetscMalloc1(pep->nmat,&coeff);
 74:   if (deriv) PEPEvaluateBasisDerivative(pep,lambda,0,coeff,NULL);
 75:   else PEPEvaluateBasis(pep,lambda,0,coeff,NULL);
 76:   STGetMatStructure(pep->st,&str);
 77:   MatZeroEntries(T);
 78:   if (!deriv && T != P) {
 79:     STGetSplitPreconditionerInfo(pep->st,NULL,&strp);
 80:     MatZeroEntries(P);
 81:   }
 82:   i = deriv?1:0;
 83:   for (;i<pep->nmat;i++) {
 84:     MatAXPY(T,coeff[i],A[i],str);
 85:     if (!deriv && T != P) MatAXPY(P,coeff[i],K[i],strp);
 86:   }
 87:   PetscFree(coeff);
 88:   PetscFunctionReturn(0);
 89: }

 91: /*
 92:   Set up KSP solvers for every integration point
 93: */
 94: static PetscErrorCode PEPCISSSetUp(PEP pep,Mat T,Mat P)
 95: {
 96:   PEP_CISS         *ctx = (PEP_CISS*)pep->data;
 97:   SlepcContourData contour;
 98:   PetscInt         i,p_id;
 99:   Mat              Amat,Pmat;

101:   if (!ctx->contour || !ctx->contour->ksp) PEPCISSGetKSPs(pep,NULL,NULL);
102:   contour = ctx->contour;
103:   for (i=0;i<contour->npoints;i++) {
104:     p_id = i*contour->subcomm->n + contour->subcomm->color;
105:     MatDuplicate(T,MAT_DO_NOT_COPY_VALUES,&Amat);
106:     if (T != P) MatDuplicate(P,MAT_DO_NOT_COPY_VALUES,&Pmat); else Pmat = Amat;
107:     PEPComputeFunction(pep,ctx->omega[p_id],Amat,Pmat,PETSC_FALSE);
108:     PEP_KSPSetOperators(contour->ksp[i],Amat,Pmat);
109:     MatDestroy(&Amat);
110:     if (T != P) MatDestroy(&Pmat);
111:   }
112:   PetscFunctionReturn(0);
113: }

115: /*
116:   Y_i = F(z_i)^{-1}Fp(z_i)V for every integration point, Y=[Y_i] is in the context
117: */
118: static PetscErrorCode PEPCISSSolve(PEP pep,Mat dT,BV V,PetscInt L_start,PetscInt L_end)
119: {
120:   PEP_CISS         *ctx = (PEP_CISS*)pep->data;
121:   SlepcContourData contour;
122:   PetscInt         i,p_id;
123:   Mat              MV,BMV=NULL,MC;

125:   contour = ctx->contour;
126:   BVSetActiveColumns(V,L_start,L_end);
127:   BVGetMat(V,&MV);
128:   for (i=0;i<contour->npoints;i++) {
129:     p_id = i*contour->subcomm->n + contour->subcomm->color;
130:     PEPComputeFunction(pep,ctx->omega[p_id],dT,NULL,PETSC_TRUE);
131:     BVSetActiveColumns(ctx->Y,i*ctx->L+L_start,i*ctx->L+L_end);
132:     BVGetMat(ctx->Y,&MC);
133:     if (!i) {
134:       MatProductCreate(dT,MV,NULL,&BMV);
135:       MatProductSetType(BMV,MATPRODUCT_AB);
136:       MatProductSetFromOptions(BMV);
137:       MatProductSymbolic(BMV);
138:     }
139:     MatProductNumeric(BMV);
140:     KSPMatSolve(contour->ksp[i],BMV,MC);
141:     BVRestoreMat(ctx->Y,&MC);
142:   }
143:   MatDestroy(&BMV);
144:   BVRestoreMat(V,&MV);
145:   PetscFunctionReturn(0);
146: }

148: PetscErrorCode PEPSetUp_CISS(PEP pep)
149: {
150:   PEP_CISS         *ctx = (PEP_CISS*)pep->data;
151:   SlepcContourData contour;
152:   PetscInt         i,nwork,nsplit;
153:   PetscBool        istrivial,isellipse,flg;
154:   PetscObjectId    id;
155:   PetscObjectState state;
156:   Vec              v0;

158:   if (pep->ncv==PETSC_DEFAULT) pep->ncv = ctx->L_max*ctx->M;
159:   else {
160:     ctx->L_max = pep->ncv/ctx->M;
161:     if (!ctx->L_max) {
162:       ctx->L_max = 1;
163:       pep->ncv = ctx->L_max*ctx->M;
164:     }
165:   }
166:   ctx->L = PetscMin(ctx->L,ctx->L_max);
167:   if (pep->max_it==PETSC_DEFAULT) pep->max_it = 5;
168:   if (pep->mpd==PETSC_DEFAULT) pep->mpd = pep->ncv;
169:   if (!pep->which) pep->which = PEP_ALL;
171:   PEPCheckUnsupported(pep,PEP_FEATURE_STOPPING);
172:   PEPCheckIgnored(pep,PEP_FEATURE_SCALE);

174:   /* check region */
175:   RGIsTrivial(pep->rg,&istrivial);
177:   RGGetComplement(pep->rg,&flg);
179:   PetscObjectTypeCompare((PetscObject)pep->rg,RGELLIPSE,&isellipse);

182:   /* if the region has changed, then reset contour data */
183:   PetscObjectGetId((PetscObject)pep->rg,&id);
184:   PetscObjectStateGet((PetscObject)pep->rg,&state);
185:   if (ctx->rgid && (id != ctx->rgid || state != ctx->rgstate)) {
186:     SlepcContourDataDestroy(&ctx->contour);
187:     PetscInfo(pep,"Resetting the contour data structure due to a change of region\n");
188:     ctx->rgid = id; ctx->rgstate = state;
189:   }

191:   /* create contour data structure */
192:   if (!ctx->contour) {
193:     RGCanUseConjugates(pep->rg,ctx->isreal,&ctx->useconj);
194:     SlepcContourDataCreate(ctx->useconj?ctx->N/2:ctx->N,ctx->npart,(PetscObject)pep,&ctx->contour);
195:   }

197:   PEPAllocateSolution(pep,0);
198:   if (ctx->weight) PetscFree4(ctx->weight,ctx->omega,ctx->pp,ctx->sigma);
199:   PetscMalloc4(ctx->N,&ctx->weight,ctx->N,&ctx->omega,ctx->N,&ctx->pp,ctx->L_max*ctx->M,&ctx->sigma);
200:   PetscLogObjectMemory((PetscObject)pep,3*ctx->N*sizeof(PetscScalar)+ctx->L_max*ctx->N*sizeof(PetscReal));

202:   /* allocate basis vectors */
203:   BVDestroy(&ctx->S);
204:   BVDuplicateResize(pep->V,ctx->L*ctx->M,&ctx->S);
205:   PetscLogObjectParent((PetscObject)pep,(PetscObject)ctx->S);
206:   BVDestroy(&ctx->V);
207:   BVDuplicateResize(pep->V,ctx->L,&ctx->V);
208:   PetscLogObjectParent((PetscObject)pep,(PetscObject)ctx->V);

210:   /* check if a user-defined split preconditioner has been set */
211:   STGetSplitPreconditionerInfo(pep->st,&nsplit,NULL);
212:   if (nsplit) {
213:     PetscFree(ctx->Psplit);
214:     PetscMalloc1(nsplit,&ctx->Psplit);
215:     for (i=0;i<nsplit;i++) STGetSplitPreconditionerTerm(pep->st,i,&ctx->Psplit[i]);
216:   }

218:   contour = ctx->contour;
219:   SlepcContourRedundantMat(contour,pep->nmat,pep->A,ctx->Psplit);
220:   if (!ctx->J) {
221:     MatDuplicate(contour->pA?contour->pA[0]:pep->A[0],MAT_DO_NOT_COPY_VALUES,&ctx->J);
222:     PetscLogObjectParent((PetscObject)pep,(PetscObject)ctx->J);
223:   }
224:   if (contour->pA) {
225:     BVGetColumn(ctx->V,0,&v0);
226:     SlepcContourScatterCreate(contour,v0);
227:     BVRestoreColumn(ctx->V,0,&v0);
228:     BVDestroy(&ctx->pV);
229:     BVCreate(PetscObjectComm((PetscObject)contour->xsub),&ctx->pV);
230:     BVSetSizesFromVec(ctx->pV,contour->xsub,pep->n);
231:     BVSetFromOptions(ctx->pV);
232:     BVResize(ctx->pV,ctx->L,PETSC_FALSE);
233:     PetscLogObjectParent((PetscObject)pep,(PetscObject)ctx->pV);
234:   }

236:   BVDestroy(&ctx->Y);
237:   if (contour->pA) {
238:     BVCreate(PetscObjectComm((PetscObject)contour->xsub),&ctx->Y);
239:     BVSetSizesFromVec(ctx->Y,contour->xsub,pep->n);
240:     BVSetFromOptions(ctx->Y);
241:     BVResize(ctx->Y,contour->npoints*ctx->L,PETSC_FALSE);
242:   } else BVDuplicateResize(pep->V,contour->npoints*ctx->L,&ctx->Y);

244:   if (ctx->extraction == PEP_CISS_EXTRACTION_HANKEL) DSSetType(pep->ds,DSGNHEP);
245:   else if (ctx->extraction == PEP_CISS_EXTRACTION_CAA) DSSetType(pep->ds,DSNHEP);
246:   else {
247:     DSSetType(pep->ds,DSPEP);
248:     DSPEPSetDegree(pep->ds,pep->nmat-1);
249:     DSPEPSetCoefficients(pep->ds,pep->pbc);
250:   }
251:   DSAllocate(pep->ds,pep->ncv);
252:   nwork = 2;
253:   PEPSetWorkVecs(pep,nwork);
254:   PetscFunctionReturn(0);
255: }

257: PetscErrorCode PEPSolve_CISS(PEP pep)
258: {
259:   PEP_CISS         *ctx = (PEP_CISS*)pep->data;
260:   SlepcContourData contour = ctx->contour;
261:   Mat              X,M,E,T,P;
262:   PetscInt         i,j,ld,L_add=0,nv=0,L_base=ctx->L,inner,*inside,nsplit;
263:   PetscScalar      *Mu,*H0,*H1,*rr,*temp,center;
264:   PetscReal        error,max_error,radius,rgscale,est_eig,eta;
265:   PetscBool        isellipse,*fl1;
266:   Vec              si;
267:   SlepcSC          sc;
268:   PetscRandom      rand;

270:   DSSetFromOptions(pep->ds);
271:   DSGetSlepcSC(pep->ds,&sc);
272:   sc->comparison    = SlepcCompareLargestMagnitude;
273:   sc->comparisonctx = NULL;
274:   sc->map           = NULL;
275:   sc->mapobj        = NULL;
276:   DSGetLeadingDimension(pep->ds,&ld);
277:   RGComputeQuadrature(pep->rg,RG_QUADRULE_TRAPEZOIDAL,ctx->N,ctx->omega,ctx->pp,ctx->weight);
278:   STGetSplitPreconditionerInfo(pep->st,&nsplit,NULL);
279:   if (contour->pA) {
280:     T = contour->pA[0];
281:     P = nsplit? contour->pP[0]: T;
282:   } else {
283:     T = pep->A[0];
284:     P = nsplit? ctx->Psplit[0]: T;
285:   }
286:   PEPCISSSetUp(pep,T,P);
287:   BVSetActiveColumns(ctx->V,0,ctx->L);
288:   BVSetRandomSign(ctx->V);
289:   BVGetRandomContext(ctx->V,&rand);
290:   if (contour->pA) BVScatter(ctx->V,ctx->pV,contour->scatterin,contour->xdup);
291:   PEPCISSSolve(pep,ctx->J,(contour->pA)?ctx->pV:ctx->V,0,ctx->L);
292:   PetscObjectTypeCompare((PetscObject)pep->rg,RGELLIPSE,&isellipse);
293:   if (isellipse) {
294:     BVTraceQuadrature(ctx->Y,ctx->V,ctx->L,ctx->L,ctx->weight,contour->scatterin,contour->subcomm,contour->npoints,ctx->useconj,&est_eig);
295:     PetscInfo(pep,"Estimated eigenvalue count: %f\n",(double)est_eig);
296:     eta = PetscPowReal(10.0,-PetscLog10Real(pep->tol)/ctx->N);
297:     L_add = PetscMax(0,(PetscInt)PetscCeilReal((est_eig*eta)/ctx->M)-ctx->L);
298:     if (L_add>ctx->L_max-ctx->L) {
299:       PetscInfo(pep,"Number of eigenvalues inside the contour path may be too large\n");
300:       L_add = ctx->L_max-ctx->L;
301:     }
302:   }
303:   /* Updates L after estimate the number of eigenvalue */
304:   if (L_add>0) {
305:     PetscInfo(pep,"Changing L %" PetscInt_FMT " -> %" PetscInt_FMT " by Estimate #Eig\n",ctx->L,ctx->L+L_add);
306:     BVCISSResizeBases(ctx->S,contour->pA?ctx->pV:ctx->V,ctx->Y,ctx->L,ctx->L+L_add,ctx->M,contour->npoints);
307:     BVSetActiveColumns(ctx->V,ctx->L,ctx->L+L_add);
308:     BVSetRandomSign(ctx->V);
309:     if (contour->pA) BVScatter(ctx->V,ctx->pV,contour->scatterin,contour->xdup);
310:     ctx->L += L_add;
311:     PEPCISSSolve(pep,ctx->J,(contour->pA)?ctx->pV:ctx->V,ctx->L-L_add,ctx->L);
312:   }

314:   PetscMalloc2(ctx->L*ctx->L*ctx->M*2,&Mu,ctx->L*ctx->M*ctx->L*ctx->M,&H0);
315:   for (i=0;i<ctx->refine_blocksize;i++) {
316:     BVDotQuadrature(ctx->Y,(contour->pA)?ctx->pV:ctx->V,Mu,ctx->M,ctx->L,ctx->L,ctx->weight,ctx->pp,contour->subcomm,contour->npoints,ctx->useconj);
317:     CISS_BlockHankel(Mu,0,ctx->L,ctx->M,H0);
318:     PetscLogEventBegin(PEP_CISS_SVD,pep,0,0,0);
319:     SlepcCISS_BH_SVD(H0,ctx->L*ctx->M,ctx->delta,ctx->sigma,&nv);
320:     PetscLogEventEnd(PEP_CISS_SVD,pep,0,0,0);
321:     if (ctx->sigma[0]<=ctx->delta || nv < ctx->L*ctx->M || ctx->L == ctx->L_max) break;
322:     L_add = L_base;
323:     if (ctx->L+L_add>ctx->L_max) L_add = ctx->L_max-ctx->L;
324:     PetscInfo(pep,"Changing L %" PetscInt_FMT " -> %" PetscInt_FMT " by SVD(H0)\n",ctx->L,ctx->L+L_add);
325:     BVCISSResizeBases(ctx->S,contour->pA?ctx->pV:ctx->V,ctx->Y,ctx->L,ctx->L+L_add,ctx->M,contour->npoints);
326:     BVSetActiveColumns(ctx->V,ctx->L,ctx->L+L_add);
327:     BVSetRandomSign(ctx->V);
328:     if (contour->pA) BVScatter(ctx->V,ctx->pV,contour->scatterin,contour->xdup);
329:     ctx->L += L_add;
330:     PEPCISSSolve(pep,ctx->J,(contour->pA)?ctx->pV:ctx->V,ctx->L-L_add,ctx->L);
331:     if (L_add) {
332:       PetscFree2(Mu,H0);
333:       PetscMalloc2(ctx->L*ctx->L*ctx->M*2,&Mu,ctx->L*ctx->M*ctx->L*ctx->M,&H0);
334:     }
335:   }

337:   RGGetScale(pep->rg,&rgscale);
338:   RGEllipseGetParameters(pep->rg,&center,&radius,NULL);

340:   if (ctx->extraction == PEP_CISS_EXTRACTION_HANKEL) PetscMalloc1(ctx->L*ctx->M*ctx->L*ctx->M,&H1);

342:   while (pep->reason == PEP_CONVERGED_ITERATING) {
343:     pep->its++;
344:     for (inner=0;inner<=ctx->refine_inner;inner++) {
345:       if (ctx->extraction == PEP_CISS_EXTRACTION_HANKEL) {
346:         BVDotQuadrature(ctx->Y,(contour->pA)?ctx->pV:ctx->V,Mu,ctx->M,ctx->L,ctx->L,ctx->weight,ctx->pp,contour->subcomm,contour->npoints,ctx->useconj);
347:         CISS_BlockHankel(Mu,0,ctx->L,ctx->M,H0);
348:         PetscLogEventBegin(PEP_CISS_SVD,pep,0,0,0);
349:         SlepcCISS_BH_SVD(H0,ctx->L*ctx->M,ctx->delta,ctx->sigma,&nv);
350:         PetscLogEventEnd(PEP_CISS_SVD,pep,0,0,0);
351:       } else {
352:         BVSumQuadrature(ctx->S,ctx->Y,ctx->M,ctx->L,ctx->L,ctx->weight,ctx->pp,contour->scatterin,contour->subcomm,contour->npoints,ctx->useconj);
353:         /* compute SVD of S */
354:         BVSVDAndRank(ctx->S,ctx->M,ctx->L,ctx->delta,(ctx->extraction==PEP_CISS_EXTRACTION_CAA)?BV_SVD_METHOD_QR_CAA:BV_SVD_METHOD_QR,H0,ctx->sigma,&nv);
355:       }
356:       PetscInfo(pep,"Estimated rank: nv = %" PetscInt_FMT "\n",nv);
357:       if (ctx->sigma[0]>ctx->delta && nv==ctx->L*ctx->M && inner!=ctx->refine_inner) {
358:         BVSumQuadrature(ctx->S,ctx->Y,ctx->M,ctx->L,ctx->L,ctx->weight,ctx->pp,contour->scatterin,contour->subcomm,contour->npoints,ctx->useconj);
359:         BVSetActiveColumns(ctx->S,0,ctx->L);
360:         BVSetActiveColumns(ctx->V,0,ctx->L);
361:         BVCopy(ctx->S,ctx->V);
362:         if (contour->pA) BVScatter(ctx->V,ctx->pV,contour->scatterin,contour->xdup);
363:         PEPCISSSolve(pep,ctx->J,(contour->pA)?ctx->pV:ctx->V,0,ctx->L);
364:       } else break;
365:     }
366:     pep->nconv = 0;
367:     if (nv == 0) { pep->reason = PEP_CONVERGED_TOL; break; }
368:     else {
369:       /* Extracting eigenpairs */
370:       DSSetDimensions(pep->ds,nv,0,0);
371:       DSSetState(pep->ds,DS_STATE_RAW);
372:       if (ctx->extraction == PEP_CISS_EXTRACTION_HANKEL) {
373:         CISS_BlockHankel(Mu,0,ctx->L,ctx->M,H0);
374:         CISS_BlockHankel(Mu,1,ctx->L,ctx->M,H1);
375:         DSGetArray(pep->ds,DS_MAT_A,&temp);
376:         for (j=0;j<nv;j++)
377:           for (i=0;i<nv;i++)
378:             temp[i+j*ld] = H1[i+j*ctx->L*ctx->M];
379:         DSRestoreArray(pep->ds,DS_MAT_A,&temp);
380:         DSGetArray(pep->ds,DS_MAT_B,&temp);
381:         for (j=0;j<nv;j++)
382:           for (i=0;i<nv;i++)
383:             temp[i+j*ld] = H0[i+j*ctx->L*ctx->M];
384:         DSRestoreArray(pep->ds,DS_MAT_B,&temp);
385:       } else if (ctx->extraction == PEP_CISS_EXTRACTION_CAA) {
386:         BVSetActiveColumns(ctx->S,0,nv);
387:         DSGetArray(pep->ds,DS_MAT_A,&temp);
388:         for (i=0;i<nv;i++) PetscArraycpy(temp+i*ld,H0+i*nv,nv);
389:         DSRestoreArray(pep->ds,DS_MAT_A,&temp);
390:       } else {
391:         BVSetActiveColumns(ctx->S,0,nv);
392:         for (i=0;i<pep->nmat;i++) {
393:           DSGetMat(pep->ds,DSMatExtra[i],&E);
394:           BVMatProject(ctx->S,pep->A[i],ctx->S,E);
395:           DSRestoreMat(pep->ds,DSMatExtra[i],&E);
396:         }
397:         nv = (pep->nmat-1)*nv;
398:       }
399:       DSSolve(pep->ds,pep->eigr,pep->eigi);
400:       DSSynchronize(pep->ds,pep->eigr,pep->eigi);
401:       if (ctx->extraction == PEP_CISS_EXTRACTION_CAA || ctx->extraction == PEP_CISS_EXTRACTION_HANKEL) {
402:         for (i=0;i<nv;i++) {
403:           pep->eigr[i] = (pep->eigr[i]*radius+center)*rgscale;
404:         }
405:       }
406:       PetscMalloc3(nv,&fl1,nv,&inside,nv,&rr);
407:       DSVectors(pep->ds,DS_MAT_X,NULL,NULL);
408:       DSGetMat(pep->ds,DS_MAT_X,&X);
409:       SlepcCISS_isGhost(X,nv,ctx->sigma,ctx->spurious_threshold,fl1);
410:       MatDestroy(&X);
411:       RGCheckInside(pep->rg,nv,pep->eigr,pep->eigi,inside);
412:       for (i=0;i<nv;i++) {
413:         if (fl1[i] && inside[i]>=0) {
414:           rr[i] = 1.0;
415:           pep->nconv++;
416:         } else rr[i] = 0.0;
417:       }
418:       DSSort(pep->ds,pep->eigr,pep->eigi,rr,NULL,&pep->nconv);
419:       DSSynchronize(pep->ds,pep->eigr,pep->eigi);
420:       if (ctx->extraction == PEP_CISS_EXTRACTION_CAA || ctx->extraction == PEP_CISS_EXTRACTION_HANKEL) {
421:         for (i=0;i<nv;i++) pep->eigr[i] = (pep->eigr[i]*radius+center)*rgscale;
422:       }
423:       PetscFree3(fl1,inside,rr);
424:       BVSetActiveColumns(pep->V,0,nv);
425:       DSVectors(pep->ds,DS_MAT_X,NULL,NULL);
426:       if (ctx->extraction == PEP_CISS_EXTRACTION_HANKEL) {
427:         BVSumQuadrature(ctx->S,ctx->Y,ctx->M,ctx->L,ctx->L,ctx->weight,ctx->pp,contour->scatterin,contour->subcomm,contour->npoints,ctx->useconj);
428:         BVSetActiveColumns(ctx->S,0,nv);
429:         BVCopy(ctx->S,pep->V);
430:         DSGetMat(pep->ds,DS_MAT_X,&X);
431:         BVMultInPlace(ctx->S,X,0,pep->nconv);
432:         BVMultInPlace(pep->V,X,0,pep->nconv);
433:         MatDestroy(&X);
434:       } else {
435:         DSGetMat(pep->ds,DS_MAT_X,&X);
436:         BVMultInPlace(ctx->S,X,0,pep->nconv);
437:         MatDestroy(&X);
438:         BVSetActiveColumns(ctx->S,0,pep->nconv);
439:         BVCopy(ctx->S,pep->V);
440:       }
441:       max_error = 0.0;
442:       for (i=0;i<pep->nconv;i++) {
443:         BVGetColumn(pep->V,i,&si);
444:         VecNormalize(si,NULL);
445:         PEPComputeResidualNorm_Private(pep,pep->eigr[i],0,si,NULL,pep->work,&error);
446:         (*pep->converged)(pep,pep->eigr[i],0,error,&error,pep->convergedctx);
447:         BVRestoreColumn(pep->V,i,&si);
448:         max_error = PetscMax(max_error,error);
449:       }
450:       if (max_error <= pep->tol) pep->reason = PEP_CONVERGED_TOL;
451:       else if (pep->its > pep->max_it) pep->reason = PEP_DIVERGED_ITS;
452:       else {
453:         if (pep->nconv > ctx->L) nv = pep->nconv;
454:         else if (ctx->L > nv) nv = ctx->L;
455:         nv = PetscMin(nv,ctx->L*ctx->M);
456:         MatCreateSeqDense(PETSC_COMM_SELF,nv,ctx->L,NULL,&M);
457:         MatSetRandom(M,rand);
458:         BVSetActiveColumns(ctx->S,0,nv);
459:         BVMultInPlace(ctx->S,M,0,ctx->L);
460:         MatDestroy(&M);
461:         BVSetActiveColumns(ctx->S,0,ctx->L);
462:         BVSetActiveColumns(ctx->V,0,ctx->L);
463:         BVCopy(ctx->S,ctx->V);
464:         if (contour->pA) BVScatter(ctx->V,ctx->pV,contour->scatterin,contour->xdup);
465:         PEPCISSSolve(pep,ctx->J,(contour->pA)?ctx->pV:ctx->V,0,ctx->L);
466:       }
467:     }
468:   }
469:   PetscFree2(Mu,H0);
470:   if (ctx->extraction == PEP_CISS_EXTRACTION_HANKEL) PetscFree(H1);
471:   PetscFunctionReturn(0);
472: }

474: static PetscErrorCode PEPCISSSetSizes_CISS(PEP pep,PetscInt ip,PetscInt bs,PetscInt ms,PetscInt npart,PetscInt bsmax,PetscBool realmats)
475: {
476:   PEP_CISS       *ctx = (PEP_CISS*)pep->data;
477:   PetscInt       oN,oL,oM,oLmax,onpart;
478:   PetscMPIInt    size;

480:   oN = ctx->N;
481:   if (ip == PETSC_DECIDE || ip == PETSC_DEFAULT) {
482:     if (ctx->N!=32) { ctx->N =32; ctx->M = ctx->N/4; }
483:   } else {
486:     if (ctx->N!=ip) { ctx->N = ip; ctx->M = ctx->N/4; }
487:   }
488:   oL = ctx->L;
489:   if (bs == PETSC_DECIDE || bs == PETSC_DEFAULT) {
490:     ctx->L = 16;
491:   } else {
493:     ctx->L = bs;
494:   }
495:   oM = ctx->M;
496:   if (ms == PETSC_DECIDE || ms == PETSC_DEFAULT) {
497:     ctx->M = ctx->N/4;
498:   } else {
501:     ctx->M = PetscMax(ms,2);
502:   }
503:   onpart = ctx->npart;
504:   if (npart == PETSC_DECIDE || npart == PETSC_DEFAULT) {
505:     ctx->npart = 1;
506:   } else {
507:     MPI_Comm_size(PetscObjectComm((PetscObject)pep),&size);
509:     ctx->npart = npart;
510:   }
511:   oLmax = ctx->L_max;
512:   if (bsmax == PETSC_DECIDE || bsmax == PETSC_DEFAULT) {
513:     ctx->L_max = 64;
514:   } else {
516:     ctx->L_max = PetscMax(bsmax,ctx->L);
517:   }
518:   if (onpart != ctx->npart || oN != ctx->N || realmats != ctx->isreal) {
519:     SlepcContourDataDestroy(&ctx->contour);
520:     PetscInfo(pep,"Resetting the contour data structure due to a change of parameters\n");
521:     pep->state = PEP_STATE_INITIAL;
522:   }
523:   ctx->isreal = realmats;
524:   if (oL != ctx->L || oM != ctx->M || oLmax != ctx->L_max) pep->state = PEP_STATE_INITIAL;
525:   PetscFunctionReturn(0);
526: }

528: /*@
529:    PEPCISSSetSizes - Sets the values of various size parameters in the CISS solver.

531:    Logically Collective on pep

533:    Input Parameters:
534: +  pep   - the polynomial eigensolver context
535: .  ip    - number of integration points
536: .  bs    - block size
537: .  ms    - moment size
538: .  npart - number of partitions when splitting the communicator
539: .  bsmax - max block size
540: -  realmats - all coefficient matrices of P(.) are real

542:    Options Database Keys:
543: +  -pep_ciss_integration_points - Sets the number of integration points
544: .  -pep_ciss_blocksize - Sets the block size
545: .  -pep_ciss_moments - Sets the moment size
546: .  -pep_ciss_partitions - Sets the number of partitions
547: .  -pep_ciss_maxblocksize - Sets the maximum block size
548: -  -pep_ciss_realmats - all coefficient matrices of P(.) are real

550:    Notes:
551:    The default number of partitions is 1. This means the internal KSP object is shared
552:    among all processes of the PEP communicator. Otherwise, the communicator is split
553:    into npart communicators, so that npart KSP solves proceed simultaneously.

555:    Level: advanced

557: .seealso: PEPCISSGetSizes()
558: @*/
559: PetscErrorCode PEPCISSSetSizes(PEP pep,PetscInt ip,PetscInt bs,PetscInt ms,PetscInt npart,PetscInt bsmax,PetscBool realmats)
560: {
568:   PetscTryMethod(pep,"PEPCISSSetSizes_C",(PEP,PetscInt,PetscInt,PetscInt,PetscInt,PetscInt,PetscBool),(pep,ip,bs,ms,npart,bsmax,realmats));
569:   PetscFunctionReturn(0);
570: }

572: static PetscErrorCode PEPCISSGetSizes_CISS(PEP pep,PetscInt *ip,PetscInt *bs,PetscInt *ms,PetscInt *npart,PetscInt *bsmax,PetscBool *realmats)
573: {
574:   PEP_CISS *ctx = (PEP_CISS*)pep->data;

576:   if (ip) *ip = ctx->N;
577:   if (bs) *bs = ctx->L;
578:   if (ms) *ms = ctx->M;
579:   if (npart) *npart = ctx->npart;
580:   if (bsmax) *bsmax = ctx->L_max;
581:   if (realmats) *realmats = ctx->isreal;
582:   PetscFunctionReturn(0);
583: }

585: /*@
586:    PEPCISSGetSizes - Gets the values of various size parameters in the CISS solver.

588:    Not Collective

590:    Input Parameter:
591: .  pep - the polynomial eigensolver context

593:    Output Parameters:
594: +  ip    - number of integration points
595: .  bs    - block size
596: .  ms    - moment size
597: .  npart - number of partitions when splitting the communicator
598: .  bsmax - max block size
599: -  realmats - all coefficient matrices of P(.) are real

601:    Level: advanced

603: .seealso: PEPCISSSetSizes()
604: @*/
605: PetscErrorCode PEPCISSGetSizes(PEP pep,PetscInt *ip,PetscInt *bs,PetscInt *ms,PetscInt *npart,PetscInt *bsmax,PetscBool *realmats)
606: {
608:   PetscUseMethod(pep,"PEPCISSGetSizes_C",(PEP,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscInt*,PetscBool*),(pep,ip,bs,ms,npart,bsmax,realmats));
609:   PetscFunctionReturn(0);
610: }

612: static PetscErrorCode PEPCISSSetThreshold_CISS(PEP pep,PetscReal delta,PetscReal spur)
613: {
614:   PEP_CISS *ctx = (PEP_CISS*)pep->data;

616:   if (delta == PETSC_DEFAULT) {
617:     ctx->delta = SLEPC_DEFAULT_TOL*1e-4;
618:   } else {
620:     ctx->delta = delta;
621:   }
622:   if (spur == PETSC_DEFAULT) {
623:     ctx->spurious_threshold = PetscSqrtReal(SLEPC_DEFAULT_TOL);
624:   } else {
626:     ctx->spurious_threshold = spur;
627:   }
628:   PetscFunctionReturn(0);
629: }

631: /*@
632:    PEPCISSSetThreshold - Sets the values of various threshold parameters in
633:    the CISS solver.

635:    Logically Collective on pep

637:    Input Parameters:
638: +  pep   - the polynomial eigensolver context
639: .  delta - threshold for numerical rank
640: -  spur  - spurious threshold (to discard spurious eigenpairs)

642:    Options Database Keys:
643: +  -pep_ciss_delta - Sets the delta
644: -  -pep_ciss_spurious_threshold - Sets the spurious threshold

646:    Level: advanced

648: .seealso: PEPCISSGetThreshold()
649: @*/
650: PetscErrorCode PEPCISSSetThreshold(PEP pep,PetscReal delta,PetscReal spur)
651: {
655:   PetscTryMethod(pep,"PEPCISSSetThreshold_C",(PEP,PetscReal,PetscReal),(pep,delta,spur));
656:   PetscFunctionReturn(0);
657: }

659: static PetscErrorCode PEPCISSGetThreshold_CISS(PEP pep,PetscReal *delta,PetscReal *spur)
660: {
661:   PEP_CISS *ctx = (PEP_CISS*)pep->data;

663:   if (delta) *delta = ctx->delta;
664:   if (spur)  *spur = ctx->spurious_threshold;
665:   PetscFunctionReturn(0);
666: }

668: /*@
669:    PEPCISSGetThreshold - Gets the values of various threshold parameters in
670:    the CISS solver.

672:    Not Collective

674:    Input Parameter:
675: .  pep - the polynomial eigensolver context

677:    Output Parameters:
678: +  delta - threshold for numerical rank
679: -  spur  - spurious threshold (to discard spurious eigenpairs)

681:    Level: advanced

683: .seealso: PEPCISSSetThreshold()
684: @*/
685: PetscErrorCode PEPCISSGetThreshold(PEP pep,PetscReal *delta,PetscReal *spur)
686: {
688:   PetscUseMethod(pep,"PEPCISSGetThreshold_C",(PEP,PetscReal*,PetscReal*),(pep,delta,spur));
689:   PetscFunctionReturn(0);
690: }

692: static PetscErrorCode PEPCISSSetRefinement_CISS(PEP pep,PetscInt inner,PetscInt blsize)
693: {
694:   PEP_CISS *ctx = (PEP_CISS*)pep->data;

696:   if (inner == PETSC_DEFAULT) {
697:     ctx->refine_inner = 0;
698:   } else {
700:     ctx->refine_inner = inner;
701:   }
702:   if (blsize == PETSC_DEFAULT) {
703:     ctx->refine_blocksize = 0;
704:   } else {
706:     ctx->refine_blocksize = blsize;
707:   }
708:   PetscFunctionReturn(0);
709: }

711: /*@
712:    PEPCISSSetRefinement - Sets the values of various refinement parameters
713:    in the CISS solver.

715:    Logically Collective on pep

717:    Input Parameters:
718: +  pep    - the polynomial eigensolver context
719: .  inner  - number of iterative refinement iterations (inner loop)
720: -  blsize - number of iterative refinement iterations (blocksize loop)

722:    Options Database Keys:
723: +  -pep_ciss_refine_inner - Sets number of inner iterations
724: -  -pep_ciss_refine_blocksize - Sets number of blocksize iterations

726:    Level: advanced

728: .seealso: PEPCISSGetRefinement()
729: @*/
730: PetscErrorCode PEPCISSSetRefinement(PEP pep,PetscInt inner,PetscInt blsize)
731: {
735:   PetscTryMethod(pep,"PEPCISSSetRefinement_C",(PEP,PetscInt,PetscInt),(pep,inner,blsize));
736:   PetscFunctionReturn(0);
737: }

739: static PetscErrorCode PEPCISSGetRefinement_CISS(PEP pep,PetscInt *inner,PetscInt *blsize)
740: {
741:   PEP_CISS *ctx = (PEP_CISS*)pep->data;

743:   if (inner)  *inner = ctx->refine_inner;
744:   if (blsize) *blsize = ctx->refine_blocksize;
745:   PetscFunctionReturn(0);
746: }

748: /*@
749:    PEPCISSGetRefinement - Gets the values of various refinement parameters
750:    in the CISS solver.

752:    Not Collective

754:    Input Parameter:
755: .  pep - the polynomial eigensolver context

757:    Output Parameters:
758: +  inner  - number of iterative refinement iterations (inner loop)
759: -  blsize - number of iterative refinement iterations (blocksize loop)

761:    Level: advanced

763: .seealso: PEPCISSSetRefinement()
764: @*/
765: PetscErrorCode PEPCISSGetRefinement(PEP pep, PetscInt *inner, PetscInt *blsize)
766: {
768:   PetscUseMethod(pep,"PEPCISSGetRefinement_C",(PEP,PetscInt*,PetscInt*),(pep,inner,blsize));
769:   PetscFunctionReturn(0);
770: }

772: static PetscErrorCode PEPCISSSetExtraction_CISS(PEP pep,PEPCISSExtraction extraction)
773: {
774:   PEP_CISS *ctx = (PEP_CISS*)pep->data;

776:   if (ctx->extraction != extraction) {
777:     ctx->extraction = extraction;
778:     pep->state      = PEP_STATE_INITIAL;
779:   }
780:   PetscFunctionReturn(0);
781: }

783: /*@
784:    PEPCISSSetExtraction - Sets the extraction technique used in the CISS solver.

786:    Logically Collective on pep

788:    Input Parameters:
789: +  pep        - the polynomial eigensolver context
790: -  extraction - the extraction technique

792:    Options Database Key:
793: .  -pep_ciss_extraction - Sets the extraction technique (either 'ritz', 'hankel' or 'caa')

795:    Notes:
796:    By default, the Rayleigh-Ritz extraction is used (PEP_CISS_EXTRACTION_RITZ).

798:    If the 'hankel' or the 'caa' option is specified (PEP_CISS_EXTRACTION_HANKEL or
799:    PEP_CISS_EXTRACTION_CAA), then the Block Hankel method, or the Communication-avoiding
800:    Arnoldi method, respectively, is used for extracting eigenpairs.

802:    Level: advanced

804: .seealso: PEPCISSGetExtraction(), PEPCISSExtraction
805: @*/
806: PetscErrorCode PEPCISSSetExtraction(PEP pep,PEPCISSExtraction extraction)
807: {
810:   PetscTryMethod(pep,"PEPCISSSetExtraction_C",(PEP,PEPCISSExtraction),(pep,extraction));
811:   PetscFunctionReturn(0);
812: }

814: static PetscErrorCode PEPCISSGetExtraction_CISS(PEP pep,PEPCISSExtraction *extraction)
815: {
816:   PEP_CISS *ctx = (PEP_CISS*)pep->data;

818:   *extraction = ctx->extraction;
819:   PetscFunctionReturn(0);
820: }

822: /*@
823:    PEPCISSGetExtraction - Gets the extraction technique used in the CISS solver.

825:    Not Collective

827:    Input Parameter:
828: .  pep - the polynomial eigensolver context

830:    Output Parameters:
831: .  extraction - extraction technique

833:    Level: advanced

835: .seealso: PEPCISSSetExtraction() PEPCISSExtraction
836: @*/
837: PetscErrorCode PEPCISSGetExtraction(PEP pep,PEPCISSExtraction *extraction)
838: {
841:   PetscUseMethod(pep,"PEPCISSGetExtraction_C",(PEP,PEPCISSExtraction*),(pep,extraction));
842:   PetscFunctionReturn(0);
843: }

845: static PetscErrorCode PEPCISSGetKSPs_CISS(PEP pep,PetscInt *nsolve,KSP **ksp)
846: {
847:   PEP_CISS         *ctx = (PEP_CISS*)pep->data;
848:   SlepcContourData contour;
849:   PetscInt         i,nsplit;
850:   PC               pc;
851:   MPI_Comm         child;

853:   if (!ctx->contour) {  /* initialize contour data structure first */
854:     RGCanUseConjugates(pep->rg,ctx->isreal,&ctx->useconj);
855:     SlepcContourDataCreate(ctx->useconj?ctx->N/2:ctx->N,ctx->npart,(PetscObject)pep,&ctx->contour);
856:   }
857:   contour = ctx->contour;
858:   if (!contour->ksp) {
859:     PetscMalloc1(contour->npoints,&contour->ksp);
860:     PEPGetST(pep,&pep->st);
861:     STGetSplitPreconditionerInfo(pep->st,&nsplit,NULL);
862:     PetscSubcommGetChild(contour->subcomm,&child);
863:     for (i=0;i<contour->npoints;i++) {
864:       KSPCreate(child,&contour->ksp[i]);
865:       PetscObjectIncrementTabLevel((PetscObject)contour->ksp[i],(PetscObject)pep,1);
866:       KSPSetOptionsPrefix(contour->ksp[i],((PetscObject)pep)->prefix);
867:       KSPAppendOptionsPrefix(contour->ksp[i],"pep_ciss_");
868:       PetscLogObjectParent((PetscObject)pep,(PetscObject)contour->ksp[i]);
869:       PetscObjectSetOptions((PetscObject)contour->ksp[i],((PetscObject)pep)->options);
870:       KSPSetErrorIfNotConverged(contour->ksp[i],PETSC_TRUE);
871:       KSPSetTolerances(contour->ksp[i],SlepcDefaultTol(pep->tol),PETSC_DEFAULT,PETSC_DEFAULT,PETSC_DEFAULT);
872:       KSPGetPC(contour->ksp[i],&pc);
873:       if (nsplit) {
874:         KSPSetType(contour->ksp[i],KSPBCGS);
875:         PCSetType(pc,PCBJACOBI);
876:       } else {
877:         KSPSetType(contour->ksp[i],KSPPREONLY);
878:         PCSetType(pc,PCLU);
879:       }
880:     }
881:   }
882:   if (nsolve) *nsolve = contour->npoints;
883:   if (ksp)    *ksp    = contour->ksp;
884:   PetscFunctionReturn(0);
885: }

887: /*@C
888:    PEPCISSGetKSPs - Retrieve the array of linear solver objects associated with
889:    the CISS solver.

891:    Not Collective

893:    Input Parameter:
894: .  pep - polynomial eigenvalue solver

896:    Output Parameters:
897: +  nsolve - number of solver objects
898: -  ksp - array of linear solver object

900:    Notes:
901:    The number of KSP solvers is equal to the number of integration points divided by
902:    the number of partitions. This value is halved in the case of real matrices with
903:    a region centered at the real axis.

905:    Level: advanced

907: .seealso: PEPCISSSetSizes()
908: @*/
909: PetscErrorCode PEPCISSGetKSPs(PEP pep,PetscInt *nsolve,KSP **ksp)
910: {
912:   PetscUseMethod(pep,"PEPCISSGetKSPs_C",(PEP,PetscInt*,KSP**),(pep,nsolve,ksp));
913:   PetscFunctionReturn(0);
914: }

916: PetscErrorCode PEPReset_CISS(PEP pep)
917: {
918:   PEP_CISS       *ctx = (PEP_CISS*)pep->data;

920:   BVDestroy(&ctx->S);
921:   BVDestroy(&ctx->V);
922:   BVDestroy(&ctx->Y);
923:   SlepcContourDataReset(ctx->contour);
924:   MatDestroy(&ctx->J);
925:   BVDestroy(&ctx->pV);
926:   PetscFree(ctx->Psplit);
927:   PetscFunctionReturn(0);
928: }

930: PetscErrorCode PEPSetFromOptions_CISS(PetscOptionItems *PetscOptionsObject,PEP pep)
931: {
932:   PEP_CISS          *ctx = (PEP_CISS*)pep->data;
933:   PetscReal         r1,r2;
934:   PetscInt          i,i1,i2,i3,i4,i5,i6,i7;
935:   PetscBool         b1,flg,flg2,flg3,flg4,flg5,flg6;
936:   PEPCISSExtraction extraction;

938:   PetscOptionsHead(PetscOptionsObject,"PEP CISS Options");

940:     PEPCISSGetSizes(pep,&i1,&i2,&i3,&i4,&i5,&b1);
941:     PetscOptionsInt("-pep_ciss_integration_points","Number of integration points","PEPCISSSetSizes",i1,&i1,&flg);
942:     PetscOptionsInt("-pep_ciss_blocksize","Block size","PEPCISSSetSizes",i2,&i2,&flg2);
943:     PetscOptionsInt("-pep_ciss_moments","Moment size","PEPCISSSetSizes",i3,&i3,&flg3);
944:     PetscOptionsInt("-pep_ciss_partitions","Number of partitions","PEPCISSSetSizes",i4,&i4,&flg4);
945:     PetscOptionsInt("-pep_ciss_maxblocksize","Maximum block size","PEPCISSSetSizes",i5,&i5,&flg5);
946:     PetscOptionsBool("-pep_ciss_realmats","True if all coefficient matrices of P(.) are real","PEPCISSSetSizes",b1,&b1,&flg6);
947:     if (flg || flg2 || flg3 || flg4 || flg5 || flg6) PEPCISSSetSizes(pep,i1,i2,i3,i4,i5,b1);

949:     PEPCISSGetThreshold(pep,&r1,&r2);
950:     PetscOptionsReal("-pep_ciss_delta","Threshold for numerical rank","PEPCISSSetThreshold",r1,&r1,&flg);
951:     PetscOptionsReal("-pep_ciss_spurious_threshold","Threshold for the spurious eigenpairs","PEPCISSSetThreshold",r2,&r2,&flg2);
952:     if (flg || flg2) PEPCISSSetThreshold(pep,r1,r2);

954:     PEPCISSGetRefinement(pep,&i6,&i7);
955:     PetscOptionsInt("-pep_ciss_refine_inner","Number of inner iterative refinement iterations","PEPCISSSetRefinement",i6,&i6,&flg);
956:     PetscOptionsInt("-pep_ciss_refine_blocksize","Number of blocksize iterative refinement iterations","PEPCISSSetRefinement",i7,&i7,&flg2);
957:     if (flg || flg2) PEPCISSSetRefinement(pep,i6,i7);

959:     PetscOptionsEnum("-pep_ciss_extraction","Extraction technique","PEPCISSSetExtraction",PEPCISSExtractions,(PetscEnum)ctx->extraction,(PetscEnum*)&extraction,&flg);
960:     if (flg) PEPCISSSetExtraction(pep,extraction);

962:   PetscOptionsTail();

964:   if (!pep->rg) PEPGetRG(pep,&pep->rg);
965:   RGSetFromOptions(pep->rg); /* this is necessary here to set useconj */
966:   if (!ctx->contour || !ctx->contour->ksp) PEPCISSGetKSPs(pep,NULL,NULL);
967:   for (i=0;i<ctx->contour->npoints;i++) KSPSetFromOptions(ctx->contour->ksp[i]);
968:   PetscSubcommSetFromOptions(ctx->contour->subcomm);
969:   PetscFunctionReturn(0);
970: }

972: PetscErrorCode PEPDestroy_CISS(PEP pep)
973: {
974:   PEP_CISS       *ctx = (PEP_CISS*)pep->data;

976:   SlepcContourDataDestroy(&ctx->contour);
977:   PetscFree4(ctx->weight,ctx->omega,ctx->pp,ctx->sigma);
978:   PetscFree(pep->data);
979:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSSetSizes_C",NULL);
980:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSGetSizes_C",NULL);
981:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSSetThreshold_C",NULL);
982:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSGetThreshold_C",NULL);
983:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSSetRefinement_C",NULL);
984:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSGetRefinement_C",NULL);
985:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSSetExtraction_C",NULL);
986:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSGetExtraction_C",NULL);
987:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSGetKSPs_C",NULL);
988:   PetscFunctionReturn(0);
989: }

991: PetscErrorCode PEPView_CISS(PEP pep,PetscViewer viewer)
992: {
993:   PEP_CISS       *ctx = (PEP_CISS*)pep->data;
994:   PetscBool      isascii;
995:   PetscViewer    sviewer;

997:   PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&isascii);
998:   if (isascii) {
999:     PetscViewerASCIIPrintf(viewer,"  sizes { integration points: %" PetscInt_FMT ", block size: %" PetscInt_FMT ", moment size: %" PetscInt_FMT ", partitions: %" PetscInt_FMT ", maximum block size: %" PetscInt_FMT " }\n",ctx->N,ctx->L,ctx->M,ctx->npart,ctx->L_max);
1000:     if (ctx->isreal) PetscViewerASCIIPrintf(viewer,"  exploiting symmetry of integration points\n");
1001:     PetscViewerASCIIPrintf(viewer,"  threshold { delta: %g, spurious threshold: %g }\n",(double)ctx->delta,(double)ctx->spurious_threshold);
1002:     PetscViewerASCIIPrintf(viewer,"  iterative refinement  { inner: %" PetscInt_FMT ", blocksize: %" PetscInt_FMT " }\n",ctx->refine_inner, ctx->refine_blocksize);
1003:     PetscViewerASCIIPrintf(viewer,"  extraction: %s\n",PEPCISSExtractions[ctx->extraction]);
1004:     if (!ctx->contour || !ctx->contour->ksp) PEPCISSGetKSPs(pep,NULL,NULL);
1005:     PetscViewerASCIIPushTab(viewer);
1006:     if (ctx->npart>1 && ctx->contour->subcomm) {
1007:       PetscViewerGetSubViewer(viewer,ctx->contour->subcomm->child,&sviewer);
1008:       if (!ctx->contour->subcomm->color) KSPView(ctx->contour->ksp[0],sviewer);
1009:       PetscViewerFlush(sviewer);
1010:       PetscViewerRestoreSubViewer(viewer,ctx->contour->subcomm->child,&sviewer);
1011:       PetscViewerFlush(viewer);
1012:       /* extra call needed because of the two calls to PetscViewerASCIIPushSynchronized() in PetscViewerGetSubViewer() */
1013:       PetscViewerASCIIPopSynchronized(viewer);
1014:     } else KSPView(ctx->contour->ksp[0],viewer);
1015:     PetscViewerASCIIPopTab(viewer);
1016:   }
1017:   PetscFunctionReturn(0);
1018: }

1020: SLEPC_EXTERN PetscErrorCode PEPCreate_CISS(PEP pep)
1021: {
1022:   PEP_CISS       *ctx = (PEP_CISS*)pep->data;

1024:   PetscNewLog(pep,&ctx);
1025:   pep->data = ctx;
1026:   /* set default values of parameters */
1027:   ctx->N                  = 32;
1028:   ctx->L                  = 16;
1029:   ctx->M                  = ctx->N/4;
1030:   ctx->delta              = SLEPC_DEFAULT_TOL*1e-4;
1031:   ctx->L_max              = 64;
1032:   ctx->spurious_threshold = PetscSqrtReal(SLEPC_DEFAULT_TOL);
1033:   ctx->isreal             = PETSC_FALSE;
1034:   ctx->npart              = 1;

1036:   pep->ops->solve          = PEPSolve_CISS;
1037:   pep->ops->setup          = PEPSetUp_CISS;
1038:   pep->ops->setfromoptions = PEPSetFromOptions_CISS;
1039:   pep->ops->reset          = PEPReset_CISS;
1040:   pep->ops->destroy        = PEPDestroy_CISS;
1041:   pep->ops->view           = PEPView_CISS;

1043:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSSetSizes_C",PEPCISSSetSizes_CISS);
1044:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSGetSizes_C",PEPCISSGetSizes_CISS);
1045:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSSetThreshold_C",PEPCISSSetThreshold_CISS);
1046:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSGetThreshold_C",PEPCISSGetThreshold_CISS);
1047:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSSetRefinement_C",PEPCISSSetRefinement_CISS);
1048:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSGetRefinement_C",PEPCISSGetRefinement_CISS);
1049:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSSetExtraction_C",PEPCISSSetExtraction_CISS);
1050:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSGetExtraction_C",PEPCISSGetExtraction_CISS);
1051:   PetscObjectComposeFunction((PetscObject)pep,"PEPCISSGetKSPs_C",PEPCISSGetKSPs_CISS);
1052:   PetscFunctionReturn(0);
1053: }