]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add MGCoarseGridApplyOperator 12663/head
authorPeter Munch <peterrmuench@gmail.com>
Tue, 17 Aug 2021 06:28:17 +0000 (08:28 +0200)
committerPeter Munch <peterrmuench@gmail.com>
Mon, 7 Oct 2024 15:27:06 +0000 (17:27 +0200)
include/deal.II/multigrid/mg_coarse.h
tests/multigrid/mg_coarse_01.cc
tests/multigrid/mg_coarse_01.with_p4est=true.with_trilinos=true.mpirun=1.output
tests/multigrid/mg_coarse_01.with_p4est=true.with_trilinos=true.mpirun=3.output

index b9d98289ba28e2a2552b6ed594c93a2b1725618e..0a847c41ba73264b5dee876ea12ae4cd3644d527 100644 (file)
@@ -80,6 +80,55 @@ private:
 
 
 
+/**
+ * Coarse grid solver using an operator, e.g., preconditioner, only.
+ * This is a little wrapper, transforming an operator into a coarse grid solver.
+ */
+template <class VectorType, class MatrixType>
+class MGCoarseGridApplyOperator : public MGCoarseGridBase<VectorType>
+{
+public:
+  /**
+   * Default constructor.
+   */
+  MGCoarseGridApplyOperator();
+
+  /**
+   * Constructor. Store a pointer to the operator for later use.
+   */
+  MGCoarseGridApplyOperator(const MatrixType &matrix);
+
+  /**
+   * Clear the pointer.
+   */
+  void
+  clear();
+
+  /**
+   * Initialize new data.
+   */
+  void
+  initialize(const MatrixType &matrix);
+
+  /**
+   * Implementation of the abstract function.
+   */
+  virtual void
+  operator()(const unsigned int level,
+             VectorType        &dst,
+             const VectorType  &src) const override;
+
+private:
+  /**
+   * Reference to the operator.
+   */
+  ObserverPointer<const MatrixType,
+                  MGCoarseGridApplyOperator<VectorType, MatrixType>>
+    matrix;
+};
+
+
+
 /**
  * Coarse grid multigrid operator for an iterative solver.
  *
@@ -284,6 +333,54 @@ MGCoarseGridApplySmoother<VectorType>::operator()(const unsigned int level,
   coarse_smooth->apply(level, dst, src);
 }
 
+/* ------------------ Functions for MGCoarseGridApplyOperator ----------*/
+
+template <class VectorType, class PreconditionerType>
+MGCoarseGridApplyOperator<VectorType,
+                          PreconditionerType>::MGCoarseGridApplyOperator()
+  : matrix(0, typeid(*this).name())
+{}
+
+
+
+template <class VectorType, class PreconditionerType>
+MGCoarseGridApplyOperator<VectorType, PreconditionerType>::
+  MGCoarseGridApplyOperator(const PreconditionerType &matrix)
+  : matrix(&matrix, typeid(*this).name())
+{}
+
+
+
+template <class VectorType, class PreconditionerType>
+void
+MGCoarseGridApplyOperator<VectorType, PreconditionerType>::initialize(
+  const PreconditionerType &matrix_)
+{
+  matrix = &matrix_;
+}
+
+
+
+template <class VectorType, class PreconditionerType>
+void
+MGCoarseGridApplyOperator<VectorType, PreconditionerType>::clear()
+{
+  matrix = 0;
+}
+
+
+template <class VectorType, class PreconditionerType>
+void
+MGCoarseGridApplyOperator<VectorType, PreconditionerType>::operator()(
+  const unsigned int /*level*/,
+  VectorType       &dst,
+  const VectorType &src) const
+{
+  Assert(matrix != nullptr, ExcNotInitialized());
+
+  matrix->vmult(dst, src);
+}
+
 /* ------------------ Functions for MGCoarseGridIterativeSolver ------------ */
 
 template <typename VectorType,
index add169691902cc3ee5f15f10f460c83d3a334cab..bbf5a5385b98deaf0db90a5be9f8e2033c09409f 100644 (file)
@@ -555,6 +555,20 @@ namespace Step50
               << std::endl;
     }
 
+    {
+      deallog << "AMG:" << std::endl;
+
+      LA::MPI::PreconditionAMG prec;
+      prec.initialize(coarse_matrix);
+
+      MGCoarseGridApplyOperator<vector_t, LA::MPI::PreconditionAMG>
+        coarse_grid_solver(prec);
+
+      vcycle(coarse_grid_solver);
+      deallog << "coarse iterations: " << coarse_solver_control.last_step()
+              << std::endl;
+    }
+
     {
       deallog << "AMG:" << std::endl;
       LA::MPI::PreconditionAMG::AdditionalData Amg_data;
index 80c6792b3989baf1967b4307c82d769d82825e6c..cdd60bddcabbf9465658055102ebb45ea0703476 100644 (file)
@@ -21,6 +21,11 @@ DEAL::AMG:
 DEAL::check residual: 0.0231622
 DEAL::check residual: 0.0192417
 DEAL::check residual: 0.0172953
+DEAL::coarse iterations: 1
+DEAL::AMG:
+DEAL::check residual: 0.0231622
+DEAL::check residual: 0.0192417
+DEAL::check residual: 0.0172953
 DEAL::applications: 3
 DEAL::Cycle 1:
 DEAL::   Number of active cells:       484
@@ -44,6 +49,11 @@ DEAL::AMG:
 DEAL::check residual: 0.0126770
 DEAL::check residual: 0.0105349
 DEAL::check residual: 0.00947063
+DEAL::coarse iterations: 1
+DEAL::AMG:
+DEAL::check residual: 0.0126770
+DEAL::check residual: 0.0105349
+DEAL::check residual: 0.00947063
 DEAL::applications: 3
 DEAL::Cycle 2:
 DEAL::   Number of active cells:       1024
@@ -64,6 +74,11 @@ DEAL::check residual: 0.00725329
 DEAL::check residual: 0.00652099
 DEAL::coarse iterations: 22
 DEAL::AMG:
+DEAL::check residual: 0.0125665
+DEAL::check residual: 0.0140128
+DEAL::check residual: 0.0147028
+DEAL::coarse iterations: 22
+DEAL::AMG:
 DEAL::check residual: 0.0114120
 DEAL::check residual: 0.0128120
 DEAL::check residual: 0.0135811
index 2e0aadb5ffcf27308312e2069a3c728ad430cfd4..4a5f2456481178983f30aed937cfafc525d11af9 100644 (file)
@@ -21,6 +21,11 @@ DEAL::AMG:
 DEAL::check residual: 0.0231622
 DEAL::check residual: 0.0192417
 DEAL::check residual: 0.0172953
+DEAL::coarse iterations: 1
+DEAL::AMG:
+DEAL::check residual: 0.0231622
+DEAL::check residual: 0.0192417
+DEAL::check residual: 0.0172953
 DEAL::applications: 3
 DEAL::Cycle 1:
 DEAL::   Number of active cells:       484
@@ -44,6 +49,11 @@ DEAL::AMG:
 DEAL::check residual: 0.0126770
 DEAL::check residual: 0.0105349
 DEAL::check residual: 0.00947063
+DEAL::coarse iterations: 1
+DEAL::AMG:
+DEAL::check residual: 0.0126770
+DEAL::check residual: 0.0105349
+DEAL::check residual: 0.00947063
 DEAL::applications: 3
 DEAL::Cycle 2:
 DEAL::   Number of active cells:       1024
@@ -64,6 +74,11 @@ DEAL::check residual: 0.00725329
 DEAL::check residual: 0.00652099
 DEAL::coarse iterations: 20
 DEAL::AMG:
+DEAL::check residual: 0.0121261
+DEAL::check residual: 0.0132637
+DEAL::check residual: 0.0138558
+DEAL::coarse iterations: 20
+DEAL::AMG:
 DEAL::check residual: 0.0115344
 DEAL::check residual: 0.0130870
 DEAL::check residual: 0.0139614

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.