atomicrex  0.1
An advanced atomistic model building tool
NeighborList.h
1 //
3 // Copyright (C) 2017, Alexander Stukowski and Paul Erhart
4 //
5 // This file is part of atomicrex.
6 //
7 // Atomicrex is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Atomicrex is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //
21 
22 #pragma once
23 
24 #include "../Atomicrex.h"
25 
26 namespace atomicrex {
27 
28 class AtomicStructure;
29 class Potential;
30 
32 {
33  Vector3 delta; // delta = x[j] - x[i]
34  double r; // r = |delta|
35  int index; // Index of second atom of the neighbor bond (this may be a local or a ghost atom).
36  int localIndex; // Index of second local atom (this is always the corresponding local atom).
37 
38  // Pointer to additional memory for the potential routines to store pair-wise information.
39  void* bondDataPtr;
40 
41  template<typename T>
42  T& bondData() {
43  BOOST_ASSERT(bondDataPtr != nullptr);
44  return *static_cast<T*>(bondDataPtr);
45  }
46 
47  template<typename T>
48  const T& bondData() const {
49  BOOST_ASSERT(bondDataPtr != nullptr);
50  return *static_cast<const T*>(bondDataPtr);
51  }
52 };
53 
59 {
60 public:
61 
63  NeighborList() : _numAtoms(0) {}
64 
66  int numAtoms() const { return _numAtoms; }
67 
69  int atomIndex(int i) const { return _ilist[i]; }
70 
72  int numNeighborsHalf(int atomIndex) const { return _numNeighborsHalf[atomIndex]; }
73 
75  int numNeighborsFull(int atomIndex) const { return _numNeighborsFull[atomIndex]; }
76 
78  NeighborListEntry* neighborList(int atomIndex) {
79  BOOST_ASSERT(atomIndex >= 0 && atomIndex < _firstNeighbor.size());
80  return &_neighborList[_firstNeighbor[atomIndex]];
81  }
82 
84  const NeighborListEntry* neighborList(int atomIndex) const {
85  BOOST_ASSERT(atomIndex >= 0 && atomIndex < _firstNeighbor.size());
86  return &_neighborList[_firstNeighbor[atomIndex]];
87  }
88 
90  void build(const AtomicStructure& structure, const Potential& potential, double cutoffRange);
91 
95  void update(const AtomicStructure& structure);
96 
97 private:
98 
100  int _numAtoms;
102  std::vector<int> _ilist;
104  std::vector<int> _numNeighborsHalf;
106  std::vector<int> _numNeighborsFull;
108  std::vector<int> _firstNeighbor;
110  std::vector<NeighborListEntry> _neighborList;
112  std::vector<unsigned char> _perBondPotentialData;
113 };
114 
115 } // End of namespace
Base class for maintaining structures.
Definition: AtomicStructure.h:42
Definition: NeighborList.h:31
NeighborList()
Constructor.
Definition: NeighborList.h:63
Definition: NeighborList.h:58
NeighborListEntry * neighborList(int atomIndex)
Returns a pointer to the first entry in the neighbor list of the given real atom. ...
Definition: NeighborList.h:78
int numNeighborsFull(int atomIndex) const
Returns the number of neighbors of a real atom (full neighbor list).
Definition: NeighborList.h:75
int atomIndex(int i) const
Returns the index of the i-th atom in this neighbor list.
Definition: NeighborList.h:69
This file collects the definition of classes that define various simple crystal structures.
Definition: Atomicrex.h:67
int numAtoms() const
Returns the number of atoms included in this neighbor list.
Definition: NeighborList.h:66
const NeighborListEntry * neighborList(int atomIndex) const
Returns a const-pointer to the first entry in the neighbor list of the given real atom...
Definition: NeighborList.h:84
int numNeighborsHalf(int atomIndex) const
Returns the number of neighbors of a real atom (half neighbor list).
Definition: NeighborList.h:72
Base class for potential.
Definition: Potential.h:41