source: src/LinkedCell/unittests/LinkedCell_ControllerUnitTest.cpp@ 53d894

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 53d894 was c80643, checked in by Frederik Heber <heber@…>, 13 years ago

LinkedCell_Controller::getView() now needs a PointCloud set.

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