source: src/unittests/LinkedCellUnitTest.cpp@ e5c0a1

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 e5c0a1 was 4ac1aa, checked in by Frederik Heber <heber@…>, 15 years ago

Removed two unused variables.

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