| 1 | /*
|
|---|
| 2 | * dirichlet_fas_lr.cpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: 25.01.2011
|
|---|
| 5 | * Author: Julian Iseringhausen
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifdef HAVE_CONFIG_H
|
|---|
| 9 | #include <config.h>
|
|---|
| 10 | #endif
|
|---|
| 11 |
|
|---|
| 12 | #include <boost/test/unit_test.hpp>
|
|---|
| 13 | #include <boost/test/floating_point_comparison.hpp>
|
|---|
| 14 |
|
|---|
| 15 | #include "base/factory.hpp"
|
|---|
| 16 | #include "base/math.hpp"
|
|---|
| 17 | #include "base/vector.hpp"
|
|---|
| 18 | #include "comm/comm_serial.hpp"
|
|---|
| 19 | #include "level/level_operator_fas.hpp"
|
|---|
| 20 | #include "level/level_operator.hpp"
|
|---|
| 21 | #include "samples/discretization_poisson_fv.hpp"
|
|---|
| 22 | #include "samples/techniques.hpp"
|
|---|
| 23 | #include "smoother/gsrb.hpp"
|
|---|
| 24 | #ifdef HAVE_LAPACK
|
|---|
| 25 | #include "solver/dgesv.hpp"
|
|---|
| 26 | #endif
|
|---|
| 27 | #include "solver/givens.hpp"
|
|---|
| 28 | #include "solver/solver_regular.hpp"
|
|---|
| 29 | #include "mg.hpp"
|
|---|
| 30 |
|
|---|
| 31 | #include "interface_sinus.hpp"
|
|---|
| 32 |
|
|---|
| 33 | using namespace VMG;
|
|---|
| 34 |
|
|---|
| 35 | const vmg_float sine_factor = static_cast<vmg_float>(2.0 * Math::pi);
|
|---|
| 36 |
|
|---|
| 37 | struct LibraryDirichletFASLRFixture
|
|---|
| 38 | {
|
|---|
| 39 | LibraryDirichletFASLRFixture()
|
|---|
| 40 | {
|
|---|
| 41 | Factory& factory = MG::GetFactory();
|
|---|
| 42 |
|
|---|
| 43 | Comm *comm = new CommSerial(Boundary(Dirichlet, Dirichlet, Dirichlet));
|
|---|
| 44 | comm->Register("COMM");
|
|---|
| 45 |
|
|---|
| 46 | Interface* interface = new VMGInterfaces::InterfaceSinus(sine_factor, comm->BoundaryConditions(), 2, 6, 0.0, 1.0, 2, 1.6);
|
|---|
| 47 | MG::SetInterface(interface, comm);
|
|---|
| 48 |
|
|---|
| 49 | Discretization* discretization = new DiscretizationPoissonFV(2);
|
|---|
| 50 | discretization->Register("DISCRETIZATION");
|
|---|
| 51 |
|
|---|
| 52 | LevelOperator* lop = new LevelOperatorFAS(Stencils::RestrictionFullWeight, Stencils::Injection, Stencils::InterpolationTrilinear);
|
|---|
| 53 | lop->Register("LEVEL_OPERATOR");
|
|---|
| 54 |
|
|---|
| 55 | Smoother* smoother = new GaussSeidelRB();
|
|---|
| 56 | smoother->Register("SMOOTHER");
|
|---|
| 57 |
|
|---|
| 58 | #ifdef HAVE_LAPACK
|
|---|
| 59 | Solver* solver = new DGESV<SolverRegular>();
|
|---|
| 60 | #else
|
|---|
| 61 | Solver* solver = new Givens<SolverRegular>();
|
|---|
| 62 | #endif
|
|---|
| 63 |
|
|---|
| 64 | solver->Register("SOLVER");
|
|---|
| 65 |
|
|---|
| 66 | Techniques::SetFullApproximationSchemeDirichlet(interface->MinLevel(), interface->MaxLevel(), 2);
|
|---|
| 67 |
|
|---|
| 68 | factory.RegisterObjectStorage("PRESMOOTHSTEPS", 3);
|
|---|
| 69 | factory.RegisterObjectStorage("POSTSMOOTHSTEPS", 3);
|
|---|
| 70 | factory.RegisterObjectStorage("PRECISION", 1e-10);
|
|---|
| 71 | factory.RegisterObjectStorage("MAX_ITERATION", 8);
|
|---|
| 72 |
|
|---|
| 73 | MG::IsInitialized();
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | ~LibraryDirichletFASLRFixture()
|
|---|
| 77 | {
|
|---|
| 78 | MG::Destroy();
|
|---|
| 79 | }
|
|---|
| 80 | };
|
|---|
| 81 |
|
|---|
| 82 | BOOST_FIXTURE_TEST_CASE(LibraryDirichletFASLRTest, LibraryDirichletFASLRFixture)
|
|---|
| 83 | {
|
|---|
| 84 | MG::Solve();
|
|---|
| 85 |
|
|---|
| 86 | double res_init = MG::GetFactory().Get("INITIAL_RESIDUAL")->Cast< ObjectStorage<double> >()->Val();
|
|---|
| 87 | double res = MG::GetComm()->ComputeResidualNorm(*MG::GetSol(), *MG::GetRhs());
|
|---|
| 88 |
|
|---|
| 89 | BOOST_CHECK_SMALL(res/res_init, 1e-10);
|
|---|
| 90 | }
|
|---|