/*
 * Copyright (C) 2008-2012 Delft University of Technology - All rights reserved.
 *
 * Author: Reijer Idema
 */

/**
 * @file PetscMatSeqAij.h
 * PetscMatSeqAij header.
 * Provides some PETSc matrix operations for MATSEQAIJ matrices,
 * that benefit from being pulled out of the PETSc framework.
 * These benefits are generally const versions and/or speed.
 */
#ifndef PetscUtils_PetscMatSeqAij_h
#define PetscUtils_PetscMatSeqAij_h

#include "petscmat.h"
#include "PetscUtils.def"

PETSCUTILS_NAMESPACE_BEGIN

typedef const _p_Mat* ConstMat;		///< Constant PETSc matrix type.

/**
 * Gets the number of rows in a matrix.
 * Const version of the PETSc function MatGetSize().
 * @param mat matrix.
 * @return number of rows.
 */
PetscInt MatSeqAijGetRowCount(ConstMat mat);

/**
 * Gets the number of columns in a matrix.
 * Const version of the PETSc function MatGetSize().
 * @param mat matrix.
 * @return number of columns.
 */
PetscInt MatSeqAijGetColCount(ConstMat mat);

/**
 * Gets the number of non-zero values in a matrix.
 * @param mat matrix.
 * @return number of non-zero values.
 */
PetscInt MatSeqAijGetValCount(ConstMat mat);

/**
 * Gets pointers to the data of a row in a PETSc matrix of type MATSEQAIJ.
 * Const version of the PETSc function MatGetRow().
 * @param[in] mat PETSc matrix of type MATSEQAIJ.
 * @param[in] row index of the row to get.
 * @param[out] ncols if not PETSC_NULL, the number of non-zeros in the row.
 * @param[out] cols if not PETSC_NULL, the column indices of the non-zeros.
 * @param[out] vals if not PETSC_NULL, the values.
 * @return error code, 0 if there was no error.
 */
PetscErrorCode MatSeqAijGetRow(ConstMat mat, PetscInt row, PetscInt* ncols, const PetscInt *cols[], const PetscScalar *vals[]);

/**
 * Restores a row of a PETSc matrix of type MATSEQAIJ after a call to MatSeqAijGetRow().
 * Const version of the PETSc function MatRestoreRow().
 * @param[in] mat PETSc matrix of type MATSEQAIJ.
 * @param[in] row index of the row to get.
 * @param[out] ncols if not PETSC_NULL, the number of non-zeros in the row.
 * @param[out] cols if not PETSC_NULL, the column indices of the non-zeros.
 * @param[out] vals if not PETSC_NULL, the values.
 * @return error code, 0 if there was no error.
 */
PetscErrorCode MatSeqAijRestoreRow(ConstMat mat, PetscInt row, PetscInt* ncols, const PetscInt *cols[], const PetscScalar *vals[]);

/**
 * Prints a matrix of type MATSEQAIJ to the standard output.
 * Const version of the PETSc function MatView().
 * @param[in] mat PETSc matrix of type MATSEQAIJ.
 * @return error code, 0 if there was no error.
 */
PetscErrorCode MatSeqAijView(ConstMat mat);

PETSCUTILS_NAMESPACE_END

#endif // PetscUtils_PetscMatSeqAij_h
