"Fossies" - the Fresh Open Source Software Archive

Member "dune-istl-2.7.1/dune/istl/test/superlutest.cc" (26 Nov 2020, 5659 Bytes) of package /linux/misc/dune/dune-istl-2.7.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "superlutest.cc": 2.6.0_vs_2.7.0.

    1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
    2 // vi: set et ts=4 sw=2 sts=2:
    3 #include <config.h>
    4 
    5 #include <complex>
    6 
    7 #include <dune/common/fmatrix.hh>
    8 #include <dune/common/fvector.hh>
    9 #include <dune/common/timer.hh>
   10 
   11 #include <dune/istl/bvector.hh>
   12 #include <dune/istl/operators.hh>
   13 #include <dune/istl/superlu.hh>
   14 
   15 #include "laplacian.hh"
   16 
   17 #if HAVE_SUPERLU
   18 template<typename Matrix, typename Vector>
   19 void runSuperLU(std::size_t N)
   20 {
   21   using Operator = Dune::MatrixAdapter<Matrix,Vector,Vector>;
   22 
   23   Matrix mat;
   24   Operator fop(mat);
   25   Vector b(N*N), x(N*N), b1(N/2), x1(N/2);
   26 
   27   setupLaplacian(mat,N);
   28   b=1;
   29   b1=1;
   30   x=0;
   31   x1=0;
   32 
   33   Dune::Timer watch;
   34 
   35   watch.reset();
   36 
   37   Dune::SuperLU<Matrix> solver(mat, true);
   38 
   39   Dune::InverseOperatorResult res;
   40 
   41   Dune::SuperLU<Matrix> solver1;
   42 
   43   solver.setVerbosity(true);
   44   solver.apply(x,b, res);
   45 
   46   std::set<std::size_t> mrs;
   47   for(std::size_t s=0; s < N/2; ++s)
   48     mrs.insert(s);
   49 
   50   solver1.setSubMatrix(mat,mrs);
   51 
   52   solver1.apply(x1,b1, res);
   53   solver1.apply(reinterpret_cast<typename Matrix::field_type*>(&x1[0]),
   54                 reinterpret_cast<typename Matrix::field_type*>(&b1[0]));
   55 }
   56 
   57 // explicit template instantiation of SuperLU class
   58 
   59 #if HAVE_SLU_SDEFS_H
   60 template class Dune::SuperLU<Dune::BCRSMatrix<float>>;
   61 template class Dune::SuperLU<Dune::BCRSMatrix<Dune::FieldMatrix<float,1,1> >>;
   62 template class Dune::SuperLU<Dune::BCRSMatrix<Dune::FieldMatrix<float,2,2> >>;
   63 #endif
   64 
   65 #if HAVE_SLU_DDEFS_H
   66 template class Dune::SuperLU<Dune::BCRSMatrix<double>>;
   67 template class Dune::SuperLU<Dune::BCRSMatrix<Dune::FieldMatrix<double,1,1> >>;
   68 template class Dune::SuperLU<Dune::BCRSMatrix<Dune::FieldMatrix<double,2,2> >>;
   69 #endif
   70 
   71 #if HAVE_SLU_CDEFS_H
   72 template class Dune::SuperLU<Dune::BCRSMatrix<std::complex<float> >>;
   73 template class Dune::SuperLU<Dune::BCRSMatrix<Dune::FieldMatrix<std::complex<float>,1,1> >>;
   74 template class Dune::SuperLU<Dune::BCRSMatrix<Dune::FieldMatrix<std::complex<float>,2,2> >>;
   75 #endif
   76 
   77 #if HAVE_SLU_ZDEFS_H
   78 template class Dune::SuperLU<Dune::BCRSMatrix<std::complex<double> >>;
   79 template class Dune::SuperLU<Dune::BCRSMatrix<Dune::FieldMatrix<std::complex<double>,1,1> >>;
   80 template class Dune::SuperLU<Dune::BCRSMatrix<Dune::FieldMatrix<std::complex<double>,2,2> >>;
   81 #endif
   82 
   83 #endif
   84 
   85 
   86 int main(int argc, char** argv)
   87 try
   88 {
   89 #if HAVE_SUPERLU
   90   std::size_t N=100;
   91 
   92   if(argc>1)
   93     N = atoi(argv[1]);
   94 
   95   // ------------------------------------------------------------------------------
   96   std::cout<<"testing for N="<<N<<" BCRSMatrix<T>"<<std::endl;
   97 #if HAVE_SLU_SDEFS_H
   98   {
   99     using Matrix = Dune::BCRSMatrix<float>;
  100     using Vector = Dune::BlockVector<float>;
  101     runSuperLU<Matrix,Vector>(N);
  102   }
  103 #endif
  104 #if HAVE_SLU_DDEFS_H
  105   {
  106     using Matrix = Dune::BCRSMatrix<double>;
  107     using Vector = Dune::BlockVector<double>;
  108     runSuperLU<Matrix,Vector>(N);
  109   }
  110 #endif
  111 #if HAVE_SLU_CDEFS_H
  112   {
  113     using Matrix = Dune::BCRSMatrix<std::complex<float> >;
  114     using Vector = Dune::BlockVector<std::complex<float> >;
  115     runSuperLU<Matrix,Vector>(N);
  116   }
  117 #endif
  118 #if HAVE_SLU_ZDEFS_H
  119   {
  120     using Matrix = Dune::BCRSMatrix<std::complex<double> >;
  121     using Vector = Dune::BlockVector<std::complex<double> >;
  122     runSuperLU<Matrix,Vector>(N);
  123   }
  124 #endif
  125 
  126   // ------------------------------------------------------------------------------
  127   std::cout<<"testing for N="<<N<<" BCRSMatrix<FieldMatrix<T,1,1> >"<<std::endl;
  128 #if HAVE_SLU_SDEFS_H
  129   {
  130     using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<float,1,1> >;
  131     using Vector = Dune::BlockVector<Dune::FieldVector<float,1> >;
  132     runSuperLU<Matrix,Vector>(N);
  133   }
  134 #endif
  135 #if HAVE_SLU_DDEFS_H
  136   {
  137     using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<double,1,1> >;
  138     using Vector = Dune::BlockVector<Dune::FieldVector<double,1> >;
  139     runSuperLU<Matrix,Vector>(N);
  140   }
  141 #endif
  142 #if HAVE_SLU_CDEFS_H
  143   {
  144     using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<std::complex<float>,1,1> >;
  145     using Vector = Dune::BlockVector<Dune::FieldVector<std::complex<float>,1> >;
  146     runSuperLU<Matrix,Vector>(N);
  147   }
  148 #endif
  149 #if HAVE_SLU_ZDEFS_H
  150   {
  151     using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<std::complex<double>,1,1> >;
  152     using Vector = Dune::BlockVector<Dune::FieldVector<std::complex<double>,1> >;
  153     runSuperLU<Matrix,Vector>(N);
  154   }
  155 #endif
  156 
  157   // ------------------------------------------------------------------------------
  158   std::cout<<"testing for N="<<N<<" BCRSMatrix<FieldMatrix<T,2,2> >"<<std::endl;
  159 #if HAVE_SLU_SDEFS_H
  160   {
  161     using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<float,2,2> >;
  162     using Vector = Dune::BlockVector<Dune::FieldVector<float,2> >;
  163     runSuperLU<Matrix,Vector>(N);
  164   }
  165 #endif
  166 #if HAVE_SLU_DDEFS_H
  167   {
  168     using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<double,2,2> >;
  169     using Vector = Dune::BlockVector<Dune::FieldVector<double,2> >;
  170     runSuperLU<Matrix,Vector>(N);
  171   }
  172 #endif
  173 #if HAVE_SLU_CDEFS_H
  174   {
  175     using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<std::complex<float>,2,2> >;
  176     using Vector = Dune::BlockVector<Dune::FieldVector<std::complex<float>,2> >;
  177     runSuperLU<Matrix,Vector>(N);
  178   }
  179 #endif
  180 #if HAVE_SLU_ZDEFS_H
  181   {
  182     using Matrix = Dune::BCRSMatrix<Dune::FieldMatrix<std::complex<double>,2,2> >;
  183     using Vector = Dune::BlockVector<Dune::FieldVector<std::complex<double>,2> >;
  184     runSuperLU<Matrix,Vector>(N);
  185   }
  186 #endif
  187 
  188   return 0;
  189 
  190 #else // HAVE_SUPERLU
  191   std::cerr << "You need SuperLU to run this test." << std::endl;
  192   return 77;
  193 #endif // HAVE_SUPERLU
  194 }
  195 catch (std::exception &e)
  196 {
  197   std::cout << "ERROR: " << e.what() << std::endl;
  198   return 1;
  199 }
  200 catch (...)
  201 {
  202   std::cerr << "Dune reported an unknown error." << std::endl;
  203   exit(1);
  204 }