ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
neighbor_list.h
Go to the documentation of this file.
1#ifndef NEIGHBOR_LIST_H
2#define NEIGHBOR_LIST_H
3
5
6#include <vector>
7#include "page_allocator.h"
8
10{
11public:
12 NeighborList() = default;
13 ~NeighborList() = default;
14
15 void initialize(std::size_t ncentral_atoms, std::size_t pgsize)
16 {
17 ncentral_atoms_ = ModuleNeighList::checked_int_size(ncentral_atoms, "NeighborList central atom count");
18 allocator_.initialize(ModuleNeighList::checked_int_size(pgsize, "NeighborList page size"));
19 numneigh_.assign(ncentral_atoms, 0);
20 firstneigh_.assign(ncentral_atoms, nullptr);
21 }
22
23 void reset()
24 {
25 allocator_.reset();
26 }
27
28 int get_ncentral_atoms() const { return ncentral_atoms_; }
29 int get_numneigh(int i) const { return numneigh_[i]; }
30 int* get_firstneigh(int i) { return firstneigh_[i]; }
31 const int* get_firstneigh(int i) const { return firstneigh_[i]; }
33 std::vector<int> get_neighbors_sorted_by_distance(int central_atom,
34 const std::vector<double>& coordinates) const;
36 const PageAllocator& get_allocator() const { return allocator_; }
37
38 void set_neighbors(int i, const std::vector<int>& neighbors)
39 {
40 numneigh_[i] = ModuleNeighList::checked_int_size(neighbors.size(), "NeighborList neighbor count");
41 firstneigh_[i] = allocator_.allocate(numneigh_[i]);
42 for (int j = 0; j < numneigh_[i]; ++j)
43 {
44 firstneigh_[i][j] = neighbors[j];
45 }
46 }
47
48private:
50 std::vector<int> numneigh_;
51 std::vector<int*> firstneigh_;
53
54 friend class BinManager;
55};
56
57#endif // NEIGHBOR_LIST_H
int get_ncentral_atoms() const
Definition neighbor_list.h:28
PageAllocator allocator_
Definition neighbor_list.h:52
int ncentral_atoms_
Definition neighbor_list.h:49
void set_neighbors(int i, const std::vector< int > &neighbors)
Definition neighbor_list.h:38
std::vector< int > get_neighbors_sorted_by_distance(int central_atom, const std::vector< double > &coordinates) const
Return a distance-sorted copy of one atom's neighbors without changing the stored order.
Definition neighbor_list.cpp:6
void initialize(std::size_t ncentral_atoms, std::size_t pgsize)
Definition neighbor_list.h:15
void reset()
Definition neighbor_list.h:23
NeighborList()=default
~NeighborList()=default
const int * get_firstneigh(int i) const
Definition neighbor_list.h:31
int * get_firstneigh(int i)
Definition neighbor_list.h:30
std::vector< int * > firstneigh_
Definition neighbor_list.h:51
friend class BinManager
Definition neighbor_list.h:54
const PageAllocator & get_allocator() const
Definition neighbor_list.h:36
PageAllocator & get_allocator()
Definition neighbor_list.h:35
std::vector< int > numneigh_
Definition neighbor_list.h:50
int get_numneigh(int i) const
Definition neighbor_list.h:29
Definition page_allocator.h:7
int checked_int_size(const std::size_t value, const char *context)
Definition neighbor_types.h:16