]> https://gitweb.dealii.org/ - dealii.git/commitdiff
TrilinosWrappers::SolverDirect: adjust interface 16727/head
authorPeter Munch <peterrmuench@gmail.com>
Thu, 7 Mar 2024 12:14:15 +0000 (13:14 +0100)
committerPeter Munch <peterrmuench@gmail.com>
Wed, 13 Mar 2024 07:11:58 +0000 (08:11 +0100)
include/deal.II/lac/trilinos_solver.h
source/lac/trilinos_solver.cc

index 34e54b0ad68281847b27953e403e5717071999c5..9af69640576a879c260043b6bb07bc6382699fa7 100644 (file)
@@ -480,7 +480,7 @@ namespace TrilinosWrappers
    *
    * @ingroup TrilinosWrappers
    */
-  class SolverDirect
+  class SolverDirect : public Subscriptor
   {
   public:
     /**
@@ -522,6 +522,11 @@ namespace TrilinosWrappers
       std::string solver_type;
     };
 
+    /**
+     * Constructor. Creates the solver without solver control object.
+     */
+    explicit SolverDirect(const AdditionalData &data = AdditionalData());
+
     /**
      * Constructor. Takes the solver control object and creates the solver.
      */
@@ -542,10 +547,20 @@ namespace TrilinosWrappers
     void
     initialize(const SparseMatrix &A);
 
+    /**
+     * Initializes the direct solver for the matrix <tt>A</tt> and creates a
+     * factorization for it with the package chosen from the additional
+     * data structure. Note that there is no need for a preconditioner
+     * here and solve() is not called. Furthermore, @p data replaces the
+     * data stored in this instance.
+     */
+    void
+    initialize(const SparseMatrix &A, const AdditionalData &data);
+
     /**
      * Solve the linear system <tt>Ax=b</tt> based on the
-     * package set in initialize(). Note the matrix is not refactorized during
-     * this call.
+     * package set in the constructor on initialize(). Note the matrix is not
+     * refactored during this call.
      */
     void
     solve(MPI::Vector &x, const MPI::Vector &b);
@@ -553,12 +568,29 @@ namespace TrilinosWrappers
     /**
      * Solve the linear system <tt>Ax=b</tt> based on the package set in
      * initialize() for deal.II's own parallel vectors. Note the matrix is not
-     * refactorized during this call.
+     * refactored during this call.
      */
     void
     solve(dealii::LinearAlgebra::distributed::Vector<double>       &x,
           const dealii::LinearAlgebra::distributed::Vector<double> &b);
 
+    /**
+     * Solve the linear system <tt>Ax=b</tt> based on the
+     * package set in the constructor or initialize(). Note the matrix is not
+     * refactored during this call.
+     */
+    void
+    vmult(MPI::Vector &x, const MPI::Vector &b) const;
+
+    /**
+     * Solve the linear system <tt>Ax=b</tt> based on the package set in
+     * initialize() for deal.II's own parallel vectors. Note the matrix is not
+     * refactored during this call.
+     */
+    void
+    vmult(dealii::LinearAlgebra::distributed::Vector<double>       &x,
+          const dealii::LinearAlgebra::distributed::Vector<double> &b) const;
+
     /**
      * Solve the linear system <tt>Ax=b</tt>. Creates a factorization of the
      * matrix with the package chosen from the additional data structure and
@@ -613,6 +645,11 @@ namespace TrilinosWrappers
     void
     do_solve();
 
+    /**
+     * Local dummy solver control object.
+     */
+    SolverControl solver_control_own;
+
     /**
      * Reference to the object that controls convergence of the iterative
      * solver. In fact, for these Trilinos wrappers, Trilinos does so itself,
@@ -637,7 +674,7 @@ namespace TrilinosWrappers
     /**
      * Store a copy of the flags for this particular solver.
      */
-    const AdditionalData additional_data;
+    AdditionalData additional_data;
   };
 
 
index 37422f0bc057d7c628da03ed32b51f23907562de..1e65888912c05d3c14ff2915e4a843d246bd158e 100644 (file)
@@ -636,6 +636,13 @@ namespace TrilinosWrappers
 
 
 
+  SolverDirect::SolverDirect(const AdditionalData &data)
+    : solver_control(solver_control_own)
+    , additional_data(data.output_solver_details, data.solver_type)
+  {}
+
+
+
   SolverDirect::SolverDirect(SolverControl &cn, const AdditionalData &data)
     : solver_control(cn)
     , additional_data(data.output_solver_details, data.solver_type)
@@ -696,8 +703,35 @@ namespace TrilinosWrappers
   }
 
 
+
+  void
+  SolverDirect::initialize(const SparseMatrix &A, const AdditionalData &data)
+  {
+    this->additional_data = data;
+
+    this->initialize(A);
+  }
+
+
   void
   SolverDirect::solve(MPI::Vector &x, const MPI::Vector &b)
+  {
+    this->vmult(x, b);
+  }
+
+
+
+  void
+  SolverDirect::solve(
+    dealii::LinearAlgebra::distributed::Vector<double>       &x,
+    const dealii::LinearAlgebra::distributed::Vector<double> &b)
+  {
+    this->vmult(x, b);
+  }
+
+
+  void
+  SolverDirect::vmult(MPI::Vector &x, const MPI::Vector &b) const
   {
     // Assign the empty LHS vector to the Epetra_LinearProblem object
     linear_problem->SetLHS(&x.trilinos_vector());
@@ -725,9 +759,9 @@ namespace TrilinosWrappers
 
 
   void
-  SolverDirect::solve(
+  SolverDirect::vmult(
     dealii::LinearAlgebra::distributed::Vector<double>       &x,
-    const dealii::LinearAlgebra::distributed::Vector<double> &b)
+    const dealii::LinearAlgebra::distributed::Vector<double> &b) const
   {
     Epetra_Vector ep_x(View,
                        linear_problem->GetOperator()->OperatorDomainMap(),

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.