Beispiel #1
0
void LASError(LASErrIdType ErrId, char *ProcName, char *Object1Name,
	      char *Object2Name, char *Object3Name)
/* Set error status to ErrId, ... */
{
    LASErrId = ErrId;
    
    /* release current values of error variables */
    if (LASProcName != NULL)
        free(LASProcName);
    if (LASObject1Name != NULL)
        free(LASObject1Name);
    if (LASObject2Name != NULL)
        free(LASObject2Name);
    if (LASObject3Name != NULL)
        free(LASObject2Name);
    LASProcName = NULL;
    LASObject1Name = NULL;
    LASObject2Name = NULL;
    LASObject3Name = NULL;
    
    LASProcName = (char *)malloc((strlen(ProcName) + 1) * sizeof(char));
    if (LASProcName != NULL) {
        strcpy(LASProcName, ProcName);
	
	if (Object1Name != NULL && strlen(Object1Name) > 0) {
            LASObject1Name = (char *)malloc((strlen(Object1Name) + 1) * sizeof(char));
            if (LASObject1Name != NULL)
                strcpy(LASObject1Name, Object1Name);
	}
	if (Object2Name != NULL && strlen(Object2Name) > 0) {
            LASObject2Name = (char *)malloc((strlen(Object2Name) + 1) * sizeof(char));
            if (LASObject2Name != NULL)
                strcpy(LASObject2Name, Object2Name);
	}
	if (Object3Name != NULL && strlen(Object3Name) > 0) {
            LASObject3Name = (char *)malloc((strlen(Object3Name) + 1) * sizeof(char));
            if (LASObject3Name != NULL)
                strcpy(LASObject3Name, Object3Name);
	}
    } else {
        strcpy(LASProcName, "(procedure unknown)");
    }

    WriteLASErrDescr(stderr);

}
std::pair<unsigned int, Real>
LaspackLinearSolver<T>::adjoint_solve (SparseMatrix<T> &matrix_in,
                                       NumericVector<T> &solution_in,
                                       NumericVector<T> &rhs_in,
                                       const double tol,
                                       const unsigned int m_its)
{
  START_LOG("adjoint_solve()", "LaspackLinearSolver");
  this->init ();

  // Make sure the data passed in are really in Laspack types
  LaspackMatrix<T>* matrix   = cast_ptr<LaspackMatrix<T>*>(&matrix_in);
  LaspackVector<T>* solution = cast_ptr<LaspackVector<T>*>(&solution_in);
  LaspackVector<T>* rhs      = cast_ptr<LaspackVector<T>*>(&rhs_in);

  // Zero-out the solution to prevent the solver from exiting in 0
  // iterations (?)
  //TODO:[BSK] Why does Laspack do this?  Comment out this and try ex13...
  solution->zero();

  // Close the matrix and vectors in case this wasn't already done.
  matrix->close ();
  solution->close ();
  rhs->close ();

  // Set the preconditioner type
  this->set_laspack_preconditioner_type ();

  // Set the solver tolerance
  SetRTCAccuracy (tol);

  // Solve the linear system
  switch (this->_solver_type)
    {
      // Conjugate-Gradient
    case CG:
      {
        CGIter (Transp_Q(&matrix->_QMat),
                &solution->_vec,
                &rhs->_vec,
                m_its,
                _precond_type,
                1.);
        break;
      }

      // Conjugate-Gradient Normalized
    case CGN:
      {
        CGNIter (Transp_Q(&matrix->_QMat),
                 &solution->_vec,
                 &rhs->_vec,
                 m_its,
                 _precond_type,
                 1.);
        break;
      }

      // Conjugate-Gradient Squared
    case CGS:
      {
        CGSIter (Transp_Q(&matrix->_QMat),
                 &solution->_vec,
                 &rhs->_vec,
                 m_its,
                 _precond_type,
                 1.);
        break;
      }

      // Bi-Conjugate Gradient
    case BICG:
      {
        BiCGIter (Transp_Q(&matrix->_QMat),
                  &solution->_vec,
                  &rhs->_vec,
                  m_its,
                  _precond_type,
                  1.);
        break;
      }

      // Bi-Conjugate Gradient Stabilized
    case BICGSTAB:
      {
        BiCGSTABIter (Transp_Q(&matrix->_QMat),
                      &solution->_vec,
                      &rhs->_vec,
                      m_its,
                      _precond_type,
                      1.);
        break;
      }

      // Quasi-Minimum Residual
    case QMR:
      {
        QMRIter (Transp_Q(&matrix->_QMat),
                 &solution->_vec,
                 &rhs->_vec,
                 m_its,
                 _precond_type,
                 1.);
        break;
      }

      // Symmetric over-relaxation
    case SSOR:
      {
        SSORIter (Transp_Q(&matrix->_QMat),
                  &solution->_vec,
                  &rhs->_vec,
                  m_its,
                  _precond_type,
                  1.);
        break;
      }

      // Jacobi Relaxation
    case JACOBI:
      {
        JacobiIter (Transp_Q(&matrix->_QMat),
                    &solution->_vec,
                    &rhs->_vec,
                    m_its,
                    _precond_type,
                    1.);
        break;
      }

      // Generalized Minimum Residual
    case GMRES:
      {
        SetGMRESRestart (30);
        GMRESIter (Transp_Q(&matrix->_QMat),
                   &solution->_vec,
                   &rhs->_vec,
                   m_its,
                   _precond_type,
                   1.);
        break;
      }

      // Unknown solver, use GMRES
    default:
      {
        libMesh::err << "ERROR:  Unsupported LASPACK Solver: "
                     << Utility::enum_to_string(this->_solver_type) << std::endl
                     << "Continuing with GMRES" << std::endl;

        this->_solver_type = GMRES;

        return this->solve (*matrix,
                            *solution,
                            *rhs,
                            tol,
                            m_its);
      }
    }

  // Check for an error
  if (LASResult() != LASOK)
    {
      WriteLASErrDescr(stdout);
      libmesh_error_msg("Exiting after LASPACK Error!");
    }

  STOP_LOG("adjoint_solve()", "LaspackLinearSolver");
  // Get the convergence step # and residual
  return std::make_pair(GetLastNoIter(), GetLastAccuracy());
}