]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add slepc quicktest, thanks Toby
authorTimo Heister <timo.heister@gmail.com>
Wed, 6 Nov 2013 14:47:38 +0000 (14:47 +0000)
committerTimo Heister <timo.heister@gmail.com>
Wed, 6 Nov 2013 14:47:38 +0000 (14:47 +0000)
git-svn-id: https://svn.dealii.org/trunk@31563 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/tests/quick_tests/CMakeLists.txt
deal.II/tests/quick_tests/step-slepc.cc [new file with mode: 0644]

index 57ef944d871a2e78375cb07a0216034fb04950b8..2a4031cfab6b2bb329bf10b333c33adf9709d3c0 100644 (file)
@@ -85,6 +85,10 @@ IF (DEAL_II_WITH_P4EST)
   make_quicktest("p4est" ${_mybuild} 10)
 ENDIF()
 
+# Test slepc
+IF (DEAL_II_WITH_SLEPC)
+  make_quicktest("step-slepc" ${_mybuild} "")
+ENDIF()
 
 # A custom test target:
 ADD_CUSTOM_TARGET(test
diff --git a/deal.II/tests/quick_tests/step-slepc.cc b/deal.II/tests/quick_tests/step-slepc.cc
new file mode 100644 (file)
index 0000000..51bc2a6
--- /dev/null
@@ -0,0 +1,205 @@
+/* ---------------------------------------------------------------------\r
+ * $Id$\r
+ *\r
+ * Copyright (C) 2013 by the deal.II authors\r
+ *\r
+ * This file is part of the deal.II library.\r
+ *\r
+ * The deal.II library is free software; you can use it, redistribute\r
+ * it, and/or modify it under the terms of the GNU Lesser General\r
+ * Public License as published by the Free Software Foundation; either\r
+ * version 2.1 of the License, or (at your option) any later version.\r
+ * The full text of the license can be found in the file LICENSE at\r
+ * the top level of the deal.II distribution.\r
+ *\r
+ * ---------------------------------------------------------------------\r
+ */\r
+\r
+#include <deal.II/base/logstream.h>\r
+#include <deal.II/base/quadrature_lib.h>\r
+#include <deal.II/base/function.h>\r
+#include <deal.II/base/utilities.h>\r
+#include <deal.II/grid/tria.h>\r
+#include <deal.II/grid/grid_generator.h>\r
+#include <deal.II/grid/tria_accessor.h>\r
+#include <deal.II/grid/tria_iterator.h>\r
+#include <deal.II/dofs/dof_handler.h>\r
+#include <deal.II/dofs/dof_accessor.h>\r
+#include <deal.II/dofs/dof_tools.h>\r
+#include <deal.II/fe/fe_q.h>\r
+#include <deal.II/fe/fe_values.h>\r
+#include <deal.II/numerics/vector_tools.h>\r
+#include <deal.II/numerics/matrix_tools.h>\r
+#include <deal.II/numerics/data_out.h>\r
+#include <deal.II/lac/full_matrix.h>\r
+#include <deal.II/lac/petsc_sparse_matrix.h>\r
+#include <deal.II/lac/petsc_vector.h>\r
+#include <deal.II/lac/slepc_solver.h>\r
+\r
+#include <fstream>\r
+#include <iostream>\r
+\r
+using namespace dealii;\r
+\r
+// Test that deal.II is working with SLEPc by solving the Laplace's\r
+// eigenspectrum problem in 2d.\r
+class LaplaceEigenspectrumProblem\r
+{\r
+public:\r
+  LaplaceEigenspectrumProblem ();\r
+  void run ();\r
+  \r
+private:\r
+  void setup_system ();\r
+  void assemble_system ();\r
+  void solve ();\r
+  \r
+  Triangulation<2> triangulation;\r
+  FE_Q<2>          fe;\r
+  DoFHandler<2>    dof_handler;\r
+  \r
+  PETScWrappers::SparseMatrix        A, B;\r
+  std::vector<PETScWrappers::Vector> x;\r
+  std::vector<double>                lambda;\r
+  \r
+  ConstraintMatrix constraints;\r
+};\r
+\r
+LaplaceEigenspectrumProblem::LaplaceEigenspectrumProblem ()\r
+  :\r
+  fe (1),\r
+  dof_handler (triangulation)\r
+{}\r
+\r
+void LaplaceEigenspectrumProblem::setup_system ()\r
+{\r
+  GridGenerator::hyper_cube (triangulation, -1, 1);\r
+  triangulation.refine_global (3);\r
+  dof_handler.distribute_dofs (fe);\r
+  \r
+  DoFTools::make_zero_boundary_constraints (dof_handler, constraints);\r
+  constraints.close ();\r
+  \r
+  A.reinit (dof_handler.n_dofs(), dof_handler.n_dofs(),\r
+           dof_handler.max_couplings_between_dofs());\r
+  B.reinit (dof_handler.n_dofs(), dof_handler.n_dofs(),\r
+           dof_handler.max_couplings_between_dofs());\r
+  \r
+  x.resize (1);\r
+  x[0].reinit (dof_handler.n_dofs ());\r
+  lambda.resize (1);\r
+  lambda[0] = 0.;\r
+}\r
+\r
+void LaplaceEigenspectrumProblem::assemble_system ()\r
+{\r
+  QGauss<2> quadrature_formula(2);\r
+  \r
+  FEValues<2> fe_values (fe, quadrature_formula,\r
+                        update_values            | \r
+                        update_gradients         |\r
+                        update_quadrature_points | \r
+                        update_JxW_values);\r
+  \r
+  const unsigned int dofs_per_cell = fe.dofs_per_cell;\r
+  const unsigned int n_q_points    = quadrature_formula.size();\r
+  \r
+  FullMatrix<double> cell_A (dofs_per_cell, dofs_per_cell);\r
+  FullMatrix<double> cell_B (dofs_per_cell, dofs_per_cell);\r
+  \r
+  std::vector<types::global_dof_index> local_dof_indices (dofs_per_cell);\r
+  \r
+  typename DoFHandler<2>::active_cell_iterator\r
+    cell = dof_handler.begin_active (),\r
+    endc = dof_handler.end ();\r
+  \r
+  for (; cell!=endc; ++cell)\r
+    {\r
+      fe_values.reinit (cell);\r
+      cell_A = 0;\r
+      cell_B = 0;\r
+      \r
+      for (unsigned int q_point=0; q_point<n_q_points; ++q_point)\r
+       for (unsigned int i=0; i<dofs_per_cell; ++i)\r
+         for (unsigned int j=0; j<dofs_per_cell; ++j)\r
+           {\r
+             cell_A (i, j)\r
+               += \r
+               fe_values.shape_grad (i, q_point) *\r
+               fe_values.shape_grad (j, q_point)\r
+               * \r
+               fe_values.JxW (q_point);\r
+             \r
+             cell_B (i, j)\r
+                += \r
+               fe_values.shape_value (i, q_point) *\r
+               fe_values.shape_value (j, q_point)\r
+               * \r
+               fe_values.JxW (q_point);\r
+           }\r
+      \r
+      cell->get_dof_indices (local_dof_indices);\r
+      \r
+      constraints.distribute_local_to_global (cell_A, local_dof_indices, A);\r
+      constraints.distribute_local_to_global (cell_B, local_dof_indices, B);\r
+    }\r
+  \r
+  A.compress (VectorOperation::add);\r
+  B.compress (VectorOperation::add);\r
+}\r
+\r
+void LaplaceEigenspectrumProblem::solve ()\r
+{\r
+  SolverControl solver_control (1., 1e-03);\r
+  SLEPcWrappers::SolverLAPACK eigensolver (solver_control);\r
+  eigensolver.solve (A, B, lambda, x, x.size());\r
+}\r
+\r
+void LaplaceEigenspectrumProblem::run ()\r
+{\r
+  setup_system ();\r
+  assemble_system ();\r
+  solve ();\r
+}\r
+\r
+\r
+int main (int argc, char **argv)\r
+{\r
+  try\r
+    {\r
+      dealii::Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, 1);\r
+      {\r
+        deallog.depth_console (0);\r
+        LaplaceEigenspectrumProblem problem;\r
+        problem.run ();\r
+       deallog << "OK" << std::endl;\r
+      }\r
+    }\r
+\r
+  catch (std::exception &exc)\r
+    {\r
+      std::cerr << std::endl << std::endl\r
+                << "----------------------------------------------------"\r
+                << std::endl;\r
+      std::cerr << "Exception on processing: " << std::endl\r
+                << exc.what() << std::endl\r
+                << "Aborting!" << std::endl\r
+                << "----------------------------------------------------"\r
+                << std::endl;\r
+\r
+      return 1;\r
+    }\r
+  catch (...)\r
+    {\r
+      std::cerr << std::endl << std::endl\r
+                << "----------------------------------------------------"\r
+                << std::endl;\r
+      std::cerr << "Unknown exception!" << std::endl\r
+                << "Aborting!" << std::endl\r
+                << "----------------------------------------------------"\r
+                << std::endl;\r
+      return 1;\r
+    }\r
+\r
+  return 0;\r
+}\r

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.