1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2016 Frederik Heber. All rights reserved.
|
---|
5 | *
|
---|
6 | *
|
---|
7 | * This file is part of MoleCuilder.
|
---|
8 | *
|
---|
9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
10 | * it under the terms of the GNU General Public License as published by
|
---|
11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
12 | * (at your option) any later version.
|
---|
13 | *
|
---|
14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
17 | * GNU General Public License for more details.
|
---|
18 | *
|
---|
19 | * You should have received a copy of the GNU General Public License
|
---|
20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /*
|
---|
24 | * ExportGraph_ToJobsUnitTest.cpp
|
---|
25 | *
|
---|
26 | * Created on: Mar 10, 2016
|
---|
27 | * Author: heber
|
---|
28 | */
|
---|
29 |
|
---|
30 | // include config.h
|
---|
31 | #ifdef HAVE_CONFIG_H
|
---|
32 | #include <config.h>
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | using namespace std;
|
---|
36 |
|
---|
37 | #include <cppunit/CompilerOutputter.h>
|
---|
38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
40 |
|
---|
41 | #include "ExportGraph_ToJobsUnitTest.hpp"
|
---|
42 |
|
---|
43 | #include <limits>
|
---|
44 | #include <vector>
|
---|
45 |
|
---|
46 | #include <boost/assign.hpp>
|
---|
47 |
|
---|
48 | #include "CodePatterns/Assert.hpp"
|
---|
49 |
|
---|
50 | #include "Fragmentation/Exporters/ExportGraph_ToJobs.hpp"
|
---|
51 | #include "World.hpp"
|
---|
52 |
|
---|
53 | #ifdef HAVE_TESTRUNNER
|
---|
54 | #include "UnitTestMain.hpp"
|
---|
55 | #endif /*HAVE_TESTRUNNER*/
|
---|
56 |
|
---|
57 | /********************************************** Test classes **************************************/
|
---|
58 |
|
---|
59 | // Registers the fixture into the 'registry'
|
---|
60 | CPPUNIT_TEST_SUITE_REGISTRATION( ExportGraph_ToJobsTest );
|
---|
61 |
|
---|
62 |
|
---|
63 | void ExportGraph_ToJobsTest::setUp()
|
---|
64 | {
|
---|
65 | // failing asserts should be thrown
|
---|
66 | ASSERT_DO(Assert::Throw);
|
---|
67 |
|
---|
68 | // setVerbosity(6);
|
---|
69 | }
|
---|
70 |
|
---|
71 |
|
---|
72 | void ExportGraph_ToJobsTest::tearDown()
|
---|
73 | {
|
---|
74 | World::purgeInstance();
|
---|
75 | }
|
---|
76 |
|
---|
77 | /** UnitTest for getGridExtentsForGivenBoundingBox().
|
---|
78 | */
|
---|
79 | void ExportGraph_ToJobsTest::getGridExtentsForGivenBoundingBox_Test()
|
---|
80 | {
|
---|
81 | double begin[NDIM] = { 0., 0., 0. };
|
---|
82 | double end[NDIM] = { 40., 40., 40. };
|
---|
83 | double level = 5;
|
---|
84 | const SamplingGridProperties domain(begin, end, level);
|
---|
85 | double empty_boundary = 5.;
|
---|
86 |
|
---|
87 | std::vector< Vector > fragment_extents =
|
---|
88 | boost::assign::list_of
|
---|
89 | ( Vector( 5.2, 5.2, 5.2) ) // simple test
|
---|
90 | ( Vector( 5., 5., 5.) ); // simple test: higher and lower center is same point
|
---|
91 |
|
---|
92 | const double delta = 2.1;
|
---|
93 | for (std::vector< Vector >::const_iterator iter = fragment_extents.begin();
|
---|
94 | iter != fragment_extents.end(); ++iter)
|
---|
95 | {
|
---|
96 | const Vector &fragment_extent = *iter;
|
---|
97 | for (double x = 0.; x <= end[0]-fragment_extent[0]; x+= delta)
|
---|
98 | for (double y = 0.; y <= end[1]-fragment_extent[1]; y+= delta)
|
---|
99 | for (double z = 0.; z <= end[2]-fragment_extent[2]; z+= delta) {
|
---|
100 | Vector minimum( x, y, z);
|
---|
101 | Vector maximum = minimum+fragment_extent;
|
---|
102 | const SamplingGridProperties grid =
|
---|
103 | ExportGraph_ToJobs::getGridExtentsForGivenBoundingBox(
|
---|
104 | std::make_pair(minimum, maximum), domain, empty_boundary);
|
---|
105 | for (size_t i=0;i<NDIM;++i) {
|
---|
106 | CPPUNIT_ASSERT( grid.begin[i] >= domain.begin[i] );
|
---|
107 | CPPUNIT_ASSERT( grid.end[i] <= domain.end[i] );
|
---|
108 | // check the desired fragment extent plus boundary is contained
|
---|
109 | const double extent = grid.end[i] - grid.begin[i];
|
---|
110 | CPPUNIT_ASSERT (extent > (2.*empty_boundary+fragment_extent[i]));
|
---|
111 | // check the number of grid points of the grid is divisible integer and ...
|
---|
112 | const double delta = domain.getDeltaPerAxis(i); // grid would give a screwed delta that matches
|
---|
113 | const unsigned int gridpoints = extent/delta;
|
---|
114 | CPPUNIT_ASSERT ( fabs( extent/delta - (double)gridpoints) < std::numeric_limits<double>::epsilon()*1e4 );
|
---|
115 | // ... divisible by 2
|
---|
116 | const double power = log(extent/delta)/log(2.);
|
---|
117 | const unsigned int power_of_two = power;
|
---|
118 | CPPUNIT_ASSERT_EQUAL( (int)power_of_two, grid.level );
|
---|
119 | CPPUNIT_ASSERT ( fabs( power - (double)power_of_two) < std::numeric_limits<double>::epsilon()*1e4 );
|
---|
120 | CPPUNIT_ASSERT ( fabs( ::pow(2., power_of_two) - gridpoints) < std::numeric_limits<double>::epsilon()*1e4);
|
---|
121 | // check that fragment grid's begin and end are on domain discrete points
|
---|
122 | const double lower_begin = domain.getNearestLowerGridPoint(grid.begin[i], i);
|
---|
123 | const double higher_begin = domain.getNearestHigherGridPoint(grid.begin[i], i);
|
---|
124 | CPPUNIT_ASSERT( fabs( lower_begin - higher_begin) < std::numeric_limits<double>::epsilon()*1e4 );
|
---|
125 | const double lower_end = domain.getNearestLowerGridPoint(grid.end[i], i);
|
---|
126 | const double higher_end = domain.getNearestHigherGridPoint(grid.end[i], i);
|
---|
127 | CPPUNIT_ASSERT( fabs( lower_end - higher_end) < std::numeric_limits<double>::epsilon()*1e4 );
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|
131 | }
|
---|
132 |
|
---|
133 | /** UnitTest for setAcceptableFragmentLevel().
|
---|
134 | */
|
---|
135 | void ExportGraph_ToJobsTest::setAcceptableFragmentLevel_Test()
|
---|
136 | {
|
---|
137 | double begin[NDIM] = { 0., 0., 0. };
|
---|
138 | double end[NDIM] = { 20., 20., 20. };
|
---|
139 | double level = 5;
|
---|
140 |
|
---|
141 | const double min_meshwidth = 20./::pow(2., level);
|
---|
142 | const unsigned int threshold_level = 9;
|
---|
143 | const double threshold = 20./::pow(2., threshold_level);
|
---|
144 | const double delta = 0.05;
|
---|
145 |
|
---|
146 | unsigned int oldlevel=0;
|
---|
147 | for (double max_meshwidth = min_meshwidth+1.; max_meshwidth >= threshold; max_meshwidth -= delta) {
|
---|
148 | SamplingGridProperties domain(begin, end, level);
|
---|
149 | ExportGraph_ToJobs::setAcceptableFragmentLevel(domain, max_meshwidth);
|
---|
150 | // must always be larger equal to old value
|
---|
151 | CPPUNIT_ASSERT( (unsigned int)domain.level >= oldlevel );
|
---|
152 | oldlevel = domain.level;
|
---|
153 | // may never get smaller than minimal value
|
---|
154 | CPPUNIT_ASSERT( (unsigned int)domain.level >= 1 );
|
---|
155 | // cannot get larger than upper most level
|
---|
156 | CPPUNIT_ASSERT( (unsigned int)domain.level <= threshold_level );
|
---|
157 | }
|
---|
158 | }
|
---|