eOn 3.2.0
Long-timescale dynamics: aKMC, NEB, parallel replica
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
VesinNeighbors.cpp
Go to the documentation of this file.
1
/*
2
** This file is part of eOn.
3
**
4
** SPDX-License-Identifier: BSD-3-Clause
5
*/
6
7
#include "
eon/VesinNeighbors.h
"
8
9
#include <cstdlib>
10
#include <cstring>
11
#include <memory>
12
13
namespace
eonc
{
14
15
VesinNeighbors::VesinNeighbors
(
VesinNeighbors
&&other) noexcept
16
:
list_
(other.list_),
17
owns_
(other.owns_) {
18
other.list_ = VesinNeighborList{};
19
other.owns_ =
false
;
20
}
21
22
VesinNeighbors
&
VesinNeighbors::operator=
(
VesinNeighbors
&&other)
noexcept
{
23
if
(
this
!= &other) {
24
free_list
();
25
list_
= other.list_;
26
owns_
= other.owns_;
27
other.list_ = VesinNeighborList{};
28
other.owns_ =
false
;
29
}
30
return
*
this
;
31
}
32
33
VesinNeighbors::~VesinNeighbors
() {
free_list
(); }
34
35
void
VesinNeighbors::free_list
() {
36
if
(
owns_
) {
37
vesin_free(&
list_
);
38
owns_
=
false
;
39
}
40
list_
= VesinNeighborList{};
41
}
42
43
void
VesinNeighbors::compute
(
const
double
*R, std::size_t n,
const
double
*box,
44
const
Options
&opt) {
45
if
(R ==
nullptr
|| (n > 0 && box ==
nullptr
)) {
46
throw
std::invalid_argument(
"VesinNeighbors::compute: null R or box"
);
47
}
48
if
(opt.
cutoff
<= 0.0) {
49
free_list
();
50
return
;
51
}
52
53
// Pass the existing VesinNeighborList through so vesin can re-use pair /
54
// distance / vector buffers (upstream contract). Do not vesin_free first —
55
// that forces a full realloc every call and is the #386 ASV regression.
56
VesinOptions vopt{};
57
vopt.cutoff = opt.
cutoff
;
58
vopt.full = opt.
full
;
59
vopt.sorted = opt.
sorted
;
60
vopt.algorithm = opt.
algorithm
;
61
vopt.skin = opt.
skin
;
62
vopt.n_threads = opt.
n_threads
;
63
vopt.return_shifts = opt.
return_shifts
;
64
vopt.return_distances = opt.
return_distances
;
65
vopt.return_vectors = opt.
return_vectors
;
66
67
bool
periodic[3] = {opt.
periodic
[0], opt.
periodic
[1], opt.
periodic
[2]};
68
double
box33[3][3];
69
for
(
int
a = 0; a < 3; ++a) {
70
for
(
int
b = 0; b < 3; ++b) {
71
box33[a][b] = box[3 * a + b];
72
}
73
}
74
75
VesinDevice cpu{VesinCPU, 0};
76
const
char
*error_message =
nullptr
;
77
int
status =
78
vesin_neighbors(
reinterpret_cast<
const
double
(*)[3]
>
(R), n, box33,
79
periodic, cpu, vopt, &
list_
, &error_message);
80
if
(status != EXIT_SUCCESS) {
81
std::string err =
"vesin_neighbors failed"
;
82
if
(error_message !=
nullptr
) {
83
err +=
": "
;
84
err += error_message;
85
}
86
free_list
();
87
throw
std::runtime_error(err);
88
}
89
owns_
=
true
;
90
}
91
92
VesinNeighborList *
VesinNeighbors::release
() {
93
if
(!
owns_
) {
94
return
nullptr
;
95
}
96
auto
heap = std::make_unique<VesinNeighborList>(
list_
);
97
list_
= VesinNeighborList{};
98
owns_
=
false
;
99
return
heap.release();
100
}
101
102
}
// namespace eonc
VesinNeighbors.h
eonc::VesinNeighbors::free_list
void free_list()
Definition
VesinNeighbors.cpp:35
eonc::VesinNeighbors::owns_
bool owns_
Definition
VesinNeighbors.h:94
eonc::VesinNeighbors::list_
VesinNeighborList list_
Definition
VesinNeighbors.h:93
eonc::VesinNeighbors::~VesinNeighbors
~VesinNeighbors()
Definition
VesinNeighbors.cpp:33
eonc::VesinNeighbors::release
VesinNeighborList * release()
Steal ownership of the internal list (for Metatomic custom deleters).
Definition
VesinNeighbors.cpp:92
eonc::VesinNeighbors::operator=
VesinNeighbors & operator=(const VesinNeighbors &)=delete
eonc::VesinNeighbors::compute
void compute(const double *R, std::size_t n, const double *box, const Options &opt)
Build / rebuild the list.
Definition
VesinNeighbors.cpp:43
eonc::VesinNeighbors::VesinNeighbors
VesinNeighbors()=default
eonc
RAII resource manager for the ARTn C library with global synchronization.
Definition
ARTnSaddleSearch.cpp:23
eonc::VesinNeighbors::Options
Definition
VesinNeighbors.h:29
eonc::VesinNeighbors::Options::algorithm
VesinAlgorithm algorithm
vesin pair-search algorithm (auto / brute-force MIC / cell list).
Definition
VesinNeighbors.h:46
eonc::VesinNeighbors::Options::n_threads
int32_t n_threads
Threads for the vesin build; 1 keeps small builds deterministic and spawn-free, 0 defers to OMP_NUM_T...
Definition
VesinNeighbors.h:44
eonc::VesinNeighbors::Options::skin
double skin
vesin 0.6 native Verlet skin: > 0 lets vesin cache the topology in this list until an atom moves more...
Definition
VesinNeighbors.h:41
eonc::VesinNeighbors::Options::return_vectors
bool return_vectors
Definition
VesinNeighbors.h:35
eonc::VesinNeighbors::Options::full
bool full
true: both i→j and j→i; false: half list
Definition
VesinNeighbors.h:31
eonc::VesinNeighbors::Options::cutoff
double cutoff
Definition
VesinNeighbors.h:30
eonc::VesinNeighbors::Options::return_shifts
bool return_shifts
Definition
VesinNeighbors.h:33
eonc::VesinNeighbors::Options::periodic
std::array< bool, 3 > periodic
Definition
VesinNeighbors.h:36
eonc::VesinNeighbors::Options::return_distances
bool return_distances
Definition
VesinNeighbors.h:34
eonc::VesinNeighbors::Options::sorted
bool sorted
Definition
VesinNeighbors.h:32
client
VesinNeighbors.cpp
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf