9 #include <ddMd/storage/ConstGhostIterator.h> 10 #include <util/containers/ArraySet.h> 27 totalAtomCapacity_(0),
44 UTIL_THROW(
"AtomMap can only be initialized once");
46 atomPtrs_.allocate(totalAtomCapacity);
47 totalAtomCapacity_ = totalAtomCapacity;
48 for (
int i = 0; i < totalAtomCapacity_; ++i) {
51 isInitialized_ =
true;
61 int atomId = ptr->
id();
62 if (atomId < 0 || atomId >= totalAtomCapacity_) {
63 Log::file() <<
"atomId = " << atomId << std::endl;
66 if (atomPtrs_[atomId]) {
67 Log::file() <<
"atomId = " << atomId << std::endl;
70 Log::file() <<
"Old Position = " << atomPtrs_[atomId]->position()
72 UTIL_THROW(
"Local atom with specified id is already present");
76 atomPtrs_[atomId] = ptr;
85 int atomId = ptr->
id();
86 if (atomId < 0 || atomId >= totalAtomCapacity_) {
87 Log::file() <<
"atomId = " << atomId << std::endl;
90 if (ptr == atomPtrs_[atomId]) {
93 atomPtrs_[atomId] = 0;
97 if (!ghostMap_.empty()) {
98 GhostMap::iterator iter = ghostMap_.find(atomId);
99 if (iter != ghostMap_.end()) {
100 atomPtrs_[atomId] = iter->second;
102 ghostMap_.erase(iter);
107 if (0 == atomPtrs_[atomId]) {
108 UTIL_THROW(
"Error: Attempt to remove absent local atom");
122 int atomId = ptr->
id();
123 if (atomId < 0 || atomId >= totalAtomCapacity_) {
127 if (0 == atomPtrs_[atomId]) {
128 atomPtrs_[atomId] = ptr;
131 ghostMap_.insert(std::pair<int, Atom*>(atomId, ptr));
141 int atomId = ptr->
id();
142 if (atomId < 0 || atomId >= totalAtomCapacity_) {
146 if (atomPtrs_[atomId] == ptr) {
149 atomPtrs_[atomId] = 0;
153 if (!ghostMap_.empty()) {
154 GhostMap::iterator iter = ghostMap_.find(atomId);
155 if (iter != ghostMap_.end()) {
156 atomPtrs_[atomId] = iter->second;
158 ghostMap_.erase(iter);
164 if (atomPtrs_[atomId] != 0) {
166 std::pair<GhostMap::iterator, GhostMap::iterator> ret;
167 ret = ghostMap_.equal_range(atomId);
168 GhostMap::iterator it = ret.first;
169 GhostMap::iterator last = ret.second;
170 for ( ; it != last; ++it) {
171 assert(it->first == atomId);
172 if (it->second == ptr) {
177 UTIL_THROW(
"Error: Attempt to remove absent ghost");
179 UTIL_THROW(
"Error: Attempt to remove absent ghost");
199 for (ghostSet.
begin(iter); iter.
notEnd(); ++iter) {
202 if (atomPtrs_[
id] == ptr) {
222 for (i = 0; i < totalAtomCapacity_ ; ++i) {
228 Log::file() <<
"Index i in atomPtrs_ " << i << std::endl;
229 Log::file() <<
"atomPtrs_[i]->id() " <<
id << std::endl;
235 if (nAtom != nLocal_ + nGhostDistinct_) {
236 UTIL_THROW(
"Inconsistent count of atoms in atomPtrs");
240 GhostMap::const_iterator it;
241 for (it = ghostMap_.begin(); it != ghostMap_.end(); ++it) {
244 if (
id != ptr->
id()) {
246 Log::file() <<
"key ghostMap " <<
id << std::endl;
247 Log::file() <<
"Atom::id() " << ptr->
id() << std::endl;
250 if (atomPtrs_[
id] == 0) {
251 UTIL_THROW(
"Id in ghostMap_ does not appear in atomPtrs_");
void begin(PArrayIterator< Data > &iterator) const
Set a PArrayIterator to the beginning of this PArray.
const Data * get() const
Return a pointer to const current data.
bool isValid() const
Check validity of this AtomMap.
void addLocal(Atom *ptr)
Add local atom.
Vector & position()
Get position Vector by reference.
void allocate(int totalAtomCapacity)
Set parameters, allocate memory and initialize.
File containing preprocessor macros for error handling.
A point particle in an MD simulation.
Parallel domain decomposition (DD) MD simulation.
int id() const
Get unique global index for this atom.
void removeLocal(Atom *ptr)
Remove a specific Atom.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
A container for pointers to a subset of elements of an associated array.
int nGhost() const
Return the number of ghosts, including images.
Utility classes for scientific computation.
static std::ostream & file()
Get log ostream by reference.
bool notEnd() const
Is the current pointer not at the end of the array?
int size() const
Return logical size.
Iterator for all ghost atoms owned by an AtomStorage.
void removeGhost(Atom *ptr)
Remove a ghost Atom.
void addGhost(Atom *ptr)
Add ghost atom.
void clearGhosts(const ArraySet< Atom > &ghostSet)
Clear all ghosts from this map.