source: src/unittests/LinkedCellUnitTest.cpp@ 4c1230

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 4c1230 was af2c424, checked in by Frederik Heber <heber@…>, 14 years ago

LinkedCell constructor rewritten.

  • had to introduce getValue(iterator) to: molecule, tesselation, LinkedCell::LinkedNodes
  • LinkedCell::LinkedNodes is not a typedef anymore
  • new class LinkedCell::LinkedNodes derived from stl::list<TesselPoint *> to add getValue(iterator).
  • LinkedCell constructors changed:
    • use template for all classes that have begin(), end() and ... sigh ... getValue()
    • Argh! STL containers do all have begin() and end() but no consistent operator* (maps return pair<> ...)
    • specialized version for PointCloud derivatives
    • various functions had to be changed due to changed signature of LinkedCell constructor
  • Property mode set to 100644
File size: 12.2 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * LinkedCellUnitTest.cpp
10 *
11 * Created on: Apr 9, 2010
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 <iostream>
27#include <stdio.h>
28#include <cstring>
29
30#include "atom.hpp"
31#include "element.hpp"
32#include "linkedcell.hpp"
33#include "molecule.hpp"
34#include "periodentafel.hpp"
35#include "LinkedCellUnitTest.hpp"
36#include "World.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( LinkedCellTest );
46
47
48void LinkedCellTest::setUp()
49{
50 atom *Walker = NULL;
51
52 // construct element
53 hydrogen = World::getInstance().getPeriode()->FindElement(1);
54 CPPUNIT_ASSERT(hydrogen != NULL && "could not find element hydrogen");
55
56 // construct molecule (water molecule)
57 TestMolecule = World::getInstance().createMolecule();
58 CPPUNIT_ASSERT(TestMolecule != NULL && "could not create molecule");
59 for (double x=0.5;x<3;x+=1.)
60 for (double y=0.5;y<3;y+=1.)
61 for (double z=0.5;z<3;z+=1.) {
62 Walker = World::getInstance().createAtom();
63 CPPUNIT_ASSERT(Walker != NULL && "could not create atom");
64 Walker->setType(hydrogen);
65 Walker->setPosition(Vector(x, y, z ));
66 TestMolecule->AddAtom(Walker);
67 }
68
69 // construct linked cell
70 LC = new LinkedCell (*TestMolecule, 1.);
71 CPPUNIT_ASSERT(LC != NULL && "could not create LinkedCell");
72
73 // check that TestMolecule was correctly constructed
74 CPPUNIT_ASSERT_EQUAL( TestMolecule->getAtomCount(), 3*3*3 );
75};
76
77
78void LinkedCellTest::tearDown()
79{
80 delete(LC);
81 World::purgeInstance();
82};
83
84
85/** UnitTest for LinkedCell::CheckBounds().
86 */
87void LinkedCellTest::CheckBoundsTest()
88{
89 // check for within bounds
90 LC->n[0] = LC->n[1] = LC->n[2] = 0;
91 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
92 LC->n[0] = LC->n[1] = LC->n[2] = 1;
93 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
94 LC->n[0] = LC->n[1] = LC->n[2] = 2;
95 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
96
97 // check for out of bounds
98 cout << "The following test is supposed to fail and produce an ERROR." << endl;
99 LC->n[0] = 404040;
100 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
101 cout << "The following test is supposed to fail and produce an ERROR." << endl;
102 LC->n[0] = 0;
103 LC->n[1] = 5000;
104 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
105 cout << "The following test is supposed to fail and produce an ERROR." << endl;
106 LC->n[1] = 0;
107 LC->n[2] = -70;
108 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
109 cout << "The following test is supposed to fail and produce an ERROR." << endl;
110 LC->n[0] = LC->n[1] = LC->n[2] = 3;
111 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
112};
113
114
115/** UnitTest for LinkedCell::GetCurrentCell().
116 * Note that CheckBounds() is used and has to be tested already.
117 */
118void LinkedCellTest::GetCurrentCellTest()
119{
120 // within bounds
121 LC->n[0] = LC->n[1] = LC->n[2] = 0;
122 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0 * 3*3 + 0 * 3 + 0], LC->GetCurrentCell() );
123 LC->n[0] = LC->n[1] = LC->n[2] = 1;
124 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[1 * 3*3 + 1 * 3 + 1], LC->GetCurrentCell() );
125 LC->n[0] = LC->n[1] = LC->n[2] = 2;
126 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[2 * 3*3 + 2 * 3 + 2], LC->GetCurrentCell() );
127
128 // out of bounds
129 LC->n[0] = LC->n[1] = LC->n[2] = 3;
130 cout << "The following test is supposed to fail and produce an ERROR." << endl;
131 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetCurrentCell() );
132 LC->n[0] = LC->n[1] = LC->n[2] = -1;
133 cout << "The following test is supposed to fail and produce an ERROR." << endl;
134 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetCurrentCell() );
135};
136
137/** UnitTest for LinkedCell::GetRelativeToCurrentCell().
138 */
139void LinkedCellTest::GetRelativeToCurrentCellTest()
140{
141 int offset[3];
142
143 // offset to (0,0,0) always
144 offset[0] = offset[1] = offset[2] = 0;
145 LC->n[0] = LC->n[1] = LC->n[2] = 0;
146 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
147 offset[0] = offset[1] = offset[2] = -1;
148 LC->n[0] = LC->n[1] = LC->n[2] = 1;
149 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
150 offset[0] = offset[1] = offset[2] = -2;
151 LC->n[0] = LC->n[1] = LC->n[2] = 2;
152 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
153
154 // offset to (0,0,0) - 1.*(x/y/z) out of bounds
155 offset[0] = offset[1] = offset[2] = 0;
156 offset[0] = -1;
157 LC->n[0] = LC->n[1] = LC->n[2] = 0;
158 cout << "The following test is supposed to fail and produce an ERROR." << endl;
159 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
160 offset[0] = offset[1] = offset[2] = 0;
161 offset[1] = -1;
162 LC->n[0] = LC->n[1] = LC->n[2] = 0;
163 cout << "The following test is supposed to fail and produce an ERROR." << endl;
164 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
165 offset[0] = offset[1] = offset[2] = 0;
166 offset[2] = -1;
167 LC->n[0] = LC->n[1] = LC->n[2] = 0;
168 cout << "The following test is supposed to fail and produce an ERROR." << endl;
169 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
170
171 // out of bounds
172 offset[0] = offset[1] = offset[2] = -5054932;
173 LC->n[0] = LC->n[1] = LC->n[2] = 1;
174 cout << "The following test is supposed to fail and produce an ERROR." << endl;
175 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
176 offset[0] = offset[1] = offset[2] = 192345;
177 LC->n[0] = LC->n[1] = LC->n[2] = 1;
178 cout << "The following test is supposed to fail and produce an ERROR." << endl;
179 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
180
181 // index is out of bounds, offset points within
182 offset[0] = offset[1] = offset[2] = -2;
183 LC->n[0] = LC->n[1] = LC->n[2] = 4;
184 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[2 * 3*3 + 2 * 3 + 2], LC->GetRelativeToCurrentCell(offset) );
185
186 // index is within bounds, offset points out
187 offset[0] = offset[1] = offset[2] = 2;
188 LC->n[0] = LC->n[1] = LC->n[2] = 2;
189 cout << "The following test is supposed to fail and produce an ERROR." << endl;
190 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
191};
192
193
194/** UnitTest for LinkedCell::SetIndexToNode().
195 */
196void LinkedCellTest::SetIndexToNodeTest()
197{
198 // check all atoms
199 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end();++iter){
200 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(*iter) );
201 }
202
203 // check internal vectors, returns false, because this atom is not in LC-list!
204 atom *newAtom = World::getInstance().createAtom();
205 newAtom->setName("test");
206 newAtom->setPosition(Vector(1,1,1));
207 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) );
208 World::getInstance().destroyAtom(newAtom);
209
210 // check out of bounds vectors
211 newAtom = World::getInstance().createAtom();
212 newAtom->setName("test");
213 newAtom->setPosition(Vector(0,-1,0));
214 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) );
215 World::getInstance().destroyAtom(newAtom);
216};
217
218
219/** UnitTest for LinkedCell::SetIndexToVector().
220 */
221void LinkedCellTest::SetIndexToVectorTest()
222{
223 Vector tester;
224
225 // check center of each cell
226 for (double x=0.5;x<3;x+=1.)
227 for (double y=0.5;y<3;y+=1.)
228 for (double z=0.5;z<3;z+=1.) {
229 tester = Vector(x,y,z);
230 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(tester) );
231 }
232 // check corners of each cell
233 for (double x=1.;x<4;x+=1.)
234 for (double y=1.;y<4;y+=1.)
235 for (double z=1.;z<4;z+=1.) {
236 tester= Vector(x,y,z);
237 cout << "Tester is at " << tester << "." << endl;
238 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(tester) );
239 }
240 // check out of bounds
241 for (double x=0.5-1e-10;x<5;x+=3.1)
242 for (double y=0.5-1e-10;y<5;y+=3.1)
243 for (double z=0.5-1e-10;z<5;z+=3.1) {
244 tester = Vector(x,y,z);
245 cout << "The following test is supposed to fail and produce an ERROR." << endl;
246 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(tester) );
247 }
248 // check nonsense vectors
249 tester= Vector(-423598,3245978,29349);
250 cout << "The following test is supposed to fail and produce an ERROR." << endl;
251 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(tester) );
252};
253
254
255/** UnitTest for LinkedCell::GetNeighbourBounds().
256 */
257void LinkedCellTest::GetNeighbourBoundsTest()
258{
259 Vector tester;
260 int lower[NDIM], upper[NDIM];
261
262 tester= Vector(0.5,0.5,0.5);
263 LC->SetIndexToVector(tester);
264 LC->GetNeighbourBounds(lower, upper);
265 for (int i=0;i<NDIM;i++)
266 CPPUNIT_ASSERT_EQUAL( 0, lower[i]);
267 for (int i=0;i<NDIM;i++)
268 CPPUNIT_ASSERT_EQUAL( 1, upper[i]);
269};
270
271
272/** UnitTest for LinkedCell::GetallNeighbours().
273 */
274void LinkedCellTest::GetallNeighboursTest()
275{
276 Vector tester;
277 LinkedCell::LinkedNodes *ListOfPoints = NULL;
278 size_t size = 0;
279
280 // get all atoms
281 tester= Vector(1.5,1.5,1.5);
282 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(tester) );
283 ListOfPoints = LC->GetallNeighbours();
284 size = ListOfPoints->size();
285 CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
286
287 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){
288 ListOfPoints->remove((*iter));
289 size--;
290 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
291 }
292 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
293 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
294 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
295 delete(ListOfPoints);
296
297 // get all atoms in one corner
298 tester= Vector(0.5, 0.5, 0.5);
299 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(tester) );
300 ListOfPoints = LC->GetallNeighbours();
301 size=ListOfPoints->size();
302 CPPUNIT_ASSERT_EQUAL( (size_t)8, size );
303 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){
304 if (((*iter)->at(0) <2) && ((*iter)->at(1) <2) && ((*iter)->at(2) <2)) {
305 ListOfPoints->remove(*iter);
306 size--;
307 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
308 }
309 }
310 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
311 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
312 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
313 delete(ListOfPoints);
314
315 // get all atoms from one corner
316 tester = Vector(0.5, 0.5, 0.5);
317 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(tester) );
318 ListOfPoints = LC->GetallNeighbours(3);
319 size=ListOfPoints->size();
320 CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
321 for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){
322 ListOfPoints->remove(*iter);
323 size--;
324 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
325 }
326 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
327 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
328 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
329 delete(ListOfPoints);
330};
331
332
333/** UnitTest for LinkedCell::GetPointsInsideSphere().
334 */
335void LinkedCellTest::GetPointsInsideSphereTest()
336{
337 Vector tester;
338 LinkedCell::LinkedNodes *ListOfPoints = NULL;
339 size_t size = 0;
340
341 // get all points around central arom with radius 1.
342 tester= Vector(1.5,1.5,1.5);
343 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(tester) );
344 ListOfPoints = LC->GetPointsInsideSphere(1., &tester);
345 size = ListOfPoints->size();
346 CPPUNIT_ASSERT_EQUAL( (size_t)7, size );
347 for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){
348 if (((*iter)->DistanceSquared(tester) - 1.) < MYEPSILON ) {
349 ListOfPoints->remove(*iter);
350 size--;
351 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
352 }
353 }
354 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
355 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
356 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
357 delete(ListOfPoints);
358};
Note: See TracBrowser for help on using the repository browser.