]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add a quick test for Arpack
authorDenis Davydov <davydden@gmail.com>
Thu, 13 Oct 2016 09:29:19 +0000 (11:29 +0200)
committerDenis Davydov <davydden@gmail.com>
Thu, 13 Oct 2016 09:29:19 +0000 (11:29 +0200)
tests/quick_tests/CMakeLists.txt
tests/quick_tests/arpack.cc [new file with mode: 0644]

index 97bae28fca15e78d88e6a1c65444b5598e9b85ab..84fcbfb0537641aa83d312ccc8ea98612333c987 100644 (file)
@@ -136,6 +136,11 @@ IF (DEAL_II_WITH_GSL)
   make_quicktest("gsl" ${_mybuild} "")
 ENDIF()
 
+# Test Arpack
+IF (DEAL_II_WITH_ARPACK AND DEAL_II_WITH_UMFPACK)
+  make_quicktest("arpack" ${_mybuild} "")
+ENDIF()
+
 
 
 # A custom test target:
diff --git a/tests/quick_tests/arpack.cc b/tests/quick_tests/arpack.cc
new file mode 100644 (file)
index 0000000..087d061
--- /dev/null
@@ -0,0 +1,106 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2016 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// test Arpack by calculating eigenvalues of Laplace matrix.
+
+#include "../tests.h"
+#include <iostream>
+#include <fstream>
+#include <cstdlib>
+
+#include <deal.II/base/quadrature_lib.h>
+#include <deal.II/base/function.h>
+
+#include <deal.II/fe/fe_q.h>
+#include <deal.II/fe/fe_values.h>
+
+#include <deal.II/dofs/dof_tools.h>
+
+#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/sparsity_pattern.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/lac/sparse_direct.h>
+#include <deal.II/lac/arpack_solver.h>
+#include <deal.II/lac/sparse_direct.h>
+#include <deal.II/lac/solver_control.h>
+
+#include <deal.II/grid/tria.h>
+#include <deal.II/grid/grid_generator.h>
+
+#include <deal.II/numerics/vector_tools.h>
+#include <deal.II/numerics/matrix_tools.h>
+
+
+
+template <int dim>
+void test ()
+{
+  const unsigned int n_eigenvalues=3;
+
+  Triangulation<dim> tria;
+  GridGenerator::hyper_cube (tria,0,1);
+  tria.refine_global (3);
+
+  FE_Q<dim> fe (1);
+  DoFHandler<dim> dof_handler (tria);
+  dof_handler.distribute_dofs (fe);
+
+  deallog << "Number of dofs = " << dof_handler.n_dofs() << std::endl;
+
+  SparsityPattern sparsity_pattern;
+  sparsity_pattern.reinit (dof_handler.n_dofs(),
+                           dof_handler.n_dofs(),
+                           dof_handler.max_couplings_between_dofs());
+  DoFTools::make_sparsity_pattern (dof_handler, sparsity_pattern);
+  sparsity_pattern.compress ();
+
+  SparseMatrix<double> A,B;
+  A.reinit (sparsity_pattern);
+  B.reinit (sparsity_pattern);
+
+  std::vector<Vector<double> > eigenvectors(n_eigenvalues,
+                                            Vector<double>(dof_handler.n_dofs()));
+  std::vector<std::complex<double> > eigenvalues(n_eigenvalues);
+
+  QGauss<dim> qr (2);
+  MatrixTools::create_laplace_matrix (dof_handler, qr, A);
+  MatrixTools::create_mass_matrix (dof_handler, qr, B);
+
+  SolverControl solver_control (dof_handler.n_dofs(), 1e-10);
+  SparseDirectUMFPACK inverse;
+  inverse.initialize (A);
+  const unsigned int num_arnoldi_vectors = 2*eigenvalues.size() + 2;
+  ArpackSolver::AdditionalData additional_data(num_arnoldi_vectors,
+                                               ArpackSolver::largest_magnitude,
+                                               true);
+  ArpackSolver eigensolver (solver_control, additional_data);
+  eigensolver.solve (A,
+                     B,
+                     inverse,
+                     eigenvalues,
+                     eigenvectors,
+                     eigenvalues.size());
+}
+
+
+int main ()
+{
+  std::ofstream logfile("output");
+  deallog.attach(logfile);
+  deallog.threshold_double(1.e-9);
+
+  test<2> ();
+}

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.