Exemplo n.º 1
0
void Solver::ProccessStart(void) {

	#include "perem.cpp"
	#include "viraj.cpp"
#ifdef __TASK1__
	QMatrix A;
	Vector B, D;

	Q_Constr(&A, (char*)"A", 3 * total, False, Rowws, Normal, True);
	V_Constr(&B, (char*)"B", 3 * total, Normal, True);
	V_Constr(&D, (char*)"D", 3 * total, Normal, True);
	SetRTCAccuracy(1e-8);
#endif
#ifdef __TASK2__
	double *A = new double [3 * 9 * total * 3];
	int sizeA = 0;
	double *B = new double [3 * total];
	double *D = new double [3 * total];
#endif

#ifdef __TASK1__
		mm = 1;
#endif
#ifdef __TASK2__
		mm = 0;
#endif

 	for(int i = 0; i < total; i++) {
#ifdef __TASK1__
		V_SetCmp(&D, 3 * i + mm, G[i]);
		V_SetCmp(&D, 3 * i + 1 + mm, V1[i]);
		V_SetCmp(&D, 3 * i + 2 + mm, V2[i]);
#endif
#ifdef __TASK2__
		D[3 * i + mm] = G[i];
		D[3 * i + 1 + mm] = V1[i];
		D[3 * i + 2 + mm] = V2[i];
#endif
	}

	for (nn = 1; nn <= N;nn++) {
		tt = nn * tau;

		#include "mum.cpp"
//#ifdef __TASK1__
		mm = 1;
//#endif
#ifdef __TASK2__
//		mm = 0;
		sizeA = 0;
#endif
		for (m = 0; m < Dim; m++) {

		
			int n_, m_;
			int i00, i0m1, i0p1, i0pp1, i0mm1;
			i00 = m;
			Getmn(i00, &m_, &n_);
			GetN(&i0m1, m_, n_ - 1);
			GetN(&i0p1, m_, n_ + 1);
			GetN(&i0pp1, m_,n_ + 2);
			GetN(&i0mm1, m_,n_ - 2);

			M0L[m] = i0m1;
			M0R[m] = i0p1;
	
			xx = m_ * h1;
			yy = n_ * h2;

			switch (st[m]){
				#include "case0.cpp"
				#include "case1.cpp"
				#include "case2.cpp"
				#include "case3.cpp"
				#include "case4.cpp"
				#include "case5.cpp"
				#include "case6.cpp"
				#include "case7.cpp"
				#include "case8.cpp"
				#include "case9.cpp"
			}
		}


		//CGSIter(&A, &D, &B, 2000, NULL, 1.2);
#ifdef __TASK1__
		SetRTCAccuracy(1e-8);
		BiCGSTABIter(&A, &D, &B, 2000, NULL, 1.2);
#endif
#ifdef __TASK2__
		t2Solve(A, D, B, 3 * total, 2000);
#endif

#ifdef __TASK1__
	mm = 1;
#endif
#ifdef __TASK2__
	mm = 0;
#endif

		for (m = 0; m < Dim; m++) {
#ifdef __TASK1__
			G[m] = V_GetCmp(&D, 3 * m + mm);
			V1[m] = V_GetCmp(&D, 3 * m + 1 + mm);
			V2[m] = V_GetCmp(&D, 3 * m + 2 + mm);
#endif
#ifdef __TASK2__
			G[m] = D[3 * m + mm];
			V1[m] = D[3 * m + 1 + mm];
			V2[m] = D[3 * m + 2 + mm];
#endif
		}
#ifdef __TASK3__
		std::stringstream str;

		str << "_plot" << nn;
		FILE *f = fopen(str.str().c_str(), "w");
		for (m = 0; m < Dim; m++) {
			int n_, m_;
			Getmn(m, &m_, &n_);
			fprintf(f, "%lf %lf %lf %lf\n", m_ * h1, - n_ * h2, V1[m] / 10, - V2[m]);
		}
		fclose(f);

		str.str("");
		str << "_dense" << nn;
		FILE *fd = fopen(str.str().c_str(), "w");
		for (m = 0; m < Dim; m++) {
			int n_, m_;
			Getmn(m, &m_, &n_);
			fprintf(fd, "%lf %lf %d\n", m_ * h1, - n_ * h2, exp(G[m]) > 1);
		}
		fclose(fd);
#endif
	}	

#ifdef __TASK1__
	Q_Destr(&A);
	V_Destr(&B);
	V_Destr(&D);
#endif
#ifdef __TASK2__
	delete [] A;
	delete [] B;
	delete [] D;
#endif
}	
Exemplo n.º 2
0
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());
}