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

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

Added implementation of linked cell model part using LinkedCell.

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