source: src/LinkedCell/LinkedCell_View.cpp@ ff4fff9

CombiningParticlePotentialParsing
Last change on this file since ff4fff9 was 7daf73, checked in by Frederik Heber <heber@…>, 9 years ago

LinkedCell's LinkedList is now a vector and no longer a set.

  • this was causing conflicts in tests as the order of the atoms/TesselPoints in the LinkedList returned by getAllNeighbors() would depend on the order in memory and not on the geometrical ordering or on the ids.
  • TESTFIX: needed to replace use of insert() in (unit)tests by push_back. But all in all only Molecules Removal regression test's pdb file is affected.
  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * LinkedCell_View.cpp
25 *
26 * Created on: Nov 15, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include "LinkedCell_View.hpp"
38
39#include <algorithm>
40
41#include "CodePatterns/Assert.hpp"
42#include "CodePatterns/Log.hpp"
43
44#include "Atom/TesselPoint.hpp"
45#include "Box.hpp"
46#include "LinearAlgebra/Vector.hpp"
47#include "LinkedCell.hpp"
48#include "LinkedCell_Model.hpp"
49#include "LinkedCell_View_ModelWrapper.hpp"
50#include "tripleIndex.hpp"
51
52using namespace LinkedCell;
53
54// static multimap instance
55LinkedCell_View::ModelInstanceMap LinkedCell_View::RAIIMap;
56
57/** Constructor of class LinkedCell_View.
58 *
59 * We add ourselves to RAIIMap here.
60 */
61LinkedCell_View::LinkedCell_View(const LinkedCell_Model &_LC) :
62 LC( new LinkedCell_View_ModelWrapper(&_LC) )
63{
64 // add us to RAII counting map
65#ifndef NDEBUG
66 std::pair< ModelInstanceMap::iterator, bool> inserter =
67#endif
68 RAIIMap.insert( this );
69 ASSERT( inserter.second,
70 "LinkedCell_View::LinkedCell_View() - we "+toString(this)+" are already present in RAIIMap.");
71 LOG(3, "INFO: Placing instance "+toString(this)+" into RAIIMap.");
72}
73
74/** Copy Constructor of class LinkedCell_View.
75 *
76 * We add ourselves to RAIIMap here.
77 */
78LinkedCell_View::LinkedCell_View(const LinkedCell_View &_view) :
79 LC( new LinkedCell_View_ModelWrapper(_view.LC->getModel()) )
80{
81 if (this != &_view) {
82 // add us to RAII counting map
83 #ifndef NDEBUG
84 std::pair< ModelInstanceMap::iterator, bool> inserter =
85 #endif
86 RAIIMap.insert( this );
87 ASSERT( inserter.second,
88 "LinkedCell_View::LinkedCell_View(&view) - we "+toString(this)+" are already present in RAIIMap.");
89 LOG(3, "INFO: Placing instance "+toString(this)+" copied from "+toString(&_view)+" into RAIIMap.");
90 }
91}
92
93/** Destructor of class LinkedCell_View.
94 *
95 * We remove ourselves from RAIIMap here.
96 */
97LinkedCell_View::~LinkedCell_View()
98{
99 ModelInstanceMap::iterator iter = RAIIMap.find(this);
100 ASSERT( iter != RAIIMap.end(),
101 "LinkedCell_View::~LinkedCell_View() - there is no instance "
102 +toString(this)+" in RAIIMap.");
103 if (iter != RAIIMap.end()) {
104 RAIIMap.erase(iter);
105 LOG(3, "INFO: Removing instance "+toString(this)+" from RAIIMap.");
106 } else {
107 ELOG(1, "Failed to remove instance "+toString(this)+" from RAIIMap.");
108 }
109 delete LC;
110}
111
112/** Return at least as many points as are inside a sphere of \a radius around \a center.
113 *
114 * \sa LinkedCell_View::getPointsInsideSphere()
115 *
116 * @param radius radius of sphere
117 * @param center center of sphere
118 * @return a list containing at least all points inside described sphere
119 */
120LinkedList LinkedCell_View::getAllNeighbors(const double radius, const Vector &center) const
121{
122 LinkedList TesselList; // we do not need a set, as nodes are uniquely associated to a cell.
123
124 const LinkedCell_Model * const LCmodel = LC->getModel(); // get quick ref to model
125 // get relative bounds
126 const tripleIndex step = LCmodel->getStep(radius);
127 const tripleIndex index = LCmodel->getIndexToVector(center);
128 LinkedCell_Model::LinkedCellNeighborhoodBounds neighbors =
129 LCmodel->getNeighborhoodBounds(index, step);
130
131 tripleIndex n;
132 for (n[0] = 0; n[0] < neighbors.second[0]; n[0]++)
133 for (n[1] = 0; n[1] < neighbors.second[1]; n[1]++)
134 for (n[2] = 0; n[2] < neighbors.second[2]; n[2]++) {
135 tripleIndex absolute_n = neighbors.first + n;
136 if (!LCmodel->checkArrayBounds(absolute_n))
137 LCmodel->applyBoundaryConditions(absolute_n);
138 const LinkedCell &List = LCmodel->getCell(absolute_n);
139 LOG(4, "INFO: Current cell is " << neighbors.first << " plus " << n << ", yielding " << absolute_n << ".");
140 for (LinkedCell::const_iterator Runner = List.begin(); Runner != List.end(); Runner++) {
141 TesselList.push_back(*Runner);
142 LOG(5, "INFO: Inserting " << **Runner);
143 }
144 }
145 return TesselList;
146}
147
148LinkedList LinkedCell_View::getPointsInsideSphere(const double radius, const Vector &center) const
149{
150 // get overly much points
151 const LinkedList TesselList = getAllNeighbors(radius, center);
152 LinkedList ReturnList;
153
154 // remove all unnecessary ones
155 const Box& domain = LC->getModel()->getDomain();
156 for (LinkedList::const_iterator iter = TesselList.begin(); iter != TesselList.end(); ++iter) {
157 if (domain.periodicDistanceSquared(center, (*iter)->getPosition()) <= radius*radius)
158 ReturnList.push_back(*iter);
159 }
160
161 return ReturnList;
162}
Note: See TracBrowser for help on using the repository browser.