From 3e8d601e959f1d20858f36d9b4310f18a5a4533d Mon Sep 17 00:00:00 2001
From: Christoph Grueninger <christoph.grueninger@iws.uni-stuttgart.de>
Date: Thu, 17 Jul 2014 12:02:06 +0000
Subject: [PATCH] Add UMFPack to test stokes2cni.

It is 10% faster in the test.
We have to investigate to use UMFPack more.
(reviewed by bernd)


git-svn-id: svn://svn.iws.uni-stuttgart.de/DUMUX/dumux/trunk@13068 2fb0f335-1f38-0410-981e-8018bf24f1b0
---
 dumux/linear/seqsolverbackend.hh              | 59 ++++++++++++++++++-
 test/freeflow/stokes2cni/CMakeLists.txt       |  1 +
 .../stokes2cni/stokes2cnitestproblem.hh       |  5 ++
 3 files changed, 64 insertions(+), 1 deletion(-)

diff --git a/dumux/linear/seqsolverbackend.hh b/dumux/linear/seqsolverbackend.hh
index 2e76d856fe..0686c0a5ae 100644
--- a/dumux/linear/seqsolverbackend.hh
+++ b/dumux/linear/seqsolverbackend.hh
@@ -26,6 +26,7 @@
 #include <dune/istl/preconditioners.hh>
 #include <dune/istl/solvers.hh>
 #include <dune/istl/superlu.hh>
+#include <dune/istl/umfpack.hh>
 
 #include <dumux/common/parameters.hh>
 #include <dumux/common/basicproperties.hh>
@@ -587,7 +588,63 @@ private:
   Dune::InverseOperatorResult result_;
   const Problem& problem_;
 };
-#endif
+#endif // HAVE_SUPERLU
+
+
+
+#if HAVE_UMFPACK
+template <class TypeTag>
+class UMFPackBackend
+{
+  typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
+
+public:
+
+  UMFPackBackend(const Problem& problem)
+  : problem_(problem)
+  {}
+
+  template<class Matrix, class Vector>
+  bool solve(const Matrix& A, Vector& x, const Vector& b)
+  {
+    Vector bTmp(b);
+
+    typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
+    enum {blockSize = GET_PROP_VALUE(TypeTag, LinearSolverBlockSize)};
+    typedef typename Dune::FieldMatrix<Scalar, blockSize, blockSize> MatrixBlock;
+    typedef typename Dune::BCRSMatrix<MatrixBlock> ISTLMatrix;
+
+    int verbosity = GET_PARAM_FROM_GROUP(TypeTag, int, LinearSolver, Verbosity);
+    Dune::UMFPack<ISTLMatrix> solver(A, verbosity > 0);
+
+    solver.apply(x, bTmp, result_);
+
+    int size = x.size();
+    for (int i = 0; i < size; i++)
+    {
+        for (int j = 0; j < blockSize; j++)
+        {
+            if (std::isnan(x[i][j]) || std::isinf(x[i][j]))
+            {
+                result_.converged = false;
+                break;
+            }
+        }
+    }
+
+    return result_.converged;
+  }
+
+  const Dune::InverseOperatorResult& result() const
+  {
+    return result_;
+  }
+
+private:
+  Dune::InverseOperatorResult result_;
+  const Problem& problem_;
+};
+#endif // HAVE_UMFPACK
 
 }
 #endif
diff --git a/test/freeflow/stokes2cni/CMakeLists.txt b/test/freeflow/stokes2cni/CMakeLists.txt
index 6997547274..d3372c0947 100644
--- a/test/freeflow/stokes2cni/CMakeLists.txt
+++ b/test/freeflow/stokes2cni/CMakeLists.txt
@@ -7,3 +7,4 @@ add_dumux_test(test_stokes2cni test_stokes2cni test_stokes2cni.cc
   -ParameterFile ${CMAKE_CURRENT_SOURCE_DIR}/test_stokes2cni.input
   -Grid.File ${CMAKE_CURRENT_SOURCE_DIR}/grids/test_stokes2cni.dgf)
 add_dune_superlu_flags(test_stokes2cni)
+add_dune_umfpack_flags(test_stokes2cni)
diff --git a/test/freeflow/stokes2cni/stokes2cnitestproblem.hh b/test/freeflow/stokes2cni/stokes2cnitestproblem.hh
index 8959eba3c5..f41b440807 100644
--- a/test/freeflow/stokes2cni/stokes2cnitestproblem.hh
+++ b/test/freeflow/stokes2cni/stokes2cnitestproblem.hh
@@ -28,6 +28,7 @@
 #if HAVE_PARDISO
 #include <dumux/linear/pardisobackend.hh>
 #endif
+#include <dumux/linear/seqsolverbackend.hh>
 
 #include <dumux/material/fluidsystems/h2oairfluidsystem.hh>
 #include <dumux/freeflow/stokesncni/stokesncnimodel.hh>
@@ -58,6 +59,10 @@ SET_PROP(Stokes2cniTestProblem, FluidSystem)
     typedef Dumux::FluidSystems::H2OAir<Scalar> type;
 };
 
+#if HAVE_UMFPACK
+SET_TYPE_PROP(Stokes2cniTestProblem, LinearSolver, UMFPackBackend<TypeTag>);
+#endif
+
 //! Scalar is set to type long double for higher accuracy
 //SET_TYPE_PROP(Stokes2cniTestProblem, Scalar, long double);
 
-- 
GitLab