source: src/CandidateForTesselation.cpp@ 5b4605

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

converted #define's to enums, consts and typedefs [Meyers, "Effective C++", item 1].

basic changes:

  • #define bla 1.3 -> const double bla = 1.3
  • #define bla "test" -> const char * const bla = "test
  • use class specific constants! (HULLEPSILON)

const int Class::bla = 1.3; (in .cpp)
static const int bla; (in .hpp inside class private section)

  • "enum hack": #define bla 5 -> enum { bla = 5 };
    • if const int bla=5; impossible
    • e.g. necessary if constant is used in array declaration (int blabla[bla];)

details:

  • new file defs.cpp where const double reside in and are referenced by extern "C" const double
  • joiner.cpp: main() had to be changed due to concatenation of two #define possible, of two const char * not
  • class specific constants: HULLEPSILON, BONDTHRESHOLD, SPHERERADIUS
  • extended GetPathLengthonCircumCircle to additional parameter HULLEPSILON
  • Property mode set to 100644
File size: 7.3 KB
Line 
1/*
2 * CandidateForTesselation.cpp
3 *
4 * Created on: Jul 29, 2010
5 * Author: heber
6 */
7
8#include "CandidateForTesselation.hpp"
9
10#include <iostream>
11#include <iomanip>
12
13#include "BoundaryLineSet.hpp"
14#include "BoundaryPointSet.hpp"
15#include "TesselPoint.hpp"
16
17#include "Helpers/Assert.hpp"
18#include "Helpers/Info.hpp"
19//#include "Line.hpp"
20#include "linkedcell.hpp"
21#include "Helpers/Log.hpp"
22//#include "Plane.hpp"
23#include "LinearAlgebra/Vector.hpp"
24#include "Helpers/Verbose.hpp"
25
26using namespace std;
27
28
29const double CandidateForTesselation::HULLEPSILON = 1e-9;
30
31
32/** Constructor of class CandidateForTesselation.
33 */
34CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) :
35 BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
36{
37 Info FunctionInfo(__func__);
38}
39;
40
41/** Constructor of class CandidateForTesselation.
42 */
43CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, const Vector &OptCandidateCenter, const Vector &OtherOptCandidateCenter) :
44 BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
45{
46 Info FunctionInfo(__func__);
47 OptCenter = OptCandidateCenter;
48 OtherOptCenter = OtherOptCandidateCenter;
49};
50
51
52/** Destructor for class CandidateForTesselation.
53 */
54CandidateForTesselation::~CandidateForTesselation()
55{
56}
57;
58
59/** Checks validity of a given sphere of a candidate line.
60 * Sphere must touch all candidates and the baseline endpoints and there must be no other atoms inside.
61 * \param RADIUS radius of sphere
62 * \param *LC LinkedCell structure with other atoms
63 * \return true - sphere is valid, false - sphere contains other points
64 */
65bool CandidateForTesselation::CheckValidity(const double RADIUS, const LinkedCell *LC) const
66{
67 Info FunctionInfo(__func__);
68
69 const double radiusSquared = RADIUS * RADIUS;
70 list<const Vector *> VectorList;
71 VectorList.push_back(&OptCenter);
72 //VectorList.push_back(&OtherOptCenter); // don't check the other (wrong) center
73
74 if (!pointlist.empty())
75 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
76 else
77 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
78 // check baseline for OptCenter and OtherOptCenter being on sphere's surface
79 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
80 for (int i = 0; i < 2; i++) {
81 const double distance = fabs((*VRunner)->DistanceSquared(BaseLine->endpoints[i]->node->getPosition()) - radiusSquared);
82 if (distance > HULLEPSILON) {
83 DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
84 return false;
85 }
86 }
87 }
88
89 // check Candidates for OptCenter and OtherOptCenter being on sphere's surface
90 for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
91 const TesselPoint *Walker = *Runner;
92 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
93 const double distance = fabs((*VRunner)->DistanceSquared(Walker->getPosition()) - radiusSquared);
94 if (distance > HULLEPSILON) {
95 DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
96 return false;
97 } else {
98 DoLog(1) && (Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl);
99 }
100 }
101 }
102
103 DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
104 bool flag = true;
105 for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
106 // get all points inside the sphere
107 TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
108
109 DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << (*VRunner) << ":" << endl);
110 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
111 DoLog(1) && (Log() << Verbose(1) << " " << *(*Runner) << " with distance " << (*Runner)->distance(*(*VRunner)) << "." << endl);
112
113 // remove baseline's endpoints and candidates
114 for (int i = 0; i < 2; i++) {
115 DoLog(1) && (Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl);
116 ListofPoints->remove(BaseLine->endpoints[i]->node);
117 }
118 for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
119 DoLog(1) && (Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl);
120 ListofPoints->remove(*Runner);
121 }
122 if (!ListofPoints->empty()) {
123 DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
124 flag = false;
125 DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
126 for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
127 DoeLog(1) && (eLog() << Verbose(1) << " " << *(*Runner) << " at distance " << setprecision(13) << (*Runner)->distance(*(*VRunner)) << setprecision(6) << "." << endl);
128
129 // check with animate_sphere.tcl VMD script
130 if (ThirdPoint != NULL) {
131 DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
132 } else {
133 DoeLog(1) && (eLog() << Verbose(1) << "Check by: ... missing third point ..." << endl);
134 DoeLog(1) && (eLog() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter[0] << " " << OldCenter[1] << " " << OldCenter[2] << " " << (*VRunner)->at(0) << " " << (*VRunner)->at(1) << " " << (*VRunner)->at(2) << endl);
135 }
136 }
137 delete (ListofPoints);
138
139 }
140 return flag;
141}
142;
143
144/** output operator for CandidateForTesselation.
145 * \param &ost output stream
146 * \param &a boundary line
147 */
148ostream & operator <<(ostream &ost, const CandidateForTesselation &a)
149{
150 ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->getName() << "," << a.BaseLine->endpoints[1]->node->getName() << "] with ";
151 if (a.pointlist.empty())
152 ost << "no candidate.";
153 else {
154 ost << "candidate";
155 if (a.pointlist.size() != 1)
156 ost << "s ";
157 else
158 ost << " ";
159 for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
160 ost << *(*Runner) << " ";
161 ost << " at angle " << (a.ShortestAngle) << ".";
162 }
163
164 return ost;
165}
166;
167
Note: See TracBrowser for help on using the repository browser.