| 1 | /*
|
|---|
| 2 | * smoother_test.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: 20.09.2010
|
|---|
| 5 | * Author: Julian Iseringhausen
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifdef HAVE_CONFIG_H
|
|---|
| 9 | #include <config.h>
|
|---|
| 10 | #endif
|
|---|
| 11 |
|
|---|
| 12 | #include "comm/comm_serial.hpp"
|
|---|
| 13 | #include "interface/interface.hpp"
|
|---|
| 14 | #include "samples/discretization_poisson_fd.hpp"
|
|---|
| 15 | #include "smoother/gs.hpp"
|
|---|
| 16 | #include "smoother/gsrb.hpp"
|
|---|
| 17 | #include "mg.hpp"
|
|---|
| 18 |
|
|---|
| 19 | #include "interface_sinus.hpp"
|
|---|
| 20 | #include "smoother_test.hpp"
|
|---|
| 21 |
|
|---|
| 22 | using namespace VMG;
|
|---|
| 23 | using VMGTests::SmootherTestSuite;
|
|---|
| 24 |
|
|---|
| 25 | CPPUNIT_TEST_SUITE_REGISTRATION(SmootherTestSuite);
|
|---|
| 26 |
|
|---|
| 27 | void SmootherTestSuite::setUp()
|
|---|
| 28 | {
|
|---|
| 29 | Boundary boundary(Dirichlet, Dirichlet, Dirichlet);
|
|---|
| 30 |
|
|---|
| 31 | Comm* comm = new CommSerial(boundary);
|
|---|
| 32 | comm->Register("COMM");
|
|---|
| 33 |
|
|---|
| 34 | Discretization* discretization = new DiscretizationPoissonFD();
|
|---|
| 35 | discretization->Register("DISCRETIZATION");
|
|---|
| 36 |
|
|---|
| 37 | Interface* interface = new VMGInterfaces::InterfaceSinus(boundary, 4, 4, 0.0, 1.0);
|
|---|
| 38 | MG::SetInterface(interface, comm);
|
|---|
| 39 |
|
|---|
| 40 | interface->ImportRightHandSide(*MG::GetRhs());
|
|---|
| 41 |
|
|---|
| 42 | gs = new GaussSeidel();
|
|---|
| 43 | gsrb = new GaussSeidelRB();
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | void SmootherTestSuite::tearDown()
|
|---|
| 47 | {
|
|---|
| 48 | MG::Destroy();
|
|---|
| 49 |
|
|---|
| 50 | delete gs;
|
|---|
| 51 | delete gsrb;
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | void SmootherTestSuite::GaussSeidelLEXTest()
|
|---|
| 55 | {
|
|---|
| 56 | double norm;
|
|---|
| 57 | Multigrid& sol = *MG::GetSol();
|
|---|
| 58 | Multigrid& rhs = *MG::GetRhs();
|
|---|
| 59 | Comm& comm = *MG::GetComm();
|
|---|
| 60 |
|
|---|
| 61 | sol.ClearAll();
|
|---|
| 62 |
|
|---|
| 63 | for (int i=0; i<20; ++i) {
|
|---|
| 64 |
|
|---|
| 65 | gs->Run(sol, rhs, 50);
|
|---|
| 66 | norm = comm.ComputeResidualNorm(sol, rhs);
|
|---|
| 67 |
|
|---|
| 68 | if (norm < 1e-10)
|
|---|
| 69 | break;
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Gauss-Seidel LEX smoother does not converge.", 0.0, norm, 1e-10);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 | void SmootherTestSuite::GaussSeidelRBTest()
|
|---|
| 77 | {
|
|---|
| 78 | double norm;
|
|---|
| 79 |
|
|---|
| 80 | MG::GetSol()->ClearAll();
|
|---|
| 81 |
|
|---|
| 82 | for (int i=0; i<20; ++i) {
|
|---|
| 83 |
|
|---|
| 84 | gsrb->Run(*MG::GetSol(), *MG::GetRhs(), 50);
|
|---|
| 85 | norm = MG::GetComm()->ComputeResidualNorm(*MG::GetSol(), *MG::GetRhs());
|
|---|
| 86 |
|
|---|
| 87 | if (norm < 1e-10)
|
|---|
| 88 | break;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Gauss Seidel RB smoother does not converge.", 0.0, norm, 1e-10);
|
|---|
| 92 | }
|
|---|