source: src/linkedcell.cpp@ cd4ccc

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 cd4ccc was 357fba, checked in by Frederik Heber <heber@…>, 16 years ago

Huge refactoring of Tesselation routines, but not finished yet.

  • new file tesselation.cpp with all of classes tesselation, Boundary..Set and CandidatesForTesselationOB
  • new file tesselationhelper.cpp with all auxiliary functions.
  • boundary.cpp just contains super functions, combininb molecule and Tesselation pointers
  • new pointer molecule::TesselStruct
  • PointMap, LineMap, TriangleMap DistanceMap have been moved from molecules.hpp to tesselation.hpp
  • new abstract class PointCloud and TesselPoint
  • atom inherits TesselPoint
  • molecule inherits PointCloud (i.e. a set of TesselPoints) and implements all virtual functions for the chained list
  • TriangleFilesWritten is thrown out, intermediate steps are written in find_nonconvex_border and not in find_next_triangle()
  • LinkedCell class uses TesselPoint as its nodes, i.e. as long as any class inherits TesselPoint, it may make use of LinkedCell as well and a PointCloud is used to initialize
  • class atom and bond definitions have been moved to own header files

NOTE: This is not bugfree yet. Tesselation of heptan produces way too many triangles, but runs without faults or leaks.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1#include "linkedcell.hpp"
2#include "molecules.hpp"
3#include "tesselation.hpp"
4
5// ========================================================= class LinkedCell ===========================================
6
7
8/** Constructor for class LinkedCell.
9 */
10LinkedCell::LinkedCell()
11{
12 LC = NULL;
13 for(int i=0;i<NDIM;i++)
14 N[i] = 0;
15 index = -1;
16 RADIUS = 0.;
17 max.Zero();
18 min.Zero();
19};
20
21/** Puts all atoms in \a *mol into a linked cell list with cell's lengths of \a RADIUS
22 * \param *set LCNodeSet class with all LCNode's
23 * \param RADIUS edge length of cells
24 */
25LinkedCell::LinkedCell(PointCloud *set, double radius)
26{
27 TesselPoint *Walker = NULL;
28
29 RADIUS = radius;
30 LC = NULL;
31 for(int i=0;i<NDIM;i++)
32 N[i] = 0;
33 index = -1;
34 max.Zero();
35 min.Zero();
36 cout << Verbose(1) << "Begin of LinkedCell" << endl;
37 if (set->IsEmpty()) {
38 cerr << "ERROR: set contains no linked cell nodes!" << endl;
39 return;
40 }
41 // 1. find max and min per axis of atoms
42 set->GoToFirst();
43 Walker = set->GetPoint();
44 for (int i=0;i<NDIM;i++) {
45 max.x[i] = Walker->node->x[i];
46 min.x[i] = Walker->node->x[i];
47 }
48 set->GoToFirst();
49 while (!set->IsLast()) {
50 Walker = set->GetPoint();
51 for (int i=0;i<NDIM;i++) {
52 if (max.x[i] < Walker->node->x[i])
53 max.x[i] = Walker->node->x[i];
54 if (min.x[i] > Walker->node->x[i])
55 min.x[i] = Walker->node->x[i];
56 }
57 set->GoToNext();
58 }
59 cout << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl;
60
61 // 2. find then number of cells per axis
62 for (int i=0;i<NDIM;i++) {
63 N[i] = (int)floor((max.x[i] - min.x[i])/RADIUS)+1;
64 }
65 cout << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl;
66
67 // 3. allocate the lists
68 cout << Verbose(2) << "Allocating cells ... ";
69 if (LC != NULL) {
70 cout << Verbose(1) << "ERROR: Linked Cell list is already allocated, I do nothing." << endl;
71 return;
72 }
73 LC = new LinkedNodes[N[0]*N[1]*N[2]];
74 for (index=0;index<N[0]*N[1]*N[2];index++) {
75 LC [index].clear();
76 }
77 cout << "done." << endl;
78
79 // 4. put each atom into its respective cell
80 cout << Verbose(2) << "Filling cells ... ";
81 set->GoToFirst();
82 while (!set->IsLast()) {
83 Walker = set->GetPoint();
84 for (int i=0;i<NDIM;i++) {
85 n[i] = (int)floor((Walker->node->x[i] - min.x[i])/RADIUS);
86 }
87 index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
88 LC[index].push_back(Walker);
89 //cout << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
90 set->GoToNext();
91 }
92 cout << "done." << endl;
93 cout << Verbose(1) << "End of LinkedCell" << endl;
94};
95
96/** Destructor for class LinkedCell.
97 */
98LinkedCell::~LinkedCell()
99{
100 if (LC != NULL)
101 for (index=0;index<N[0]*N[1]*N[2];index++)
102 LC[index].clear();
103 delete[](LC);
104 for(int i=0;i<NDIM;i++)
105 N[i] = 0;
106 index = -1;
107 max.Zero();
108 min.Zero();
109};
110
111/** Checks whether LinkedCell::n[] is each within [0,N[]].
112 * \return if all in intervals - true, else -false
113 */
114bool LinkedCell::CheckBounds()
115{
116 bool status = true;
117 for(int i=0;i<NDIM;i++)
118 status = status && ((n[i] >=0) && (n[i] < N[i]));
119 if (!status)
120 cerr << "ERROR: indices are out of bounds!" << endl;
121 return status;
122};
123
124
125/** Returns a pointer to the current cell.
126 * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[] are out of bounds.
127 */
128LinkedNodes* LinkedCell::GetCurrentCell()
129{
130 if (CheckBounds()) {
131 index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
132 return (&(LC[index]));
133 } else {
134 return NULL;
135 }
136};
137
138/** Calculates the index for a given LCNode *Walker.
139 * \param *Walker LCNode to set index tos
140 * \return if the atom is also found in this cell - true, else - false
141 */
142bool LinkedCell::SetIndexToNode(TesselPoint *Walker)
143{
144 bool status = false;
145 for (int i=0;i<NDIM;i++) {
146 n[i] = (int)floor((Walker->node->x[i] - min.x[i])/RADIUS);
147 }
148 index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2];
149 if (CheckBounds()) {
150 for (LinkedNodes::iterator Runner = LC[index].begin(); Runner != LC[index].end(); Runner++)
151 status = status || ((*Runner) == Walker);
152 return status;
153 } else {
154 cerr << Verbose(1) << "ERROR: Node at " << *Walker << " is out of bounds." << endl;
155 return false;
156 }
157};
158
159/** Calculates the index for a given Vector *x.
160 * \param *x Vector with coordinates
161 * \return Vector is inside bounding box - true, else - false
162 */
163bool LinkedCell::SetIndexToVector(Vector *x)
164{
165 bool status = true;
166 for (int i=0;i<NDIM;i++) {
167 n[i] = (int)floor((x->x[i] - min.x[i])/RADIUS);
168 if (max.x[i] < x->x[i])
169 status = false;
170 if (min.x[i] > x->x[i])
171 status = false;
172 }
173 return status;
174};
175
Note: See TracBrowser for help on using the repository browser.