Avoid crash in PETScMatrix when user doesn't specify any linear solver parameters

git-svn-id: http://svn.sintef.no/trondheim/IFEM/trunk@849 e10b68d5-8a6e-419e-a041-bce267b0401d
This commit is contained in:
kmo 2011-02-25 18:08:07 +00:00 committed by Knut Morten Okstad
parent 2b8d092d3d
commit 715a0cddb8
2 changed files with 21 additions and 16 deletions

View File

@ -1,4 +1,4 @@
// $Id: DenseMatrix.C,v 1.17 2010-12-06 09:06:08 rho Exp $
// $Id$
//==============================================================================
//!
//! \file DenseMatrix.C
@ -219,7 +219,7 @@ static void assemDense (const Matrix& eM, Matrix& SM, Vector& SV,
bool DenseMatrix::assemble (const Matrix& eM, const SAM& sam, int e)
{
if (myMat.rows() != sam.neq || myMat.cols() < sam.neq)
if (myMat.rows() != (size_t)sam.neq || myMat.cols() < (size_t)sam.neq)
return false;
int ierr = 0;
@ -245,7 +245,7 @@ bool DenseMatrix::assemble (const Matrix& eM, const SAM& sam, int e)
bool DenseMatrix::assemble (const Matrix& eK, const SAM& sam,
SystemVector& B, int e)
{
if (myMat.rows() != sam.neq || myMat.cols() < sam.neq)
if (myMat.rows() != (size_t)sam.neq || myMat.cols() < (size_t)sam.neq)
return false;
StdVector* Bptr = dynamic_cast<StdVector*>(&B);
@ -375,7 +375,7 @@ bool DenseMatrix::multiply (const SystemVector& B, SystemVector& C)
bool DenseMatrix::solve (SystemVector& B, bool newLHS)
{
const int n = myMat.rows();
const size_t n = myMat.rows();
if (n < 1) return true; // No equations to solve
if (n > myMat.cols()) return false;
@ -408,7 +408,7 @@ bool DenseMatrix::solve (SystemVector& B, bool newLHS)
bool DenseMatrix::solveEig (RealArray& val, Matrix& vec, int nv)
{
const int n = myMat.rows();
const size_t n = myMat.rows();
if (n < 1 || nv < 1) return true; // No equations to solve
if (n > myMat.cols()) return false;
@ -456,7 +456,7 @@ bool DenseMatrix::solveEig (RealArray& val, Matrix& vec, int nv)
bool DenseMatrix::solveEig (DenseMatrix& B, RealArray& val, Matrix& vec, int nv,
real)
{
const int n = myMat.rows();
const size_t n = myMat.rows();
if (n < 1 || nv < 1) return true; // No equations to solve
if (n > myMat.cols()) return false;
@ -494,9 +494,9 @@ bool DenseMatrix::solveEig (DenseMatrix& B, RealArray& val, Matrix& vec, int nv,
std::cerr <<"LAPACK::DSYGVX: ";
if (info < 0)
std::cerr <<"Invalid argument #"<< -info << std::endl;
else if (info <= n)
else if ((size_t)info <= n)
std::cerr << info <<" eigenvectors failed to converge."<< std::endl;
else if (info <= 2*n)
else if ((size_t)info <= 2*n)
std::cerr <<"The leading minor of order "<< info-n
<<" of matrix B is not positive definite."<< std::endl;
#else
@ -508,11 +508,11 @@ bool DenseMatrix::solveEig (DenseMatrix& B, RealArray& val, Matrix& vec, int nv,
bool DenseMatrix::solveEigNon (RealArray& r_val, RealArray& c_val)
{
const int n = myMat.rows();
const size_t n = myMat.rows();
if (n < 1) return true; // No equations to solve
#ifdef USE_CBLAS
int m, info = 0;
int info = 0;
char jobvl = 'N';
char jobvr = 'N';
real dummy = 0.0;

View File

@ -1,4 +1,4 @@
// $Id: SystemMatrix.C,v 1.10 2011-02-04 17:02:38 kmo Exp $
// $Id$
//==============================================================================
//!
//! \file SystemMatrix.C
@ -28,10 +28,11 @@ SystemVector* SystemVector::create (Type vectorType)
#ifdef HAS_PETSC
case PETSC : return new PETScVector();
#endif
default:
std::cerr <<"SystemVector::create: Unsupported vector type "
<< vectorType << std::endl;
}
std::cerr <<"SystemVector::create: Unsupported vector type "
<< vectorType << std::endl;
return 0;
}
@ -54,11 +55,15 @@ SystemMatrix* SystemMatrix::create (Type matrixType, int num_thread_SLU)
case SPARSE: return new SparseMatrix(SparseMatrix::SUPERLU,num_thread_SLU);
case SAMG : return new SparseMatrix(SparseMatrix::S_A_M_G);
#ifdef HAS_PETSC
case PETSC : return new PETScMatrix(LinSolParams());
case PETSC :
// Use default PETSc settings when no parameters are provided by user
static LinSolParams defaultPar;
return new PETScMatrix(defaultPar);
#endif
default:
std::cerr <<"SystemMatrix::create: Unsupported matrix type "
<< matrixType << std::endl;
}
std::cerr <<"SystemMatrix::create: Unsupported matrix type "
<< matrixType << std::endl;
return 0;
}