source: src/LinkedCell/unittests/LinkedCell_ModelUnitTest.cpp@ 8c31865

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

Added new class LinkedCellArrayCache that performs the lazy updates on a LinkedCellArray.

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