source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ a1510d

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 a1510d was a1510d, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Merge branch 'FreddiesRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Patterns/Observer.cpp
molecuilder/src/World.cpp
molecuilder/src/boundary.cpp
molecuilder/src/molecule_dynamics.cpp
molecuilder/src/unittests/AnalysisCorrelationToPointUnitTest.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/AnalysisPairCorrelationUnitTest.cpp
molecuilder/src/unittests/Makefile.am
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/unittests/listofbondsunittest.cpp

  • Property mode set to 100644
File size: 6.4 KB
Line 
1/*
2 * AnalysisCorrelationToSurfaceUnitTest.cpp
3 *
4 * Created on: Oct 13, 2009
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 <cstring>
15
16#include "analysis_correlation.hpp"
17#include "AnalysisCorrelationToSurfaceUnitTest.hpp"
18
19#include "World.hpp"
20#include "atom.hpp"
21#include "boundary.hpp"
22#include "element.hpp"
23#include "molecule.hpp"
24#include "linkedcell.hpp"
25#include "periodentafel.hpp"
26#include "tesselation.hpp"
27#include "World.hpp"
28
29#ifdef HAVE_TESTRUNNER
30#include "UnitTestMain.hpp"
31#endif /*HAVE_TESTRUNNER*/
32
33/********************************************** Test classes **************************************/
34
35// Registers the fixture into the 'registry'
36CPPUNIT_TEST_SUITE_REGISTRATION( AnalysisCorrelationToSurfaceUnitTest );
37
38void AnalysisCorrelationToSurfaceUnitTest::setUp()
39{
40 atom *Walker = NULL;
41
42 // init private all pointers to zero
43 TestList = NULL;
44 TestMolecule = NULL;
45 hydrogen = NULL;
46 tafel = NULL;
47 surfacemap = NULL;
48 binmap = NULL;
49 Surface = NULL;
50 LC = NULL;
51
52 // construct element
53 hydrogen = new element;
54 hydrogen->Z = 1;
55 strcpy(hydrogen->name, "hydrogen");
56 strcpy(hydrogen->symbol, "H");
57 carbon = new element;
58 carbon->Z = 6;
59 strcpy(carbon->name, "carbon");
60 strcpy(carbon->symbol, "C");
61
62 // construct periodentafel
63 tafel = World::get()->getPeriode();
64 tafel->AddElement(hydrogen);
65 tafel->AddElement(carbon);
66
67 // construct molecule (tetraeder of hydrogens) base
68 TestMolecule = World::get()->createMolecule();
69 Walker = World::get()->createAtom();
70 Walker->type = hydrogen;
71 Walker->node->Init(1., 0., 1. );
72 TestMolecule->AddAtom(Walker);
73 Walker = World::get()->createAtom();
74 Walker->type = hydrogen;
75 Walker->node->Init(0., 1., 1. );
76 TestMolecule->AddAtom(Walker);
77 Walker = World::get()->createAtom();
78 Walker->type = hydrogen;
79 Walker->node->Init(1., 1., 0. );
80 TestMolecule->AddAtom(Walker);
81 Walker = World::get()->createAtom();
82 Walker->type = hydrogen;
83 Walker->node->Init(0., 0., 0. );
84 TestMolecule->AddAtom(Walker);
85
86 // check that TestMolecule was correctly constructed
87 CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
88
89 TestList = World::get()->getMolecules();
90 TestMolecule->ActiveFlag = true;
91 TestList->insert(TestMolecule);
92
93 // init tesselation and linked cell
94 Surface = new Tesselation;
95 FindNonConvexBorder(TestMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
96 LC = new LinkedCell(TestMolecule, 5.);
97 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
98 CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
99 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
100
101 // add outer atoms
102 Walker = World::get()->createAtom();
103 Walker->type = carbon;
104 Walker->node->Init(4., 0., 4. );
105 TestMolecule->AddAtom(Walker);
106 Walker = World::get()->createAtom();
107 Walker->type = carbon;
108 Walker->node->Init(0., 4., 4. );
109 TestMolecule->AddAtom(Walker);
110 Walker = World::get()->createAtom();
111 Walker->type = carbon;
112 Walker->node->Init(4., 4., 0. );
113 TestMolecule->AddAtom(Walker);
114 // add inner atoms
115 Walker = World::get()->createAtom();
116 Walker->type = carbon;
117 Walker->node->Init(0.5, 0.5, 0.5 );
118 TestMolecule->AddAtom(Walker);
119
120 // init maps
121 surfacemap = NULL;
122 binmap = NULL;
123
124};
125
126
127void AnalysisCorrelationToSurfaceUnitTest::tearDown()
128{
129 if (surfacemap != NULL)
130 delete(surfacemap);
131 if (binmap != NULL)
132 delete(binmap);
133
134 delete(Surface);
135 // note that all the atoms are cleaned by TestMolecule
136 delete(LC);
137 World::destroy();
138 MemoryUsageObserver::purgeInstance();
139 logger::purgeInstance();
140};
141
142
143void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
144{
145 // do the pair correlation
146 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
147 CPPUNIT_ASSERT( surfacemap != NULL );
148 CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
149};
150
151void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinNoRangeTest()
152{
153 BinPairMap::iterator tester;
154 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
155 // put pair correlation into bins and check with no range
156 binmap = BinData( surfacemap, 0.5, 0., 0. );
157 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
158 //OutputCorrelation ( binmap );
159 tester = binmap->begin();
160 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
161 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
162
163};
164
165void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
166{
167 BinPairMap::iterator tester;
168 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
169 // ... and check with [0., 2.] range
170 binmap = BinData( surfacemap, 0.5, 0., 2. );
171 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
172 //OutputCorrelation ( binmap );
173 tester = binmap->begin();
174 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
175 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
176 tester = binmap->find(1.);
177 CPPUNIT_ASSERT_EQUAL( 1., tester->first );
178 CPPUNIT_ASSERT_EQUAL( 0, tester->second );
179
180};
181
182void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
183{
184 BinPairMap::iterator tester;
185 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
186 // put pair correlation into bins and check with no range
187 binmap = BinData( surfacemap, 0.5, 0., 0. );
188 CPPUNIT_ASSERT_EQUAL( (size_t)2, binmap->size() );
189 OutputCorrelation ( (ofstream *)&cout, binmap );
190 // inside point is first and must have negative value
191 tester = binmap->lower_bound(2.95); // start depends on the min value and
192 CPPUNIT_ASSERT( tester != binmap->end() );
193 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
194 // inner point
195 tester = binmap->lower_bound(-0.5);
196 CPPUNIT_ASSERT( tester != binmap->end() );
197 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
198};
199
200void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinRangeTest()
201{
202 BinPairMap::iterator tester;
203 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
204 // ... and check with [0., 2.] range
205 binmap = BinData( surfacemap, 0.5, -2., 4. );
206 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
207 OutputCorrelation ( (ofstream *)&cout, binmap );
208 // three outside points
209 tester = binmap->lower_bound(3.);
210 CPPUNIT_ASSERT( tester != binmap->end() );
211 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
212 // inner point
213 tester = binmap->lower_bound(-0.5);
214 CPPUNIT_ASSERT( tester != binmap->end() );
215 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
216
217};
Note: See TracBrowser for help on using the repository browser.