source: src/unittests/LinkedCellUnitTest.cpp@ c6efc1

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 c6efc1 was 8cbb97, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'VectorRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Legacy/oldmenu.cpp
molecuilder/src/Makefile.am
molecuilder/src/analysis_correlation.cpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/ellipsoid.cpp
molecuilder/src/linkedcell.cpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/tesselationhelpers.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/vector.cpp
molecuilder/src/vector.hpp

  • Property mode set to 100644
File size: 12.4 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 // init private all pointers to zero
41 TestMolecule = NULL;
42 hydrogen = NULL;
43 tafel = NULL;
44
45 // construct element
46 hydrogen = new element;
47 hydrogen->Z = 1;
48 hydrogen->CovalentRadius = 0.23;
49 strcpy(hydrogen->name, "hydrogen");
50 strcpy(hydrogen->symbol, "H");
51
52 // construct periodentafel
53 tafel = World::getInstance().getPeriode();
54 tafel->AddElement(hydrogen);
55
56 // construct molecule (water molecule)
57 TestMolecule = World::getInstance().createMolecule();
58 for (double x=0.5;x<3;x+=1.)
59 for (double y=0.5;y<3;y+=1.)
60 for (double z=0.5;z<3;z+=1.) {
61 Walker = World::getInstance().createAtom();
62 Walker->type = hydrogen;
63 *Walker->node = Vector(x, y, z );
64 TestMolecule->AddAtom(Walker);
65 }
66
67 // construct linked cell
68 LC = new LinkedCell (TestMolecule, 1.);
69
70 // check that TestMolecule was correctly constructed
71 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 3*3*3 );
72 Walker = TestMolecule->start->next;
73 CPPUNIT_ASSERT( TestMolecule->end != Walker );
74};
75
76
77void LinkedCellTest::tearDown()
78{
79 delete(LC);
80 World::purgeInstance();
81 MemoryUsageObserver::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 atom *Walker = TestMolecule->start;
200 while (Walker->next != TestMolecule->end) {
201 Walker = Walker->next;
202 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(Walker) );
203 }
204
205 // check internal vectors, returns false, because this atom is not in LC-list!
206 Walker = World::getInstance().createAtom();
207 Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker");
208 strcpy(Walker->Name, "test");
209 Walker->x= Vector(1,1,1);
210 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
211 World::getInstance().destroyAtom(Walker);
212
213 // check out of bounds vectors
214 Walker = World::getInstance().createAtom();
215 Walker->Name = Malloc<char>(6, "LinkedCellTest::SetIndexToNodeTest - Walker");
216 strcpy(Walker->Name, "test");
217 Walker->x = Vector(0,-1,0);
218 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(Walker) );
219 World::getInstance().destroyAtom(Walker);
220};
221
222
223/** UnitTest for LinkedCell::SetIndexToVector().
224 */
225void LinkedCellTest::SetIndexToVectorTest()
226{
227 Vector tester;
228
229 // check center of each cell
230 for (double x=0.5;x<3;x+=1.)
231 for (double y=0.5;y<3;y+=1.)
232 for (double z=0.5;z<3;z+=1.) {
233 tester = Vector(x,y,z);
234 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
235 }
236 // check corners of each cell
237 for (double x=1.;x<4;x+=1.)
238 for (double y=1.;y<4;y+=1.)
239 for (double z=1.;z<4;z+=1.) {
240 tester= Vector(x,y,z);
241 cout << "Tester is at " << tester << "." << endl;
242 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
243 }
244 // check out of bounds
245 for (double x=0.5-1e-10;x<5;x+=3.1)
246 for (double y=0.5-1e-10;y<5;y+=3.1)
247 for (double z=0.5-1e-10;z<5;z+=3.1) {
248 tester = Vector(x,y,z);
249 cout << "The following test is supposed to fail and produce an ERROR." << endl;
250 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
251 }
252 // check nonsense vectors
253 tester= Vector(-423598,3245978,29349);
254 cout << "The following test is supposed to fail and produce an ERROR." << endl;
255 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
256};
257
258
259/** UnitTest for LinkedCell::GetNeighbourBounds().
260 */
261void LinkedCellTest::GetNeighbourBoundsTest()
262{
263 Vector tester;
264 int lower[NDIM], upper[NDIM];
265
266 tester= Vector(0.5,0.5,0.5);
267 LC->SetIndexToVector(&tester);
268 LC->GetNeighbourBounds(lower, upper);
269 for (int i=0;i<NDIM;i++)
270 CPPUNIT_ASSERT_EQUAL( 0, lower[i]);
271 for (int i=0;i<NDIM;i++)
272 CPPUNIT_ASSERT_EQUAL( 1, upper[i]);
273};
274
275
276/** UnitTest for LinkedCell::GetallNeighbours().
277 */
278void LinkedCellTest::GetallNeighboursTest()
279{
280 Vector tester;
281 LinkedCell::LinkedNodes *ListOfPoints = NULL;
282 atom *Walker = NULL;
283 size_t size = 0;
284
285 // get all atoms
286 tester= Vector(1.5,1.5,1.5);
287 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
288 ListOfPoints = LC->GetallNeighbours();
289 size = ListOfPoints->size();
290 CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
291 Walker = TestMolecule->start;
292 Walker = TestMolecule->start;
293 while (Walker->next != TestMolecule->end) {
294 Walker = Walker->next;
295 ListOfPoints->remove(Walker);
296 size--;
297 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
298 }
299 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
300 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
301 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
302 delete(ListOfPoints);
303
304 // get all atoms in one corner
305 tester= Vector(0.5, 0.5, 0.5);
306 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
307 ListOfPoints = LC->GetallNeighbours();
308 size=ListOfPoints->size();
309 CPPUNIT_ASSERT_EQUAL( (size_t)8, size );
310 Walker = TestMolecule->start;
311 while (Walker->next != TestMolecule->end) {
312 Walker = Walker->next;
313 if ((Walker->x[0] <2) && (Walker->x[1] <2) && (Walker->x[2] <2)) {
314 ListOfPoints->remove(Walker);
315 size--;
316 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
317 }
318 }
319 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
320 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
321 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
322 delete(ListOfPoints);
323
324 // get all atoms from one corner
325 tester = Vector(0.5, 0.5, 0.5);
326 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
327 ListOfPoints = LC->GetallNeighbours(3);
328 size=ListOfPoints->size();
329 CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
330 Walker = TestMolecule->start;
331 while (Walker->next != TestMolecule->end) {
332 Walker = Walker->next;
333 ListOfPoints->remove(Walker);
334 size--;
335 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
336 }
337 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
338 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
339 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
340 delete(ListOfPoints);
341};
342
343
344/** UnitTest for LinkedCell::GetPointsInsideSphere().
345 */
346void LinkedCellTest::GetPointsInsideSphereTest()
347{
348 Vector tester;
349 LinkedCell::LinkedNodes *ListOfPoints = NULL;
350 atom *Walker = NULL;
351 size_t size = 0;
352
353 // get all points around central arom with radius 1.
354 tester= Vector(1.5,1.5,1.5);
355 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
356 ListOfPoints = LC->GetPointsInsideSphere(1., &tester);
357 size = ListOfPoints->size();
358 CPPUNIT_ASSERT_EQUAL( (size_t)7, size );
359 Walker = TestMolecule->start;
360 while (Walker->next != TestMolecule->end) {
361 Walker = Walker->next;
362 if ((Walker->x.DistanceSquared(tester) - 1.) < MYEPSILON ) {
363 ListOfPoints->remove(Walker);
364 size--;
365 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
366 }
367 }
368 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
369 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
370 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
371 delete(ListOfPoints);
372};
Note: See TracBrowser for help on using the repository browser.