Debian Codegraph @

packages/muelu/test/unit_tests/Smoothers/IfpackSmoother.cpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #include "Teuchos_UnitTestHarness.hpp"
11 #include "MueLu_TestHelpers.hpp"
12 #include "MueLu_TestHelpersSmoothers.hpp"
13
14 #include "MueLu_IfpackSmoother.hpp"
15
16 /*
17 Comments about tests with hard coded results:
18 1) Chebyshev smoothing must pass for any number of processors.
19 2) Gauss-Seidel must pass for 1 and 4 processors.
20 3) For any processor count except 1 and 4, the Gauss-Seidel test will
21 report "passing", but this is only because the Teuchos test macro is skipped.
22 */
23
24 namespace MueLuTests {
25
26 typedef double Scalar;
27 typedef int LocalOrdinal;
28 typedef int GlobalOrdinal;
29 typedef Xpetra::EpetraNode Node;
30 #include "MueLu_UseShortNames.hpp"
31
32 // this namespace already has: #include "MueLu_UseShortNames.hpp"
33 using namespace TestHelpers::Smoothers;
34
35 TEUCHOS_UNIT_TEST(IfpackSmoother, NotSetup) {
36 MUELU_TEST_ONLY_FOR(Xpetra::UseEpetra) {
37 IfpackSmoother smoother("point relaxation stand-alone", Teuchos::ParameterList());
38 testApplyNoSetup(smoother, out, success);
39 }
40 }
41
42 // Tests interface to Ifpack's Gauss-Seidel preconditioner.
43 TEUCHOS_UNIT_TEST(IfpackSmoother, HardCodedResult_GaussSeidel1) {
44 MUELU_TEST_ONLY_FOR(Xpetra::UseEpetra) {
45 RCP<const Teuchos::Comm<int> > comm = TestHelpers::Parameters::getDefaultComm();
46
47 Teuchos::ParameterList paramList;
48 paramList.set("relaxation: type", "Gauss-Seidel");
49 paramList.set("relaxation: sweeps", (int)1);
50 paramList.set("relaxation: damping factor", (double)1.0);
51 paramList.set("relaxation: zero starting solution", false);
52
53 IfpackSmoother smoother("point relaxation stand-alone", paramList);
54
55 Teuchos::ScalarTraits<SC>::magnitudeType residualNorms = testApply_A125_X1_RHS0(smoother, out, success);
56
57 switch (comm->getSize()) {
58 case 1:
59 case 4:
60 TEST_FLOATING_EQUALITY(residualNorms, 5.773502691896257e-01, 1e-12);
61 break;
62 default:
63 out << "Pass/Fail is checked only for 1 and 4 processes." << std::endl;
64 break;
65 } // switch
66 }
67 }
68
69 // Tests interface to Ifpack's Gauss-Seidel preconditioner.
70 TEUCHOS_UNIT_TEST(IfpackSmoother, HardCodedResult_GaussSeidel2) {
71 MUELU_TEST_ONLY_FOR(Xpetra::UseEpetra) {
72 RCP<const Teuchos::Comm<int> > comm = TestHelpers::Parameters::getDefaultComm();
73
74 Teuchos::ParameterList paramList;
75 paramList.set("relaxation: type", "Gauss-Seidel");
76 paramList.set("relaxation: sweeps", (int)10);
77 paramList.set("relaxation: damping factor", (double)1.0);
78 paramList.set("relaxation: zero starting solution", false);
79
80 IfpackSmoother smoother("point relaxation stand-alone", paramList);
81
82 Teuchos::ScalarTraits<SC>::magnitudeType residualNorms = testApply_A125_X1_RHS0(smoother, out, success);
83
84 switch (comm->getSize()) {
85 case 1:
86 TEST_FLOATING_EQUALITY(residualNorms, 8.326553652741774e-02, 1e-12);
87 break;
88 case 4:
89 TEST_FLOATING_EQUALITY(residualNorms, 8.326553653078517e-02, 1e-12);
90 break;
91 default:
92 out << "Pass/Fail is checked only for 1 and 4 processes." << std::endl;
93 break;
94
95 } // switch
96 }
97 } // GaussSeidel
98
99 // Tests interface to Ifpack's Chebyshev preconditioner.
100 TEUCHOS_UNIT_TEST(IfpackSmoother, HardCodedResult_Chebyshev) {
101 MUELU_TEST_ONLY_FOR(Xpetra::UseEpetra) {
102 // TODO This test should really calculate the reduction analytically.
103
104 Teuchos::ParameterList paramList;
105 paramList.set("chebyshev: degree", (int)3);
106 paramList.set("chebyshev: max eigenvalue", (double)1.98476);
107 paramList.set("chebyshev: min eigenvalue", (double)1.0);
108 paramList.set("chebyshev: ratio eigenvalue", (double)20);
109 paramList.set("chebyshev: zero starting solution", false);
110
111 IfpackSmoother smoother("Chebyshev", paramList);
112
113 Teuchos::ScalarTraits<SC>::magnitudeType residualNorms = testApply_A125_X1_RHS0(smoother, out, success);
114
115 TEST_FLOATING_EQUALITY(residualNorms, 5.269156e-01, 1e-7); // Compare to residual reported by ML
116 }
117 } // Chebyshev
118
119 // Tests interface to Ifpack's ILU(0) preconditioner.
120 TEUCHOS_UNIT_TEST(IfpackSmoother, HardCodedResult_ILU) {
121 MUELU_TEST_ONLY_FOR(Xpetra::UseEpetra) {
122 // FIXME this will probably fail in parallel b/c it becomes block Jacobi
123
124 IfpackSmoother smoother("ILU", Teuchos::ParameterList());
125
126 Teuchos::ScalarTraits<SC>::magnitudeType residualNorms = testApply_A125_X0_RandomRHS(smoother, out, success);
127
128 RCP<const Teuchos::Comm<int> > comm = TestHelpers::Parameters::getDefaultComm();
129 if (comm->getSize() == 1) {
130 TEST_EQUALITY(residualNorms < 1e-10, true);
131 } else {
132 out << "Pass/Fail is only checked in serial." << std::endl;
133 }
134 }
135 } // ILU
136
137 } // namespace MueLuTests
138
139 // TODO: test if 10 its of ifpack == 10 apply call
140 // TODO: TEST_EQUALITY(smoother->GetNIts(),10);
141 // TODO: check failed if TPETRA