forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathneighbor_search.h
More file actions
163 lines (130 loc) · 5.04 KB
/
Copy pathneighbor_search.h
File metadata and controls
163 lines (130 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef NEIGHBOR_SEARCH_H
#define NEIGHBOR_SEARCH_H
#include "source_cell/module_neighlist/neighbor_atom.h"
#include "source_cell/module_neighlist/bin_manager.h"
#include "source_cell/module_neighlist/neighbor_list.h"
#include "source_cell/module_neighlist/local_atom.h"
#include "source_cell/basecell.h"
class MDCell;
class UnitCell;
/**
* @brief Neighbor search algorithm for building atom neighbor lists.
*
* This class implements a neighbor search algorithm that finds all atoms
* within a given cutoff radius. It uses a binning strategy for efficiency
* and supports MPI parallelization by decomposing the simulation domain.
*
* The workflow is:
* 1. Call init() to initialize with unit cell and search radius
* 2. Call build_neighbors() to construct the neighbor list
* 3. Access results via get_neighbor_list()
*/
class NeighborSearch
{
public:
/**
* @brief Default constructor.
*/
NeighborSearch() = default;
/**
* @brief Default destructor.
*/
~NeighborSearch() = default;
// ========== Main public interface ==========
/**
* @brief Initialize the neighbor search with unit cell and search radius.
*
* This method sets up the domain decomposition, identifies inside and
* ghost atoms, and prepares internal data structures.
*
* @param ucell Unit cell providing atom positions and lattice info.
* @param sr Search radius (cutoff distance) in Bohr.
*/
void init(BaseCell& cell, double sr);
/**
* @brief Build the neighbor list for all inside atoms.
*
* Must be called after init(). Uses binning to efficiently find
* all neighbors within the search radius.
*/
void build_neighbors();
/// Refresh positions and derive the physical-cutoff list from a cached
/// cutoff-plus-skin candidate list for an MDCell.
void refresh_mdcell(const MDCell& cell, double cutoff);
// ========== Getter methods ==========
/**
* @brief Get the constructed neighbor list.
* @return Reference to the NeighborList object.
*/
NeighborList& get_neighbor_list();
/**
* @brief Get the constructed neighbor list (const version).
* @return Const reference to the NeighborList object.
*/
const NeighborList& get_neighbor_list() const;
/**
* @brief Get the search radius.
* @return Search radius in lattice units.
*/
double get_search_radius() const;
/**
* @brief Get all atoms (including periodic images).
* @return Const reference to the vector of all atoms.
*/
const std::vector<NeighborAtom>& get_all_atoms() const;
/**
* @brief Get atoms inside the local MPI domain.
* @return Const reference to the vector of inside atoms.
*/
const std::vector<NeighborAtom>& get_inside_atoms() const;
/**
* @brief Get ghost atoms (neighbors of inside atoms).
* @return Const reference to the vector of ghost atoms.
*/
const std::vector<NeighborAtom>& get_ghost_atoms() const;
private:
// ========== Internal methods ==========
double cross_product_norm(double a1, double a2, double a3,
double b1, double b2, double b3);
/**
* @brief Check and compute expansion layer counts.
*
* Determines how many periodic images are needed to cover
* the search radius in each lattice direction.
*
* @param ucell Unit cell providing lattice vectors.
*/
void init_from_unitcell_(const UnitCell& ucell, double sr);
void init_from_mdcell_(const MDCell& cell, double sr);
void check_expand_condition(const UnitCell& ucell, int& glayerX_minus, int& glayerX, int& glayerY_minus, int& glayerY, int& glayerZ_minus, int& glayerZ);
/**
* @brief Set member variables by generating periodic images.
*
* Populates all_atoms_ with atoms from the unit cell and
* all required periodic images.
*
* @param ucell Unit cell providing atom positions.
*/
void set_member_variables(const UnitCell& ucell, int glayerX_minus, int glayerX, int glayerY_minus, int glayerY, int glayerZ_minus, int glayerZ);
// ========== Data members ==========
/// Search radius in lattice units
double search_radius_ = 0.0;
/// All atoms including periodic images
std::vector<NeighborAtom> all_atoms_;
/// Atoms inside the local MPI domain
std::vector<NeighborAtom> inside_atoms_;
/// Ghost atoms (neighbors from other domains or images)
std::vector<NeighborAtom> ghost_atoms_;
/// The constructed neighbor list
NeighborList neighbor_list_;
NeighborList candidate_neighbor_list_;
/// Bin manager for efficient neighbor search
BinManager bin_manager_;
void filter_candidate_neighbors_(double cutoff, double lat0);
// ========== Compile-time constants ==========
/// Offset added to expansion layers in positive directions
static constexpr int positive_layer_offset = 1;
/// Reserve factor for neighbor list capacity estimation
static constexpr int neighbor_reserve_factor = 2;
};
#endif // NEIGHBOR_SEARCH_H