Simpatico  v1.10
tools/storage/AtomStorage.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "AtomStorage.h"
9 
10 namespace Tools
11 {
12 
13  /*
14  * Constructor.
15  */
17  : newPtr_(0)
18  {}
19 
20  /*
21  * Destructor.
22  */
24  {}
25 
26  /*
27  * Allocate and initialize memory.
28  */
30  {
31  atoms_.allocate(capacity);
32  atomPtrs_.allocate(capacity);
33  clear();
34  }
35 
36  /*
37  * Return pointer to location for new atom.
38  */
40  {
41  if (newPtr_) {
42  UTIL_THROW("Error: an new atom is still active");
43  }
44  int size = atoms_.size() + 1;
45  atoms_.resize(size);
46  newPtr_ = &atoms_[size - 1];
47  return newPtr_;
48  }
49 
50  /*
51  * Finalize addition of new atom.
52  */
54  {
55  if (!newPtr_) {
56  UTIL_THROW("Error: No active new atom");
57  }
58  int id = newPtr_->id;
59  atomPtrs_[id] = newPtr_;
60  newPtr_ = 0;
61  }
62 
63  /*
64  * Remove all atoms and bonds - set to empty state.
65  */
67  {
68  atoms_.clear();
69  int capacity = atomPtrs_.capacity();
70  for (int i = 0; i < capacity; ++i) {
71  atomPtrs_[i] = 0;
72  }
73  }
74 
75 }
int id
Unique global index (tag)
int size() const
Get number of atoms.
int capacity() const
Get atom capacity (maximum id + 1).
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Definition: global.h:51
void add()
Finalize addition of atom (allows lookup by id).
Single-processor classes for pre- and post-processing MD trajectories.
void clear()
Clear all atoms and groups.
A point particle in an MD simulation.
Atom * newPtr()
Return pointer to location for new atom.
void allocate(int capacity)
Allocate and initialize memory.