source: src/unittests/LinkedCellUnitTest.cpp@ a7b761b

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 Candidate_v1.7.0 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 a7b761b was a7b761b, checked in by Tillmann Crueger <crueger@…>, 16 years ago

Merge branch 'MoleculeStartEndSwitch' into StructureRefactoring

Conflicts:

molecuilder/src/Helpers/Assert.cpp
molecuilder/src/Helpers/Assert.hpp
molecuilder/src/Legacy/oldmenu.cpp
molecuilder/src/Makefile.am
molecuilder/src/Patterns/Cacheable.hpp
molecuilder/src/Patterns/Observer.cpp
molecuilder/src/Patterns/Observer.hpp
molecuilder/src/analysis_correlation.cpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/helpers.hpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule.hpp
molecuilder/src/molecule_dynamics.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/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/ObserverTest.cpp
molecuilder/src/unittests/ObserverTest.hpp

  • Property mode set to 100644
File size: 12.0 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->getAtomCount(), 3*3*3 );
72};
73
74
75void LinkedCellTest::tearDown()
76{
77 delete(LC);
78 World::purgeInstance();
79 MemoryUsageObserver::purgeInstance();
80};
81
82
83/** UnitTest for LinkedCell::CheckBounds().
84 */
85void LinkedCellTest::CheckBoundsTest()
86{
87 // check for within bounds
88 LC->n[0] = LC->n[1] = LC->n[2] = 0;
89 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
90 LC->n[0] = LC->n[1] = LC->n[2] = 1;
91 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
92 LC->n[0] = LC->n[1] = LC->n[2] = 2;
93 CPPUNIT_ASSERT_EQUAL( true, LC->CheckBounds() );
94
95 // check for out of bounds
96 cout << "The following test is supposed to fail and produce an ERROR." << endl;
97 LC->n[0] = 404040;
98 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
99 cout << "The following test is supposed to fail and produce an ERROR." << endl;
100 LC->n[0] = 0;
101 LC->n[1] = 5000;
102 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
103 cout << "The following test is supposed to fail and produce an ERROR." << endl;
104 LC->n[1] = 0;
105 LC->n[2] = -70;
106 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
107 cout << "The following test is supposed to fail and produce an ERROR." << endl;
108 LC->n[0] = LC->n[1] = LC->n[2] = 3;
109 CPPUNIT_ASSERT_EQUAL( false, LC->CheckBounds() );
110};
111
112
113/** UnitTest for LinkedCell::GetCurrentCell().
114 * Note that CheckBounds() is used and has to be tested already.
115 */
116void LinkedCellTest::GetCurrentCellTest()
117{
118 // within bounds
119 LC->n[0] = LC->n[1] = LC->n[2] = 0;
120 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0 * 3*3 + 0 * 3 + 0], LC->GetCurrentCell() );
121 LC->n[0] = LC->n[1] = LC->n[2] = 1;
122 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[1 * 3*3 + 1 * 3 + 1], LC->GetCurrentCell() );
123 LC->n[0] = LC->n[1] = LC->n[2] = 2;
124 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[2 * 3*3 + 2 * 3 + 2], LC->GetCurrentCell() );
125
126 // out of bounds
127 LC->n[0] = LC->n[1] = LC->n[2] = 3;
128 cout << "The following test is supposed to fail and produce an ERROR." << endl;
129 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetCurrentCell() );
130 LC->n[0] = LC->n[1] = LC->n[2] = -1;
131 cout << "The following test is supposed to fail and produce an ERROR." << endl;
132 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetCurrentCell() );
133};
134
135/** UnitTest for LinkedCell::GetRelativeToCurrentCell().
136 */
137void LinkedCellTest::GetRelativeToCurrentCellTest()
138{
139 int offset[3];
140
141 // offset to (0,0,0) always
142 offset[0] = offset[1] = offset[2] = 0;
143 LC->n[0] = LC->n[1] = LC->n[2] = 0;
144 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
145 offset[0] = offset[1] = offset[2] = -1;
146 LC->n[0] = LC->n[1] = LC->n[2] = 1;
147 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
148 offset[0] = offset[1] = offset[2] = -2;
149 LC->n[0] = LC->n[1] = LC->n[2] = 2;
150 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[0], LC->GetRelativeToCurrentCell(offset) );
151
152 // offset to (0,0,0) - 1.*(x/y/z) out of bounds
153 offset[0] = offset[1] = offset[2] = 0;
154 offset[0] = -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 offset[0] = offset[1] = offset[2] = 0;
159 offset[1] = -1;
160 LC->n[0] = LC->n[1] = LC->n[2] = 0;
161 cout << "The following test is supposed to fail and produce an ERROR." << endl;
162 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
163 offset[0] = offset[1] = offset[2] = 0;
164 offset[2] = -1;
165 LC->n[0] = LC->n[1] = LC->n[2] = 0;
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 // out of bounds
170 offset[0] = offset[1] = offset[2] = -5054932;
171 LC->n[0] = LC->n[1] = LC->n[2] = 1;
172 cout << "The following test is supposed to fail and produce an ERROR." << endl;
173 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
174 offset[0] = offset[1] = offset[2] = 192345;
175 LC->n[0] = LC->n[1] = LC->n[2] = 1;
176 cout << "The following test is supposed to fail and produce an ERROR." << endl;
177 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
178
179 // index is out of bounds, offset points within
180 offset[0] = offset[1] = offset[2] = -2;
181 LC->n[0] = LC->n[1] = LC->n[2] = 4;
182 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)&LC->LC[2 * 3*3 + 2 * 3 + 2], LC->GetRelativeToCurrentCell(offset) );
183
184 // index is within bounds, offset points out
185 offset[0] = offset[1] = offset[2] = 2;
186 LC->n[0] = LC->n[1] = LC->n[2] = 2;
187 cout << "The following test is supposed to fail and produce an ERROR." << endl;
188 CPPUNIT_ASSERT_EQUAL( (const LinkedCell::LinkedNodes*)NULL, LC->GetRelativeToCurrentCell(offset) );
189};
190
191
192/** UnitTest for LinkedCell::SetIndexToNode().
193 */
194void LinkedCellTest::SetIndexToNodeTest()
195{
196 // check all atoms
197 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end();++iter){
198 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToNode(*iter) );
199 }
200
201 // check internal vectors, returns false, because this atom is not in LC-list!
202 atom *newAtom = World::getInstance().createAtom();
203 newAtom->setName("test");
204 newAtom->x= Vector(1,1,1);
205 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) );
206 World::getInstance().destroyAtom(newAtom);
207
208 // check out of bounds vectors
209 newAtom = World::getInstance().createAtom();
210 newAtom->setName("test");
211 newAtom->x = Vector(0,-1,0);
212 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToNode(newAtom) );
213 World::getInstance().destroyAtom(newAtom);
214};
215
216
217/** UnitTest for LinkedCell::SetIndexToVector().
218 */
219void LinkedCellTest::SetIndexToVectorTest()
220{
221 Vector tester;
222
223 // check center of each cell
224 for (double x=0.5;x<3;x+=1.)
225 for (double y=0.5;y<3;y+=1.)
226 for (double z=0.5;z<3;z+=1.) {
227 tester = Vector(x,y,z);
228 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
229 }
230 // check corners of each cell
231 for (double x=1.;x<4;x+=1.)
232 for (double y=1.;y<4;y+=1.)
233 for (double z=1.;z<4;z+=1.) {
234 tester= Vector(x,y,z);
235 cout << "Tester is at " << tester << "." << endl;
236 CPPUNIT_ASSERT_EQUAL( true, LC->SetIndexToVector(&tester) );
237 }
238 // check out of bounds
239 for (double x=0.5-1e-10;x<5;x+=3.1)
240 for (double y=0.5-1e-10;y<5;y+=3.1)
241 for (double z=0.5-1e-10;z<5;z+=3.1) {
242 tester = Vector(x,y,z);
243 cout << "The following test is supposed to fail and produce an ERROR." << endl;
244 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
245 }
246 // check nonsense vectors
247 tester= Vector(-423598,3245978,29349);
248 cout << "The following test is supposed to fail and produce an ERROR." << endl;
249 CPPUNIT_ASSERT_EQUAL( false, LC->SetIndexToVector(&tester) );
250};
251
252
253/** UnitTest for LinkedCell::GetNeighbourBounds().
254 */
255void LinkedCellTest::GetNeighbourBoundsTest()
256{
257 Vector tester;
258 int lower[NDIM], upper[NDIM];
259
260 tester= Vector(0.5,0.5,0.5);
261 LC->SetIndexToVector(&tester);
262 LC->GetNeighbourBounds(lower, upper);
263 for (int i=0;i<NDIM;i++)
264 CPPUNIT_ASSERT_EQUAL( 0, lower[i]);
265 for (int i=0;i<NDIM;i++)
266 CPPUNIT_ASSERT_EQUAL( 1, upper[i]);
267};
268
269
270/** UnitTest for LinkedCell::GetallNeighbours().
271 */
272void LinkedCellTest::GetallNeighboursTest()
273{
274 Vector tester;
275 LinkedCell::LinkedNodes *ListOfPoints = NULL;
276 atom *Walker = NULL;
277 size_t size = 0;
278
279 // get all atoms
280 tester= Vector(1.5,1.5,1.5);
281 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
282 ListOfPoints = LC->GetallNeighbours();
283 size = ListOfPoints->size();
284 CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
285
286 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){
287 ListOfPoints->remove((*iter));
288 size--;
289 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
290 }
291 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
292 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
293 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
294 delete(ListOfPoints);
295
296 // get all atoms in one corner
297 tester= Vector(0.5, 0.5, 0.5);
298 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
299 ListOfPoints = LC->GetallNeighbours();
300 size=ListOfPoints->size();
301 CPPUNIT_ASSERT_EQUAL( (size_t)8, size );
302 for(molecule::iterator iter = TestMolecule->begin(); iter != TestMolecule->end(); ++iter){
303 if (((*iter)->x[0] <2) && ((*iter)->x[1] <2) && ((*iter)->x[2] <2)) {
304 ListOfPoints->remove(*iter);
305 size--;
306 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
307 }
308 }
309 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
310 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
311 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
312 delete(ListOfPoints);
313
314 // get all atoms from one corner
315 tester = Vector(0.5, 0.5, 0.5);
316 CPPUNIT_ASSERT_EQUAL ( true, LC->SetIndexToVector(&tester) );
317 ListOfPoints = LC->GetallNeighbours(3);
318 size=ListOfPoints->size();
319 CPPUNIT_ASSERT_EQUAL( (size_t)27, size );
320 for(molecule::iterator iter = TestMolecule->begin(); iter!=TestMolecule->end();++iter){
321 ListOfPoints->remove(*iter);
322 size--;
323 CPPUNIT_ASSERT_EQUAL( size, ListOfPoints->size() );
324 }
325 CPPUNIT_ASSERT_EQUAL( (size_t)0, size );
326 CPPUNIT_ASSERT_EQUAL( (size_t)0, ListOfPoints->size() );
327 CPPUNIT_ASSERT_EQUAL( true, ListOfPoints->empty() );
328 delete(ListOfPoints);
329};
330
331
332/** UnitTest for LinkedCell::GetPointsInsideSphere().
333 */
334void LinkedCellTest::GetPointsInsideSphereTest()
335{
336 Vector tester;
337 LinkedCell::LinkedNodes *ListOfPoints = NULL;
338 atom *Walker = 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)->x.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.