source: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp@ 920c70

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

Removed all Malloc/Calloc/ReAlloc (&Free) and replaced by new and delete/delete[].

Due to the new MemDebug framework there is no need (or even unnecessary/unwanted competition between it and) for the MemoryAllocator and ..UsageObserver anymore.
They can however still be used with c codes such as pcp and alikes.

In Molecuilder lots of glibc corruptions arose and the C-like syntax make it generally harder to get allocation and deallocation straight.

Signed-off-by: Frederik Heber <heber@…>

  • Property mode set to 100644
File size: 7.1 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 "atom.hpp"
20#include "boundary.hpp"
21#include "element.hpp"
22#include "molecule.hpp"
23#include "linkedcell.hpp"
24#include "periodentafel.hpp"
25#include "tesselation.hpp"
26#include "World.hpp"
27
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(Assert::Throw);
42
43 atom *Walker = NULL;
44
45 // init private all pointers to zero
46 TestList = NULL;
47 TestSurfaceMolecule = NULL;
48 surfacemap = NULL;
49 binmap = NULL;
50 Surface = NULL;
51 LC = NULL;
52
53 // construct molecule (tetraeder of hydrogens) base
54 hydrogen = World::getInstance().getPeriode()->FindElement(1);
55 TestSurfaceMolecule = World::getInstance().createMolecule();
56 Walker = World::getInstance().createAtom();
57 Walker->type = hydrogen;
58 *Walker->node = Vector(1., 0., 1. );
59
60 TestSurfaceMolecule->AddAtom(Walker);
61 Walker = World::getInstance().createAtom();
62 Walker->type = hydrogen;
63 *Walker->node = Vector(0., 1., 1. );
64 TestSurfaceMolecule->AddAtom(Walker);
65 Walker = World::getInstance().createAtom();
66 Walker->type = hydrogen;
67 *Walker->node = Vector(1., 1., 0. );
68 TestSurfaceMolecule->AddAtom(Walker);
69 Walker = World::getInstance().createAtom();
70 Walker->type = hydrogen;
71 *Walker->node = Vector(0., 0., 0. );
72 TestSurfaceMolecule->AddAtom(Walker);
73
74 // check that TestMolecule was correctly constructed
75 CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 );
76
77 TestList = World::getInstance().getMolecules();
78 TestSurfaceMolecule->ActiveFlag = true;
79 TestList->insert(TestSurfaceMolecule);
80
81 // init tesselation and linked cell
82 Surface = new Tesselation;
83 LC = new LinkedCell(TestSurfaceMolecule, 5.);
84 FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
85
86 // add outer atoms
87 carbon = World::getInstance().getPeriode()->FindElement(6);
88 TestSurfaceMolecule = World::getInstance().createMolecule();
89 Walker = World::getInstance().createAtom();
90 Walker->type = carbon;
91 *Walker->node = Vector(4., 0., 4. );
92 TestSurfaceMolecule->AddAtom(Walker);
93 Walker = World::getInstance().createAtom();
94 Walker->type = carbon;
95 *Walker->node = Vector(0., 4., 4. );
96 TestSurfaceMolecule->AddAtom(Walker);
97 Walker = World::getInstance().createAtom();
98 Walker->type = carbon;
99 *Walker->node = Vector(4., 4., 0. );
100 TestSurfaceMolecule->AddAtom(Walker);
101 // add inner atoms
102 Walker = World::getInstance().createAtom();
103 Walker->type = carbon;
104 *Walker->node = Vector(0.5, 0.5, 0.5 );
105 TestSurfaceMolecule->AddAtom(Walker);
106 TestSurfaceMolecule->ActiveFlag = true;
107 TestList->insert(TestSurfaceMolecule);
108
109 // init maps
110 surfacemap = NULL;
111 binmap = NULL;
112
113};
114
115
116void AnalysisCorrelationToSurfaceUnitTest::tearDown()
117{
118 if (surfacemap != NULL)
119 delete(surfacemap);
120 if (binmap != NULL)
121 delete(binmap);
122
123 delete(Surface);
124 // note that all the atoms are cleaned by TestMolecule
125 delete(LC);
126 World::purgeInstance();
127 logger::purgeInstance();
128};
129
130
131/** Checks whether setup() does the right thing.
132 */
133void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
134{
135 CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->AtomCount );
136 CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() );
137 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
138 CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
139 CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
140};
141
142void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
143{
144 // do the pair correlation
145 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
146// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
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// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
157 binmap = BinData( surfacemap, 0.5, 0., 0. );
158 CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
159 OutputCorrelation ( (ofstream *)&cout, binmap );
160 tester = binmap->begin();
161 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
162 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
163
164};
165
166void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceHydrogenBinRangeTest()
167{
168 BinPairMap::iterator tester;
169 surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
170// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
171 // ... and check with [0., 2.] range
172 binmap = BinData( surfacemap, 0.5, 0., 2. );
173 CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
174// OutputCorrelation ( (ofstream *)&cout, binmap );
175 tester = binmap->begin();
176 CPPUNIT_ASSERT_EQUAL( 0., tester->first );
177 CPPUNIT_ASSERT_EQUAL( 4, tester->second );
178 tester = binmap->find(1.);
179 CPPUNIT_ASSERT_EQUAL( 1., tester->first );
180 CPPUNIT_ASSERT_EQUAL( 0, tester->second );
181
182};
183
184void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceCarbonBinNoRangeTest()
185{
186 BinPairMap::iterator tester;
187 surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
188// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
189 // put pair correlation into bins and check with no range
190 binmap = BinData( surfacemap, 0.5, 0., 0. );
191 //OutputCorrelation ( (ofstream *)&cout, binmap );
192 CPPUNIT_ASSERT_EQUAL( (size_t)9, binmap->size() );
193 // inside point is first and must have negative value
194 tester = binmap->lower_bound(4.25-0.5); // 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.);
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// OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
208 // ... and check with [0., 2.] range
209 binmap = BinData( surfacemap, 0.5, -2., 4. );
210 //OutputCorrelation ( (ofstream *)&cout, binmap );
211 CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
212 // three outside points
213 tester = binmap->lower_bound(4.25-0.5);
214 CPPUNIT_ASSERT( tester != binmap->end() );
215 CPPUNIT_ASSERT_EQUAL( 3, tester->second );
216 // inner point
217 tester = binmap->lower_bound(0.);
218 CPPUNIT_ASSERT( tester != binmap->end() );
219 CPPUNIT_ASSERT_EQUAL( 1, tester->second );
220};
Note: See TracBrowser for help on using the repository browser.