source: src/LinkedCell/unittests/LinkedCell_ModelUnitTest.cpp@ c80643

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

Extracted defines for unit tests and placed into extra header file for re-use.

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2011 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_ModelUnitTest.cpp
10 *
11 * Created on: Nov 17, 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 <list>
27
28#include "Box.hpp"
29#include "CodePatterns/Assert.hpp"
30#include "CodePatterns/Log.hpp"
31#include "LinearAlgebra/RealSpaceMatrix.hpp"
32#include "LinkedCell/LinkedCell.hpp"
33#include "LinkedCell/LinkedCell_Model.hpp"
34#include "LinkedCell/PointCloudAdaptor.hpp"
35#include "LinkedCell/unittests/defs.hpp"
36
37#include "LinkedCell_ModelUnitTest.hpp"
38
39#ifdef HAVE_TESTRUNNER
40#include "UnitTestMain.hpp"
41#endif /*HAVE_TESTRUNNER*/
42
43/********************************************** Test classes **************************************/
44
45// Registers the fixture into the 'registry'
46CPPUNIT_TEST_SUITE_REGISTRATION( LinkedCell_ModelTest );
47
48
49void LinkedCell_ModelTest::setUp()
50{
51 // failing asserts should be thrown
52 ASSERT_DO(Assert::Throw);
53
54 setVerbosity(3);
55
56 // create diag(20.) matrix
57 RealSpaceMatrix BoxM;
58 BoxM.setIdentity();
59 BoxM *= DOMAINLENGTH;
60
61 // create Box with this matrix
62 domain = new Box(BoxM);
63
64 // create LinkedCell structure with this Box
65 LC = new LinkedCell::LinkedCell_Model(EDGELENGTH, *domain);
66
67 // create a list of nodes and add to LCImpl
68 std::vector< Vector > VectorList;
69 for (size_t i=0;i<((size_t)floor(NUMBERCELLS));++i)
70 VectorList.push_back(Vector((double)i*EDGELENGTH,(double)i*EDGELENGTH,(double)i*EDGELENGTH));
71 for (size_t i=0;i<VectorList.size();++i) {
72 TesselPoint * Walker = new TesselPoint();
73 Walker->setName(std::string("Walker")+toString(i));
74 Walker->setPosition(VectorList[i]);
75 NodeList.insert(Walker);
76 }
77}
78
79
80void LinkedCell_ModelTest::tearDown()
81{
82 delete LC;
83 delete domain;
84
85 // remove all nodes again
86 for (PointSet::iterator iter = NodeList.begin();
87 !NodeList.empty();
88 iter = NodeList.begin()) {
89 delete *iter;
90 NodeList.erase(iter);
91 }
92}
93
94/** UnitTest for correct construction
95 */
96void LinkedCell_ModelTest::AllocationTest()
97{
98 // check that first cell is allocated
99 LinkedCell::tripleIndex index;
100 index[0] = index[1] = index[2] = 0;
101 CPPUNIT_ASSERT(LC->N(index) != NULL);
102
103 // check that very last cell is allocated
104 index[0] = index[1] = index[2] = (size_t)floor(NUMBERCELLS)-1;
105 CPPUNIT_ASSERT(LC->N(index) != NULL);
106
107}
108
109/** UnitTest for getSize()
110 */
111void LinkedCell_ModelTest::getSizeTest()
112{
113 // check getSize()
114 for(size_t i=0; i<NDIM; ++i)
115 CPPUNIT_ASSERT_EQUAL((LinkedCell::LinkedCellArray::index)floor(NUMBERCELLS), LC->getSize(i));
116#ifndef NDEBUG
117 std::cout << "The following assertion is intended and is not a failure of the code." << std::endl;
118 CPPUNIT_ASSERT_THROW( LC->getSize(4), Assert::AssertionFailure);
119#endif
120}
121
122/** UnitTest for Reset()
123 */
124void LinkedCell_ModelTest::ResetTest()
125{
126 LC->Reset();
127
128 for(size_t i=0; i<NDIM; ++i)
129 CPPUNIT_ASSERT_EQUAL((LinkedCell::LinkedCellArray::index)0, LC->getSize(i));
130}
131
132
133/** UnitTest for insertPointCloud()
134 */
135void LinkedCell_ModelTest::insertPointCloudTest()
136{
137
138 // create the linked cell structure
139 PointCloudAdaptor< PointSet > cloud(&NodeList, std::string("NodeList"));
140 LC->insertPointCloud(cloud);
141
142 // test structure
143 CPPUNIT_ASSERT_EQUAL(((size_t)floor(NUMBERCELLS)), LC->CellLookup.size());
144 LinkedCell::tripleIndex index;
145 for (size_t i=0;i<((size_t)floor(NUMBERCELLS));++i) {
146 index[0] = index[1] = index[2] = i;
147 // assert that in the destined cell we have one Walker
148 CPPUNIT_ASSERT_EQUAL((size_t)1, LC->N(index)->size());
149 }
150 index[0] = 9;
151 index[1] = index[2] = 0;
152 // assert that in the destined cell we have one Walker
153 CPPUNIT_ASSERT_EQUAL((size_t)0, LC->N(index)->size());
154
155}
156
157/** UnitTest for insertPointCloud()
158 */
159void LinkedCell_ModelTest::setPartitionTest()
160{
161 RealSpaceMatrix Pmatrix = LC->Partition;
162 RealSpaceMatrix Dmatrix = LC->Dimensions;
163
164 LC->Reset();
165
166 LC->setPartition(2.*EDGELENGTH);
167
168 Pmatrix *= 0.5;
169 Dmatrix *= 0.5;
170
171 CPPUNIT_ASSERT_EQUAL(Pmatrix, LC->Partition);
172 CPPUNIT_ASSERT_EQUAL(Dmatrix, LC->Dimensions);
173}
174
175/** UnitTest for insertPointCloud()
176 */
177void LinkedCell_ModelTest::getStepTest()
178{
179 // zero distance
180 LinkedCell::tripleIndex index = LC->getStep(0.);
181 for (size_t i = 0; i<NDIM; ++i)
182 CPPUNIT_ASSERT( (size_t)0 == index[i]);
183 // check all possible shells on boundary
184 for (double length = EDGELENGTH; length < DOMAINLENGTH; length+=EDGELENGTH) {
185 LinkedCell::tripleIndex index = LC->getStep(length);
186 for (size_t i = 0; i<NDIM; ++i) {
187 std::cout << (size_t)(length/EDGELENGTH) << " ==" << index[i] << std::endl;
188 CPPUNIT_ASSERT( (LinkedCell::LinkedCellArray::index)(length/EDGELENGTH) == index[i]);
189 }
190 }
191 // check all possible shells at half interval
192 for (double length = 0.5 * EDGELENGTH; length < DOMAINLENGTH; length+=EDGELENGTH) {
193 LinkedCell::tripleIndex index = LC->getStep(length);
194 for (size_t i = 0; i<NDIM; ++i)
195 CPPUNIT_ASSERT( (LinkedCell::LinkedCellArray::index)ceil(length/EDGELENGTH) == index[i]);
196 }
197}
198
199/** UnitTest for insertPointCloud()
200 */
201void LinkedCell_ModelTest::getIndexToVectorTest()
202{
203 {
204 const Vector test(0.,0.,0.);
205 const LinkedCell::tripleIndex index = LC->getIndexToVector(test);
206 for (size_t i = 0; i<NDIM; ++i)
207 CPPUNIT_ASSERT( (size_t)0 == index[i]);
208 }
209 {
210 const Vector test(DOMAINLENGTH/2.,DOMAINLENGTH/2.,DOMAINLENGTH/2.);
211 const LinkedCell::tripleIndex index = LC->getIndexToVector(test);
212 for (size_t i = 0; i<NDIM; ++i)
213 CPPUNIT_ASSERT( (size_t)floor(DOMAINLENGTH/EDGELENGTH/2.) == index[i]);
214 }
215 {
216 const Vector test(DOMAINLENGTH/2.,DOMAINLENGTH/3.,DOMAINLENGTH/4.);
217 const LinkedCell::tripleIndex index = LC->getIndexToVector(test);
218 for (size_t i = 0; i<NDIM; ++i)
219 CPPUNIT_ASSERT( (LinkedCell::LinkedCellArray::index)floor(DOMAINLENGTH/EDGELENGTH/(double)(i+2.)) == index[i]);
220 }
221}
222
223/** UnitTest for insertPointCloud()
224 */
225void LinkedCell_ModelTest::nodeTest()
226{
227 // create point
228 TesselPoint * Walker = new TesselPoint();
229 Walker->setName(std::string("Walker9"));
230 Walker->setPosition(Vector(9.8,7.6,5.4));
231 PointCloudAdaptor< PointSet > cloud(&NodeList, std::string("NodeList"));
232 LC->insertPointCloud(cloud);
233
234 // check addNode
235 LC->addNode(Walker);
236 CPPUNIT_ASSERT_EQUAL( NodeList.size()+1, LC->CellLookup.size());
237 LinkedCell::tripleIndex index1 = LC->getIndexToVector(Walker->getPosition());
238 const LinkedCell::tripleIndex &index2 = LC->CellLookup[Walker]->getIndices();
239 CPPUNIT_ASSERT(index1 == index2);
240
241 // check moveNode
242#ifndef NDEBUG
243 std::cout << "The following assertion is intended and is not a failure of the code." << std::endl;
244 CPPUNIT_ASSERT_THROW( LC->moveNode(Walker), Assert::AssertionFailure );
245#endif
246
247 // check deleteNode
248 LC->deleteNode(Walker);
249 CPPUNIT_ASSERT_EQUAL( NodeList.size(), LC->CellLookup.size());
250
251 delete Walker;
252}
Note: See TracBrowser for help on using the repository browser.