int main()
{
  int n = 10;
  Eigen::SparseMatrix<double> S = Eigen::MatrixXd::Random(n,n).sparseView(0.5,1);
  S = S.transpose()*S;

  MatrixReplacement A;
  A.attachMyMatrix(S);

  Eigen::VectorXd b(n), x;
  b.setRandom();

  // Solve Ax = b using various iterative solver with matrix-free version:
  {
    Eigen::ConjugateGradient<MatrixReplacement, Eigen::Lower|Eigen::Upper, Eigen::IdentityPreconditioner> cg;
    cg.compute(A);
    x = cg.solve(b);
    std::cout << "CG:       #iterations: " << cg.iterations() << ", estimated error: " << cg.error() << std::endl;
  }

  {
    Eigen::BiCGSTAB<MatrixReplacement, Eigen::IdentityPreconditioner> bicg;
    bicg.compute(A);
    x = bicg.solve(b);
    std::cout << "BiCGSTAB: #iterations: " << bicg.iterations() << ", estimated error: " << bicg.error() << std::endl;
  }

  {
    Eigen::GMRES<MatrixReplacement, Eigen::IdentityPreconditioner> gmres;
    gmres.compute(A);
    x = gmres.solve(b);
    std::cout << "GMRES:    #iterations: " << gmres.iterations() << ", estimated error: " << gmres.error() << std::endl;
  }

  {
    Eigen::DGMRES<MatrixReplacement, Eigen::IdentityPreconditioner> gmres;
    gmres.compute(A);
    x = gmres.solve(b);
    std::cout << "DGMRES:   #iterations: " << gmres.iterations() << ", estimated error: " << gmres.error() << std::endl;
  }

  {
    Eigen::MINRES<MatrixReplacement, Eigen::Lower|Eigen::Upper, Eigen::IdentityPreconditioner> minres;
    minres.compute(A);
    x = minres.solve(b);
    std::cout << "MINRES:   #iterations: " << minres.iterations() << ", estimated error: " << minres.error() << std::endl;
  }
}
예제 #2
0
void ReconstructionSurface::construction_RBF(){
    //calcul des distances
    int taille = static_cast<int>(vertices_tab.size());
    Eigen::SparseMatrix<double> distances(taille, taille);
    for (int i = 0; i < taille; ++i) {
        for (int j = i; j < taille; ++j) {
            double dist = glm::distance(vertices_tab.at(i), vertices_tab.at(j));
            dist = fonction_RBF(dist);
            distances.coeffRef(i,j) = dist;
            distances.coeffRef(j,i) = dist;
        }
    }
    //calcul des poids par resolution du système avec matrice creuse
    Eigen::BiCGSTAB< Eigen::SparseMatrix<double> > solver;
    solver.compute(distances);
    weight_tab = solver.solve(iso_tab);
    std::cout << "###########################" << std::endl;
    std::cout << "Sorties du solveurs :      " << std::endl;
    std::cout << "Iterations :     " << solver.iterations() << std::endl;
    std::cout << "Estimated error: " << solver.error()      << std::endl;
    std::cout << "###########################" << std::endl;
}