| Line 47... |
Line 47... |
PetscInt i,*workperm;
|
PetscInt i,*workperm;
|
char filename[PETSC_MAX_PATH_LEN];
|
char filename[PETSC_MAX_PATH_LEN];
|
PetscViewer viewer;
|
PetscViewer viewer;
|
|
|
PetscFunctionBegin;
|
PetscFunctionBegin;
|
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
|
|
|
if (!svd->setupcalled) { ierr = SVDSetUp(svd);CHKERRQ(ierr); }
|
if (!svd->setupcalled) { ierr = SVDSetUp(svd);CHKERRQ(ierr); }
|
svd->its = 0;
|
svd->its = 0;
|
svd->matvecs = 0;
|
svd->matvecs = 0;
|
svd->nconv = 0;
|
svd->nconv = 0;
|
| Line 115... |
Line 115... |
|
|
@*/
|
@*/
|
PetscErrorCode SVDGetIterationNumber(SVD svd,PetscInt *its)
|
PetscErrorCode SVDGetIterationNumber(SVD svd,PetscInt *its)
|
{
|
{
|
PetscFunctionBegin;
|
PetscFunctionBegin;
|
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
|
PetscValidIntPointer(its,2);
|
PetscValidIntPointer(its,2);
|
*its = svd->its;
|
*its = svd->its;
|
PetscFunctionReturn(0);
|
PetscFunctionReturn(0);
|
}
|
}
|
|
|
| Line 150... |
Line 150... |
.seealso: SVDSetTolerances(), SVDSolve(), SVDConvergedReason
|
.seealso: SVDSetTolerances(), SVDSolve(), SVDConvergedReason
|
@*/
|
@*/
|
PetscErrorCode SVDGetConvergedReason(SVD svd,SVDConvergedReason *reason)
|
PetscErrorCode SVDGetConvergedReason(SVD svd,SVDConvergedReason *reason)
|
{
|
{
|
PetscFunctionBegin;
|
PetscFunctionBegin;
|
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
|
PetscValidIntPointer(reason,2);
|
PetscValidIntPointer(reason,2);
|
*reason = svd->reason;
|
*reason = svd->reason;
|
PetscFunctionReturn(0);
|
PetscFunctionReturn(0);
|
}
|
}
|
|
|
| Line 178... |
Line 178... |
|
|
@*/
|
@*/
|
PetscErrorCode SVDGetConverged(SVD svd,PetscInt *nconv)
|
PetscErrorCode SVDGetConverged(SVD svd,PetscInt *nconv)
|
{
|
{
|
PetscFunctionBegin;
|
PetscFunctionBegin;
|
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
|
PetscValidIntPointer(nconv,2);
|
PetscValidIntPointer(nconv,2);
|
if (svd->reason == SVD_CONVERGED_ITERATING) {
|
if (svd->reason == SVD_CONVERGED_ITERATING) {
|
SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "SVDSolve must be called first");
|
SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "SVDSolve must be called first");
|
}
|
}
|
*nconv = svd->nconv;
|
*nconv = svd->nconv;
|
| Line 222... |
Line 222... |
PetscInt j,nloc,M,N;
|
PetscInt j,nloc,M,N;
|
PetscScalar *pU;
|
PetscScalar *pU;
|
Vec w;
|
Vec w;
|
|
|
PetscFunctionBegin;
|
PetscFunctionBegin;
|
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
|
PetscValidPointer(sigma,3);
|
PetscValidPointer(sigma,3);
|
if (svd->reason == SVD_CONVERGED_ITERATING) {
|
if (svd->reason == SVD_CONVERGED_ITERATING) {
|
SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "SVDSolve must be called first");
|
SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "SVDSolve must be called first");
|
}
|
}
|
if (i<0 || i>=svd->nconv) {
|
if (i<0 || i>=svd->nconv) {
|
| Line 234... |
Line 234... |
}
|
}
|
*sigma = svd->sigma[svd->perm[i]];
|
*sigma = svd->sigma[svd->perm[i]];
|
ierr = MatGetSize(svd->OP,&M,&N);CHKERRQ(ierr);
|
ierr = MatGetSize(svd->OP,&M,&N);CHKERRQ(ierr);
|
if (M<N) { w = u; u = v; v = w; }
|
if (M<N) { w = u; u = v; v = w; }
|
if (u) {
|
if (u) {
|
PetscValidHeaderSpecific(u,VEC_COOKIE,4);
|
PetscValidHeaderSpecific(u,VEC_CLASSID,4);
|
if (!svd->U) {
|
if (!svd->U) {
|
ierr = PetscMalloc(sizeof(Vec)*svd->ncv,&svd->U);CHKERRQ(ierr);
|
ierr = PetscMalloc(sizeof(Vec)*svd->ncv,&svd->U);CHKERRQ(ierr);
|
ierr = SVDMatGetLocalSize(svd,&nloc,PETSC_NULL);CHKERRQ(ierr);
|
ierr = SVDMatGetLocalSize(svd,&nloc,PETSC_NULL);CHKERRQ(ierr);
|
ierr = PetscMalloc(svd->ncv*nloc*sizeof(PetscScalar),&pU);CHKERRQ(ierr);
|
ierr = PetscMalloc(svd->ncv*nloc*sizeof(PetscScalar),&pU);CHKERRQ(ierr);
|
for (j=0;j<svd->ncv;j++) {
|
for (j=0;j<svd->ncv;j++) {
|
| Line 251... |
Line 251... |
}
|
}
|
}
|
}
|
ierr = VecCopy(svd->U[svd->perm[i]],u);CHKERRQ(ierr);
|
ierr = VecCopy(svd->U[svd->perm[i]],u);CHKERRQ(ierr);
|
}
|
}
|
if (v) {
|
if (v) {
|
PetscValidHeaderSpecific(v,VEC_COOKIE,5);
|
PetscValidHeaderSpecific(v,VEC_CLASSID,5);
|
ierr = VecCopy(svd->V[svd->perm[i]],v);CHKERRQ(ierr);
|
ierr = VecCopy(svd->V[svd->perm[i]],v);CHKERRQ(ierr);
|
}
|
}
|
PetscFunctionReturn(0);
|
PetscFunctionReturn(0);
|
}
|
}
|
|
|
| Line 290... |
Line 290... |
Vec u,v,x = PETSC_NULL,y = PETSC_NULL;
|
Vec u,v,x = PETSC_NULL,y = PETSC_NULL;
|
PetscReal sigma;
|
PetscReal sigma;
|
PetscInt M,N;
|
PetscInt M,N;
|
|
|
PetscFunctionBegin;
|
PetscFunctionBegin;
|
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
|
if (svd->reason == SVD_CONVERGED_ITERATING) {
|
if (svd->reason == SVD_CONVERGED_ITERATING) {
|
SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "SVDSolve must be called first");
|
SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "SVDSolve must be called first");
|
}
|
}
|
if (i<0 || i>=svd->nconv) {
|
if (i<0 || i>=svd->nconv) {
|
SETERRQ(PETSC_ERR_ARG_OUTOFRANGE, "Argument 2 out of range");
|
SETERRQ(PETSC_ERR_ARG_OUTOFRANGE, "Argument 2 out of range");
|
| Line 357... |
Line 357... |
{
|
{
|
PetscErrorCode ierr;
|
PetscErrorCode ierr;
|
PetscReal sigma,norm1,norm2;
|
PetscReal sigma,norm1,norm2;
|
|
|
PetscFunctionBegin;
|
PetscFunctionBegin;
|
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
|
PetscValidPointer(error,2);
|
PetscValidPointer(error,2);
|
ierr = SVDGetSingularTriplet(svd,i,&sigma,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
|
ierr = SVDGetSingularTriplet(svd,i,&sigma,PETSC_NULL,PETSC_NULL);CHKERRQ(ierr);
|
ierr = SVDComputeResidualNorms(svd,i,&norm1,&norm2);CHKERRQ(ierr);
|
ierr = SVDComputeResidualNorms(svd,i,&norm1,&norm2);CHKERRQ(ierr);
|
*error = sqrt(norm1*norm1+norm2*norm2);
|
*error = sqrt(norm1*norm1+norm2*norm2);
|
if (sigma>*error) *error /= sigma;
|
if (sigma>*error) *error /= sigma;
|
| Line 392... |
Line 392... |
PetscErrorCode SVDGetOperationCounters(SVD svd,PetscInt* matvecs,PetscInt* dots)
|
PetscErrorCode SVDGetOperationCounters(SVD svd,PetscInt* matvecs,PetscInt* dots)
|
{
|
{
|
PetscErrorCode ierr;
|
PetscErrorCode ierr;
|
|
|
PetscFunctionBegin;
|
PetscFunctionBegin;
|
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
|
PetscValidHeaderSpecific(svd,SVD_CLASSID,1);
|
if (matvecs) *matvecs = svd->matvecs;
|
if (matvecs) *matvecs = svd->matvecs;
|
if (dots) {
|
if (dots) {
|
ierr = IPGetOperationCounters(svd->ip,dots);CHKERRQ(ierr);
|
ierr = IPGetOperationCounters(svd->ip,dots);CHKERRQ(ierr);
|
}
|
}
|
PetscFunctionReturn(0);
|
PetscFunctionReturn(0);
|