source: src/LinkedCell/unittests/LinkedCell_ViewUnitTest.cpp@ ce81e76

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

LinkedCell_Controller now signs on to Channel WorldTime::TimeChanged.

  • we need to know when WorldTime changes because then all atomic positions change. we might use some more elaborate method here but for the moment we just use the method which is also employed in case of Box::MatrixChanged.
  • renamed LinkedCell_Controller::updateModelsForNewBoxMatrix() -> ::updateModels().
  • Property mode set to 100644
File size: 7.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 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_ViewUnitTest.cpp
10 *
11 * Created on: Nov 18, 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 <algorithm>
27#include <list>
28
29#include "Box.hpp"
30#include "CodePatterns/Assert.hpp"
31#include "CodePatterns/Log.hpp"
32#include "LinearAlgebra/defs.hpp"
33#include "LinearAlgebra/RealSpaceMatrix.hpp"
34#include "LinkedCell/LinkedCell.hpp"
35#include "LinkedCell/LinkedCell_Model.hpp"
36#include "LinkedCell/LinkedCell_View.hpp"
37#include "LinkedCell/PointCloudAdaptor.hpp"
38#include "LinkedCell/unittests/defs.hpp"
39#include "World.hpp"
40#include "WorldTime.hpp"
41
42#include "LinkedCell_ViewUnitTest.hpp"
43
44#ifdef HAVE_TESTRUNNER
45#include "UnitTestMain.hpp"
46#endif /*HAVE_TESTRUNNER*/
47
48/********************************************** Test classes **************************************/
49
50// Registers the fixture into the 'registry'
51CPPUNIT_TEST_SUITE_REGISTRATION( LinkedCell_ViewTest );
52
53
54void LinkedCell_ViewTest::setUp()
55{
56 // failing asserts should be thrown
57 ASSERT_DO(Assert::Throw);
58
59 //setVerbosity(3);
60
61 // create diag(20.) matrix
62 RealSpaceMatrix BoxM;
63 BoxM.setIdentity();
64 BoxM *= 20.;
65
66 // create Box with this matrix
67 domain = new Box(BoxM);
68
69 // create LinkedCell structure with this Box
70 LCImpl = new LinkedCell::LinkedCell_Model(EDGELENGTH, *domain);
71
72 // create a list of nodes and add to LCImpl
73 std::vector< Vector > VectorList;
74 for (size_t i=0;i<((size_t)floor(NUMBERCELLS));++i)
75 VectorList.push_back(Vector((double)i*EDGELENGTH,(double)i*EDGELENGTH,(double)i*EDGELENGTH));
76 for (size_t i=0;i<VectorList.size();++i) {
77 TesselPoint * Walker = new TesselPoint();
78 Walker->setName(std::string("Walker")+toString(i));
79 Walker->setPosition(VectorList[i]);
80 NodeList.insert(Walker);
81 LCImpl->addNode(Walker);
82 }
83
84 // create LinkedCell_View from that
85 LC = new LinkedCell::LinkedCell_View(*LCImpl);
86}
87
88
89void LinkedCell_ViewTest::tearDown()
90{
91 delete LC;
92 delete LCImpl;
93 delete domain;
94
95 // remove all nodes again
96 for (PointSet::iterator iter = NodeList.begin();
97 !NodeList.empty();
98 iter = NodeList.begin()) {
99 delete *iter;
100 NodeList.erase(iter);
101 }
102
103 // delete in correct order
104 World::purgeInstance();
105 WorldTime::purgeInstance();
106}
107
108
109/** UnitTest for getAllNeighbors()
110 */
111void LinkedCell_ViewTest::getAllNeighborsTest()
112{
113 // define some center vector
114 Vector center(DOMAINLENGTH/2.,DOMAINLENGTH/2.,DOMAINLENGTH/2.);
115
116 // get LinkedList from LC
117 const double distance = 2.;
118 LinkedCell::LinkedList NeighborList = LC->getAllNeighbors(distance, center);
119// for (LinkedCell::LinkedList::const_iterator iter = NeighborList.begin();
120// iter != NeighborList.end(); ++iter)
121// std::cout << **iter << " is in returned neighbor list." << std::endl;
122
123 // gather points from NodeList
124 LinkedCell::LinkedList ComparisonList;
125 for (PointSet::const_iterator iter = NodeList.begin(); iter != NodeList.end(); ++iter)
126 if (center.DistanceSquared((*iter)->getPosition()) <= distance*distance) {
127 ComparisonList.insert(*iter);
128 //std::cout << **iter << " is inside of " << center << " plus " << distance << "." << std::endl;
129 }
130 // check that we get at least as many as needed
131 CPPUNIT_ASSERT(ComparisonList.size() <= NeighborList.size());
132
133 // check element-wise and skip unrequired ones
134 LinkedCell::LinkedList::iterator iter1 = ComparisonList.begin();
135 LinkedCell::LinkedList::iterator iter2 = NeighborList.begin();
136 for(;(iter1 != ComparisonList.end()) && (iter2 != NeighborList.end()); ++iter1, ++iter2) {
137 while (*iter1 != *iter2) {
138 CPPUNIT_ASSERT( iter2 != NeighborList.end() );
139 ++iter2;
140 }
141 //std::cout << **iter1 << " == " << **iter2 << std::endl;
142 CPPUNIT_ASSERT( iter2 != NeighborList.end() );
143 }
144}
145
146/** UnitTest for getPointsInsideSphere()
147 */
148void LinkedCell_ViewTest::getPointsInsideSphereTest()
149{
150 // define some center vector
151 Vector center(DOMAINLENGTH/2.,DOMAINLENGTH/2.,DOMAINLENGTH/2.);
152
153 // get LinkedList from LC
154 const double distance = 3.;
155 LinkedCell::LinkedList NeighborList = LC->getPointsInsideSphere(distance, center);
156// for (LinkedCell::LinkedList::const_iterator iter = NeighborList.begin();
157// iter != NeighborList.end(); ++iter)
158// std::cout << **iter << " is in returned restricted neighbor list." << std::endl;
159
160 // gather points from NodeList
161 LinkedCell::LinkedList ComparisonList;
162 for (PointSet::const_iterator iter = NodeList.begin(); iter != NodeList.end(); ++iter)
163 if (center.DistanceSquared((*iter)->getPosition()) <= distance*distance) {
164 ComparisonList.insert(*iter);
165 //std::cout << **iter << " is inside of " << center << " plus " << distance << "." << std::endl;
166 }
167 // check that we get at least as many as needed
168 CPPUNIT_ASSERT(ComparisonList.size() == NeighborList.size());
169
170 // check element-wise and skip unrequired ones
171 LinkedCell::LinkedList::iterator iter1 = ComparisonList.begin();
172 LinkedCell::LinkedList::iterator iter2 = NeighborList.begin();
173 for(;(iter1 != ComparisonList.end()) && (iter2 != NeighborList.end()); ++iter1, ++iter2) {
174 //std::cout << **iter1 << " == " << **iter2 << std::endl;
175 CPPUNIT_ASSERT( *iter1 == *iter2 );
176 }
177}
178
179
180LinkedCell::LinkedCell_View returnView(LinkedCell::LinkedCell_View &view)
181{
182 return view;
183}
184
185LinkedCell::LinkedCell_View returnCopiedView(LinkedCell::LinkedCell_View &view)
186{
187 LinkedCell::LinkedCell_View retview(view);
188 return retview;
189}
190
191/** UnitTest on whether counting in RAIIMap works
192 */
193void LinkedCell_ViewTest::RAIIMapTest()
194{
195 CPPUNIT_ASSERT_EQUAL( (size_t)1, LinkedCell::LinkedCell_View::RAIIMap.size() );
196
197 // check that we are present
198 LinkedCell::LinkedCell_View::ModelInstanceMap::iterator iter =
199 LinkedCell::LinkedCell_View::RAIIMap.find(LC);
200 CPPUNIT_ASSERT( iter != LinkedCell::LinkedCell_View::RAIIMap.end() );
201 CPPUNIT_ASSERT( *iter == LC );
202
203 // check that we are the only value present
204 ++iter;
205 CPPUNIT_ASSERT( iter == LinkedCell::LinkedCell_View::RAIIMap.end() );
206
207 // add another view and check that there is not assertion
208 LinkedCell::LinkedCell_View *view = NULL;
209 CPPUNIT_ASSERT_NO_THROW( view = new LinkedCell::LinkedCell_View(*LCImpl) );
210 CPPUNIT_ASSERT_EQUAL( (size_t)2, LinkedCell::LinkedCell_View::RAIIMap.size() );
211 delete view;
212 CPPUNIT_ASSERT_EQUAL( (size_t)1, LinkedCell::LinkedCell_View::RAIIMap.size() );
213
214 // copy current view
215 {
216 LinkedCell::LinkedCell_View view(*LC);
217 CPPUNIT_ASSERT_EQUAL( (size_t)2, LinkedCell::LinkedCell_View::RAIIMap.size() );
218 LinkedCell::LinkedCell_View view2 = *LC;
219 CPPUNIT_ASSERT_EQUAL( (size_t)3, LinkedCell::LinkedCell_View::RAIIMap.size() );
220 }
221 CPPUNIT_ASSERT_EQUAL( (size_t)1, LinkedCell::LinkedCell_View::RAIIMap.size() );
222
223 // with function returning view
224 {
225 LinkedCell::LinkedCell_View view = returnView(*LC);
226 CPPUNIT_ASSERT_EQUAL( (size_t)2, LinkedCell::LinkedCell_View::RAIIMap.size() );
227 }
228 CPPUNIT_ASSERT_EQUAL( (size_t)1, LinkedCell::LinkedCell_View::RAIIMap.size() );
229
230 // with function returning copied view
231 {
232 LinkedCell::LinkedCell_View view = returnCopiedView(*LC);
233 CPPUNIT_ASSERT_EQUAL( (size_t)2, LinkedCell::LinkedCell_View::RAIIMap.size() );
234 }
235 CPPUNIT_ASSERT_EQUAL( (size_t)1, LinkedCell::LinkedCell_View::RAIIMap.size() );
236}
237
Note: See TracBrowser for help on using the repository browser.