/*
SVD routines for setting up the solver.
*/
#include "src/svd/svdimpl.h" /*I "slepcsvd.h" I*/
#undef __FUNCT__
#define __FUNCT__ "SVDSetOperator"
/*@C
SVDSetOperator - Set the matrix associated with the singular value problem.
Collective on SVD and Mat
Input Parameters:
+ svd - the singular value solver context
- A - the matrix associated with the singular value problem
Level: beginner
.seealso: SVDSolve(), SVDGetOperators()
@*/
PetscErrorCode SVDSetOperator(SVD svd,Mat mat)
{
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
PetscValidHeaderSpecific(mat,MAT_COOKIE,2);
PetscCheckSameComm(svd,1,mat,2);
ierr = PetscObjectReference((PetscObject)mat);CHKERRQ(ierr);
if (svd->A) {
ierr = MatDestroy(svd->A);CHKERRQ(ierr);
}
svd->A = mat;
svd->setupcalled = 0;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SVDGetOperator"
/*@C
SVDGetOperator - Get the matrix associated with the singular value problem.
Not collective, though parallel Mats are returned if the SVD is parallel
Input Parameter:
. svd - the singular value solver context
Output Parameters:
. A - the matrix associated with the singular value problem
Level: intermediate
.seealso: SVDSetOperator()
@*/
PetscErrorCode SVDGetOperator(SVD svd,Mat *A)
{
PetscFunctionBegin;
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
PetscValidPointer(A,2);
*A = svd->A;
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SVDSetFromOptions"
/*@
SVDSetFromOptions - Sets SVD options from the options database.
This routine must be called before SVDSetUp() if the user is to be
allowed to set the solver type.
Collective on SVD
Input Parameters:
. svd - the singular value solver context
Notes:
To see all options, run your program with the -help option.
Level: beginner
.seealso:
@*/
PetscErrorCode SVDSetFromOptions(SVD svd)
{
PetscErrorCode ierr;
char type[256];
PetscTruth flg;
PetscFunctionBegin;
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
ierr = PetscOptionsBegin(svd->comm,svd->prefix,"Singular Value Solver (SVD) Options","SVD");CHKERRQ(ierr);
ierr = PetscOptionsList("-svd_type","Singular Value Solver method","SVDSetType",SVDList,(char*)(svd->type_name?svd->type_name:SVDEIGENSOLVER),type,256,&flg);CHKERRQ(ierr);
if (flg) {
ierr = SVDSetType(svd,type);CHKERRQ(ierr);
} else if (!svd->type_name) {
ierr = SVDSetType(svd,SVDEIGENSOLVER);CHKERRQ(ierr);
}
ierr = PetscOptionsName("-svd_view","Print detailed information on solver used","SVDiew",0);CHKERRQ(ierr);
if (svd->ops->setfromoptions) {
ierr = (*svd->ops->setfromoptions)(svd);CHKERRQ(ierr);
}
ierr = PetscOptionsEnd();CHKERRQ(ierr);
PetscFunctionReturn(0);
}
#undef __FUNCT__
#define __FUNCT__ "SVDSetUp"
/*@
SVDSetUp - Sets up all the internal data structures necessary for the
execution of the singular value solver.
Collective on SVD
Input Parameter:
. SVD - singular value solver context
Level: advanced
Notes:
This function need not be called explicitly in most cases, since SVDSolve()
calls it. It can be useful when one wants to measure the set-up time
separately from the solve time.
.seealso: SVDCreate(), SVDSolve(), SVDDestroy()
@*/
PetscErrorCode SVDSetUp(SVD svd)
{
PetscErrorCode ierr;
PetscFunctionBegin;
PetscValidHeaderSpecific(svd,SVD_COOKIE,1);
if (svd->setupcalled) PetscFunctionReturn(0);
ierr = PetscLogEventBegin(SVD_SetUp,svd,0,0,0);CHKERRQ(ierr);
/* Set default solver type */
if (!svd->type_name) {
ierr = SVDSetType(svd,SVDEIGENSOLVER);CHKERRQ(ierr);
}
/* check matrix */
if (!svd->A) {
SETERRQ(PETSC_ERR_ARG_WRONGSTATE, "SVDSetOperator must be called first");
}
/* call specific solver setup */
ierr = (*svd->ops->setup)(svd);CHKERRQ(ierr);
ierr = PetscLogEventEnd(SVD_SetUp,svd,0,0,0);CHKERRQ(ierr);
svd->setupcalled = 1;
PetscFunctionReturn(0);
}