source: src/unittests/tesselation_insideoutsideunittest.cpp@ c15ca2

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

Changes to FindClosest...ToVector() and use of ..Map,..Set,..List defines in tesselation.cpp.

  • Property mode set to 100644
File size: 6.5 KB
Line 
1/*
2 * tesselation_insideoutsideunittest.cpp
3 *
4 * Created on: Dec 28, 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 "defs.hpp"
15#include "tesselation.hpp"
16#include "tesselation_insideoutsideunittest.hpp"
17
18#define SPHERERADIUS 2.
19
20/********************************************** Test classes **************************************/
21
22// Registers the fixture into the 'registry'
23CPPUNIT_TEST_SUITE_REGISTRATION( TesselationInOutsideTest );
24
25
26void TesselationInOutsideTest::setUp()
27{
28 setVerbosity(3);
29
30 // create corners
31 class TesselPoint *Walker;
32 Walker = new TesselPoint;
33 Walker->node = new Vector(0., 0., 0.);
34 Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp");
35 strcpy(Walker->Name, "1");
36 Walker->nr = 1;
37 Corners.push_back(Walker);
38 Walker = new TesselPoint;
39 Walker->node = new Vector(0., 1., 0.);
40 Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp");
41 strcpy(Walker->Name, "2");
42 Walker->nr = 2;
43 Corners.push_back(Walker);
44 Walker = new TesselPoint;
45 Walker->node = new Vector(1., 0., 0.);
46 Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp");
47 strcpy(Walker->Name, "3");
48 Walker->nr = 3;
49 Corners.push_back(Walker);
50 Walker = new TesselPoint;
51 Walker->node = new Vector(1., 1., 0.);
52 Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp");
53 strcpy(Walker->Name, "4");
54 Walker->nr = 4;
55 Corners.push_back(Walker);
56 Walker = new TesselPoint;
57 Walker->node = new Vector(0., 0., 1.);
58 Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp");
59 strcpy(Walker->Name, "5");
60 Walker->nr = 5;
61 Corners.push_back(Walker);
62 Walker = new TesselPoint;
63 Walker->node = new Vector(0., 1., 1.);
64 Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp");
65 strcpy(Walker->Name, "6");
66 Walker->nr = 6;
67 Corners.push_back(Walker);
68 Walker = new TesselPoint;
69 Walker->node = new Vector(1., 0., 1.);
70 Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp");
71 strcpy(Walker->Name, "7");
72 Walker->nr = 7;
73 Corners.push_back(Walker);
74 Walker = new TesselPoint;
75 Walker->node = new Vector(1., 1., 1.);
76 Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp");
77 strcpy(Walker->Name, "8");
78 Walker->nr = 8;
79 Corners.push_back(Walker);
80
81 // create linkedcell
82 LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS);
83
84 // create tesselation
85 TesselStruct = new Tesselation;
86 TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
87
88 CandidateForTesselation *baseline = NULL;
89 BoundaryTriangleSet *T = NULL;
90 bool OneLoopWithoutSuccessFlag = true;
91 bool TesselationFailFlag = false;
92 while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
93 // 2a. fill all new OpenLines
94 Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for candidates:" << endl;
95 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
96 Log() << Verbose(2) << *(Runner->second) << endl;
97
98 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
99 baseline = Runner->second;
100 if (baseline->pointlist.empty()) {
101 T = (((baseline->BaseLine->triangles.begin()))->second);
102 Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl;
103 TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
104 }
105 }
106
107 // 2b. search for smallest ShortestAngle among all candidates
108 double ShortestAngle = 4.*M_PI;
109 Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for the best candidates:" << endl;
110 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
111 Log() << Verbose(2) << *(Runner->second) << endl;
112
113 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
114 if (Runner->second->ShortestAngle < ShortestAngle) {
115 baseline = Runner->second;
116 ShortestAngle = baseline->ShortestAngle;
117 //Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *baseline->point << " and angle " << baseline->ShortestAngle << endl;
118 }
119 }
120 if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
121 OneLoopWithoutSuccessFlag = false;
122 else {
123 TesselStruct->AddCandidateTriangle(*baseline);
124 }
125 }
126};
127
128
129void TesselationInOutsideTest::tearDown()
130{
131 delete(LinkedList);
132 delete(TesselStruct);
133 for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
134 delete((*Runner)->node);
135 delete(*Runner);
136 }
137 Corners.clear();
138 MemoryUsageObserver::purgeInstance();
139 logger::purgeInstance();
140 errorLogger::purgeInstance();
141};
142
143/** UnitTest for Tesselation::IsInnerPoint()
144 */
145void TesselationInOutsideTest::IsInnerPointTest()
146{
147 double n[3];
148 const double boundary = 5.;
149 const double step = 1.;
150
151 // go through the mesh and check each point
152 for (n[0] = -boundary; n[0] <= boundary; n[0]+=step)
153 for (n[1] = -boundary; n[1] <= boundary; n[1]+=step)
154 for (n[2] = -boundary; n[2] <= boundary; n[2]+=step) {
155 if ( ((n[0] > 0) && (n[0] > 0) && (n[0] > 0)) && (n[0]+n[1]+n[2] <= 1.))
156 CPPUNIT_ASSERT_EQUAL( true , TesselStruct->IsInnerPoint(Vector(n[0], n[1], n[2]), LinkedList) );
157 else
158 CPPUNIT_ASSERT_EQUAL( false , TesselStruct->IsInnerPoint(Vector(n[0], n[1], n[2]), LinkedList) );
159 }
160};
161
162/********************************************** Main routine **************************************/
163
164int main(int argc, char **argv)
165{
166 // Get the top level suite from the registry
167 CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
168
169 // Adds the test to the list of test to run
170 CppUnit::TextUi::TestRunner runner;
171 runner.addTest( suite );
172
173 // Change the default outputter to a compiler error format outputter
174 runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
175 std::cerr ) );
176 // Run the tests.
177 bool wasSucessful = runner.run();
178
179 // Return error code 1 if the one of test failed.
180 return wasSucessful ? 0 : 1;
181};
Note: See TracBrowser for help on using the repository browser.