]> https://gitweb.dealii.org/ - dealii.git/commitdiff
parpack: add set_initial_vector() for Krylov subspace 2680/head
authorDenis Davydov <davydden@gmail.com>
Tue, 14 Jun 2016 09:00:47 +0000 (11:00 +0200)
committerDenis Davydov <davydden@gmail.com>
Tue, 14 Jun 2016 15:01:19 +0000 (17:01 +0200)
include/deal.II/lac/parpack_solver.h
tests/arpack/step-36_parpack.cc
tests/arpack/step-36_parpack_trilinos.cc

index 972de1286a3d5db179ba4cfbe3a10db25e557545..5cfbf425917f2e3e739522146a8d4ea4b6151f5c 100644 (file)
@@ -259,7 +259,13 @@ public:
               const std::vector<IndexSet> &partitioning);
 
   /**
-   * Set desired shift value.
+   * Set initial vector for building Krylov space.
+   */
+  void set_initial_vector(const VectorType &vec);
+
+  /**
+   * Set desired shift value. If this function is not called, the
+   * shift is assumed to be zero.
    */
   void set_shift(const double s );
 
@@ -344,6 +350,11 @@ protected:
    */
   std::vector<double> v;
 
+  /**
+   * An auxiliary flag which is set to true when initial vector is provided.
+   */
+  bool initial_vector_provided;
+
   /**
    * The initial residual vector, possibly from a previous run.  On output, it
    * contains the final residual vector.
@@ -491,6 +502,7 @@ PArpackSolver<VectorType>::PArpackSolver (SolverControl        &control,
   additional_data (data),
   mpi_communicator( mpi_communicator ),
   mpi_communicator_fortran ( MPI_Comm_c2f( mpi_communicator ) ),
+  initial_vector_provided(false),
   shift_value(0.0)
 
 {}
@@ -501,6 +513,19 @@ void PArpackSolver<VectorType>::set_shift(const double s )
   shift_value = s;
 }
 
+template <typename VectorType>
+void PArpackSolver<VectorType>::
+set_initial_vector(const VectorType &vec)
+{
+  initial_vector_provided = true;
+  Assert (resid.size() == local_indices.size(),
+          ExcDimensionMismatch(resid.size(),local_indices.size()));
+  vec.extract_subvector_to (local_indices.begin(),
+                            local_indices.end(),
+                            &resid[0]);
+}
+
+
 template <typename VectorType>
 void PArpackSolver<VectorType>::
 internal_reinit(const IndexSet &locally_owned_dofs)
@@ -684,7 +709,7 @@ void PArpackSolver<VectorType>::solve
   //  possibly from a previous run.
   // Typical choices in this situation might be to use the final value
   // of the starting vector from the previous eigenvalue calculation
-  int info = 1;
+  int info = initial_vector_provided? 1 : 0;
 
   // Number of eigenvalues of OP to be computed. 0 < NEV < N.
   int nev = n_eigenvalues;
index 7e4df13cb8319547b9634022ce46367da916b1b7..b9cef33e1508cd36b13340aa3601698c3cde5e0e 100644 (file)
@@ -286,6 +286,8 @@ void test ()
         mpi_communicator,
         additional_data);
     eigensolver.reinit(locally_owned_dofs);
+    eigenfunctions[0] = 1.;
+    eigensolver.set_initial_vector(eigenfunctions[0]);
     eigensolver.solve (stiffness_matrix,
                        mass_matrix,
                        inverse,
index 90a2a65ccfd4efd7c4e2a4f1333890d38c102947..ee2ff903b8b37f23fbc720b2edf3fb79d0cb34c7 100644 (file)
@@ -276,7 +276,8 @@ void test ()
                                                               additional_data);
     eigensolver.reinit(locally_owned_dofs);
     eigensolver.set_shift(shift);
-
+    eigenfunctions[0] = 1.;
+    eigensolver.set_initial_vector(eigenfunctions[0]);
     // avoid output of iterative solver:
     const unsigned int previous_depth = deallog.depth_file(0);
     eigensolver.solve (stiffness_matrix,

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.