void OpenSMOKE_PARDISO_Unsymmetric::SetSparsityPattern(BzzMatrixSparse &M)
{
	if (kind_ != OPENSMOKE_DIRECTSOLVER_SQUAREMATRIX)
		ErrorMessage("SetSparsityPattern(BzzMatrixSparse &M) can be used only for OPENSMOKE_DIRECTSOLVER_SQUAREMATRIX");

	if (status_	!= OPENSMOKE_DIRECTSOLVER_STATUS_OPEN)
		ErrorMessage("SetSparsityPattern(BzzMatrixSparse &M) cannot be used if the Matrix was already closed");

	n = M.Rows();
	rows = new int[n+1];
	perm = new int[n];
	rows[0] = 1;

	// Counting non zero elements
	{
		double* ptrVal;
		int i, j;
		double val;

		int count = 0;
		int iRows = 1;
		M.BeginScanning();
		while(ptrVal = M.Scanning(&i,&j,&val))
		{
			if (iRows != i)
			{
				rows[iRows] = count+1;
				iRows = i;
			}
			count++;
		}
		rows[n] = count+1;
		numberNonZeroElements = count;
	}

	values  = new double[numberNonZeroElements];
	columns = new int[numberNonZeroElements];
	
	// Filling non zero elements
	{	
		double* ptrVal;
		int i, j;
		double val;
		int count = 0;

		M.BeginScanning();
		while(ptrVal = M.Scanning(&i,&j,&val))
		{
			columns[count] = j;
			values[count]  = val;
			count++;
		}
	}

	// Complete Matrix
	CompleteMatrix();

	// Update Status
	status_	= OPENSMOKE_DIRECTSOLVER_STATUS_TOFACTORIZE;
}
예제 #2
0
// This function creates a CompleteMatrix from the given tinyxml Element
// and its children. 
//
// Input:
//   matElement: tinyxml DOM node containing a Matrix element
// Postconditions"
//   If no problems, CompleteMatrix subclass object created and
//   initialized.
// Returns:
//   CompleteMatrix object (will be empty if some failure occurs).
CompleteMatrix MatrixFactory::CreateComplete(TiXmlElement* matElement)
{
  string type;
  string init;
  int rows, columns;
  FLOAT multiplier;
  string values;
  TiXmlHandle matHandle(matElement);

  GetAttributes(matElement, type, init, rows, columns, multiplier);

#ifdef MDEBUG
  cerr << "Creating Matrix with attributes: " << type << ", " << init
       << ", " << rows << "X" << columns << ", " << multiplier << endl;
#endif

  // Get the Text node that contains the matrix values, if needed
  if (init == "none") {
    TiXmlText* valuesNode = matHandle.FirstChild().Text();
    if (valuesNode == NULL)
      throw KII_invalid_argument("Contents not specified for Matrix with init='none'.");

    values = valuesNode->Value();
#ifdef MDEBUG
    cerr << "\tData present for initialization: " << values << endl;
#endif
  } else if (init == "implementation")
    throw KII_invalid_argument("MatrixFactory cannot create implementation-dependent Matrices; client program must perform creation.");

  if (type == "sparse")
    throw KII_invalid_argument("Sparse matrix requested by XML but CreateComplete called");

  if ((type == "complete") || (type == "diag"))
    return CompleteMatrix(type, init, rows, columns, multiplier, values);
  else if (type == "sparse")
    throw KII_invalid_argument("No such thing as sparse CompleteMatrices");
  else
    throw KII_invalid_argument("Illegal Vector type");

  return CompleteMatrix();
}
void OpenSMOKE_PARDISO_Unsymmetric::CloseMatrix()
{
	if (kind_ != OPENSMOKE_DIRECTSOLVER_SQUAREMATRIX_ROW_BY_ROW)
		ErrorMessage("CloseMatrix() can be used only for OPENSMOKE_DIRECTSOLVER_SQUAREMATRIX_ROW_BY_ROW");

	if (status_	!= OPENSMOKE_DIRECTSOLVER_STATUS_OPEN)
		ErrorMessage("CloseMatrix() can be used only for Open Matrices");

	CompleteMatrix();

	// Update status
	status_ = OPENSMOKE_DIRECTSOLVER_STATUS_TOFACTORIZE;
}