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

/**
 * @file PetscUtils.h
 * PetscUtils header.
 */
#ifndef PetscUtils_PetscUtils_h
#define PetscUtils_PetscUtils_h

#include <string>
#include "petsc.h"
#include "PetscMatSeqAij.h"		// Provide interface to PetscMatSeqAij functions
#include "PetscVecSeq.h"		// Provide interface to PetscVecSeq functions
#include "PetscUtils.def"

/* :NOTE: As preprocessor directives defines are namespace independent */
/// PETSc error code for general use.
#define PETSC_ERR_GENERAL 1
/// Bool returning alternative for the PETSc error macro CHKERRQ. Returns \c false on error, \c true otherwise.
#define CHKERRB(n) if (PetscUnlikely(n)) { PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_REPEAT," "); return false; }
/// Bool returning alternative for the PETSc error macro SETERRQ. Returns \c false on error, \c true otherwise.
//#define SETERRB(c,n,s) { PetscError(c,__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,n,PETSC_ERROR_INITIAL,s); return false; }


PETSCUTILS_NAMESPACE_BEGIN

/**
 * Checks whether PETSc has been initialized.
 * @return \c true if initialized, \c false if not.
 */
bool IsInitialized(void);

/**
 * Gets a string from the command line options.
 * @param[in] optionName string used to identify the command line option.
 * @param[out] optionString string, or empty string if the option was not found.
 * @param[in] maxLength maximum number of character in the option string.
 * @return error code, 0 if there was no error.
 */
PetscErrorCode GetOptionsString(const std::string& optionName, std::string& optionString, PetscInt maxLength);

PETSCUTILS_NAMESPACE_END

#endif // PetscUtils_PetscUtils_h
