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

/*
 * PetscUtils source.
 */
#include "PetscUtils.h"

PETSCUTILS_NAMESPACE_BEGIN

#undef __FUNCT__
#define __FUNCT__ "PetscUtils::IsInitialized"
bool IsInitialized(void)
{
	PetscBool init;
	PetscInitialized(&init);
	return init;
} // PetscUtils::IsInitialized


#undef __FUNCT__
#define __FUNCT__ "PetscUtils::GetStringFromOptions"
PetscErrorCode GetOptionsString(const std::string& optionName, std::string& optionString, PetscInt maxLength)
{
	char option[maxLength+1];
	option[0] = 0;
	PetscBool flg;
	PetscErrorCode err = PetscOptionsGetString(PETSC_NULL, optionName.c_str(), option, maxLength, &flg); CHKERRQ(err);
	if (flg == PETSC_FALSE)
	{
		optionString = "";
	}
	else
	{
		optionString = std::string(option);
	}
	return 0;
} // PetscUtils::GetStringFromOptions


PETSCUTILS_NAMESPACE_END
