forked from espressomd/espresso
-
Notifications
You must be signed in to change notification settings - Fork 1
/
EspressoSystemInterface.cpp
140 lines (113 loc) · 3.93 KB
/
EspressoSystemInterface.cpp
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
#include "EspressoSystemInterface.hpp"
#include "cells.hpp"
#include "particle_data.hpp"
#include "grid.hpp"
#include "cuda_interface.hpp"
#include <iostream>
/* Need explicite specialization, otherwise some compilers do not produce the objects. */
template class EspressoSystemInterface::const_iterator<SystemInterface::Real>;
template class EspressoSystemInterface::const_iterator<SystemInterface::Vector3>;
template class EspressoSystemInterface::const_iterator<int>;
/********************************************************************************************/
template<class value_type>
value_type EspressoSystemInterface::const_iterator<value_type>::operator*() const {
return (*m_const_iterator);
}
template<class value_type>
SystemInterface::const_iterator<value_type> &EspressoSystemInterface::const_iterator<value_type>::operator=(const SystemInterface::const_iterator<value_type> &rhs) {
m_const_iterator = static_cast<const EspressoSystemInterface::const_iterator<value_type> &>(rhs).m_const_iterator;
return *this;
}
template<class value_type>
EspressoSystemInterface::const_iterator<value_type> &EspressoSystemInterface::const_iterator<value_type>::operator=(typename std::vector<value_type>::const_iterator rhs) {
m_const_iterator = rhs;
return *this;
}
template<class value_type>
bool EspressoSystemInterface::const_iterator<value_type>::operator==(SystemInterface::const_iterator<value_type> const &rhs) const {
return (m_const_iterator == static_cast<const EspressoSystemInterface::const_iterator<value_type> &>(rhs).m_const_iterator);
}
template<class value_type>
bool EspressoSystemInterface::const_iterator<value_type>::operator!=(SystemInterface::const_iterator<value_type> const &rhs) const {
return (m_const_iterator != static_cast<const EspressoSystemInterface::const_iterator<value_type> &>(rhs).m_const_iterator);
}
template<class value_type>
SystemInterface::const_iterator<value_type> &EspressoSystemInterface::const_iterator<value_type>::operator++() {
++m_const_iterator;
return *this;
}
/********************************************************************************************/
void EspressoSystemInterface::gatherParticles() {
Cell *cell;
Particle *p;
int i,c,np;
// get particles from other nodes
#ifdef CUDA
if (m_gpu)
{
if(gpu_get_global_particle_vars_pointer_host()->communication_enabled) {
ESIF_TRACE(puts("Calling copy_part_data_to_gpu()"));
copy_part_data_to_gpu();
reallocDeviceMemory(gpu_get_global_particle_vars_pointer_host()->number_of_particles);
if(m_splitParticleStructGpu && (this_node == 0))
split_particle_struct();
}
}
#endif
if (needsQ() || needsR()) {
R.clear();
#ifdef ELECTROSTATICS
Q.clear();
#endif
for (c = 0; c < local_cells.n; c++) {
cell = local_cells.cell[c];
p = cell->part;
np = cell->n;
if(needsR())
R.reserve(R.size()+np);
#ifdef ELECTROSTATICS
if(needsQ())
Q.reserve(Q.size()+np);
#endif
for(i = 0; i < np; i++) {
if(needsR())
R.push_back(Vector3(p[i].r.p));
#ifdef ELECTROSTATICS
if(needsQ())
Q.push_back(p[i].p.q);
#endif
}
}
}
}
void EspressoSystemInterface::init() {
gatherParticles();
}
void EspressoSystemInterface::update() {
gatherParticles();
}
SystemInterface::const_vec_iterator &EspressoSystemInterface::rBegin() {
m_r_begin = R.begin();
return m_r_begin;
}
const SystemInterface::const_vec_iterator &EspressoSystemInterface::rEnd() {
m_r_end = R.end();
return m_r_end;
}
#ifdef ELECTROSTATICS
SystemInterface::const_real_iterator &EspressoSystemInterface::qBegin() {
m_q_begin = Q.begin();
return m_q_begin;
}
const SystemInterface::const_real_iterator &EspressoSystemInterface::qEnd() {
m_q_end = Q.end();
return m_q_end;
}
#endif
unsigned int EspressoSystemInterface::npart() {
return m_npart;
}
SystemInterface::Vector3 EspressoSystemInterface::box() {
return Vector3(box_l);
}
EspressoSystemInterface espressoSystemInterface;