Example #1
0
static PetscErrorCode TestMatrix(Mat A,Vec X,Vec Y,Vec Z)
{
    PetscErrorCode ierr;
    Vec            W1,W2;
    Mat            E;
    const char     *mattypename;
    PetscViewer    viewer = PETSC_VIEWER_STDOUT_WORLD;

    PetscFunctionBegin;
    ierr = VecDuplicate(X,&W1);
    CHKERRQ(ierr);
    ierr = VecDuplicate(X,&W2);
    CHKERRQ(ierr);
    ierr = MatScale(A,31);
    CHKERRQ(ierr);
    ierr = MatShift(A,37);
    CHKERRQ(ierr);
    ierr = MatDiagonalScale(A,X,Y);
    CHKERRQ(ierr);
    ierr = MatScale(A,41);
    CHKERRQ(ierr);
    ierr = MatDiagonalScale(A,Y,Z);
    CHKERRQ(ierr);
    ierr = MatComputeExplicitOperator(A,&E);
    CHKERRQ(ierr);

    ierr = PetscObjectGetType((PetscObject)A,&mattypename);
    CHKERRQ(ierr);
    ierr = PetscViewerASCIIPrintf(viewer,"Matrix of type: %s\n",mattypename);
    CHKERRQ(ierr);
    ierr = MatView(E,viewer);
    CHKERRQ(ierr);
    ierr = MatMult(A,Z,W1);
    CHKERRQ(ierr);
    ierr = MatMultTranspose(A,W1,W2);
    CHKERRQ(ierr);
    ierr = VecView(W2,viewer);
    CHKERRQ(ierr);
    ierr = MatGetDiagonal(A,W2);
    CHKERRQ(ierr);
    ierr = VecView(W2,viewer);
    CHKERRQ(ierr);
    ierr = MatDestroy(&E);
    CHKERRQ(ierr);
    ierr = VecDestroy(&W1);
    CHKERRQ(ierr);
    ierr = VecDestroy(&W2);
    CHKERRQ(ierr);
    PetscFunctionReturn(0);
}
Example #2
0
/*@
    MatSchurComplementGetAinvType - get the type of approximation for the inverse of the (0,0) block used in forming Sp in MatSchurComplementGetPmat()

    Not collective.

    Input Parameter:
.   S      - matrix obtained with MatCreateSchurComplement() (or equivalent) and implementing the action of A11 - A10 ksp(A00,Ap00) A01

    Output Parameter:
.   ainvtype - type of approximation used to form A00inv from A00 when assembling Sp = A11 - A10 A00inv A01:
                      MAT_SCHUR_COMPLEMENT_AINV_DIAG or MAT_SCHUR_COMPLEMENT_AINV_LUMP

    Note:
    Since the real Schur complement is usually dense, providing a good approximation to newpmat usually requires
    application-specific information.  The default for assembled matrices is to use the inverse of the diagonal of
    the (0,0) block A00 in place of A00^{-1}. This rarely produce a scalable algorithm. Optionally, A00 can be lumped
    before forming inv(diag(A00)).

    Level: advanced

    Concepts: matrices^submatrices

.seealso: MatSchurComplementAinvType, MatCreateSchurComplement(), MatGetSchurComplement(), MatSchurComplementGetPmat(), MatSchurComplementSetAinvType()
@*/
PetscErrorCode  MatSchurComplementGetAinvType(Mat S,MatSchurComplementAinvType *ainvtype)
{
  PetscErrorCode      ierr;
  const char*         t;
  PetscBool           isschur;
  Mat_SchurComplement *schur;

  PetscFunctionBegin;
  PetscValidHeaderSpecific(S,MAT_CLASSID,1);
  ierr = PetscObjectGetType((PetscObject)S,&t);CHKERRQ(ierr);
  ierr = PetscStrcmp(t,MATSCHURCOMPLEMENT,&isschur);CHKERRQ(ierr);
  if (!isschur) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Expected Mat of type MATSCHURCOMPLEMENT, got %s instead",t);
  schur = (Mat_SchurComplement*)S->data;
  if (ainvtype) *ainvtype = schur->ainvtype;
  PetscFunctionReturn(0);
}