source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ 8d2772

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

Changed conditional criticalExit in constructor of BoundaryTriangleSet to Assertion.

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