当前位置: 首页>>代码示例>>C++>>正文


C++ Epetra_SerialDenseMatrix::Print方法代码示例

本文整理汇总了C++中Epetra_SerialDenseMatrix::Print方法的典型用法代码示例。如果您正苦于以下问题:C++ Epetra_SerialDenseMatrix::Print方法的具体用法?C++ Epetra_SerialDenseMatrix::Print怎么用?C++ Epetra_SerialDenseMatrix::Print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Epetra_SerialDenseMatrix的用法示例。


在下文中一共展示了Epetra_SerialDenseMatrix::Print方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[])
{

#ifdef HAVE_MPI
  MPI_Init(&argc,&argv);
  Epetra_MpiComm Comm( MPI_COMM_WORLD );
#else
  Epetra_SerialComm Comm;
#endif

  bool verbose = false;

  // Check if we should print results to standard out
  verbose = true;

  if (verbose && Comm.MyPID()==0)
    cout << Epetra_Version() << endl << endl;

  int rank = Comm.MyPID();

  if (verbose) cout << Comm <<endl;

  // Redefine verbose to only print on PE 0
  if (verbose && rank!=0) verbose = false;
	
  int N = 5;
  int NRHS = 5;
  double * X = new double[NRHS];
  double * ed_X = new double[NRHS];

  double * B = new double[NRHS];
  double * ed_B = new double[NRHS];

  Ifpack_SerialTriDiSolver solver;
  Ifpack_SerialTriDiMatrix * Matrix;

  Epetra_SerialDenseSolver ed_solver;
  Epetra_SerialDenseMatrix * ed_Matrix;

  bool Transpose = false;
  bool Refine = false;
  solver.SolveWithTranspose(Transpose);
  solver.SolveToRefinedSolution(Refine);

  ed_solver.SolveWithTranspose(Transpose);
  ed_solver.SolveToRefinedSolution(Refine);

  Matrix = new Ifpack_SerialTriDiMatrix(5,true);
  ed_Matrix = new Epetra_SerialDenseMatrix(5,5);

  for(int i=0;i<N;++i) {
    B[i] = ed_B[i] =2;
    Matrix->D()[i]=2.0;
    if(i<(N-1)) {
      Matrix->DL()[i]=-1.0;
      if(i!=2) Matrix->DU()[i]=-1.0;
    }
  }

  Matrix->Print(std::cout);

  double * ed_a = ed_Matrix->A();
  for(int i=0;i<N;++i)
    for(int j=0;j<N;++j) {
      if(i==j) ed_a[j*N+i] = 2.0;
      else if(abs(i-j) == 1)   ed_a[j*N+i] = -1.0;
      else  ed_a[j*N + i] = 0;
      if(i==2&&j==3) ed_a[j*N+i] = 0.0;
    }


  Epetra_SerialDenseVector LHS(Copy, X, N);
  Epetra_SerialDenseVector RHS(Copy, B, N);

  Epetra_SerialDenseVector ed_LHS(Copy, ed_X, N);
  Epetra_SerialDenseVector ed_RHS(Copy, ed_B, N);

  solver.SetMatrix(*Matrix);
  solver.SetVectors(LHS, RHS);
  
  ed_solver.SetMatrix(*ed_Matrix);
  ed_solver.SetVectors(ed_LHS, ed_RHS);

  solver.Solve();  
  ed_solver.Solve();

  std::cout << " LHS vals are: "<<std::endl;
  bool TestPassed=true;
  for(int i=0;i<N;++i) { 
    std::cout << "["<<i<<"] "<< LHS(i)<<"  "<<ed_LHS(i)<<" delta "<<LHS(i)-ed_LHS(i)<<std::endl;
    if( fabs( (LHS(i)- ed_LHS(i))/(LHS(i)+ ed_LHS(i)) ) > 1.0e-12 ) {
       TestPassed = false;
       std::cout << " not equal for "<<i<<" delta "<< LHS(i)- ed_LHS(i)<<std::endl;
    }
  }

  Ifpack_SerialTriDiMatrix * tdfac = solver.FactoredMatrix();
  Epetra_SerialDenseMatrix * sdfac = ed_solver.FactoredMatrix();

  std::cout << " Tri Di Factored "<<std::endl;
//.........这里部分代码省略.........
开发者ID:KineticTheory,项目名称:Trilinos,代码行数:101,代码来源:tridi_main.cpp


注:本文中的Epetra_SerialDenseMatrix::Print方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。