source: src/LinkedCell/unittests/LinkedCell_ControllerUnitTest.cpp@ 429069

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 429069 was 0aa122, checked in by Frederik Heber <heber@…>, 13 years ago

Updated all source files's copyright note to current year 2012.

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