source: src/LinkedCell/unittests/LinkedCell_ControllerUnitTest.cpp@ 4459fc

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 4459fc was fe8253, checked in by Frederik Heber <heber@…>, 13 years ago

Added first reasonable heuristic, and added required implementation for Controller.

  • LinkedCell_Controller::getBestModel() nows contains some more advanced heuristics.
  • extended unit test on all of the added parts.
  • Property mode set to 100644
File size: 8.8 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2011 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * LinkedCell_ControllerUnitTest.cpp
10 *
11 * Created on: Nov 29, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20using namespace std;
21
22#include <cppunit/CompilerOutputter.h>
23#include <cppunit/extensions/TestFactoryRegistry.h>
24#include <cppunit/ui/text/TestRunner.h>
25
26#include "Box.hpp"
27#include "CodePatterns/Assert.hpp"
28#include "LinearAlgebra/RealSpaceMatrix.hpp"
29#include "LinkedCell/LinkedCell_Controller.hpp"
30#include "LinkedCell/LinkedCell_View.hpp"
31#include "LinkedCell/unittests/defs.hpp"
32
33#include "LinkedCell_ControllerUnitTest.hpp"
34
35#ifdef HAVE_TESTRUNNER
36#include "UnitTestMain.hpp"
37#endif /*HAVE_TESTRUNNER*/
38
39/********************************************** Test classes **************************************/
40
41// Registers the fixture into the 'registry'
42CPPUNIT_TEST_SUITE_REGISTRATION( LinkedCell_ControllerTest );
43
44
45void LinkedCell_ControllerTest::setUp()
46{
47 // failing asserts should be thrown
48 ASSERT_DO(Assert::Throw);
49
50 // create diag(20.) matrix
51 BoxM = new RealSpaceMatrix;
52 BoxM->setIdentity();
53 (*BoxM) *= DOMAINLENGTH;
54
55 // create Box with this matrix
56 domain = new Box(*BoxM);
57
58 controller = new LinkedCell::LinkedCell_Controller(*domain);
59}
60
61
62void LinkedCell_ControllerTest::tearDown()
63{
64 delete controller;
65 delete domain;
66}
67
68/** UnitTest for LinkedCell_Controller's lower and upper thresholds.
69 */
70void LinkedCell_ControllerTest::thresholdTest()
71{
72 /// re-create instances
73 delete controller;
74 delete domain;
75
76 /// create diag(..) matrix beyond upper_threshold
77 const double old_threshold = controller->upper_threshold;
78 controller->lower_threshold = old_threshold*0.9;
79 RealSpaceMatrix BoxM;
80 BoxM.setIdentity();
81 BoxM *= controller->upper_threshold*.5;
82
83 /// create Box with this matrix
84 domain = new Box(BoxM);
85
86 controller = new LinkedCell::LinkedCell_Controller(*domain);
87
88 /// check that thresholds have been adapted
89 CPPUNIT_ASSERT( controller->upper_threshold != old_threshold );
90 CPPUNIT_ASSERT( controller->lower_threshold != old_threshold*0.9 );
91}
92
93/** UnitTest for LinkedCell_Controller::getHeuristicRange().
94 */
95void LinkedCell_ControllerTest::getHeuristicRangeTest()
96{
97 /// re-implementing function to check is nonsense here, instead try some
98 /// hard-coded, working values;
99 controller->lower_threshold = 1.;
100 controller->upper_threshold = 20.;
101 const double inbetween = 9.5; // half and twice is definitely within both thresholds.
102
103 /// check distance in between
104 range<double> interval = controller->getHeuristicRange(inbetween);
105 CPPUNIT_ASSERT ( interval.first != controller->lower_threshold );
106 CPPUNIT_ASSERT ( interval.last != controller->upper_threshold );
107}
108
109/** UnitTest for LinkedCell_Controller::getViewTest() for getting twice the same view.
110 */
111void LinkedCell_ControllerTest::getView_SameViewTest()
112{
113 /// obtain a view
114 CPPUNIT_ASSERT_EQUAL( (size_t)0, controller->ModelsMap.size() );
115 LinkedCell::LinkedCell_View view = controller->getView(2.);
116 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
117
118 {
119 /// get same view again and check that now new instance appears
120 LinkedCell::LinkedCell_View view_again = controller->getView(2.);
121 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
122 }
123}
124
125/** UnitTest for LinkedCell_Controller::getViewTest() for picking two different views.
126 */
127void LinkedCell_ControllerTest::getView_DifferentViewTest()
128{
129 /// obtain a view
130 CPPUNIT_ASSERT_EQUAL( (size_t)0, controller->ModelsMap.size() );
131 LinkedCell::LinkedCell_View view = controller->getView(2.);
132 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
133
134 {
135 /// pick another view that is not close enough
136 LinkedCell::LinkedCell_View view_other = controller->getView(5.);
137 CPPUNIT_ASSERT_EQUAL( (size_t)2, controller->ModelsMap.size() );
138 }
139}
140
141/** UnitTest for LinkedCell_Controller::getViewTest() for picking further views in range of present one.
142 */
143void LinkedCell_ControllerTest::getView_InRangeViewTest()
144{
145 /// obtain a view
146 const double edgelength = 2.;
147 CPPUNIT_ASSERT_EQUAL( (size_t)0, controller->ModelsMap.size() );
148 LinkedCell::LinkedCell_View view = controller->getView(edgelength);
149 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
150
151 /// pick views that are close enough
152 range<double> interval = controller->getHeuristicRange(edgelength);
153 {
154 /// ... at half lower interval half
155 LinkedCell::LinkedCell_View view_lowerhalf = controller->getView((edgelength + interval.first)/2.);
156 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
157 }
158 {
159 /// ... at half upper interval half
160 LinkedCell::LinkedCell_View view_upperhalf = controller->getView((interval.last + edgelength)/2.);
161 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
162 }
163 {
164 /// ... close to lower boundary
165 LinkedCell::LinkedCell_View view_closelower = controller->getView(interval.first + std::numeric_limits<double>::round_error());
166 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
167 }
168 {
169 /// ... close to upper boundary
170 LinkedCell::LinkedCell_View view_closerupper = controller->getView(interval.last - std::numeric_limits<double>::round_error());
171 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
172 }
173 {
174 /// on lower boundary
175 LinkedCell::LinkedCell_View view_onlower = controller->getView(interval.first);
176 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
177 }
178}
179
180/** UnitTest for LinkedCell_Controller::getViewTest() for picking further views outside range.
181 */
182void LinkedCell_ControllerTest::getView_OutOfRangeViewTest()
183{
184 /// Here we need half of the edge length to be greater than lower_threshold
185 const double edgelength = 2.5;
186 CPPUNIT_ASSERT( (edgelength/2.) > controller->lower_threshold );
187 /// obtain a view
188 CPPUNIT_ASSERT_EQUAL( (size_t)0, controller->ModelsMap.size() );
189 LinkedCell::LinkedCell_View view = controller->getView(edgelength);
190 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
191
192 /// pick views that are not close enough and check for new instance
193 range<double> interval = controller->getHeuristicRange(edgelength);
194 {
195 /// ... outside lower boundary
196 LinkedCell::LinkedCell_View view_outsidelower = controller->getView(interval.first - std::numeric_limits<double>::round_error());
197 CPPUNIT_ASSERT_EQUAL( (size_t)2, controller->ModelsMap.size() );
198 }
199 {
200 /// ... on upper boundary
201 LinkedCell::LinkedCell_View view_onupper = controller->getView(interval.last);
202 CPPUNIT_ASSERT_EQUAL( (size_t)3, controller->ModelsMap.size() );
203 }
204}
205
206/** UnitTest for LinkedCell_Controller::getViewTest() for picking views beneath lower threshold.
207 */
208void LinkedCell_ControllerTest::getView_LowerThresholdViewTest()
209{
210 /// obtain a view
211 const double edgelength = 1.9*controller->lower_threshold;
212 CPPUNIT_ASSERT_EQUAL( (size_t)0, controller->ModelsMap.size() );
213 LinkedCell::LinkedCell_View view = controller->getView(edgelength);
214 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
215
216 {
217 /// get a view at threshold and check that no new instance has been created
218 LinkedCell::LinkedCell_View view_onlower = controller->getView(controller->lower_threshold);
219 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
220 }
221 {
222 /// pick a view below 1.
223 LinkedCell::LinkedCell_View view_beneathlower = controller->getView(0.1*controller->lower_threshold);
224 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
225 }
226}
227
228/** UnitTest for LinkedCell_Controller::getViewTest() for picking views above upper threshold.
229 */
230void LinkedCell_ControllerTest::getView_UpperThresholdViewTest()
231{
232 /// obtain a view
233 const double edgelength = controller->upper_threshold;
234 CPPUNIT_ASSERT_EQUAL( (size_t)0, controller->ModelsMap.size() );
235 LinkedCell::LinkedCell_View view = controller->getView(edgelength);
236 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
237
238 {
239 /// get a view beyond threshold and check that no new instance has been created
240 LinkedCell::LinkedCell_View view_beyondupper = controller->getView(1.1*controller->upper_threshold);
241 CPPUNIT_ASSERT_EQUAL( (size_t)1, controller->ModelsMap.size() );
242 }
243
244 {
245 /// pick a view below threshold and check for new instance (if we make it outside acceptable range)
246 range<double> interval = controller->getHeuristicRange(edgelength);
247 if ( !interval.isInRange(0.1*controller->upper_threshold) ) {
248 LinkedCell::LinkedCell_View view_beneathupper = controller->getView(0.1*controller->upper_threshold);
249 CPPUNIT_ASSERT_EQUAL( (size_t)2, controller->ModelsMap.size() );
250 }
251 }
252}
Note: See TracBrowser for help on using the repository browser.