source: test/unit_test/library/force_sinus.cpp@ 0260d3

Last change on this file since 0260d3 was 0260d3, checked in by Julian Iseringhausen <isering@…>, 13 years ago

vmg: Removed debug output from test suite.

git-svn-id: https://svn.version.fz-juelich.de/scafacos/trunk@1901 5161e1c8-67bf-11de-9fd5-51895aff932f

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * vmg - a versatile multigrid solver
3 * Copyright (C) 2012 Institute for Numerical Simulation, University of Bonn
4 *
5 * vmg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * vmg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/*
20 * force_sinus.cpp
21 *
22 * Created on: 13.06.2012
23 * Author: Julian Iseringhausen
24 */
25
26#ifdef HAVE_CONFIG_H
27#include <config.h>
28#endif
29
30#include <boost/test/unit_test.hpp>
31#include <boost/test/floating_point_comparison.hpp>
32
33#ifdef HAVE_MPI
34#include <mpi.h>
35#ifdef HAVE_MARMOT
36#include <enhancempicalls.h>
37#include <sourceinfompicalls.h>
38#endif
39
40#include <cmath>
41#include <iostream>
42
43#include "base/factory.hpp"
44#include "base/math.hpp"
45#include "base/vector.hpp"
46#include "comm/comm_mpi.hpp"
47#include "comm/domain_decomposition_mpi.hpp"
48#include "level/level_operator_cs.hpp"
49#include "level/level_operator.hpp"
50#include "samples/discretization_poisson_fd.hpp"
51#include "samples/techniques.hpp"
52#include "smoother/gsrb.hpp"
53#include "solver/givens.hpp"
54#include "solver/solver_singular.hpp"
55#include "units/particle/interpolation.hpp"
56#include "units/particle/particle.hpp"
57#include "mg.hpp"
58
59#include "interface_sinus.hpp"
60
61using namespace VMG;
62
63const vmg_float sine_factor = static_cast<vmg_float>(2.0 * Math::pi);
64
65struct LibraryForceSinusFixture
66{
67 LibraryForceSinusFixture()
68 {
69 Factory& factory = MG::GetFactory();
70
71 Comm* comm = new CommMPI(Boundary(Periodic, Periodic, Periodic), new DomainDecompositionMPI());
72 Interface* interface = new VMGInterfaces::InterfaceSinus(sine_factor, comm->BoundaryConditions(), 2, 6, 0.0, 1.0);
73 Discretization* discretization = new DiscretizationPoissonFD(2);
74 LevelOperator* lop = new LevelOperatorCS(Stencils::RestrictionFullWeight, Stencils::InterpolationTrilinear);
75 Smoother* smoother = new GaussSeidelRB();
76 Solver* solver = new Givens<SolverSingular>();
77
78 comm->Register("COMM");
79 interface->Register("INTERFACE");
80 discretization->Register("DISCRETIZATION");
81 lop->Register("LEVEL_OPERATOR");
82 smoother->Register("SMOOTHER");
83 solver->Register("SOLVER");
84
85 Techniques::SetCorrectionSchemePeriodic(interface->MinLevel(), interface->MaxLevel(), 2);
86
87 factory.RegisterObjectStorage("PRESMOOTHSTEPS", 3);
88 factory.RegisterObjectStorage("POSTSMOOTHSTEPS", 3);
89 factory.RegisterObjectStorage("PRECISION", 1e-10);
90 factory.RegisterObjectStorage("MAX_ITERATION", 7);
91
92 MG::PostInit();
93
94 MG::IsInitialized();
95 }
96
97 ~LibraryForceSinusFixture()
98 {
99 MG::Destroy();
100 }
101};
102
103BOOST_FIXTURE_TEST_CASE(LibraryForceSinusTest, LibraryForceSinusFixture)
104{
105 Particle::Interpolation ip(5);
106 Particle::Particle p;
107 Vector pos;
108
109 MG::Solve();
110
111 const Grid& sol = (*MG::GetSol())(MG::GetSol()->MaxLevel());
112
113 for (pos.X()=0.25; pos.X()<=0.75; pos.X()+=0.01)
114 for (pos.Y()=0.25; pos.Y()<=0.75; pos.Y()+=0.01)
115 for (pos.Z()=0.25; pos.Z()<=0.75; pos.Z()+=0.01) {
116
117 p.Pos() = pos;
118
119 const Index index = (p.Pos()-sol.Extent().Begin())/sol.Extent().MeshWidth()-sol.Global().LocalBegin()+sol.Local().Begin();
120
121 ip.ComputeCoefficients(sol, index);
122 ip.Evaluate(p);
123
124 Vector ref = Vector(std::cos(sine_factor*p.Pos().X())*std::sin(sine_factor*p.Pos().Y())*std::sin(sine_factor*p.Pos().Z()),
125 std::sin(sine_factor*p.Pos().X())*std::cos(sine_factor*p.Pos().Y())*std::sin(sine_factor*p.Pos().Z()),
126 std::sin(sine_factor*p.Pos().X())*std::sin(sine_factor*p.Pos().Y())*std::cos(sine_factor*p.Pos().Z()));
127 ref *= -1.0 * sine_factor;
128
129 for (int i=0; i<3; ++i)
130 BOOST_CHECK_SMALL(p.Field()[i] - ref[i], 0.01);
131
132 }
133}
134
135#endif /* HAVE_MPI */
Note: See TracBrowser for help on using the repository browser.